From patchwork Tue Jan 17 23:16:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 13105218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A5E4C00A5A for ; Tue, 17 Jan 2023 23:16:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 189066B0072; Tue, 17 Jan 2023 18:16:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 09B836B0078; Tue, 17 Jan 2023 18:16:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1D346B0074; Tue, 17 Jan 2023 18:16:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BDBE06B0072 for ; Tue, 17 Jan 2023 18:16:42 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 87DE21C5B35 for ; Tue, 17 Jan 2023 23:16:42 +0000 (UTC) X-FDA: 80365852644.02.E8BFC93 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf03.hostedemail.com (Postfix) with ESMTP id CCFD720010 for ; Tue, 17 Jan 2023 23:16:39 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=j08AWUcI; spf=pass (imf03.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673997399; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=QYlhvxpn1g/r4dWO5+sPLebA9xNT77jNrSyttGo3dyo=; b=S2xl2bvkWJSBWFH55mc4dZ6d+HYROc3VIyS4h8R3ZrCfYHBZSOGwBTiEu2zt0i5QgnTx1W wImweF4lyJRTMQLWlI4rlQw4yIlmNXKpZSeQ/uU70j5avaIIXlNytwD88tMBLkYEDrGvCV XT73y9MhPYufM6V8SwdvRnXBiNV2JX4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=j08AWUcI; spf=pass (imf03.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673997399; a=rsa-sha256; cv=none; b=EoNOANNH2Bp+6fzHzwftvWxvJJ75i3UTvgcAdh7nk2oKM9Z1NLqX4Z9ZRksjl1XrWn/XDX f83vu3g6iEmIGZXDqom307VU8LPMdIooOebcgCwmG+hPSo91rMRjuGW2XoawE0wBGtvKJQ cHN/Ljq1zCKK8cmJ0LbNmEeUyRfT95Q= Received: by mail-pg1-f182.google.com with SMTP id v3so23210324pgh.4 for ; Tue, 17 Jan 2023 15:16:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=QYlhvxpn1g/r4dWO5+sPLebA9xNT77jNrSyttGo3dyo=; b=j08AWUcIVyI2/yHykLABxKp1sDwWbEofJttmSP3/rw60yRelBsKPqIfY4+/bYgIPxC 5ynfexqfZiEffFJ5WzTJVnRQaaB9wvKnBE5HA/5VvZr/Q4C+NxxVPvRz2Aj4LUyMbqyp ROiePmzKnmm49Em7xPM/47hH6vWeqFb6aFEv7chKTg6fQBxGvD3ClP9cLVVXmStFUSsy jjqS8CGg4yibtu21orMKGYOrPW9DdQSLtICy8MB0nRyvGhzCcSvZYeuNO3gjVaV26wEE B3mJrW9472YkkUVzWdPV9GJ4KUM/N03MP0Y/F53hIMCLwIC7cQOYuCY7YftWDQYCzQ5I Okfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QYlhvxpn1g/r4dWO5+sPLebA9xNT77jNrSyttGo3dyo=; b=atoKlB6alCfKIr+EmC4NlrPMeKg06+77l/axvVzHK2NJQs+iyOnVpaeTXulR8edgM8 pqRhbTCZXuNFcpSYascfA1HovXfrvDWD2M/SQ4pLlITe+tsWulnxHyF/dHcoXWTL56nS HeuTlo4OhyRpE7bZXMq3X2n3MBxtleHB5dQ/gYuk8A1ROtvYIIVdAhKZLghtH97g8qKu SsLU9xJbAJN24tufr2ZCvVQ5JrdqqaTNKrG5y1+LUT7IbOGJgDVB3f/AdNfMaYFVyWV/ eLFAehek9oocd5ORxkw/fTy059xpqLtCBmP2G3bzm3AjGW7ObS9sX/HnDSyUGtDL2L3W bLmg== X-Gm-Message-State: AFqh2kohsy/z5X2TNALTq3lFtv2gWlpxwaU9sjN7Xw2RD/o7l/d/Q8Bs lW7CHx6C8gYaqcxjnpgmdKk= X-Google-Smtp-Source: AMrXdXt9femFWM5vCqmpojysBu31yevt6KdvWuuzJnuY+tl/Bw5Cphuw+uWzvw5j8aS/tOWf6OxAbQ== X-Received: by 2002:a05:6a00:24d4:b0:57e:866d:c095 with SMTP id d20-20020a056a0024d400b0057e866dc095mr6948251pfv.25.1673997398358; Tue, 17 Jan 2023 15:16:38 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:27ce:97b5:ee13:dbfe]) by smtp.gmail.com with ESMTPSA id c24-20020aa79538000000b0057447bb0ddcsm5180965pfp.49.2023.01.17.15.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 15:16:37 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: Suren Baghdasaryan , Matthew Wilcox , linux-mm , LKML , Michal Hocko , SeongJae Park , Minchan Kim Subject: [PATCH 1/3] mm: return the number of pages successfully paged out Date: Tue, 17 Jan 2023 15:16:30 -0800 Message-Id: <20230117231632.2734737-1-minchan@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CCFD720010 X-Rspam-User: X-Stat-Signature: kxwyoggchinqkubdiuhdo36mkux5kehk X-HE-Tag: 1673997399-70203 X-HE-Meta: U2FsdGVkX19CLttzEPS8PDi5026f+0FNBYDIcZEdcUP/l357xfqkdULe+Jyp5w5kBadDNmh6yAxSPZCqRy2+8Xypn33rLqDPV7Oimk+R3BiE1JlgU6R2I0CaTD8zpa6nbxxSdh7jZax2muCN8msZwTKOXFRYU5qRa0jermnaEdpTKkSStEQWT8VJwB69461RMaoE9hnNe4e9LpFJ/cPzx2XGAMGdRXcliByNLDqhfxuiDhyzzVDT1QAUUC1ZWHDz6bqQ7/hrzA01Qlsl49x8ePxU0OxB5OXk2EhEvZ2G9JB9JIo2s/yKN/R3krgMD3wrBZe3DFQXP3j6ZB4Xk11cjz2WLItsxHTC8Pynjv42gk2ZAkidrqwj5ncNU8cvpD168YvD1rR9mkg7hm3TBCsjDl3nrU2CKuzH2DCzDqkOSmYnWLuLqVbJzTd2mqcw9yKEfZbNlqAFt4Wt8TOCJIKCcA0M+cltLXIAYBDiKaeL9FNQRpomy7sLQEfe52PdmElbpRGcYvyp8lV3IvGmdMqDRi/SX0CANmrcehRxzgvGg8Ecp1cMaDuZcFBp7KOVkEv/In3c+zjudTe0i7nFOFoqwZDSVxzCQm7lIP3iHalFWoaQBhFlA2dyei+UvrSRIUs498JqExt0+3kkMqXl/xxRZ6Ft3Y7/Tqo4DAE5afdo+F20vxAZVB8xv0bA86vxVc5SKKq41UWjhufZqDdmwROn76AMwpmdzaBozFPXamFsqPnKJovz3RpF0UMcu9om+bTTRazJorledwokvtSW9RWx6RUbgxGaz3pnw4Pv0PacljPVjLL7Cvbes4/PAoxpyZsV2KbM/3mSqAJrgfiNSb/nd+ZPYpO8gUTweBEC5MFhbGRNYgMVCzZfdcvcOs3h7eWoO+UT2oY2ty0q8uZ8AEuMpF9F+B/0+171LwSFml/aFdXcMMS/Op1DnP65dXhmf2ttzUEIfNOuxhoKFgMV01k TBx+snfP sRQE5uzMx4qPCwCqA5IXos/5dKBR+rHEAK9X3eb9smdNEPOHq8OtNEKci5FdQtBc03vilfqsbjuSFL65bYqQzWevGkixoL+RFRc1WGUeZe+FW3cZ67z4nm5V8fx6R8vs6AdkyiEH4mNo6NX1rwz5YBJ6HvNeTJjreXyd1dy/jseWAIHoVPmxUzwm1QuccocC0UW2zjsFOnj1xgIOxYP9GDkFFRRjtbzGnG9MS2QiMeKtkF4TuCQ8Ef+pSOwI2vOk5qp42TthTvjTQkumBzzWWeWmLxZINX3o0VQnPFKwBQX+Q67qoLpKaNDFDZ2BEAmGR6i+mjhv7oO7JVOYSn9r9jWxfadALD9cY/TzYoKnK7P4b6kcyC67/xlIYu2a/4YRGo/z1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The reclaim_pages MADV_PAGEOUT uses needs to return the number of pages paged-out successfully, not only the number of reclaimed pages in the operation because those pages paged-out successfully will be reclaimed easily at the memory pressure due to asynchronous writeback rotation(i.e., PG_reclaim with folio_rotate_reclaimable). This patch renames the reclaim_pages with paging_out(with hope that it's clear from operation point of view) and then adds a additional stat in reclaim_stat to represent the number of paged-out but kept in the memory for rotation on writeback completion. With that stat, madvise_pageout can know how many pages were paged-out successfully as well as reclaimed. The return value will be used for statistics in next patch. Signed-off-by: Minchan Kim --- include/linux/swap.h | 2 +- include/linux/vmstat.h | 1 + mm/damon/paddr.c | 2 +- mm/madvise.c | 4 ++-- mm/vmscan.c | 31 ++++++++++++++++++++++--------- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index a18cf4b7c724..0ada46b595cd 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -435,7 +435,7 @@ extern unsigned long shrink_all_memory(unsigned long nr_pages); extern int vm_swappiness; long remove_mapping(struct address_space *mapping, struct folio *folio); -extern unsigned long reclaim_pages(struct list_head *page_list); +extern unsigned int paging_out(struct list_head *page_list); #ifdef CONFIG_NUMA extern int node_reclaim_mode; extern int sysctl_min_unmapped_ratio; diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 19cf5b6892ce..cda903a8fa6e 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -28,6 +28,7 @@ struct reclaim_stat { unsigned nr_writeback; unsigned nr_immediate; unsigned nr_pageout; + unsigned nr_pageout_keep; unsigned nr_activate[ANON_AND_FILE]; unsigned nr_ref_keep; unsigned nr_unmap_fail; diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index e1a4315c4be6..be2a731d3459 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -226,7 +226,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r) put_page(page); } } - applied = reclaim_pages(&page_list); + applied = paging_out(&page_list); cond_resched(); return applied * PAGE_SIZE; } diff --git a/mm/madvise.c b/mm/madvise.c index c7105ec6d08c..a4a03054ab6b 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -400,7 +400,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, huge_unlock: spin_unlock(ptl); if (pageout) - reclaim_pages(&page_list); + paging_out(&page_list); return 0; } @@ -491,7 +491,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, arch_leave_lazy_mmu_mode(); pte_unmap_unlock(orig_pte, ptl); if (pageout) - reclaim_pages(&page_list); + paging_out(&page_list); cond_resched(); return 0; diff --git a/mm/vmscan.c b/mm/vmscan.c index 04d8b88e5216..579a7ebbe24a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1933,6 +1933,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, goto activate_locked; case PAGE_SUCCESS: stat->nr_pageout += nr_pages; + stat->nr_pageout_keep += nr_pages; if (folio_test_writeback(folio)) goto keep; @@ -1948,6 +1949,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, if (folio_test_dirty(folio) || folio_test_writeback(folio)) goto keep_locked; + + stat->nr_pageout_keep -= nr_pages; mapping = folio_mapping(folio); fallthrough; case PAGE_CLEAN: @@ -2646,9 +2649,9 @@ static void shrink_active_list(unsigned long nr_to_scan, } static unsigned int reclaim_folio_list(struct list_head *folio_list, - struct pglist_data *pgdat) + struct pglist_data *pgdat, + struct reclaim_stat *stat) { - struct reclaim_stat dummy_stat; unsigned int nr_reclaimed; struct folio *folio; struct scan_control sc = { @@ -2659,7 +2662,7 @@ static unsigned int reclaim_folio_list(struct list_head *folio_list, .no_demotion = 1, }; - nr_reclaimed = shrink_folio_list(folio_list, pgdat, &sc, &dummy_stat, false); + nr_reclaimed = shrink_folio_list(folio_list, pgdat, &sc, stat, false); while (!list_empty(folio_list)) { folio = lru_to_folio(folio_list); list_del(&folio->lru); @@ -2669,15 +2672,23 @@ static unsigned int reclaim_folio_list(struct list_head *folio_list, return nr_reclaimed; } -unsigned long reclaim_pages(struct list_head *folio_list) +/* + * paging_out - reclaim clean pages and write dirty pages into storage + * @folio_list: pages for paging out + * + * paging_out() writes dirty pages to backing storage and/or reclaim + * clean pages from memory. Returns the number of written/reclaimed pages. + */ +unsigned int paging_out(struct list_head *folio_list) { int nid; - unsigned int nr_reclaimed = 0; + unsigned int nr_pageout = 0; LIST_HEAD(node_folio_list); unsigned int noreclaim_flag; + struct reclaim_stat stat; if (list_empty(folio_list)) - return nr_reclaimed; + return nr_pageout; noreclaim_flag = memalloc_noreclaim_save(); @@ -2691,15 +2702,17 @@ unsigned long reclaim_pages(struct list_head *folio_list) continue; } - nr_reclaimed += reclaim_folio_list(&node_folio_list, NODE_DATA(nid)); + nr_pageout += reclaim_folio_list(&node_folio_list, NODE_DATA(nid), &stat); + nr_pageout += stat.nr_pageout_keep; nid = folio_nid(lru_to_folio(folio_list)); } while (!list_empty(folio_list)); - nr_reclaimed += reclaim_folio_list(&node_folio_list, NODE_DATA(nid)); + nr_pageout += reclaim_folio_list(&node_folio_list, NODE_DATA(nid), &stat); + nr_pageout += stat.nr_pageout_keep; memalloc_noreclaim_restore(noreclaim_flag); - return nr_reclaimed; + return nr_pageout; } static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,