Re: [PATCH 1/2] Page migration via Swap V2: Page Eviction

Christoph Lameter
2005-10-19T20:32:36Z

On Wed, 19 Oct 2005, Magnus Damm wrote:

> I'm trying to figure out if this code works in all cases:
>
> + spin_lock_irq(&zone->lru_lock);
> + list_del(&page->lru);
> + if (!TestSetPageLRU(page)) {
> + if (PageActive(page))
> + add_page_to_active_list(zone, page);
> + else
> + add_page_to_inactive_list(zone, page);
> + count++;
> + }
> + spin_unlock_irq(&zone->lru_lock);
>
> Why not use if (TestSetPageLRU(page)) BUG()?

The memory hotplug project has a BUG() there and I cannot find a way that
something else could legitimately set the LRU bit. You are right. Thus
this fix which also includes the addition of put_page() already included
in an earlier patch.

Index: linux-2.6.14-rc4-mm1/mm/vmscan.c
===================================================================
--- linux-2.6.14-rc4-mm1.orig/mm/vmscan.c 2005-10-17 16:19:21.000000000 -0700
+++ linux-2.6.14-rc4-mm1/mm/vmscan.c 2005-10-19 13:30:00.000000000 -0700
@@ -886,14 +886,16 @@ int putback_lru_pages(struct list_head *

spin_lock_irq(&zone->lru_lock);
list_del(&page->lru);
- if (!TestSetPageLRU(page)) {
- if (PageActive(page))
- add_page_to_active_list(zone, page);
- else
- add_page_to_inactive_list(zone, page);
- count++;
- }
+ if (TestSetPageLRU(page))
+ BUG();
+ if (PageActive(page))
+ add_page_to_active_list(zone, page);
+ else
+ add_page_to_inactive_list(zone, page);
+ count++;
spin_unlock_irq(&zone->lru_lock);
+ /* Undo the get from isolate_lru_page */
+ put_page(page);
}
return count;
}