Commit 33f2ef89 authored by Andy Whitcroft's avatar Andy Whitcroft Committed by Linus Torvalds

[PATCH] mm: make compound page destructor handling explicit

Currently we we use the lru head link of the second page of a compound page
to hold its destructor.  This was ok when it was purely an internal
implmentation detail.  However, hugetlbfs overrides this destructor
violating the layering.  Abstract this out as explicit calls, also
introduce a type for the callback function allowing them to be type
checked.  For each callback we pre-declare the function, causing a type
error on definition rather than on use elsewhere.

[akpm@osdl.org: cleanups]
Signed-off-by: default avatarAndy Whitcroft <apw@shadowen.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 3c517a61
...@@ -295,6 +295,24 @@ void put_pages_list(struct list_head *pages); ...@@ -295,6 +295,24 @@ void put_pages_list(struct list_head *pages);
void split_page(struct page *page, unsigned int order); void split_page(struct page *page, unsigned int order);
/*
* Compound pages have a destructor function. Provide a
* prototype for that function and accessor functions.
* These are _only_ valid on the head of a PG_compound page.
*/
typedef void compound_page_dtor(struct page *);
static inline void set_compound_page_dtor(struct page *page,
compound_page_dtor *dtor)
{
page[1].lru.next = (void *)dtor;
}
static inline compound_page_dtor *get_compound_page_dtor(struct page *page)
{
return (compound_page_dtor *)page[1].lru.next;
}
/* /*
* Multiple processes may "see" the same page. E.g. for untouched * Multiple processes may "see" the same page. E.g. for untouched
* mappings of /dev/null, all processes see the same page full of * mappings of /dev/null, all processes see the same page full of
......
...@@ -109,7 +109,7 @@ static int alloc_fresh_huge_page(void) ...@@ -109,7 +109,7 @@ static int alloc_fresh_huge_page(void)
if (nid == MAX_NUMNODES) if (nid == MAX_NUMNODES)
nid = first_node(node_online_map); nid = first_node(node_online_map);
if (page) { if (page) {
page[1].lru.next = (void *)free_huge_page; /* dtor */ set_compound_page_dtor(page, free_huge_page);
spin_lock(&hugetlb_lock); spin_lock(&hugetlb_lock);
nr_huge_pages++; nr_huge_pages++;
nr_huge_pages_node[page_to_nid(page)]++; nr_huge_pages_node[page_to_nid(page)]++;
......
...@@ -230,7 +230,7 @@ static void prep_compound_page(struct page *page, unsigned long order) ...@@ -230,7 +230,7 @@ static void prep_compound_page(struct page *page, unsigned long order)
int i; int i;
int nr_pages = 1 << order; int nr_pages = 1 << order;
page[1].lru.next = (void *)free_compound_page; /* set dtor */ set_compound_page_dtor(page, free_compound_page);
page[1].lru.prev = (void *)order; page[1].lru.prev = (void *)order;
for (i = 0; i < nr_pages; i++) { for (i = 0; i < nr_pages; i++) {
struct page *p = page + i; struct page *p = page + i;
......
...@@ -57,9 +57,9 @@ static void put_compound_page(struct page *page) ...@@ -57,9 +57,9 @@ static void put_compound_page(struct page *page)
{ {
page = (struct page *)page_private(page); page = (struct page *)page_private(page);
if (put_page_testzero(page)) { if (put_page_testzero(page)) {
void (*dtor)(struct page *page); compound_page_dtor *dtor;
dtor = (void (*)(struct page *))page[1].lru.next; dtor = get_compound_page_dtor(page);
(*dtor)(page); (*dtor)(page);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment