Skip to contentSkip to conversation

Check PageActive when evictable page and unevicetable page race happen

PATCH In review Minchan Kim 2 participants 5 messages Apr 24, 2011

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

PATCH 1/1 Check PageActive when evictable page and unevicetable page race happen

In putback_lru_page, unevictable page can be changed into evictable 's one while we move it among lru. So we have checked it again and rescued it. But we don't check PageActive, again. It could add active page into inactive list so we can see the BUG in isolate_lru_pages. (But I didn't see any report because I think it's very subtle)

It could happen in race that zap_pte_range's mark_page_accessed and putback_lru_page. It's subtle but could be possible.

Note:
While I review the code, I found it. So it's not real report.

Cc Rik van Riel <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Lee Schermerhorn <[email protected]>
---
 mm/vmscan.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
mm/vmscan.c +3 -1
index b3a569f..c0cd1aa 100644
@@ -562,7 +562,7 @@ int remove_mapping(struct address_space *mapping, struct page *page)
 void putback_lru_page(struct page *page)
 {
 	int lru;
-	int active = !!TestClearPageActive(page);
+	int active;
 	int was_unevictable = PageUnevictable(page);
 
 	VM_BUG_ON(PageLRU(page));
@@ -571,6 +571,7 @@ redo:
 	ClearPageUnevictable(page);
 
 	if (page_evictable(page, NULL)) {
+		active = !!TestClearPageActive(page);
 		/*
 		 * For evictable pages, we can use the cache.
 		 * In event of a race, worst case is we end up with an
@@ -584,6 +585,7 @@ redo:
 		 * Put unevictable pages directly on zone's unevictable
 		 * list.
 		 */
+		ClearPageActive(page);
 		lru = LRU_UNEVICTABLE;
 		add_page_to_unevictable_list(page);
 		/*
Signature · 1 line
1.7.1
#1 lore raw
Quoted 5 lines · Minchan Kim

In putback_lru_page, unevictable page can be changed into evictable 's one while we move it among lru. So we have checked it again and rescued it. But we don't check PageActive, again. It could add active page into inactive list so we can see the BUG in isolate_lru_pages. (But I didn't see any report because I think it's very subtle)

As I look the code further, that's because lru_cache_add_lru always cleans up PageActive regardless of LRU list.
If active page goes to inactive list, we shouldn't meet the BUG but it's apparently wrong.

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
In reply to Minchan Kim

2011/4/24 Minchan Kim <[email protected]>:

Quoted 44 lines

In putback_lru_page, unevictable page can be changed into evictable 's one while we move it among lru. So we have checked it again and rescued it. But we don't check PageActive, again. It could add active page into inactive list so we can see the BUG in isolate_lru_pages. (But I didn't see any report because I think it's very subtle)

It could happen in race that zap_pte_range's mark_page_accessed and putback_lru_page. It's subtle but could be possible.

Note:
While I review the code, I found it. So it's not real report.

Cc Rik van Riel <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Lee Schermerhorn <[email protected]>

---
 mm/vmscan.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
mm/vmscan.c +2 -1
index b3a569f..c0cd1aa 100644
@@ -562,7 +562,7 @@ int remove_mapping(struct address_space *mapping, struct page *page)
  void putback_lru_page(struct page *page)
  {
        int lru;
-       int active = !!TestClearPageActive(page);
+       int active;
        int was_unevictable = PageUnevictable(page);
 
        VM_BUG_ON(PageLRU(page));
@@ -571,6 +571,7 @@ redo:
        ClearPageUnevictable(page);
 
        if (page_evictable(page, NULL)) {
+               active = !!TestClearPageActive(page);
                /*
                 * For evictable pages, we can use the cache.
                 * In event of a race, worst case is we end up with an

mm/vmscan.c redo: · line 590

Quoted 6 lines
mm/vmscan.c +1 -0
@@ -584,6 +585,7 @@ redo:
                 * Put unevictable pages directly on zone's unevictable
                 * list.
                 */
+               ClearPageActive(page);
                lru = LRU_UNEVICTABLE;
                add_page_to_unevictable_list(page);

I think we forgot 'goto redo' case. following patch is better?

------------------------------------------------
if (page_evictable(page, NULL)) {
/*
* For evictable pages, we can use the cache.
* In event of a race, worst case is we end up with an
* unevictable page on [in]active list.
* We know how to handle that.
*/
lru = active + page_lru_base_type(page);
+ if (active)

+                   SetPageActive(page);
                lru_cache_add_lru(page, lru);
#3 lore raw

Hi KOSAKI,

Quoted 63 lines · KOSAKI Motohiro

2011/4/24 Minchan Kim <[email protected]>:

Quoted 44 lines

In putback_lru_page, unevictable page can be changed into evictable 's one while we move it among lru. So we have checked it again and rescued it. But we don't check PageActive, again. It could add active page into inactive list so we can see the BUG in isolate_lru_pages. (But I didn't see any report because I think it's very subtle)

It could happen in race that zap_pte_range's mark_page_accessed and putback_lru_page. It's subtle but could be possible.

Note:
While I review the code, I found it. So it's not real report.

Cc Rik van Riel <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Lee Schermerhorn <[email protected]>
---
 mm/vmscan.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
mm/vmscan.c +2 -1
index b3a569f..c0cd1aa 100644
@@ -562,7 +562,7 @@ int remove_mapping(struct address_space *mapping, struct page *page)
 void putback_lru_page(struct page *page)
 {
       int lru;
-       int active = !!TestClearPageActive(page);
+       int active;
       int was_unevictable = PageUnevictable(page);
 
       VM_BUG_ON(PageLRU(page));
@@ -571,6 +571,7 @@ redo:
       ClearPageUnevictable(page);
 
       if (page_evictable(page, NULL)) {
+               active = !!TestClearPageActive(page);
               /*
                * For evictable pages, we can use the cache.
                * In event of a race, worst case is we end up with an

mm/vmscan.c redo: · line 590

Quoted 6 lines
mm/vmscan.c +1 -0
@@ -584,6 +585,7 @@ redo:
                * Put unevictable pages directly on zone's unevictable
                * list.
                */
+               ClearPageActive(page);
               lru = LRU_UNEVICTABLE;
               add_page_to_unevictable_list(page);

I think we forgot 'goto redo' case. following patch is better?

------------------------------------------------
if (page_evictable(page, NULL)) {
/*
* For evictable pages, we can use the cache.
* In event of a race, worst case is we end up with an
* unevictable page on [in]active list.
* We know how to handle that.
*/
lru = active + page_lru_base_type(page);

Review

Quoted 3 lines
(quoted diff) +2 -0
+              if (active)
+                   SetPageActive(page);
                lru_cache_add_lru(page, lru);

PageActive is reset by lru_cache_add_lru so it's meaningless. BTW, please ignore this patch. :)

I think LRU status of isolated page cannot be changed. Thanks for the review.

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw
In reply to Minchan Kim
Quoted 8 lines · Minchan Kim

In putback_lru_page, unevictable page can be changed into evictable 's one while we move it among lru. So we have checked it again and rescued it. But we don't check PageActive, again. It could add active page into inactive list so we can see the BUG in isolate_lru_pages. (But I didn't see any report because I think it's very subtle)

It could happen in race that zap_pte_range's mark_page_accessed and putback_lru_page. It's subtle but could be possible.

Please Ignore this. I was confused.
The race never happens.

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>