--- Gnu-Mach/kern/slab.h 2020/09/02 04:45:20 1.1.1.1 +++ Gnu-Mach/kern/slab.h 2020/09/02 04:47:38 1.1.1.2 @@ -47,6 +47,7 @@ #ifndef _KERN_SLAB_H #define _KERN_SLAB_H +#include #include #include #include @@ -147,14 +148,20 @@ typedef vm_offset_t (*kmem_slab_alloc_fn typedef void (*kmem_slab_free_fn_t)(vm_offset_t, vm_size_t); /* - * Cache name buffer size. + * Cache name buffer size. The size is chosen so that struct + * kmem_cache fits into two cache lines. The size of a cache line on + * a typical CPU is 64 bytes. */ -#define KMEM_CACHE_NAME_SIZE 32 +#define KMEM_CACHE_NAME_SIZE 24 /* * Cache of objects. * * Locking order : cpu_pool -> cache. CPU pools locking is ordered by CPU ID. + * + * Currently, SLAB_USE_CPU_POOLS is not defined. KMEM_CACHE_NAME_SIZE + * is chosen so that the struct fits into two cache lines. The first + * cache line contains all hot fields. */ struct kmem_cache { #if SLAB_USE_CPU_POOLS @@ -170,25 +177,27 @@ struct kmem_cache { struct list free_slabs; struct rbtree active_slabs; int flags; + size_t bufctl_dist; /* Distance from buffer to bufctl */ + size_t slab_size; + unsigned long bufs_per_slab; + unsigned long nr_objs; /* Number of allocated objects */ + unsigned long nr_free_slabs; + kmem_cache_ctor_t ctor; + /* All fields below are cold */ size_t obj_size; /* User-provided size */ + /* Assuming ! SLAB_USE_CPU_POOLS, here is the cacheline boundary */ size_t align; size_t buf_size; /* Aligned object size */ - size_t bufctl_dist; /* Distance from buffer to bufctl */ - size_t slab_size; size_t color; size_t color_max; - unsigned long bufs_per_slab; - unsigned long nr_objs; /* Number of allocated objects */ unsigned long nr_bufs; /* Total number of buffers */ unsigned long nr_slabs; - unsigned long nr_free_slabs; - kmem_cache_ctor_t ctor; kmem_slab_alloc_fn_t slab_alloc_fn; kmem_slab_free_fn_t slab_free_fn; char name[KMEM_CACHE_NAME_SIZE]; size_t buftag_dist; /* Distance from buffer to buftag */ size_t redzone_pad; /* Bytes from end of object to redzone word */ -}; +} __cacheline_aligned; /* * Mach-style declarations for struct kmem_cache.