[PATCH 3/4] mm/page_reporting: Introduce "page_reporting_factor=" boot parameter

From: Xunlei Pang
Date: Fri Mar 26 2021 - 05:46:02 EST


Currently the default behaviour(value 100) is to do full report,
although we can control it after boot via "page_reporting_factor"
sysfs knob, it could still be late because some amount of memory
has already been reported before operating this knob.

Sometimes we really want it safely off by default and turn it on
as needed at runtime, so "page_reporting_factor=" boot parameter
is that guarantee and meets different default setting requirements.

There's also a real-world problem that I noticed on tiny instances,
it always reports some memory at boot stage before application
starts and uses up memory which retriggers EPT fault after boot.

The following data(right after boot) indicates that 172032KiB pages
were unnecessarily reported and refault in:
$ cat /sys/kernel/mm/page_reporting/refault_kbytes
172032
$ cat /sys/kernel/mm/page_reporting/reported_kbytes
0

Thus it's reasonable to turn the page reporting off by default and
enable it at runtime as needed.

Signed-off-by: Xunlei Pang <xlpang@xxxxxxxxxxxxxxxxx>
---
Documentation/admin-guide/kernel-parameters.txt | 3 +++
mm/page_reporting.c | 13 +++++++++++++
2 files changed, 16 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 0454572..46e296c 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -3524,6 +3524,9 @@
off: turn off poisoning (default)
on: turn on poisoning

+ page_reporting_factor= [KNL] Guest Free Page Reporting percentile.
+ [0, 100]: 0 - off, not report; 100 - default, full report.
+
panic= [KNL] Kernel behaviour on panic: delay <timeout>
timeout > 0: seconds before rebooting
timeout = 0: wait forever
diff --git a/mm/page_reporting.c b/mm/page_reporting.c
index 86c6479..6ffedb8 100644
--- a/mm/page_reporting.c
+++ b/mm/page_reporting.c
@@ -524,3 +524,16 @@ static int __init page_reporting_init(void)
}

module_init(page_reporting_init);
+
+static int __init setup_reporting_factor(char *str)
+{
+ int v;
+
+ if (kstrtoint(str, 10, &v))
+ return -EINVAL;
+ if (v >= 0 && v <= 100)
+ reporting_factor = v;
+
+ return 0;
+}
+__setup("page_reporting_factor=", setup_reporting_factor);
--
1.8.3.1