Skip to content

Commit faecd8d

Browse files
JoonsooKimtorvalds
authored andcommitted
mm/rmap: factor lock function out of rmap_walk_anon()
When we traverse anon_vma, we need to take a read-side anon_lock. But there is subtle difference in the situation so that we can't use same method to take a lock in each cases. Therefore, we need to make rmap_walk_anon() taking difference lock function. This patch is the first step, factoring lock function for anon_lock out of rmap_walk_anon(). It will be used in case of removing migration entry and in default of rmap_walk_anon(). Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Hugh Dickins <hughd@google.com> Cc: Rik van Riel <riel@redhat.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Hillf Danton <dhillf@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0f843c6 commit faecd8d

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

‎mm/rmap.c‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,24 @@ void __put_anon_vma(struct anon_vma *anon_vma)
16841684
}
16851685

16861686
#ifdef CONFIG_MIGRATION
1687+
static struct anon_vma *rmap_walk_anon_lock(struct page *page)
1688+
{
1689+
struct anon_vma *anon_vma;
1690+
1691+
/*
1692+
* Note: remove_migration_ptes() cannot use page_lock_anon_vma_read()
1693+
* because that depends on page_mapped(); but not all its usages
1694+
* are holding mmap_sem. Users without mmap_sem are required to
1695+
* take a reference count to prevent the anon_vma disappearing
1696+
*/
1697+
anon_vma = page_anon_vma(page);
1698+
if (!anon_vma)
1699+
return NULL;
1700+
1701+
anon_vma_lock_read(anon_vma);
1702+
return anon_vma;
1703+
}
1704+
16871705
/*
16881706
* rmap_walk() and its helpers rmap_walk_anon() and rmap_walk_file():
16891707
* Called by migrate.c to remove migration ptes, but might be used more later.
@@ -1696,16 +1714,10 @@ static int rmap_walk_anon(struct page *page, int (*rmap_one)(struct page *,
16961714
struct anon_vma_chain *avc;
16971715
int ret = SWAP_AGAIN;
16981716

1699-
/*
1700-
* Note: remove_migration_ptes() cannot use page_lock_anon_vma_read()
1701-
* because that depends on page_mapped(); but not all its usages
1702-
* are holding mmap_sem. Users without mmap_sem are required to
1703-
* take a reference count to prevent the anon_vma disappearing
1704-
*/
1705-
anon_vma = page_anon_vma(page);
1717+
anon_vma = rmap_walk_anon_lock(page);
17061718
if (!anon_vma)
17071719
return ret;
1708-
anon_vma_lock_read(anon_vma);
1720+
17091721
anon_vma_interval_tree_foreach(avc, &anon_vma->rb_root, pgoff, pgoff) {
17101722
struct vm_area_struct *vma = avc->vma;
17111723
unsigned long address = vma_address(page, vma);

0 commit comments

Comments
 (0)