mm/page_reporting: Add page_reporting_delay_ms sysctl
Subsystems (2)
PATCH 1/1 mm/page_reporting: Add page_reporting_delay_ms sysctl
From: Pratyush Mallick <[email protected]>
Currently, the free page reporting daemon uses a hardcoded delay of (2 HZ) between reporting intervals. While this is a reasonable default, it lacks the flexibility to adapt to varying guest workloads.
A low delay allows aggressive memory reclamation, returning unused pages to the hypervisor as quickly as possible. However, during spiky allocation/free churn, this immediate reporting can lead to a severe performance penalty (nested page faults) as the guest re-allocates memory that the hypervisor has just unmapped. In these scenarios, there is benefit from increasing the delay to batch free pages over a longer window, absorbing the churn without hypercall and re-fault overhead.
This patch refactors the delay into a dynamically tunable sysctl, /proc/sys/vm/page_reporting_delay_ms, measured in milliseconds. The value defaults to 2000ms to precisely match the original (2 HZ) behavior.
---
v1: Fixed feedback from RFC.
- Added lower and upper cap to sysctl value.
- Reverted the reordering on page_reporting_delay_ms.
- Droped the mod_delayed_work() change.
- https://lore.kernel.org/linux-mm/[email protected]/T/#u
mm/page_reporting.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
mm/page_reporting.c +26 -3
@@ -6,6 +6,7 @@#include <linux/export.h> #include <linux/module.h> #include <linux/delay.h> +#include <linux/sysctl.h> #include <linux/scatterlist.h> #include "page_reporting.h"
@@ -47,7 +48,10 @@ MODULE_PARM_DESC(page_reporting_order, "Set page reporting order");*/ EXPORT_SYMBOL_GPL (page_reporting_order); -#define PAGE_REPORTING_DELAY (2 * HZ) +#define PAGE_REPORTING_DELAY_MS_MAX (10 * MSEC_PER_SEC) + +static unsigned int page_reporting_delay_ms =2 *MSEC_PER_SEC ; +static unsigned int page_reporting_delay_ms_max =PAGE_REPORTING_DELAY_MS_MAX ;static struct page_reporting_dev_info __rcu *pr_dev_info__read_mostly ;enum {
@@ -56,6 +60,18 @@ enum { PAGE_REPORTING_ACTIVE }; +static struct ctl_table page_reporting_sysctls[] = { + { + .procname ="page_reporting_delay_ms" , + .data = &page_reporting_delay_ms, + .maxlen =sizeof (unsigned int ), + .mode =0644 , + .proc_handler = proc_douintvec_minmax, + .extra1 =SYSCTL_ZERO , + .extra2 = &page_reporting_delay_ms_max, + }, +}; +/* request page reporting */ static void __page_reporting_request (struct page_reporting_dev_info *prdev)
@@ -80,7 +96,7 @@ __page_reporting_request(struct page_reporting_dev_info *prdev)* now we are limiting this to running no more than once every * couple of seconds. */ -schedule_delayed_work (&prdev->work,PAGE_REPORTING_DELAY ); +schedule_delayed_work (&prdev->work,msecs_to_jiffies (page_reporting_delay_ms)); }/* notify prdev of free page reporting request */
@@ -340,7 +356,7 @@ static void page_reporting_process(struct work_struct *work)*/ state =atomic_cmpxchg (&prdev->state, state,PAGE_REPORTING_IDLE );if (state ==PAGE_REPORTING_REQUESTED ) -schedule_delayed_work (&prdev->work,PAGE_REPORTING_DELAY ); +schedule_delayed_work (&prdev->work,msecs_to_jiffies (page_reporting_delay_ms)); }static DEFINE_MUTEX (page_reporting_mutex);
@@ -416,3 +432,10 @@ void page_reporting_unregister(struct page_reporting_dev_info *prdev)mutex_unlock (&page_reporting_mutex); }EXPORT_SYMBOL_GPL (page_reporting_unregister); + +static int __init page_reporting_sysctl_init (void ) +{ +register_sysctl_init ("vm" , page_reporting_sysctls); +return 0 ; +} +late_initcall (page_reporting_sysctl_init);
Signature · 1 line
2.55.0.229.g6434b31f56-goog