Skip to contentSkip to conversation

alloc_pages_limit & pages_min

PATCH New Roger Larsson (by way of Roger Larsson <[email protected]>) 1 participant 1 message Aug 23, 2001

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

PATCH 1/1 alloc_pages_limit & pages_min

Hi,

[Same patch as earlier sent to linux-mm, now tested]

Patch is agains 2.4.8-pre3, but should apply cleanly. The only performance difference I have noticed is for copying a huge file, then it performs a lot better (but I do not have a baseline run for an unpatched -pre3, but I have benchmarked both earlier and later revisions)

* The original code in __alloc_pages_limit has a little bug in the case when:
- kreclaimd were not allowed to run for a LONG time... Lots of kernel activity, RT tasks, or code running around for a long time allocating memory.
- there were lots of inactive clean pages
- pages were allocated without direct_reclaim (higher order) (networking might be one candidate)
it could result in using up ALL free pages!

This patch tries to prevent this situation in several ways:
1) Do not allow to alloc a free page when they are critically low. [last line of patch, the really critical part of this patch]

2) If direct reclaims are allowed do some additional work. reclaim & free until pages_min,
alloc one page,
reclaim and free until pages_low

/RogerL

--
Roger Larsson
Skellefteå
Sweden

*******************************************
Patch prepared by: [email protected] with comments from Riel

mm/page_alloc.c renamed from mm/page_alloc.c.orig +28 -4
@@ -253,11 +253,35 @@
 
 		if (z->free_pages + z->inactive_clean_pages >= water_mark) {
 			struct page *page = NULL;
-			/* If possible, reclaim a page directly. */
-			if (direct_reclaim)
+
+			/*
+			 * Reclaim a page from the inactive_clean list.
+			 * If needed, refill the free list up to the
+			 * low water mark.
+			 */
+			if (direct_reclaim) {
 				page = reclaim_page(z);
-			/* If that fails, fall back to rmqueue. */
-			if (!page)
+
+				while (page && z->free_pages < z->pages_min) {
+					__free_page(page);
+					page = reclaim_page(z);
+				}
+
+				if (page) {
+					while (z->free_pages < z->pages_low) {
+						struct page *extra = reclaim_page(z);
+						if (!extra)
+							break;
+						__free_page(extra);
+					}
+				}
+
+				/* let kreclaimd handle up to pages_high */
+			}
+			/* If that fails, fall back to rmqueue, but never let
+			*  free_pages go below pages_min...
+			*/
+			if (!page && z->free_pages >= z->pages_min)
 				page = rmqueue(z, order);
 			if (page)
 				return page;