• Andrew Morton's avatar
    [PATCH] slab reclaim balancing · b65bbded
    Andrew Morton authored
    A patch from Ed Tomlinson which improves the way in which the kernel
    reclaims slab objects.
    
    The theory is: a cached object's usefulness is measured in terms of the
    number of disk seeks which it saves.  Furthermore, we assume that one
    dentry or inode saves as many seeks as one pagecache page.
    
    So we reap slab objects at the same rate as we reclaim pages.  For each
    1% of reclaimed pagecache we reclaim 1% of slab.  (Actually, we _scan_
    1% of slab for each 1% of scanned pages).
    
    Furthermore we assume that one swapout costs twice as many seeks as one
    pagecache page, and twice as many seeks as one slab object.  So we
    double the pressure on slab when anonymous pages are being considered
    for eviction.
    
    The code works nicely, and smoothly.  Possibly it does not shrink slab
    hard enough, but that is now very easy to tune up and down.  It is just:
    
    	ratio *= 3;
    
    in shrink_caches().
    
    Slab caches no longer hold onto completely empty pages.  Instead, pages
    are freed as soon as they have zero objects.  This is possibly a
    performance hit for slabs which have constructors, but it's doubtful.
    Most allocations after a batch of frees are satisfied from inside
    internally-fragmented pages and by the time slab gets back onto using
    the wholly-empty pages they'll be cache-cold.  slab would be better off
    going and requesting a new, cache-warm page and reconstructing the
    objects therein.  (Once we have the per-cpu hot-page allocator in
    place.  It's happening).
    
    As a consequence of the above, kmem_cache_shrink() is now unused.  No
    great loss there - the serialising effect of kmem_cache_shrink and its
    semaphore in front of page reclaim was measurably bad.
    
    Still todo:
    
    - batch up the shrinking so we don't call into prune_dcache and
      friends at high frequency asking for a tiny number of objects.
    
    - Maybe expose the shrink ratio via a tunable.
    
    - clean up slab.c
    
    - highmem page reclaim in prune_icache: highmem pages can pin
      inodes.
    b65bbded
inode.c 26.3 KB