From patchwork Mon Dec 12 00:37:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13070694 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 A179BC4167B for ; Mon, 12 Dec 2022 00:37:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42E378E0005; Sun, 11 Dec 2022 19:37:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DE668E0002; Sun, 11 Dec 2022 19:37:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 280008E0005; Sun, 11 Dec 2022 19:37:46 -0500 (EST) 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 18AFA8E0002 for ; Sun, 11 Dec 2022 19:37:46 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D8726A9175 for ; Mon, 12 Dec 2022 00:37:45 +0000 (UTC) X-FDA: 80231791290.19.511E918 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf24.hostedemail.com (Postfix) with ESMTP id 3A13118000D for ; Mon, 12 Dec 2022 00:37:42 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=bWMeQ5bn; spf=pass (imf24.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.48 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=1670805462; a=rsa-sha256; cv=none; b=VBn86p2LHFdw++HZw+ncKinUA03N8KP/a9d8A+JQyj+5T/mRRKShelF1cJjYfNEeWeyMSb uN4QX/aXRVkQGIQAGlN7bBQkErKrC740pVBsxTRprR6v46s5TXvAr7p2ezXF8qC2dM0dIR 7vn3ldpeHewDpfUXgrBMh78Y8v8ga88= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=bWMeQ5bn; spf=pass (imf24.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.48 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=1670805462; 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=EWked+wJERqcTSi79JV5oNIuOa0tfY0vnwLs5gY8MS8=; b=pjqcb7D6ST1k21gaBEu2JLipEurtMMFMgniHAzPRGYdzKQJBKpki0Me4GXGQl5DpgOCcGQ JM2zqvs5LlVG5mtgruZ9asj74cohWRWlAWcLfRmwjkXtj6dcyLQKGEMUycjFasHKOdlf71 /RRlz/lKHfoNBXqa9nPMA1Y4f8v9Qao= Received: by mail-pj1-f48.google.com with SMTP id q17-20020a17090aa01100b002194cba32e9so13887507pjp.1 for ; Sun, 11 Dec 2022 16:37: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:from:to:cc:subject:date :message-id:reply-to; bh=EWked+wJERqcTSi79JV5oNIuOa0tfY0vnwLs5gY8MS8=; b=bWMeQ5bnX0TAF6bOdYkP/oOKV5jf+3Uc15vF0wU9CfGJjw8kfYoU9EPZGM+bc1iKJx ky0g+H15r5zMpolW5OyrMmBrnfZpvmLsGwkUUacNNe8GZ4BzalwNbsYnV8siK0KSl7lv 9/STfhGYSN5Bjms4C9NOCDfn0fZIaDlTYFfh4UM012DUHv+Y/RfbqnWW06UsZxe8BGa4 +qnpdhR49of03EqQmxuVAUhq0r8nqWyKiAn1qvq5SLlOTbQKqnSOoCbL3MnLuPcYWUUF p3LOJ5YBnQDwUEvNREGZPpa+SVWD17iJwLObXxC6Z/3sjrjshYcCezzIqtZ1d8aoDxMB UFyg== 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=EWked+wJERqcTSi79JV5oNIuOa0tfY0vnwLs5gY8MS8=; b=Z2SMrO/KhM4ITNa9Sjy7I4OVoNHPGjfYusbsQmdpj6cRBJnaVNrQzHOSWWimbdC4QJ E3NdPozIrF3W2ThTQwWtQwL0SYhMvj7CaJZ59vGtZWz/DdmJlFlu8X7VZfL3MyDB7Lop uo8PO/rwEs/pcsHfySlD0+ux8/2BbiKYV9pzuflTH9jvCCJ8+Zst5y3M3Ou28aiihs2U KbWgJqP6Ky/bLxr/z+Kfjqxh/eixp3M7G82hQiKHHg8n0H8f1mJYqtSxdmvyJbmwJuzz IFVr6E34OZnFfZF8uzOYcK8eLGV2QDmqu2c2wNcqhF9Oe5l1Y4J9ztIC43bExnzNYq5t kzOw== X-Gm-Message-State: ANoB5pliisRykl3THN3byx1eY+stuh0Oc7Vh8L0TeI1xrZ1cSWDErGyo L8ep/tE0vM7qDEsXj2qiGcw= X-Google-Smtp-Source: AA0mqf7ELqiSpWsfHtvtdVOpa+IdGBSzwZN2i+Zxsp57q2bOLFd/Qst7Jv0nZP60GjGAejI5hY2y/g== X-Received: by 2002:a17:902:728d:b0:189:6293:e01a with SMTP id d13-20020a170902728d00b001896293e01amr13335786pll.12.1670805461055; Sun, 11 Dec 2022 16:37:41 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Dec 2022 16:37:40 -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 1/9] mm: Introduce active vm item Date: Mon, 12 Dec 2022 00:37:03 +0000 Message-Id: <20221212003711.24977-2-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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3A13118000D X-Stat-Signature: ypwu3dzwhmc99m3en8yxmahgprmaqgpr X-HE-Tag: 1670805462-21523 X-HE-Meta: U2FsdGVkX1/HGkApgF9O4iSViRnMv5lj2UvQdpa5FapJGRJbbaywFTX60zNbAT6SfYt2nmptYtXgmrKcs/CuO2cGFXdGZ/b8NlJVFQ852yonHYaPhS+xxJkTdfSS8TdHIwP97XVdmymlFd/xLIUy8zOi1b/YyMY4tXbjeG/tLglEhTO+26FXO3Ylrne8Xc9cw8zigeTjETjicDn7bVhmuPguYhM01v4sUrNhBsnquHk2+rNAivLW44IR8w877GHNwC0Dk6sjk+8PzjVQjbqVQRJAMfv5Hy5BsMn1M1nosEjQTDdFBXTw5QUxHIcnbJRSNFo8vQyCJWiss3T2cmWOmyo77zXbYkevR2jCn7iFcN7Q8y1lwmP72XeXmktwjv64p8nYjr8ra7IlQphY2aLw4gdk3etetzQfcC5hRmu4WiR7V0M4W7vrYY6nHt2vNst98Zf321lMP7qacFajcPDndC5Sy+3ueyVglDuOSZetZMvpIppWHTbch2FyT5aPeCdUBoZUYOh7HHr4Hz9xQRyorD4IOgr3ZPNmwWoR7jDwDFA2Y1MQ0FXSOAWEwG6SfmgEb6F8fIlJ9R6dVZPf4arje2fTsxP2eX6j0DrYEVVt/6q9mhlWTm20nkU4Wjn17aoOGo3fwMWkgdz9SSiCZbXNKHQKTd7wxAQOrEFFwbHE4sbgm8Uiu/qMwZdoGCjXf7lPTWCpuSbKhEg17S2VZugduPx4cNFYf3fm5wk8sSh7tP60+jJ2rIDKQjJvfeb9tv5E1jZXA5Ffe4uhoT+qNybvPJCZXIF2u43lXAbMiwkfh0nY5hU3OR+XpRn+GW65wgbGKYWIj7c3g5rYG62sR6P/ktiYWxGxoPRZ0ZT66rnLufhdzrg1Rs4qbPG2GpP+GlXQILmTNfncUEeDckrzq9ZTKOAISzH4IShfv64j5WZFPEI4LjqDPXT6o90T/puBJrtW7p3PubMiz7fXk6B+B66 SFyt+mTv LOfUquwiQEXxkrh9Voycq2hRFpepDwHKWH/TIALHc4AFHxniXxTm8XWSA5fub1zwMyQvKpJawiu6dYi8Z3YSvdl+qd5y+wn3X5vOAi6dALD4BuwNMGxFyC+XnPPr7L9nrme+JABnYzVA71ZB8bwr1lNot6LcU8rVxyx1DUbkY2BDgCVKAtUMH+9ny4cBmW7iLySFVBvtvYVJ3S5bQPlhOolq36Mp0ptqxcgna+QNnPsh6ql4= 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: A new page extension active_vm is introduced in this patch. It can be enabled and disabled by setting CONFIG_ACTIVE_VM at compile time or a boot parameter 'active_vm' at run time. In the followup patches, we will use it to account specific memory allocation for page, slab and percpu memory. Signed-off-by: Yafang Shao --- include/linux/active_vm.h | 23 +++++++++++++++++++++++ mm/Kconfig | 8 ++++++++ mm/Makefile | 1 + mm/active_vm.c | 33 +++++++++++++++++++++++++++++++++ mm/active_vm.h | 8 ++++++++ mm/page_ext.c | 4 ++++ 6 files changed, 77 insertions(+) create mode 100644 include/linux/active_vm.h create mode 100644 mm/active_vm.c create mode 100644 mm/active_vm.h diff --git a/include/linux/active_vm.h b/include/linux/active_vm.h new file mode 100644 index 000000000000..899e578e94fa --- /dev/null +++ b/include/linux/active_vm.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __INCLUDE_ACTIVE_VM_H +#define __INCLUDE_ACTIVE_VM_H + +#ifdef CONFIG_ACTIVE_VM +#include + +extern struct static_key_true active_vm_disabled; + +static inline bool active_vm_enabled(void) +{ + if (static_branch_likely(&active_vm_disabled)) + return false; + + return true; +} +#else +static inline bool active_vm_enabled(void) +{ + return false; +} +#endif /* CONFIG_ACTIVE_VM */ +#endif /* __INCLUDE_ACTIVE_VM_H */ diff --git a/mm/Kconfig b/mm/Kconfig index 57e1d8c5b505..ba1087e4afff 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1150,6 +1150,14 @@ config LRU_GEN_STATS This option has a per-memcg and per-node memory overhead. # } +config ACTIVE_VM + bool "To track memory size of active VM item" + default y + depends on PAGE_EXTENSION + help + Allow scope-based memory accouting for specific memory, e.g. the + system-wide BPF memory usage. + source "mm/damon/Kconfig" endmenu diff --git a/mm/Makefile b/mm/Makefile index 8e105e5b3e29..347dcff061d5 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -138,3 +138,4 @@ obj-$(CONFIG_IO_MAPPING) += io-mapping.o obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o +obj-$(CONFIG_ACTIVE_VM) += active_vm.o diff --git a/mm/active_vm.c b/mm/active_vm.c new file mode 100644 index 000000000000..60849930a7d3 --- /dev/null +++ b/mm/active_vm.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +static bool __active_vm_enabled __initdata = + IS_ENABLED(CONFIG_ACTIVE_VM); + +DEFINE_STATIC_KEY_TRUE(active_vm_disabled); +EXPORT_SYMBOL(active_vm_disabled); + +static int __init early_active_vm_param(char *buf) +{ + return strtobool(buf, &__active_vm_enabled); +} + +early_param("active_vm", early_active_vm_param); + +static bool __init need_active_vm(void) +{ + return __active_vm_enabled; +} + +static void __init init_active_vm(void) +{ + if (!__active_vm_enabled) + return; + + static_branch_disable(&active_vm_disabled); +} + +struct page_ext_operations active_vm_ops = { + .need = need_active_vm, + .init = init_active_vm, +}; diff --git a/mm/active_vm.h b/mm/active_vm.h new file mode 100644 index 000000000000..72978955833e --- /dev/null +++ b/mm/active_vm.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __MM_ACTIVE_VM_H +#define __MM_ACTIVE_VM_H + +#ifdef CONFIG_ACTIVE_VM +extern struct page_ext_operations active_vm_ops; +#endif /* CONFIG_ACTIVE_VM */ +#endif /* __MM_ACTIVE_VM_H */ diff --git a/mm/page_ext.c b/mm/page_ext.c index ddf1968560f0..3a3a91bc9e06 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -10,6 +10,7 @@ #include #include #include +#include "active_vm.h" /* * struct page extension @@ -84,6 +85,9 @@ static struct page_ext_operations *page_ext_ops[] __initdata = { #ifdef CONFIG_PAGE_TABLE_CHECK &page_table_check_ops, #endif +#ifdef CONFIG_ACTIVE_VM + &active_vm_ops, +#endif }; unsigned long page_ext_size = sizeof(struct page_ext);