Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [00/20] Sl[auo]b: Common code rework V11

Patches refreshed.

V10->V11
- Fix issues pointed out by Joonsoo and Glauber
- Simplify Slab bootstrap further

V9->V10
- Memory leak was a false alarm
- Resequence patches to make it easier
  to apply.
- Do more boot sequence consolidation in slab/slub.
  [We could still do much more like common kmalloc
  handling]
- Fixes suggested by David and Glauber

V8->V9:
- Fix numerous things pointed out by Glauber.
- Cleanup the way error handling works in the
  common kmem_cache_create() function.
- General cleanup by breaking things up
  into multiple patches were necessary.

V7->V8:
- Do not use kfree for kmem_cache in slub.
- Add more patches up to a common
  scheme for object alignment.

V6->V7:
- Omit pieces that were merged for 3.6
- Fix issues pointed out by Glauber.
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [08/20] Move freeing of kmem_cache structure to common code

The freeing action is basically the same in all slab allocators.
Move to the common kmem_cache_destroy() function.

Reviewed-by: Joonsoo Kim <js1304 <at> gmail.com>
Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slab.c        |    1 -
 mm/slab_common.c |    1 +
 mm/slob.c        |    2 --
 mm/slub.c        |    1 -
 4 files changed, 1 insertion(+), 4 deletions(-)

Index: linux-2.6/mm/slab_common.c
===================================================================
--- linux-2.6.orig/mm/slab_common.c	2012-08-03 09:02:43.432389623 -0500
+++ linux-2.6/mm/slab_common.c	2012-08-03 09:02:44.064400579 -0500
 <at>  <at>  -144,6 +144,7  <at>  <at>  void kmem_cache_destroy(struct kmem_cach
 				rcu_barrier();

 			__kmem_cache_destroy(s);
+			kmem_cache_free(kmem_cache, s);
 		} else {
 			list_add(&s->list, &slab_caches);
 			printk(KERN_ERR "kmem_cache_destroy %s: Slab cache still has objects\n",
Index: linux-2.6/mm/slob.c
===================================================================
--- linux-2.6.orig/mm/slob.c	2012-08-03 09:02:43.436389695 -0500
+++ linux-2.6/mm/slob.c	2012-08-03 09:02:44.064400579 -0500
 <at>  <at>  -540,8 +540,6  <at>  <at>  struct kmem_cache *__kmem_cache_create(c
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [04/20] Improve error handling in kmem_cache_create

Instead of using s == NULL use an errorcode. This allows much more
detailed diagnostics as to what went wrong. As we add more functionality
from the slab allocators to the common kmem_cache_create() function we will
also add more error conditions.

Print the error code during the panic as well as in a warning if the module
can handle failure. The API for kmem_cache_create() currently does not allow
the returning of an error code. Return NULL but log the cause of the problem
in the syslog.

Acked-by: David Rientjes <rientjes <at> google.com>
Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/mm/slab_common.c
===================================================================
--- linux-2.6.orig/mm/slab_common.c	2012-08-02 14:00:41.547674458 -0500
+++ linux-2.6/mm/slab_common.c	2012-08-02 14:21:07.061676525 -0500
 <at>  <at>  -51,13 +51,13  <at>  <at> 
 struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align,
 		unsigned long flags, void (*ctor)(void *))
 {
-	struct kmem_cache *s = NULL;
+	struct kmem_cache *s;
+	int err = 0;

 #ifdef CONFIG_DEBUG_VM
 	if (!name || in_interrupt() || size < sizeof(void *) ||
 		size > KMALLOC_MAX_SIZE) {
-		printk(KERN_ERR "kmem_cache_create(%s) integrity check"
-			" failed\n", name);
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [09/20] Get rid of __kmem_cache_destroy

What is done there can be done in __kmem_cache_shutdown.

This affects RCU handling somewhat. On rcu free all slab allocators
do not refer to other management structures than the kmem_cache structure.
Therefore these other structures can be freed before the rcu deferred
free to the page allocator occurs.

Reviewed-by: Joonsoo Kim <js1304 <at> gmail.com>
Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slab.c        |   43 +++++++++++++++++++++----------------------
 mm/slab.h        |    1 -
 mm/slab_common.c |    1 -
 mm/slob.c        |    4 ----
 mm/slub.c        |   10 +++++-----
 5 files changed, 26 insertions(+), 33 deletions(-)

Index: linux-2.6/mm/slob.c
===================================================================
--- linux-2.6.orig/mm/slob.c	2012-08-08 09:54:14.412139056 -0500
+++ linux-2.6/mm/slob.c	2012-08-09 08:52:56.767926051 -0500
 <at>  <at>  -538,10 +538,6  <at>  <at>  struct kmem_cache *__kmem_cache_create(c
 	return c;
 }

-void __kmem_cache_destroy(struct kmem_cache *c)
-{
-}
-
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [13/20] Move kmem_cache allocations into common code.

Shift the allocations to common code. That way the allocation
and freeing of the kmem_cache structures is handled by common code.

V2->V3: Use GFP_KERNEL instead of GFP_NOWAIT (JoonSoo Kim).
V1->V2: Use the return code from setup_cpucache() in slab instead of returning -ENOSPC

Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/mm/slab.c
===================================================================
--- linux-2.6.orig/mm/slab.c	2012-08-08 12:56:08.517806807 -0500
+++ linux-2.6/mm/slab.c	2012-08-08 12:56:19.405836235 -0500
 <at>  <at>  -1673,7 +1673,8  <at>  <at>  void __init kmem_cache_init(void)
 	 * bug.
 	 */

-	sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
+	sizes[INDEX_AC].cs_cachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
+	__kmem_cache_create(sizes[INDEX_AC].cs_cachep, names[INDEX_AC].name,
 					sizes[INDEX_AC].cs_size,
 					ARCH_KMALLOC_MINALIGN,
 					ARCH_KMALLOC_FLAGS|SLAB_PANIC,
 <at>  <at>  -1681,8 +1682,8  <at>  <at>  void __init kmem_cache_init(void)

 	list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
 	if (INDEX_AC != INDEX_L3) {
-		sizes[INDEX_L3].cs_cachep =
-			__kmem_cache_create(names[INDEX_L3].name,
+		sizes[INDEX_L3].cs_cachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
+		__kmem_cache_create(sizes[INDEX_L3].cs_cachep, names[INDEX_L3].name,
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [05/20] Move list_add() to slab_common.c

Move the code to append the new kmem_cache to the list of slab caches to
the kmem_cache_create code in the shared code.

This is possible now since the acquisition of the mutex was moved into
kmem_cache_create().

V1->V2:
	- SLOB: Add code to remove the slab from list
	 (will be removed a couple of patches down when we also move the
	 list_del to common code).

Acked-by: David Rientjes <rientjes <at> google.com>
Reviewed-by: Glauber Costa <glommer <at> parallels.com>
Reviewed-by: Joonsoo Kim <js1304 <at> gmail.com>
Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slab.c        |    7 +++++--
 mm/slab_common.c |    7 +++++++
 mm/slub.c        |    2 --
 3 files changed, 12 insertions(+), 4 deletions(-)

Index: linux-2.6/mm/slab_common.c
===================================================================
--- linux-2.6.orig/mm/slab_common.c	2012-08-08 09:45:01.039150037 -0500
+++ linux-2.6/mm/slab_common.c	2012-08-08 09:45:02.847153178 -0500
 <at>  <at>  -96,6 +96,13  <at>  <at>  struct kmem_cache *kmem_cache_create(con
 	if (!s)
 		err = -ENOSYS; /* Until __kmem_cache_create returns code */

(Continue reading)

JoonSoo Kim | 14 Aug 2012 20:43
Picon

Re: Common11r [05/20] Move list_add() to slab_common.c

2012/8/9 Christoph Lameter <cl <at> linux.com>:
> Move the code to append the new kmem_cache to the list of slab caches to
> the kmem_cache_create code in the shared code.
>
> This is possible now since the acquisition of the mutex was moved into
> kmem_cache_create().
>
> V1->V2:
>         - SLOB: Add code to remove the slab from list
>          (will be removed a couple of patches down when we also move the
>          list_del to common code).

There is no code for "SLOB: Add code to remove the slab from list"

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo <at> kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont <at> kvack.org"> email <at> kvack.org </a>

Christoph Lameter | 14 Aug 2012 22:24
Picon

Re: Common11r [05/20] Move list_add() to slab_common.c

On Wed, 15 Aug 2012, JoonSoo Kim wrote:

> 2012/8/9 Christoph Lameter <cl <at> linux.com>:
> > Move the code to append the new kmem_cache to the list of slab caches to
> > the kmem_cache_create code in the shared code.
> >
> > This is possible now since the acquisition of the mutex was moved into
> > kmem_cache_create().
> >
> > V1->V2:
> >         - SLOB: Add code to remove the slab from list
> >          (will be removed a couple of patches down when we also move the
> >          list_del to common code).
>
> There is no code for "SLOB: Add code to remove the slab from list

Seems to have fallen through the cracks when the patches were rearranged.

Updated version (which also requires the next patch to be refreshed).
See the git tree at

	git://gentwo.org/christoph common

for the full update.

Subject: Move list_add() to slab_common.c

Move the code to append the new kmem_cache to the list of slab caches to
the kmem_cache_create code in the shared code.

(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [12/20] Move sysfs_slab_add to common

Simplify locking by moving the slab_add_sysfs after all locks
have been dropped. Eases the upcoming move to provide sysfs
support for all allocators.

Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/mm/slab.h
===================================================================
--- linux-2.6.orig/mm/slab.h	2012-08-08 10:01:43.620981188 -0500
+++ linux-2.6/mm/slab.h	2012-08-09 08:52:56.751925638 -0500
 <at>  <at>  -39,10 +39,13  <at>  <at>  struct kmem_cache *__kmem_cache_create(c
 #ifdef CONFIG_SLUB
 struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
 	size_t align, unsigned long flags, void (*ctor)(void *));
+extern int sysfs_slab_add(struct kmem_cache *s);
 #else
 static inline struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
 	size_t align, unsigned long flags, void (*ctor)(void *))
 { return NULL; }
+static inline int sysfs_slab_add(struct kmem_cache *s) { return 0; }
+
 #endif

 
Index: linux-2.6/mm/slab_common.c
===================================================================
--- linux-2.6.orig/mm/slab_common.c	2012-08-08 10:40:49.125818807 -0500
+++ linux-2.6/mm/slab_common.c	2012-08-09 08:52:56.779926362 -0500
 <at>  <at>  -140,6 +140,14  <at>  <at>  out:
 		return NULL;
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [11/20] Do slab aliasing call from common code

The slab aliasing logic causes some strange contortions in
slub. So add a call to deal with aliases to slab_common.c
but disable it for other slab allocators by providng stubs
that fail to create aliases.

Full general support for aliases will require additional
cleanup passes and more standardization of fields in
kmem_cache.

V1->V2:
	- Move kstrdup before kmem_cache_alias invocation.
	(JoonSoo Kim)

Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slab.h        |   10 ++++++++++
 mm/slab_common.c |   16 +++++++---------
 mm/slub.c        |   18 ++++++++++++------
 3 files changed, 29 insertions(+), 15 deletions(-)

Index: linux-2.6/mm/slab.h
===================================================================
--- linux-2.6.orig/mm/slab.h	2012-08-08 09:54:18.000000000 -0500
+++ linux-2.6/mm/slab.h	2012-08-09 08:53:10.104271149 -0500
 <at>  <at>  -36,6 +36,16  <at>  <at>  extern struct kmem_cache *kmem_cache;
 struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
 	size_t align, unsigned long flags, void (*ctor)(void *));

+#ifdef CONFIG_SLUB
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [01/20] slub: Add debugging to verify correct cache use on kmem_cache_free()

Add additional debugging to check that the objects is actually from the cache
the caller claims. Doing so currently trips up some other debugging code. It
takes a lot to infer from that what was happening.

V2: Only warn once. 

Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/mm/slub.c
===================================================================
--- linux-2.6.orig/mm/slub.c	2012-08-03 14:16:27.396663869 -0500
+++ linux-2.6/mm/slub.c	2012-08-03 14:16:38.664866880 -0500
 <at>  <at>  -2607,6 +2607,13  <at>  <at>  void kmem_cache_free(struct kmem_cache *

 	page = virt_to_head_page(x);

+	if (kmem_cache_debug(s) && page->slab != s) {
+		printk("kmem_cache_free: Wrong slab cache. %s but object"
+			" is from  %s\n", page->slab->name, s->name);
+		WARN_ON_ONCE(1);
+		return;
+	}
+
 	slab_free(s, page, x, _RET_IP_);

 	trace_kmem_cache_free(_RET_IP_, x);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo <at> kvack.org.  For more info on Linux MM,
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [17/20] create common functions for boot slab creation

Use a special function to create kmalloc caches and use that function in
SLAB and SLUB.

Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slab.c |   53 +++++++++++++++++++++++------------------------------
 1 file changed, 23 insertions(+), 30 deletions(-)

Index: linux-2.6/mm/slab.c
===================================================================
--- linux-2.6.orig/mm/slab.c	2012-08-08 14:33:32.438009523 -0500
+++ linux-2.6/mm/slab.c	2012-08-08 14:33:32.846012306 -0500
 <at>  <at>  -1681,23 +1681,13  <at>  <at>  void __init kmem_cache_init(void)
 	 * bug.
 	 */

-	sizes[INDEX_AC].cs_cachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
-	sizes[INDEX_AC].cs_cachep->name = names[INDEX_AC].name;
-	sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
-	sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
-	sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
-	__kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
-	list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
+	sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
+					sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);

-	if (INDEX_AC != INDEX_L3) {
-		sizes[INDEX_L3].cs_cachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
-		sizes[INDEX_L3].cs_cachep->name = names[INDEX_L3].name;
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [16/20] slab: Simplify bootstrap

The nodelists field in kmem_cache is pointing to the first unused
object in the array field when bootstrap is complete.

On boot we use a statically allocated array for that purpose.

A problem with the current approach is that the statically sized
kmem_cache structure can only contain NR_CPUS entries. If the number
of nodes plus the number of cpus is greater then we would overwrite
memory following the kmem_cache_boot definition.

Increase the size of the array field to ensure that also the node
pointers fit into the array field.

Once we do that we no longer need the kmem_cache_nodelists
array and we can then also simplify bootstrap.

Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/include/linux/slab_def.h
===================================================================
--- linux-2.6.orig/include/linux/slab_def.h	2012-08-08 14:29:24.524288560 -0500
+++ linux-2.6/include/linux/slab_def.h	2012-08-08 14:30:08.084595349 -0500
 <at>  <at>  -92,7 +92,7  <at>  <at>  struct kmem_cache {
 	 * is statically defined, so we reserve the max number of cpus.
 	 */
 	struct kmem_list3 **nodelists;
-	struct array_cache *array[NR_CPUS];
+	struct array_cache *array[NR_CPUS + MAX_NUMNODES];
 	/*
 	 * Do not add fields after array[]
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [10/20] Move duping of slab name to slab_common.c

Duping of the slabname has to be done by each slab. Moving this code
to slab_common avoids duplicate implementations.

With this patch we have common string handling for all slab allocators.
Strings passed to kmem_cache_create() are copied internally. Subsystems
can create temporary strings to create slab caches.

Slabs allocated in early states of bootstrap will never be freed (and those
can never be freed since they are essential to slab allocator operations).
During bootstrap we therefore do not have to worry about duping names.

Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slab_common.c |   24 +++++++++++++++++-------
 mm/slub.c        |    5 -----
 2 files changed, 17 insertions(+), 12 deletions(-)

Index: linux-2.6/mm/slab_common.c
===================================================================
--- linux-2.6.orig/mm/slab_common.c	2012-08-08 09:54:18.576146705 -0500
+++ linux-2.6/mm/slab_common.c	2012-08-08 09:54:31.016169589 -0500
 <at>  <at>  -54,6 +54,7  <at>  <at>  struct kmem_cache *kmem_cache_create(con
 {
 	struct kmem_cache *s;
 	int err = 0;
+	char *n;

 #ifdef CONFIG_DEBUG_VM
 	if (!name || in_interrupt() || size < sizeof(void *) ||
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [03/20] Rename oops label

The label is actually used for successful exits so change the name.
Easy to do now before more users of this label surface.

Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/mm/slab_common.c
===================================================================
--- linux-2.6.orig/mm/slab_common.c	2012-08-02 09:18:07.570384286 -0500
+++ linux-2.6/mm/slab_common.c	2012-08-02 09:18:53.311194644 -0500
 <at>  <at>  -89,7 +89,7  <at>  <at> 
 				name);
 			dump_stack();
 			s = NULL;
-			goto oops;
+			goto out_locked;
 		}
 	}

 <at>  <at>  -99,7 +99,7  <at>  <at> 
 	s = __kmem_cache_create(name, size, align, flags, ctor);

 #ifdef CONFIG_DEBUG_VM
-oops:
+out_locked:
 #endif
 	mutex_unlock(&slab_mutex);
 	put_online_cpus();

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [15/20] Move kmem_cache refcounting to common code

Get rid of the refcount stuff in the allocators and do that
part of kmem_cache management in the common code.

Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/mm/slab.c
===================================================================
--- linux-2.6.orig/mm/slab.c	2012-08-08 12:58:11.038137838 -0500
+++ linux-2.6/mm/slab.c	2012-08-08 13:04:01.267084197 -0500
 <at>  <at>  -2550,7 +2550,6  <at>  <at>  __kmem_cache_create (struct kmem_cache *
 		 */
 		BUG_ON(ZERO_OR_NULL_PTR(cachep->slabp_cache));
 	}
-	cachep->refcount = 1;

 	err = setup_cpu_cache(cachep, gfp);
 	if (err) {
Index: linux-2.6/mm/slab_common.c
===================================================================
--- linux-2.6.orig/mm/slab_common.c	2012-08-08 12:58:11.038137838 -0500
+++ linux-2.6/mm/slab_common.c	2012-08-08 13:04:01.271084210 -0500
 <at>  <at>  -110,11 +110,12  <at>  <at>  struct kmem_cache *kmem_cache_create(con
 		}

 		err = __kmem_cache_create(s, flags);
-		if (!err)
+		if (!err) {

+			s->refcount = 1;
 			list_add(&s->list, &slab_caches);
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [02/20] slub: Use kmem_cache for the kmem_cache structure

Do not use kmalloc() but kmem_cache_alloc() for the allocation
of the kmem_cache structures in slub.

Acked-by: David Rientjes <rientjes <at> google.com>
Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/mm/slub.c
===================================================================
--- linux-2.6.orig/mm/slub.c	2012-08-03 09:01:06.650720492 -0500
+++ linux-2.6/mm/slub.c	2012-08-03 09:01:23.583012476 -0500
 <at>  <at>  -213,7 +213,7  <at>  <at>  static inline int sysfs_slab_alias(struc
 static inline void sysfs_slab_remove(struct kmem_cache *s)
 {
 	kfree(s->name);
-	kfree(s);
+	kmem_cache_free(kmem_cache, s);
 }

 #endif
 <at>  <at>  -3962,7 +3962,7  <at>  <at>  struct kmem_cache *__kmem_cache_create(c
 	if (!n)
 		return NULL;

-	s = kmalloc(kmem_size, GFP_KERNEL);
+	s = kmem_cache_alloc(kmem_cache, GFP_KERNEL);
 	if (s) {
 		if (kmem_cache_open(s, n,
 				size, align, flags, ctor)) {
 <at>  <at>  -3979,7 +3979,7  <at>  <at>  struct kmem_cache *__kmem_cache_create(c
 			list_del(&s->list);
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [20/20] Common alignment code

Extract the code to do object alignment from the allocators.
Do the alignment calculations in slab_common so that the
__kmem_cache_create functions of the allocators do not have
to deal with alignment.

Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slab.c        |   22 +---------------------
 mm/slab.h        |    3 +++
 mm/slab_common.c |   30 +++++++++++++++++++++++++++++-
 mm/slob.c        |   11 -----------
 mm/slub.c        |   45 ++++++++-------------------------------------
 5 files changed, 41 insertions(+), 70 deletions(-)

Index: linux-2.6/mm/slab.c
===================================================================
--- linux-2.6.orig/mm/slab.c	2012-08-08 15:35:59.498657814 -0500
+++ linux-2.6/mm/slab.c	2012-08-08 15:37:08.031043824 -0500
 <at>  <at>  -2368,22 +2368,6  <at>  <at>  __kmem_cache_create (struct kmem_cache *
 		cachep->size &= ~(BYTES_PER_WORD - 1);
 	}

-	/* calculate the final buffer alignment: */
-
-	/* 1) arch recommendation: can be overridden for debug */
-	if (flags & SLAB_HWCACHE_ALIGN) {
-		/*
-		 * Default alignment: as specified by the arch code.  Except if
-		 * an object is really small, then squeeze multiple objects into
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [19/20] slab: Use the new create_boot_cache function to simplify bootstrap

Simplify setup and reduce code in kmem_cache_init(). This allows us to
get rid of initarray_cache as well as the manual setup code for
the kmem_cache and kmem_cache_node arrays during bootstrap.

We introduce a new bootstrap state "PARTIAL" for slab that signals the
creation of a kmem_cache boot cache.

V1->V2: Get rid of initarray_cache as well.

Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/mm/slab.c
===================================================================
--- linux-2.6.orig/mm/slab.c	2012-08-08 15:29:45.048490847 -0500
+++ linux-2.6/mm/slab.c	2012-08-08 15:35:59.498657814 -0500
 <at>  <at>  -579,8 +579,6  <at>  <at>  static struct cache_names __initdata cac
 #undef CACHE
 };

-static struct arraycache_init initarray_cache __initdata =
-    { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
 static struct arraycache_init initarray_generic =
     { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };

 <at>  <at>  -1591,12 +1589,9  <at>  <at>  static void setup_nodelists_pointer(stru
  */
 void __init kmem_cache_init(void)
 {
-	size_t left_over;
 	struct cache_sizes *sizes;
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [14/20] Shrink __kmem_cache_create() parameter lists

Do the initial settings of the fields in common code. This will allow
us to push more processing into common code later and improve readability.

Signed-off-by: Christoph Lameter <cl <at> linux.com>

Index: linux-2.6/mm/slab.h
===================================================================
--- linux-2.6.orig/mm/slab.h	2012-08-08 12:56:19.000000000 -0500
+++ linux-2.6/mm/slab.h	2012-08-08 12:58:11.038137838 -0500
 <at>  <at>  -33,8 +33,7  <at>  <at>  extern struct list_head slab_caches;
 extern struct kmem_cache *kmem_cache;

 /* Functions provided by the slab allocators */
-extern int __kmem_cache_create(struct kmem_cache *, const char *name,
-	size_t size, size_t align, unsigned long flags, void (*ctor)(void *));
+extern int __kmem_cache_create(struct kmem_cache *, unsigned long flags);

 #ifdef CONFIG_SLUB
 struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
Index: linux-2.6/mm/slab_common.c
===================================================================
--- linux-2.6.orig/mm/slab_common.c	2012-08-08 12:56:19.000000000 -0500
+++ linux-2.6/mm/slab_common.c	2012-08-08 12:58:11.038137838 -0500
 <at>  <at>  -54,7 +54,6  <at>  <at>  struct kmem_cache *kmem_cache_create(con
 {
 	struct kmem_cache *s;
 	int err = 0;
-	char *n;

 #ifdef CONFIG_DEBUG_VM
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [18/20] slub: Use a statically allocated kmem_cache boot structure for bootstrap

Simplify bootstrap by statically allocated two kmem_cache structures. These are
freed after bootup is complete. Allows us to no longer worry about calculations
of sizes of kmem_cache structures during bootstrap.

Reviewed-by: Glauber Costa <glommer <at> parallels.com>
Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slub.c |   32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)

Index: linux-2.6/mm/slub.c
===================================================================
--- linux-2.6.orig/mm/slub.c	2012-08-08 14:33:38.738052474 -0500
+++ linux-2.6/mm/slub.c	2012-08-08 14:41:00.520972896 -0500
 <at>  <at>  -3635,9 +3635,6  <at>  <at>  static void __init kmem_cache_bootstrap_
 {
 	int node;

-	list_add(&s->list, &slab_caches);
-	s->refcount = -1;
-
 	for_each_node_state(node, N_NORMAL_MEMORY) {
 		struct kmem_cache_node *n = get_node(s, node);
 		struct page *p;
 <at>  <at>  -3654,13 +3651,13  <at>  <at>  static void __init kmem_cache_bootstrap_
 	}
 }

+static __initdata struct kmem_cache boot_kmem_cache,
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [06/20] Extract a common function for kmem_cache_destroy

kmem_cache_destroy does basically the same in all allocators.

Extract common code which is easy since we already have common mutex handling.

V1-V2:
	- Move percpu freeing to later so that we fail cleaner if
		objects are left in the cache [JoonSoo Kim]

Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slab.c        |   55 +++----------------------------------------------------
 mm/slab.h        |    3 +++
 mm/slab_common.c |   25 +++++++++++++++++++++++++
 mm/slob.c        |   11 +++++++----
 mm/slub.c        |   35 +++++++++++------------------------
 5 files changed, 49 insertions(+), 80 deletions(-)

Index: linux-2.6/mm/slab_common.c
===================================================================
--- linux-2.6.orig/mm/slab_common.c	2012-08-08 09:45:02.000000000 -0500
+++ linux-2.6/mm/slab_common.c	2012-08-09 08:53:39.045016801 -0500
 <at>  <at>  -130,6 +130,31  <at>  <at>  out:
 }
 EXPORT_SYMBOL(kmem_cache_create);

+void kmem_cache_destroy(struct kmem_cache *s)
+{
+	get_online_cpus();
+	mutex_lock(&slab_mutex);
(Continue reading)

Christoph Lameter | 9 Aug 2012 15:56
Picon

Common11r [07/20] Always use the name "kmem_cache" for the slab cache with the kmem_cache structure.

Make all allocators use the "kmem_cache" slabname for the "kmem_cache" structure.

Reviewed-by: Glauber Costa <glommer <at> parallels.com>
Reviewed-by: Joonsoo Kim <js1304 <at> gmail.com>
Signed-off-by: Christoph Lameter <cl <at> linux.com>

---
 mm/slab.c        |   72 ++++++++++++++++++++++++++++---------------------------
 mm/slab.h        |    6 ++++
 mm/slab_common.c |    1 
 mm/slob.c        |    9 ++++++
 mm/slub.c        |    2 -
 5 files changed, 52 insertions(+), 38 deletions(-)

Index: linux-2.6/mm/slab.c
===================================================================
--- linux-2.6.orig/mm/slab.c	2012-08-02 14:11:00.322806409 -0500
+++ linux-2.6/mm/slab.c	2012-08-02 14:11:04.186875599 -0500
 <at>  <at>  -585,9 +585,9  <at>  <at> 
     { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };

 /* internal cache of cache description objs */
-static struct kmem_list3 *cache_cache_nodelists[MAX_NUMNODES];
-static struct kmem_cache cache_cache = {
-	.nodelists = cache_cache_nodelists,
+static struct kmem_list3 *kmem_cache_nodelists[MAX_NUMNODES];
+static struct kmem_cache kmem_cache_boot = {
+	.nodelists = kmem_cache_nodelists,
 	.batchcount = 1,
 	.limit = BOOT_CPUCACHE_ENTRIES,
(Continue reading)

Christoph Lameter | 14 Aug 2012 17:48
Picon

Re: Common11r [00/20] Sl[auo]b: Common code rework V11

I put all of this in git and will keep it up to date vs tree changes in
Linus's tree.

Do a

git pull git://gentwo.org/christoph commmon

to get the latest rev.

There is also a gitweb to browse the stuff at http::/gentwo.org/gitweb

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo <at> kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont <at> kvack.org"> email <at> kvack.org </a>


Gmane