Skip to contentSkip to conversation

split anon and file LRUs

RFC PATCH In review Rik van Riel 3 participants 31 messages Nov 3, 2007 – Nov 7, 2007

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

cover split anon and file LRUs

The current page replacement scheme in Linux has a number of problems, which can be boiled down to:
- Sometimes the kernel evicts the wrong pages, which can result in bad performance.
- The kernel scans over pages that should not be evicted. On systems with a few GB of RAM, this can result in the VM using an annoying amount of CPU. On systems with >128GB of RAM, this can knock the system out for hours since excess CPU use is compounded with lock contention and other issues.

This patch series tries to address the issues by splitting the LRU lists into two sets, one for swap/ram backed pages ("anon") and one for filesystem backed pages ("file").

The current version only has the infrastructure. Large changes to the page replacement policy will follow later.

More details can be found on this page:

http://linux-mm.org/PageReplacementDesign

TODO:
- have any mlocked and ramfs pages live off of the LRU list, so we do not need to scan these pages
- switch to SEQ replacement for the anon LRU lists, so the worst case number of pages to scan is reduced greatly.
- figure out if the file LRU lists need page replacement changes to help with worst case scenarios
- implement and benchmark a scalable non-resident page tracking implementation in the radix tree, this may make the anon/file balancing algorithm more stable and could allow for further simplifications in the balancing algorithm

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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

RFC PATCH 1/10 move isolate_lru_page to vmscan.c

move isolate_lru_page() to vmscan.c

Against 2.6.23-rc4-mm1

V1 -> V2 [lts]:
+ fix botched merge -- add back "get_page_unless_zero()"

From: Nick Piggin <[email protected]>
To: Linux Memory Management <[email protected]>
Subject: [patch 1/4] mm: move and rework isolate_lru_page
Date: Mon, 12 Mar 2007 07:38:44 +0100 (CET)

isolate_lru_page logically belongs to be in vmscan.c than migrate.c.

It is tough, because we don't need that function without memory migration so there is a valid argument to have it in migrate.c. However a subsequent patch needs to make use of it in the core mm, so we can happily move it to vmscan.c.

Also, make the function a little more generic by not requiring that it adds an isolated page to a given list. Callers can do that.

Note that we now have '__isolate_lru_page()', that does something quite different, visible outside of vmscan.c for use with memory controller. Methinks we need to
rationalize these names/purposes. --lts

 include/linux/migrate.h |    3 ---
 mm/internal.h           |    2 ++
 mm/mempolicy.c          |   10 ++++++++--
 mm/migrate.c            |   47 ++++++++++-------------------------------------
 mm/vmscan.c             |   41 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 61 insertions(+), 42 deletions(-)
include/linux/migrate.h +0 -3
Index: Linux/include/linux/migrate.h
===================================================================
@@ -25,7 +25,6 @@ static inline int vma_migratable(struct 
 	return 1;
 }
 
-extern int isolate_lru_page(struct page *p, struct list_head *pagelist);
 extern int putback_lru_pages(struct list_head *l);
 extern int migrate_page(struct address_space *,
 			struct page *, struct page *);
@@ -42,8 +41,6 @@ extern int migrate_vmas(struct mm_struct
 static inline int vma_migratable(struct vm_area_struct *vma)
 					{ return 0; }
 
-static inline int isolate_lru_page(struct page *p, struct list_head *list)
-					{ return -ENOSYS; }
 static inline int putback_lru_pages(struct list_head *l) { return 0; }
 static inline int migrate_pages(struct list_head *l, new_page_t x,
 		unsigned long private) { return -ENOSYS; }
mm/internal.h +2 -0
Index: Linux/mm/internal.h
===================================================================
@@ -34,6 +34,8 @@ static inline void __put_page(struct pag
 	atomic_dec(&page->_count);
 }
 
+extern int isolate_lru_page(struct page *page);
+
 extern void fastcall __init __free_pages_bootmem(struct page *page,
 						unsigned int order);
 
mm/migrate.c +10 -37

60 lines not on this page · raw message

mm/vmscan.c +41 -0

47 lines not on this page · raw message

mm/mempolicy.c +8 -2
Index: Linux/mm/mempolicy.c
===================================================================
@@ -93,6 +93,8 @@
 #include <asm/tlbflush.h>
 #include <asm/uaccess.h>
 
+#include "internal.h"
+
 /* Internal flags */
 #define MPOL_MF_DISCONTIG_OK (MPOL_MF_INTERNAL << 0)	/* Skip checks for continuous vmas */
 #define MPOL_MF_INVERT (MPOL_MF_INTERNAL << 1)		/* Invert check for nodemask */
@@ -603,8 +605,12 @@ static void migrate_page_add(struct page
 	/*
 	 * Avoid migrating a page that is shared with others.
 	 */
-	if ((flags & MPOL_MF_MOVE_ALL) || page_mapcount(page) == 1)
-		isolate_lru_page(page, pagelist);
+	if ((flags & MPOL_MF_MOVE_ALL) || page_mapcount(page) == 1) {
+		if (!isolate_lru_page(page)) {
+			get_page(page);
+			list_add_tail(&page->lru, pagelist);
+		}
+	}
 }
 
 static struct page *new_node_page(struct page *page, unsigned long node, int **x)

--
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>

#3 lore raw

RFC PATCH 2/10 free swap space entries if vm_swap_full()

In reply to Rik van Riel

Rik van Riel's patch to free swap space on swap-in/activiation, forward ported by Lee Schermerhorn.

Against: 2.6.23-rc2-mm2 atop:
+ lts' convert anon_vma list lock to reader/write lock patch
+ Nick Piggin's move and rework isolate_lru_page() patch

Patch Description: quick attempt by lts

Free swap cache entries when swapping in pages if vm_swap_full() [swap space > 1/2 used?]. Uses new pagevec to reduce pressure on locks.

 include/linux/pagevec.h |    1 +
 mm/swap.c               |   18 ++++++++++++++++++
 mm/vmscan.c             |   16 +++++++++++-----
 3 files changed, 30 insertions(+), 5 deletions(-)
mm/vmscan.c +11 -5
Index: linux-2.6.23-rc6-mm1/mm/vmscan.c
===================================================================
@@ -613,6 +613,9 @@ free_it:
 		continue;
 
 activate_locked:
+		/* Not a candidate for swapping, so reclaim swap space. */
+		if (PageSwapCache(page) && vm_swap_full())
+			remove_exclusive_swap_page(page);
 		SetPageActive(page);
 		pgactivate++;
 keep_locked:
@@ -1142,14 +1145,13 @@ force_reclaim_mapped:
 		}
 	}
 	__mod_zone_page_state(zone, NR_INACTIVE, pgmoved);
+	spin_unlock_irq(&zone->lru_lock);
 	pgdeactivate += pgmoved;
-	if (buffer_heads_over_limit) {
-		spin_unlock_irq(&zone->lru_lock);
-		pagevec_strip(&pvec);
-		spin_lock_irq(&zone->lru_lock);
-	}
 
+	if (buffer_heads_over_limit)
+		pagevec_strip(&pvec);
 	pgmoved = 0;
+	spin_lock_irq(&zone->lru_lock);
 	while (!list_empty(&l_active)) {
 		page = lru_to_page(&l_active);
 		prefetchw_prev_lru_page(page, &l_active, flags);
@@ -1163,6 +1165,8 @@ force_reclaim_mapped:
 			__mod_zone_page_state(zone, NR_ACTIVE, pgmoved);
 			pgmoved = 0;
 			spin_unlock_irq(&zone->lru_lock);
+			if (vm_swap_full())
+				pagevec_swap_free(&pvec);
 			__pagevec_release(&pvec);
 			spin_lock_irq(&zone->lru_lock);
 		}
@@ -1172,6 +1176,8 @@ force_reclaim_mapped:
 	__count_zone_vm_events(PGREFILL, zone, pgscanned);
 	__count_vm_events(PGDEACTIVATE, pgdeactivate);
 	spin_unlock_irq(&zone->lru_lock);
+	if (vm_swap_full())
+		pagevec_swap_free(&pvec);
 
 	pagevec_release(&pvec);
 }
mm/swap.c +18 -0
Index: linux-2.6.23-rc6-mm1/mm/swap.c
===================================================================
@@ -421,6 +421,24 @@ void pagevec_strip(struct pagevec *pvec)
 	}
 }
 
+/*
+ * Try to free swap space from the pages in a pagevec
+ */
+void pagevec_swap_free(struct pagevec *pvec)
+{
+	int i;
+
+	for (i = 0; i < pagevec_count(pvec); i++) {
+		struct page *page = pvec->pages[i];
+
+		if (PageSwapCache(page) && !TestSetPageLocked(page)) {
+			if (PageSwapCache(page))
+				remove_exclusive_swap_page(page);
+			unlock_page(page);
+		}
+	}
+}
+
 /**
  * pagevec_lookup - gang pagecache lookup
  * @pvec:	Where the resulting pages are placed
include/linux/pagevec.h +1 -0
Index: linux-2.6.23-rc6-mm1/include/linux/pagevec.h
===================================================================
@@ -26,6 +26,7 @@ void __pagevec_free(struct pagevec *pvec
 void __pagevec_lru_add(struct pagevec *pvec);
 void __pagevec_lru_add_active(struct pagevec *pvec);
 void pagevec_strip(struct pagevec *pvec);
+void pagevec_swap_free(struct pagevec *pvec);
 unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
 		pgoff_t start, unsigned nr_pages);
 unsigned pagevec_lookup_tag(struct pagevec *pvec,

--
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>

#4 lore raw

Re: [RFC PATCH 2/10] free swap space entries if vm_swap_full()

Quoted 9 lines · Rik van Riel
mm/vmscan.c +1 -3
@@ -1142,14 +1145,13 @@ force_reclaim_mapped:
 		}
 	}
 	__mod_zone_page_state(zone, NR_INACTIVE, pgmoved);
+	spin_unlock_irq(&zone->lru_lock);
 	pgdeactivate += pgmoved;
-	if (buffer_heads_over_limit) {
-		spin_unlock_irq(&zone->lru_lock);
-		pagevec_strip(&pvec);

mm/vmscan.c force_reclaim_mapped: · line 1157

Quoted 10 lines
mm/vmscan.c +3 -2
-		spin_lock_irq(&zone->lru_lock);
-	}
 
+	if (buffer_heads_over_limit)
+		pagevec_strip(&pvec);
 	pgmoved = 0;
+	spin_lock_irq(&zone->lru_lock);
 	while (!list_empty(&l_active)) {
 		page = lru_to_page(&l_active);
 		prefetchw_prev_lru_page(page, &l_active, flags);

Why are we dropping the lock here now? There would be less activity on the lru_lock if we would only drop it if necessary.

mm/vmscan.c force_reclaim_mapped: · line 1172

Quoted 9 lines
mm/vmscan.c +2 -0
@@ -1163,6 +1165,8 @@ force_reclaim_mapped:
 			__mod_zone_page_state(zone, NR_ACTIVE, pgmoved);
 			pgmoved = 0;
 			spin_unlock_irq(&zone->lru_lock);
+			if (vm_swap_full())
+				pagevec_swap_free(&pvec);
 			__pagevec_release(&pvec);
 			spin_lock_irq(&zone->lru_lock);
 		}

Same here. Maybe the spin_unlock and the spin_lock can go into pagevec_swap_free?

--
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>

#5 lore raw

Re: [RFC PATCH 2/10] free swap space entries if vm_swap_full()

Quoted 14 lines · On Tue, 6 Nov 2007 18:20:44 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 12 lines · Rik van Riel
mm/vmscan.c +1 -5
@@ -1142,14 +1145,13 @@ force_reclaim_mapped:
 		}
 	}
 	__mod_zone_page_state(zone, NR_INACTIVE, pgmoved);
+	spin_unlock_irq(&zone->lru_lock);
 	pgdeactivate += pgmoved;
-	if (buffer_heads_over_limit) {
-		spin_unlock_irq(&zone->lru_lock);
-		pagevec_strip(&pvec);
-		spin_lock_irq(&zone->lru_lock);
-	}
 
Quoted 10 lines

mm/vmscan.c force_reclaim_mapped: · line 1157

Quoted 7 lines
mm/vmscan.c +3 -0
+	if (buffer_heads_over_limit)
+		pagevec_strip(&pvec);
 	pgmoved = 0;
+	spin_lock_irq(&zone->lru_lock);
 	while (!list_empty(&l_active)) {
 		page = lru_to_page(&l_active);
 		prefetchw_prev_lru_page(page, &l_active, flags);

Why are we dropping the lock here now? There would be less activity on the lru_lock if we would only drop it if necessary.

Fixed, thank you.

This will be in the next split VM series, later this week.

Quoted 4 lines
Quoted 4 lines
mm/vmscan.c +0 -0
@@ -1163,6 +1165,8 @@ force_reclaim_mapped:
 			__mod_zone_page_state(zone, NR_ACTIVE, pgmoved);
 			pgmoved = 0;
 			spin_unlock_irq(&zone->lru_lock);
Quoted 8 lines

mm/vmscan.c force_reclaim_mapped: · line 1172

Quoted 5 lines
mm/vmscan.c +2 -0
+			if (vm_swap_full())
+				pagevec_swap_free(&pvec);
 			__pagevec_release(&pvec);
 			spin_lock_irq(&zone->lru_lock);
 		}

Same here. Maybe the spin_unlock and the spin_lock can go into pagevec_swap_free?

We need to unlock the zone->lru_lock across the
__pagevec_release(), which is why the unlock/lock
sequence was already there in the original code.

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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>
#6 lore raw

RFC PATCH 3/10 define page_file_cache

In reply to Rik van Riel

Define page_file_cache() function to answer the question:
is page backed by a file?

Originally part of Rik van Riel's split-lru patch. Extracted to make available for other, independent reclaim patches.

Moved inline function to linux/mm_inline.h where it will be needed by subsequent "split LRU" and "noreclaim" patches.

Unfortunately this needs to use a page flag, since the PG_swapbacked state needs to be preserved all the way to the point where the page is last removed from the LRU. Trying to derive the status from other info in the page resulted in wrong VM statistics in earlier split VM patchsets.

include/linux/mm_inline.h +21 -0
Index: linux-2.6.23-mm1/include/linux/mm_inline.h
===================================================================
@@ -1,3 +1,23 @@
+#ifndef LINUX_MM_INLINE_H
+#define LINUX_MM_INLINE_H
+
+/**
+ * page_file_cache(@page)
+ * Returns !0 if @page is page cache page backed by a regular file,
+ * or 0 if @page is anonymous, tmpfs or otherwise swap backed.
+ *
+ * We would like to get this info without a page flag, but the state
+ * needs to propagate to whereever the page is last deleted from the LRU.
+ */
+static inline int page_file_cache(struct page *page)
+{
+	if (PageSwapBacked(page))
+		return 0;
+
+	/* The page is page cache backed by a normal filesystem. */
+	return 2;
+}
+
 static inline void
 add_page_to_active_list(struct zone *zone, struct page *page)
 {
@@ -38,3 +58,4 @@ del_page_from_lru(struct zone *zone, str
 	}
 }
 
+#endif
mm/shmem.c +1 -0
Index: linux-2.6.23-mm1/mm/shmem.c
===================================================================
@@ -1267,6 +1267,7 @@ repeat:
 				goto failed;
 			}
 
+			SetPageSwapBacked(filepage);
 			spin_lock(&info->lock);
 			entry = shmem_swp_alloc(info, idx, sgp);
 			if (IS_ERR(entry))
include/linux/page-flags.h +5 -0
Index: linux-2.6.23-mm1/include/linux/page-flags.h
===================================================================
@@ -89,6 +89,7 @@
 #define PG_mappedtodisk		16	/* Has blocks allocated on-disk */
 #define PG_reclaim		17	/* To be reclaimed asap */
 #define PG_buddy		19	/* Page is free, on buddy lists */
+#define PG_swapbacked		20	/* Page is backed by RAM/swap */
 
 /* PG_readahead is only used for file reads; PG_reclaim is only for writes */
 #define PG_readahead		PG_reclaim /* Reminder to do async read-ahead */
@@ -216,6 +217,10 @@ static inline void SetPageUptodate(struc
 #define ClearPageReclaim(page)	clear_bit(PG_reclaim, &(page)->flags)
 #define TestClearPageReclaim(page) test_and_clear_bit(PG_reclaim, &(page)->flags)
 
+#define PageSwapBacked(page)	test_bit(PG_swapbacked, &(page)->flags)
+#define SetPageSwapBacked(page)	set_bit(PG_swapbacked, &(page)->flags)
+#define __ClearPageSwapBacked(page)	__clear_bit(PG_swapbacked, &(page)->flags)
+
 #define PageCompound(page)	test_bit(PG_compound, &(page)->flags)
 #define __SetPageCompound(page)	__set_bit(PG_compound, &(page)->flags)
 #define __ClearPageCompound(page) __clear_bit(PG_compound, &(page)->flags)
mm/memory.c +3 -0
Index: linux-2.6.23-mm1/mm/memory.c
===================================================================
@@ -1669,6 +1669,7 @@ gotten:
 		ptep_clear_flush(vma, address, page_table);
 		set_pte_at(mm, address, page_table, entry);
 		update_mmu_cache(vma, address, entry);
+		SetPageSwapBacked(new_page);
 		lru_cache_add_active(new_page);
 		page_add_new_anon_rmap(new_page, vma, address);
 
@@ -2198,6 +2199,7 @@ static int do_anonymous_page(struct mm_s
 	if (!pte_none(*page_table))
 		goto release;
 	inc_mm_counter(mm, anon_rss);
+	SetPageSwapBacked(page);
 	lru_cache_add_active(page);
 	page_add_new_anon_rmap(page, vma, address);
 	set_pte_at(mm, address, page_table, entry);
@@ -2351,6 +2353,7 @@ static int __do_fault(struct mm_struct *
 		set_pte_at(mm, address, page_table, entry);
 		if (anon) {
                         inc_mm_counter(mm, anon_rss);
+			SetPageSwapBacked(page);
                         lru_cache_add_active(page);
                         page_add_new_anon_rmap(page, vma, address);
 		} else {
mm/swap_state.c +1 -0
Index: linux-2.6.23-mm1/mm/swap_state.c
===================================================================
@@ -91,6 +91,7 @@ static int __add_to_swap_cache(struct pa
 		if (!error) {
 			page_cache_get(page);
 			SetPageSwapCache(page);
+			SetPageSwapBacked(page);
 			set_page_private(page, entry.val);
 			total_swapcache_pages++;
 			__inc_zone_page_state(page, NR_FILE_PAGES);
mm/migrate.c +2 -0
Index: linux-2.6.23-mm1/mm/migrate.c
===================================================================
@@ -551,6 +551,8 @@ static int move_to_new_page(struct page 
 	/* Prepare mapping for the new page.*/
 	newpage->index = page->index;
 	newpage->mapping = page->mapping;
+	if (PageSwapBacked(page))
+		SetPageSwapBacked(newpage);
 
 	mapping = page_mapping(page);
 	if (!mapping)
mm/page_alloc.c +4 -0
Index: linux-2.6.23-mm1/mm/page_alloc.c
===================================================================
@@ -253,6 +253,7 @@ static void bad_page(struct page *page)
 			1 << PG_slab    |
 			1 << PG_swapcache |
 			1 << PG_writeback |
+			1 << PG_swapbacked |
 			1 << PG_buddy );
 	set_page_count(page, 0);
 	reset_page_mapcount(page);
@@ -486,6 +487,8 @@ static inline int free_pages_check(struc
 		bad_page(page);
 	if (PageDirty(page))
 		__ClearPageDirty(page);
+	if (PageSwapBacked(page))
+		__ClearPageSwapBacked(page);
 	/*
 	 * For now, we report if PG_reserved was found set, but do not
 	 * clear it, and do not free the page.  But we shall soon need
@@ -632,6 +635,7 @@ static int prep_new_page(struct page *pa
 			1 << PG_swapcache |
 			1 << PG_writeback |
 			1 << PG_reserved |
+			1 << PG_swapbacked |
 			1 << PG_buddy ))))
 		bad_page(page);
 

--
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>

#7 lore raw

Re: [RFC PATCH 3/10] define page_file_cache

Quoted 2 lines · Rik van Riel

Define page_file_cache() function to answer the question:
is page backed by a file?

Well its not clear what is meant by a file in the first place. By file you mean disk space in contrast to ram based filesystems?

I think we could add a flag to the bdi to indicate wheter the backing store is a disk file. In fact you can also deduce if if a device has no writeback capability set in the BDI.

Quoted 6 lines

Unfortunately this needs to use a page flag, since the PG_swapbacked state needs to be preserved all the way to the point where the page is last removed from the LRU. Trying to derive the status from other info in the page resulted in wrong VM statistics in earlier split VM patchsets.

The bdi may avoid that extra flag.

--
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>

#8 lore raw

Re: [RFC PATCH 3/10] define page_file_cache

Quoted 7 lines · On Tue, 6 Nov 2007 18:23:44 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 2 lines · Rik van Riel

Define page_file_cache() function to answer the question:
is page backed by a file?

Well its not clear what is meant by a file in the first place. By file you mean disk space in contrast to ram based filesystems?

Yes. I have improved the comment over page_file_cache() a bit:

/**
* page_file_cache(@page)
* Returns !0 if @page is page cache page backed by a regular filesystem,
* or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed. *
* We would like to get this info without a page flag, but the state
* needs to survive until the page is last deleted from the LRU, which
* could be as far down as __page_cache_release.
*/

Quoted 4 lines

I think we could add a flag to the bdi to indicate wheter the backing store is a disk file. In fact you can also deduce if if a device has no writeback capability set in the BDI.

Quoted 8 lines
Quoted 6 lines

Unfortunately this needs to use a page flag, since the PG_swapbacked state needs to be preserved all the way to the point where the page is last removed from the LRU. Trying to derive the status from other info in the page resulted in wrong VM statistics in earlier split VM patchsets.

The bdi may avoid that extra flag.

The bdi will no longer be accessible by the time a page makes it to free_hot_cold_page, which is one place in the kernel where this information is needed.

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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>
#9 lore raw

Re: [RFC PATCH 3/10] define page_file_cache

Quoted 11 lines · Rik van Riel
Quoted 11 lines

I think we could add a flag to the bdi to indicate wheter the backing store is a disk file. In fact you can also deduce if if a device has no writeback capability set in the BDI.

Quoted 6 lines

Unfortunately this needs to use a page flag, since the PG_swapbacked state needs to be preserved all the way to the point where the page is last removed from the LRU. Trying to derive the status from other info in the page resulted in wrong VM statistics in earlier split VM patchsets.

Quoted 5 lines
Quoted 1 line

The bdi may avoid that extra flag.

The bdi will no longer be accessible by the time a page makes it to free_hot_cold_page, which is one place in the kernel where this information is needed.

At that point you need only information about which list the page was put on. Dont we need something like PageLRU -> PageFileLRU and PageMemLRU?

The page may change its nature I think? What if a page becomes swap backed?

--
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>

#10 lore raw

Re: [RFC PATCH 3/10] define page_file_cache

Quoted 15 lines · On Tue, 6 Nov 2007 19:02:47 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 13 lines · Rik van Riel
Quoted 12 lines

I think we could add a flag to the bdi to indicate wheter the backing store is a disk file. In fact you can also deduce if if a device has no writeback capability set in the BDI.

Quoted 6 lines

Unfortunately this needs to use a page flag, since the PG_swapbacked state needs to be preserved all the way to the point where the page is last removed from the LRU. Trying to derive the status from other info in the page resulted in wrong VM statistics in earlier split VM patchsets.

The bdi may avoid that extra flag.

Quoted 7 lines
Quoted 3 lines

The bdi will no longer be accessible by the time a page makes it to free_hot_cold_page, which is one place in the kernel where this information is needed.

At that point you need only information about which list the page was put on. Dont we need something like PageLRU -> PageFileLRU and PageMemLRU?

That is exactly why we need a page flag. If you have a better name for the page flag, please let me know.

Note that the kind of page needs to be separate from PageLRU, since pages are taken off of and put back onto LRUs all the time.

Quoted 2 lines

The page may change its nature I think? What if a page becomes swap backed?

Every anonymous, tmpfs or shared memory segment page is potentially swap backed. That is the whole point of the PG_swapbacked flag.

A page from a filesystem like ext3 or NFS cannot suddenly turn into a swap backed page. This page "nature" is not changed during the lifetime of a page.

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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>
#11 lore raw

Re: [RFC PATCH 3/10] define page_file_cache

Quoted 2 lines · Rik van Riel

Every anonymous, tmpfs or shared memory segment page is potentially swap backed. That is the whole point of the PG_swapbacked flag.

One of the current issues with anonymous pages is the accounting when they become file backed and get dirty. There are performance issue with swap writeout because we are not doing it in file order and on a page by page basis.

Do ramfs pages count as memory backed?

Quoted 3 lines

A page from a filesystem like ext3 or NFS cannot suddenly turn into a swap backed page. This page "nature" is not changed during the lifetime of a page.

Well COW sortof does that but then its a new page.

--
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>

#12 lore raw

Re: [RFC PATCH 3/10] define page_file_cache

Quoted 7 lines · On Tue, 6 Nov 2007 19:26:33 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 2 lines · Rik van Riel

Every anonymous, tmpfs or shared memory segment page is potentially swap backed. That is the whole point of the PG_swapbacked flag.

One of the current issues with anonymous pages is the accounting when they become file backed and get dirty.

What are you talking about?

How exactly can an anonymous page ever become file backed?

Quoted 1 line

There are performance issue with swap writeout

That is one of the reasons everything that is ram/swap backed goes onto a different set of LRU lists from everything that is backed by a disk or network filesystem.

Quoted 1 line

Do ramfs pages count as memory backed?

Since ramfs pages cannot be evicted from memory at all, they should go into the "noreclaim" page set.

Quoted 5 lines
Quoted 3 lines

A page from a filesystem like ext3 or NFS cannot suddenly turn into a swap backed page. This page "nature" is not changed during the lifetime of a page.

Well COW sortof does that but then its a new page.

Exactly. As far as I know, a page never changes from a file page into an anonymous page, or the other way around.

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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>
#13 lore raw

Re: [RFC PATCH 3/10] define page_file_cache

Quoted 1 line · Rik van Riel

How exactly can an anonymous page ever become file backed?

When they get assigned a swap entry.

Quoted 4 lines
Quoted 1 line

Do ramfs pages count as memory backed?

Since ramfs pages cannot be evicted from memory at all, they should go into the "noreclaim" page set.

Which LRU do they go on.

--
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>

#14 lore raw

Re: [RFC PATCH 3/10] define page_file_cache

Quoted 5 lines · On Wed, 7 Nov 2007 10:06:10 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 1 line · Rik van Riel

How exactly can an anonymous page ever become file backed?

When they get assigned a swap entry.

That does not change their status. They're still swap backed.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Do ramfs pages count as memory backed?

Since ramfs pages cannot be evicted from memory at all, they should go into the "noreclaim" page set.

Which LRU do they go on.

With the patch set from last weekend, the file LRU.

With the patch set later this week, they'll be in the "noreclaim" page set, which is never scanned by the VM.

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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>
#15 lore raw

Re: [RFC PATCH 3/10] define page_file_cache

Quoted 10 lines · Rik van Riel
Quoted 5 lines · On Wed, 7 Nov 2007 10:06:10 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 1 line · Rik van Riel

How exactly can an anonymous page ever become file backed?

When they get assigned a swap entry.

That does not change their status. They're still swap backed.

If they are swap backed then they have a backing store on disk. They are file backed in some sense.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Do ramfs pages count as memory backed?

Since ramfs pages cannot be evicted from memory at all, they should go into the "noreclaim" page set.

Which LRU do they go on.

With the patch set from last weekend, the file LRU.

Argh.

Quoted 2 lines

With the patch set later this week, they'll be in the "noreclaim" page set, which is never scanned by the VM.

That sounds better.

--
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>

#16 lore raw

RFC PATCH 4/10 debug page_file_cache

In reply to Rik van Riel

Debug whether we end up classifying the wrong pages as filesystem backed. This has not triggered in stress tests on my system, but who knows...

include/linux/mm_inline.h +10 -0
Index: linux-2.6.23-mm1/include/linux/mm_inline.h
===================================================================
@@ -1,6 +1,8 @@
 #ifndef LINUX_MM_INLINE_H
 #define LINUX_MM_INLINE_H
 
+#include <linux/fs.h>  /* for struct address_space */
+
 /**
  * page_file_cache(@page)
  * Returns !0 if @page is page cache page backed by a regular file,
@@ -9,11 +11,19 @@
  * We would like to get this info without a page flag, but the state
  * needs to propagate to whereever the page is last deleted from the LRU.
  */
+extern const struct address_space_operations shmem_aops;
 static inline int page_file_cache(struct page *page)
 {
+	struct address_space * mapping = page_mapping(page);
+
 	if (PageSwapBacked(page))
 		return 0;
 
+	/* These pages should all be marked PG_swapbacked */
+	WARN_ON(PageAnon(page));
+	WARN_ON(PageSwapCache(page));
+	WARN_ON(mapping && mapping->a_ops && mapping->a_ops == &shmem_aops);
+
 	/* The page is page cache backed by a normal filesystem. */
 	return 2;
 }
mm/shmem.c +2 -2
Index: linux-2.6.23-mm1/mm/shmem.c
===================================================================
@@ -180,7 +180,7 @@ static inline void shmem_unacct_blocks(u
 }
 
 static const struct super_operations shmem_ops;
-static const struct address_space_operations shmem_aops;
+const struct address_space_operations shmem_aops;
 static const struct file_operations shmem_file_operations;
 static const struct inode_operations shmem_inode_operations;
 static const struct inode_operations shmem_dir_inode_operations;
@@ -2344,7 +2344,7 @@ static void destroy_inodecache(void)
 	kmem_cache_destroy(shmem_inode_cachep);
 }
 
-static const struct address_space_operations shmem_aops = {
+const struct address_space_operations shmem_aops = {
 	.writepage	= shmem_writepage,
 	.set_page_dirty	= __set_page_dirty_no_writeback,
 #ifdef CONFIG_TMPFS

--
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>

#17 lore raw

RFC PATCH 5/10 use an indexed array for LRU lists and variables

In reply to Rik van Riel

Use an indexed array for LRU variables. This makes the rest of the split VM code a lot cleaner.

V1 -> V2 [lts]:
+ Remove extraneous __dec_zone_state(zone, NR_ACTIVE) pointed out by Mel G.

#18 lore raw

RFC PATCH 6/10 split anon and file LRUs

In reply to Rik van Riel

Split the LRU lists in two, one set for pages that are backed by real file systems ("file") and one for pages that are backed by memory and swap ("anon"). The latter includes tmpfs.

Eventually mlocked pages will be taken off the LRUs alltogether. A patch for that already exists and just needs to be integrated into this series.

This patch mostly has the infrastructure and a basic policy to balance how much we scan the anon lists and how much we scan the file lists. Fancy policy changes will be in separate patches.

fs/proc/proc_misc.c +35 -31
Index: linux-2.6.23-mm1/fs/proc/proc_misc.c
===================================================================
@@ -149,43 +149,47 @@ static int meminfo_read_proc(char *page,
 	 * Tagged format, for easy grepping and expansion.
 	 */
 	len = sprintf(page,
-		"MemTotal:     %8lu kB\n"
-		"MemFree:      %8lu kB\n"
-		"Buffers:      %8lu kB\n"
-		"Cached:       %8lu kB\n"
-		"SwapCached:   %8lu kB\n"
-		"Active:       %8lu kB\n"
-		"Inactive:     %8lu kB\n"
+		"MemTotal:       %8lu kB\n"
+		"MemFree:        %8lu kB\n"
+		"Buffers:        %8lu kB\n"
+		"Cached:         %8lu kB\n"
+		"SwapCached:     %8lu kB\n"
+		"Active(anon):   %8lu kB\n"
+		"Inactive(anon): %8lu kB\n"
+		"Active(file):   %8lu kB\n"
+		"Inactive(file): %8lu kB\n"
 #ifdef CONFIG_HIGHMEM
-		"HighTotal:    %8lu kB\n"
-		"HighFree:     %8lu kB\n"
-		"LowTotal:     %8lu kB\n"
-		"LowFree:      %8lu kB\n"
-#endif
-		"SwapTotal:    %8lu kB\n"
-		"SwapFree:     %8lu kB\n"
-		"Dirty:        %8lu kB\n"
-		"Writeback:    %8lu kB\n"
-		"AnonPages:    %8lu kB\n"
-		"Mapped:       %8lu kB\n"
-		"Slab:         %8lu kB\n"
-		"SReclaimable: %8lu kB\n"
-		"SUnreclaim:   %8lu kB\n"
-		"PageTables:   %8lu kB\n"
-		"NFS_Unstable: %8lu kB\n"
-		"Bounce:       %8lu kB\n"
-		"CommitLimit:  %8lu kB\n"
-		"Committed_AS: %8lu kB\n"
-		"VmallocTotal: %8lu kB\n"
-		"VmallocUsed:  %8lu kB\n"
-		"VmallocChunk: %8lu kB\n",
+		"HighTotal:      %8lu kB\n"
+		"HighFree:       %8lu kB\n"
+		"LowTotal:       %8lu kB\n"
+		"LowFree:        %8lu kB\n"
+#endif
+		"SwapTotal:      %8lu kB\n"
+		"SwapFree:       %8lu kB\n"
+		"Dirty:          %8lu kB\n"
+		"Writeback:      %8lu kB\n"
+		"AnonPages:      %8lu kB\n"
+		"Mapped:         %8lu kB\n"
+		"Slab:           %8lu kB\n"
+		"SReclaimable:   %8lu kB\n"
+		"SUnreclaim:     %8lu kB\n"
+		"PageTables:     %8lu kB\n"
+		"NFS_Unstable:   %8lu kB\n"
+		"Bounce:         %8lu kB\n"
+		"CommitLimit:    %8lu kB\n"
+		"Committed_AS:   %8lu kB\n"
+		"VmallocTotal:   %8lu kB\n"
+		"VmallocUsed:    %8lu kB\n"
+		"VmallocChunk:   %8lu kB\n",
 		K(i.totalram),
 		K(i.freeram),
 		K(i.bufferram),
 		K(cached),
 		K(total_swapcache_pages),
-		K(global_page_state(NR_ACTIVE)),
-		K(global_page_state(NR_INACTIVE)),
+		K(global_page_state(NR_ACTIVE_ANON)),
+		K(global_page_state(NR_INACTIVE_ANON)),
+		K(global_page_state(NR_ACTIVE_FILE)),
+		K(global_page_state(NR_INACTIVE_FILE)),
 #ifdef CONFIG_HIGHMEM
 		K(i.totalhigh),
 		K(i.freehigh),
fs/cifs/file.c +2 -2
Index: linux-2.6.23-mm1/fs/cifs/file.c
===================================================================
@@ -1740,7 +1740,7 @@ static void cifs_copy_cache_pages(struct
 		SetPageUptodate(page);
 		unlock_page(page);
 		if (!pagevec_add(plru_pvec, page))
-			__pagevec_lru_add(plru_pvec);
+			__pagevec_lru_add_file(plru_pvec);
 		data += PAGE_CACHE_SIZE;
 	}
 	return;
@@ -1878,7 +1878,7 @@ static int cifs_readpages(struct file *f
 		bytes_read = 0;
 	}
 
-	pagevec_lru_add(&lru_pvec);
+	pagevec_lru_add_file(&lru_pvec);
 
 /* need to free smb_read_data buf before exit */
 	if (smb_read_data) {
fs/ntfs/file.c +2 -2
Index: linux-2.6.23-mm1/fs/ntfs/file.c
===================================================================
@@ -439,7 +439,7 @@ static inline int __ntfs_grab_cache_page
 			pages[nr] = *cached_page;
 			page_cache_get(*cached_page);
 			if (unlikely(!pagevec_add(lru_pvec, *cached_page)))
-				__pagevec_lru_add(lru_pvec);
+				__pagevec_lru_add_file(lru_pvec);
 			*cached_page = NULL;
 		}
 		index++;
@@ -2087,7 +2087,7 @@ err_out:
 						OSYNC_METADATA|OSYNC_DATA);
 		}
   	}
-	pagevec_lru_add(&lru_pvec);
+	pagevec_lru_add_file(&lru_pvec);
 	ntfs_debug("Done.  Returning %s (written 0x%lx, status %li).",
 			written ? "written" : "status", (unsigned long)written,
 			(long)status);
fs/nfs/dir.c +1 -1
Index: linux-2.6.23-mm1/fs/nfs/dir.c
===================================================================
@@ -1488,7 +1488,7 @@ static int nfs_symlink(struct inode *dir
 	if (!add_to_page_cache(page, dentry->d_inode->i_mapping, 0,
 							GFP_KERNEL)) {
 		pagevec_add(&lru_pvec, page);
-		pagevec_lru_add(&lru_pvec);
+		pagevec_lru_add_file(&lru_pvec);
 		SetPageUptodate(page);
 		unlock_page(page);
 	} else
fs/ramfs/file-nommu.c +4 -2
Index: linux-2.6.23-mm1/fs/ramfs/file-nommu.c
===================================================================
@@ -110,13 +110,15 @@ static int ramfs_nommu_expand_for_mappin
 		if (ret < 0)
 			goto add_error;
 
+//TODO:  how does this interact w/ vmscan and use of page_file_cache()?
+//       don't want to test ramfs there...
 		if (!pagevec_add(&lru_pvec, page))
-			__pagevec_lru_add(&lru_pvec);
+			__pagevec_lru_add_anon(&lru_pvec);
 
 		unlock_page(page);
 	}
 
-	pagevec_lru_add(&lru_pvec);
+	pagevec_lru_add_anon(&lru_pvec);
 	return 0;
 
  fsize_exceeded:
drivers/base/node.c +26 -22

59 lines not on this page · raw message

mm/memory.c +3 -3
Index: linux-2.6.23-mm1/mm/memory.c
===================================================================
@@ -1670,7 +1670,7 @@ gotten:
 		set_pte_at(mm, address, page_table, entry);
 		update_mmu_cache(vma, address, entry);
 		SetPageSwapBacked(new_page);
-		lru_cache_add_active(new_page);
+		lru_cache_add_active_anon(new_page);
 		page_add_new_anon_rmap(new_page, vma, address);
 
 		/* Free the old page.. */
@@ -2200,7 +2200,7 @@ static int do_anonymous_page(struct mm_s
 		goto release;
 	inc_mm_counter(mm, anon_rss);
 	SetPageSwapBacked(page);
-	lru_cache_add_active(page);
+	lru_cache_add_active_anon(page);
 	page_add_new_anon_rmap(page, vma, address);
 	set_pte_at(mm, address, page_table, entry);
 
@@ -2354,7 +2354,7 @@ static int __do_fault(struct mm_struct *
 		if (anon) {
                         inc_mm_counter(mm, anon_rss);
 			SetPageSwapBacked(page);
-                        lru_cache_add_active(page);
+                        lru_cache_add_active_anon(page);
                         page_add_new_anon_rmap(page, vma, address);
 		} else {
 			inc_mm_counter(mm, file_rss);
mm/page_alloc.c +17 -7
Index: linux-2.6.23-mm1/mm/page_alloc.c
===================================================================
@@ -1904,10 +1904,13 @@ void show_free_areas(void)
 		}
 	}
 
-	printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n"
+	printk("Active_anon:%lu active_file:%lu inactive_anon%lu\n"
+		" inactive_file:%lu dirty:%lu writeback:%lu unstable:%lu\n"
 		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
-		global_page_state(NR_ACTIVE),
-		global_page_state(NR_INACTIVE),
+		global_page_state(NR_ACTIVE_ANON),
+		global_page_state(NR_ACTIVE_FILE),
+		global_page_state(NR_INACTIVE_ANON),
+		global_page_state(NR_INACTIVE_FILE),
 		global_page_state(NR_FILE_DIRTY),
 		global_page_state(NR_WRITEBACK),
 		global_page_state(NR_UNSTABLE_NFS),
@@ -1930,8 +1933,10 @@ void show_free_areas(void)
 			" min:%lukB"
 			" low:%lukB"
 			" high:%lukB"
-			" active:%lukB"
-			" inactive:%lukB"
+			" active_anon:%lukB"
+			" inactive_anon:%lukB"
+			" active_file:%lukB"
+			" inactive_file:%lukB"
 			" present:%lukB"
 			" pages_scanned:%lu"
 			" all_unreclaimable? %s"
@@ -1941,8 +1946,10 @@ void show_free_areas(void)
 			K(zone->pages_min),
 			K(zone->pages_low),
 			K(zone->pages_high),
-			K(zone_page_state(zone, NR_ACTIVE)),
-			K(zone_page_state(zone, NR_INACTIVE)),
+			K(zone_page_state(zone, NR_ACTIVE_ANON)),
+			K(zone_page_state(zone, NR_INACTIVE_ANON)),
+			K(zone_page_state(zone, NR_ACTIVE_FILE)),
+			K(zone_page_state(zone, NR_INACTIVE_FILE)),
 			K(zone->present_pages),
 			zone->pages_scanned,
 			(zone_is_all_unreclaimable(zone) ? "yes" : "no")
@@ -3470,6 +3477,9 @@ static void __meminit free_area_init_cor
 			INIT_LIST_HEAD(&zone->list[l]);
 			zone->nr_scan[l] = 0;
 		}
+		zone->recent_rotated_anon = 0;
+		zone->recent_rotated_file = 0;
+//TODO recent_scanned_* ???
 		zap_zone_vm_stats(zone);
 		zone->flags = 0;
 		if (!size)
mm/swap.c +112 -21

205 lines not on this page · raw message

mm/migrate.c +8 -2
Index: linux-2.6.23-mm1/mm/migrate.c
===================================================================
@@ -60,9 +60,15 @@ static inline void move_to_lru(struct pa
 		 * the PG_active bit is off.
 		 */
 		ClearPageActive(page);
-		lru_cache_add_active(page);
+		if (page_file_cache(page))
+			lru_cache_add_active_file(page);
+		else
+			lru_cache_add_active_anon(page);
 	} else {
-		lru_cache_add(page);
+		if (page_file_cache(page))
+			lru_cache_add_file(page);
+		else
+			lru_cache_add_anon(page);
 	}
 	put_page(page);
 }
mm/readahead.c +1 -1
Index: linux-2.6.23-mm1/mm/readahead.c
===================================================================
@@ -229,7 +229,7 @@ int do_page_cache_readahead(struct addre
  */
 unsigned long max_sane_readahead(unsigned long nr)
 {
-	return min(nr, (node_page_state(numa_node_id(), NR_INACTIVE)
+	return min(nr, (node_page_state(numa_node_id(), NR_INACTIVE_FILE)
 		+ node_page_state(numa_node_id(), NR_FREE_PAGES)) / 2);
 }
 
mm/filemap.c +7 -2
Index: linux-2.6.23-mm1/mm/filemap.c
===================================================================
@@ -32,6 +32,7 @@
 #include <linux/cpuset.h>
 #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */
 #include <linux/memcontrol.h>
+#include <linux/mm_inline.h> /* for page_file_cache() */
 #include "internal.h"
 
 /*
@@ -474,8 +475,12 @@ int add_to_page_cache_lru(struct page *p
 				pgoff_t offset, gfp_t gfp_mask)
 {
 	int ret = add_to_page_cache(page, mapping, offset, gfp_mask);
-	if (ret == 0)
-		lru_cache_add(page);
+	if (ret == 0) {
+		if (page_file_cache(page))
+			lru_cache_add_file(page);
+		else
+			lru_cache_add_active_anon(page);
+	}
 	return ret;
 }
 
mm/vmstat.c +9 -5
Index: linux-2.6.23-mm1/mm/vmstat.c
===================================================================
@@ -684,8 +684,10 @@ const struct seq_operations pagetypeinfo
 static const char * const vmstat_text[] = {
 	/* Zoned VM counters */
 	"nr_free_pages",
-	"nr_inactive",
-	"nr_active",
+	"nr_inactive_anon",
+	"nr_active_anon",
+	"nr_inactive_file",
+	"nr_active_file",
 	"nr_anon_pages",
 	"nr_mapped",
 	"nr_file_pages",
@@ -748,7 +750,7 @@ static void zoneinfo_show_print(struct s
 		   "\n        min      %lu"
 		   "\n        low      %lu"
 		   "\n        high     %lu"
-		   "\n        scanned  %lu (a: %lu i: %lu)"
+		   "\n        scanned  %lu (aa: %lu ia: %lu af: %lu if: %lu)"
 		   "\n        spanned  %lu"
 		   "\n        present  %lu",
 		   zone_page_state(zone, NR_FREE_PAGES),
@@ -756,8 +758,10 @@ static void zoneinfo_show_print(struct s
 		   zone->pages_low,
 		   zone->pages_high,
 		   zone->pages_scanned,
-		   zone->nr_scan[LRU_ACTIVE],
-		   zone->nr_scan[LRU_INACTIVE],
+		   zone->nr_scan[LRU_ACTIVE_ANON],
+		   zone->nr_scan[LRU_INACTIVE_ANON],
+		   zone->nr_scan[LRU_ACTIVE_FILE],
+		   zone->nr_scan[LRU_INACTIVE_FILE],
 		   zone->spanned_pages,
 		   zone->present_pages);
 
mm/vmscan.c +180 -182

629 lines not on this page · raw message

mm/swap_state.c +1 -1
Index: linux-2.6.23-mm1/mm/swap_state.c
===================================================================
@@ -370,7 +370,7 @@ struct page *read_swap_cache_async(swp_e
 			/*
 			 * Initiate read into locked page and return.
 			 */
-			lru_cache_add_active(new_page);
+			lru_cache_add_active_anon(new_page);
 			swap_readpage(NULL, new_page);
 			return new_page;
 		}
include/linux/mmzone.h +19 -5
Index: linux-2.6.23-mm1/include/linux/mmzone.h
===================================================================
@@ -80,21 +80,23 @@ struct zone_padding {
 enum zone_stat_item {
 	/* First 128 byte cacheline (assuming 64 bit words) */
 	NR_FREE_PAGES,
-	NR_INACTIVE,	/* must match order of LRU_[IN]ACTIVE */
-	NR_ACTIVE,	/*  "     "     "   "       "         */
+	NR_INACTIVE_ANON,	/* must match order of LRU_[IN]ACTIVE_* */
+	NR_ACTIVE_ANON,		/*  "     "     "   "       "           */
+	NR_INACTIVE_FILE,	/*  "     "     "   "       "           */
+	NR_ACTIVE_FILE,		/*  "     "     "   "       "           */
 	NR_ANON_PAGES,	/* Mapped anonymous pages */
 	NR_FILE_MAPPED,	/* pagecache pages mapped into pagetables.
 			   only modified from process context */
 	NR_FILE_PAGES,
 	NR_FILE_DIRTY,
 	NR_WRITEBACK,
-	/* Second 128 byte cacheline */
 	NR_SLAB_RECLAIMABLE,
 	NR_SLAB_UNRECLAIMABLE,
 	NR_PAGETABLE,		/* used for pagetables */
 	NR_UNSTABLE_NFS,	/* NFS unstable pages */
 	NR_BOUNCE,
 	NR_VMSCAN_WRITE,
+	/* Second 128 byte cacheline */
 #ifdef CONFIG_NUMA
 	NUMA_HIT,		/* allocated in intended node */
 	NUMA_MISS,		/* allocated in non intended node */
@@ -106,12 +108,20 @@ enum zone_stat_item {
 	NR_VM_ZONE_STAT_ITEMS };
 
 enum lru_list {
-	LRU_INACTIVE,	/* must match order of NR_[IN]ACTIVE */
-	LRU_ACTIVE,	/*  "     "     "   "       "        */
+	LRU_INACTIVE_ANON,	/* must be first enum  */
+	LRU_ACTIVE_ANON,	/* must match order of NR_[IN]ACTIVE_* */
+	LRU_INACTIVE_FILE,	/*  "     "     "   "       "          */
+	LRU_ACTIVE_FILE,	/*  "     "     "   "       "          */
 	NR_LRU_LISTS };
 
 #define for_each_lru(l) for (l = 0; l < NR_LRU_LISTS; l++)
 
+static inline int is_file_lru(enum lru_list l)
+{
+	BUILD_BUG_ON(LRU_INACTIVE_FILE != 2 || LRU_ACTIVE_FILE != 3);
+	return (l/2 == 1);
+}
+
 struct per_cpu_pages {
 	int count;		/* number of pages in the list */
 	int high;		/* high watermark, emptying needed */
@@ -267,6 +277,10 @@ struct zone {
 	spinlock_t		lru_lock;	
 	struct list_head	list[NR_LRU_LISTS];
 	unsigned long		nr_scan[NR_LRU_LISTS];
+
+	unsigned long		recent_rotated_anon;
+	unsigned long		recent_rotated_file;
+
 	unsigned long		pages_scanned;	   /* since last reclaim */
 	unsigned long		flags;		   /* zone flags, see below */
 
include/linux/mm_inline.h +39 -14

98 lines not on this page · raw message

include/linux/pagevec.h +12 -4
Index: linux-2.6.23-mm1/include/linux/pagevec.h
===================================================================
@@ -23,8 +23,10 @@ struct pagevec {
 void __pagevec_release(struct pagevec *pvec);
 void __pagevec_release_nonlru(struct pagevec *pvec);
 void __pagevec_free(struct pagevec *pvec);
-void __pagevec_lru_add(struct pagevec *pvec);
-void __pagevec_lru_add_active(struct pagevec *pvec);
+void __pagevec_lru_add_file(struct pagevec *pvec);
+void __pagevec_lru_add_active_file(struct pagevec *pvec);
+void __pagevec_lru_add_anon(struct pagevec *pvec);
+void __pagevec_lru_add_active_anon(struct pagevec *pvec);
 void pagevec_strip(struct pagevec *pvec);
 void pagevec_swap_free(struct pagevec *pvec);
 unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
@@ -82,10 +84,16 @@ static inline void pagevec_free(struct p
 		__pagevec_free(pvec);
 }
 
-static inline void pagevec_lru_add(struct pagevec *pvec)
+static inline void pagevec_lru_add_file(struct pagevec *pvec)
 {
 	if (pagevec_count(pvec))
-		__pagevec_lru_add(pvec);
+		__pagevec_lru_add_file(pvec);
+}
+
+static inline void pagevec_lru_add_anon(struct pagevec *pvec)
+{
+	if (pagevec_count(pvec))
+		__pagevec_lru_add_anon(pvec);
 }
 
 #endif /* _LINUX_PAGEVEC_H */
include/linux/vmstat.h +10 -0
Index: linux-2.6.23-mm1/include/linux/vmstat.h
===================================================================
@@ -149,6 +149,16 @@ static inline unsigned long zone_page_st
 	return x;
 }
 
+extern unsigned long global_lru_pages(void);
+
+static inline unsigned long zone_lru_pages(struct zone *zone)
+{
+	return (zone_page_state(zone, NR_ACTIVE_ANON)
+		+ zone_page_state(zone, NR_ACTIVE_FILE)
+		+ zone_page_state(zone, NR_INACTIVE_ANON)
+		+ zone_page_state(zone, NR_INACTIVE_FILE));
+}
+
 #ifdef CONFIG_NUMA
 /*
  * Determine the per node value of a stat item. This function
mm/page-writeback.c +2 -6
Index: linux-2.6.23-mm1/mm/page-writeback.c
===================================================================
@@ -264,9 +264,7 @@ static unsigned long highmem_dirtyable_m
 		struct zone *z =
 			&NODE_DATA(node)->node_zones[ZONE_HIGHMEM];
 
-		x += zone_page_state(z, NR_FREE_PAGES)
-			+ zone_page_state(z, NR_INACTIVE)
-			+ zone_page_state(z, NR_ACTIVE);
+		x += zone_page_state(z, NR_FREE_PAGES) + zone_lru_pages(z);
 	}
 	/*
 	 * Make sure that the number of highmem pages is never larger
@@ -284,9 +282,7 @@ static unsigned long determine_dirtyable
 {
 	unsigned long x;
 
-	x = global_page_state(NR_FREE_PAGES)
-		+ global_page_state(NR_INACTIVE)
-		+ global_page_state(NR_ACTIVE);
+	x = global_page_state(NR_FREE_PAGES) + global_lru_pages();
 	x -= highmem_dirtyable_memory(x);
 	return x + 1;	/* Ensure that we never return 0 */
 }
include/linux/swap.h +4 -2
Index: linux-2.6.23-mm1/include/linux/swap.h
===================================================================
@@ -174,8 +174,10 @@ extern unsigned int nr_free_pagecache_pa
 
 
 /* linux/mm/swap.c */
-extern void FASTCALL(lru_cache_add(struct page *));
-extern void FASTCALL(lru_cache_add_active(struct page *));
+extern void FASTCALL(lru_cache_add_file(struct page *));
+extern void FASTCALL(lru_cache_add_anon(struct page *));
+extern void FASTCALL(lru_cache_add_active_file(struct page *));
+extern void FASTCALL(lru_cache_add_active_anon(struct page *));
 extern void FASTCALL(activate_page(struct page *));
 extern void FASTCALL(mark_page_accessed(struct page *));
 extern void lru_add_drain(void);
include/linux/memcontrol.h +1 -1
Index: linux-2.6.23-mm1/include/linux/memcontrol.h
===================================================================
@@ -41,7 +41,7 @@ extern unsigned long mem_cgroup_isolate_
 					unsigned long *scanned, int order,
 					int mode, struct zone *z,
 					struct mem_cgroup *mem_cont,
-					int active);
+					int active, int file);
 extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask);
 extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
 					gfp_t gfp_mask);
mm/memcontrol.c +2 -1
Index: linux-2.6.23-mm1/mm/memcontrol.c
===================================================================
@@ -201,7 +201,7 @@ unsigned long mem_cgroup_isolate_pages(u
 					unsigned long *scanned, int order,
 					int mode, struct zone *z,
 					struct mem_cgroup *mem_cont,
-					int active)
+					int active, int file)
 {
 	unsigned long nr_taken = 0;
 	struct page *page;
@@ -210,6 +210,7 @@ unsigned long mem_cgroup_isolate_pages(u
 	struct list_head *src;
 	struct page_cgroup *pc;
 
+//TODO:  memory container maintain separate file/anon lists?
 	if (active)
 		src = &mem_cont->active_list;
 	else

--
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>

#19 lore raw
Quoted 3 lines · Rik van Riel

Split the LRU lists in two, one set for pages that are backed by real file systems ("file") and one for pages that are backed by memory and swap ("anon"). The latter includes tmpfs.

If we split the memory backed from the disk backed pages then they are no longer competing with one another on equal terms? So the file LRU may run faster than the memory LRU?

The patch looks awfully large.

--
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>

#20 lore raw
Quoted 9 lines · On Tue, 6 Nov 2007 18:28:19 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 3 lines · Rik van Riel

Split the LRU lists in two, one set for pages that are backed by real file systems ("file") and one for pages that are backed by memory and swap ("anon"). The latter includes tmpfs.

If we split the memory backed from the disk backed pages then they are no longer competing with one another on equal terms? So the file LRU may run faster than the memory LRU?

The file LRU probably *should* run faster than the memory LRU most of the time, since we stream the readahead data for many sequentially accessed files through the file LRU.

We adjust the rates at which the two LRUs are scanned depending on the fraction of referenced pages found when scanning each list. Look at vmscan.c:get_scan_ratio() for the magic.

Quoted 1 line

The patch looks awfully large.

Making it smaller would probably result in something that does not work right.

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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>
#21 lore raw

RFC PATCH 7/10 clean up the LRU array arithmetic

In reply to Rik van Riel

Make the LRU arithmetic more explicit. Hopefully this will make the code a little easier to read and less prone to future errors.

include/linux/mm_inline.h +1 -1
Index: linux-2.6.23-mm1/include/linux/mm_inline.h
===================================================================
@@ -28,7 +28,7 @@ static inline int page_file_cache(struct
 		return 0;
 
 	/* The page is page cache backed by a normal filesystem. */
-	return (LRU_INACTIVE_FILE - LRU_INACTIVE_ANON);
+	return LRU_FILE;
 }
 
 static inline void
mm/swap.c +2 -2
Index: linux-2.6.23-mm1/mm/swap.c
===================================================================
@@ -180,12 +180,12 @@ void fastcall activate_page(struct page 
 
 	spin_lock_irq(&zone->lru_lock);
 	if (PageLRU(page) && !PageActive(page)) {
-		int l = LRU_INACTIVE_ANON;
+		int l = LRU_BASE;
 		l += page_file_cache(page);
 		del_page_from_lru_list(zone, page, l);
 
 		SetPageActive(page);
-		l += LRU_ACTIVE_ANON - LRU_INACTIVE_ANON;
+		l += LRU_ACTIVE;
 		add_page_to_lru_list(zone, page, l);
 		__count_vm_event(PGACTIVATE);
 		mem_cgroup_move_lists(page_get_page_cgroup(page), true);
mm/vmscan.c +9 -9
Index: linux-2.6.23-mm1/mm/vmscan.c
===================================================================
@@ -786,11 +786,11 @@ static unsigned long isolate_pages_globa
 					struct mem_cgroup *mem_cont,
 					int active, int file)
 {
-	int l = LRU_INACTIVE_ANON;
+	int l = LRU_BASE;
 	if (active)
-		l += LRU_ACTIVE_ANON - LRU_INACTIVE_ANON;
+		l += LRU_ACTIVE;
 	if (file)
-		l += LRU_INACTIVE_FILE - LRU_INACTIVE_ANON;
+		l += LRU_FILE;
 	return isolate_lru_pages(nr, &z->list[l], dst, scanned, order,
 								mode, !!file);
 }
@@ -842,7 +842,7 @@ int isolate_lru_page(struct page *page)
 
 		spin_lock_irq(&zone->lru_lock);
 		if (PageLRU(page) && get_page_unless_zero(page)) {
-			int l = LRU_INACTIVE_ANON;
+			int l = LRU_BASE;
 			ret = 0;
 			ClearPageLRU(page);
 
@@ -938,19 +938,19 @@ static unsigned long shrink_inactive_lis
 		 * Put back any unfreeable pages.
 		 */
 		while (!list_empty(&page_list)) {
-			int l = LRU_INACTIVE_ANON;
+			int l = LRU_BASE;
 			page = lru_to_page(&page_list);
 			VM_BUG_ON(PageLRU(page));
 			SetPageLRU(page);
 			list_del(&page->lru);
 			if (file) {
-				l += LRU_INACTIVE_FILE - LRU_INACTIVE_ANON;
+				l += LRU_FILE;
 				zone->recent_rotated_file += sc->activated;
 			} else {
 				zone->recent_rotated_anon += sc->activated;
 			}
 			if (PageActive(page))
-				l += LRU_ACTIVE_ANON - LRU_INACTIVE_ANON;
+				l += LRU_ACTIVE;
 			add_page_to_lru_list(zone, page, l);
 			if (!pagevec_add(&pvec, page)) {
 				spin_unlock_irq(&zone->lru_lock);
@@ -1051,7 +1051,7 @@ static void shrink_active_list(unsigned 
 	 */
 	pagevec_init(&pvec, 1);
 	pgmoved = 0;
-	l = LRU_INACTIVE_ANON + file * (LRU_INACTIVE_FILE - LRU_INACTIVE_ANON);
+	l = LRU_BASE + file * LRU_FILE;
 	spin_lock_irq(&zone->lru_lock);
 	while (!list_empty(&list[LRU_INACTIVE_ANON])) {
 		page = lru_to_page(&list[LRU_INACTIVE_ANON]);
@@ -1083,7 +1083,7 @@ static void shrink_active_list(unsigned 
 	if (buffer_heads_over_limit)
 		pagevec_strip(&pvec);
 	pgmoved = 0;
-	l = LRU_ACTIVE_ANON + file * (LRU_ACTIVE_FILE - LRU_ACTIVE_ANON);
+	l = LRU_ACTIVE + file * LRU_FILE;
 	spin_lock_irq(&zone->lru_lock);
 	while (!list_empty(&list[LRU_ACTIVE_ANON])) {
 		page = lru_to_page(&list[LRU_ACTIVE_ANON]);
include/linux/mmzone.h +15 -4
Index: linux-2.6.23-mm1/include/linux/mmzone.h
===================================================================
@@ -107,11 +107,22 @@ enum zone_stat_item {
 #endif
 	NR_VM_ZONE_STAT_ITEMS };
 
+/*
+ * We do arithmetic on the LRU lists in various places in the code,
+ * so it is important to keep the active lists LRU_ACTIVE higher in
+ * the array than the corresponding inactive lists, and to keep
+ * the *_FILE lists LRU_FILE higher than the corresponding _ANON lists.
+ */
+#define LRU_BASE 0
+#define LRU_ANON LRU_BASE
+#define LRU_ACTIVE 1
+#define LRU_FILE 2
+
 enum lru_list {
-	LRU_INACTIVE_ANON,	/* must be first enum  */
-	LRU_ACTIVE_ANON,	/* must match order of NR_[IN]ACTIVE_* */
-	LRU_INACTIVE_FILE,	/*  "     "     "   "       "          */
-	LRU_ACTIVE_FILE,	/*  "     "     "   "       "          */
+	LRU_INACTIVE_ANON = LRU_BASE,
+	LRU_ACTIVE_ANON = LRU_BASE + LRU_ACTIVE,
+	LRU_INACTIVE_FILE = LRU_BASE + LRU_FILE,
+	LRU_ACTIVE_FILE = LRU_BASE + LRU_FILE + LRU_ACTIVE,
 	NR_LRU_LISTS };
 
 #define for_each_lru(l) for (l = 0; l < NR_LRU_LISTS; l++)

--
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>

#22 lore raw

RFC PATCH 8/10 make split VM and lumpy reclaim work together

In reply to Rik van Riel

Make lumpy reclaim and the split VM code work together better, by allowing both file and anonymous pages to be relaimed together.

Will be merged into patch 6/10 soon, split out for the benefit of people who have looked at the older code in the past.

mm/vmscan.c +26 -23
Index: linux-2.6.23-mm1/mm/vmscan.c
===================================================================
@@ -752,10 +752,6 @@ static unsigned long isolate_lru_pages(u
 
 			cursor_page = pfn_to_page(pfn);
 
-			/* Don't lump pages of different types:  file vs anon */
-			if (!PageLRU(page) || (file != !!page_file_cache(cursor_page)))
-				break;
-
 			/* Check that we have not crossed a zone boundary. */
 			if (unlikely(page_zone_id(cursor_page) != zone_id))
 				continue;
@@ -799,16 +795,22 @@ static unsigned long isolate_pages_globa
  * clear_active_flags() is a helper for shrink_active_list(), clearing
  * any active bits from the pages in the list.
  */
-static unsigned long clear_active_flags(struct list_head *page_list)
+static unsigned long clear_active_flags(struct list_head *page_list,
+					unsigned int *count)
 {
 	int nr_active = 0;
+	int lru;
 	struct page *page;
 
-	list_for_each_entry(page, page_list, lru)
+	list_for_each_entry(page, page_list, lru) {
+		lru = page_file_cache(page);
 		if (PageActive(page)) {
+			lru += LRU_ACTIVE;
 			ClearPageActive(page);
 			nr_active++;
 		}
+		count[lru]++;
+	}
 
 	return nr_active;
 }
@@ -876,24 +878,25 @@ static unsigned long shrink_inactive_lis
 		unsigned long nr_scan;
 		unsigned long nr_freed;
 		unsigned long nr_active;
+		unsigned int count[NR_LRU_LISTS] = { 0, };
+		int mode = (sc->order > PAGE_ALLOC_COSTLY_ORDER) ?
+					ISOLATE_BOTH : ISOLATE_INACTIVE;
 
 		nr_taken = sc->isolate_pages(sc->swap_cluster_max,
-			     &page_list, &nr_scan, sc->order,
-			     (sc->order > PAGE_ALLOC_COSTLY_ORDER)?
-					     ISOLATE_BOTH : ISOLATE_INACTIVE,
+			     &page_list, &nr_scan, sc->order, mode,
 				zone, sc->mem_cgroup, 0, file);
-		nr_active = clear_active_flags(&page_list);
+		nr_active = clear_active_flags(&page_list, count);
 		__count_vm_events(PGDEACTIVATE, nr_active);
 
-		if (file) {
-			__mod_zone_page_state(zone, NR_ACTIVE_FILE, -nr_active);
-			__mod_zone_page_state(zone, NR_INACTIVE_FILE,
-						-(nr_taken - nr_active));
-		} else {
-			__mod_zone_page_state(zone, NR_ACTIVE_ANON, -nr_active);
-			__mod_zone_page_state(zone, NR_INACTIVE_ANON,
-						-(nr_taken - nr_active));
-		}
+		__mod_zone_page_state(zone, NR_ACTIVE_FILE,
+						-count[LRU_ACTIVE_FILE]);
+		__mod_zone_page_state(zone, NR_INACTIVE_FILE,
+						-count[LRU_INACTIVE_FILE]);
+		__mod_zone_page_state(zone, NR_ACTIVE_ANON,
+						-count[LRU_ACTIVE_ANON]);
+		__mod_zone_page_state(zone, NR_INACTIVE_ANON,
+						-count[LRU_INACTIVE_ANON]);
+
 		zone->pages_scanned += nr_scan;
 		spin_unlock_irq(&zone->lru_lock);
 
@@ -914,7 +917,7 @@ static unsigned long shrink_inactive_lis
 			 * The attempt at page out may have made some
 			 * of the pages active, mark them inactive again.
 			 */
-			nr_active = clear_active_flags(&page_list);
+			nr_active = clear_active_flags(&page_list, count);
 			count_vm_events(PGDEACTIVATE, nr_active);
 
 			nr_freed += shrink_page_list(&page_list, sc,
@@ -943,11 +946,11 @@ static unsigned long shrink_inactive_lis
 			VM_BUG_ON(PageLRU(page));
 			SetPageLRU(page);
 			list_del(&page->lru);
-			if (file) {
+			if (page_file_cache(page)) {
 				l += LRU_FILE;
-				zone->recent_rotated_file += sc->activated;
+				zone->recent_rotated_file++;
 			} else {
-				zone->recent_rotated_anon += sc->activated;
+				zone->recent_rotated_anon++;
 			}
 			if (PageActive(page))
 				l += LRU_ACTIVE;

--
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>

#23 lore raw

RFC PATCH 9/10 split VM and memory controllers

In reply to Rik van Riel

The memory controller code is still quite simple, so don't do anything fancy for now trying to make it work better with the split VM code.

Will be merged into 6/10 soon.

mm/memcontrol.c +6 -1
Index: linux-2.6.23-mm1/mm/memcontrol.c
===================================================================
@@ -210,7 +210,6 @@ unsigned long mem_cgroup_isolate_pages(u
 	struct list_head *src;
 	struct page_cgroup *pc;
 
-//TODO:  memory container maintain separate file/anon lists?
 	if (active)
 		src = &mem_cont->active_list;
 	else
@@ -222,6 +221,9 @@ unsigned long mem_cgroup_isolate_pages(u
 		page = pc->page;
 		VM_BUG_ON(!pc);
 
+		/*
+		 * TODO: play better with lumpy reclaim, grabbing anything.
+		 */
 		if (PageActive(page) && !active) {
 			__mem_cgroup_move_lists(pc, true);
 			scan--;
@@ -240,6 +242,9 @@ unsigned long mem_cgroup_isolate_pages(u
 		if (page_zone(page) != z)
 			continue;
 
+		if (file != !!page_file_cache(page))
+			continue;
+
 		/*
 		 * Check if the meta page went away from under us
 		 */

--
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>

#24 lore raw

RFC PATCH 10/10 add swapped in pages to the inactive list

In reply to Rik van Riel

Swapin_readahead can read in a lot of data that the processes in memory never need. Adding swap cache pages to the inactive list prevents them from putting too much pressure on the working set.

This has the potential to help the programs that are already in memory, but it could also be a disadvantage to processes that are trying to get swapped in.

In short, this patch needs testing.

mm/swap_state.c +1 -1
Index: linux-2.6.23-mm1/mm/swap_state.c
===================================================================
@@ -370,7 +370,7 @@ struct page *read_swap_cache_async(swp_e
 			/*
 			 * Initiate read into locked page and return.
 			 */
-			lru_cache_add_active_anon(new_page);
+			lru_cache_add_anon(new_page);
 			swap_readpage(NULL, new_page);
 			return new_page;
 		}

--
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>

#25 lore raw
In reply to Rik van Riel
Quoted 2 lines · Rik van Riel

The current version only has the infrastructure. Large changes to the page replacement policy will follow later.

Hmmmm.. I'd rather see where we are going. One other way of addressing many of these issues is to allow large page sizes on the LRU which will reduce the number of entities that have to be managed. Both approaches actually would work in tandem.

Quoted 3 lines

TODO:
- have any mlocked and ramfs pages live off of the LRU list, so we do not need to scan these pages

I think that is the most urgent issue at hand. At least for us.

Quoted 2 lines

- switch to SEQ replacement for the anon LRU lists, so the worst case number of pages to scan is reduced greatly.

No idea what that is?

Quoted 2 lines

- figure out if the file LRU lists need page replacement changes to help with worst case scenarios

We do not have an accepted standard load. So how would we figure that one out?

--
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>

#26 lore raw
Quoted 6 lines · On Tue, 6 Nov 2007 18:11:39 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 2 lines · Rik van Riel

The current version only has the infrastructure. Large changes to the page replacement policy will follow later.

Hmmmm.. I'd rather see where we are going.

http://linux-mm.org/PageReplacementDesign

Quoted 2 lines

One other way of addressing many of these issues is to allow large page sizes on the LRU which will reduce the number of entities that have to be managed.

Linus seems to have vetoed that (unless I am mistaken), so the chances of that happening soon are probably not very large.

Also, a factor 16 increase in page size is not going to help if memory sizes also increase by a factor 16, since we already have trouble with today's memory sizes.

Quoted 1 line

Both approaches actually would work in tandem.

Hence, this patch series.

Quoted 5 lines
Quoted 3 lines

TODO:
- have any mlocked and ramfs pages live off of the LRU list, so we do not need to scan these pages

I think that is the most urgent issue at hand. At least for us.

For some workloads this is the most urgent change, indeed. Since the patches for this already exist, integrating them is at the top of my list. Expect this to be integrated into the split VM patch series by the end of this week.

Quoted 4 lines
Quoted 2 lines

- switch to SEQ replacement for the anon LRU lists, so the worst case number of pages to scan is reduced greatly.

No idea what that is?

See http://linux-mm.org/PageReplacementDesign

Quoted 5 lines
Quoted 2 lines

- figure out if the file LRU lists need page replacement changes to help with worst case scenarios

We do not have an accepted standard load. So how would we figure that one out?

The current worst case is where we need to scan all of memory, just to find a few pages we can swap out. With the effects of lock contention figured in, this can take hours on huge systems.

In order to make the VM more scalable, we need to find acceptable pages to swap out with low complexity in the VM. The "worst case" above refers to the upper bound on how much work the VM needs to do in order to get something evicted from the page cache or swapped out.

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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>
#27 lore raw
Quoted 3 lines · Rik van Riel

Also, a factor 16 increase in page size is not going to help if memory sizes also increase by a factor 16, since we already have trouble with today's memory sizes.

Note that a factor 16 increase usually goes hand in hand with more processors. The synchronization of multiple processors becomes a concern. If you have an 8p and each of them tries to get the zone locks for reclaim then we are already in trouble. And given the immaturity of the handling of cacheline contention in current commodity hardware this is likely to result in livelocks and/or starvation on some level.

Quoted 6 lines
Quoted 1 line

I think that is the most urgent issue at hand. At least for us.

For some workloads this is the most urgent change, indeed. Since the patches for this already exist, integrating them is at the top of my list. Expect this to be integrated into the split VM patch series by the end of this week.

Good to hear.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

- switch to SEQ replacement for the anon LRU lists, so the worst case number of pages to scan is reduced greatly.

No idea what that is?

See http://linux-mm.org/PageReplacementDesign

A bit sparse but limiting the scanning if we cannot do much is certainly the right thing to do. The percentage of memory taken up by anonymous pages varies depending on the load. HPC applications may consume all of memory with anonymous pages. But there the pain is already so bad that many users go to huge pages already which bypasses the VM.

Quoted 6 lines
Quoted 2 lines

We do not have an accepted standard load. So how would we figure that one out?

The current worst case is where we need to scan all of memory, just to find a few pages we can swap out. With the effects of lock contention figured in, this can take hours on huge systems.

Right but I think this looks like a hopeless situation regardless of the algorithm if you have a couple of million pages and are trying to free one. Now image a series of processors going on the hunt for the few pages that can be reclaimed.

--
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>

#28 lore raw
Quoted 6 lines · On Tue, 6 Nov 2007 18:40:46 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 3 lines · Rik van Riel

Also, a factor 16 increase in page size is not going to help if memory sizes also increase by a factor 16, since we already have trouble with today's memory sizes.

Quoted 6 lines

Note that a factor 16 increase usually goes hand in hand with more processors. The synchronization of multiple processors becomes a concern. If you have an 8p and each of them tries to get the zone locks for reclaim then we are already in trouble. And given the immaturity of the handling of cacheline contention in current commodity hardware this is likely to result in livelocks and/or starvation on some level.

Which is why we need to greatly reduce the number of pages scanned to free a page. In all workloads.

Quoted 11 lines
Quoted 6 lines
Quoted 2 lines

We do not have an accepted standard load. So how would we figure that one out?

The current worst case is where we need to scan all of memory, just to find a few pages we can swap out. With the effects of lock contention figured in, this can take hours on huge systems.

Right but I think this looks like a hopeless situation regardless of the algorithm if you have a couple of million pages and are trying to free one. Now image a series of processors going on the hunt for the few pages that can be reclaimed.

An algorithm that only clears the referenced bit and then moves the anonymous page from the active to the inactive list will do a lot less work than an algorithm that needs to scan the *whole* active list because all of the pages on it are referenced.

This is not a theoretical situation: every anonymous page starts out referenced!

Add in a relatively small inactive list on huge memory systems, and we could have something of an acceptable algorithmic complexity.

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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>
maintainer
#29 lore raw
Quoted 17 lines · On Tue, 6 Nov 2007 21:51:27 -0500 Rik van Riel <[email protected]> wrote:
Quoted 6 lines · On Tue, 6 Nov 2007 18:40:46 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 3 lines · Rik van Riel

Also, a factor 16 increase in page size is not going to help if memory sizes also increase by a factor 16, since we already have trouble with today's memory sizes.

Quoted 6 lines

Note that a factor 16 increase usually goes hand in hand with more processors. The synchronization of multiple processors becomes a concern. If you have an 8p and each of them tries to get the zone locks for reclaim then we are already in trouble. And given the immaturity of the handling of cacheline contention in current commodity hardware this is likely to result in livelocks and/or starvation on some level.

Quoted 2 lines

Which is why we need to greatly reduce the number of pages scanned to free a page. In all workloads.

It strikes me that splitting one list into two lists will not provide sufficient improvement in search efficiency to do that. I mean, a naive guess would be that it will, on average, halve the amount of work which needs to be done.

But we need multiple-orders-of-magnitude improvements to address the pathological worst-cases which you're looking at there. Where is this coming from?

Or is the problem which you're seeing due to scanning of mapped pages at low "distress" levels?

Would be interested in seeing more details on all of this, please.

--
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>

#30 lore raw
Quoted 7 lines · On Wed, 7 Nov 2007 09:59:45 -0800 Andrew Morton <[email protected]>…
Quoted 4 lines · On Tue, 6 Nov 2007 21:51:27 -0500 Rik van Riel <[email protected]> wrote:

Which is why we need to greatly reduce the number of pages scanned to free a page. In all workloads.

It strikes me that splitting one list into two lists will not provide sufficient improvement in search efficiency to do that.

Well, if you look at the typical problem systems today, you will see that most of the pages being allocated and evicted are in the page cache, while most of the pages in memory are actually anonymous pages.

Not having to scan over that 80% of memory that contains anonymous pages and shared memory segments to get at the 20% page cache pages is much more than a factor two improvement.

Quoted 6 lines

I mean, a naive guess would be that it will, on average, halve the amount of work which needs to be done.

But we need multiple-orders-of-magnitude improvements to address the pathological worst-cases which you're looking at there. Where is this coming from?

Replacing page cache pages is easy. If they were referenced once (typical), we can just evict the page the first time we scan it.

Anonymous pages have a similar optimization: every anonymous page starts out referenced, so moving referenced pages back to the front of the active list is unneeded work.

However, we cannot just place referenced anonymous pages onto an inactive list that is shared with page cache pages, because of the difference in replacement cost and relative importance of both types of pages!

Quoted 4 lines

Or is the problem which you're seeing due to scanning of mapped pages at low "distress" levels?

Would be interested in seeing more details on all of this, please.

http://linux-mm.org/PageReplacementDesign

Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
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>