mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: mel@skynet.ie (Mel Gorman)
To: Paul Jackson <pj@sgi.com>
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org, haveblue@us.ibm.com,
	apw@shadowen.org, ak@muc.de, benh@kernel.crashing.org,
	paulus@samba.org, kmannth@gmail.com, tony.luck@intel.com,
	kamezawa.hiroyu@jp.fujitsu.com, y-goto@jp.fujitsu.com
Subject: [PATCH] Fix memmap accounting by approximating the map size
Date: Thu, 7 Sep 2006 15:27:44 +0100	[thread overview]
Message-ID: <20060907142744.GA31799@skynet.ie> (raw)
In-Reply-To: <Pine.LNX.4.64.0609071502001.31287@skynet.skynet.ie>

Arch-independent zone-sizing uses account_memmap() in an attempt to accurately
account for how much memory was used in a zone by memmap.  Watermarks and
per-cpu sizes initialisations then take the memmap into account. However,
the memmap may span multiple zones and in one case, there was an underflow
causing boot failures.

The fix that perfectly accounts for memory consumed by memmap is complicated
with no clear benefit. The architecture-specific code in x86_64 was simpler
because it approximated how much memory was consumed for memmap backing that
zone regardless of where the memmap was really stored.

This patch ditches the account_memmap() complexity and replaces with the
simple approximation used by x86_64 while ensuring no underflow occurs.

Signed-off-by: Mel Gorman <mel@csn.ul.ie>

diff -rup -X /usr/src/patchset-0.6/bin//dontdiff linux-2.6.18-rc4-mm3-clean/mm/page_alloc.c linux-2.6.18-rc4-mm3-101_fix_account_memmap/mm/page_alloc.c
--- linux-2.6.18-rc4-mm3-clean/mm/page_alloc.c	2006-08-28 15:05:30.000000000 +0100
+++ linux-2.6.18-rc4-mm3-101_fix_account_memmap/mm/page_alloc.c	2006-09-07 14:36:05.000000000 +0100
@@ -2364,58 +2364,6 @@ static void __init calculate_node_totalp
 							realtotalpages);
 }
 
-#ifdef CONFIG_FLAT_NODE_MEM_MAP
-/* Account for mem_map for CONFIG_FLAT_NODE_MEM_MAP */
-unsigned long __meminit account_memmap(struct pglist_data *pgdat,
-						int zone_index)
-{
-	unsigned long pages = 0;
-	if (zone_index == memmap_zone_idx(pgdat->node_mem_map)) {
-		pages = pgdat->node_spanned_pages;
-		pages = (pages * sizeof(struct page)) >> PAGE_SHIFT;
-		printk(KERN_DEBUG "%lu pages used for memmap\n", pages);
-	}
-	return pages;
-}
-#else
-/* Account for mem_map for CONFIG_SPARSEMEM */
-unsigned long account_memmap(struct pglist_data *pgdat, int zone_index)
-{
-	unsigned long pages = 0;
-	unsigned long memmap_pfn;
-	struct page *memmap_addr;
-	int pnum;
-	unsigned long pgdat_startpfn, pgdat_endpfn;
-	struct mem_section *section;
-
-	pgdat_startpfn = pgdat->node_start_pfn;
-	pgdat_endpfn = pgdat_startpfn + pgdat->node_spanned_pages;
-
-	/* Go through valid sections looking for memmap */
-	for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
-		if (!valid_section_nr(pnum))
-			continue;
-
-		section = __nr_to_section(pnum);
-		if (!section_has_mem_map(section))
-			continue;
-
-		memmap_addr = __section_mem_map_addr(section);
-		memmap_pfn = (unsigned long)memmap_addr >> PAGE_SHIFT;
-
-		if (memmap_pfn < pgdat_startpfn || memmap_pfn >= pgdat_endpfn)
-			continue;
-
-		if (zone_index == memmap_zone_idx(memmap_addr))
-			pages += (PAGES_PER_SECTION * sizeof(struct page));
-	}
-
-	pages >>= PAGE_SHIFT;
-	printk(KERN_DEBUG "%lu pages used for SPARSE memmap\n", pages);
-	return pages;
-}
-#endif
-
 /*
  * Set up the zone data structures:
  *   - mark all pages reserved
@@ -2437,17 +2385,32 @@ static void __meminit free_area_init_cor
 	
 	for (j = 0; j < MAX_NR_ZONES; j++) {
 		struct zone *zone = pgdat->node_zones + j;
-		unsigned long size, realsize;
+		unsigned long size, realsize, memmap_pages;
 
 		size = zone_spanned_pages_in_node(nid, j, zones_size);
 		realsize = size - zone_absent_pages_in_node(nid, j,
 								zholes_size);
 
-		realsize -= account_memmap(pgdat, j);
+		/*
+		 * Adjust realsize so that it accounts for how much memory
+		 * is used by this zone for memmap. This affects the watermark
+		 * and per-cpu initialisations
+		 */
+		memmap_pages = (size * sizeof(struct page)) >> PAGE_SHIFT;
+		if (realsize >= memmap_pages) {
+			realsize -= memmap_pages;
+			printk(KERN_DEBUG
+				"  %s zone: %lu pages used for memmap\n",
+				zone_names[j], memmap_pages);
+		} else
+			printk(KERN_WARNING
+				"  %s zone: %lu pages exceeds realsize %lu\n",
+				zone_names[j], memmap_pages, realsize);
+
 		/* Account for reserved DMA pages */
 		if (j == ZONE_DMA && realsize > dma_reserve) {
 			realsize -= dma_reserve;
-			printk(KERN_DEBUG "%lu pages DMA reserved\n",
+			printk(KERN_DEBUG "  DMA zone: %lu pages reserved\n",
 								dma_reserve);
 		}
 

  reply	other threads:[~2006-09-07 14:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-31 10:46 x86_64 account-for-memmap patch in 2.6.18-rc4-mm3 doesn't boot Paul Jackson
2006-08-31 16:17 ` Mel Gorman
2006-08-31 17:01   ` Paul Jackson
2006-09-01  8:38     ` Mel Gorman
2006-09-02  3:24       ` Paul Jackson
2006-09-04  9:45         ` Mel Gorman
2006-09-06 22:10           ` Paul Jackson
2006-09-07 14:16             ` Mel Gorman
2006-09-07 14:27               ` Mel Gorman [this message]
2006-09-07 15:33                 ` [PATCH] Fix memmap accounting by approximating the map size Paul Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060907142744.GA31799@skynet.ie \
    --to=mel@skynet.ie \
    --cc=ak@muc.de \
    --cc=akpm@osdl.org \
    --cc=apw@shadowen.org \
    --cc=benh@kernel.crashing.org \
    --cc=haveblue@us.ibm.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kmannth@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=pj@sgi.com \
    --cc=tony.luck@intel.com \
    --cc=y-goto@jp.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®