2006-01-14 12:47:17

by Pekka Enberg

[permalink] [raw]
Subject: [patch 05/10] slab: extract slab_destroy_objs()

From: Matthew Dobson <[email protected]>

This patch creates a helper function, slab_destroy_objs() which called from
slab_destroy(). This makes slab_destroy() smaller and more readable, and moves
ifdefs outside the function body.

Signed-off-by: Matthew Dobson <[email protected]>
Acked-by: Manfred Spraul <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
---

mm/slab.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)

Index: 2.6/mm/slab.c
===================================================================
--- 2.6.orig/mm/slab.c
+++ 2.6/mm/slab.c
@@ -1456,15 +1456,13 @@ static void check_poison_obj(kmem_cache_
}
#endif

-/* Destroy all the objs in a slab, and release the mem back to the system.
- * Before calling the slab must have been unlinked from the cache.
- * The cache-lock is not held/needed.
+#if DEBUG
+/**
+ * slab_destroy_objs - call the registered destructor for each object in
+ * a slab that is to be destroyed.
*/
-static void slab_destroy(kmem_cache_t *cachep, struct slab *slabp)
+static void slab_destroy_objs(kmem_cache_t *cachep, struct slab *slabp)
{
- void *addr = slabp->s_mem - slabp->colouroff;
-
-#if DEBUG
int i;
for (i = 0; i < cachep->num; i++) {
void *objp = slabp->s_mem + cachep->buffer_size * i;
@@ -1493,7 +1491,10 @@ static void slab_destroy(kmem_cache_t *c
if (cachep->dtor && !(cachep->flags & SLAB_POISON))
(cachep->dtor) (objp + obj_offset(cachep), cachep, 0);
}
+}
#else
+static void slab_destroy_objs(kmem_cache_t *cachep, struct slab *slabp)
+{
if (cachep->dtor) {
int i;
for (i = 0; i < cachep->num; i++) {
@@ -1501,8 +1502,19 @@ static void slab_destroy(kmem_cache_t *c
(cachep->dtor) (objp, cachep, 0);
}
}
+}
#endif

+/**
+ * Destroy all the objs in a slab, and release the mem back to the system.
+ * Before calling the slab must have been unlinked from the cache.
+ * The cache-lock is not held/needed.
+ */
+static void slab_destroy(kmem_cache_t *cachep, struct slab *slabp)
+{
+ void *addr = slabp->s_mem - slabp->colouroff;
+
+ slab_destroy_objs(cachep, slabp);
if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU)) {
struct slab_rcu *slab_rcu;


--


2006-01-18 18:31:36

by Christoph Lameter

[permalink] [raw]
Subject: Re: [patch 05/10] slab: extract slab_destroy_objs()

On Sat, 14 Jan 2006, Pekka Enberg wrote:

> +static void slab_destroy_objs(kmem_cache_t *cachep, struct slab *slabp)

This is only called once right? Make this inline?

2006-01-19 09:07:22

by Pekka Enberg

[permalink] [raw]
Subject: Re: [patch 05/10] slab: extract slab_destroy_objs()

On Sat, 14 Jan 2006, Pekka Enberg wrote:
> > +static void slab_destroy_objs(kmem_cache_t *cachep, struct slab *slabp)

On Wed, 18 Jan 2006, Christoph Lameter wrote:
> This is only called once right? Make this inline?

We get better stack traces when its not inlined so I don't see the point.

Pekka

2006-01-20 17:09:09

by Horst H. von Brand

[permalink] [raw]
Subject: Re: [patch 05/10] slab: extract slab_destroy_objs()

Christoph Lameter <[email protected]> wrote:
> On Sat, 14 Jan 2006, Pekka Enberg wrote:
>
> > +static void slab_destroy_objs(kmem_cache_t *cachep, struct slab *slabp)
>
> This is only called once right? Make this inline?

Leave it to gcc. It might be called once today, and all over the place
tomorrow.

In any case, it can't be performance-critical.
--
Dr. Horst H. von Brand User #22616 counter.li.org
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513