HUGETLBFS_UNLINKED_FD(3)

πŸ’– HUGETLBFS_UNLINKED_FD πŸ’–

okay bestie, so this one is a Library Functions Manual page (section 3, we love a (3)), and it's all about two little functions: hugetlbfs_unlinked_fd and hugetlbfs_unlinked_fd_for_size. their whole job? getting you a file descriptor for a brand new unlinked file in hugetlbfs. that's it, that's the gig. πŸŽ€


✨ NAME ✨

hugetlbfs_unlinked_fd, hugetlbfs_unlinked_fd_for_size β€” Obtain a file descriptor for a new unlinked file in hugetlbfs

no cap, that's literally what they do. πŸ’…


🌸 SYNOPSIS 🌸

#include <hugetlbfs.h>

int hugetlbfs_unlinked_fd(void);
int hugetlbfs_unlinked_fd_for_size(long page_size);

look at those signatures, they're so clean, they're giving minimalist icon. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so these functions hand you back an open file descriptor for a unique, newly-created file sitting in a hugetlbfs filesystem. and here's the part that's actually the whole point β€” to avoid leaking hugepages, the file gets unlinked automatically before the function returns. so by the time you even have the fd in your hands, the directory entry is already gone. it's giving commitment issues but make it responsible. πŸ’€

for hugetlbfs_unlinked_fd, it just uses the default huge page size (go check gethugepagesize(3) for that one).

for hugetlbfs_unlinked_fd_for_size, you must pass in a valid huge page size (peep gethugepagesizes(3) for the list of what counts as valid). so like, pick a real one, bestie. 🫢


πŸ”₯ RETURN VALUE πŸ”₯

  • on success, you get a valid open file descriptor back. iconic, we love that for you. πŸ’–
  • on failure, -1 gets returned, and errno may be set appropriately. so like, check it. don't be that person. 😭

πŸ‘‘ SEE ALSO πŸ‘‘

gethugepagesize(3), gethugepagesizes(3), mkstemp(3), libhugetlbfs(7)

go read those too, they're the supporting cast and they ate. 🌈


🌟 AUTHORS 🌟

libhugetlbfs was written by various people on the libhugetlbfs-devel mailing list. a whole committee of legends, honestly. πŸ‘‘


quick reminder bestie: those long page_size vibes are not optional for the _for_size one. it needs a valid huge page size or it's not gonna have a good time. no guessing, no vibes-based page sizes. 🚫

and that's the whole page!! mwah πŸ’‹ this version is dated March 7, 2012, straight from the Library Functions Manual era, and it covers HUGETLBFS_UNLINKED_FD(3) β€” stay hydrated, unlink responsibly, and slay πŸ§šπŸ’œ