Re: [PATCH 1/2] Make page->private usable in compound pages V1

From: Christoph Lameter
Date: Fri Apr 06 2007 - 15:46:58 EST


On Thu, 5 Apr 2007, Andrew Morton wrote:

> A new virt_to_head_page() is needed.

Add virt_to_head_page and consolidate code in slab and slub.

Signed-off-by: Christoph Lameter <clameter@xxxxxxx>

Index: linux-2.6.21-rc5-mm4/include/linux/mm.h
===================================================================
--- linux-2.6.21-rc5-mm4.orig/include/linux/mm.h 2007-04-06 19:35:51.000000000 +0000
+++ linux-2.6.21-rc5-mm4/include/linux/mm.h 2007-04-06 19:42:53.000000000 +0000
@@ -316,6 +316,12 @@
atomic_inc(&page->_count);
}

+static inline struct page *virt_to_head_page(const void *x)
+{
+ struct page *page = virt_to_page(x);
+ return compound_head(page);
+}
+
/*
* Setup the page count before being freed into the page allocator for
* the first time (boot or memory hotplug)
Index: linux-2.6.21-rc5-mm4/mm/slab.c
===================================================================
--- linux-2.6.21-rc5-mm4.orig/mm/slab.c 2007-04-06 19:38:58.000000000 +0000
+++ linux-2.6.21-rc5-mm4/mm/slab.c 2007-04-06 19:41:57.000000000 +0000
@@ -614,20 +614,19 @@

static inline struct slab *page_get_slab(struct page *page)
{
- page = compound_head(page);
BUG_ON(!PageSlab(page));
return (struct slab *)page->lru.prev;
}

static inline struct kmem_cache *virt_to_cache(const void *obj)
{
- struct page *page = virt_to_page(obj);
+ struct page *page = virt_to_head_page(obj);
return page_get_cache(page);
}

static inline struct slab *virt_to_slab(const void *obj)
{
- struct page *page = virt_to_page(obj);
+ struct page *page = virt_to_head_page(obj);
return page_get_slab(page);
}

@@ -2884,7 +2883,7 @@

objp -= obj_offset(cachep);
kfree_debugcheck(objp);
- page = virt_to_page(objp);
+ page = virt_to_head_page(objp);

slabp = page_get_slab(page);

@@ -3108,7 +3107,7 @@
struct slab *slabp;
unsigned objnr;

- slabp = page_get_slab(virt_to_page(objp));
+ slabp = page_get_slab(virt_to_head_page(objp));
objnr = (unsigned)(objp - slabp->s_mem) / cachep->buffer_size;
slab_bufctl(slabp)[objnr] = BUFCTL_ACTIVE;
}
Index: linux-2.6.21-rc5-mm4/mm/slub.c
===================================================================
--- linux-2.6.21-rc5-mm4.orig/mm/slub.c 2007-04-06 19:37:49.000000000 +0000
+++ linux-2.6.21-rc5-mm4/mm/slub.c 2007-04-06 19:38:56.000000000 +0000
@@ -1297,9 +1297,7 @@
{
struct page * page;

- page = virt_to_page(x);
-
- page = compound_head(page);
+ page = virt_to_head_page(x);

if (unlikely(PageError(page) && (s->flags & SLAB_STORE_USER)))
set_tracking(s, x, 1);
@@ -1310,7 +1308,7 @@
/* Figure out on which slab object the object resides */
static struct page *get_object_page(const void *x)
{
- struct page *page = compound_head(virt_to_page(x));
+ struct page *page = virt_to_head_page(x);

if (!PageSlab(page))
return NULL;
@@ -1952,7 +1950,7 @@
if (!x)
return;

- page = compound_head(virt_to_page(x));
+ page = virt_to_head_page(x);

s = page->slab;

@@ -1988,7 +1986,7 @@
return NULL;
}

- page = compound_head(virt_to_page(p));
+ page = virt_to_head_page(p);

new_cache = get_slab(new_size, flags);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/