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: 44868 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2052798wrn; Tue, 17 Jan 2023 16:11:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXtO7fj/AOtA3Buhm25CZC7VnE1Y85dKTedOoAs+XlbDS+1shEU+sCZJ6UUcDWvgYnJnmWdl X-Received: by 2002:a05:6402:5419:b0:49e:351d:37 with SMTP id ev25-20020a056402541900b0049e351d0037mr4074197edb.8.1674000680795; Tue, 17 Jan 2023 16:11:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674000680; cv=none; d=google.com; s=arc-20160816; b=dVibVg7yuMgMaMi/q9ZzpSvvBtwA3Ydl00cmqIAMKCWQlWqkxe5ClMwzIlrgAHc+/o iv9RGtiygIXkMXZetha+LYofOaSuzivnMLosLsJVfVIg++W0UuD1m37dRLa9qKQ72aFy 1sutv/yCSPefv92I1l4SUN9lJth5M9zQDI0NpDLhwm9dsZStlNNEhlmoaVzpZ1oZXjXL Kdb59iVVk3rkHsRbPKR6oXptnFIlafd2FZjKpy+FzWBnscbQgR1FD1c6mSHzhUpOtTfN 8/hpu6bBjVCKS9zOc5o9eQLj5VM67+0C/uc0kmXdAzGXrHvbrOTXSu7w3N+iu9ahawuX MMOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=QYlhvxpn1g/r4dWO5+sPLebA9xNT77jNrSyttGo3dyo=; b=KnLg+43D5fsZcnT005vG2EcYUn4tRgXu8gbz9LWJc6uG531ilOuRaeMPgjfecRCnWc lK6T97E/vJOlCwuv7uAwGttC6ZYgyJZTH78WB1N/SMU44q7929JxXTl2dWor49TbFxko t2gflKDXUzmmqN5Fs/XAZ4ccHNCMyhZlIW90aBVTKoBnHfHZYs+7K8A3CgfdxxiyHlo6 RTVyzgRLaMc+p46ig7J9WZZzitCt6kfiVPxOl2FlUjhWukiB2XN2SObYlwcK85ErUWwI 7BtRJtznLnI/rR2bh9JHqh39o1JRAUWNNPXAyY+boDmnmaFqXyFbwA8g8puUQeGvgKRL vOPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=j08AWUcI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v2-20020a056402348200b0049e29ce0a51si6474762edc.17.2023.01.17.16.10.55; Tue, 17 Jan 2023 16:11:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=j08AWUcI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229771AbjARADr (ORCPT + 99 others); Tue, 17 Jan 2023 19:03:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbjARADO (ORCPT ); Tue, 17 Jan 2023 19:03:14 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60353BD145 for ; Tue, 17 Jan 2023 15:16:39 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id g68so22107027pgc.11 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=Sy8E6ntsYRFe3KJO9fMnASiLGE7jqnZQBLWlxeQU5+ImJtHBruJsP4KzbbgmatmQnB jvB0OoB11HhG/8yDoyJbyU8QAF53eqGv85Y4xzOvg/RI5XY//y79NxfLHU4hc/LKbu6p uSzX9Z/a4HRAvZH1RmnzQ+ze/Iw7Sx9saGn/QesI7sYPSxf2nU0Mbwpw65XFJ3ltTKrp i5qoS442W89wQe+1VDTJoN9Ub9GFphSj7BSTVAIRdU5FmSbJsPY3Oc4Zx0eo2NOM5J1k aGyDwBP5NvzimnJTcnzimiOUiwzWhGiMvaFzV8jL0pEVSPYQsAxZqej/xeJlsGsX0u+I cVaA== X-Gm-Message-State: AFqh2kqJ42Wx6F9mhw/J7j7wNke+SzcbjDRVPUpozOaptjJc+KxXHNuH jSFaTtPlvBIOM9827DkwvFs= 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) Sender: Minchan Kim 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-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755316937993387097?= X-GMAIL-MSGID: =?utf-8?q?1755316937993387097?= 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: 44869 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2053117wrn; Tue, 17 Jan 2023 16:12:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXudsAbEmtgosJOk/64C9n9Z28DHA5GfgMYRldPOR/8f74K0LqMehSuE0zDocFfD+JzX3DXu X-Received: by 2002:a17:906:fc0e:b0:84d:3fa7:12d7 with SMTP id ov14-20020a170906fc0e00b0084d3fa712d7mr4598396ejb.21.1674000728496; Tue, 17 Jan 2023 16:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674000728; cv=none; d=google.com; s=arc-20160816; b=c5LWpBcNJ2VBokIMdfZAVuusBDnserTrfvUVIo5rqSQI57fSXcT+27YjQGPDCksH1s n9+92XwoJNUnSfKuW0BpQdeEEYaem2P1LjjdUM3E0yfmYjIg7+8WTtjse84pcvRWZ/z9 FiEPNldT2My70hVS7skiiLT3gMp4sUbp1zasqIDmOoOV51aYbXwbCpETj3MgJjTNcJ8W V3jcFWgxBoWGZLUdnwLv+QqOj0NBZsGZjWTmyTLm8jr9l0nh0kY3NBnAGrq0tZDdGOnB oJev7/0q2LpI8U/+Wsenlabsc6w1mMfLi38O2WevG2ldBDBfTKYnPOQMgsJdyWKdfafB bWIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=gTiyHD7Ef/752rEDI0F/LBvIYY0+LQDTJtaLZSqbVXc=; b=hN3AZAnBTIGcS+X1kvpZbg/5bGJLXyu0dDqsIVzS0MXAF9iQmgxmC5QHx9+tA9gpuT eiAgtBwHNyXxjeZyZ+MxNM/BRurxHioYtw49vfZkCDekWWHC01+moPXdagxEO8J3a9tw Dnjrck7D9xgHzhmr6mbRQzzO2TqAR5+QzaWjh+r5NTMyc1wvxm+hPlD+ATPGLLHH47T1 hFSA80X3kcFFkFandsXunsayPjxojMyt5KWLcJceir2JB37n6HDlZ2bvVqrjxFeG7spT hM6BX9A9fLYuDUUNrcX35mgwcgiOjGaD6LwYHy7KoyeoRJDu33efhDc95RHQVVWx8MUX /rLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kOHVN4iC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk42-20020a1709077faa00b0078797f6668fsi23878766ejc.364.2023.01.17.16.11.44; Tue, 17 Jan 2023 16:12:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kOHVN4iC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229600AbjARADw (ORCPT + 99 others); Tue, 17 Jan 2023 19:03:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbjARADQ (ORCPT ); Tue, 17 Jan 2023 19:03:16 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60AD3BD14B for ; Tue, 17 Jan 2023 15:16:40 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id b10so2483702pjo.1 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=7KBNU+FRkUwycTtp4wjc9e/FeT06d6U/lbk9XfQS+EBWiPceeOS4myHfxokUtWpLIY J9f0aXyRU6cyaqP13xU6HPYlvRfdXhGsff31vPtzJKSFjk5JAjL5uZpcAxsYZGOzA0NJ BCphjtLEWmCJfIhoK7pDGDT6MlrQP/6pjM0DF6SlFSHw3N2fO+Tim13l4sOngilvn5fX 1X15AtLCkbmHbn7Shh/dr9pMgRy/w1DZ/SM+FDIJ8ASgNUOPVj+w0aXVc3s0pWlDa4CN ixd378k5xdeicBQuv6yZy/vbXdB4V++AU/vLWz3m3CQNZf34/YaCKAZTwGu7jNxL9X8D 0QFw== X-Gm-Message-State: AFqh2kpFxHt+SiI7rzk5mJAJaF4XpZnBTMWZKi+Khjhu5RsKfIJvGyzi 7lbk3723WFRWvauORwowOj0= 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) Sender: Minchan Kim 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-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755316987509770231?= X-GMAIL-MSGID: =?utf-8?q?1755316987509770231?= 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: 44870 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2053254wrn; Tue, 17 Jan 2023 16:12:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXvxLMlKOpO21ybMHf+Z4qroiYPilAQFDPqqNAFCE/GgUxplycvslYnVW1DDOOsKvn5c9CBi X-Received: by 2002:a17:906:f0c7:b0:86f:41b2:3e with SMTP id dk7-20020a170906f0c700b0086f41b2003emr4856842ejb.71.1674000749281; Tue, 17 Jan 2023 16:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674000749; cv=none; d=google.com; s=arc-20160816; b=euym4Kv9efMJd/4YK07cradhyQh8xXp4B+l3oL6YSFbxGXT5TL+G+HjVIcR+93Io4C XbSXcbZqEXkl4UwX64P0FAUGJ0zP6cF8XSpja86FVGR43h2PO6EKJvBHNLCWZQjUpJ7T ZuVJ9tK6XwrnSC7f9pOwcftQpqeT0jqYxsBKqr6PczbTdiNKqNQz7SW9nqvkLUmTCdtj +Y4up6QGHAui65FBN8boFxmiLxnLuERhpRk/Kh1QaaYLhKnHuvc5DpEFzl6DoBpBBLwZ aYLslQF4iWCc/rI4uGPNl9Ak3kP2ejRyJVQuqrcekYrrEyt9EGrBCLzGCGvAVE8FhOLG M+kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=SMrwqounr0oUuG21W3XQfHvNf7os8CE1mar5f82JgxI=; b=G82QUUw11YihHNF205p7H0umqsic0Lx3DuYMX4MTpYKgw5Xv3FpuO8OEf2iabaRN6S e6rz+S2iTTVMUt1D9F3/JUq0AdRUZ8fp4+OHshGkG+tLoTd7Ws97sdgc1sgxP1dFN6n1 lNjbfuSpS+E/ExWPtVzqqEgfQx5B4qfkOcWDpCpf1yziT/Q61Wk65HFAgDP0EwAtDuMF PDI+3uQbC28FdTr5RAHvKEZFb8xF7LeEFpj1DE49Yqonq8XaknhnWwmKmokffVuYOQ2K eOb57ReQbZ9AriURp1nZuN19+lPI/QuiIbAnFAKdqwaAfEbulrOIMhZKB5aHCyIhfUdk Af7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="pS/gUVrl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ck17-20020a170906c45100b0078356aaeb63si27252023ejb.288.2023.01.17.16.12.06; Tue, 17 Jan 2023 16:12:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="pS/gUVrl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbjARAD6 (ORCPT + 99 others); Tue, 17 Jan 2023 19:03:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbjARAD1 (ORCPT ); Tue, 17 Jan 2023 19:03:27 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E44BEBC8BC for ; Tue, 17 Jan 2023 15:16:42 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id y3-20020a17090a390300b00229add7bb36so423268pjb.4 for ; Tue, 17 Jan 2023 15:16:42 -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=FyQAiGa3zC2gPZVsa5YHBd7DYOS/c6tbajDVpM1MTGpXFtEi0WeNirfBZ0brZdfXKy Qv6uZAi03F/WyJ9GVADO4Cwl8wteadoZxg8ifgQMZlxtQ4HsJXGx8sBuN6W6/o2cZ2FQ qAawAA+QSiTL7HOc+BV0Lt61T4nDwkDjWImD0x3kQ51cNDcqXZf89kPnTYQFKT7KvBpK cs6bJxw4tc0VnjnpfDbYwJAcXjumkYPZJeDtZHdepIQy7rxOJA+Ze9ADRnheppIw19/R uiWTF1A5rizlbFRuDzBricYSmToxveKjrTB2hWSXNZTcH2j1RzkvtLpINKR+NdGVVtVF 0w5Q== X-Gm-Message-State: AFqh2ko7fMoKvyMTrBcbPovuVzLREK0i9gCA6sWN8Iw9GIwGoRxmw6IW 2nxdxgBm1eZl7mhEcxjwtKY= 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) Sender: Minchan Kim 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-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755317009845110737?= X-GMAIL-MSGID: =?utf-8?q?1755317009845110737?= 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",