From: Yafang Shao <laoar.shao@gmail.com>
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 <laoar.shao@gmail.com>
Subject: [RFC PATCH bpf-next 1/9] mm: Introduce active vm item
Date: Mon, 12 Dec 2022 00:37:03 +0000 [thread overview]
Message-ID: <20221212003711.24977-2-laoar.shao@gmail.com> (raw)
In-Reply-To: <20221212003711.24977-1-laoar.shao@gmail.com>
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 <laoar.shao@gmail.com>
---
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 <linux/jump_label.h>
+
+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 <linux/page_ext.h>
+
+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 <linux/page_idle.h>
#include <linux/page_table_check.h>
#include <linux/rcupdate.h>
+#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);
--
2.30.1 (Apple Git-130)
next prev parent reply other threads:[~2022-12-12 0:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-12 0:37 [RFC PATCH bpf-next 0/9] mm, bpf: Add BPF into /proc/meminfo Yafang Shao
2022-12-12 0:37 ` Yafang Shao [this message]
2022-12-12 0:37 ` [RFC PATCH bpf-next 2/9] mm: Allow using active vm in all contexts Yafang Shao
2022-12-12 0:37 ` [RFC PATCH bpf-next 3/9] mm: percpu: Account active vm for percpu Yafang Shao
2022-12-12 0:37 ` [RFC PATCH bpf-next 4/9] mm: slab: Account active vm for slab Yafang Shao
2022-12-12 0:37 ` [RFC PATCH bpf-next 5/9] mm: Account active vm for page Yafang Shao
2022-12-12 0:37 ` [RFC PATCH bpf-next 6/9] bpf: Introduce new helpers bpf_ringbuf_pages_{alloc,free} Yafang Shao
2022-12-12 0:37 ` [RFC PATCH bpf-next 7/9] bpf: Use bpf_map_kzalloc in arraymap Yafang Shao
2022-12-12 0:37 ` [RFC PATCH bpf-next 8/9] bpf: Use bpf_map_kvcalloc in bpf_local_storage Yafang Shao
2022-12-12 0:37 ` [RFC PATCH bpf-next 9/9] bpf: Use active vm to account bpf map memory usage Yafang Shao
2022-12-14 8:45 ` kernel test robot
2022-12-14 12:01 ` Yafang Shao
2022-12-12 17:54 ` [RFC PATCH bpf-next 0/9] mm, bpf: Add BPF into /proc/meminfo Vlastimil Babka
2022-12-13 11:52 ` Yafang Shao
2022-12-13 14:56 ` Hyeonggon Yoo
2022-12-13 15:52 ` Vlastimil Babka
2022-12-13 19:21 ` Paul E. McKenney
2022-12-14 10:46 ` Yafang Shao
2022-12-14 10:43 ` Yafang Shao
2022-12-14 10:34 ` Yafang Shao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221212003711.24977-2-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cl@linux.com \
--cc=daniel@iogearbox.net \
--cc=dennis@kernel.org \
--cc=haoluo@google.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=tj@kernel.org \
--cc=vbabka@suse.cz \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).