Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932310Ab0DGAH7 (ORCPT ); Tue, 6 Apr 2010 20:07:59 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:45695 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932267Ab0DGAHA (ORCPT ); Tue, 6 Apr 2010 20:07:00 -0400 Date: Tue, 6 Apr 2010 17:06:23 -0700 From: Andrew Morton To: Mel Gorman Cc: Andrea Arcangeli , Christoph Lameter , Adam Litke , Avi Kivity , David Rientjes , Minchan Kim , KAMEZAWA Hiroyuki , KOSAKI Motohiro , Rik van Riel , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 14/14] mm,migration: Allow the migration of PageSwapCache pages Message-Id: <20100406170623.50631eb8.akpm@linux-foundation.org> In-Reply-To: <1270224168-14775-15-git-send-email-mel@csn.ul.ie> References: <1270224168-14775-1-git-send-email-mel@csn.ul.ie> <1270224168-14775-15-git-send-email-mel@csn.ul.ie> X-Mailer: Sylpheed 2.4.8 (GTK+ 2.12.9; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3458 Lines: 108 On Fri, 2 Apr 2010 17:02:48 +0100 Mel Gorman wrote: > PageAnon pages that are unmapped may or may not have an anon_vma so are > not currently migrated. However, a swap cache page can be migrated and > fits this description. This patch identifies page swap caches and allows > them to be migrated but ensures that no attempt to made to remap the pages > would would potentially try to access an already freed anon_vma. > > ... > > @@ -484,7 +484,8 @@ static int fallback_migrate_page(struct address_space *mapping, > * < 0 - error code > * == 0 - success > */ > -static int move_to_new_page(struct page *newpage, struct page *page) > +static int move_to_new_page(struct page *newpage, struct page *page, > + int remap_swapcache) You're not a fan of `bool'. > { > struct address_space *mapping; > int rc; > @@ -519,10 +520,12 @@ static int move_to_new_page(struct page *newpage, struct page *page) > else > rc = fallback_migrate_page(mapping, newpage, page); > > - if (!rc) > - remove_migration_ptes(page, newpage); > - else > + if (rc) { > newpage->mapping = NULL; > + } else { > + if (remap_swapcache) > + remove_migration_ptes(page, newpage); > + } > > unlock_page(newpage); > > @@ -539,6 +542,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private, > int rc = 0; > int *result = NULL; > struct page *newpage = get_new_page(page, private, &result); > + int remap_swapcache = 1; > int rcu_locked = 0; > int charge = 0; > struct mem_cgroup *mem = NULL; > @@ -600,18 +604,27 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private, > rcu_read_lock(); > rcu_locked = 1; > > - /* > - * If the page has no mappings any more, just bail. An > - * unmapped anon page is likely to be freed soon but worse, > - * it's possible its anon_vma disappeared between when > - * the page was isolated and when we reached here while > - * the RCU lock was not held > - */ > - if (!page_mapped(page)) > - goto rcu_unlock; > + /* Determine how to safely use anon_vma */ > + if (!page_mapped(page)) { > + if (!PageSwapCache(page)) > + goto rcu_unlock; > > - anon_vma = page_anon_vma(page); > - atomic_inc(&anon_vma->external_refcount); > + /* > + * We cannot be sure that the anon_vma of an unmapped > + * swapcache page is safe to use. Why not? A full explanation here would be nice. > In this case, the > + * swapcache page gets migrated but the pages are not > + * remapped > + */ > + remap_swapcache = 0; > + } else { > + /* > + * Take a reference count on the anon_vma if the > + * page is mapped so that it is guaranteed to > + * exist when the page is remapped later > + */ > + anon_vma = page_anon_vma(page); > + atomic_inc(&anon_vma->external_refcount); > + } > } > > /* > @@ -646,9 +659,9 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private, > > skip_unmap: > if (!page_mapped(page)) > - rc = move_to_new_page(newpage, page); > + rc = move_to_new_page(newpage, page, remap_swapcache); > > - if (rc) > + if (rc && remap_swapcache) > remove_migration_ptes(page, page); > rcu_unlock: -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/