git: kernel - Add kmalloc_obj subsystem step 1

Matthew Dillon dillon at crater.dragonflybsd.org
Sun Mar 21 12:13:44 PDT 2021


commit e9dbfea17a45e13134f19ed8fa22fbe8d11ac99c
Author: Matthew Dillon <dillon at apollo.backplane.com>
Date:   Sun Mar 21 11:48:26 2021 -0700

    kernel - Add kmalloc_obj subsystem  step 1
    
    * Implement per-zone memory management to kmalloc() in the form of
      kmalloc_obj() and friends.  Currently the subsystem uses the same
      malloc_type structure but is otherwise distinct from the normal
      kmalloc(), so to avoid programming mistakes the *_obj() subsystem
      post-pends '_obj' to malloc_type pointers passed into it.
    
      This mechanism will eventually replace objcache.  This mechanism is
      designed to greatly reduce fragmentation issues on systems with long
      uptimes.
    
      Eventually the feature will be better integrated and I will be able
      to remove the _obj stuff.
    
    * This is a object allocator, so the zone must be dedicated to one
      type of object with a fixed size.  All allocations out of the zone
      are of the object.
    
      The allocator is not quite type-stable yet, but will be once existential
      locks are integrated into the freeing mechanism.
    
    * Implement a mini-slab allocator for management.  Since the zones are
      single-object, similar to objcache, the fixed-size mini-slabs are a
      lot easier to optimize and much simpler in construction than the
      main kernel slab allocator.
    
      Uses a per-zone/per-cpu active/alternate slab with an ultra-optimized
      allocation path, and a per-zone partial/full/empty list.
    
      Also has a globaldata-based per-cpu cache of free slabs.  The mini-slab
      allocator frees slabs back to the same cpu they were originally
      allocated from in order to retain memory locality over time.
    
    * Implement a passive cleanup poller.  This currently polls kmalloc zones
      very slowly looking for excess full slabs to release back to the global
      slab cache or the system (if the global slab cache is full).
    
      This code will ultimately also handle existential type-stable freeing.
    
    * Fragmentation is greatly reduced due to the distinct zones.  Slabs are
      dedicated to the zone and do not share allocation space with other zones.
      Also, when a zone is destroyed, all of its memory is cleanly disposed
      of and there will be no left-over fragmentation.
    
    * Initially use the new interface for the following.  These zones
      tend to or can become quite big:
    
      vnodes
      namecache (but not related strings)
      hammer2 chains
      hammer2 inodes
      tmpfs nodes
      tmpfs dirents (but not related strings)

Summary of changes:
 sys/conf/files                   |   1 +
 sys/dev/drm/include/linux/idr.h  |   2 +-
 sys/dev/drm/include/linux/slab.h |   3 +-
 sys/kern/kern_kmalloc.c          | 938 +++++++++++++++++++++++++++++++++++++++
 sys/kern/kern_slaballoc.c        | 149 ++++++-
 sys/kern/vfs_cache.c             |  28 +-
 sys/kern/vfs_lock.c              |  11 +-
 sys/sys/_malloc.h                | 103 ++++-
 sys/sys/globaldata.h             |   1 +
 sys/sys/malloc.h                 | 145 +++++-
 sys/vfs/hammer2/hammer2.h        |   6 +-
 sys/vfs/hammer2/hammer2_chain.c  |  10 +-
 sys/vfs/hammer2/hammer2_inode.c  |   4 +-
 sys/vfs/hammer2/hammer2_iocom.c  |   2 +-
 sys/vfs/hammer2/hammer2_vfsops.c |  14 +-
 sys/vfs/tmpfs/tmpfs.h            |  15 +-
 sys/vfs/tmpfs/tmpfs_subr.c       |  26 +-
 sys/vfs/tmpfs/tmpfs_vfsops.c     |  91 +---
 usr.bin/vmstat/vmstat.c          |  90 ++--
 19 files changed, 1426 insertions(+), 213 deletions(-)
 create mode 100644 sys/kern/kern_kmalloc.c

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/e9dbfea17a45e13134f19ed8fa22fbe8d11ac99c


-- 
DragonFly BSD source repository



More information about the Commits mailing list