[Devel] [PATCH RHEL7 COMMIT] x86: "pages zeroing on free" option introduced

Konstantin Khorenko khorenko at virtuozzo.com
Wed Nov 25 02:25:31 PST 2015


The commit is pushed to "branch-rh7-3.10.0-229.7.2.vz7.9.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-229.7.2.vz7.9.13
------>
commit 709598cd93c2c0e7d088c341c5277143d9b963f6
Author: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
Date:   Wed Nov 25 14:25:31 2015 +0400

    x86: "pages zeroing on free" option introduced
    
    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.
    
    https://jira.sw.ru/browse/PSBM-33071
    
    Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
    Reviewed-by: Vladimir Davydov <vdavydov 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