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

Konstantin Khorenko khorenko at virtuozzo.com
Thu Sep 30 17:44:00 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit 48704ca788d5eea521bbe290d685c7c391cb74c1
Author: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
Date:   Thu Sep 30 17:44:00 2021 +0300

    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: Fix section mismatch of zero_free_pages
    
    zero_free_pages is used not only from boot code:
    
    WARNING: vmlinux.o(.text+0x21f668): Section mismatch in reference from the function __free_pages_ok() to the variable .init.data:zero_free_pages
    The function __free_pages_ok() references
    the variable __initdata zero_free_pages.
    This is often because __free_pages_ok lacks a __initdata
    annotation or the annotation of zero_free_pages is wrong.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    (cherry-picked from vz8 commit 26c485e52037 ("x86: "pages zeroing on free"
    option introduced"))
    
    Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 mm/page_alloc.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 710e60eaa581..ad69d7664e90 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -225,6 +225,24 @@ static inline void set_pcppage_migratetype(struct page *page, int migratetype)
 	page->index = migratetype;
 }
 
+static int zero_data_pages_enabled;
+struct static_key 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
@@ -1330,6 +1348,9 @@ static __always_inline bool free_pages_prepare(struct page *page,
 				continue;
 			}
 			(page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
+
+			if (static_key_false(&zero_free_pages))
+				clear_highpage(page + i);
 		}
 	}
 	if (PageMappingFlags(page))
@@ -1341,6 +1362,9 @@ static __always_inline bool free_pages_prepare(struct page *page,
 	if (bad)
 		return false;
 
+	if (static_key_false(&zero_free_pages))
+		clear_highpage(page);
+
 	page_cpupid_reset_last(page);
 	page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
 	reset_page_owner(page, order);


More information about the Devel mailing list