From patchwork Mon Dec 12 00:37:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13070698 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 BA50CC4332F for ; Mon, 12 Dec 2022 00:38:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56777900002; Sun, 11 Dec 2022 19:38:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 517718E0002; Sun, 11 Dec 2022 19:38:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B81A900002; Sun, 11 Dec 2022 19:38:04 -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 29B598E0002 for ; Sun, 11 Dec 2022 19:38:04 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F2CE080823 for ; Mon, 12 Dec 2022 00:38:03 +0000 (UTC) X-FDA: 80231792046.22.F59C95C Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf17.hostedemail.com (Postfix) with ESMTP id 58E2040007 for ; Mon, 12 Dec 2022 00:38:02 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=P7L3A8LS; spf=pass (imf17.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670805482; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lNKI7Uo9ceKwdJtylngktQ/nCvprH/we2VJP8jXRS4g=; b=OGud9XKKwBFYQlgZOE6poLXAYZ/kad38ZxYHL/B842D7orIh+gveFyEx0KzVGg9km1uA49 wxVDIwYYSr8ExhF91L5qmgEYaJ6HlyStbRKS3ak1xkio0yRBl6mrw7HL9j+yng+EKwTVcJ 0VxUXLGCkXfAZmx6Cz5UrognNeJpP2k= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=P7L3A8LS; spf=pass (imf17.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670805482; a=rsa-sha256; cv=none; b=C2NMdTFVxpyI10268NqKKqsd6lg8suQ9llLS8O+4BPtRjcX3ta6TpkiExRDOIrhpIbiD7N DnInXtHl0ez4PGJa6G0G9+pWqPHQEjtkOjCSXK8I6Q9sKqXzwiF2is04KKR8JHQg6XTVsQ e5CV2emhfhCCOdMTjuRT9Id0QS74I3c= Received: by mail-pl1-f174.google.com with SMTP id 4so4460397plj.3 for ; Sun, 11 Dec 2022 16:38:02 -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:from:to:cc:subject:date :message-id:reply-to; bh=lNKI7Uo9ceKwdJtylngktQ/nCvprH/we2VJP8jXRS4g=; b=P7L3A8LSQ6EuBchoo9o72G0HR9beI6ptksZv7pGabGWc21e5bYToqayU6KK7gpv+KW LNO60GB0maoylCFzxuy7ZqsXKuIBcgvGt+apx8Tmq/mfpL7XtcE8QC5AuyQB0bUSs4CV t+qTZt3ykBrEDsJ1dX7EGsQMucv4KFNDm9W2KRsa9nhIYqiyhZdcTkwfdZP9jue72YQF xGaOwfN8haEgmbtswwr6QpNh82Qg3XEOAMM94W24qrBtb/wUM72Uhhj+8XRzzxb1Zvkn tyjFOn5ZuO/uYxaYuu58vwbl3foO3tgwR9ZUZGqgmrQiON9ADCHjs8LsgoZ4WmuB+Zj+ YhpA== 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:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lNKI7Uo9ceKwdJtylngktQ/nCvprH/we2VJP8jXRS4g=; b=lU/p8VpYcaGQn0lvz5eHnK2S7rmWSSpoeSSgyEAyIXDOm7SuEZ3yoEhsmOX/D8jQ4C sj4Y9K0TW0iNGEa07ri6/3Z9YqkwoZ1mrOmRAfDnFCT3jj1gQjs9vXH3wnD0dTI0VE3Y QFCaiR4AQlF3Kyup8V1wExBzOAE00MydTyiJqqFCmfnmZwK4D1dHCyJJh95WcMWob11D kef3zOArxMaJ30cX3LeP0GvrO32glbduDaxIC5+aFdl6ZAb3MN6S33jWSES72AXC+R/j IU36/SWOJR5vITvD088BEuTrVGaYI+hGkhc0y4XA5O4WhPkXOh2KE05hXtQCDn6CuP+a qdmg== X-Gm-Message-State: ANoB5plyg/8/nlGhtsB7j/XsgkZQ5jYlwC7f8iDmtViz+j1yM5se3SG+ fPkrtWQPyuVb3oifjHmNTbs= X-Google-Smtp-Source: AA0mqf6gVkVR/BLhx3chzrF6SJRugCJ3u+HzeGV/gLvVMYMtlhxlpXYv9UYQhE7PhTOyWjPolnJ7Mw== X-Received: by 2002:a17:902:7c8c:b0:185:4421:72ed with SMTP id y12-20020a1709027c8c00b00185442172edmr14327503pll.50.1670805481847; Sun, 11 Dec 2022 16:38:01 -0800 (PST) Received: from vultr.guest ([2001:19f0:7002:8c7:5400:4ff:fe3d:656a]) by smtp.gmail.com with ESMTPSA id w9-20020a170902e88900b00177fb862a87sm4895960plg.20.2022.12.11.16.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Dec 2022 16:38:01 -0800 (PST) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tj@kernel.org, dennis@kernel.org, cl@linux.com, akpm@linux-foundation.org, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com Cc: linux-mm@kvack.org, bpf@vger.kernel.org, Yafang Shao Subject: [RFC PATCH bpf-next 5/9] mm: Account active vm for page Date: Mon, 12 Dec 2022 00:37:07 +0000 Message-Id: <20221212003711.24977-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221212003711.24977-1-laoar.shao@gmail.com> References: <20221212003711.24977-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 58E2040007 X-Stat-Signature: ij7knf5uqg91hhhgcecfpnopycgfjxri X-Rspam-User: X-HE-Tag: 1670805482-401613 X-HE-Meta: U2FsdGVkX18boijMDf+WenRpgF1bUG1s5epg27Hf8xWMFjF/OSAlUtCqvAD9Ud3uLV0mzHecVQLBeeGqo6MyYkJM3Ev/kcNnMOpt9bGzTd+QrPOFMFqPUBRv027FMzt++OYQyq9RRMCwnxBbsngmlrOLsZxzFVQb+iE+YNWMMpuU9Fiyw+JyiTNSMLVKaVYFGFN7423B7lSBWMBC4BMffbu1eWd5OizJVYWvGkWItw90h4dPJW1KHGRteWRJPABTk+Qg+9vWTL2TlYxW0aonViIFWV18ppHshwkZv/ZsToU+5TkRPE4Ikd8KTWyhrT+jtn094yC4EcomLngUg9izEH5DpeycC+4b3elWhrC15cHYyJ4zRtf3RcqBPzS2c8V7NTULusYDg+SACCDmIfDBDsjF3VSlp8cdUIJXisQSrbOTuj68nyB/wu/o1cAer3OPchnjgFuGjkoget5ijXp7ELI0x3pS1Mgmc5txGSnnvLKS5m0E+v/q+qtlBUQavhfJO7NsfWabXYHCaba6T4+7pjOUNdH50A73Xao2QPsDeJA/E9Az7felNs8OyE0Gr6VQ0RbCfaWPlbmk0GIt9iwRww2O7ZMAyle1y3JkyV3vLw2kQwmIAot+8oioQZ/qXjYslf2PlZiXV4kyZKfKLxq7wiLGeWDyjElViMX1h4G6BZiNWcNVSA4zG3CgoP99uLCHooqlsBbPi0A+hu5iWimcVbqWc0r90zkT0lZin5+snMu6wdLZ4fj8bB/6OwUDOZ5jTeIx6WzNIaXB6V4d5HK0/lNvDRHsfhCxW0uNQUsLgxq2e8Xc1jMPgJXv9ymatH4vGaSMtgKQqL+S16gumzIthoe9pg3+CNOWcwGs4tp/F55uP+mOLtTLSuMhagl65jmkVWv319Z6avkKp7WhqK+EMR1H9WHCw/Wb2lbfvRUzj0h+B7byBnU+TD22CRwFrzPI6azi1SovMyrhRBFTAlW WdUA+O8S o6w1+nsaXP01Mzj+SuPr/tlff4PP3LxycCl/1jBKhvipT9H1aC8WxMPigaN6IaUxmy/0XMRKguxR4TgPqX2xjJrg4WzuwXz2nFkmGvgjjaW1cSJ/D5Sptvx5eG8c1dwaEWFtCCh2KCuzzAROCW4Is8UmGX1yWFki2IkHDxpJNnVPYrIeR4BueGI1Tidkhzcj6X2ZzbwycY3rQV7S8L8+BcZIiFaRh/Y7XG074xiCxIFPfop0= 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: Account active vm for page allocation and unaccount then page is freed. We can reuse the slab_data in struct active_vm to store the information of page allocation. Signed-off-by: Yafang Shao --- include/linux/page_ext.h | 1 + mm/active_vm.c | 38 +++++++++++++++++++++++++++++++++++++- mm/active_vm.h | 12 ++++++++++++ mm/page_alloc.c | 14 ++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index 22be4582faae..5d02f939d5df 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -5,6 +5,7 @@ #include #include #include +#include struct pglist_data; struct page_ext_operations { diff --git a/mm/active_vm.c b/mm/active_vm.c index ee38047a4adc..a06987639e00 100644 --- a/mm/active_vm.c +++ b/mm/active_vm.c @@ -34,7 +34,10 @@ static void __init init_active_vm(void) } struct active_vm { - int *slab_data; /* for slab */ + union { + int *slab_data; /* for slab */ + unsigned long page_data; /* for page */ + } }; struct page_ext_operations active_vm_ops = { @@ -165,3 +168,36 @@ void active_vm_slab_sub(struct kmem_cache *s, struct slab *slab, void **p, int c } page_ext_put(page_ext); } + +void page_set_active_vm(struct page *page, unsigned int item, unsigned int order) +{ + struct page_ext *page_ext = page_ext_get(page); + struct active_vm *av; + + if (unlikely(!page_ext)) + return; + + av = (void *)(page_ext) + active_vm_ops.offset; + WARN_ON_ONCE(av->page_data != 0); + av->page_data = item; + page_ext_put(page_ext); + active_vm_item_add(item, PAGE_SIZE << order); +} + +void page_test_clear_active_vm(struct page *page, unsigned int order) +{ + struct page_ext *page_ext = page_ext_get(page); + struct active_vm *av; + + if (unlikely(!page_ext)) + return; + + av = (void *)(page_ext) + active_vm_ops.offset; + if (av->page_data <= 0) + goto out; + + active_vm_item_sub(av->page_data, PAGE_SIZE << order); + av->page_data = 0; +out: + page_ext_put(page_ext); +} diff --git a/mm/active_vm.h b/mm/active_vm.h index cf80b35412c5..1ff27b0b5dbe 100644 --- a/mm/active_vm.h +++ b/mm/active_vm.h @@ -10,6 +10,8 @@ extern struct page_ext_operations active_vm_ops; void active_vm_slab_add(struct kmem_cache *s, gfp_t flags, size_t size, void **p); void active_vm_slab_sub(struct kmem_cache *s, struct slab *slab, void **p, int cnt); void active_vm_slab_free(struct slab *slab); +void page_set_active_vm(struct page *page, unsigned int item, unsigned int order); +void page_test_clear_active_vm(struct page *page, unsigned int order); static inline int active_vm_item(void) { @@ -33,6 +35,7 @@ static inline void active_vm_item_sub(int item, long delta) WARN_ON_ONCE(item <= 0); this_cpu_sub(active_vm_stats.stat[item - 1], delta); } + #else /* CONFIG_ACTIVE_VM */ static inline int active_vm_item(void) { @@ -58,5 +61,14 @@ static inline void active_vm_slab_sub(struct kmem_cache *s, struct slab *slab, v static inline void active_vm_slab_free(struct slab *slab) { } + +static inline void page_set_active_vm(struct page *page, int item, + unsigned int order) +{ +} + +static inline void page_test_clear_active_vm(struct page *page, unsigned int order) +{ +} #endif /* CONFIG_ACTIVE_VM */ #endif /* __MM_ACTIVE_VM_H */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6e60657875d3..deac544e9050 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -76,6 +76,8 @@ #include #include #include +#include +#include #include #include #include @@ -83,6 +85,7 @@ #include "shuffle.h" #include "page_reporting.h" #include "swap.h" +#include "active_vm.h" /* Free Page Internal flags: for internal, non-pcp variants of free_pages(). */ typedef int __bitwise fpi_t; @@ -1449,6 +1452,10 @@ static __always_inline bool free_pages_prepare(struct page *page, page->mapping = NULL; if (memcg_kmem_enabled() && PageMemcgKmem(page)) __memcg_kmem_uncharge_page(page, order); + + if (active_vm_enabled()) + page_test_clear_active_vm(page, order); + if (check_free && free_page_is_bad(page)) bad++; if (bad) @@ -5577,6 +5584,13 @@ struct page *__alloc_pages(gfp_t gfp, unsigned int order, int preferred_nid, page = NULL; } + if (active_vm_enabled() && (gfp & __GFP_ACCOUNT) && page) { + int active_vm = active_vm_item(); + + if (active_vm > 0) + page_set_active_vm(page, active_vm, order); + } + trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype); kmsan_alloc_page(page, order, alloc_gfp);