Skip to content

Commit b49af68

Browse files
Christoph LameterLinus Torvalds
authored andcommitted
Add virt_to_head_page and consolidate code in slab and slub
Signed-off-by: Christoph Lameter <clameter@sgi.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6d77795 commit b49af68

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

include/linux/mm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ static inline void get_page(struct page *page)
286286
atomic_inc(&page->_count);
287287
}
288288

289+
static inline struct page *virt_to_head_page(const void *x)
290+
{
291+
struct page *page = virt_to_page(x);
292+
return compound_head(page);
293+
}
294+
289295
/*
290296
* Setup the page count before being freed into the page allocator for
291297
* the first time (boot or memory hotplug)

mm/slab.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,20 +614,19 @@ static inline void page_set_slab(struct page *page, struct slab *slab)
614614

615615
static inline struct slab *page_get_slab(struct page *page)
616616
{
617-
page = compound_head(page);
618617
BUG_ON(!PageSlab(page));
619618
return (struct slab *)page->lru.prev;
620619
}
621620

622621
static inline struct kmem_cache *virt_to_cache(const void *obj)
623622
{
624-
struct page *page = virt_to_page(obj);
623+
struct page *page = virt_to_head_page(obj);
625624
return page_get_cache(page);
626625
}
627626

628627
static inline struct slab *virt_to_slab(const void *obj)
629628
{
630-
struct page *page = virt_to_page(obj);
629+
struct page *page = virt_to_head_page(obj);
631630
return page_get_slab(page);
632631
}
633632

@@ -2876,7 +2875,7 @@ static void *cache_free_debugcheck(struct kmem_cache *cachep, void *objp,
28762875

28772876
objp -= obj_offset(cachep);
28782877
kfree_debugcheck(objp);
2879-
page = virt_to_page(objp);
2878+
page = virt_to_head_page(objp);
28802879

28812880
slabp = page_get_slab(page);
28822881

@@ -3100,7 +3099,7 @@ static void *cache_alloc_debugcheck_after(struct kmem_cache *cachep,
31003099
struct slab *slabp;
31013100
unsigned objnr;
31023101

3103-
slabp = page_get_slab(virt_to_page(objp));
3102+
slabp = page_get_slab(virt_to_head_page(objp));
31043103
objnr = (unsigned)(objp - slabp->s_mem) / cachep->buffer_size;
31053104
slab_bufctl(slabp)[objnr] = BUFCTL_ACTIVE;
31063105
}

mm/slub.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,9 +1323,7 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
13231323
{
13241324
struct page * page;
13251325

1326-
page = virt_to_page(x);
1327-
1328-
page = compound_head(page);
1326+
page = virt_to_head_page(x);
13291327

13301328
if (unlikely(PageError(page) && (s->flags & SLAB_STORE_USER)))
13311329
set_tracking(s, x, TRACK_FREE);
@@ -1336,7 +1334,7 @@ EXPORT_SYMBOL(kmem_cache_free);
13361334
/* Figure out on which slab object the object resides */
13371335
static struct page *get_object_page(const void *x)
13381336
{
1339-
struct page *page = compound_head(virt_to_page(x));
1337+
struct page *page = virt_to_head_page(x);
13401338

13411339
if (!PageSlab(page))
13421340
return NULL;
@@ -2076,7 +2074,7 @@ void kfree(const void *x)
20762074
if (!x)
20772075
return;
20782076

2079-
page = compound_head(virt_to_page(x));
2077+
page = virt_to_head_page(x);
20802078

20812079
s = page->slab;
20822080

@@ -2112,7 +2110,7 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags)
21122110
return NULL;
21132111
}
21142112

2115-
page = compound_head(virt_to_page(p));
2113+
page = virt_to_head_page(p);
21162114

21172115
new_cache = get_slab(new_size, flags);
21182116

0 commit comments

Comments
 (0)