* [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction
@ 2025-01-27 21:50 Michal Clapinski
2025-01-27 21:50 ` [PATCH v3 1/2] mm/compaction: remove low watermark cap for " Michal Clapinski
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Michal Clapinski @ 2025-01-27 21:50 UTC (permalink / raw)
To: Andrew Morton, Vlastimil Babka, Pasha Tatashin
Cc: linux-mm, linux-kernel, Michal Clapinski
Our goal is to keep memory usage of a VM low on the host. For that
reason, we use free page reporting which by default reports free pages
of order 9 and larger to the host to be freed. The feature works well
only if the memory in the guest is not fragmented below pages of order
9. Proactive compaction can be reused to achieve defragmentation after
some parameter tweaking.
When the fragmentation score (lower is better) gets larger than the
high watermark, proactive compaction kicks in. Compaction stops when
the score goes below the low watermark (or no progress is made and
backoff kicks in). Let's define the difference between high and low
watermarks as leeway. Before these changes, the minimum possible value
for low watermark was 5 and the leeway was hardcoded to 10 (so minimum
possible value for high watermark was 15).
v3: Remove gerrit ids from commit msgs.
v2: Change commit msgs and document the new sysctl.
Michal Clapinski (2):
mm/compaction: remove low watermark cap for proactive compaction
mm/compaction: make proactive compaction high watermark configurable
via sysctl
Documentation/admin-guide/sysctl/vm.rst | 17 +++++++++++++++++
mm/compaction.c | 14 ++++++++++++--
2 files changed, 29 insertions(+), 2 deletions(-)
--
2.48.1.262.g85cc9f2d1e-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 1/2] mm/compaction: remove low watermark cap for proactive compaction
2025-01-27 21:50 [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction Michal Clapinski
@ 2025-01-27 21:50 ` Michal Clapinski
2025-01-28 1:17 ` Andrew Morton
2025-01-27 21:50 ` [PATCH v3 2/2] mm/compaction: make proactive compaction high watermark configurable via sysctl Michal Clapinski
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Michal Clapinski @ 2025-01-27 21:50 UTC (permalink / raw)
To: Andrew Morton, Vlastimil Babka, Pasha Tatashin
Cc: linux-mm, linux-kernel, Michal Clapinski
Previously a min cap of 5 has been set in the commit introducing
proactive compaction. This was to make sure users don't hurt themselves
by setting the proactiveness to 100 and making their system
unresponsive. But the compaction mechanism has a backoff mechanism that
will sleep for 30s if no progress is made, so I don't see a significant
risk here. My system (20GB of memory) has been perfectly fine with
proactiveness set to 100 and leeway set to 0.
Signed-off-by: Michal Clapinski <mclapinski@google.com>
---
mm/compaction.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/compaction.c b/mm/compaction.c
index a2b16b08cbbff..29524242a16ef 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -2253,7 +2253,7 @@ static unsigned int fragmentation_score_wmark(bool low)
* activity in case a user sets the proactiveness tunable
* close to 100 (maximum).
*/
- wmark_low = max(100U - sysctl_compaction_proactiveness, 5U);
+ wmark_low = 100U - sysctl_compaction_proactiveness;
return low ? wmark_low : min(wmark_low + 10, 100U);
}
--
2.48.1.262.g85cc9f2d1e-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 2/2] mm/compaction: make proactive compaction high watermark configurable via sysctl
2025-01-27 21:50 [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction Michal Clapinski
2025-01-27 21:50 ` [PATCH v3 1/2] mm/compaction: remove low watermark cap for " Michal Clapinski
@ 2025-01-27 21:50 ` Michal Clapinski
2025-01-28 1:18 ` Andrew Morton
2025-01-28 1:07 ` [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction Andrew Morton
2025-03-17 1:02 ` Andrew Morton
3 siblings, 1 reply; 9+ messages in thread
From: Michal Clapinski @ 2025-01-27 21:50 UTC (permalink / raw)
To: Andrew Morton, Vlastimil Babka, Pasha Tatashin
Cc: linux-mm, linux-kernel, Michal Clapinski
Currently, the difference between the high and low watermarks for
proactive compaction is hardcoded to 10. This hardcoded difference is
too large for free page reporting to work well.
Add a new sysctl, `compaction_proactiveness_leeway`, to control the
difference between the high and low watermarks.
Signed-off-by: Michal Clapinski <mclapinski@google.com>
---
Documentation/admin-guide/sysctl/vm.rst | 17 +++++++++++++++++
mm/compaction.c | 12 +++++++++++-
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst
index f48eaa98d22d2..ec6343ee4248d 100644
--- a/Documentation/admin-guide/sysctl/vm.rst
+++ b/Documentation/admin-guide/sysctl/vm.rst
@@ -27,6 +27,7 @@ Currently, these files are in /proc/sys/vm:
- admin_reserve_kbytes
- compact_memory
- compaction_proactiveness
+- compaction_proactiveness_leeway
- compact_unevictable_allowed
- dirty_background_bytes
- dirty_background_ratio
@@ -133,6 +134,22 @@ proactive compaction is not being effective.
Be careful when setting it to extreme values like 100, as that may
cause excessive background compaction activity.
+compaction_proactiveness_leeway
+===============================
+
+This tunable controls the difference between high and low watermarks for
+proactive compaction. This tunable takes a value in the range [0, 100] with
+a default value of 10. Higher values will result in proactive compaction
+triggering less often but doing more work when it does trigger.
+
+Proactive compaction triggers when fragmentation score (lower is better) gets
+larger than high watermark. Compaction stops when the score gets smaller or
+equal to low watermark (or when no progress is being made).
+The watermarks are calculated as follows:
+
+low_wmark = 100 - compaction_proactiveness;
+high_wmark = low_wmark + compaction_proactiveness_leeway;
+
compact_unevictable_allowed
===========================
diff --git a/mm/compaction.c b/mm/compaction.c
index 29524242a16ef..fd546b797e544 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1921,6 +1921,7 @@ static int sysctl_compact_unevictable_allowed __read_mostly = CONFIG_COMPACT_UNE
* background. It takes values in the range [0, 100].
*/
static unsigned int __read_mostly sysctl_compaction_proactiveness = 20;
+static unsigned int __read_mostly sysctl_compaction_proactiveness_leeway = 10;
static int sysctl_extfrag_threshold = 500;
static int __read_mostly sysctl_compact_memory;
@@ -2254,7 +2255,7 @@ static unsigned int fragmentation_score_wmark(bool low)
* close to 100 (maximum).
*/
wmark_low = 100U - sysctl_compaction_proactiveness;
- return low ? wmark_low : min(wmark_low + 10, 100U);
+ return low ? wmark_low : min(wmark_low + sysctl_compaction_proactiveness_leeway, 100U);
}
static bool should_proactive_compact_node(pg_data_t *pgdat)
@@ -3314,6 +3315,15 @@ static struct ctl_table vm_compaction[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE_HUNDRED,
},
+ {
+ .procname = "compaction_proactiveness_leeway",
+ .data = &sysctl_compaction_proactiveness_leeway,
+ .maxlen = sizeof(sysctl_compaction_proactiveness_leeway),
+ .mode = 0644,
+ .proc_handler = compaction_proactiveness_sysctl_handler,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = SYSCTL_ONE_HUNDRED,
+ },
{
.procname = "extfrag_threshold",
.data = &sysctl_extfrag_threshold,
--
2.48.1.262.g85cc9f2d1e-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction
2025-01-27 21:50 [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction Michal Clapinski
2025-01-27 21:50 ` [PATCH v3 1/2] mm/compaction: remove low watermark cap for " Michal Clapinski
2025-01-27 21:50 ` [PATCH v3 2/2] mm/compaction: make proactive compaction high watermark configurable via sysctl Michal Clapinski
@ 2025-01-28 1:07 ` Andrew Morton
2025-03-17 1:02 ` Andrew Morton
3 siblings, 0 replies; 9+ messages in thread
From: Andrew Morton @ 2025-01-28 1:07 UTC (permalink / raw)
To: Michal Clapinski; +Cc: Vlastimil Babka, Pasha Tatashin, linux-mm, linux-kernel
On Mon, 27 Jan 2025 22:50:18 +0100 Michal Clapinski <mclapinski@google.com> wrote:
> Our goal is to keep memory usage of a VM low on the host. For that
> reason, we use free page reporting which by default reports free pages
> of order 9 and larger to the host to be freed. The feature works well
> only if the memory in the guest is not fragmented below pages of order
> 9. Proactive compaction can be reused to achieve defragmentation after
> some parameter tweaking.
>
> When the fragmentation score (lower is better) gets larger than the
> high watermark, proactive compaction kicks in. Compaction stops when
> the score goes below the low watermark (or no progress is made and
> backoff kicks in). Let's define the difference between high and low
> watermarks as leeway. Before these changes, the minimum possible value
> for low watermark was 5 and the leeway was hardcoded to 10 (so minimum
> possible value for high watermark was 15).
>
It would be helpful to let us know the benefits of this change for our
users. Some reasonably detailed real-world before-and-after narrative
would suit, please.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/2] mm/compaction: remove low watermark cap for proactive compaction
2025-01-27 21:50 ` [PATCH v3 1/2] mm/compaction: remove low watermark cap for " Michal Clapinski
@ 2025-01-28 1:17 ` Andrew Morton
0 siblings, 0 replies; 9+ messages in thread
From: Andrew Morton @ 2025-01-28 1:17 UTC (permalink / raw)
To: Michal Clapinski; +Cc: Vlastimil Babka, Pasha Tatashin, linux-mm, linux-kernel
On Mon, 27 Jan 2025 22:50:19 +0100 Michal Clapinski <mclapinski@google.com> wrote:
> Previously a min cap of 5 has been set in the commit introducing
> proactive compaction. This was to make sure users don't hurt themselves
> by setting the proactiveness to 100 and making their system
> unresponsive. But the compaction mechanism has a backoff mechanism that
> will sleep for 30s if no progress is made, so I don't see a significant
> risk here. My system (20GB of memory) has been perfectly fine with
> proactiveness set to 100 and leeway set to 0.
Sure. And if setting a particular value makes your system blow up then
Don't Do That - the kernel needn't care too much about protecting the
sysadmin from misguided configurations.
As long as we've actually documented what the thing does, which appears
to be the case this time. Please do review
Documentation/admin-guide/sysctl/vm.rst:compaction_proactiveness for
accuracy and completeness? From what you've said, that final paragraph
sounds too emphatic.
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -2253,7 +2253,7 @@ static unsigned int fragmentation_score_wmark(bool low)
> * activity in case a user sets the proactiveness tunable
> * close to 100 (maximum).
> */
> - wmark_low = max(100U - sysctl_compaction_proactiveness, 5U);
> + wmark_low = 100U - sysctl_compaction_proactiveness;
> return low ? wmark_low : min(wmark_low + 10, 100U);
> }
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] mm/compaction: make proactive compaction high watermark configurable via sysctl
2025-01-27 21:50 ` [PATCH v3 2/2] mm/compaction: make proactive compaction high watermark configurable via sysctl Michal Clapinski
@ 2025-01-28 1:18 ` Andrew Morton
2025-01-30 14:18 ` Vlastimil Babka
0 siblings, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2025-01-28 1:18 UTC (permalink / raw)
To: Michal Clapinski; +Cc: Vlastimil Babka, Pasha Tatashin, linux-mm, linux-kernel
On Mon, 27 Jan 2025 22:50:20 +0100 Michal Clapinski <mclapinski@google.com> wrote:
> Currently, the difference between the high and low watermarks for
> proactive compaction is hardcoded to 10. This hardcoded difference is
> too large for free page reporting to work well.
>
> Add a new sysctl, `compaction_proactiveness_leeway`, to control the
> difference between the high and low watermarks.
>
Oh dear, yet another tunable. Is there any way in which we can
acceptably improve the kernel without adding this?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] mm/compaction: make proactive compaction high watermark configurable via sysctl
2025-01-28 1:18 ` Andrew Morton
@ 2025-01-30 14:18 ` Vlastimil Babka
2025-01-30 18:15 ` Michał Cłapiński
0 siblings, 1 reply; 9+ messages in thread
From: Vlastimil Babka @ 2025-01-30 14:18 UTC (permalink / raw)
To: Andrew Morton, Michal Clapinski; +Cc: Pasha Tatashin, linux-mm, linux-kernel
On 1/28/25 02:18, Andrew Morton wrote:
> On Mon, 27 Jan 2025 22:50:20 +0100 Michal Clapinski <mclapinski@google.com> wrote:
>
>> Currently, the difference between the high and low watermarks for
>> proactive compaction is hardcoded to 10. This hardcoded difference is
>> too large for free page reporting to work well.
>>
>> Add a new sysctl, `compaction_proactiveness_leeway`, to control the
>> difference between the high and low watermarks.
>>
>
> Oh dear, yet another tunable. Is there any way in which we can
> acceptably improve the kernel without adding this?
compaction_proactiveness between 0 and 90 works as usual,
thus up to low watermark of 10 and high watermark of 20
compaction_proactiveness between 90 and 100 additionally reduces leeway,
with value of 100 resulting of low = high = 0
or some similar scheme, as long as a value of 100 does low = high = 0
It's rather arbitrary but AFAIU does what Michal needs and higher
proactiveness means more aggressive compaction.
Question is, would anyone else find it useful to have low_watermark of 0 and
high watermark of 10?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] mm/compaction: make proactive compaction high watermark configurable via sysctl
2025-01-30 14:18 ` Vlastimil Babka
@ 2025-01-30 18:15 ` Michał Cłapiński
0 siblings, 0 replies; 9+ messages in thread
From: Michał Cłapiński @ 2025-01-30 18:15 UTC (permalink / raw)
To: Vlastimil Babka; +Cc: Andrew Morton, Pasha Tatashin, linux-mm, linux-kernel
On Thu, Jan 30, 2025 at 3:18 PM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 1/28/25 02:18, Andrew Morton wrote:
> > On Mon, 27 Jan 2025 22:50:20 +0100 Michal Clapinski <mclapinski@google.com> wrote:
> >
> >> Currently, the difference between the high and low watermarks for
> >> proactive compaction is hardcoded to 10. This hardcoded difference is
> >> too large for free page reporting to work well.
> >>
> >> Add a new sysctl, `compaction_proactiveness_leeway`, to control the
> >> difference between the high and low watermarks.
> >>
> >
> > Oh dear, yet another tunable. Is there any way in which we can
> > acceptably improve the kernel without adding this?
>
> compaction_proactiveness between 0 and 90 works as usual,
> thus up to low watermark of 10 and high watermark of 20
>
> compaction_proactiveness between 90 and 100 additionally reduces leeway,
> with value of 100 resulting of low = high = 0
>
> or some similar scheme, as long as a value of 100 does low = high = 0
Yes, I was thinking about
leeway = min(10, (100 - wmark_low) / 2);
to be able to get small leeway (and therefore more stable memory usage
on the host) without having to opt for very aggressive compaction
goals.
Both of those solutions have the disadvantage of introducing even
bigger changes to the behavior of systems that were already set to
compaction_proactiveness close to 100. Though I'm not sure how common
changing this tunable at all is.
> It's rather arbitrary but AFAIU does what Michal needs and higher
> proactiveness means more aggressive compaction.
>
> Question is, would anyone else find it useful to have low_watermark of 0 and
> high watermark of 10?
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction
2025-01-27 21:50 [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction Michal Clapinski
` (2 preceding siblings ...)
2025-01-28 1:07 ` [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction Andrew Morton
@ 2025-03-17 1:02 ` Andrew Morton
3 siblings, 0 replies; 9+ messages in thread
From: Andrew Morton @ 2025-03-17 1:02 UTC (permalink / raw)
To: Michal Clapinski; +Cc: Vlastimil Babka, Pasha Tatashin, linux-mm, linux-kernel
On Mon, 27 Jan 2025 22:50:18 +0100 Michal Clapinski <mclapinski@google.com> wrote:
> Our goal is to keep memory usage of a VM low on the host. For that
> reason, we use free page reporting which by default reports free pages
> of order 9 and larger to the host to be freed. The feature works well
> only if the memory in the guest is not fragmented below pages of order
> 9. Proactive compaction can be reused to achieve defragmentation after
> some parameter tweaking.
>
> When the fragmentation score (lower is better) gets larger than the
> high watermark, proactive compaction kicks in. Compaction stops when
> the score goes below the low watermark (or no progress is made and
> backoff kicks in). Let's define the difference between high and low
> watermarks as leeway. Before these changes, the minimum possible value
> for low watermark was 5 and the leeway was hardcoded to 10 (so minimum
> possible value for high watermark was 15).
>
I'm not seeing enthusiasm for these changes and a couple of comments
from myself remain unaddressed. I'll drop the series - let's revisit
in the next -rc cycle, if you feel so motivated.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-03-17 1:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-27 21:50 [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction Michal Clapinski
2025-01-27 21:50 ` [PATCH v3 1/2] mm/compaction: remove low watermark cap for " Michal Clapinski
2025-01-28 1:17 ` Andrew Morton
2025-01-27 21:50 ` [PATCH v3 2/2] mm/compaction: make proactive compaction high watermark configurable via sysctl Michal Clapinski
2025-01-28 1:18 ` Andrew Morton
2025-01-30 14:18 ` Vlastimil Babka
2025-01-30 18:15 ` Michał Cłapiński
2025-01-28 1:07 ` [PATCH v3 0/2] mm/compaction: allow more aggressive proactive compaction Andrew Morton
2025-03-17 1:02 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox