Commit 6babc32c41e3642d875372cb6afbd9ade7a9f311

Authored by Andy Whitcroft
Committed by Linus Torvalds
1 parent 4b19de6d1c

mm: handle initialising compound pages at orders greater than MAX_ORDER

When we initialise a compound page we initialise the page flags and head
page pointer for all base pages spanned by that page.  When we initialise
a gigantic page (a page of order greater than or equal to MAX_ORDER) we
have to initialise more than MAX_ORDER_NR_PAGES pages.  Currently we
assume that all elements of the mem_map in this page are contigious in
memory.  However this is only guarenteed out to MAX_ORDER_NR_PAGES pages,
and with SPARSEMEM enabled they will not be contigious.  This leads us to
walk off the end of the first section and scribble on everything which
follows, BAD.

When we reach a MAX_ORDER_NR_PAGES boundary we much locate the next
section of the mem_map.  As gigantic pages can only be maximally aligned
we know this will occur at exact multiple of MAX_ORDER_NR_PAGES pages from
the start of the page.

This is a bug fix for the gigantic page support in hugetlbfs.

Credit to Mel Gorman for spotting the issue.

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Jon Tollefson <kniht@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 8 additions and 5 deletions Side-by-side Diff

... ... @@ -268,13 +268,14 @@
268 268 {
269 269 int i;
270 270 int nr_pages = 1 << order;
  271 + struct page *p = page + 1;
271 272  
272 273 set_compound_page_dtor(page, free_compound_page);
273 274 set_compound_order(page, order);
274 275 __SetPageHead(page);
275   - for (i = 1; i < nr_pages; i++) {
276   - struct page *p = page + i;
277   -
  276 + for (i = 1; i < nr_pages; i++, p++) {
  277 + if (unlikely((i & (MAX_ORDER_NR_PAGES - 1)) == 0))
  278 + p = pfn_to_page(page_to_pfn(page) + i);
278 279 __SetPageTail(p);
279 280 p->first_page = page;
280 281 }
... ... @@ -284,6 +285,7 @@
284 285 {
285 286 int i;
286 287 int nr_pages = 1 << order;
  288 + struct page *p = page + 1;
287 289  
288 290 if (unlikely(compound_order(page) != order))
289 291 bad_page(page);
... ... @@ -291,8 +293,9 @@
291 293 if (unlikely(!PageHead(page)))
292 294 bad_page(page);
293 295 __ClearPageHead(page);
294   - for (i = 1; i < nr_pages; i++) {
295   - struct page *p = page + i;
  296 + for (i = 1; i < nr_pages; i++, p++) {
  297 + if (unlikely((i & (MAX_ORDER_NR_PAGES - 1)) == 0))
  298 + p = pfn_to_page(page_to_pfn(page) + i);
296 299  
297 300 if (unlikely(!PageTail(p) |
298 301 (p->first_page != page)))