2007-02-22 12:37:41

by Pekka Enberg

[permalink] [raw]
Subject: [PATCH] slab: remove colouroff from struct slab

From: Pekka Enberg <[email protected]>

As the color offset is always within the first page of the slab,
virt_to_page() works just fine without slabp->colouroff.

Cc: William Lee Irwin III <[email protected]>
Cc: Christoph Lameter <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
---
mm/slab.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

Index: 2.6/mm/slab.c
===================================================================
--- 2.6.orig/mm/slab.c 2007-02-22 13:51:41.000000000 +0200
+++ 2.6/mm/slab.c 2007-02-22 13:57:39.000000000 +0200
@@ -219,7 +219,6 @@
*/
struct slab {
struct list_head list;
- unsigned long colouroff;
void *s_mem; /* including colour offset */
unsigned int inuse; /* num of objs active in slab */
kmem_bufctl_t free;
@@ -1908,18 +1907,16 @@
*/
static void slab_destroy(struct kmem_cache *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;

slab_rcu = (struct slab_rcu *)slabp;
slab_rcu->cachep = cachep;
- slab_rcu->addr = addr;
+ slab_rcu->addr = slabp->s_mem;
call_rcu(&slab_rcu->head, kmem_rcu_free);
} else {
- kmem_freepages(cachep, addr);
+ kmem_freepages(cachep, slabp->s_mem);
if (OFF_SLAB(cachep))
kmem_cache_free(cachep->slabp_cache, slabp);
}
@@ -2585,7 +2582,6 @@
colour_off += cachep->slab_size;
}
slabp->inuse = 0;
- slabp->colouroff = colour_off;
slabp->s_mem = objp + colour_off;
slabp->nodeid = nodeid;
return slabp;


2007-02-23 14:00:40

by Christoph Lameter

[permalink] [raw]
Subject: Re: [PATCH] slab: remove colouroff from struct slab

On Thu, 22 Feb 2007, Pekka J Enberg wrote:

> As the color offset is always within the first page of the slab,
> virt_to_page() works just fine without slabp->colouroff.

True but then we pass an address to kmem_freepages that is not the start
of the page. kmem_freepages will then in turn call free_pages() with an
address that is not the start of a page. free_pages() will then do another
virt_to_page() which ignored the offset into the page again. And so the
approach works but an uneasy feeling remains since the address we got from
kmem_getpages() is different from what we pass to kmem_freepages().

Could you think about a way to do this in a cleaner way? Maybe use a
struct page * in both kmem_get/freepages? Or add some comment explaining
the situation?