POSIX_MADVISE(3P)

🌸 POSIX_MADVISE(3P) 🌸

okay bestie, welcome to POSIX_MADVISE(3P) β€” it's a page straight outta the POSIX Programmer's Manual, and we're about to vibe check your memory. πŸ’–

πŸ’« PROLOG πŸ’«

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go consult the corresponding Linux manual page for the tea on Linux behavior, fr), or honestly the interface might not even be implemented on Linux at all. πŸ™ˆ


✨ NAME ✨

posix_madvise β€” memory advisory information and alignment control (ADVANCED REALTIME)

periodt. that's the whole name. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/mman.h>

int posix_madvise(void *addr, size_t len, int advice);

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the lore: posix_madvise() shall advise the implementation on the expected behavior of the application with respect to the data in the memory starting at address addr, and continuing for len bytes. Think of it as you sliding into the implementation's DMs like "hey bestie, here's what I'm about to do with this memory, just so you know." The implementation may use this info to optimize handling of the specified data. ✨

But here's the important part, no cap: posix_madvise() shall have no effect on the semantics of access to memory in the specified range, although it may affect the performance of access. It's giving advisory, not controlling. It's a suggestion, not a command. 🫢

The implementation may require that addr be a multiple of the page size β€” and that page size is the value returned by sysconf() when the name value _SC_PAGESIZE is used. 🧚

The advice to be applied to the memory range is specified by the advice parameter, and it may be one of these iconic values:

  • POSIX_MADV_NORMAL β€” Specifies that the application has no advice to give on its behavior with respect to the specified range. It's the default characteristic if no advice is given for a range of memory. basically the "no thoughts, head empty" option πŸ“
  • POSIX_MADV_SEQUENTIAL β€” Specifies that the application expects to access the specified range sequentially from lower addresses to higher addresses. front to back, like reading a book, we love a linear storyline πŸ“–
  • POSIX_MADV_RANDOM β€” Specifies that the application expects to access the specified range in a random order. chaos. unhinged. we stan. πŸ”₯
  • POSIX_MADV_WILLNEED β€” Specifies that the application expects to access the specified range in the near future. manifesting it. πŸ‘‘
  • POSIX_MADV_DONTNEED β€” Specifies that the application expects that it will not access the specified range in the near future. it's giving "we're not gonna talk about it" πŸ’€

These values are defined in the <sys/mman.h> header. iykyk. πŸ’œ


🌈 RETURN VALUE 🌈

Upon successful completion, posix_madvise() shall return zero. otherwise, an error number shall be returned to indicate the error. (yes bestie, it returns the error number itself, not -1 and not errno β€” read the return value, not errno, okay?) 😭


πŸ’€ ERRORS πŸ’€

The posix_madvise() function shall fail if:

  • EINVAL β€” The value of advice is invalid.
  • ENOMEM β€” Addresses in the range starting at addr and continuing for len bytes are partly or completely outside the range allowed for the address space of the calling process.

The posix_madvise() function may fail if:

  • EINVAL β€” The value of addr is not a multiple of the value returned by sysconf() when the name value _SC_PAGESIZE is used.
  • EINVAL β€” The value of len is zero.
lowkey note the difference bestie: "shall fail" is a promise, "may fail" is a maybe. two separate EINVAL entries too, don't @ me. πŸ™ˆ

The following sections are informative. (so like, they're the commentary track, not the main plot πŸŽ€)


🌸 EXAMPLES 🌸

None. 😭


🫢 APPLICATION USAGE 🫢

The posix_madvise() function is part of the Advisory Information option and need not be provided on all implementations. so don't be shocked if your platform just... doesn't have it. vibe check your implementation first, bestie. πŸ’…


⭐ RATIONALE ⭐

None. ✨


🧚 FUTURE DIRECTIONS 🧚

None. 🌈


πŸ’– SEE ALSO πŸ’–

  • mmap()
  • posix_fadvise()
  • sysconf()

The Base Definitions volume of POSIX.1‐2017, <sys_mman.h>


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


okay that's the whole page bestie, we ate and left no crumbs πŸ½οΈπŸ’… this lil masterpiece came to you courtesy of IEEE/The Open Group, 2017, and its name is POSIX_MADVISE(3P) β€” now go advise some memory responsibly, mwah πŸ’–πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from