Changeset 4ed41b3 in mainline


Ignore:
Timestamp:
2018-02-20T11:07:51Z (6 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a211838
Parents:
fec0240
Message:

use a dedicated cache for the per-CPU magazines of caches

This avoids using the malloc()/free() API within the SLAB allocator
itself (which was slightly inconsistent) and it should also conserve
memory since the cache for the per-CPU magazines is sized precisely
according to the number of CPUs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/slab.c

    rfec0240 r4ed41b3  
    125125/** Cache for cache descriptors */
    126126static slab_cache_t slab_cache_cache;
     127
     128/** Cache for per-CPU magazines of caches */
     129static slab_cache_t slab_mag_cache;
    127130
    128131/** Cache for external slab descriptors
     
    589592        assert(_slab_initialized >= 2);
    590593       
    591         cache->mag_cache = malloc(sizeof(slab_mag_cache_t) * config.cpu_count,
    592             FRAME_ATOMIC);
     594        cache->mag_cache = slab_alloc(&slab_mag_cache, FRAME_ATOMIC);
    593595        if (!cache->mag_cache)
    594596                return false;
     
    723725}
    724726
     727/** Return object to cache, use slab if known
     728 *
     729 */
     730NO_TRACE static void _slab_free(slab_cache_t *cache, void *obj, slab_t *slab)
     731{
     732        ipl_t ipl = interrupts_disable();
     733       
     734        if ((cache->flags & SLAB_CACHE_NOMAGAZINE) ||
     735            (magazine_obj_put(cache, obj)))
     736                slab_obj_destroy(cache, obj, slab);
     737       
     738        interrupts_restore(ipl);
     739        atomic_dec(&cache->allocated_objs);
     740}
     741
    725742/** Check that there are no slabs and remove cache from system
    726743 *
     
    751768                panic("Destroying cache that is not empty.");
    752769       
    753         if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
    754                 free(cache->mag_cache);
     770        if (!(cache->flags & SLAB_CACHE_NOMAGAZINE)) {
     771                slab_t *mag_slab = obj2slab(cache->mag_cache);
     772                _slab_free(mag_slab->cache, cache->mag_cache, mag_slab);
     773        }
    755774       
    756775        slab_free(&slab_cache_cache, cache);
     
    779798       
    780799        return result;
    781 }
    782 
    783 /** Return object to cache, use slab if known
    784  *
    785  */
    786 NO_TRACE static void _slab_free(slab_cache_t *cache, void *obj, slab_t *slab)
    787 {
    788         ipl_t ipl = interrupts_disable();
    789        
    790         if ((cache->flags & SLAB_CACHE_NOMAGAZINE) ||
    791             (magazine_obj_put(cache, obj)))
    792                 slab_obj_destroy(cache, obj, slab);
    793        
    794         interrupts_restore(ipl);
    795         atomic_dec(&cache->allocated_objs);
    796800}
    797801
     
    931935#endif
    932936       
     937        _slab_cache_create(&slab_mag_cache, "slab_mag_cache",
     938            sizeof(slab_mag_cache_t) * config.cpu_count, sizeof(uintptr_t),
     939            NULL, NULL, SLAB_CACHE_NOMAGAZINE | SLAB_CACHE_SLINSIDE);
     940       
    933941        irq_spinlock_lock(&slab_cache_lock, false);
    934942       
Note: See TracChangeset for help on using the changeset viewer.