io_uring_mlock_size(3)

πŸ’– io_uring_mlock_size β€” get required memlock size for a ring πŸ’–

okay bestie, so you know how io_uring is this whole liburing thing and you're like "how much memlock do I even need for my ring??" β€” this page is literally that. it's from the liburing manual, section 3 (that's the library-functions section, iykyk), and it's here to tell you the exact number so you don't have to guess. πŸŽ€


✨ SYNOPSIS ✨

#include <liburing.h>

ssize_t io_uring_mlock_size(unsigned entries, unsigned flags);

🌸 DESCRIPTION 🌸

so io_uring_mlock_size(3) is the function that returns the required RLIMIT_MEMLOCK memory size for an io_uring ring that has entries entries and whatever setup flags you passed in. that's it, that's the whole job. πŸ’…

now here's the tea, and it depends on your kernel:

  • on newer kernels (5.12+), io_uring no longer requires any memlock memory, and this function will return 0. yes, zero, nothing, she's free πŸ¦‹
  • on older kernels (5.11 and prior), this returns the required memory so that the caller can make sure there's enough RLIMIT_MEMLOCK space available before setting up a ring. like checking your bank balance before you tap your card, fr fr.

and if you want more control over the ring parameters? use io_uring_mlock_size_params(3) instead. that one's the glow-up version. ✨


🫢 RETURN VALUE 🫢

  • returns the required memlock size in bytes on success 🌈
  • returns 0 if no memlock is needed (hi, modern kernels) πŸ‘‘
  • or a negative errno value on error 😭

πŸ‘€ SEE ALSO πŸ‘€


lowkey important reminder: don't just vibe-check this number into existence β€” the whole point is calling it before you set up the ring, so future-you doesn't get yelled at by the kernel. πŸ’€

and that's a wrap, bestie πŸ’œ this was liburing-2.4, dated January 18, 2025 β€” mwah, go touch some ring buffers πŸŽ€βœ¨

πŸ“¦ where this page comes from