public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH]Fix: Init page count for all pages during higher order allocs
@ 2002-04-29 14:54 Suparna Bhattacharya
  2002-04-29 17:40 ` Eric W. Biederman
  0 siblings, 1 reply; 13+ messages in thread
From: Suparna Bhattacharya @ 2002-04-29 14:54 UTC (permalink / raw)
  To: linux-kernel; +Cc: marcelo

The call to set_page_count(page, 1) in page_alloc.c appears to happen 
only for the first page, for order 1 and higher allocations.
This leaves the count for the rest of the pages in that block 
uninitialised.

We ran into this while working on some lkcd changes where we check
the page count to help exclude unreferenced pages, and found
that we were missing some referenced pages too (e.g the second page
of thread_info/stack pages which involve order 1 allocations)

Here is a patch from Bharata B. Rao that sets the page count 
for all the pages allocated. This is along the same lines
as the code in slab.c to issue SET_PAGE_CACHE/SET_PAGE_SLAB
on all the pages in an allocated block based on the slab order.
(That code seems to be preceded by a somewhat scary comment
 so hope there is nothing to be concerned about; are there 
 any caveats ? )

Comments ? 
Does this look like the right thing to do ?

Regards
Suparna

--- 2418-pure/mm/page_alloc.c	Tue Feb 26 01:08:14 2002
+++ linux-2.4.18+lkcd/mm/page_alloc.c	Mon Apr 29 14:16:37 2002
@@ -181,7 +181,7 @@
 static struct page * rmqueue(zone_t *zone, unsigned int order)
 {
 	free_area_t * area = zone->free_area + order;
-	unsigned int curr_order = order;
+	unsigned int i, curr_order = order;
 	struct list_head *head, *curr;
 	unsigned long flags;
 	struct page *page;
@@ -206,13 +206,18 @@
 			page = expand(zone, page, index, order, curr_order, area);
 			spin_unlock_irqrestore(&zone->lock, flags);
 
-			set_page_count(page, 1);
-			if (BAD_RANGE(zone,page))
-				BUG();
-			if (PageLRU(page))
-				BUG();
-			if (PageActive(page))
-				BUG();
+			i = 1UL << order;
+			page += i;
+			do {
+				page--;
+				set_page_count(page, 1);
+				if (BAD_RANGE(zone,page))
+					BUG();
+				if (PageLRU(page))
+					BUG();
+				if (PageActive(page))
+					BUG();
+			} while (--i);
 			return page;	
 		}
 		curr_order++;
@@ -236,6 +241,7 @@
 {
 	struct page * page = NULL;
 	int __freed = 0;
+	unsigned int i;
 
 	if (!(gfp_mask & __GFP_WAIT))
 		goto out;
@@ -264,25 +270,29 @@
 				if (tmp->index == order && memclass(tmp->zone, classzone)) {
 					list_del(entry);
 					current->nr_local_pages--;
-					set_page_count(tmp, 1);
-					page = tmp;
 
-					if (page->buffers)
-						BUG();
-					if (page->mapping)
-						BUG();
-					if (!VALID_PAGE(page))
-						BUG();
-					if (PageSwapCache(page))
-						BUG();
-					if (PageLocked(page))
-						BUG();
-					if (PageLRU(page))
-						BUG();
-					if (PageActive(page))
-						BUG();
-					if (PageDirty(page))
-						BUG();
+					i = 1UL << order;
+					page = tmp + i;
+					do {
+						page--;
+						set_page_count(page, 1);
+						if (page->buffers)
+							BUG();
+						if (page->mapping)
+							BUG();
+						if (!VALID_PAGE(page))
+							BUG();
+						if (PageSwapCache(page))
+							BUG();
+						if (PageLocked(page))
+							BUG();
+						if (PageLRU(page))
+							BUG();
+						if (PageActive(page))
+							BUG();
+						if (PageDirty(page))
+							BUG();
+					} while (--i);
 
 					break;
 				}

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2002-05-07 10:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-29 14:54 [PATCH]Fix: Init page count for all pages during higher order allocs Suparna Bhattacharya
2002-04-29 17:40 ` Eric W. Biederman
2002-04-30  5:31   ` Suparna Bhattacharya
2002-04-30 14:05     ` Eric W. Biederman
2002-04-30 15:08       ` Suparna Bhattacharya
2002-04-30 19:47     ` Andrew Morton
2002-05-02  8:54       ` Suparna Bhattacharya
2002-05-02 13:08         ` Hugh Dickins
2002-05-02 21:13           ` Daniel Phillips
2002-05-03 12:24           ` Suparna Bhattacharya
2002-05-03 13:46             ` Hugh Dickins
2002-05-07 10:11               ` Suparna Bhattacharya
2002-05-07  7:34         ` Bharata B Rao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox