[Devel] [PATCH rh7 v2] x86: "pages zeroing on free" option introduced

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Wed Nov 18 08:31:03 PST 2015


This patch add pages zeroing option to free_pages_prepare().
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 file.
The reason for this is to simplify rebases in future.

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

v2: All the code was moved to mm/pages_alloc.c

Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 mm/page_alloc.c |   23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index f70c5f4..e3ba363 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -120,6 +120,24 @@ unsigned long dirty_balance_reserve __read_mostly;
 int percpu_pagelist_fraction;
 gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;
 
+static int zero_data_pages_enabled;
+struct static_key __initdata zero_free_pages = STATIC_KEY_INIT_FALSE;
+
+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);
+
 #ifdef CONFIG_PM_SLEEP
 /*
  * The following functions are used by the suspend/hibernate code to temporarily
@@ -730,8 +748,11 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
 
 	if (PageAnon(page))
 		page->mapping = NULL;
-	for (i = 0; i < (1 << order); i++)
+	for (i = 0; i < (1 << order); i++) {
 		bad += free_pages_check(page + i);
+		if (static_key_false(&zero_free_pages))
+			clear_highpage(page + i);
+	}
 	if (bad)
 		return false;
 



More information about the Devel mailing list