new file mode 100644
@@ -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 */
@@ -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
@@ -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
new file mode 100644
@@ -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,
+};
new file mode 100644
@@ -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 */
@@ -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);
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