From patchwork Fri Oct 11 12:49:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13832524 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 BA04CD0D785 for ; Fri, 11 Oct 2024 12:49:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4583D6B00A3; Fri, 11 Oct 2024 08:49:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4079D6B00A9; Fri, 11 Oct 2024 08:49:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25A866B00AA; Fri, 11 Oct 2024 08:49:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id F314C6B00A3 for ; Fri, 11 Oct 2024 08:49:40 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BF964AC9F5 for ; Fri, 11 Oct 2024 12:49:31 +0000 (UTC) X-FDA: 82661302878.12.7720683 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf02.hostedemail.com (Postfix) with ESMTP id D3DBC80019 for ; Fri, 11 Oct 2024 12:49:32 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=eF0kt74p; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf02.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728650949; a=rsa-sha256; cv=none; b=H8hQQwC2R2RbKDCEF7iG7QhXCkzrnzcGYjRPVpS7WvIoCcf+9LpwBrrjeH1/T16Vh92MVV Y34VkAyIPJ73Ys09CxEKURVGSGtnWx5l2HrgxgQx2wIP0lpALMKHbZFCX2HD2rjdfHjk23 0Q9HGbqUmWp3U6pJd5LN0lL3+0P4usA= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=eF0kt74p; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf02.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728650949; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=ZDDxYTyUSVZN/3oOMtfj8vkA3ZrBEhFDTR3n8K4qjAs=; b=VwpihJA+ImUNm/9/fUlhaiP+ZQkTBVjB3VBnYzCggQxESbgrLrnOLb7hlFOjJUZrxIlWU8 eF7GV5S6nLedZH2H2T1PDT+OjQG6LJL1UdnCGsnc52Ny516KCPb/NzT3Vc043EBoXl8TRQ 4179PIDOEi/7jaXsJsczxvqYmf1X0+U= Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20241011124933epoutp02d50940c87b5363e9cec460c6eac43b89~9Zubi32oP2808028080epoutp02W for ; Fri, 11 Oct 2024 12:49:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20241011124933epoutp02d50940c87b5363e9cec460c6eac43b89~9Zubi32oP2808028080epoutp02W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1728650973; bh=ZDDxYTyUSVZN/3oOMtfj8vkA3ZrBEhFDTR3n8K4qjAs=; h=From:To:Cc:Subject:Date:References:From; b=eF0kt74pOEhotJqyI7WqimZAWTPsepRP7TS6orji9OlXJMqCwbFJMlQeTC9ncv0j+ Tm6fkwhOBJwQdl1XAMbeqeRXLmJNyKZY9enlJJxYENYWmbiTXmSEZDfsCGPjho2HTp veWdYzydycf6gPX7NEl2WloSzjckCMdiNJDvCYHk= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20241011124933epcas1p35ebd9763fef301994d077b4ac48ed194~9Zua9QY5l1466914669epcas1p3o; Fri, 11 Oct 2024 12:49:33 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.38.249]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4XQ5zw5nSMz4x9Pv; Fri, 11 Oct 2024 12:49:32 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id 98.B5.09398.CDE19076; Fri, 11 Oct 2024 21:49:32 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20241011124931epcas1p176b2ce6a566f7557468dff1e12677a11~9ZuZxr9tB0397703977epcas1p13; Fri, 11 Oct 2024 12:49:31 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20241011124931epsmtrp1894f8a76a79fa4863e9a32084b58cdf6~9ZuZxAJID2084420844epsmtrp1Q; Fri, 11 Oct 2024 12:49:31 +0000 (GMT) X-AuditID: b6c32a39-39fff700000024b6-c7-67091edcb57b Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 8C.F5.08229.BDE19076; Fri, 11 Oct 2024 21:49:31 +0900 (KST) Received: from localhost.localdomain (unknown [10.253.104.99]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20241011124931epsmtip1f1fdaf407b83077f147fe941f7992a64~9ZuZmIyyL3079430794epsmtip1s; Fri, 11 Oct 2024 12:49:31 +0000 (GMT) From: Jaewon Kim To: sj@kernel.org, minchan@kernel.org, vbabka@suse.cz, kaleshsingh@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, Jaewon Kim Subject: [PATCH v2] vmscan: add a vmscan event for reclaim_pages Date: Fri, 11 Oct 2024 21:49:28 +0900 Message-Id: <20241011124928.1224813-1-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupik+LIzCtJLcpLzFFi42LZdlhTX/eOHGe6wZceHYs569ewWXRvnslo 0fv+FZNF076Z7BaXd81hs7i35j+rxbKv79ktDn99w2Qxu7GP0YHTY+esu+weCzaVemxa1cnm senTJHaPEzN+s3j0bVnF6HFmwRF2j8+b5AI4orJtMlITU1KLFFLzkvNTMvPSbZW8g+Od403N DAx1DS0tzJUU8hJzU22VXHwCdN0yc4DOU1IoS8wpBQoFJBYXK+nb2RTll5akKmTkF5fYKqUW pOQUmBXoFSfmFpfmpevlpZZYGRoYGJkCFSZkZ/w+MpW94J16xbWDqxgbGPcpdjFyckgImEhc u3mauYuRi0NIYAejxNInq5ggnE+MEr9fdLBDON8YJTa9ecsE09LS/QQqsZdRYuarDjYI5zNQ /4TbbCBVbALaEu8XTGIFsUUEsiRWH73EAmIzC5RKvH1zAmghB4ewgIPE78PeIGEWAVWJht6V YCW8AvYSW99BlEsIyEvMvPSdHSIuKHFy5hOoMfISzVtng90tIfCVXaL540N2iAYXiaffJzFD 2MISr45vgYpLSbzsb4Oy8yUuXHzFBHKDhECNxMKJhhBhe4ldX2ewgoSZBTQl1u/Sh1jFJ/Hu aw8rRDWvREebEES1mkTLs6+sELaMxN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Wpo7GLev+qB3iJGJg/EQowQHs5IIr+5C1nQh 3pTEyqrUovz4otKc1OJDjNIcLErivOIvelOEBNITS1KzU1MLUotgskwcnFINTIUPNBeKS6dO UDv64vi5MH8dOy9zL16DKOONVyq/Z98XdNz8lrk+PFOIbbNd0n8D9uVv7eYKfJn9UerB+hVV zG7xcrOsfwdFbpiwdo+zXPzJF8qKzM88ImecWel6zo1plgD/KqHp2v6bbx2XnWvDO3f/JIMQ 3+e7f/HcicruYmPw+9IiIGd4Xaf2wLflBraqzdK/nJe+iN3c9zGnwHCp2R0Rhvq7CxOXJoi/ vKKS6snzl/U7Y/2jtpJPvRuju9dEsK28pxjS2zg1wVen/liYyt4/M85srs77HzO56e38Q3+f nb9eru1TeHrZFbmm8p2MHQat938d+PZx6bWramk7vvmrnt1TGGOqHXYk9FLcTSWW4oxEQy3m ouJEANPn9OnYAgAA X-CMS-MailID: 20241011124931epcas1p176b2ce6a566f7557468dff1e12677a11 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20241011124931epcas1p176b2ce6a566f7557468dff1e12677a11 References: X-Rspam-User: X-Stat-Signature: p58yop7d3xkwhgdi7swynukbu3r4zq1k X-Rspamd-Queue-Id: D3DBC80019 X-Rspamd-Server: rspam02 X-HE-Tag: 1728650972-113051 X-HE-Meta: U2FsdGVkX18gWpuIiyFPfiR0SOmVJnYUXjOQ0JPoK/Cd0GSAYXxdTzJFsSNKx4cST2YwDdl9dJpe1K+yW8lMmhQmL6xRjQt1wdcIXbOH5Fq83tjyANoq53xJXaME0k54JgOakBgJg+jVJO/oiqYo3BQSuBAiydILF2V43si3S7CIJ8a1nOqIiksZu1pyvGk8P7XYWzy1VIfrxFFad79/vqidq80/JnssQaKacRjRPeV4w/jzCsFFXoAtRACNZyWiPjIn8dLAqTTr84/OLJK0q8QUZSLzmWVzgrRWvgf+PF9MWG/flTHGYvpLYIJZMatoTJrMtauUwBIbh/CsS8jNBbSkyHBQ5lfLc6krGt6Yh7OY05JCCA4NO6gThIfgKpzDsqUOPfZ3kMCFjnOOxN8DnHp126HOSD/twG2EnNEbXrRIxqLUsTIHZ+L7QIqYEySlLk+rKy5M7awVeFPcB9cpWcvQ6XwLsnSE+RGcf7Iq9iI0Ev9NMzmgtO/boBqA2GovYC90M8NbHer7c0lHnNE5D5dpOF/O10GQlqz9RM4uLUAUjspUe0QjDuhmDZm2hGkag2f/B/YcqXgJVaAefQmkDxsvjVDjqjIqjvfeyGmOndFbiVZx9ROvfy+d7Mv3w2xMmXIzxIVphj3kOzmTjvzWSuRRSop7F8rCrFdxdzlqULEeHlJ1OYG6ycDAAmjNK9zCbEsihOlmmZcjZy73iumeA2a8pMBGCv2M4IWOkbb3fDBcC9zAjRgtqgyTwb+s8CJKyH9SKRNCb186buFbXsMLveekLsRG6SSx6HOkVFsiytRP1asaEA2YrJc5Y2krCX/Tl4wz+V1Ig/pwtRUt4ylV/qF0PFpkXflaCQz5tNem0Xht03+DbC/eRmvmAd+zeHo5vcDKKQVMGFiSTFC556jAhB9WJDXv6OGVbHU65vGTh/Ep9EZTVAoV6jjKOAe9G3GJA32o+EkPdiHk7RVYQ+4 IEHE5zqV GyBzMpymTT4AZclXWdBRX4fvrn9wPj3hZlj4uVJi+qWh9eBNPIIyR7iXYt5b4uzcdm+LxRdlvw71jrC21bmeAaefHVkLVVLDvO1sFQF4NzGtnkgJA65XWgXa0yF0yt/4xlRGlEmfXYLXzlmlC0rngnaIHcb8euqPcIauqClmwJSzLO4vAAtUY/+rc+tv1QPMyBBnkofB9re1lMFz2ruasyBExqw== 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: List-Subscribe: List-Unsubscribe: The reclaim_folio_list uses a dummy reclaim_stat and is not being used. To know the memory stat, add a new trace event. This is useful how how many pages are not reclaimed or why. This is an example. mm_vmscan_reclaim_pages: nid=0 nr_scanned=112 nr_reclaimed=112 nr_dirty=0 nr_writeback=0 nr_congested=0 nr_immediate=0 nr_activate_anon=0 nr_activate_file=0 nr_ref_keep=0 nr_unmap_fail=0 Currenlty reclaim_folio_list is only called by reclaim_pages, and reclaim_pages is used by damon and madvise. In the latest Android, reclaim_pages is also used by shmem to reclaim all pages in a address_space. Signed-off-by: Jaewon Kim --- v2: remove reclaim_stat_add function and call the trace on each node v1: introduce a new trace event --- include/trace/events/vmscan.h | 45 +++++++++++++++++++++++++++++++++++ mm/vmscan.c | 16 +++++++++---- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h index 1a488c30afa5..490958fa10de 100644 --- a/include/trace/events/vmscan.h +++ b/include/trace/events/vmscan.h @@ -346,6 +346,51 @@ TRACE_EVENT(mm_vmscan_write_folio, show_reclaim_flags(__entry->reclaim_flags)) ); +TRACE_EVENT(mm_vmscan_reclaim_pages, + + TP_PROTO(int nid, + unsigned long nr_scanned, unsigned long nr_reclaimed, + struct reclaim_stat *stat), + + TP_ARGS(nid, nr_scanned, nr_reclaimed, stat), + + TP_STRUCT__entry( + __field(int, nid) + __field(unsigned long, nr_scanned) + __field(unsigned long, nr_reclaimed) + __field(unsigned long, nr_dirty) + __field(unsigned long, nr_writeback) + __field(unsigned long, nr_congested) + __field(unsigned long, nr_immediate) + __field(unsigned int, nr_activate0) + __field(unsigned int, nr_activate1) + __field(unsigned long, nr_ref_keep) + __field(unsigned long, nr_unmap_fail) + ), + + TP_fast_assign( + __entry->nid = nid; + __entry->nr_scanned = nr_scanned; + __entry->nr_reclaimed = nr_reclaimed; + __entry->nr_dirty = stat->nr_dirty; + __entry->nr_writeback = stat->nr_writeback; + __entry->nr_congested = stat->nr_congested; + __entry->nr_immediate = stat->nr_immediate; + __entry->nr_activate0 = stat->nr_activate[0]; + __entry->nr_activate1 = stat->nr_activate[1]; + __entry->nr_ref_keep = stat->nr_ref_keep; + __entry->nr_unmap_fail = stat->nr_unmap_fail; + ), + + TP_printk("nid=%d nr_scanned=%ld nr_reclaimed=%ld nr_dirty=%ld nr_writeback=%ld nr_congested=%ld nr_immediate=%ld nr_activate_anon=%d nr_activate_file=%d nr_ref_keep=%ld nr_unmap_fail=%ld", + __entry->nid, + __entry->nr_scanned, __entry->nr_reclaimed, + __entry->nr_dirty, __entry->nr_writeback, + __entry->nr_congested, __entry->nr_immediate, + __entry->nr_activate0, __entry->nr_activate1, + __entry->nr_ref_keep, __entry->nr_unmap_fail) +); + TRACE_EVENT(mm_vmscan_lru_shrink_inactive, TP_PROTO(int nid, diff --git a/mm/vmscan.c b/mm/vmscan.c index 749cdc110c74..0c2c36bf4c5a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2126,9 +2126,10 @@ static void shrink_active_list(unsigned long nr_to_scan, } static unsigned int reclaim_folio_list(struct list_head *folio_list, + unsigned int nr_scanned, struct pglist_data *pgdat) { - struct reclaim_stat dummy_stat; + struct reclaim_stat stat; unsigned int nr_reclaimed; struct folio *folio; struct scan_control sc = { @@ -2139,12 +2140,13 @@ 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, true); + nr_reclaimed = shrink_folio_list(folio_list, pgdat, &sc, &stat, true); while (!list_empty(folio_list)) { folio = lru_to_folio(folio_list); list_del(&folio->lru); folio_putback_lru(folio); } + trace_mm_vmscan_reclaim_pages(pgdat->node_id, nr_scanned, nr_reclaimed, &stat); return nr_reclaimed; } @@ -2152,6 +2154,7 @@ static unsigned int reclaim_folio_list(struct list_head *folio_list, unsigned long reclaim_pages(struct list_head *folio_list) { int nid; + unsigned int nr_scanned = 0; unsigned int nr_reclaimed = 0; LIST_HEAD(node_folio_list); unsigned int noreclaim_flag; @@ -2168,15 +2171,18 @@ unsigned long reclaim_pages(struct list_head *folio_list) if (nid == folio_nid(folio)) { folio_clear_active(folio); list_move(&folio->lru, &node_folio_list); + nr_scanned += folio_nr_pages(folio); continue; } - nr_reclaimed += reclaim_folio_list(&node_folio_list, NODE_DATA(nid)); + nr_reclaimed += reclaim_folio_list(&node_folio_list, nr_scanned, + NODE_DATA(nid)); + nr_scanned = 0; 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_reclaimed += reclaim_folio_list(&node_folio_list, nr_scanned, + NODE_DATA(nid)); memalloc_noreclaim_restore(noreclaim_flag); return nr_reclaimed;