Skip to contentSkip to conversation

mm: init_per_zone_pages_min - get rid of sqrt call on small machines

PATCH In review Cyrill Gorcunov 3 participants 3 messages May 6, 2009

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

PATCH 1/1 mm: init_per_zone_pages_min - get rid of sqrt call on small machines

For small machines we may eliminate call for int_sqrt by using precaulculated value.

---
 mm/page_alloc.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
mm/page_alloc.c +8 -4
Index: linux-2.6.git/mm/page_alloc.c
=====================================================================
@@ -4610,11 +4610,15 @@ static int __init init_per_zone_pages_mi
 
 	lowmem_kbytes = nr_free_buffer_pages() * (PAGE_SIZE >> 10);
 
-	min_free_kbytes = int_sqrt(lowmem_kbytes * 16);
-	if (min_free_kbytes < 128)
+	/* for small values we may eliminate sqrt operation completely */
+	if (lowmem_kbytes < 1024)
 		min_free_kbytes = 128;
-	if (min_free_kbytes > 65536)
-		min_free_kbytes = 65536;
+	else {
+		min_free_kbytes = int_sqrt(lowmem_kbytes * 16);
+		if (min_free_kbytes > 65536)
+			min_free_kbytes = 65536;
+	}
+
 	setup_per_zone_pages_min();
 	setup_per_zone_lowmem_reserve();
 	setup_per_zone_inactive_ratio();

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw
Quoted 14 lines · Cyrill Gorcunov

Index: linux-2.6.git/mm/page_alloc.c
=====================================================================

mm/page_alloc.c +2 -3
@@ -4610,11 +4610,15 @@ static int __init init_per_zone_pages_mi
 
 	lowmem_kbytes = nr_free_buffer_pages() * (PAGE_SIZE >> 10);
 
-	min_free_kbytes = int_sqrt(lowmem_kbytes * 16);
-	if (min_free_kbytes < 128)
+	/* for small values we may eliminate sqrt operation completely */
+	if (lowmem_kbytes < 1024)
 		min_free_kbytes = 128;
-	if (min_free_kbytes > 65536)

mm/page_alloc.c static int __init init_per_zone_pages_mi · line 4624

Quoted 10 lines
mm/page_alloc.c +6 -1
-		min_free_kbytes = 65536;
+	else {
+		min_free_kbytes = int_sqrt(lowmem_kbytes * 16);
+		if (min_free_kbytes > 65536)
+			min_free_kbytes = 65536;
+	}
+
 	setup_per_zone_pages_min();
 	setup_per_zone_lowmem_reserve();
 	setup_per_zone_inactive_ratio();

For a function that's called once, this just isn't worth it. int_sqrt() isn't expensive enough to warrant the assault on the readability of the code.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

[David Rientjes - Tue, May 05, 2009 at 11:36:38PM -0700]

| On Wed, 6 May 2009, Cyrill Gorcunov wrote:
| 
| > Index: linux-2.6.git/mm/page_alloc.c
| > =====================================================================
| > --- linux-2.6.git.orig/mm/page_alloc.c
| > +++ linux-2.6.git/mm/page_alloc.c
| > @@ -4610,11 +4610,15 @@ static int __init init_per_zone_pages_mi
| >  
| >  	lowmem_kbytes = nr_free_buffer_pages() * (PAGE_SIZE >> 10);
| >  
| > -	min_free_kbytes = int_sqrt(lowmem_kbytes * 16);
| > -	if (min_free_kbytes < 128)
| > +	/* for small values we may eliminate sqrt operation completely */
| > +	if (lowmem_kbytes < 1024)
| >  		min_free_kbytes = 128;
| > -	if (min_free_kbytes > 65536)
| > -		min_free_kbytes = 65536;
| > +	else {
| > +		min_free_kbytes = int_sqrt(lowmem_kbytes * 16);
| > +		if (min_free_kbytes > 65536)
| > +			min_free_kbytes = 65536;
| > +	}
| > +
| >  	setup_per_zone_pages_min();
| >  	setup_per_zone_lowmem_reserve();
| >  	setup_per_zone_inactive_ratio();
| 
| For a function that's called once, this just isn't worth it.  int_sqrt() 
| isn't expensive enough to warrant the assault on the readability of the 
| code.
| 

ok, then we could just drop it.

-- Cyrill

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>