From patchwork Wed Jan 25 00:54:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 47988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp23463wrn; Tue, 24 Jan 2023 17:02:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXvKZTghwLIHOaglrxTHExqBN1ntD36y9yDJFiR5/RgjsJ90Pgz00cbpOVViSAKNBZ2dBLnN X-Received: by 2002:a17:906:eb54:b0:7c1:8ba6:6eb3 with SMTP id mc20-20020a170906eb5400b007c18ba66eb3mr30726627ejb.35.1674608567066; Tue, 24 Jan 2023 17:02:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674608567; cv=none; d=google.com; s=arc-20160816; b=tpUwYrYIC+VD04GhDGTOJmozeFvxdM0EBV3B3vT+swIb5AQCj5DmJS7kVBCjWlQgfz WHkd/yxLhCcQ26Hnvx5sYScLtAb1Y6gbhurHtyUcanKdoMONxPXNQkIejXD2Zdu5sUdH BGlMHDRBG5r8gll/yc+1/t8vvF4Yj2xHtv3XqqjOkdhZ3CzleSvMh2r/QbuG+q1YcprP XaD4DDx4MyCPamgmp1dq/mzZhpq33aL+CITuGRvtOqLBZkhgfULp2jGCP2voyZ3hIKoy N/UuOmRCLqK4c+Z2elkmqiCMt/PiAjzWjg8srQN80w2wOzuB8cGJIGdy+qwF+jcdFRvK 232A== 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=QltKSpTGzf0W2SQSXFYMm7GCriu7mCw+n+d5pfVUmzI=; b=p1V7+2GgRR3aruMSFhBIJj5FpGcmkDMFNrQnkrhmFZjZWibVduGs5hQyjc6gwolIc9 Gq+OP5mxFvANV3X+BuhOocQydjgMvP1aJOMkKxezSAk+CaMxIXYzEZtGENi6wbTz/STW L9iWQ64FGiuCZ/r1qbLjo10mtNtwtHJDQTkCkbbkaQYsze0v+P9YzC6iZiBH+Yjov37F jaUbhZ5LCgZ5lMW8WBazLiv8mV3YZrXsMupXGX8VUPKHR5V1xa8BYZ6pt5/5by8fHtcC BvOmFI6ibEm4zIae+dKmKA45Xa35Rl5l6fggMTkxyaWRaVKBiKGgy3XMniqR3zW4eD7d 09vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="SztRo/gP"; 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 jr8-20020a170906514800b007c12aad4c05si3924641ejc.123.2023.01.24.17.02.19; Tue, 24 Jan 2023 17:02:47 -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="SztRo/gP"; 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 S233694AbjAYAzF (ORCPT + 99 others); Tue, 24 Jan 2023 19:55:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbjAYAzD (ORCPT ); Tue, 24 Jan 2023 19:55:03 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A522B903F for ; Tue, 24 Jan 2023 16:55:01 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id 88so5314211pjo.3 for ; Tue, 24 Jan 2023 16:55:01 -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=QltKSpTGzf0W2SQSXFYMm7GCriu7mCw+n+d5pfVUmzI=; b=SztRo/gPi1DtM3PLDVXZHbb6GoWTRcTNOAOWMzjHK3/chfZSoCPdh0W6jNWnJ57BTP Wn12B6epK1ZGv8TrlkTddxdGUYThbooFXWFKI7CAWtIYTz8gS7m2K1bkOi+7L8jtwGWH +efWvGCE0QjbK0vPfkUDwWPvcSTmOdmWOa+SASdTeG+QvveQSMSkU654JPcu0RdIPMMe zn49Gx+gVgIwiXTeKfBnVr9veVFUOEHuj/07R/C/Ufm0nLB1lsxMnTzR+hje+0iZWq+m cjhydTDCT5/68GIm2ebCSo26R6ICjPHskKvQb+mqyrIJWmhQjU4QLavkBXTkpl64Hd/a 2XkA== 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=QltKSpTGzf0W2SQSXFYMm7GCriu7mCw+n+d5pfVUmzI=; b=KyOMMUj6+LfdU2T1I0hs+q+l0i6eLCE+Fq4MjXzwBpYf2JrhoL7gq1Z5XVXuHr+iVP NDfLmYNtxzWvQW97g1B6QpYODLgNfui5RWCqcnBTtVgQ40/7qoxr9szFKXXU7qO/zSzr us8IVng+WxmGdGowntPcfLY8zCoIFv8RK179CU0zm9IjU2lRefI/TSaLLMkgKZp3+k3M KXowu03LP2aqBSrkVyolMhFMemfZZHfsWHmPD1p8cUqvOAA2wKDQmDkSl8Vb8TurE1Zl dqywudsdlbHljVNoR/xpsLpMma2XmBjZZVSLK/RenYISh/gVxDjv10IdB3qg93jsdZ5o koQA== X-Gm-Message-State: AFqh2kqTRntcmqDc+ZbXAhEGORiYc4mh7LJmCwn8UkMHAjMPcu7icCR2 WpLLwhFiyqOpI2e201TmIrk= X-Received: by 2002:a05:6a20:3a83:b0:b6:5bde:3064 with SMTP id d3-20020a056a203a8300b000b65bde3064mr29899507pzh.16.1674608101144; Tue, 24 Jan 2023 16:55:01 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:7797:cacf:485:8c8]) by smtp.gmail.com with ESMTPSA id cq6-20020a17090af98600b0022bffc59164sm177272pjb.17.2023.01.24.16.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 16:55:00 -0800 (PST) Sender: Minchan Kim From: Minchan Kim To: Andrew Morton Cc: Suren Baghdasaryan , Matthew Wilcox , linux-mm , LKML , Michal Hocko , Minchan Kim Subject: [PATCH v2] mm/madvise: add vmstat statistics for madvise_[cold|pageout] Date: Tue, 24 Jan 2023 16:54:57 -0800 Message-Id: <20230125005457.4139289-1-minchan@kernel.org> X-Mailer: git-send-email 2.39.1.405.gd4c25cc71f-goog MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 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?1755954353002925065?= X-GMAIL-MSGID: =?utf-8?q?1755954353002925065?= 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 adds those two statistics in vmstat. madvise_pgscanned, madvise_pghinted Since proactive reclaim using process_madvise(2) as userland memory policy is popular(e.g,. Android ActivityManagerService), those stats are helpful to know how efficiently the policy works well. Signed-off-by: Minchan Kim --- * From v1 - https://lore.kernel.org/linux-mm/20230117231632.2734737-1-minchan@kernel.org/ * not relying on the pageout for accounting - mhocko * drop unnecessary changes - mhocko include/linux/vm_event_item.h | 2 ++ mm/madvise.c | 8 ++++++++ mm/vmstat.c | 2 ++ 3 files changed, 12 insertions(+) diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 7f5d1caf5890..3c117858946d 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -52,6 +52,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 7db6622f8293..d2624e77f729 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -344,6 +344,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, spinlock_t *ptl; struct folio *folio = NULL; LIST_HEAD(folio_list); + unsigned int nr_scanned = 0; + unsigned int nr_hinted = 0; bool pageout_anon_only_filter; if (fatal_signal_pending(current)) @@ -357,6 +359,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) @@ -414,6 +417,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, } } else folio_deactivate(folio); + nr_hinted += HPAGE_PMD_NR; huge_unlock: spin_unlock(ptl); if (pageout) @@ -431,6 +435,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; @@ -508,6 +513,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, } } else folio_deactivate(folio); + nr_hinted++; } arch_leave_lazy_mmu_mode(); @@ -515,6 +521,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, if (pageout) reclaim_pages(&folio_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 1ea6a5ce1c41..84acc90820e1 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1283,6 +1283,8 @@ const char * const vmstat_text[] = { "pgscan_file", "pgsteal_anon", "pgsteal_file", + "madvise_pgscanned", + "madvise_pghinted", #ifdef CONFIG_NUMA "zone_reclaim_failed",