haiku/headers/posix
Michael Lotz b3bd66961a libroot/kernel: Implement MADV_FREE madvise() extension.
It allows an application to signal that it no longer needs the data in
the given address range and the underlying pages can be discarded and
reused elsewhere. This is finer grained than working with full areas
or mappings at a time and enables unmapping sections of partially used
mappings without giving up its address space.

Compared with punching holes into a mapping by "mapping over" with
PROT_NONE and MAP_NORESERVE, this has the obvious advantage of not
producing a lot of unused extra areas and saves the corresponding
resources. It is also a lot "lighter" of an operation than cutting
existing areas.

This introduces madvise() alongside the existing posix_madvise() to
allow for OS specific extensions. The constants for both functions are
aliased, the POSIX_MADV_* being a subset of the MADV_* ones without the
non-POSIX extensions. Internally posix_madvise() simply calls madvise().

MADV_FREE is commonly supported in other OSes with various subtle
semantic differences as to when pages are actually freed/cleared and how
or whether the pages are counted against the memory use of a process.
In the variant implemented here, pages are always immediately discarded
and memory counting is not altered. This behaviour should be considered
an implementation detail and may be altered later. The actual unmap and
discard could for example be delayed until pages are needed elsewhere to
reduce overhead in case of repeated discarding and remapping.

Note that MADV_FREE doesn't really align with the rest of the madvise()
API as it works like a command (i.e. discard these pages) and does not
add an attribute to the pages in the given range (i.e. mark these pages
for quick access from now on). As such, an MADV_FREE does not need to be
undone by setting a different advice later on, unlike how the other
flags work. This discrepancy may be the reason why it is not part of
POSIX.

Change-Id: Icc093379125a43e465dc4409d8f5ae0f64e107e0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2844
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2020-08-01 19:23:27 +00:00
..
arch kernel/x86_64: AVX support 2020-06-03 06:16:48 +00:00
arpa arpa/nameser.h: Fix build on GCC8. 2020-07-03 15:30:00 -04:00
compat/sys
net posix/if_types.h: Remove IFT_IEEE1394, breaks build 2019-04-22 13:21:50 -05:00
netinet headers: More removal of the BSD Advertising Clause. 2020-07-03 15:00:37 -04:00
netinet6 Fix IN6_IS_ADDR_V4MAPPED & IN6_IS_ADDR_V4COMPAT false positives 2018-11-27 02:43:53 +00:00
sys libroot/kernel: Implement MADV_FREE madvise() extension. 2020-08-01 19:23:27 +00:00
alloca.h
assert.h assert.h: reintroduce headers guard for function declarations. 2015-08-29 23:14:03 +02:00
bsd_mem.h
complex.h complex.h: add a C++ guard. 2016-10-05 09:18:42 +02:00
ctype.h
dirent.h
div_t.h
dlfcn.h libroot.so: make first parameter of dladdr() const. 2017-09-15 23:09:24 +02:00
endian.h Clarify endianness defines. 2019-08-27 17:44:57 +02:00
errno.h
fcntl.h posix: add posix_fadvise(), only error checks. 2019-05-21 15:07:43 +00:00
fenv.h riscv64: Add missing (slightly modified) fenv.h from FreeBSD 2020-01-28 11:48:42 +00:00
fnmatch.h fnmatch: Replace BSD implementation with musl one. 2020-07-03 15:09:33 -04:00
fts.h
ftw.h
getopt.h
glob.h headers: More removal of the BSD Advertising Clause. 2020-07-03 15:00:37 -04:00
grp.h
inttypes.h Remove __STDC_FORMAT/CONSTANT_MACROS 2017-06-04 17:29:29 +02:00
iovec.h
langinfo.h
libgen.h
libio.h
limits.h limits.h: ncrease ARG_MAX 2020-08-01 17:37:01 +00:00
locale.h
malloc_debug.h malloc_debug: Implement allocation dump on exit in guarded heap. 2015-04-10 17:04:28 +02:00
malloc.h malloc: implement malloc_usable_size(). 2015-06-13 14:29:11 +02:00
math.h posix/math: Use the GCC built-ins when possible for isnan(), etc. 2020-01-06 07:44:30 +00:00
memory.h
monetary.h
netdb.h resolv.h & netdb.h: Clean up and simplify. 2020-07-02 19:33:51 -04:00
nl_types.h
null.h
poll.h
pthread.h s/Haiku License/MIT License/g. 2019-08-30 18:16:02 -04:00
pwd.h
regex.h
resolv.h resolv.h & netdb.h: Clean up and simplify. 2020-07-02 19:33:51 -04:00
sched.h
search.h search.h: fix typo. 2014-06-07 10:54:15 +02:00
semaphore.h Reimplement unnamed POSIX semaphores using user_mutex 2015-05-24 14:03:40 +01:00
setjmp.h setjmp.h: add noreturn keyword on longjmp variants. 2018-07-21 12:27:27 +02:00
shadow.h
signal.h Revert "Add sys/ucontext.h" 2014-08-09 20:18:05 +02:00
size_t.h
spawn.h s/Haiku License/MIT License/g. 2019-08-30 18:16:02 -04:00
stdint.h Remove __STDC_FORMAT/CONSTANT_MACROS 2017-06-04 17:29:29 +02:00
stdio_ext.h
stdio_post.h
stdio_pre.h
stdio.h Revert "deprecate gets and tmpnam" 2020-01-04 15:26:08 -05:00
stdlib.h mark abort() function as noreturn. 2020-05-03 15:42:41 +00:00
string.h string.h: include strings.h for compatibility. 2014-10-30 00:20:13 +01:00
strings.h strings.h: s/inline/__inline__/ 2020-05-24 13:59:57 +00:00
syslog.h syslog.h: Add LOG_NFACILITIES, LOG_FACMASK, LOG_FAC. 2017-12-26 17:09:26 -05:00
tar.h added tar.h posix header. 2014-04-26 11:09:24 +02:00
termios.h Allow custom baud rates for FTDI serial ports 2016-02-27 19:08:53 +01:00
time.h Switch to a 64-bit time_t everywhere except 32-bit x86. 2017-06-06 17:38:17 -04:00
uchar.h uchar.h: Remove duplicate definition of mbrtoc32. 2020-05-09 16:15:55 -04:00
unistd.h POSIX: add a few constants for sysconf. 2019-09-07 15:04:14 +00:00
utime.h
wchar_t.h
wchar.h Fix #7008: Add a64l and l64a from glibc, and add some missing definitions in wchar.h and stdlib.h 2014-12-14 18:06:09 +01:00
wctype.h