Skip to content

Commit 0964730

Browse files
Hugh Dickinstorvalds
authored andcommitted
mlock: fix unevictable_pgs event counts on THP
5.8 commit 5d91f31 ("mm: swap: fix vmstats for huge page") has established that vm_events should count every subpage of a THP, including unevictable_pgs_culled and unevictable_pgs_rescued; but lru_cache_add_inactive_or_unevictable() was not doing so for unevictable_pgs_mlocked, and mm/mlock.c was not doing so for unevictable_pgs mlocked, munlocked, cleared and stranded. Fix them; but THPs don't go the pagevec way in mlock.c, so no fixes needed on that path. Fixes: 5d91f31 ("mm: swap: fix vmstats for huge page") Signed-off-by: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Shakeel Butt <shakeelb@google.com> Acked-by: Yang Shi <shy828301@gmail.com> Cc: Alex Shi <alex.shi@linux.alibaba.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Qian Cai <cai@lca.pw> Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2008301408230.5954@eggly.anvils Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8d8869c commit 0964730

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

‎mm/mlock.c‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ EXPORT_SYMBOL(can_do_mlock);
5858
*/
5959
void clear_page_mlock(struct page *page)
6060
{
61+
int nr_pages;
62+
6163
if (!TestClearPageMlocked(page))
6264
return;
6365

64-
mod_zone_page_state(page_zone(page), NR_MLOCK, -thp_nr_pages(page));
65-
count_vm_event(UNEVICTABLE_PGCLEARED);
66+
nr_pages = thp_nr_pages(page);
67+
mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages);
68+
count_vm_events(UNEVICTABLE_PGCLEARED, nr_pages);
6669
/*
6770
* The previous TestClearPageMlocked() corresponds to the smp_mb()
6871
* in __pagevec_lru_add_fn().
@@ -76,7 +79,7 @@ void clear_page_mlock(struct page *page)
7679
* We lost the race. the page already moved to evictable list.
7780
*/
7881
if (PageUnevictable(page))
79-
count_vm_event(UNEVICTABLE_PGSTRANDED);
82+
count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages);
8083
}
8184
}
8285

@@ -93,9 +96,10 @@ void mlock_vma_page(struct page *page)
9396
VM_BUG_ON_PAGE(PageCompound(page) && PageDoubleMap(page), page);
9497

9598
if (!TestSetPageMlocked(page)) {
96-
mod_zone_page_state(page_zone(page), NR_MLOCK,
97-
thp_nr_pages(page));
98-
count_vm_event(UNEVICTABLE_PGMLOCKED);
99+
int nr_pages = thp_nr_pages(page);
100+
101+
mod_zone_page_state(page_zone(page), NR_MLOCK, nr_pages);
102+
count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages);
99103
if (!isolate_lru_page(page))
100104
putback_lru_page(page);
101105
}
@@ -138,7 +142,7 @@ static void __munlock_isolated_page(struct page *page)
138142

139143
/* Did try_to_unlock() succeed or punt? */
140144
if (!PageMlocked(page))
141-
count_vm_event(UNEVICTABLE_PGMUNLOCKED);
145+
count_vm_events(UNEVICTABLE_PGMUNLOCKED, thp_nr_pages(page));
142146

143147
putback_lru_page(page);
144148
}
@@ -154,10 +158,12 @@ static void __munlock_isolated_page(struct page *page)
154158
*/
155159
static void __munlock_isolation_failed(struct page *page)
156160
{
161+
int nr_pages = thp_nr_pages(page);
162+
157163
if (PageUnevictable(page))
158-
__count_vm_event(UNEVICTABLE_PGSTRANDED);
164+
__count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages);
159165
else
160-
__count_vm_event(UNEVICTABLE_PGMUNLOCKED);
166+
__count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages);
161167
}
162168

163169
/**

‎mm/swap.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,14 @@ void lru_cache_add_inactive_or_unevictable(struct page *page,
494494

495495
unevictable = (vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) == VM_LOCKED;
496496
if (unlikely(unevictable) && !TestSetPageMlocked(page)) {
497+
int nr_pages = thp_nr_pages(page);
497498
/*
498499
* We use the irq-unsafe __mod_zone_page_stat because this
499500
* counter is not modified from interrupt context, and the pte
500501
* lock is held(spinlock), which implies preemption disabled.
501502
*/
502-
__mod_zone_page_state(page_zone(page), NR_MLOCK,
503-
thp_nr_pages(page));
504-
count_vm_event(UNEVICTABLE_PGMLOCKED);
503+
__mod_zone_page_state(page_zone(page), NR_MLOCK, nr_pages);
504+
count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages);
505505
}
506506
lru_cache_add(page);
507507
}

0 commit comments

Comments
 (0)