bitwiseworks / libcx

kLIBC Extension Library
GNU Lesser General Public License v2.1
11 stars 1 forks source link

Uncommit pages on partial munmap #76

Open dmik opened 4 years ago

dmik commented 4 years ago

While we support partial munmap since long, it actually doesn't do anything but adjust the mapped region start and end pointers accordingly. Meaning that the actual pages remain committed if they were committed. We should decommit them so that the underlying physical pages are available for committing by other virtual pages. And also because this better suits the semantics of munmap (e.g. accessing unmapped pages should SIGSEGV).

Note that even if we uncommit pages, the virtual address range will still be occupied (and not available for further memory allocations regardless of the available physical memory). This is because OS/2 can only free the whole range of pages allocated with DosAllocMem at once. And in LIBCx this only happens when munmap is called for the whole region that was allocated using mmap.

Note that decommitting pages as described above will make them not available for any use at all. On Linux, you can put them in use again using mmap with MAP_FIXED. We don't support that either at this moment but it may make sense to add such support together with decommitting.

Note also that there is madvice which in our case also allows for committing and decommitting the pages. All of this also has some relation to #75.