git: kernel - Implement sbrk(), change low-address mmap hinting

Matthew Dillon dillon at crater.dragonflybsd.org
Sun Feb 17 17:48:28 PST 2019


commit 4b5665564ef37dc939a3a9ffbafaab9894c18885
Author: Matthew Dillon <dillon at apollo.backplane.com>
Date:   Sat Feb 16 16:41:25 2019 -0800

    kernel - Implement sbrk(), change low-address mmap hinting
    
    * Change mmap()'s internal lower address bound from dmax (32GB)
      to RLIMIT_DATA's current value.  This allows the rlimit to be
      e.g. reduced and for hinted mmap()s to then map space below
      the 4GB mark.  The default data rlimit is 32GB.
    
      This change is needed to support several languages, at least
      lua and probably another one or two, who use mmap hinting
      under the assumption that it can map space below the 4GB
      address mark.  The data limit must be lowered with a limit command
      too, which can be scripted or patched for such programs.
    
    * Implement the sbrk() system call.  This system call was already
      present but just returned EOPNOTSUPP and libc previously had its
      own shim for sbrk() which used the ancient break() system call.
      (Note that the prior implementation did not ENOSYS or signal).
    
      sbrk() in the kernel is thread-safe for positive increments and
      is also byte-granular (the old libc sbrk() was only page-granular).
    
      sbrk() in the kernel does not implement negative increments and
      will return EOPNOTSUPP if asked to.  Negative increments were
      historically designed to be able to 'free' memory allocated with
      sbrk(), but it is not possible to implement the case in a modern
      VM system due to the mmap changes above.
    
      (1) Because the new mmap hinting changes make it possible for
      normal mmap()s to have mapped space prior to the RLIMIT_DATA resource
      limit being increased, causing intermingling of sbrk() and user mmap()d
      regions.  (2) because negative increments are not even remotely
      thread-safe.
    
    * Note the previous commit refactored libc to use the kernel sbrk()
      and fall-back to its previous emulation code on failure, so libc
      supports both new and old kernels.
    
    * Remove the brk() shim from libc.  brk() is not implemented by the
      kernel.  Symbol removed.  Requires testing against ports so we may
      have to add it back in but basically there is no way to implement
      brk() properly with the mmap() hinting fix
    
    * Adjust manual pages.

Summary of changes:
 include/unistd.h           |   2 +-
 lib/libc/sys/brk.2         |  50 +++++++++++++++----
 sys/kern/imgact_aout.c     |   4 +-
 sys/kern/imgact_elf.c      |   8 ++--
 sys/kern/imgact_gzip.c     |   8 ++--
 sys/kern/init_main.c       |   2 +-
 sys/kern/kern_checkpoint.c |   4 +-
 sys/kern/kern_clock.c      |   6 +--
 sys/kern/kern_exec.c       |   5 +-
 sys/kern/kern_fork.c       |  16 +++----
 sys/kern/kern_kinfo.c      |   6 +--
 sys/kern/syscalls.master   |   4 +-
 sys/libkern/arc4random.c   |  29 +++++++----
 sys/sys/ckpt.h             |   4 +-
 sys/sys/libkern.h          |   1 +
 sys/sys/param.h            |   5 +-
 sys/vm/vm_map.c            |  38 ++++++++++-----
 sys/vm/vm_map.h            |   6 +--
 sys/vm/vm_mmap.c           |  10 ----
 sys/vm/vm_unix.c           | 117 +++++++++++++++++++++++++++++++++++++++++++--
 20 files changed, 244 insertions(+), 81 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/4b5665564ef37dc939a3a9ffbafaab9894c18885


-- 
DragonFly BSD source repository


More information about the Commits mailing list