Skip to content

Commit 1fb08ac

Browse files
yang-shitorvalds
authored andcommitted
mm: rmap: make try_to_unmap() void function
Currently try_to_unmap() return bool value by checking page_mapcount(), however this may return false positive since page_mapcount() doesn't check all subpages of compound page. The total_mapcount() could be used instead, but its cost is higher since it traverses all subpages. Actually the most callers of try_to_unmap() don't care about the return value at all. So just need check if page is still mapped by page_mapped() when necessary. And page_mapped() does bail out early when it finds mapped subpage. Link: https://lkml.kernel.org/r/bb27e3fe-6036-b637-5086-272befbfe3da@google.com Suggested-by: Hugh Dickins <hughd@google.com> Signed-off-by: Yang Shi <shy828301@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Reviewed-by: Shakeel Butt <shakeelb@google.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Hugh Dickins <hughd@google.com> Acked-by: Naoya Horiguchi <naoya.horiguchi@nec.com> Cc: Alistair Popple <apopple@nvidia.com> Cc: Jan Kara <jack@suse.cz> Cc: Jue Wang <juew@google.com> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Miaohe Lin <linmiaohe@huawei.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Peter Xu <peterx@redhat.com> Cc: Ralph Campbell <rcampbell@nvidia.com> Cc: Wang Yugui <wangyugui@e16-tech.com> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent cebc774 commit 1fb08ac

4 files changed

Lines changed: 14 additions & 21 deletions

File tree

‎include/linux/rmap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static inline void page_dup_rmap(struct page *page, bool compound)
195195
int page_referenced(struct page *, int is_locked,
196196
struct mem_cgroup *memcg, unsigned long *vm_flags);
197197

198-
bool try_to_unmap(struct page *, enum ttu_flags flags);
198+
void try_to_unmap(struct page *, enum ttu_flags flags);
199199

200200
/* Avoid racy checks */
201201
#define PVMW_SYNC (1 << 0)

‎mm/memory-failure.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
12691269
enum ttu_flags ttu = TTU_IGNORE_MLOCK;
12701270
struct address_space *mapping;
12711271
LIST_HEAD(tokill);
1272-
bool unmap_success = true;
1272+
bool unmap_success;
12731273
int kill = 1, forcekill;
12741274
struct page *hpage = *hpagep;
12751275
bool mlocked = PageMlocked(hpage);
@@ -1332,7 +1332,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
13321332
collect_procs(hpage, &tokill, flags & MF_ACTION_REQUIRED);
13331333

13341334
if (!PageHuge(hpage)) {
1335-
unmap_success = try_to_unmap(hpage, ttu);
1335+
try_to_unmap(hpage, ttu);
13361336
} else {
13371337
if (!PageAnon(hpage)) {
13381338
/*
@@ -1344,17 +1344,16 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
13441344
*/
13451345
mapping = hugetlb_page_mapping_lock_write(hpage);
13461346
if (mapping) {
1347-
unmap_success = try_to_unmap(hpage,
1348-
ttu|TTU_RMAP_LOCKED);
1347+
try_to_unmap(hpage, ttu|TTU_RMAP_LOCKED);
13491348
i_mmap_unlock_write(mapping);
1350-
} else {
1349+
} else
13511350
pr_info("Memory failure: %#lx: could not lock mapping for mapped huge page\n", pfn);
1352-
unmap_success = false;
1353-
}
13541351
} else {
1355-
unmap_success = try_to_unmap(hpage, ttu);
1352+
try_to_unmap(hpage, ttu);
13561353
}
13571354
}
1355+
1356+
unmap_success = !page_mapped(hpage);
13581357
if (!unmap_success)
13591358
pr_err("Memory failure: %#lx: failed to unmap page (mapcount=%d)\n",
13601359
pfn, page_mapcount(hpage));

‎mm/rmap.c‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
14051405
/*
14061406
* When racing against e.g. zap_pte_range() on another cpu,
14071407
* in between its ptep_get_and_clear_full() and page_remove_rmap(),
1408-
* try_to_unmap() may return false when it is about to become true,
1408+
* try_to_unmap() may return before page_mapped() has become false,
14091409
* if page table locking is skipped: use TTU_SYNC to wait for that.
14101410
*/
14111411
if (flags & TTU_SYNC)
@@ -1756,9 +1756,10 @@ static int page_not_mapped(struct page *page)
17561756
* Tries to remove all the page table entries which are mapping this
17571757
* page, used in the pageout path. Caller must hold the page lock.
17581758
*
1759-
* If unmap is successful, return true. Otherwise, false.
1759+
* It is the caller's responsibility to check if the page is still
1760+
* mapped when needed (use TTU_SYNC to prevent accounting races).
17601761
*/
1761-
bool try_to_unmap(struct page *page, enum ttu_flags flags)
1762+
void try_to_unmap(struct page *page, enum ttu_flags flags)
17621763
{
17631764
struct rmap_walk_control rwc = {
17641765
.rmap_one = try_to_unmap_one,
@@ -1783,14 +1784,6 @@ bool try_to_unmap(struct page *page, enum ttu_flags flags)
17831784
rmap_walk_locked(page, &rwc);
17841785
else
17851786
rmap_walk(page, &rwc);
1786-
1787-
/*
1788-
* When racing against e.g. zap_pte_range() on another cpu,
1789-
* in between its ptep_get_and_clear_full() and page_remove_rmap(),
1790-
* try_to_unmap() may return false when it is about to become true,
1791-
* if page table locking is skipped: use TTU_SYNC to wait for that.
1792-
*/
1793-
return !page_mapcount(page);
17941787
}
17951788

17961789
/**

‎mm/vmscan.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,8 @@ static unsigned int shrink_page_list(struct list_head *page_list,
14991499
if (unlikely(PageTransHuge(page)))
15001500
flags |= TTU_SPLIT_HUGE_PMD;
15011501

1502-
if (!try_to_unmap(page, flags)) {
1502+
try_to_unmap(page, flags);
1503+
if (page_mapped(page)) {
15031504
stat->nr_unmap_fail += nr_pages;
15041505
if (!was_swapbacked && PageSwapBacked(page))
15051506
stat->nr_lazyfree_fail += nr_pages;

0 commit comments

Comments
 (0)