* [PATCH] mm/page_alloc: fix deferred compaction accounting
@ 2026-05-26 9:12 fujunjie
2026-05-28 14:29 ` Vlastimil Babka (SUSE)
0 siblings, 1 reply; 2+ messages in thread
From: fujunjie @ 2026-05-26 9:12 UTC (permalink / raw)
To: Andrew Morton
Cc: Vlastimil Babka, Brendan Jackman, Johannes Weiner, Michal Hocko,
Suren Baghdasaryan, Zi Yan, linux-mm, linux-kernel
COMPACT_DEFERRED means compaction did not start because past failures
caused the zone to be deferred. try_to_compact_pages() returns the
maximum result seen while walking the zonelist, so a final
COMPACT_DEFERRED result means no later zone reported that compaction
actually ran.
__alloc_pages_direct_compact() skips COMPACTSTALL and COMPACTFAIL
accounting when try_to_compact_pages() returns COMPACT_SKIPPED, but not
when it returns COMPACT_DEFERRED. A deferred-only direct compaction
attempt can therefore look like a stall, and then a failure if the
allocation still cannot be satisfied.
Treat COMPACT_DEFERRED like COMPACT_SKIPPED in this accounting path. If
a later zone runs compaction and returns a result above COMPACT_DEFERRED,
or compact_zone_order() reports COMPACT_SUCCESS for a captured page, the
final result is not COMPACT_DEFERRED and the existing accounting still
runs.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
mm/page_alloc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 23c7298d3be2..ddeb79fa12db 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4161,7 +4161,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
psi_memstall_leave(&pflags);
delayacct_compact_end();
- if (*compact_result == COMPACT_SKIPPED)
+ if (*compact_result == COMPACT_SKIPPED ||
+ *compact_result == COMPACT_DEFERRED)
return NULL;
/*
* At least in one zone compaction wasn't deferred or skipped, so let's
base-commit: e8c2f9fdadee7cbc75134dc463c1e0d856d6e5c7
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/page_alloc: fix deferred compaction accounting
2026-05-26 9:12 [PATCH] mm/page_alloc: fix deferred compaction accounting fujunjie
@ 2026-05-28 14:29 ` Vlastimil Babka (SUSE)
0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-05-28 14:29 UTC (permalink / raw)
To: fujunjie, Andrew Morton
Cc: Brendan Jackman, Johannes Weiner, Michal Hocko,
Suren Baghdasaryan, Zi Yan, linux-mm, linux-kernel,
Charan Teja Kalla, David Rientjes
On 5/26/26 11:12, fujunjie wrote:
> COMPACT_DEFERRED means compaction did not start because past failures
> caused the zone to be deferred. try_to_compact_pages() returns the
> maximum result seen while walking the zonelist, so a final
> COMPACT_DEFERRED result means no later zone reported that compaction
> actually ran.
>
> __alloc_pages_direct_compact() skips COMPACTSTALL and COMPACTFAIL
> accounting when try_to_compact_pages() returns COMPACT_SKIPPED, but not
> when it returns COMPACT_DEFERRED. A deferred-only direct compaction
> attempt can therefore look like a stall, and then a failure if the
> allocation still cannot be satisfied.
>
> Treat COMPACT_DEFERRED like COMPACT_SKIPPED in this accounting path. If
> a later zone runs compaction and returns a result above COMPACT_DEFERRED,
> or compact_zone_order() reports COMPACT_SUCCESS for a captured page, the
> final result is not COMPACT_DEFERRED and the existing accounting still
> runs.
>
> Signed-off-by: fujunjie <fujunjie1@qq.com>
Hm I wonder why didn't we do that right away in 06dac2f467fe ("mm:
compaction: update the COMPACT[STALL|FAIL] events properly"), seems like
even back then there was nothing that would e.g. convert _DEFERED to
_SKIPPED from try_to_compact_pages(), and the changelog did mention deferred.
So I guess for posterity we could do (but no Cc: stable, it's just stats).
Fixes: 06dac2f467fe ("mm: compaction: update the COMPACT[STALL|FAIL] events
properly")
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Thanks!
> ---
> mm/page_alloc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 23c7298d3be2..ddeb79fa12db 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -4161,7 +4161,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
> psi_memstall_leave(&pflags);
> delayacct_compact_end();
>
> - if (*compact_result == COMPACT_SKIPPED)
> + if (*compact_result == COMPACT_SKIPPED ||
> + *compact_result == COMPACT_DEFERRED)
> return NULL;
> /*
> * At least in one zone compaction wasn't deferred or skipped, so let's
>
> base-commit: e8c2f9fdadee7cbc75134dc463c1e0d856d6e5c7
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-28 14:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-26 9:12 [PATCH] mm/page_alloc: fix deferred compaction accounting fujunjie
2026-05-28 14:29 ` Vlastimil Babka (SUSE)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®