[Devel] [PATCH rh7] x86: arch_free_page() introduced

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Thu Nov 12 10:01:14 PST 2015


This patch defines arch_free_page() callback to x86 architecture. The only
thing it does is pages contents zeroing.
It's disabled by default. To enable it one should add "zero-free-pages"
kernel option to kernel boot parameters.
Note, that kernel boot option handling and enabling of pages zeroing are
divided. The reason for this is that static keys initialization can't be
performed during kernel parameters parsing (can't specify, what is the exact
reason, but kernel just doesn't boot, if static key is incremented on
parameter callback). Because of this split, actual zeroing is enabled later
during kernel boot, but still early enough.
Another thing to notice, is that code is moved to a separate source and header
files. The reason for source file is all other are not really suitable. The
reason for header is that asm/page.h cna't be used for this (compile
dependences).

https://jira.sw.ru/browse/PSBM-33071

Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 arch/x86/include/asm/free_page.h   |   23 +++++++++++++++++++++++
 arch/x86/include/asm/thread_info.h |    1 +
 arch/x86/mm/Makefile               |    2 +-
 arch/x86/mm/free_page.c            |   28 ++++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/include/asm/free_page.h
 create mode 100644 arch/x86/mm/free_page.c

diff --git a/arch/x86/include/asm/free_page.h b/arch/x86/include/asm/free_page.h
new file mode 100644
index 0000000..f1be780
--- /dev/null
+++ b/arch/x86/include/asm/free_page.h
@@ -0,0 +1,23 @@
+#ifndef _ASM_X86_FREE_PAGE_H
+#define _ASM_X86_FREE_PAGE_H
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+
+#include <linux/jump_label.h>
+
+#define HAVE_ARCH_FREE_PAGE
+
+extern struct static_key zero_free_pages;
+extern void do_zero_pages(struct page *page, int order);
+
+static __always_inline void arch_free_page(struct page *page, int order)
+{
+	if (static_key_false(&zero_free_pages))
+		do_zero_pages(page, order);
+}
+
+#endif	// __ASSEMBLY__
+#endif	// __KERNEL__
+#endif	// _ASM_X86_FREE_PAGE_H
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index f9513ef..4275318 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -9,6 +9,7 @@
 
 #include <linux/compiler.h>
 #include <asm/page.h>
+#include <asm/free_page.h>
 #include <asm/types.h>
 
 /*
diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
index ac9ca65..5527581 100644
--- a/arch/x86/mm/Makefile
+++ b/arch/x86/mm/Makefile
@@ -1,5 +1,5 @@
 obj-y	:=  init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \
-	    pat.o pgtable.o physaddr.o gup.o setup_nx.o
+	    pat.o pgtable.o physaddr.o gup.o setup_nx.o free_page.o
 
 # Make sure __phys_addr has no stackprotector
 nostackp := $(call cc-option, -fno-stack-protector)
diff --git a/arch/x86/mm/free_page.c b/arch/x86/mm/free_page.c
new file mode 100644
index 0000000..d5d7e53
--- /dev/null
+++ b/arch/x86/mm/free_page.c
@@ -0,0 +1,28 @@
+#include <linux/highmem.h>
+#include <asm/free_page.h>
+
+static int zero_data_pages_enabled;
+struct static_key __initdata zero_free_pages = STATIC_KEY_INIT_FALSE;
+
+void do_zero_pages(struct page *page, int order)
+{
+	int i;
+
+	for (i = 0; i < (1 << order); i++)
+		clear_highpage(page + i);
+}
+
+static int __init enable_zero_free_pages(char *__unused)
+{
+	zero_data_pages_enabled = 1;
+	return 1;
+}
+__setup("zero-free-pages", enable_zero_free_pages);
+
+static int __init setup_zero_free_pages(void)
+{
+	if (zero_data_pages_enabled)
+		static_key_slow_inc(&zero_free_pages);
+	return 0;
+}
+early_initcall(setup_zero_free_pages);



More information about the Devel mailing list