Skip to content

Commit 730cdc2

Browse files
cmzxoakpm00
authored andcommitted
mm/ksm: fix ksm_pages_scanned accounting
Patch series "mm/ksm: fix some accounting problems", v3. We encountered some abnormal ksm_pages_scanned and ksm_zero_pages during some random tests. 1. ksm_pages_scanned unchanged even ksmd scanning has progress. 2. ksm_zero_pages maybe -1 in some rare cases. This patch (of 2): During testing, I found ksm_pages_scanned is unchanged although the scan_get_next_rmap_item() did return valid rmap_item that is not NULL. The reason is the scan_get_next_rmap_item() will return NULL after a full scan, so ksm_do_scan() just return without accounting of the ksm_pages_scanned. Fix it by just putting ksm_pages_scanned accounting in that loop, and it will be accounted more timely if that loop would last for a long time. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: b348b5f ("mm/ksm: add pages scanned metric") Signed-off-by: Chengming Zhou <[email protected]> Acked-by: David Hildenbrand <[email protected]> Reviewed-by: xu xin <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Ran Xiaokai <[email protected]> Cc: Stefan Roesch <[email protected]> Cc: Yang Yang <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 2ef3cec commit 730cdc2

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

mm/ksm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,18 +2754,16 @@ static void ksm_do_scan(unsigned int scan_npages)
27542754
{
27552755
struct ksm_rmap_item *rmap_item;
27562756
struct page *page;
2757-
unsigned int npages = scan_npages;
27582757

2759-
while (npages-- && likely(!freezing(current))) {
2758+
while (scan_npages-- && likely(!freezing(current))) {
27602759
cond_resched();
27612760
rmap_item = scan_get_next_rmap_item(&page);
27622761
if (!rmap_item)
27632762
return;
27642763
cmp_and_merge_page(page, rmap_item);
27652764
put_page(page);
2765+
ksm_pages_scanned++;
27662766
}
2767-
2768-
ksm_pages_scanned += scan_npages - npages;
27692767
}
27702768

27712769
static int ksmd_should_run(void)

0 commit comments

Comments
 (0)