Skip to contentSkip to conversation

move ClearPageActive from move_active_pages() to shrink_active_list()

PATCH In review KOSAKI Motohiro 3 participants 10 messages Jul 16, 2009 – Jul 20, 2009

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

PATCH 1/5 move ClearPageActive from move_active_pages() to shrink_active_list()

This patch series are several vmscan cleanups.

===================
Subject: [PATCH] move ClearPageActive from move_active_pages() to shrink_active_list()

The mvoe_active_pages_to_lru() function is called under irq disabled and ClearPageActive() doesn't need irq disabling.

Then, this patch move it into shrink_active_list().

---
 mm/vmscan.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
mm/vmscan.c +1 -4
Index: b/mm/vmscan.c
===================================================================
@@ -1230,10 +1230,6 @@ static void move_active_pages_to_lru(str
 		VM_BUG_ON(PageLRU(page));
 		SetPageLRU(page);
 
-		VM_BUG_ON(!PageActive(page));
-		if (!is_active_lru(lru))
-			ClearPageActive(page);	/* we are de-activating */
-
 		list_move(&page->lru, &zone->lru[lru].list);
 		mem_cgroup_add_lru_list(page, lru);
 		pgmoved++;
@@ -1315,6 +1311,7 @@ static void shrink_active_list(unsigned 
 			}
 		}
 
+		ClearPageActive(page);	/* we are de-activating */
 		list_add(&page->lru, &l_inactive);
 	}
 

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

PATCH 2/5 Kill unnecessary page flag test

Subject: [PATCH] Kill unnecessary page flag test

The page_lru() already evaluate PageActive() and PageSwapBacked(). We don't need to re-evaluate it.

---
 mm/vmscan.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmscan.c +2 -2
Index: b/mm/vmscan.c
===================================================================
@@ -1160,8 +1160,8 @@ static unsigned long shrink_inactive_lis
 			SetPageLRU(page);
 			lru = page_lru(page);
 			add_page_to_lru_list(zone, page, lru);
-			if (PageActive(page)) {
-				int file = !!page_is_file_cache(page);
+			if (is_active_lru(lru)) {
+				int file = !!is_file_lru(lru);
 				reclaim_stat->recent_rotated[file]++;
 			}
 			if (!pagevec_add(&pvec, 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>

#2 lore raw

PATCH 3/5 Kill unnecessary prefetch

In reply to KOSAKI Motohiro

Subject: Kill unnecessary prefetch

The pages in the list passed move_active_pages_to_lru() are already touched by shrink_active_list(). IOW the prefetch in move_active_pages_to_lru() don't populate any cache. it's pointless.

This patch remove it.

---
 mm/vmscan.c |    1 -
 1 file changed, 1 deletion(-)
mm/vmscan.c +0 -1
Index: b/mm/vmscan.c
===================================================================
@@ -1225,7 +1225,6 @@ static void move_active_pages_to_lru(str
 
 	while (!list_empty(list)) {
 		page = lru_to_page(list);
-		prefetchw_prev_lru_page(page, list, flags);
 
 		VM_BUG_ON(PageLRU(page));
 		SetPageLRU(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>

#3 lore raw

PATCH 4/5 Use add_page_to_lru_list() helper function

In reply to KOSAKI Motohiro

Subject: Use add_page_to_lru_list() helper function

add_page_to_lru_list() is equivalent to
- add lru list (global)
- add lru list (mem-cgroup)
- modify zone stat

We can use it.

---
 mm/vmscan.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/vmscan.c +2 -3
Index: b/mm/vmscan.c
===================================================================
@@ -1225,12 +1225,12 @@ static void move_active_pages_to_lru(str
 
 	while (!list_empty(list)) {
 		page = lru_to_page(list);
+		list_del(&page->lru);
 
 		VM_BUG_ON(PageLRU(page));
 		SetPageLRU(page);
 
-		list_move(&page->lru, &zone->lru[lru].list);
-		mem_cgroup_add_lru_list(page, lru);
+		add_page_to_lru_list(zone, page, lru);
 		pgmoved++;
 
 		if (!pagevec_add(&pvec, page) || list_empty(list)) {
@@ -1241,7 +1241,6 @@ static void move_active_pages_to_lru(str
 			spin_lock_irq(&zone->lru_lock);
 		}
 	}
-	__mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved);
 	if (!is_active_lru(lru))
 		__count_vm_events(PGDEACTIVATE, pgmoved);
 }

--
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: [PATCH 4/5] Use add_page_to_lru_list() helper function

Quoted 34 lines · KOSAKI Motohiro

Subject: Use add_page_to_lru_list() helper function

add_page_to_lru_list() is equivalent to
- add lru list (global)
- add lru list (mem-cgroup)
- modify zone stat

We can use it.

---
 mm/vmscan.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Index: b/mm/vmscan.c
===================================================================

mm/vmscan.c +2 -2
@@ -1225,12 +1225,12 @@ static void move_active_pages_to_lru(str
 
 	while (!list_empty(list)) {
 		page = lru_to_page(list);
+		list_del(&page->lru);
 
 		VM_BUG_ON(PageLRU(page));
 		SetPageLRU(page);
 
-		list_move(&page->lru, &zone->lru[lru].list);
-		mem_cgroup_add_lru_list(page, lru);
+		add_page_to_lru_list(zone, page, lru);
 		pgmoved++;
 
 		if (!pagevec_add(&pvec, page) || list_empty(list)) {

mm/vmscan.c static void move_active_pages_to_lru(str · line 1246

Quoted 7 lines
mm/vmscan.c +0 -1
@@ -1241,7 +1241,6 @@ static void move_active_pages_to_lru(str
 			spin_lock_irq(&zone->lru_lock);
 		}
 	}
-	__mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved);
 	if (!is_active_lru(lru))
 		__count_vm_events(PGDEACTIVATE, pgmoved);
 }

This is a net loss, you introduce pgmoved calls to __inc_zone_state, instead of the one __mod_zone_page_state() call.

--
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: [PATCH 4/5] Use add_page_to_lru_list() helper function

Quoted 11 lines

mm/vmscan.c static void move_active_pages_to_lru(str · line 1246

Quoted 8 lines
mm/vmscan.c +0 -1
@@ -1241,7 +1241,6 @@ static void move_active_pages_to_lru(str
 			spin_lock_irq(&zone->lru_lock);
 		}
 	}
-	__mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved);
 	if (!is_active_lru(lru))
 		__count_vm_events(PGDEACTIVATE, pgmoved);
 }

This is a net loss, you introduce pgmoved calls to __inc_zone_state, instead of the one __mod_zone_page_state() call.

max pgmoved is 32. 32 times __inc_zone_state() make 0 or 1 time atomic operation (not much than two).
I don't think it reduce performance.

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

Re: [PATCH 4/5] Use add_page_to_lru_list() helper function

Quoted 12 lines · KOSAKI Motohiro
Quoted 11 lines

mm/vmscan.c static void move_active_pages_to_lru(str · line 1246

Quoted 8 lines
mm/vmscan.c +0 -1
@@ -1241,7 +1241,6 @@ static void move_active_pages_to_lru(str
 			spin_lock_irq(&zone->lru_lock);
 		}
 	}
-	__mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved);
 	if (!is_active_lru(lru))
 		__count_vm_events(PGDEACTIVATE, pgmoved);
 }

This is a net loss, you introduce pgmoved calls to __inc_zone_state, instead of the one __mod_zone_page_state() call.

Quoted 3 lines

max pgmoved is 32. 32 times __inc_zone_state() make 0 or 1 time atomic operation (not much than two).
I don't think it reduce performance.

its not just atomics, count calls and branches too. It simply adds a ton of code for no particular reason.

--
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: [PATCH 4/5] Use add_page_to_lru_list() helper function

Quoted 13 lines · KOSAKI Motohiro
Quoted 12 lines
Quoted 11 lines

mm/vmscan.c static void move_active_pages_to_lru(str · line 1246

Quoted 8 lines
mm/vmscan.c +0 -1
@@ -1241,7 +1241,6 @@ static void move_active_pages_to_lru(str
 			spin_lock_irq(&zone->lru_lock);
 		}
 	}
-	__mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved);
 	if (!is_active_lru(lru))
 		__count_vm_events(PGDEACTIVATE, pgmoved);
 }

This is a net loss, you introduce pgmoved calls to __inc_zone_state, instead of the one __mod_zone_page_state() call.

Quoted 6 lines
Quoted 3 lines

max pgmoved is 32. 32 times __inc_zone_state() make 0 or 1 time atomic operation (not much than two).
I don't think it reduce performance.

its not just atomics, count calls and branches too. It simply adds a ton of code for no particular reason.

hm, I don't think it's tons penalty. I mean vmscan makes tons cache miss and function calling penalty is hidden by it.
But, I agreed this patch doesn't have strong motivation. I can drop this.

Andrew, Can you please drop this patch?

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

PATCH 5/5 move PGDEACTIVATE modification to shrink_active_list()

In reply to KOSAKI Motohiro

Subject: move PGDEACTIVATE modification to shrink_active_list()

Pgmoved accounting in move_active_pages_to_lru() doesn't make any sense. it can be calculated in irq enabled area.

This patch move #-of-deactivating-pages calcution to shrink_active_list().

---
 mm/vmscan.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
mm/vmscan.c +3 -4
Index: b/mm/vmscan.c
===================================================================
@@ -1217,7 +1217,6 @@ static void move_active_pages_to_lru(str
 				     struct list_head *list,
 				     enum lru_list lru)
 {
-	unsigned long pgmoved = 0;
 	struct pagevec pvec;
 	struct page *page;
 
@@ -1231,7 +1230,6 @@ static void move_active_pages_to_lru(str
 		SetPageLRU(page);
 
 		add_page_to_lru_list(zone, page, lru);
-		pgmoved++;
 
 		if (!pagevec_add(&pvec, page) || list_empty(list)) {
 			spin_unlock_irq(&zone->lru_lock);
@@ -1241,8 +1239,6 @@ static void move_active_pages_to_lru(str
 			spin_lock_irq(&zone->lru_lock);
 		}
 	}
-	if (!is_active_lru(lru))
-		__count_vm_events(PGDEACTIVATE, pgmoved);
 }
 
 static void shrink_active_list(unsigned long nr_pages, struct zone *zone,
@@ -1257,6 +1253,7 @@ static void shrink_active_list(unsigned 
 	struct page *page;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
 	unsigned long nr_rotated = 0;
+	unsigned long nr_deactivate = 0;
 
 	lru_add_drain();
 	spin_lock_irq(&zone->lru_lock);
@@ -1311,6 +1308,7 @@ static void shrink_active_list(unsigned 
 
 		ClearPageActive(page);	/* we are de-activating */
 		list_add(&page->lru, &l_inactive);
+		nr_deactivate++;
 	}
 
 	/*
@@ -1324,6 +1322,7 @@ static void shrink_active_list(unsigned 
 	 * get_scan_ratio.
 	 */
 	reclaim_stat->recent_rotated[!!file] += nr_rotated;
+	__count_vm_events(PGDEACTIVATE, nr_deactivate);
 
 	move_active_pages_to_lru(zone, &l_active,
 						LRU_ACTIVE + file * LRU_FILE);

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