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, From patchwork Tue Jan 17 23:16:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 13105217 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 5FBC5C38142 for ; Tue, 17 Jan 2023 23:16:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E096E6B0071; Tue, 17 Jan 2023 18:16:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB9206B0072; Tue, 17 Jan 2023 18:16:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C80C66B0075; Tue, 17 Jan 2023 18:16:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B3F116B0071 for ; Tue, 17 Jan 2023 18:16:42 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 774581404DD for ; Tue, 17 Jan 2023 23:16:42 +0000 (UTC) X-FDA: 80365852644.03.026CCD6 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf11.hostedemail.com (Postfix) with ESMTP id B5BFF4000D for ; Tue, 17 Jan 2023 23:16:40 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=kOHVN4iC; spf=pass (imf11.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.214.173 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=1673997400; a=rsa-sha256; cv=none; b=LeCC2uZAS2VBE9JftSsxhuMuWA1Ut7gdNGwD7Wr3aDPfmGha8Jb2GtDSGl4Eu0iJry3P6G zhQc3c3IIWL/x4ZnBjW6r0tJwCcutvU4TSBFUiHxCMBe68SRG9t0+Ny6J3zf223VlNRUD4 7XY9jfiD9I0eGu2NjFyt60rau+8WNZU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=kOHVN4iC; spf=pass (imf11.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.214.173 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=1673997400; 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:in-reply-to:references:references:dkim-signature; bh=gTiyHD7Ef/752rEDI0F/LBvIYY0+LQDTJtaLZSqbVXc=; b=US2mLofmiGjpj1DUSYQL3t8kaDbsEp8Hobl1zSAgTZ3Vx3W+VbpDh1mpFh1NGC1WgjwE8n Kh7oXaYQ8zsC2qPIY8heMl5TBws26s6sg2ZY3PQBKcJHYSJ+TD6M9TUvuGd/nK4LxMDZyT RlzQZtWRxCbDHKq0x01aji23ss3hWsw= Received: by mail-pl1-f173.google.com with SMTP id z13so7308405plg.6 for ; Tue, 17 Jan 2023 15:16:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=gTiyHD7Ef/752rEDI0F/LBvIYY0+LQDTJtaLZSqbVXc=; b=kOHVN4iCCmfxv/zeMoeqp1NIDCtKrp3hBek5mMJSon6a/fiUKWljfakQaTg8gv/rm0 FcO/VFOYSl46GbdZAOp3L81OQ4NMnkVuIngOcoBNCdGaqrkn+TT90/HU5K6Gb04DIXum Pug1+4LyQZeU8NUjAmeV6W7wHa/IaFckbaRGSRS1nRrfsTqTFlfbqkfiRdW12W5fb58v qJkso7ivSEnXfhkEJnroxGe/+H9/8mY0Niyj9Qv5ADD5cCEqkbgjg3fzZ4bCmCJP4FRu wtDP3Hy4Y9yo/qv/9lu6EzoAdy98bMM/ElSSd8PhoeKIc8t0VVQSilNV6W9GsG0LUmqs P12g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gTiyHD7Ef/752rEDI0F/LBvIYY0+LQDTJtaLZSqbVXc=; b=7tH94g6NZAn7IRn34noOYuFxPQIvoew/FZ3rGf+jcjQC/vE2/iEPRAnGXyhdeiw2A/ YZgRkuHRfQq0lOIeAgeiyBzgeq7nMU06l7JcUibb6h/dgnp6eBdc8gUdMVxFwaT2w30b AMLe9mqqObLDEsGs3BFaE38Ulwd03WhlB24rD0UzNqC7yllsQuwb3flpRW8/k/25i480 /q0AZw6jyVBF6R6rvesi90fpyGce1mg4IDgGoQUli7qucfxjyMdjD49MjU93QP8SfkBg wuBzv/lhlW5CleogNvAm8Qrtm9wgYVjeKKnXGMunrh14d1ZGkAS9c36z/pqUcDlhQwJ8 MR1g== X-Gm-Message-State: AFqh2koXfELF2UO+mp3DHluq6NL1EBVJAotf3IBoHEyIBudRR0Pxwbac 9J2ldVsLZ8K+ldyBITVbP/I= X-Google-Smtp-Source: AMrXdXuoGPnt0eAYkj7iSPPjbAuqd8tFEbpGverST+idm85MqQnUhGUuQkjo3Rol7XmplIK3mdIY8w== X-Received: by 2002:a05:6a20:939f:b0:b8:99e3:4835 with SMTP id x31-20020a056a20939f00b000b899e34835mr5398685pzh.17.1673997399645; Tue, 17 Jan 2023 15:16:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 15:16:39 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: Suren Baghdasaryan , Matthew Wilcox , linux-mm , LKML , Michal Hocko , SeongJae Park , Minchan Kim Subject: [PATCH 2/3] mm: return boolean for deactivate_page Date: Tue, 17 Jan 2023 15:16:31 -0800 Message-Id: <20230117231632.2734737-2-minchan@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230117231632.2734737-1-minchan@kernel.org> References: <20230117231632.2734737-1-minchan@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: B5BFF4000D X-Rspamd-Server: rspam01 X-Stat-Signature: p31i9jjpp3w4qz6asfe1egnnf7dujsuz X-HE-Tag: 1673997400-722789 X-HE-Meta: U2FsdGVkX1/GcwG6FkNpIorlysiJpKcEiJtMXDr/0H7BHmlrMDK2+9ceZoMxGwDNUinucEzsx+Sx6wyLl/qyTCoNNjwVxad2LhLtl4URfs5qXStZsT5fC3db1+0CGRZHVQmY4gq+NhTQ9oud4uAeG3L83J4m2UoDh0PWGO66YJsG+Jcd1QgK3wTB3QfqTY057J6hfF+pQAuqdEBP1gg3tjF8G19gc0i3FNk249ZqralkoT+EPV2UeicaqeUsf1IY0k93jUPLzPQ1+B9pG86LIUIG7vcjRaaiFB9+ArA6PnMtCMX3qyJ6zp4F6Z4N7IoiAvWQtQKpPADZfMdhhyL+aN0DdnqV6vGdM48wYUR+R34lzYIH9Nm0MuXaClraQqSp5ez5fULPmYnlurS1U1hLKjVMkw+0nfFeTrRvYb2zSegHADBXfpywAuNbydZe3YT+9wst/5y2R3BlP7m1/d2Dk1F6VRh2+9+COzBI92rNlyC8wZi3i1W2aC+tAL2AqTwtnuJl9GR9GoYCqqTY72tKrq1nohRC2bWNIMS35W1vi2VmSxf0WcCtPE1JSzFU6IfZqCUCfYWnuKmPnfTrhQhCKBd7WXqULW3OH79wu3RalJEmYY/ZEgShScR18+/juNQLMqRHT5PnoixALHQ84PS6mTfAJ1GJhoPWXno3zrU213b2TkSSWQGeH7cspKI9h+X7d0Ifjh4N0Ou8RZ80JQEwDbACqnHFeJhsaUMurlga5zHrgM3JawIQ9pSFVgpc3rdzf9o5wCsnwZzwT9oVzzVydOMTZvYSmESZ1sH97CVLko13SVums6t97kK9Iay6eV68x6UsN/ZyJYM9HwQ6nazSGCNE/ie/ZEUS8HTbyqF8ZyzvURO/vuuDE9QcDA7GENasFbNnNNB6bbqq4/Sn6JBOCegFHFbud1ZRwU+qqlZv2/UPU/rIXMjZiWqHpWE2IaamBBN6LoQJ4Z7rs4X9A/H DNbM5hwm j6q94rWSXpW8OiyIfWsM/5cmboPtMgm2+WyaYEx0rUvq3CYSSRquSF50Yl48Y36OgZSSOA4uIx3emyuPMNJEV1ZVJ08GTHEMe9l2nGNqEvTFY1r5B6kphZtFYDG0q47IFzzgWUwblHHGvCD8uOHuoUW0yfAyvDJbmYL6g7TnWqM2bYNgX12au2yhGk26NeGXDkPa02esC+JfMX3s5O336j3dpjsMoBJqkgU1/R5RVD1C2JhaMTnvtk51EHg+yQJ+/+HlEOnL0LZntKDPn6aECSwjthzvA80T14K466xXIj4VbPo/vE7xYkkdFwmN4Bfd42R7VGI2ixSn1Bx5Wl5w4HUScwRmiEs5xJOMGHyw/ZDD/w8kaNtiO0MmH1sJfbh7tVbTfTfccfZ/rpAqTTE94/hkbGGsNWX+S8YMwS9lLjHaMO2o= 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: Returns true if the page was successfully deactivated. The return value will be used for statistics in next patch. Signed-off-by: Minchan Kim --- include/linux/swap.h | 2 +- mm/swap.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 0ada46b595cd..803e5fa4cd86 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -409,7 +409,7 @@ extern void lru_add_drain(void); extern void lru_add_drain_cpu(int cpu); extern void lru_add_drain_cpu_zone(struct zone *zone); extern void lru_add_drain_all(void); -extern void deactivate_page(struct page *page); +extern bool deactivate_page(struct page *page); extern void mark_page_lazyfree(struct page *page); extern void swap_setup(void); diff --git a/mm/swap.c b/mm/swap.c index 955930f41d20..52532859c05b 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -725,9 +725,9 @@ void deactivate_file_folio(struct folio *folio) * * deactivate_page() moves @page to the inactive list if @page was on the active * list and was not an unevictable page. This is done to accelerate the reclaim - * of @page. + * of @page. If page was deactivated successfully, returns true. */ -void deactivate_page(struct page *page) +bool deactivate_page(struct page *page) { struct folio *folio = page_folio(page); @@ -740,7 +740,9 @@ void deactivate_page(struct page *page) fbatch = this_cpu_ptr(&cpu_fbatches.lru_deactivate); folio_batch_add_and_move(fbatch, folio, lru_deactivate_fn); local_unlock(&cpu_fbatches.lock); + return true; } + return false; } /** From patchwork Tue Jan 17 23:16:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 13105219 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 81285C38147 for ; Tue, 17 Jan 2023 23:16:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77AC56B0074; Tue, 17 Jan 2023 18:16:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 703436B0075; Tue, 17 Jan 2023 18:16:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A54B6B0078; Tue, 17 Jan 2023 18:16:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 448DA6B0074 for ; Tue, 17 Jan 2023 18:16:44 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0EB53140BC0 for ; Tue, 17 Jan 2023 23:16:43 +0000 (UTC) X-FDA: 80365852728.22.E685980 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf22.hostedemail.com (Postfix) with ESMTP id 49A3AC0003 for ; Tue, 17 Jan 2023 23:16:42 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="pS/gUVrl"; spf=pass (imf22.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.216.50 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=1673997402; a=rsa-sha256; cv=none; b=yPkEtB12WZ8b610x3tZRC1Ifzvvzu2Qh2CmDdaesraP8uPEJ99tLZDymPtYLmYHs2m0ZVP wh4EIm3frI7xOlyBaIczdjYpWuVv4LYECeN9RSGorrd0N+O1W0VGsL5DAVAoIq9A/TJlwi YNaSQbktPFZ9yYCsWkIHjo8JIdUfg4Q= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="pS/gUVrl"; spf=pass (imf22.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.216.50 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=1673997402; 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:in-reply-to:references:references:dkim-signature; bh=SMrwqounr0oUuG21W3XQfHvNf7os8CE1mar5f82JgxI=; b=KN/oqBZpLuB11EukzkQIMRlM3jpj35C9tiIfFM3HkYsiuSHG5C7wCo9wIrwxIAadv0xzu7 ZB9IhtjvYFi0pEuQ4DrjsebhkXygKMcFMFEDFGpojCTP3xlhaLl+NfsGDKLDSxmTqzHHWs u84XSE2wvlJ/h613k9sFAc1fUH8MCSE= Received: by mail-pj1-f50.google.com with SMTP id a14-20020a17090a70ce00b00229a2f73c56so468966pjm.3 for ; Tue, 17 Jan 2023 15:16:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=SMrwqounr0oUuG21W3XQfHvNf7os8CE1mar5f82JgxI=; b=pS/gUVrldsYuEvQWJem29eVikSvSY6AeGUnyAPPRx6JDLPalLF60OpyhtfbbhHVVNM blAGDRem/RXiBLYfhuMkVXlzQoEevYfTJApvZpXgxChB0zanFmX4sQTTir8d8RU7VdnS 5etir+xvETOpNvcIV9bzFP2EgZAASyCC2oVNPvv2pyP3VQB+zJ2eOPbHDGk9+TlUNMV+ f01T0BGb5Ozy++CKL4jWy5zgrnLZasNM3iqlSlU8yqlG08r7PqBbBHHQs2LU8plQM83n vdvOozKeSEhUDGgoZk0NuVQgif0pLhdH2EwrlcSLqO2NbFyZr5bBJ4WlwhLAcHJPGLkO cW2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SMrwqounr0oUuG21W3XQfHvNf7os8CE1mar5f82JgxI=; b=1Gip+CFNvOyOv6ZNL3bzeo/cDgLatY4GpeGf3hW5/4Hfb2DgHnBp4eEPP5e1Ui75Zh gg+cdeYo4MWGBZpZifxG/Z4Kokr4B9MommweKhqzU2uiWEhwd15sqAaCNQB78ICI2fLs 32eG9+KIFxl8UuujAcGRqLWZvvKDXIbXPONgrn4SSYGOSUGrLOUusri9fpFjQE85B0cc jV0GZG2FougT4LZoOrhP2azyyGjT0lGbFp13LF/0p0iQWuMxydw1X1FusScfSyNoPj6t pDCAlPp4WL8OfKyLkrWTDIyYj1ASGJ+Y8DTKR4qr09p1dYcR8OuBHQ6VwKhWsY+yH5sP meig== X-Gm-Message-State: AFqh2kpubH7JyMsSK0AmV/q5PPqRu1wQe6LmMcVcNbs2oNMaLReA7kMW oh+O6vAI3dbjcdWdKPRTseE= X-Google-Smtp-Source: AMrXdXvqtSKvPavOcMP4zOcjlEw09DB95at5PzXmZy3YQqaMHkTZhaqtBL/dDhIgMMCEEiBr3o9T/A== X-Received: by 2002:a05:6a20:4e26:b0:b8:a148:63b5 with SMTP id gk38-20020a056a204e2600b000b8a14863b5mr4792999pzb.3.1673997401048; Tue, 17 Jan 2023 15:16:41 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 15:16:40 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: Suren Baghdasaryan , Matthew Wilcox , linux-mm , LKML , Michal Hocko , SeongJae Park , Minchan Kim Subject: [PATCH 3/3] mm: add vmstat statistics for madvise_[cold|pageout] Date: Tue, 17 Jan 2023 15:16:32 -0800 Message-Id: <20230117231632.2734737-3-minchan@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230117231632.2734737-1-minchan@kernel.org> References: <20230117231632.2734737-1-minchan@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 49A3AC0003 X-Rspamd-Server: rspam01 X-Stat-Signature: f7a585jj4zca888hxrwi9n1jbhceu8xf X-HE-Tag: 1673997402-330454 X-HE-Meta: U2FsdGVkX18jANKQfjf6GylTCFPWm0whG0ZLK4SNDpZGrpzcU9EF6A1D1pCDoiFg77i1DNuyX00l83Lye4ciYPeqw1WTwLT6oBRHd9pC6yFJl5uWPc2WdbOZHEyW0TyFVd8zGO4iZ25QN1EVr/BPx/o1G2MSzYfzs4Dpd9afOUXaKiOZltLgB7UyAIDF32RPAAd3/sFqP21haQNZpxBcLoJLTJNMRbYQnKrnnbpnzxm5OjioR80ifB8dYJ3cK4eU31p2p/UzyEuHCG/47nLI9LqLzID5B8kRUgEOphe05a1ocwYSw8VnyOqR9VaLH+UlKAxTKzwKQl/C6vcsGd4/OukS71Xi4NU5XBrDLQ2pQa1DlA0XHR6iwdWzxg0zLYCN54O82XmGAfAKH2MmjDKho14Rya3nBynEVi06gRix9lmrJk9oswXAJiIFTohW9gg4vGT9ySAzqberzkTCwom9DKW+NVA1HKfG6RVqC1HL2gazHqffVn+Gw+4BRmHwmC+IJ5BW0bIQxou3AIxjJBOf0LSeEMi87o94516dM4ILcSonRPJSnw30kFeym9/oMyWJDXKpdB45gn90XSaZf99vXrUNlS9RTjo6Flfs8nNI0VvTv55+FYgjbssoyEaB1Ca6oPfR+gPlcaG4jLeavprKN2wSEZzcxAc3j0b0vXP6buyEuIGbEBIhRuy6yr2IMicr5vourc1GoAIsgmS1zlXkW63/w0SEX747ySiaT/pahrc85aqWWaQ9Squm+UEobzd+wkBeaeupAUsLBGwYrh4aFfDAF0b1nys6bUnupuH8gro/Dmu0Jn3LGyTqeiKi8W8gCisQpLpOUFpYrjnQpYhSlIRBP7PyVRN6ZiHUvTnsquPMzSJ4K/n5QbSblpXbq/FgpWHSKjNln86Ih7zvd5qVjwzcMgj4ZsisdxIYgyotvbxkAQiItOvgCZl61VuYhcfTcz7v8ySBujVD2Ye6FeL jcW4xA0+ PUcvuSgTT2gltcXlKRamOGOW2L4xA/xN/z7+vMLOx8akwbyxmEsqKW6mFAmYet15X1pnes0VKx3WvkkzjeNui/FDcXeY6RWIlLr5u/0gzNMBp590aLP3zU8Fnqu03ffZBNtg+OG17WDxVe60KcZHX9Zbhbx97pMQ7xYmZBtlgSSWAfL0ZGg3qRnB4P9wYN6ZRi3Ie+pAEtYLVunx2MNSiFnGniSJqdoipLohCSJuwJbffNa0vNQEt5HNKg2RHlC7BCvOidWxp0KdK2zd8nVo2ug8BUTNJbBsLlEmo/wY7Bn0YQ0EF4OIzXXTrQ+gd3AT8KjrIdZq6K4iVrk40eev4f2aAdXnySyYHq+msrJrJRY+WVja8LyI1Gpkq9uZhsYrPalejVTWqKz9ZEHFUSvrJYyFqlTuGDDqvNnAK+SR/ZdAJY6Y= 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: madvise LRU manipulation APIs need to scan address ranges to find present pages at page table and provides advice hints for them. Likewise pg[scan/steal] count on vmstat, madvise_pg[scanned/hinted] shows the proactive reclaim efficiency so this patch addes those two statistics in vmstat. Signed-off-by: Minchan Kim --- include/linux/vm_event_item.h | 2 ++ mm/madvise.c | 19 +++++++++++++++---- mm/vmstat.c | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 3518dba1e02f..8b9fb2e151eb 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -49,6 +49,8 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, PGSCAN_FILE, PGSTEAL_ANON, PGSTEAL_FILE, + MADVISE_PGSCANNED, + MADVISE_PGHINTED, #ifdef CONFIG_NUMA PGSCAN_ZONE_RECLAIM_FAILED, #endif diff --git a/mm/madvise.c b/mm/madvise.c index a4a03054ab6b..0e58545ff6e9 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -334,6 +334,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, spinlock_t *ptl; struct page *page = NULL; LIST_HEAD(page_list); + unsigned int nr_scanned = 0; + unsigned int nr_hinted = 0; if (fatal_signal_pending(current)) return -EINTR; @@ -343,6 +345,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, pmd_t orig_pmd; unsigned long next = pmd_addr_end(addr, end); + nr_scanned += HPAGE_PMD_NR tlb_change_page_size(tlb, HPAGE_PMD_SIZE); ptl = pmd_trans_huge_lock(pmd, vma); if (!ptl) @@ -396,11 +399,15 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, list_add(&page->lru, &page_list); } } else - deactivate_page(page); + if (deactivate_page(page)) + nr_hinted += HPAGE_PMD_NR; huge_unlock: spin_unlock(ptl); if (pageout) - paging_out(&page_list); + nr_hinted += paging_out(&page_list); + + count_vm_events(MADVISE_PGSCANNED, nr_scanned); + count_vm_events(MADVISE_PGHINTED, nr_hinted); return 0; } @@ -414,6 +421,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, arch_enter_lazy_mmu_mode(); for (; addr < end; pte++, addr += PAGE_SIZE) { ptent = *pte; + nr_scanned++; if (pte_none(ptent)) continue; @@ -485,14 +493,17 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, list_add(&page->lru, &page_list); } } else - deactivate_page(page); + if (deactivate_page(page)) + nr_hinted++; } arch_leave_lazy_mmu_mode(); pte_unmap_unlock(orig_pte, ptl); if (pageout) - paging_out(&page_list); + nr_hinted += paging_out(&page_list); cond_resched(); + count_vm_events(MADVISE_PGSCANNED, nr_scanned); + count_vm_events(MADVISE_PGHINTED, nr_hinted); return 0; } diff --git a/mm/vmstat.c b/mm/vmstat.c index b2371d745e00..0139feade854 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1280,6 +1280,8 @@ const char * const vmstat_text[] = { "pgscan_file", "pgsteal_anon", "pgsteal_file", + "madvise_pgscanned", + "madvise_pghinted", #ifdef CONFIG_NUMA "zone_reclaim_failed",