mm/page_reporting: Add page_reporting_delay_ms module parameter
Subsystems (3)
PATCH v3 1/1 mm/page_reporting: Add page_reporting_delay_ms module parameter
From: Pratyush Mallick <[email protected]>
Currently, the free page reporting 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 host 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 host 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 exposes the delay as a module parameter:/sys/module/page_reporting/parameters/page_reporting_delay_ms, measured in milliseconds and defaults to 2000ms.
---
v3:
- Converted page_reporting_delay_ms from a sysctl to a module parameter.
- Dropped the max value cap (PAGE_REPORTING_DELAY_MS_MAX).
- Documented page_reporting_delay_ms in kernel-parameters.txt.
- Updated code comments in mm/page_reporting.c.
- v2: https://lore.kernel.org/linux-mm/[email protected]/T/#t
v2:
- Documented page_reporting_delay_ms in Documentation/admin-guide/sysctl/vm.rst.
- v1: https://lore.kernel.org/linux-mm/[email protected]/T/#u
v1: Fixed feedback from RFC.
- Added lower and upper cap to sysctl value.
- Reverted the reordering on page_reporting_delay_ms.
- Dropped the mod_delayed_work() change.
- RFC: https://lore.kernel.org/linux-mm/[email protected]/T/#u
.../admin-guide/kernel-parameters.txt | 6 ++++++ mm/page_reporting.c | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +6 -0
@@ -4810,6 +4810,12 @@ Kernel parameters Adjust the minimal page reporting order. The page reporting is disabled when it exceeds MAX_PAGE_ORDER. + page_reporting.page_reporting_delay_ms= + [KNL] Free page reporting delay in milliseconds + Format: <unsigned integer> + Adjust the delay in milliseconds between free page + reporting intervals. Default is 2000 (2 seconds). + panic= [KNL] Kernel behaviour on panic: delay <timeout> timeout > 0: seconds before rebooting timeout = 0: wait forever
mm/page_reporting.c +13 -8
@@ -47,7 +47,11 @@ MODULE_PARM_DESC(page_reporting_order, "Set page reporting order");*/ EXPORT_SYMBOL_GPL (page_reporting_order); -#define PAGE_REPORTING_DELAY (2 * HZ) +static unsigned int page_reporting_delay_ms =2 *MSEC_PER_SEC ; +module_param (page_reporting_delay_ms, uint,0644 ); +MODULE_PARM_DESC (page_reporting_delay_ms, +"Set page reporting delay in milliseconds" ); +static struct page_reporting_dev_info __rcu *pr_dev_info__read_mostly ;enum {
@@ -76,11 +80,11 @@ __page_reporting_request(struct page_reporting_dev_info *prdev)return ;/* -* Delay the start of work to allow a sizable queue to build. For -* now we are limiting this to running no more than once every -* couple of seconds. +* Delay the start of work to allow a sizable queue to build. +* We limit this based on page_reporting_delay_ms. */ -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 */
@@ -335,12 +339,13 @@ static void page_reporting_process(struct work_struct *work) err_out:/* * If the state has reverted back to requested then there may be -* additional pages to be processed. We will defer for 2s to allow -* more pages to accumulate. +* additional pages to be processed. We will defer by +* page_reporting_delay_ms to allow more pages to accumulate. */ 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);
Signature · 1 line
2.55.0.229.g6434b31f56-goog
Quoted 14 lines · On Mon, 27 Jul 2026 23:05:45 +0000 [email protected] wrote:
From: Pratyush Mallick <[email protected]>
Currently, the free page reporting 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 host 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 host 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.
Quoted 3 lines
This patch exposes the delay as a module parameter:
/sys/module/page_reporting/parameters/page_reporting_delay_ms, measured in milliseconds and defaults to 2000ms.
Makes sense to me.
Quoted 2 lines
Signed-off-by Pratyush Mallick <[email protected]>
Thanks,
SJ
[...]
Andrew Morton
maintainerQuoted 14 lines · On Mon, 27 Jul 2026 23:05:45 +0000 [email protected] wrote:
From: Pratyush Mallick <[email protected]>
Currently, the free page reporting 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 host 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 host 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.
Quoted 3 lines
This patch exposes the delay as a module parameter:
/sys/module/page_reporting/parameters/page_reporting_delay_ms, measured in milliseconds and defaults to 2000ms.
Of course we'd prefer some sort of self-tuning so the kernel automatically avoids the situation. But the user's expectation that reporting occurs at a fixed frequency messes up that concept.
Documentation/admin-guide/kernel-parameters.txt
Quoted 1 line
Documentation/admin-guide/kernel-parameters.txt +0
-0
lgtm. It conflicts with Link Lin's "mm/page_reporting: use system_freezable_wq to fix UAF during suspend". Easy resolution:
Documentation/admin-guide/kernel-parameters.txt | 6 ++++ mm/page_reporting.c | 19 ++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-)
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~mm-page_reporting-add-page_reporting_delay_ms-module-parameter +6 -0
@@ -4813,6 +4813,12 @@ Kernel parameters Adjust the minimal page reporting order. The page reporting is disabled when it exceeds MAX_PAGE_ORDER. + page_reporting.page_reporting_delay_ms= + [KNL] Free page reporting delay in milliseconds + Format: <unsigned integer> + Adjust the delay in milliseconds between free page + reporting intervals. Default is 2000 (2 seconds). + panic= [KNL] Kernel behaviour on panic: delay <timeout> timeout > 0: seconds before rebooting timeout = 0: wait forever
mm/page_reporting.c renamed from mm/page_reporting.c~mm-page_reporting-add-page_reporting_delay_ms-module-parameter +11 -8
@@ -48,7 +48,11 @@ MODULE_PARM_DESC(page_reporting_order, "*/ EXPORT_SYMBOL_GPL (page_reporting_order); -#define PAGE_REPORTING_DELAY (2 * HZ) +static unsigned int page_reporting_delay_ms =2 *MSEC_PER_SEC ; +module_param (page_reporting_delay_ms, uint,0644 ); +MODULE_PARM_DESC (page_reporting_delay_ms, +"Set page reporting delay in milliseconds" ); +static struct page_reporting_dev_info __rcu *pr_dev_info__read_mostly ;enum {
@@ -77,12 +81,11 @@ __page_reporting_request(struct page_repreturn ;/* -* Delay the start of work to allow a sizable queue to build. For -* now we are limiting this to running no more than once every -* couple of seconds. +* Delay the start of work to allow a sizable queue to build. +* We limit this based on page_reporting_delay_ms. */ queue_delayed_work (system_freezable_wq, &prdev->work, -PAGE_REPORTING_DELAY ); +msecs_to_jiffies (page_reporting_delay_ms)); }/* notify prdev of free page reporting request */
@@ -337,13 +340,13 @@ static void page_reporting_process(struc err_out:/* * If the state has reverted back to requested then there may be -* additional pages to be processed. We will defer for 2s to allow -* more pages to accumulate. +* additional pages to be processed. We will defer by +* page_reporting_delay_ms to allow more pages to accumulate. */ state =atomic_cmpxchg (&prdev->state, state,PAGE_REPORTING_IDLE );if (state ==PAGE_REPORTING_REQUESTED )queue_delayed_work (system_freezable_wq, &prdev->work, -PAGE_REPORTING_DELAY ); +msecs_to_jiffies (page_reporting_delay_ms)); }static DEFINE_MUTEX (page_reporting_mutex);
_
Quoted 3 lines
Of course we'd prefer some sort of self-tuning so the kernel automatically avoids the situation. But the user's expectation that reporting occurs at a fixed frequency messes up that concept.
That's definitely a good direction to ponder for future iterations. :') Thanks for handling the merge resolution.
Regards,
Pratyush
Quoted 101 lines · Andrew Morton
Quoted 14 lines · On Mon, 27 Jul 2026 23:05:45 +0000 [email protected] wrote:
From: Pratyush Mallick <[email protected]>
Currently, the free page reporting 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 host 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 host 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.
Quoted 3 lines
This patch exposes the delay as a module parameter:
/sys/module/page_reporting/parameters/page_reporting_delay_ms, measured in milliseconds and defaults to 2000ms.Of course we'd prefer some sort of self-tuning so the kernel automatically avoids the situation. But the user's expectation that reporting occurs at a fixed frequency messes up that concept.
Documentation/admin-guide/kernel-parameters.txt
Quoted 1 line
Documentation/admin-guide/kernel-parameters.txt +0
-0lgtm. It conflicts with Link Lin's "
mm/page_reporting: usesystem_freezable_wqto fix UAF during suspend". Easy resolution:Documentation/admin-guide/kernel-parameters.txt | 6 ++++ mm/page_reporting.c | 19 ++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-)Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~mm-page_reporting-add-page_reporting_delay_ms-module-parameter +6
-0@@ -4813,6 +4813,12 @@ Kernel parameters Adjust the minimal page reporting order. The page reporting is disabled when it exceeds MAX_PAGE_ORDER. + page_reporting.page_reporting_delay_ms= + [KNL] Free page reporting delay in milliseconds + Format: <unsigned integer> + Adjust the delay in milliseconds between free page + reporting intervals. Default is 2000 (2 seconds). + panic= [KNL] Kernel behaviour on panic: delay <timeout> timeout > 0: seconds before rebooting timeout = 0: wait forevermm/page_reporting.c renamed from mm/page_reporting.c~mm-page_reporting-add-page_reporting_delay_ms-module-parameter +11
-8@@ -48,7 +48,11 @@ MODULE_PARM_DESC(page_reporting_order, "*/ EXPORT_SYMBOL_GPL (page_reporting_order); -#define PAGE_REPORTING_DELAY (2 * HZ) +static unsigned int page_reporting_delay_ms =2 *MSEC_PER_SEC ; +module_param (page_reporting_delay_ms, uint,0644 ); +MODULE_PARM_DESC (page_reporting_delay_ms, +"Set page reporting delay in milliseconds" ); +static struct page_reporting_dev_info __rcu *pr_dev_info__read_mostly ;enum {@@ -77,12 +81,11 @@ __page_reporting_request(struct page_repreturn ;/* -* Delay the start of work to allow a sizable queue to build. For -* now we are limiting this to running no more than once every -* couple of seconds. +* Delay the start of work to allow a sizable queue to build. +* We limit this based on page_reporting_delay_ms. */ queue_delayed_work (system_freezable_wq, &prdev->work, -PAGE_REPORTING_DELAY ); +msecs_to_jiffies (page_reporting_delay_ms)); }/* notify prdev of free page reporting request */ @@ -337,13 +340,13 @@ static void page_reporting_process(struc err_out:/* * If the state has reverted back to requested then there may be -* additional pages to be processed. We will defer for 2s to allow -* more pages to accumulate. +* additional pages to be processed. We will defer by +* page_reporting_delay_ms to allow more pages to accumulate. */ state =atomic_cmpxchg (&prdev->state, state,PAGE_REPORTING_IDLE );if (state ==PAGE_REPORTING_REQUESTED )queue_delayed_work (system_freezable_wq, &prdev->work, -PAGE_REPORTING_DELAY ); +msecs_to_jiffies (page_reporting_delay_ms)); }static DEFINE_MUTEX (page_reporting_mutex);_
Quoted 6 lines · On Mon, Jul 27, 2026 at 11:05:45PM +0000, [email protected] wrote:
From: Pratyush Mallick <[email protected]>
Currently, the free page reporting 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.
Quoted 7 lines
A low delay allows aggressive memory reclamation, returning unused pages to the host 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 host 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.
Since you're talking about increasing it, maybe set the floor at the current value of 2s?
Quoted 4 lines
This patch exposes the delay as a module parameter:
/sys/module/page_reporting/parameters/page_reporting_delay_ms, measured in milliseconds and defaults to 2000ms.
I'm not sure this is great as it means we now have a parameter we have to support forever and autotuning becomes harder to implement, also if later the implementation is changed, this might prevent a reimplementation.
Have you considered actually adding logic to detect the problem you're having and delay in that case?
It seems like this is the "easy" solution but it has a price too.
Quoted 60 lines
Signed-off-by Pratyush Mallick <[email protected]>---
v3:
- Convertedpage_reporting_delay_msfrom a sysctl to a module parameter.
- Dropped the max value cap (PAGE_REPORTING_DELAY_MS_MAX).
- Documentedpage_reporting_delay_msin kernel-parameters.txt.
- Updated code comments inmm/page_reporting.c.
- v2: https://lore.kernel.org/linux-mm/[email protected]/T/#tv2:
- Documentedpage_reporting_delay_msinDocumentation/admin-guide/sysctl/vm.rst.
- v1: https://lore.kernel.org/linux-mm/[email protected]/T/#uv1: Fixed feedback from RFC.
- Added lower and upper cap to sysctl value.
- Reverted the reordering onpage_reporting_delay_ms.
- Dropped themod_delayed_work()change.
- RFC: https://lore.kernel.org/linux-mm/[email protected]/T/#u.../admin-guide/kernel-parameters.txt | 6 ++++++ mm/page_reporting.c | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-)Documentation/admin-guide/kernel-parameters.txt +6
-0@@ -4810,6 +4810,12 @@ Kernel parameters Adjust the minimal page reporting order. The page reporting is disabled when it exceeds MAX_PAGE_ORDER. + page_reporting.page_reporting_delay_ms= + [KNL] Free page reporting delay in milliseconds + Format: <unsigned integer> + Adjust the delay in milliseconds between free page + reporting intervals. Default is 2000 (2 seconds). + panic= [KNL] Kernel behaviour on panic: delay <timeout> timeout > 0: seconds before rebooting timeout = 0: wait forevermm/page_reporting.c +5
-1@@ -47,7 +47,11 @@ MODULE_PARM_DESC(page_reporting_order, "Set page reporting order");*/ EXPORT_SYMBOL_GPL (page_reporting_order); -#define PAGE_REPORTING_DELAY (2 * HZ) +static unsigned int page_reporting_delay_ms =2 *MSEC_PER_SEC ; +module_param (page_reporting_delay_ms, uint,0644 ); +MODULE_PARM_DESC (page_reporting_delay_ms, +"Set page reporting delay in milliseconds" ); +static struct page_reporting_dev_info __rcu *pr_dev_info__read_mostly ;enum {@@ -76,11 +80,11 @@ __page_reporting_request(struct page_reporting_dev_info *prdev)return ;
mm/page_reporting.c __page_reporting_request(struct page_reporting_dev_info *prdev) · line 87
Quoted 10 lines
mm/page_reporting.c +4
-4/* -* Delay the start of work to allow a sizable queue to build. For -* now we are limiting this to running no more than once every -* couple of seconds. +* Delay the start of work to allow a sizable queue to build. +* We limit this based on page_reporting_delay_ms. */ -schedule_delayed_work (&prdev->work,PAGE_REPORTING_DELAY ); +schedule_delayed_work (&prdev->work, +msecs_to_jiffies (page_reporting_delay_ms));
Err, do we not want to limit this to something sensible? What if the user specifies 0 does it just hammer the system at that stage?
Quoted 7 lines
mm/page_reporting.c +0
-0}/* notify prdev of free page reporting request */ @@ -335,12 +339,13 @@ static void page_reporting_process(struct work_struct *work) err_out:/* * If the state has reverted back to requested then there may be
mm/page_reporting.c static void page_reporting_process(struct work_struct *work) · line 348
Quoted 10 lines
mm/page_reporting.c +4
-3-* additional pages to be processed. We will defer for 2s to allow -* more pages to accumulate. +* additional pages to be processed. We will defer by +* page_reporting_delay_ms to allow more pages to accumulate. */ 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));
This code is duplicated, while you've making this change maybe pull this into its own function?
Quoted 6 lines
mm/page_reporting.c +0
-1}static DEFINE_MUTEX (page_reporting_mutex); --2.55.0.229.g6434b31f56-goog
Thanks, Lorenzo
(Also this patch should require a tag from Vlasta as it comes under the page allocator.)
Cheers, Lorenzo
Quoted 4 lines · Andrew Morton
Documentation/admin-guide/kernel-parameters.txt
Quoted 1 line
Documentation/admin-guide/kernel-parameters.txt +0
-0lgtm. It conflicts with Link Lin's "
mm/page_reporting: usesystem_freezable_wqto fix UAF during suspend". Easy resolution:
Thanks Andrew for handling the conflict resolution!
Sincerely,
Link Lin
Quoted 19 lines · Lorenzo Stoakes (ARM)
Quoted 6 lines · On Mon, Jul 27, 2026 at 11:05:45PM +0000, [email protected] wrote:
From: Pratyush Mallick <[email protected]>
Currently, the free page reporting 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.
Quoted 7 lines
A low delay allows aggressive memory reclamation, returning unused pages to the host 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 host 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.
Since you're talking about increasing it, maybe set the floor at the current value of 2s?
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
This patch exposes the delay as a module parameter:
/sys/module/page_reporting/parameters/page_reporting_delay_ms, measured in milliseconds and defaults to 2000ms.I'm not sure this is great as it means we now have a parameter we have to support forever and autotuning becomes harder to implement, also if later the implementation is changed, this might prevent a reimplementation.
While I'd prefer to keep the implementation as simple as possible unless really required, I guess auto-tune could be enabled by setting the parameter to e.g., -1 in the future.
Quoted 66 lines
Have you considered actually adding logic to detect the problem you're having and delay in that case?
It seems like this is the "easy" solution but it has a price too.
Quoted 60 lines
Signed-off-by Pratyush Mallick <[email protected]>---
v3:
- Convertedpage_reporting_delay_msfrom a sysctl to a module parameter.
- Dropped the max value cap (PAGE_REPORTING_DELAY_MS_MAX).
- Documentedpage_reporting_delay_msin kernel-parameters.txt.
- Updated code comments inmm/page_reporting.c.
- v2: https://lore.kernel.org/linux-mm/[email protected]/T/#tv2:
- Documentedpage_reporting_delay_msinDocumentation/admin-guide/sysctl/vm.rst.
- v1: https://lore.kernel.org/linux-mm/[email protected]/T/#uv1: Fixed feedback from RFC.
- Added lower and upper cap to sysctl value.
- Reverted the reordering onpage_reporting_delay_ms.
- Dropped themod_delayed_work()change.
- RFC: https://lore.kernel.org/linux-mm/[email protected]/T/#u.../admin-guide/kernel-parameters.txt | 6 ++++++ mm/page_reporting.c | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-)Documentation/admin-guide/kernel-parameters.txt +6
-0@@ -4810,6 +4810,12 @@ Kernel parameters Adjust the minimal page reporting order. The page reporting is disabled when it exceeds MAX_PAGE_ORDER. + page_reporting.page_reporting_delay_ms= + [KNL] Free page reporting delay in milliseconds + Format: <unsigned integer> + Adjust the delay in milliseconds between free page + reporting intervals. Default is 2000 (2 seconds). + panic= [KNL] Kernel behaviour on panic: delay <timeout> timeout > 0: seconds before rebooting timeout = 0: wait forevermm/page_reporting.c +5
-1@@ -47,7 +47,11 @@ MODULE_PARM_DESC(page_reporting_order, "Set page reporting order");*/ EXPORT_SYMBOL_GPL (page_reporting_order); -#define PAGE_REPORTING_DELAY (2 * HZ) +static unsigned int page_reporting_delay_ms =2 *MSEC_PER_SEC ; +module_param (page_reporting_delay_ms, uint,0644 ); +MODULE_PARM_DESC (page_reporting_delay_ms, +"Set page reporting delay in milliseconds" ); +static struct page_reporting_dev_info __rcu *pr_dev_info__read_mostly ;enum {@@ -76,11 +80,11 @@ __page_reporting_request(struct page_reporting_dev_info *prdev)return ;
Quoted 13 lines
mm/page_reporting.c __page_reporting_request(struct page_reporting_dev_info *prdev) · line 87
Quoted 10 lines
mm/page_reporting.c +4
-4/* -* Delay the start of work to allow a sizable queue to build. For -* now we are limiting this to running no more than once every -* couple of seconds. +* Delay the start of work to allow a sizable queue to build. +* We limit this based on page_reporting_delay_ms. */ -schedule_delayed_work (&prdev->work,PAGE_REPORTING_DELAY ); +schedule_delayed_work (&prdev->work, +msecs_to_jiffies (page_reporting_delay_ms));Err, do we not want to limit this to something sensible? What if the user specifies 0 does it just hammer the system at that stage?
IIUC, 0 just means "as soon there is a suitable free page block to report, start reporting immediately".
With 2s, we wait 2s before we start reporting immediately by kicking the workqueue immediately.
So "0" does not mean "report all the time", rather "start reporting immediately as we are notified about a pageblock to report".
Signature · 3 lines
Cheers, David
Quoted 17 lines · David Hildenbrand (Arm)
Quoted 15 lines · Lorenzo Stoakes (ARM)
Quoted 13 lines · On Mon, Jul 27, 2026 at 11:05:45PM +0000, [email protected] wrote:
From: Pratyush Mallick <[email protected]>
Currently, the free page reporting 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 host 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 host 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.
Quoted 2 lines
Quoted 2 lines
Since you're talking about increasing it, maybe set the floor at the current value of 2s?
We benefit equally by setting the value to zero as well. This would immediately report the pages being freed back to the host without any delay. This helps when the host is under pressure, as any immediate memory release would help it.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
This patch exposes the delay as a module parameter:
/sys/module/page_reporting/parameters/page_reporting_delay_ms, measured in milliseconds and defaults to 2000ms.
Quoted 7 lines
Quoted 3 lines
I'm not sure this is great as it means we now have a parameter we have to support forever and autotuning becomes harder to implement, also if later the implementation is changed, this might prevent a reimplementation.
While I'd prefer to keep the implementation as simple as possible unless really required, I guess auto-tune could be enabled by setting the parameter to e.g., -1 in the future.
The case we're trying to solve involves tuning free page reporting based on host memory pressure. I think the host is the primary beneficiary of free page reporting, so if we wanted to dynamically autotune this delay, we would need some mechanism from the host to enlighten the guest about its current memory pressure and the autotuner would build its heuristics around it.
As far as I understand, no such mechanism currently exists. While we do have ballooning, it requires the guest to actively allocate memory under pressure, which makes it a comparatively slower mechanism and wouldn't help much for simply adjusting the reporting rate of already free pages.
Quoted 14 lines
Quoted 11 lines
mm/page_reporting.c __page_reporting_request(struct page_reporting_dev_info *prdev) · line 87
Quoted 10 lines
/*mm/page_reporting.c +4
-4-* Delay the start of work to allow a sizable queue to build. For -* now we are limiting this to running no more than once every -* couple of seconds. +* Delay the start of work to allow a sizable queue to build. +* We limit this based on page_reporting_delay_ms. */ -schedule_delayed_work (&prdev->work,PAGE_REPORTING_DELAY ); +schedule_delayed_work (&prdev->work, +msecs_to_jiffies (page_reporting_delay_ms));Quoted 2 lines
Err, do we not want to limit this to something sensible? What if the user specifies 0 does it just hammer the system at that stage?
Quoted 8 lines
IIUC, 0 just means "as soon there is a suitable free page block to report, start reporting immediately".
With 2s, we wait 2s before we start reporting immediately by kicking the workqueue immediately.
So "0" does not mean "report all the time", rather "start reporting immediately as we are notified about a pageblock to report".
Right. Setting the delay to 0 does not hammer the system. The execution is constrained by two checks:
1. The worker is only scheduled when high-order pages (default is >= 2MB) are freed. This makes scheduling relatively infrequent compared to normal 4K page allocations.
2. Even when the worker wakes up, the actual expensive operations, such as page isolation, acquiring locks, and hypercalls to report pages, are guarded by the watermark check in page_reporting_process_zone(). We only proceed with reporting if the zone has enough free pages to fill the capacity batches (32 slots by default). If the watermark is not met, the worker simply
exits and returns to the IDLE state without issuing any hypercalls.
Quoted 9 lines
Quoted 9 lines
mm/page_reporting.c __page_reporting_request(struct page_reporting_dev_info *prdev) · line 87
Quoted 5 lines
state = atomic_cmpxchg(&prdev->state, state, PAGE_REPORTING_IDLE); if (state == PAGE_REPORTING_REQUESTED)mm/page_reporting.c +2
-1-schedule_delayed_work (&prdev->work,PAGE_REPORTING_DELAY ); +schedule_delayed_work (&prdev->work, +msecs_to_jiffies (page_reporting_delay_ms));This code is duplicated, while you've making this change maybe pull this into its own function?
Thanks. I can create a new function for this and send a V4.
Regards,
Pratyush
Quoted 19 lines · Pratyush Mallick
Quoted 17 lines · David Hildenbrand (Arm)
Quoted 15 lines · Lorenzo Stoakes (ARM)
Quoted 13 lines · On Mon, Jul 27, 2026 at 11:05:45PM +0000, [email protected] wrote:
From: Pratyush Mallick <[email protected]>
Currently, the free page reporting 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 host 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 host 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.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Since you're talking about increasing it, maybe set the floor at the current value of 2s?
We benefit equally by setting the value to zero as well. This would immediately report the pages being freed back to the host without any delay. This helps when the host is under pressure, as any immediate memory release would help it.
OK page_reporting_order makes this better.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
This patch exposes the delay as a module parameter:
/sys/module/page_reporting/parameters/page_reporting_delay_ms, measured in milliseconds and defaults to 2000ms.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I'm not sure this is great as it means we now have a parameter we have to support forever and autotuning becomes harder to implement, also if later the implementation is changed, this might prevent a reimplementation.
While I'd prefer to keep the implementation as simple as possible unless really required, I guess auto-tune could be enabled by setting the parameter to e.g., -1 in the future.
We'd have to retain the customisable delay forever either way.
But I guess maybe in this case it's not such a big deal.
Quoted 10 lines
The case we're trying to solve involves tuning free page reporting based on host memory pressure. I think the host is the primary beneficiary of free page reporting, so if we wanted to dynamically autotune this delay, we would need some mechanism from the host to enlighten the guest about its current memory pressure and the autotuner would build its heuristics around it.
As far as I understand, no such mechanism currently exists. While we do have ballooning, it requires the guest to actively allocate memory under pressure, which makes it a comparatively slower mechanism and wouldn't help much for simply adjusting the reporting rate of already free pages.
You're explicitly needing to do this under certain circumstances.
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
/*mm/page_reporting.c +4
-4-* Delay the start of work to allow a sizable queue to build. For -* now we are limiting this to running no more than once every -* couple of seconds. +* Delay the start of work to allow a sizable queue to build. +* We limit this based on page_reporting_delay_ms. */ -schedule_delayed_work (&prdev->work,PAGE_REPORTING_DELAY ); +schedule_delayed_work (&prdev->work, +msecs_to_jiffies (page_reporting_delay_ms));
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Err, do we not want to limit this to something sensible? What if the user specifies 0 does it just hammer the system at that stage?
IIUC, 0 just means "as soon there is a suitable free page block to report, start reporting immediately".
There's comments like "We will defer by page_reporting_delay_ms to allow more pages to accumulate." etc.
Maybe worth tweaking that?
But with page_reporting_order == 9 (or 5 see below) then fine I guess.
If somebody asks for something stupid by setting it higher they'd already accumulate latencies, just now with a 0 timer it could be really crazy :) but I suppose they are asking for it.
Quoted 6 lines
Quoted 6 lines
With 2s, we wait 2s before we start reporting immediately by kicking the workqueue immediately.
So "0" does not mean "report all the time", rather "start reporting immediately as we are notified about a pageblock to report".
No, it's whenever pageblock_order is specified, defaulting to a pageblock.
But I guess in practice fine.
There's fun like this in virtio_balloon.c btw:
/*
* The default page reporting order is @pageblock_order, which
* corresponds to 512MB in size on ARM64 when 64KB base page
* size is used. The page reporting won't be triggered if the
* freeing page can't come up with a free area like that huge.
* So we specify the page reporting order to 5, corresponding
* to 2MB. It helps to avoid THP splitting if 4KB base page
* size is used by host.
*
* Ideally, the page reporting order is selected based on the
* host's base page size. However, it needs more work to report
* that value. The hard-coded order would be fine currently. */
#if defined(CONFIG_ARM64) && defined(CONFIG_ARM64_64K_PAGES) vb->pr_dev_info.order = 5;
#endif
Quoted 6 lines
Right. Setting the delay to 0 does not hammer the system. The execution is constrained by two checks:
1. The worker is only scheduled when high-order pages (default is >= 2MB) are freed. This makes scheduling relatively infrequent compared to normal 4K page allocations.
It's that only by default and could be overridden (and is for arm64 64 KiB page tables but probably also fine there)
But probably fine.
Quoted 7 lines
2. Even when the worker wakes up, the actual expensive operations, such as page isolation, acquiring locks, and hypercalls to report pages, are guarded by the watermark check in
page_reporting_process_zone(). We only proceed with reporting if the zone has enough free pages to fill the capacity batches (32 slots by default). If the watermark is not met, the worker simply
exits and returns to the IDLE state without issuing any hypercalls.
OK that makes it better.
Can you make these points in the commit msg on respin then?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
state = atomic_cmpxchg(&prdev->state, state, PAGE_REPORTING_IDLE); if (state == PAGE_REPORTING_REQUESTED)mm/page_reporting.c +2
-1-schedule_delayed_work (&prdev->work,PAGE_REPORTING_DELAY ); +schedule_delayed_work (&prdev->work, +msecs_to_jiffies (page_reporting_delay_ms));
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
This code is duplicated, while you've making this change maybe pull this into its own function?
Thanks. I can create a new function for this and send a V4.
Thanks
Quoted 3 lines
Regards,
Pratyush
Cheers, Lorenzo
Quoted 25 lines
Quoted 5 lines
Quoted 5 lines
With 2s, we wait 2s before we start reporting immediately by kicking the workqueue immediately.
So "0" does not mean "report all the time", rather "start reporting immediately as we are notified about a pageblock to report".
No, it's whenever
pageblock_orderis specified, defaulting to a pageblock.But I guess in practice fine.
There's fun like this in
virtio_balloon.cbtw:/*
* The default page reporting order is @pageblock_order, which
* corresponds to 512MB in size on ARM64 when 64KB base page
* size is used. The page reporting won't be triggered if the
* freeing page can't come up with a free area like that huge.
* So we specify the page reporting order to 5, corresponding
* to 2MB. It helps to avoid THP splitting if 4KB base page
* size is used by host.
*
* Ideally, the page reporting order is selected based on the
* host's base page size. However, it needs more work to report
* that value. The hard-coded order would be fine currently. */
Quoted 3 lines
#if defined(CONFIG_ARM64) && defined(CONFIG_ARM64_64K_PAGES) vb->pr_dev_info.order = 5;#endif
Yes, it's really about "a large chunk of memory was freed". On 64k " a large chunk" is unfortunately order 5 == 2MiB (so the same as on 4k where a pageblock is 2M).
Signature · 3 lines
Cheers, David
Quoted 29 lines · David Hildenbrand (Arm)
Quoted 25 lines
Quoted 5 lines
Quoted 5 lines
With 2s, we wait 2s before we start reporting immediately by kicking the workqueue immediately.
So "0" does not mean "report all the time", rather "start reporting immediately as we are notified about a pageblock to report".
No, it's whenever
pageblock_orderis specified, defaulting to a pageblock.But I guess in practice fine.
There's fun like this in
virtio_balloon.cbtw:/*
* The default page reporting order is @pageblock_order, which
* corresponds to 512MB in size on ARM64 when 64KB base page
* size is used. The page reporting won't be triggered if the
* freeing page can't come up with a free area like that huge.
* So we specify the page reporting order to 5, corresponding
* to 2MB. It helps to avoid THP splitting if 4KB base page
* size is used by host.
*
* Ideally, the page reporting order is selected based on the
* host's base page size. However, it needs more work to report
* that value. The hard-coded order would be fine currently. */Quoted 3 lines
#if defined(CONFIG_ARM64) && defined(CONFIG_ARM64_64K_PAGES) vb->pr_dev_info.order = 5;#endif
Quoted 3 lines
Yes, it's really about "a large chunk of memory was freed". On 64k " a large chunk" is unfortunately order 5 == 2MiB (so the same as on 4k where a pageblock is 2M).
Yup :)
Yeah in general I'm fine then with the timeout being 0, the fact it's batched like this makes that rather moot!
Quoted 5 lines
--
Cheers,David
Cheers, Lorenzo