Skip to contentSkip to conversation

VM fixes [2/4]

PATCH Andrea Arcangeli 3 participants 5 messages Dec 24, 2004 – Jan 3, 2005

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

This is the forward port to 2.6 of the lowmem_reserved algorithm I invented in 2.4.1*, merged in 2.4.2x already and needed to fix workloads like google (especially without swap) on x86 with >1G of ram, but it's needed in all sort of workloads with lots of ram on x86, it's also needed on x86-64 for dma allocations. This brings 2.6 in sync with latest 2.4.2x.

From: Andrea Arcangeli <[email protected]>
Subject: keep balance between different classzones

include/linux/mmzone.h renamed from include/linux/mmzone.h.orig +9 -12
@@ -112,18 +112,14 @@ struct zone {
 	unsigned long		free_pages;
 	unsigned long		pages_min, pages_low, pages_high;
 	/*
-	 * protection[] is a pre-calculated number of extra pages that must be
-	 * available in a zone in order for __alloc_pages() to allocate memory
-	 * from the zone. i.e., for a GFP_KERNEL alloc of "order" there must
-	 * be "(1<<order) + protection[ZONE_NORMAL]" free pages in the zone
-	 * for us to choose to allocate the page from that zone.
-	 *
-	 * It uses both min_free_kbytes and sysctl_lower_zone_protection.
-	 * The protection values are recalculated if either of these values
-	 * change.  The array elements are in zonelist order:
-	 *	[0] == GFP_DMA, [1] == GFP_KERNEL, [2] == GFP_HIGHMEM.
+	 * We don't know if the memory that we're going to allocate will be freeable
+	 * or/and it will be released eventually, so to avoid totally wasting several
+	 * GB of ram we must reserve some of the lower zone memory (otherwise we risk
+	 * to run OOM on the lower zones despite there's tons of freeable ram
+	 * on the higher zones). This array is recalculated at runtime if the
+	 * sysctl_lowmem_reserve_ratio sysctl changes.
 	 */
-	unsigned long		protection[MAX_NR_ZONES];
+	unsigned long		lowmem_reserve[MAX_NR_ZONES];
 
 	struct per_cpu_pageset	pageset[NR_CPUS];
 
@@ -366,7 +362,8 @@ struct ctl_table;
 struct file;
 int min_free_kbytes_sysctl_handler(struct ctl_table *, int, struct file *, 
 					void __user *, size_t *, loff_t *);
-int lower_zone_protection_sysctl_handler(struct ctl_table *, int, struct file *,
+extern int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1];
+int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *, int, struct file *,
 					void __user *, size_t *, loff_t *);
 
 #include <linux/topology.h>
include/linux/sysctl.h renamed from include/linux/sysctl.h.orig +1 -1
@@ -159,7 +159,7 @@ enum
 	VM_PAGEBUF=17,		/* struct: Control pagebuf parameters */
 	VM_HUGETLB_PAGES=18,	/* int: Number of available Huge Pages */
 	VM_SWAPPINESS=19,	/* Tendency to steal mapped memory */
-	VM_LOWER_ZONE_PROTECTION=20,/* Amount of protection of lower zones */
+	VM_LOWMEM_RESERVE_RATIO=20,/* reservation ratio for lower memory zones */
 	VM_MIN_FREE_KBYTES=21,	/* Minimum free kilobytes to maintain */
 	VM_MAX_MAP_COUNT=22,	/* int: Maximum number of mmaps/address-space */
 	VM_LAPTOP_MODE=23,	/* vm laptop mode */
kernel/sysctl.c renamed from kernel/sysctl.c.orig +5 -7
@@ -62,7 +62,6 @@ extern int core_uses_pid;
 extern char core_pattern[];
 extern int cad_pid;
 extern int pid_max;
-extern int sysctl_lower_zone_protection;
 extern int min_free_kbytes;
 extern int printk_ratelimit_jiffies;
 extern int printk_ratelimit_burst;
@@ -736,14 +735,13 @@ static ctl_table vm_table[] = {
 	 },
 #endif
 	{
-		.ctl_name	= VM_LOWER_ZONE_PROTECTION,
-		.procname	= "lower_zone_protection",
-		.data		= &sysctl_lower_zone_protection,
-		.maxlen		= sizeof(sysctl_lower_zone_protection),
+		.ctl_name	= VM_LOWMEM_RESERVE_RATIO,
+		.procname	= "lowmem_reserve_ratio",
+		.data		= &sysctl_lowmem_reserve_ratio,
+		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
 		.mode		= 0644,
-		.proc_handler	= &lower_zone_protection_sysctl_handler,
+		.proc_handler	= &lowmem_reserve_ratio_sysctl_handler,
 		.strategy	= &sysctl_intvec,
-		.extra1		= &zero,
 	},
 	{
 		.ctl_name	= VM_MIN_FREE_KBYTES,
mm/page_alloc.c renamed from mm/page_alloc.c.orig +39 -99

220 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · Andrea Arcangeli

This is the forward port to 2.6 of the lowmem_reserved algorithm I invented in 2.4.1*, merged in 2.4.2x already and needed to fix workloads like google (especially without swap) on x86 with >1G of ram, but it's needed in all sort of workloads with lots of ram on x86, it's also needed on x86-64 for dma allocations. This brings 2.6 in sync with latest 2.4.2x.

This looks OK to me. It really simplifies the code there a lot too.

The only questions I have are: should it be on by default? I don't think we ever reached an agreement. I'd say yes, after a run in -mm because it does potentially fix corner cases where lower zones get filled with un- freeable memory which could have been satisfied with higher zones.

And second, any chance you could you port it to the mm patches already in -mm? Won't be a big job, just some clashes in __alloc_pages...

mm-keep-count-of-free-areas.patch
mm-higher-order-watermarks.patch
mm-higher-order-watermarks-fix.patch
mm-teach-kswapd-about-higher-order-areas.patch

Thanks,
Nick

#2 lore raw
Quoted 9 lines · Nick Piggin
Quoted 7 lines · Andrea Arcangeli

This is the forward port to 2.6 of the lowmem_reserved algorithm I invented in 2.4.1*, merged in 2.4.2x already and needed to fix workloads like google (especially without swap) on x86 with >1G of ram, but it's needed in all sort of workloads with lots of ram on x86, it's also needed on x86-64 for dma allocations. This brings 2.6 in sync with latest 2.4.2x.

Quoted 6 lines

This looks OK to me. It really simplifies the code there a lot too.

The only questions I have are: should it be on by default? I don't think we ever reached an agreement. I'd say yes, after a run in -mm because it does potentially fix corner cases where lower zones get filled with un- freeable memory which could have been satisfied with higher zones.

Great, thanks for the review! I definitely agree it should be on by default, I already had an hang report that was solved by more recent kernels and that probably can only be explained by lowmem_reserve since there aren't other mm changes in 2.6.5 based trees.

Quoted 2 lines

And second, any chance you could you port it to the mm patches already in -mm? Won't be a big job, just some clashes in __alloc_pages...

I already had to port to 2.6.5 too, and that's enough for now unless I first get a positive ack that it will be merged (if I hadn't more interesting things to develop, I would be happily porting it).

#3 lore raw
Quoted 22 lines · Andrea Arcangeli
Quoted 9 lines · Nick Piggin
Quoted 7 lines · Andrea Arcangeli

This is the forward port to 2.6 of the lowmem_reserved algorithm I invented in 2.4.1*, merged in 2.4.2x already and needed to fix workloads like google (especially without swap) on x86 with >1G of ram, but it's needed in all sort of workloads with lots of ram on x86, it's also needed on x86-64 for dma allocations. This brings 2.6 in sync with latest 2.4.2x.

Quoted 6 lines

This looks OK to me. It really simplifies the code there a lot too.

The only questions I have are: should it be on by default? I don't think we ever reached an agreement. I'd say yes, after a run in -mm because it does potentially fix corner cases where lower zones get filled with un- freeable memory which could have been satisfied with higher zones.

Great, thanks for the review! I definitely agree it should be on by default, I already had an hang report that was solved by more recent kernels and that probably can only be explained by lowmem_reserve since there aren't other mm changes in 2.6.5 based trees.

Quoted 6 lines
Quoted 2 lines

And second, any chance you could you port it to the mm patches already in -mm? Won't be a big job, just some clashes in __alloc_pages...

I already had to port to 2.6.5 too, and that's enough for now unless I first get a positive ack that it will be merged (if I hadn't more interesting things to develop, I would be happily porting it).

I believe it can be accepted easily if you change the variable names from protection to lowmem_reserve.

Is there a need for that or its just your taste? :)

#4 lore raw
Quoted 26 lines · Marcelo Tosatti
Quoted 25 lines · Andrea Arcangeli
Quoted 9 lines · Nick Piggin
Quoted 7 lines · Andrea Arcangeli

This is the forward port to 2.6 of the lowmem_reserved algorithm I invented in 2.4.1*, merged in 2.4.2x already and needed to fix workloads like google (especially without swap) on x86 with >1G of ram, but it's needed in all sort of workloads with lots of ram on x86, it's also needed on x86-64 for dma allocations. This brings 2.6 in sync with latest 2.4.2x.

Quoted 6 lines

This looks OK to me. It really simplifies the code there a lot too.

The only questions I have are: should it be on by default? I don't think we ever reached an agreement. I'd say yes, after a run in -mm because it does potentially fix corner cases where lower zones get filled with un- freeable memory which could have been satisfied with higher zones.

Great, thanks for the review! I definitely agree it should be on by default, I already had an hang report that was solved by more recent kernels and that probably can only be explained by lowmem_reserve since there aren't other mm changes in 2.6.5 based trees.

Quoted 2 lines

And second, any chance you could you port it to the mm patches already in -mm? Won't be a big job, just some clashes in __alloc_pages...

Quoted 8 lines
Quoted 3 lines

I already had to port to 2.6.5 too, and that's enough for now unless I first get a positive ack that it will be merged (if I hadn't more interesting things to develop, I would be happily porting it).

I believe it can be accepted easily if you change the variable names from protection to lowmem_reserve.

Is there a need for that or its just your taste? :)

The naming is in sync with 2.4, I called that feature lowmem_reserve when I wrote it. Protection doesn't actually mean anything. Memory protection, mprotect, what?

The object of the feature is to reserve lower memory in function of the classzone allocation, and in function of the zone we're allocating from. So lowmem_reserve sounds a much better name. And it wasn't me to change it, it was the 2.6 kernel calling it differently in the first place. Note that at first 2.6 was doing stuff very differently from 2.4 too (and it wasn't working right infact). Now it's in perfect sync with the 2.4 algorightm I wrote originally and so I thought it would be much cleaner to call it the same way as 2.4, which is more self explanatory too.