Skip to contentSkip to conversation

memory zone balancing

RFC PATCH In review Kanoj Sarcar 6 participants 11 messages Dec 15, 1999 – Jan 6, 2000

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 memory zone balancing

Hi,

Could people try out this patch against 2.3.33 and send comments/feedback.

The patch cleans up the way we do memory balancing in the core page alloc and free routines.

Thanks.

Kanoj

dcache.c renamed from usr/tmp/p_rdiff_a000os/dcache.c +1 -1
@@ -410,7 +410,7 @@
  *  ...
  *   6 - base-level: try to shrink a bit.
  */
-int shrink_dcache_memory(int priority, unsigned int gfp_mask)
+int shrink_dcache_memory(int priority, unsigned int gfp_mask, zone_t * zone)
 {
 	if (gfp_mask & __GFP_IO) {
 		int count = 0;
inode.c renamed from usr/tmp/p_rdiff_a000p1/inode.c +1 -1
@@ -392,7 +392,7 @@
 	dispose_list(freeable);
 }
 
-int shrink_icache_memory(int priority, int gfp_mask)
+int shrink_icache_memory(int priority, int gfp_mask, zone_t *zone)
 {
 	if (gfp_mask & __GFP_IO)
 	{
linux/dcache.h renamed from usr/tmp/p_rdiff_a000pA/dcache.h +3 -3
@@ -136,13 +136,13 @@
 extern int d_invalidate(struct dentry *);
 
 #define shrink_dcache() prune_dcache(0)
-
+struct zone_struct;
 /* dcache memory management */
-extern int shrink_dcache_memory(int, unsigned int);
+extern int shrink_dcache_memory(int, unsigned int, struct zone_struct *);
 extern void prune_dcache(int);
 
 /* icache memory management (defined in linux/fs/inode.c) */
-extern int shrink_icache_memory(int, int);
+extern int shrink_icache_memory(int, int, struct zone_struct *);
 extern void prune_icache(int);
 
 /* only used at mount-time */
linux/mm.h renamed from usr/tmp/p_rdiff_a000pJ/mm.h +2 -2
@@ -183,7 +183,6 @@
 #define ClearPageError(page)	clear_bit(PG_error, &(page)->flags)
 #define PageReferenced(page)	test_bit(PG_referenced, &(page)->flags)
 #define PageDecrAfter(page)	test_bit(PG_decr_after, &(page)->flags)
-#define PageDMA(page)		(contig_page_data.node_zones + ZONE_DMA == (page)->zone)
 #define PageSlab(page)		test_bit(PG_slab, &(page)->flags)
 #define PageSwapCache(page)	test_bit(PG_swap_cache, &(page)->flags)
 #define PageReserved(page)	test_bit(PG_reserved, &(page)->flags)
@@ -434,10 +433,11 @@
 extern int do_munmap(unsigned long, size_t);
 extern unsigned long do_brk(unsigned long, unsigned long);
 
+struct zone_t;
 /* filemap.c */
 extern void remove_inode_page(struct page *);
 extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int shrink_mmap(int, int, zone_t *);
 extern void truncate_inode_pages(struct inode *, loff_t);
 
 /*
linux/swap.h renamed from usr/tmp/p_rdiff_a000pS/swap.h +3 -2
@@ -78,14 +78,15 @@
 struct vm_area_struct;
 struct sysinfo;
 
+struct zone_t;
 /* linux/ipc/shm.c */
-extern int shm_swap (int, int);
+extern int shm_swap (int, int, zone_t *);
 
 /* linux/mm/swap.c */
 extern void swap_setup (void);
 
 /* linux/mm/vmscan.c */
-extern int try_to_free_pages(unsigned int gfp_mask);
+extern int try_to_free_pages(unsigned int gfp_mask, zone_t *zone);
 
 /* linux/mm/page_io.c */
 extern void rw_swap_page(int, struct page *, int);
shm.c renamed from usr/tmp/p_rdiff_a000p-/shm.c +2 -4
@@ -799,7 +799,7 @@
 static unsigned long swap_id = 0; /* currently being swapped */
 static unsigned long swap_idx = 0; /* next to swap */
 
-int shm_swap (int prio, int gfp_mask)
+int shm_swap (int prio, int gfp_mask, zone_t *zone)
 {
 	pte_t page;
 	struct shmid_kernel *shp;
@@ -849,9 +849,7 @@
 	if (!pte_present(page))
 		goto check_table;
 	page_map = pte_page(page);
-	if ((gfp_mask & __GFP_DMA) && !PageDMA(page_map))
-		goto check_table;
-	if (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page_map))
+	if (zone && (page_map->zone != zone))
 		goto check_table;
 	swap_attempts++;
 
util.c renamed from usr/tmp/p_rdiff_a000pi/util.c +1 -1
@@ -214,7 +214,7 @@
     return;
 }
 
-int shm_swap (int prio, int gfp_mask)
+int shm_swap (int prio, int gfp_mask, zone_t *zone)
 {
     return 0;
 }
filemap.c renamed from usr/tmp/p_rdiff_a000pr/filemap.c +2 -4
@@ -211,7 +211,7 @@
 	spin_unlock(&pagecache_lock);
 }
 
-int shrink_mmap(int priority, int gfp_mask)
+int shrink_mmap(int priority, int gfp_mask, zone_t *zone)
 {
 	int ret = 0, count;
 	LIST_HEAD(young);
@@ -239,9 +239,7 @@
 
 		dispose = &old;
 		/* don't account passes over not DMA pages */
-		if ((gfp_mask & __GFP_DMA) && !PageDMA(page))
-			goto dispose_continue;
-		if (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page))
+		if (zone && (page->zone != zone))
 			goto dispose_continue;
 
 		count--;
page_alloc.c renamed from usr/tmp/p_rdiff_a000q0/page_alloc.c +16 -16
@@ -224,7 +224,7 @@
 		return 1;
 
 	current->flags |= PF_MEMALLOC;
-	freed = try_to_free_pages(gfp_mask);
+	freed = try_to_free_pages(gfp_mask, zone);
 	current->flags &= ~PF_MEMALLOC;
 
 	if (!freed && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
@@ -264,7 +264,7 @@
 		return 1;
 
 	current->flags |= PF_MEMALLOC;
-	freed = try_to_free_pages(gfp_mask);
+	freed = try_to_free_pages(gfp_mask, 0);
 	current->flags &= ~PF_MEMALLOC;
 
 	if (!freed && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
@@ -340,7 +340,7 @@
  * The main chunk of the balancing code is in this offline branch:
  */
 balance:
-	if (!balance_memory(gfp_mask))
+	if (!zone_balance_memory(z, gfp_mask))
 		goto nopage;
 	goto ready;
 }
@@ -533,9 +533,9 @@
 		i = 10;
 	if (i > 256)
 		i = 256;
-	freepages.min = i;
-	freepages.low = i * 2;
-	freepages.high = i * 3;
+	freepages.min += i;
+	freepages.low += i * 2;
+	freepages.high += i * 3;
 
 	/*
 	 * Some architectures (with lots of mem and discontinous memory
@@ -565,10 +565,9 @@
 	offset = lmem_map - mem_map;	
 	for (j = 0; j < MAX_NR_ZONES; j++) {
 		zone_t *zone = pgdat->node_zones + j;
-		unsigned long mask = -1;
-		unsigned long size;
+		unsigned long mask, size;
 
-		size = zones_size[j];
+		mask = size = zones_size[j];
 
 		printk("zone(%ld): %ld pages.\n", j, size);
 		zone->size = size;
@@ -578,13 +577,13 @@
 			continue;
 
 		zone->offset = offset;
-		/*
-		 * It's unnecessery to balance the high memory zone
-		 */
-		if (j != ZONE_HIGHMEM) {
-			zone->pages_low = freepages.low;
-			zone->pages_high = freepages.high;
-		}
+		mask = mask >> 7;
+		if (mask < 10)
+			mask = 10;
+		if (mask > 256)
+			mask = 256;
+		zone->pages_low = mask * 2;
+		zone->pages_high = mask * 3;
 		zone->low_on_memory = 0;
 
 		for (i = 0; i < size; i++) {
@@ -597,6 +596,7 @@
 		}
 
 		offset += size;
+		mask = -1;
 		for (i = 0; i < MAX_ORDER; i++) {
 			unsigned long bitmap_size;
 
slab.c renamed from usr/tmp/p_rdiff_a000q9/slab.c +5 -12
@@ -503,6 +503,11 @@
 {
 	void	*addr;
 
+	/*
+	 * If we requested dmaable memory, we will get it. Even if we 
+	 * did not request dmaable memory, we might get it, but that
+	 * would be relatively rare and ignorable.
+	 */
 	*dma = flags & SLAB_DMA;
 	addr = (void*) __get_free_pages(flags, cachep->c_gfporder);
 	/* Assume that now we have the pages no one else can legally
@@ -511,18 +516,6 @@
 	 * it is a named-page or buffer-page.  The members it tests are
 	 * of no interest here.....
 	 */
-	if (!*dma && addr) {
-		/* Need to check if can dma. */
-		struct page *page = mem_map + MAP_NR(addr);
-		*dma = 1<<cachep->c_gfporder;
-		while ((*dma)--) {
-			if (!PageDMA(page)) {
-				*dma = 0;
-				break;
-			}
-			page++;
-		}
-	}
 	return addr;
 }
 
vmscan.c renamed from usr/tmp/p_rdiff_a000qI/vmscan.c +21 -22

161 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#1 lore raw
Quoted 3 lines · Kanoj Sarcar

Hi,

Could people try out this patch against 2.3.33 and send comments/feedback.

Works fine on my x86/UP/SCSI box. Subjectively, it feels smoother. (that could well be imagination at work)

-Mike

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#3 lore raw
In reply to Kanoj Sarcar
Quoted 19 lines · Kanoj Sarcar
shm.c renamed from usr/tmp/p_rdiff_a000p-/shm.c +1 -3
-	if ((gfp_mask & __GFP_DMA) && !PageDMA(page_map))
-		goto check_table;
-	if (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page_map))
+	if (zone && (page_map->zone != zone))
		goto check_table;
	swap_attempts++;

		/* don't account passes over not DMA pages */
filemap.c renamed from usr/tmp/p_rdiff_a000pr/filemap.c +1 -3
-		if ((gfp_mask & __GFP_DMA) && !PageDMA(page))
-			goto dispose_continue;
-		if (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page))
+		if (zone && (page->zone != zone))
			goto dispose_continue;

	if (PageReserved(page)
	    || PageLocked(page)
vmscan.c renamed from usr/tmp/p_rdiff_a000qI/vmscan.c +1 -2
-	    || ((gfp_mask & __GFP_DMA) && !PageDMA(page))
-	    || (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page)))
+	    || (zone && (page->zone != zone)))
Quoted 1 line
		goto out_failed;

The above changes you proposed will cause you to go oom even if you still have 16mbyte of pure (ISA-DMA) RAM free in a no-bigmem kernel. With a bigmem kernel you'll go OOM even if you still have 1giga of memory free.

As I just told you privately in previous email the checks should be a kind of ">" (or a more complex operation implemented in a function) and not a "!=".

Andrea

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.nl.linux.org/Linux-MM/

#4 lore raw
Quoted 29 lines · Kanoj Sarcar
Quoted 20 lines
(quoted diff) +1 -3
-	if ((gfp_mask & __GFP_DMA) && !PageDMA(page_map))
-		goto check_table;
-	if (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page_map))
+	if (zone && (page_map->zone != zone))
		goto check_table;
	swap_attempts++;

		/* don't account passes over not DMA pages */
(quoted diff) +1 -3
-		if ((gfp_mask & __GFP_DMA) && !PageDMA(page))
-			goto dispose_continue;
-		if (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page))
+		if (zone && (page->zone != zone))
			goto dispose_continue;

	if (PageReserved(page)
	    || PageLocked(page)
(quoted diff) +1 -2
-	    || ((gfp_mask & __GFP_DMA) && !PageDMA(page))
-	    || (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page)))
+	    || (zone && (page->zone != zone)))
Quoted 1 line
		goto out_failed;

The above changes you proposed will cause you to go oom even if you still have 16mbyte of pure (ISA-DMA) RAM free in a no-bigmem kernel. With a bigmem kernel you'll go OOM even if you still have 1giga of memory free.

Quoted 3 lines

As I just told you privately in previous email the checks should be a kind of ">" (or a more complex operation implemented in a function) and not a "!=".

Okay, here is a reworked version. Note that this version does not do per-zone balancing, since experiments show that we need to tune per-zone watermarks properly before we can start doing that. I am working on coming up with a good estimate of per-zone watermarks. Basically, I am trying to answer the question: if there are d dmapages, r regular pages and h highmem pages, for a total of d+r+h pages, what should the watermarks be for each zone?

Appended is the new (2.3.34) form of the patch.

Thanks.

Kanoj

dcache.c +1 -1
@@ -410,7 +410,7 @@
  *  ...
  *   6 - base-level: try to shrink a bit.
  */
-int shrink_dcache_memory(int priority, unsigned int gfp_mask)
+int shrink_dcache_memory(int priority, unsigned int gfp_mask, zone_t * zone)
 {
 	if (gfp_mask & __GFP_IO) {
 		int count = 0;
inode.c +1 -1
@@ -392,7 +392,7 @@
 	dispose_list(freeable);
 }
 
-int shrink_icache_memory(int priority, int gfp_mask)
+int shrink_icache_memory(int priority, int gfp_mask, zone_t *zone)
 {
 	if (gfp_mask & __GFP_IO)
 	{
linux/dcache.h +3 -3
@@ -136,13 +136,13 @@
 extern int d_invalidate(struct dentry *);
 
 #define shrink_dcache() prune_dcache(0)
-
+struct zone_struct;
 /* dcache memory management */
-extern int shrink_dcache_memory(int, unsigned int);
+extern int shrink_dcache_memory(int, unsigned int, struct zone_struct *);
 extern void prune_dcache(int);
 
 /* icache memory management (defined in linux/fs/inode.c) */
-extern int shrink_icache_memory(int, int);
+extern int shrink_icache_memory(int, int, struct zone_struct *);
 extern void prune_icache(int);
 
 /* only used at mount-time */
linux/mm.h +2 -2
@@ -183,7 +183,6 @@
 #define ClearPageError(page)	clear_bit(PG_error, &(page)->flags)
 #define PageReferenced(page)	test_bit(PG_referenced, &(page)->flags)
 #define PageDecrAfter(page)	test_bit(PG_decr_after, &(page)->flags)
-#define PageDMA(page)		(contig_page_data.node_zones + ZONE_DMA == (page)->zone)
 #define PageSlab(page)		test_bit(PG_slab, &(page)->flags)
 #define PageSwapCache(page)	test_bit(PG_swap_cache, &(page)->flags)
 #define PageReserved(page)	test_bit(PG_reserved, &(page)->flags)
@@ -434,10 +433,11 @@
 extern int do_munmap(unsigned long, size_t);
 extern unsigned long do_brk(unsigned long, unsigned long);
 
+struct zone_t;
 /* filemap.c */
 extern void remove_inode_page(struct page *);
 extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int shrink_mmap(int, int, zone_t *);
 extern void truncate_inode_pages(struct inode *, loff_t);
 
 /*
linux/mmzone.h +7 -0
@@ -25,6 +25,8 @@
 	unsigned int * map;
 } free_area_t;
 
+struct pglist_data;
+
 typedef struct zone_struct {
 	/*
 	 * Commonly accessed fields:
@@ -34,6 +36,7 @@
 	unsigned long free_pages;
 	int low_on_memory;
 	unsigned long pages_low, pages_high;
+	struct pglist_data *zone_pgdat;
 
 	/*
 	 * free areas of different sizes
@@ -80,6 +83,10 @@
 } pg_data_t;
 
 extern int numnodes;
+
+#define memclass(pgzone, tzone)	(((pgzone)->zone_pgdat == (tzone)->zone_pgdat) \
+			&& (((pgzone) - (pgzone)->zone_pgdat->node_zones) <= \
+			((tzone) - (pgzone)->zone_pgdat->node_zones)))
 
 #ifndef CONFIG_DISCONTIGMEM
 
linux/swap.h +3 -2
@@ -78,14 +78,15 @@
 struct vm_area_struct;
 struct sysinfo;
 
+struct zone_t;
 /* linux/ipc/shm.c */
-extern int shm_swap (int, int);
+extern int shm_swap (int, int, zone_t *);
 
 /* linux/mm/swap.c */
 extern void swap_setup (void);
 
 /* linux/mm/vmscan.c */
-extern int try_to_free_pages(unsigned int gfp_mask);
+extern int try_to_free_pages(unsigned int gfp_mask, zone_t *zone);
 
 /* linux/mm/page_io.c */
 extern void rw_swap_page(int, struct page *, int);
shm.c +2 -4
@@ -799,7 +799,7 @@
 static unsigned long swap_id = 0; /* currently being swapped */
 static unsigned long swap_idx = 0; /* next to swap */
 
-int shm_swap (int prio, int gfp_mask)
+int shm_swap (int prio, int gfp_mask, zone_t *zone)
 {
 	pte_t page;
 	struct shmid_kernel *shp;
@@ -849,9 +849,7 @@
 	if (!pte_present(page))
 		goto check_table;
 	page_map = pte_page(page);
-	if ((gfp_mask & __GFP_DMA) && !PageDMA(page_map))
-		goto check_table;
-	if (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page_map))
+	if (zone && (!memclass(page_map->zone, zone)))
 		goto check_table;
 	swap_attempts++;
 
util.c +1 -1
@@ -214,7 +214,7 @@
     return;
 }
 
-int shm_swap (int prio, int gfp_mask)
+int shm_swap (int prio, int gfp_mask, zone_t *zone)
 {
     return 0;
 }
filemap.c +2 -4
@@ -211,7 +211,7 @@
 	spin_unlock(&pagecache_lock);
 }
 
-int shrink_mmap(int priority, int gfp_mask)
+int shrink_mmap(int priority, int gfp_mask, zone_t *zone)
 {
 	int ret = 0, count;
 	LIST_HEAD(young);
@@ -239,9 +239,7 @@
 
 		dispose = &old;
 		/* don't account passes over not DMA pages */
-		if ((gfp_mask & __GFP_DMA) && !PageDMA(page))
-			goto dispose_continue;
-		if (!(gfp_mask & __GFP_HIGHMEM) && PageHighMem(page))
+		if (zone && (!memclass(page->zone, zone)))
 			goto dispose_continue;
 
 		count--;
page_alloc.c +8 -7
@@ -224,7 +224,7 @@
 		return 1;
 
 	current->flags |= PF_MEMALLOC;
-	freed = try_to_free_pages(gfp_mask);
+	freed = try_to_free_pages(gfp_mask, zone);
 	current->flags &= ~PF_MEMALLOC;
 
 	if (!freed && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
@@ -235,7 +235,7 @@
 /*
  * We are still balancing memory in a global way:
  */
-static inline int balance_memory (int gfp_mask)
+static inline int balance_memory (zone_t *zone, int gfp_mask)
 {
 	unsigned long free = nr_free_pages();
 	static int low_on_memory = 0;
@@ -264,7 +264,7 @@
 		return 1;
 
 	current->flags |= PF_MEMALLOC;
-	freed = try_to_free_pages(gfp_mask);
+	freed = try_to_free_pages(gfp_mask, zone);
 	current->flags &= ~PF_MEMALLOC;
 
 	if (!freed && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
@@ -340,7 +340,7 @@
  * The main chunk of the balancing code is in this offline branch:
  */
 balance:
-	if (!balance_memory(gfp_mask))
+	if (!balance_memory(z, gfp_mask))
 		goto nopage;
 	goto ready;
 }
@@ -533,9 +533,9 @@
 		i = 10;
 	if (i > 256)
 		i = 256;
-	freepages.min = i;
-	freepages.low = i * 2;
-	freepages.high = i * 3;
+	freepages.min += i;
+	freepages.low += i * 2;
+	freepages.high += i * 3;
 
 	/*
 	 * Some architectures (with lots of mem and discontinous memory
@@ -574,6 +574,7 @@
 		zone->size = size;
 		zone->name = zone_names[j];
 		zone->lock = SPIN_LOCK_UNLOCKED;
+		zone->zone_pgdat = pgdat;
 		if (!size)
 			continue;
 
slab.c +5 -12
@@ -503,6 +503,11 @@
 {
 	void	*addr;
 
+	/*
+	 * If we requested dmaable memory, we will get it. Even if we 
+	 * did not request dmaable memory, we might get it, but that
+	 * would be relatively rare and ignorable.
+	 */
 	*dma = flags & SLAB_DMA;
 	addr = (void*) __get_free_pages(flags, cachep->c_gfporder);
 	/* Assume that now we have the pages no one else can legally
@@ -511,18 +516,6 @@
 	 * it is a named-page or buffer-page.  The members it tests are
 	 * of no interest here.....
 	 */
-	if (!*dma && addr) {
-		/* Need to check if can dma. */
-		struct page *page = mem_map + MAP_NR(addr);
-		*dma = 1<<cachep->c_gfporder;
-		while ((*dma)--) {
-			if (!PageDMA(page)) {
-				*dma = 0;
-				break;
-			}
-			page++;
-		}
-	}
 	return addr;
 }
 
vmscan.c +21 -22

161 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.nl.linux.org/Linux-MM/

#5 lore raw
Quoted 7 lines · Kanoj Sarcar

Okay, here is a reworked version. Note that this version does not do per-zone balancing, since experiments show that we need to tune per-zone watermarks properly before we can start doing that. I am working on coming up with a good estimate of per-zone watermarks. Basically, I am trying to answer the question: if there are d dmapages, r regular pages and h highmem pages, for a total of d+r+h pages, what should the watermarks be for each zone?

d+r+h > limit

d     > limit/2
r     > limit/4
h     > limit/8

DMA pages should always be present, regular pages for storing pagetables and stuff need to be there too, higmem pages we don't really care about.

Btw, I think we probably want to increase freepages.min to 512 or even more on machines that have >1GB of memory. The current limit of 256 was really intended for machines with a single zone of memory...

(but on <1GB machines I don't know if it makes sense to raise the limit much more ... maybe we should raise the limit automagically if the page alloc/io rate is too high?)

regards,

Rik
--
The Internet is not a network of computers. It is a network of people. That is its real strength.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.nl.linux.org/Linux-MM/

#6 lore raw
Quoted 4 lines · Rik van Riel

d+r+h > limit

d     > limit/2
r     > limit/4
h     > limit/8

Ehmmm, wait. I messed up on this one.
We probably want to have a bit more freedom
so the page freeing algorithm doesn't do too
much scanning for nothing.

d+r+h > limit
d > limit/4
r > limit/4
h don't care, even on a 1.5GB machine h will
be 1/3 of total memory, so we'll usually
have a few free pages in here

Quoted 9 lines

DMA pages should always be present, regular pages for storing pagetables and stuff need to be there too, higmem pages we don't really care about.

Btw, I think we probably want to increase freepages.min to 512 or even more on machines that have >1GB of memory. The current limit of 256 was really intended for machines with a single zone of memory...

Quoted 4 lines

(but on <1GB machines I don't know if it makes sense to raise the limit much more ... maybe we should raise the limit automagically if the page alloc/io rate is too high?)

Rik
--
The Internet is not a network of computers. It is a network of people. That is its real strength.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.nl.linux.org/Linux-MM/

#8 lore raw
In reply to Ingo Molnar

i think this is pretty much 'type-dependent'. In earlier versions of the zone allocator i added a zone->memory_balanced() function (but removed it later because it first needed the things your patch adds). Then every zone can decide for itself wether it's balanced. Eg. the DMA zone is rather critical and we want to keep it free aggressively (part of that is already achieved by placing it at the end of the zone chain), the highmem zone might not need any balancing at all, the normal zone wants some high/low watermark stuff.

Let's be careful not to design any balancing heuristics which will fall apart on architectures where only one zone ever exists (because GFP_DMA is completely meaningless).

Later,
David S. Miller
[email protected]
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.nl.linux.org/Linux-MM/

#7 lore raw
In reply to Kanoj Sarcar
Quoted 7 lines · Kanoj Sarcar

Okay, here is a reworked version. Note that this version does not do per-zone balancing, since experiments show that we need to tune per-zone watermarks properly before we can start doing that. I am working on coming up with a good estimate of per-zone watermarks. Basically, I am trying to answer the question: if there are d dmapages, r regular pages and h highmem pages, for a total of d+r+h pages, what should the watermarks be for each zone?

i think this is pretty much 'type-dependent'. In earlier versions of the zone allocator i added a zone->memory_balanced() function (but removed it later because it first needed the things your patch adds). Then every zone can decide for itself wether it's balanced. Eg. the DMA zone is rather critical and we want to keep it free aggressively (part of that is already achieved by placing it at the end of the zone chain), the highmem zone might not need any balancing at all, the normal zone wants some high/low watermark stuff.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.nl.linux.org/Linux-MM/

#9 lore raw
In reply to David S. Miller
Quoted 4 lines

Date: Thu, 6 Jan 2000 17:05:41 +0100 (CET)
From: Ingo Molnar <[email protected]>

Quoted 9 lines

i think this is pretty much 'type-dependent'. In earlier versions of the zone allocator i added a zone->memory_balanced() function (but removed it later because it first needed the things your patch adds). Then every zone can decide for itself wether it's balanced. Eg. the DMA zone is rather critical and we want to keep it free aggressively (part of that is already achieved by placing it at the end of the zone chain), the highmem zone might not need any balancing at all, the normal zone wants some high/low watermark stuff.

After thinking about this more, I came to the conclusion that the ZONE_BALANCED macro is just a quick way of checking whether we are _really_ unbalanced. If so, then we need to see if we are really unbalanced, and do appropriate freeing. To determine whether a zone is _really_ unbalanced, I need to look at the number of free pages in the lower order zones too, then compare against the zone's water marks. Ie, the "balancing" is not just about the absolute number of free pages in the zone, but rather in the class that the zone represents.

I am waiting to see if Linus takes in my previous patch, before puting too much work into the balancing heuristics.

Quoted 4 lines

Let's be careful not to design any balancing heuristics which will fall apart on architectures where only one zone ever exists (because GFP_DMA is completely meaningless).

Yes, with all different types of machines out there, we need to be able to provide enough hooks to the arch code to tune the watermarks and balancing frequency. Luckily, the zone structure is exposed via the pg_data_t, so this should be no problem. Some sysctls are probably also called for.

Kanoj

Quoted 5 lines

Later,
David S. Miller
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.nl.linux.org/Linux-MM/

#10 lore raw
In reply to David S. Miller
Quoted 13 lines · David S. Miller

Date: Thu, 6 Jan 2000 17:05:41 +0100 (CET)
From: Ingo Molnar <[email protected]>

i think this is pretty much 'type-dependent'. In earlier versions of the zone allocator i added a zone->memory_balanced() function (but removed it later because it first needed the things your patch adds). Then every zone can decide for itself wether it's balanced. Eg. the DMA zone is rather critical and we want to keep it free aggressively (part of that is already achieved by placing it at the end of the zone chain), the highmem zone might not need any balancing at all, the normal zone wants some high/low watermark stuff.

Quoted 3 lines

Let's be careful not to design any balancing heuristics which will fall apart on architectures where only one zone ever exists (because GFP_DMA is completely meaningless).

We'll have to keep the current constraint (freepages.{min,low,high}) stuff as our overall target anyway. We simply need to add some limits that the special zones have to target for.

And it won't just be tested from kswapd(); swap_tick() and maybe even __get_pages() will have to check for the constraints too and wake up kswapd() or take action themselves...

Possible heuristics (using d for dma, n for normal and high for high free mem; limit = freepages.*) could use the following targets:

d + n > limit

d     > limit/4
n     > limit/4
h     < limit * 2 (because we don't care about free high pages

and we do care about free normal and dma pages)

Another possibility is to include the highmem (d + n + h > limit) and keep the single low-mem limits.

IMHO there should be a number of constraints for a heuristic like this:
- simple
- not force too much memory free
- the algorithm should have freedom in what to free, in order to avoid excessive scanning (alt: separate queues per zone)
- the limits for dma and normal memory should be high enough to be able to fulfill kernel allocations
- should have no impact on non-zoned machines

The (extremely simple) constraints above should probably be enough to actually get the job done. At least, I wouldn't know why we'd need more...

cheers,

Rik
--
The Internet is not a network of computers. It is a network of people. That is its real strength.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.nl.linux.org/Linux-MM/