git: kernel - Refactor malloc_type to reduce static data in image

Matthew Dillon dillon at
Mon Dec 16 23:06:45 PST 2019

commit 3ab3ae181ba0639ec0dbb537a7a19442dc504d64
Author: Matthew Dillon <dillon at>
Date:   Mon Dec 16 22:58:26 2019 -0800

    kernel - Refactor malloc_type to reduce static data in image
    * malloc_type was embedding a SMP_MAXCPU array of kmalloc_use
      structures, which winds up being 16KB a pop x 400+ MALLOC_DEFINE()
      This was over 6MB of static data in the kernel binary, and it
      wasn't BSS because the declaration is initialized with some defaults.
      So this reduction is significant and directly impacts both memory
      use and kernel boot times.
    * Change malloc_type->ks_use from an array to a pointer.  Embed
      a single kmalloc_use structure (ks_use0) as the default.
      When ncpus is probed, the kernel now goes through all malloc_type
      structures and dynamically allocates a properly-sized ks_use
      array.  Any new malloc hoppers after that point will also dynamically
      allocate ks_use.

Summary of changes:
 sys/kern/kern_slaballoc.c             | 55 ++++++++++++++++++++++++++---------
 sys/platform/pc64/x86_64/mp_machdep.c |  2 ++
 sys/platform/vkernel64/x86_64/mp.c    |  2 ++
 sys/sys/_malloc.h                     | 15 +++++++---
 sys/sys/malloc.h                      |  9 +++---
 5 files changed, 62 insertions(+), 21 deletions(-)

DragonFly BSD source repository

More information about the Commits mailing list