io_uring_register_files(3)

πŸ“¦
version 2.15 Β· 3 versions
  • 2.15 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 2.5 Β· ubuntu noble
  • 2.3 Β· debian bookworm
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ io_uring_register_files β€” register file descriptors ✨

okay bestie, welcome to the liburing Manual 🫢 this is the page for io_uring_register_files(3) and its little squad of file-table-registering besties, and honestly? it's giving ✨kernel-level efficiency✨. let's get into it.


🌸 NAME 🌸

io_uring_register_files β€” register file descriptors πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <liburing.h>

int io_uring_register_files(struct io_uring *ring,
                            const int *files,
                            unsigned nr_files);

int io_uring_register_files_tags(struct io_uring *ring,
                                 const int *files,
                                 const __u64 *tags,
                                 unsigned nr);

int io_uring_register_files_sparse(struct io_uring *ring,
                                   unsigned nr_files);

int io_uring_register_files_update(struct io_uring *ring,
                                   unsigned off,
                                   const int *files,
                                   unsigned nr_files);

int io_uring_register_files_update_tag(struct io_uring *ring,
                                       unsigned off,
                                       const int *files,
                                       const __u64 *tags,
                                       unsigned nr_files);

πŸ’– DESCRIPTION πŸ’–

so. the main character: io_uring_register_files(3). she registers nr_files number of file descriptors, defined by the array files, and those belong to the ring for all the operations that come after. registering them = they're officially part of the ring's roster now πŸŽ€

then there's io_uring_register_files_tags(3), which literally behaves the same as io_uring_register_files(3) except it also takes a tags parameter. the resource tagging deets live over in IORING_REGISTER_BUFFERS2, so go peek at that if you need the lore πŸ‘‘

and io_uring_register_files_sparse(3)? she registers an empty file table of nr_files number of file descriptors. those files have to be updated before you actually use them, like, for example with io_uring_register_files_update_tag(3). no cap, an empty table is an empty table. πŸ™ˆ

real talk though: if the size of that sparse table exceeds what RLIMIT_NOFILE allows, then io_uring_register_files_sparse(3) will attempt to raise the limit using setrlimit(2) and then retry the operation. and if the registration still fails after all that effort? an error gets returned. periodt. πŸ’€

also the sparse variant is only available in kernels 5.19 and later β€” so check your kernel before you get attached.

registering a file table is a prerequisite for using any request that uses direct descriptors. like, you cannot skip this step, bestie, it's the vibe check for direct descriptors ✨

okay now the fun part β€” why even bother? registered files have less overhead per operation than normal files. here's the tea: the kernel grabs a reference count on a file when an operation begins, and drops it when it's done. and when the process file table is shared β€” for example, if the process has ever created any threads β€” that cost goes up even more. so using registered files reduces the overhead of file reference management across requests that operate on a file. efficiency slay πŸ”₯

moving on to updates:

io_uring_register_files_update(3) updates existing registered files. off is the offset on which to start the update, and it updates nr_files number of files defined by the array files belonging to the ring. it's giving "we're editing the roster, not rewriting it" πŸ’…

and io_uring_register_files_update_tag(3)? behaves the same as io_uring_register_files_update(3) but additionally takes a tags parameter. again β€” see IORING_REGISTER_BUFFERS2 for the resource tagging description. iykyk πŸ¦‹


⭐ RETURN VALUE ⭐


🌈 SEE ALSO 🌈


and that's the whole page bestie 🫢 this was liburing-2.1, dated November 15, 2021 β€” go forth and register those files, you absolute main character πŸŽ€πŸ’…βœ¨

πŸ“¦ where this page comes from