SLQB v2
Subsystems (5)
PATCH 1/1 SLQB v2
SLQB slab allocator for mainline.
This version fixes compiles on UP and had minor code cleanups.
---
include/linux/rcupdate.h +1 -10
@@ -35,6 +35,7 @@#ifdef __KERNEL__ +#include <linux/rcu_types.h> #include <linux/cache.h> #include <linux/spinlock.h> #include <linux/threads.h>
@@ -43,16 +44,6 @@#include <linux/seqlock.h> #include <linux/lockdep.h> -/** -* struct rcu_head - callback structure for use with RCU -* @next: next update requests in a list -* @func: actual update function to call after the grace period. -*/ -struct rcu_head { -struct rcu_head *next; -void (*func)(struct rcu_head *head); -}; -#ifdef CONFIG_CLASSIC_RCU #include <linux/rcuclassic.h> #else /* #ifdef CONFIG_CLASSIC_RCU */
arch/x86/kernel/nmi_64.c +1 -1
@@ -28,7 +28,7 @@int unknown_nmi_panic;int nmi_watchdog_enabled; -int panic_on_unrecovered_nmi; +int panic_on_unrecovered_nmi =1 ;static cpumask_t backtrace_mask =CPU_MASK_NONE ;
include/linux/slqb_def.h new file +264 -0
264 lines not on this page · raw message
init/Kconfig +9 -1
@@ -701,6 +701,11 @@ config SLUB_DEBUG SLUB sysfs support. /sys/slab will not exist and there will be no support for cache validation etc. +config SLQB_DEBUG + default y + bool "Enable SLQB debugging support" + depends on SLQB + choice prompt "Choose SLAB allocator" default SLUB
@@ -724,6 +729,9 @@ config SLUB of queues of objects. SLUB can use memory efficiently and has enhanced diagnostics. +config SLQB + bool "SLQB (Qeued allocator)" + config SLOB depends on EMBEDDED bool "SLOB (Simple Allocator)"
@@ -763,7 +771,7 @@ endmenu # General setup config SLABINFO bool depends on PROC_FS - depends on SLAB || SLUB + depends on SLAB || SLUB || SLQB default y config RT_MUTEXES
lib/Kconfig.debug +10 -0
@@ -221,6 +221,16 @@ config SLUB_STATS out which slabs are relevant to a particular load. Try running: slabinfo -DA +config SLQB_DEBUG_ON + bool "SLQB debugging on by default" + depends on SLQB_DEBUG + default n + +config SLQB_STATS + default n + bool "Enable SLQB performance statistics" + depends on SLQB + config DEBUG_PREEMPT bool "Debug preemptible kernel" depends on DEBUG_KERNEL && PREEMPT && (TRACE_IRQFLAGS_SUPPORT || PPC64)
mm/slqb.c new file +4027 -0
2,661 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Part of the diff is not shown here. View the raw message.
Hi!,
On Thu, Apr 10, 2008 at 09:31:38PM +0200, Nick Piggin wrote:
...
Quoted 12 lines
include/linux/slqb_def.h new file +12
-0+ +/* +* We use struct slqb_page fields to manage some slob allocation aspects, +* however to avoid the horrible mess in include/linux/mm_types.h, we'll +* just define our own struct slqb_page type variant here. +*/ +struct slqb_page { + union { + struct { + unsigned long flags; /* mandatory */ + atomic_t _count; /* mandatory */ + unsigned int inuse; /* Nr of objects */
include/linux/slqb_def.h line 53
Quoted 10 lines
include/linux/slqb_def.h new file +10
-0+struct kmem_cache_list *list;/* Pointer to list */ +void **freelist;/* freelist req. slab lock */ +union { +struct list_head lru;/* misc. list */ +struct rcu_head rcu_head;/* for rcu freeing */ + }; + }; +struct page page; + }; +};
A small question for SLUB devs, would you accept a patch that does a similar thing by creating 'slub_page' instead of stuffing slub elements (freelist, inuse, ..) in 'mm_types::struct page' unions ?
Maybe cause I'm new to MM, but I felt I could understand the code much more better the SLQB slqb_page way.
...
Quoted 8 lines
include/linux/slqb_def.h new file +8
-0+/* +* Kmalloc subsystem. +*/ +#if defined(ARCH_KMALLOC_MINALIGN ) &&ARCH_KMALLOC_MINALIGN >8 +#define KMALLOC_MIN_SIZE ARCH_KMALLOC_MINALIGN +#else +#define KMALLOC_MIN_SIZE 8 +#endif
include/linux/slqb_def.h line 156
Quoted 10 lines
include/linux/slqb_def.h new file +10
-0+ +#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE) +#define KMALLOC_SHIFT_SLQB_HIGH (PAGE_SHIFT + 5) + +/* +* We keep the general caches in an array of slab caches that are used for +* 2^x bytes of allocations. +*/ +extern struct kmem_cache kmalloc_caches[KMALLOC_SHIFT_SLQB_HIGH +1 ]; +
So AFAIK in an x86 where PAGE_SHIFT = 12, KMALLOC_SHIFT_SLQB_HIGH+1 will equal= 18.
Quoted 27 lines
include/linux/slqb_def.h new file +27
-0+/* +* Sorry that the following has to be that ugly but some versions of GCC +* have trouble with constant propagation and loops. +*/ +static __always_inline int kmalloc_index(size_t size) +{ +if (!size) +return 0 ; + +if (size <=KMALLOC_MIN_SIZE ) +return KMALLOC_SHIFT_LOW ; + +if (size >64 && size <=96 ) +return 1 ; +if (size >128 && size <=192 ) +return 2 ; +if (size <=8 )return 3 ; +if (size <=16 )return 4 ; +if (size <=32 )return 5 ; +if (size <=64 )return 6 ; +if (size <=128 )return 7 ; +if (size <=256 )return 8 ; +if (size <=512 )return 9 ; +if (size <=1024 )return 10 ; +if (size <=2 *1024 )return 11 ; +/* +* The following is only needed to support architectures with a larger page
include/linux/slqb_def.h line 193
Quoted 10 lines
include/linux/slqb_def.h new file +10
-0+* size than 4k. +*/ +if (size <=4 *1024 )return 12 ; +if (size <=8 *1024 )return 13 ; +if (size <=16 *1024 )return 14 ; +if (size <=32 *1024 )return 15 ; +if (size <=64 *1024 )return 16 ; +if (size <=128 *1024 )return 17 ; +if (size <=256 *1024 )return 18 ; +if (size <=512 *1024 )return 19 ;
I'm sure there's something utterly wrong in my understanding, but how this is designed to not overflow kmalloc_caches[18] in an x86-32 machine ?
I can not see this possible-only-in-my-mind overflow happens in SLUB as it just delegate the work to the page allocator if size > PAGE_SIZE.
Quoted 58 lines
include/linux/slqb_def.h new file +58
-0+if (size <=1024 *1024 )return 20 ; +if (size <=2 *1024 *1024 )return 21 ; +return -1 ; + +/* +* What we really wanted to do and cannot do because of compiler issues is: +* int i; +* for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) +* if (size <= (1 << i)) +* return i; +*/ +} + +/* +* Find the slab cache for a given combination of allocation flags and size. +* +* This ought to end up with a global pointer to the right cache +* in kmalloc_caches. +*/ +static __always_inline struct kmem_cache *kmalloc_slab(size_t size) +{ +int index =kmalloc_index (size); + +if (index ==0 ) +return NULL ; + +return &kmalloc_caches[index]; +} + +#ifdef CONFIG_ZONE_DMA +#define SLQB_DMA __GFP_DMA +#else +/* Disable DMA functionality */ +#define SLQB_DMA (__force gfp_t)0 +#endif + +void *kmem_cache_alloc (struct kmem_cache *,gfp_t ); +void *__kmalloc (size_t size,gfp_t flags); + +static __always_inline void *kmalloc(size_t size, gfp_t flags) +{ +if (__builtin_constant_p (size)) { +if (likely (!(flags &SLQB_DMA ))) { +struct kmem_cache *s =kmalloc_slab (size); +if (!s) +return ZERO_SIZE_PTR ; +return kmem_cache_alloc (s, flags); + } + } +return __kmalloc (size, flags); +} + +#ifdef CONFIG_NUMA +void *__kmalloc_node (size_t size,gfp_t flags,int node); +void *kmem_cache_alloc_node (struct kmem_cache *,gfp_t flags,int node); + +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) +{
include/linux/slqb_def.h line 261
Quoted 10 lines
include/linux/slqb_def.h new file +10
-0+if (__builtin_constant_p (size)) { +if (likely (!(flags &SLQB_DMA ))) { +struct kmem_cache *s =kmalloc_slab (size); +if (!s) +return ZERO_SIZE_PTR ; +return kmem_cache_alloc_node (s, flags, node); + } + } +return __kmalloc_node (size, flags, node); +}
Why this compile-time/run-time divide although both kmem_cache_alloc{,_node} and __kmalloc{,_node} call slab_alloc() at the end ?
Quoted 8 lines
include/linux/slqb_def.h new file +3
-0+#endif + +#endif /* _LINUX_SLQB_DEF_H */ Index: linux-2.6/init/Kconfig
===================================================================
init/Kconfig config SLUB_DEBUG · line 708
Quoted 8 lines
init/Kconfig +5
-0@@ -701,6 +701,11 @@ config SLUB_DEBUG SLUB sysfs support. /sys/slab will not exist and there will be no support for cache validation etc. +config SLQB_DEBUG + default y + bool "Enable SLQB debugging support" + depends on SLQB +
Maybe if SLQB got merged it can just be easier to have a general SLAB_DEBUG option that is recognized by the current 4 slab allocators ?
Quoted 77 lines
init/Kconfig +4
-1choice prompt "Choose SLAB allocator" default SLUB@@ -724,6 +729,9 @@ config SLUB of queues of objects. SLUB can use memory efficiently and has enhanced diagnostics. +config SLQB + bool "SLQB (Qeued allocator)" + config SLOB depends on EMBEDDED bool "SLOB (Simple Allocator)"@@ -763,7 +771,7 @@ endmenu # General setup config SLABINFO bool depends on PROC_FS - depends on SLAB || SLUB + depends on SLAB || SLUB || SLQB default y config RT_MUTEXESIndex: linux-2.6/lib/Kconfig.debug
===================================================================lib/Kconfig.debug +10
-0@@ -221,6 +221,16 @@ config SLUB_STATS out which slabs are relevant to a particular load. Try running: slabinfo -DA +config SLQB_DEBUG_ON + bool "SLQB debugging on by default" + depends on SLQB_DEBUG + default n + +config SLQB_STATS + default n + bool "Enable SLQB performance statistics" + depends on SLQB + config DEBUG_PREEMPT bool "Debug preemptible kernel" depends on DEBUG_KERNEL && PREEMPT && (TRACE_IRQFLAGS_SUPPORT || PPC64)Index:
linux-2.6/mm/slqb.c
===================================================================mm/slqb.c new file +29
-0@@ -0,0 +1,4027 @@ +/* +* SLQB: A slab allocator that focuses on per-CPU scaling, and good performance +* with order-0 allocations. Fastpaths emphasis is placed on local allocaiton +* and freeing, and remote freeing (freeing on another CPU from that which +* allocated). +* +* Using ideas from mm/slab.c, mm/slob.c, and mm/slub.c, +* +* And parts of code from mm/slub.c +* (C) 2007 SGI, Christoph Lameter <[email protected]> +*/ + +#include <linux/mm.h> +#include <linux/module.h> +#include <linux/bit_spinlock.h> +#include <linux/interrupt.h> +#include <linux/bitops.h> +#include <linux/slab.h> +#include <linux/seq_file.h> +#include <linux/cpu.h> +#include <linux/cpuset.h> +#include <linux/mempolicy.h> +#include <linux/ctype.h> +#include <linux/kallsyms.h> +#include <linux/memory.h> + +/* +* Lock order: +* 1. kmem_cache_node->list_lock
mm/slqb.c line 39
Quoted 10 lines
mm/slqb.c new file +10
-0+* 2. kmem_cache_remote_free->lock +* +* Interrupts are disabled during allocation and deallocation in order to +* make the slab allocator safe to use in the context of an irq. In addition +* interrupts are disabled to ensure that the processor does not change +* while handling per_cpu slabs, due to kernel preemption. +* +* SLIB assigns one slab for allocation to each processor. +* Allocations only occur from these slabs called cpu slabs. +*
SLQB is a much more better name than SLIB :).
mm/slqb.c line 50
Quoted 11 lines
mm/slqb.c new file +11
-0+* Slabs with free elements are kept on a partial list and during regular +* operations no list for full slabs is used. If an object in a full slab is +* freed then the slab will show up again on the partial lists. +* We track full slabs for debugging purposes though because otherwise we +* cannot scan all objects. +* +* Slabs are freed when they become empty. Teardown and setup is +* minimal so we rely on the page allocators per cpu caches for +* fast frees and allocs. +*/ +
Ok, I admit I didn't do my homework yet of fully understanding the diff between SLUB and SLQB except in the kmalloc(> PAGE_SIZE) case. I hope my understanding will get better soon.
...
Quoted 10 lines
mm/slqb.c new file +10
-0+/* +* Slow path. The lockless freelist is empty or we need to perform +* debugging duties. +* +* Interrupts are disabled. +* +* Processing is still very fast if new objects have been freed to the +* regular freelist. In that case we simply take over the regular freelist +* as the lockless freelist and zap the regular freelist. +*
mm/slqb.c line 1295
Quoted 10 lines
mm/slqb.c new file +10
-0+* If that is not working then we fall back to the partial lists. We take the +* first element of the freelist as the object to allocate now and move the +* rest of the freelist to the lockless freelist. +* +* And if we were unable to get a new slab from the partial slab lists then +* we need to allocate a new slab. This is slowest path since we may sleep. +*/ +static __always_inline void *__slab_alloc(struct kmem_cache *s, +gfp_t gfpflags,int node,void *addr) +{
__slab_alloc istelf is not the slow-path, but the slow path begins from the alloc_new: label, right ?
If so, then IMHO the comment is a bit misleading since it gives the impression that the whole __slab_alloc() is the slow path.
Quoted 94 lines
mm/slqb.c new file +94
-0+void *object; +struct slqb_page *page; +struct kmem_cache_cpu *c; +struct kmem_cache_list *l; +#ifdef CONFIG_NUMA +struct kmem_cache_node *n; + +if (unlikely (node !=-1 ) &&unlikely (node !=numa_node_id ())) { + n = s->node[node]; +VM_BUG_ON (!n); + l = &n->list; + +if (unlikely (!l->nr_partial && !l->nr_free && !l->remote_free_check)) + goto alloc_new; + +spin_lock (&n->list_lock); +remote_list_have_object: + page =__cache_list_get_page (s, l); +if (unlikely (!page)) { +spin_unlock (&n->list_lock); + goto alloc_new; + } +VM_BUG_ON (node !=-1 && node !=slqb_page_to_nid (page)); + +remote_found: + object = page->freelist; + page->freelist =get_freepointer (s, object); +//prefetch(((void *)page->freelist) + s->offset); + page->inuse++; +VM_BUG_ON ((page->inuse == s->objects) != (page->freelist ==NULL )); +spin_unlock (&n->list_lock); + +return object; + } +#endif + + c =get_cpu_slab (s,smp_processor_id ()); +VM_BUG_ON (!c); + l = &c->list; + page =__cache_list_get_page (s, l); +if (unlikely (!page)) + goto alloc_new; +VM_BUG_ON (node !=-1 && node !=slqb_page_to_nid (page)); + +local_found: + object = page->freelist; + page->freelist =get_freepointer (s, object); +//prefetch(((void *)page->freelist) + s->offset); + page->inuse++; +VM_BUG_ON ((page->inuse == s->objects) != (page->freelist ==NULL )); + +return object; + +alloc_new: +#if 0 +/* XXX: load any partial? */ +#endif + +/* Caller handles __GFP_ZERO */ + gfpflags &= ~__GFP_ZERO; + +if (gfpflags & __GFP_WAIT) +local_irq_enable (); + page =new_slab_page (s, gfpflags, node); +if (gfpflags & __GFP_WAIT) +local_irq_disable (); +if (unlikely (!page)) +return NULL ; + +if (!NUMA_BUILD ||likely (slqb_page_to_nid (page) ==numa_node_id ())) { + c =get_cpu_slab (s,smp_processor_id ()); + l = &c->list; + page->list = l; + l->nr_slabs++; +if (page->inuse +1 < s->objects) { +list_add (&page->lru, &l->partial); + l->nr_partial++; + }else { +/*XXX list_add(&page->lru, &l->full); */ + } + goto local_found; + }else { +#ifdef CONFIG_NUMA + n = s->node[slqb_page_to_nid (page)]; +spin_lock (&n->list_lock); + l = &n->list; + +if (l->nr_free || l->nr_partial || l->remote_free_check) { +__free_slab (s, page); + goto remote_list_have_object; + } + + l->nr_slabs++; + page->list = l;
mm/slqb.c line 1400
Quoted 10 lines
mm/slqb.c new file +10
-0+if (page->inuse +1 < s->objects) { +list_add (&page->lru, &l->partial); + l->nr_partial++; + }else { +/*XXX list_add(&page->lru, &l->full); */ + } + goto remote_found; +#endif + } +
...
Thanks for helping me gaining a better understanding of SLQB!
Warm regards
Signature · 11 lines
"Better to light a candle, than curse the darkness" Ahmed S. Darwish Homepage: http://darwish.07.googlepages.com Blog: http://darwish-07.blogspot.com -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi, sorry I missed this message initially..
Quoted 22 lines · Ahmed S. Darwish
Hi!,
On Thu, Apr 10, 2008 at 09:31:38PM +0200, Nick Piggin wrote:
...Quoted 18 lines
include/linux/slqb_def.h new file +18
-0+ +/* +* We use struct slqb_page fields to manage some slob allocation aspects, +* however to avoid the horrible mess in include/linux/mm_types.h, we'll +* just define our own struct slqb_page type variant here. +*/ +struct slqb_page { + union { + struct { + unsigned long flags; /* mandatory */ + atomic_t _count; /* mandatory */ + unsigned int inuse; /* Nr of objects */ + struct kmem_cache_list *list; /* Pointer to list */ + void **freelist; /* freelist req. slab lock */ + union { + struct list_head lru; /* misc. list */ + struct rcu_head rcu_head; /* for rcu freeing */ + };
Quoted 8 lines
include/linux/slqb_def.h line 53
Quoted 4 lines
include/linux/slqb_def.h new file +4
-0+ }; +struct page page; + }; +};A small question for SLUB devs, would you accept a patch that does a similar thing by creating '
slub_page' instead of stuffing slub elements (freelist, inuse, ..) in 'mm_types::structpage' unions ?
I'd like to see that. I have a patch for SLUB, actually.
Quoted 17 lines
Maybe cause I'm new to MM, but I felt I could understand the code much more better the SLQB
slqb_pageway....
Quoted 13 lines
include/linux/slqb_def.h new file +13
-0+/* +* Kmalloc subsystem. +*/ +#if defined(ARCH_KMALLOC_MINALIGN ) &&ARCH_KMALLOC_MINALIGN >8 +#define KMALLOC_MIN_SIZE ARCH_KMALLOC_MINALIGN +#else +#define KMALLOC_MIN_SIZE 8 +#endif + +#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE) +#define KMALLOC_SHIFT_SLQB_HIGH (PAGE_SHIFT + 5) + +/*
Quoted 8 lines
Review
Quoted 5 lines
+ * We keep the general caches in an array of slab caches that are used for
+ * 2^x bytes of allocations.
+ */(quoted diff) +2
-0+extern struct kmem_cache kmalloc_caches[KMALLOC_SHIFT_SLQB_HIGH + 1]; +So AFAIK in an x86 where
PAGE_SHIFT= 12, KMALLOC_SHIFT_SLQB_HIGH+1 will equal= 18.
Right. It actually isn't enough in some cases it turns out. I have increased this a little bit in subsequent code (PAGE_SHIFT+8 I think is reasonable). For SLUB they hand off to the page allocator instead. It isn't really a big deal though, such allocations should be quite rare.
Quoted 41 lines
Quoted 27 lines
include/linux/slqb_def.h new file +27
-0+/* +* Sorry that the following has to be that ugly but some versions of GCC +* have trouble with constant propagation and loops. +*/ +static __always_inline int kmalloc_index(size_t size) +{ +if (!size) +return 0 ; + +if (size <=KMALLOC_MIN_SIZE ) +return KMALLOC_SHIFT_LOW ; + +if (size >64 && size <=96 ) +return 1 ; +if (size >128 && size <=192 ) +return 2 ; +if (size <=8 )return 3 ; +if (size <=16 )return 4 ; +if (size <=32 )return 5 ; +if (size <=64 )return 6 ; +if (size <=128 )return 7 ; +if (size <=256 )return 8 ; +if (size <=512 )return 9 ; +if (size <=1024 )return 10 ; +if (size <=2 *1024 )return 11 ; +/* +* The following is only needed to support architectures with a larger page include/linux/slqb_def.h line 193
Quoted 10 lines
include/linux/slqb_def.h new file +10
-0+* size than 4k. +*/ +if (size <=4 *1024 )return 12 ; +if (size <=8 *1024 )return 13 ; +if (size <=16 *1024 )return 14 ; +if (size <=32 *1024 )return 15 ; +if (size <=64 *1024 )return 16 ; +if (size <=128 *1024 )return 17 ; +if (size <=256 *1024 )return 18 ; +if (size <=512 *1024 )return 19 ;I'm sure there's something utterly wrong in my understanding, but how this is designed to not overflow kmalloc_caches[18] in an x86-32 machine ?
Quoted 2 lines
I can not see this possible-only-in-my-mind overflow happens in SLUB as it just delegate the work to the page allocator if size >
PAGE_SIZE.
Yeah, it is a big rough around the edges ;) I have fixed this up.
Quoted 11 lines
Quoted 11 lines
include/linux/slqb_def.h new file +11
-0+#ifdef CONFIG_NUMA +void *__kmalloc_node (size_t size,gfp_t flags,int node); +void *kmem_cache_alloc_node (struct kmem_cache *,gfp_t flags,int node); + +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) +{ +if (__builtin_constant_p (size)) { +if (likely (!(flags &SLQB_DMA ))) { +struct kmem_cache *s =kmalloc_slab (size); +if (!s) +return ZERO_SIZE_PTR ;
Quoted 8 lines
include/linux/slqb_def.h line 261
Quoted 5 lines
include/linux/slqb_def.h new file +5
-0+return kmem_cache_alloc_node (s, flags, node); + } + } +return __kmalloc_node (size, flags, node); +}Why this compile-time/run-time divide although both kmem_cache_alloc{,_node} and __kmalloc{,_node} call
slab_alloc()at the end ?
Constant size is by far the most common case, and so the kmalloc slab should actually be able to be found by the compiler in that case.
Quoted 11 lines
Quoted 11 lines
include/linux/slqb_def.h new file +3
-0+#endif + +#endif /* _LINUX_SLQB_DEF_H */ Index: linux-2.6/init/Kconfig
===================================================================init/Kconfig +0
-0@@ -701,6 +701,11 @@ config SLUB_DEBUG SLUB sysfs support. /sys/slab will not exist and there will be no support for cache validation etc.
Quoted 8 lines
init/Kconfig config SLUB_DEBUG · line 708
Quoted 5 lines
init/Kconfig +5
-0+config SLQB_DEBUG + default y + bool "Enable SLQB debugging support" + depends on SLQB +Maybe if SLQB got merged it can just be easier to have a general
SLAB_DEBUGoption that is recognized by the current 4 slab allocators ?
Could be an idea.
Quoted 5 lines
init/Kconfig config SLUB_DEBUG · line 711
Quoted 3 lines
init/Kconfig +3
-0+ * SLIB assigns one slab for allocation to each processor. + * Allocations only occur from these slabs called cpu slabs. + *SLQB is a much more better name than SLIB :).
Right! I experimented ;)
Quoted 41 lines
Quoted 11 lines
+ * Slabs with free elements are kept on a partial list and during regular
+ * operations no list for full slabs is used. If an object in a full slab is
+ * freed then the slab will show up again on the partial lists.
+ * We track full slabs for debugging purposes though because otherwise we
+ * cannot scan all objects.
+ *
+ * Slabs are freed when they become empty. Teardown and setup is
+ * minimal so we rely on the page allocators per cpu caches for
+ * fast frees and allocs.
+ */
+Ok, I admit I didn't do my homework yet of fully understanding the diff between SLUB and SLQB except in the
kmalloc(> PAGE_SIZE)case. I hope my understanding will get better soon....
Quoted 10 lines
init/Kconfig +10
-0+/* + * Slow path. The lockless freelist is empty or we need to perform + * debugging duties. + * + * Interrupts are disabled. + * + * Processing is still very fast if new objects have been freed to the + * regular freelist. In that case we simply take over the regular freelist + * as the lockless freelist and zap the regular freelist. + *init/Kconfig
Quoted 10 lines
init/Kconfig +10
-0+ * If that is not working then we fall back to the partial lists. We take the + * first element of the freelist as the object to allocate now and move the + * rest of the freelist to the lockless freelist. + * + * And if we were unable to get a new slab from the partial slab lists then + * we need to allocate a new slab. This is slowest path since we may sleep. + */ +static __always_inline void *__slab_alloc(struct kmem_cache *s, + gfp_t gfpflags, int node, void *addr) +{
__slab_allocistelf is not the slow-path, but the slow path begins from thealloc_new: label, right ?
Quoted 2 lines
If so, then IMHO the comment is a bit misleading since it gives the impression that the whole
__slab_alloc()is the slow path.
Oh. Yeah the comments are going to be all wrong, sorry. Ignore them and stick to the code.
Thanks,
Nick
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Nick Piggin
Quoted 3 lines
A small question for SLUB devs, would you accept a patch that does a similar thing by creating '
slub_page' instead of stuffing slub elements (freelist, inuse, ..) in 'mm_types::structpage' unions ?I'd like to see that. I have a patch for SLUB, actually.
We could do that but then how do we make sure that both definitions stay in sync? So far I have thought that it is clearer if we have one def that shows how objects are overloaded.
There is also the overloading of page flags that is now done separately in SLUB. I wonder if that needs to be moved into page-flags.h? Would clarify how page flags are overloaded.
If someone inspects the contents of a page struct via debug then it would help if all the possible uses are in one place. If the stuff in tucked away in mm/sl?b.c then its difficult to find.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 15 lines · Christoph Lameter
Quoted 5 lines · Nick Piggin
Quoted 3 lines
A small question for SLUB devs, would you accept a patch that does a similar thing by creating '
slub_page' instead of stuffing slub elements (freelist, inuse, ..) in 'mm_types::structpage' unions ?I'd like to see that. I have a patch for SLUB, actually.
We could do that but then how do we make sure that both definitions stay in sync?
So far I have thought that it is clearer if we have one def that shows how objects are overloaded.
Quoted 7 lines
There is also the overloading of page flags that is now done separately in SLUB. I wonder if that needs to be moved into
page-flags.h? Would clarify how page flags are overloaded.If someone inspects the contents of a page struct via debug then it would help if all the possible uses are in one place. If the stuff in tucked away in mm/sl?b.c then its difficult to find.
If you are not debugging sl?b.c code/pages, then why would you want to see what those fields are?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · Nick Piggin
If you are not debugging sl?b.c code/pages, then why would you want to see what those fields are?
Because you are f.e. inspecting a core dump and want to see why certain fields have certain values to verify that the structures were not overwrittten or corrupted etc.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Christoph Lameter
Quoted 2 lines · Nick Piggin
If you are not debugging sl?b.c code/pages, then why would you want to see what those fields are?
Because you are f.e. inspecting a core dump and want to see why certain fields have certain values to verify that the structures were not overwrittten or corrupted etc.
But overloading struct page values happens in other places too. Putting everything into struct page is not scalable. We could also make kmalloc return not a void pointer put a pointer to a union of every possible structure that kmalloc may ever be used for, just in case we have to inspect some data structure that could have been overwritten by something else ;)
But seriously... you can always cast a page to a slub_page to see if it is unexpectedly a slub page.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · Nick Piggin
But overloading struct page values happens in other places too. Putting everything into struct page is not scalable. We could also make kmalloc
Well lets at least attempt to catch the biggest users. Also makes code clearer if you f.e. use page->first_page instead of page->private for compound pages.
kmalloc is intended to return an arbitrary type. struct page has a defined format that needs to be respected.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · Christoph Lameter
Quoted 2 lines · Nick Piggin
But overloading struct page values happens in other places too. Putting everything into struct page is not scalable. We could also make kmalloc
Well lets at least attempt to catch the biggest users.
You want to also put slab and slob in there? What about page allocator? It is ridiculous for the sake of "being easy to inspect with debuggers". How hard is (struct slub_page *) to type?
Here is a real benefit you get with clearly defined types for struct
page: type checking.
Quoted 3 lines
Also makes code
clearer if you f.e. usepage->first_pageinstead ofpage->privatefor compound pages.
compound_page_head() is fine too.
Quoted 2 lines
kmalloc is intended to return an arbitrary type. struct page has a defined format that needs to be respected.
So does kmalloc if you take the union of all types it might possibly be used as.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>