* [PATCH v2] perf/aux: Avoid reclaim for optional higher-order allocations
@ 2026-11-25 11:54 Leo Yan
2026-11-25 12:03 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Leo Yan @ 2026-11-25 11:54 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Will Deacon, Yabin Cui,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, Tamas Petz, Tamas Zsoldos, Michiel van Tol, Dev Jain
Cc: linux-perf-users, linux-kernel, Leo Yan
PERF_AUX_GFP includes GFP_KERNEL, which contains __GFP_RECLAIM. On
fragmented systems, costly AUX allocations can wake kswapd. When perf
falls back to lower orders, the allocating task can stall in direct
reclaim or compaction. Yabin Cui reported that the resulting memory
pressure can trigger Android's lmkd to kill applications.
For PMUs that support scatter-gather, higher-order AUX allocations are
optional. Clear __GFP_RECLAIM and set __GFP_NOMEMALLOC for these
attempts. Perf can then use contiguous pages when available and fall
back to smaller orders without reclaiming memory or drawing on emergency
reserves for the larger allocation.
The comparison is based on Yabin's result from an Android Pixel, a
production phone with 4 KiB pages, 12 GiB of RAM and 6 GiB of zram.
v7.4-rc3-sim
Android baseline kernel with the v7.4-rc3 perf AUX and page
allocator paths, including commit 526d945ad9c0 ("Revert "perf/aux:
Allocate non-contiguous AUX pages by default"") and
commit 0e05a469c294 ("mm/page_alloc: avoid direct reclaim and
compaction for costly __GFP_NORETRY allocations").
rc3 + [1]-noretry
The same baseline with this patch's GFP flag changes applied only
to optional higher-order AUX allocations.
The test allocated 4 MiB AUX buffer per CPU while running Dev Jain's
compact-bench [1] at 90%, 95% and 99% memory pressure. Both kernels
completed ten runs at each level without an AUX buffer allocation
failure. Across the 30 runs per kernel, system-wide memory stall time
(PSI some) fell by 97.7%.
Totals over 30 runs v7.4-rc3-sim rc3 + [1]-noretry
Memory PSI some (ms) 1,840.29 41.78
compact_stall 522 0
allocstall 161 0
compact_daemon_wake 14 0
sp_kswapd_wk 21 1
In a separate test with realistic Android memory fragmentation, lmkd
killed an application during TRBE testing on the baseline kernel, and
SPE allocations stalled in direct compaction and reclaim. Neither issue
was observed with this patch applied. When memory was unfragmented,
the patched kernel allocated AUX buffer chunks at order 9 (2 MiB).
[1] https://lore.kernel.org/all/d2b8edf0-39ab-4a44-bd0d-58230dee2fad@arm.com/
Reported-by: Yabin Cui <yabinc@google.com>
Link: https://lore.kernel.org/lkml/CALJ9ZPO9XxF-kz5K67Jg8RtpiEmK7XFU3e+xDak6LyV_We7yBQ@mail.gmail.com/
Suggested-by: Yabin Cui <yabinc@google.com>
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
Changes in v2:
- Dropped __GFP_RETRY_MAYFAIL and kept __GFP_NORETRY, as no allocation
failures were observed in Android testing. (Dev/Yabin)
- Updated the commit log based on Yabin's test results to reflect the
benefits on Android. (Yabin)
- Link to v1: https://lore.kernel.org/r/20261109-perf_aux_alloc_optimize_psi-v1-1-d56ac4bf3ef5@arm.com
---
kernel/events/ring_buffer.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 95f4fbdfd2764de5b72d901d778c46302f525fad..317a0454be8b26d60a14a5790a15625868836257 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -619,7 +619,7 @@ long perf_output_copy_aux(struct perf_output_handle *aux_handle,
#define PERF_AUX_GFP (GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY)
-static struct page *rb_alloc_aux_page(int node, int order)
+static struct page *rb_alloc_aux_page(int node, int order, bool no_sg)
{
struct page *page;
@@ -627,7 +627,16 @@ static struct page *rb_alloc_aux_page(int node, int order)
order = MAX_PAGE_ORDER;
do {
- page = alloc_pages_node(node, PERF_AUX_GFP, order);
+ gfp_t gfp = PERF_AUX_GFP;
+
+ /*
+ * Don't reclaim or use emergency reserves for optional
+ * higher-order allocations.
+ */
+ if (order && !no_sg)
+ gfp = (gfp | __GFP_NOMEMALLOC) & ~__GFP_RECLAIM;
+
+ page = alloc_pages_node(node, gfp, order);
} while (!page && order--);
if (page && order) {
@@ -683,6 +692,7 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
pgoff_t pgoff, int nr_pages, long watermark, int flags)
{
bool overwrite = !(flags & RING_BUFFER_WRITABLE);
+ bool no_sg = event->pmu->capabilities & PERF_PMU_CAP_AUX_NO_SG;
int node = (event->cpu == -1) ? -1 : cpu_to_node(event->cpu);
int ret = -ENOMEM, max_order;
@@ -733,7 +743,7 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
int last, order;
order = min(max_order, ilog2(nr_pages - rb->aux_nr_pages));
- page = rb_alloc_aux_page(node, order);
+ page = rb_alloc_aux_page(node, order, no_sg);
if (!page)
goto out;
@@ -748,8 +758,7 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
* buffering. In this case, the entire buffer has to be one contiguous
* chunk.
*/
- if ((event->pmu->capabilities & PERF_PMU_CAP_AUX_NO_SG) &&
- overwrite) {
+ if (no_sg && overwrite) {
struct page *page = virt_to_page(rb->aux_pages[0]);
if (page_private(page) != max_order)
---
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
change-id: 20261109-perf_aux_alloc_optimize_psi-c2f8ce2e9a0c
Best regards,
--
Leo Yan <leo.yan@arm.com>
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] perf/aux: Avoid reclaim for optional higher-order allocations
2026-11-25 11:54 [PATCH v2] perf/aux: Avoid reclaim for optional higher-order allocations Leo Yan
@ 2026-11-25 12:03 ` sashiko-bot
2026-11-25 18:13 ` Yabin Cui
2026-11-26 5:38 ` Dev Jain
2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-25 12:03 UTC (permalink / raw)
To: Leo Yan; +Cc: linux-perf-users
> PERF_AUX_GFP includes GFP_KERNEL, which contains __GFP_RECLAIM. On
> fragmented systems, costly AUX allocations can wake kswapd. When perf
> falls back to lower orders, the allocating task can stall in direct
> reclaim or compaction. Yabin Cui reported that the resulting memory
> pressure can trigger Android's lmkd to kill applications.
>
> For PMUs that support scatter-gather, higher-order AUX allocations are
> optional. Clear __GFP_RECLAIM and set __GFP_NOMEMALLOC for these
> attempts. Perf can then use contiguous pages when available and fall
> back to smaller orders without reclaiming memory or drawing on emergency
> reserves for the larger allocation.
>
> The comparison is based on Yabin's result from an Android Pixel, a
> production phone with 4 KiB pages, 12 GiB of RAM and 6 GiB of zram.
>
> [ ... ]
>
> Reported-by: Yabin Cui <yabinc@google.com>
> Link: https://lore.kernel.org/lkml/CALJ9ZPO9XxF-kz5K67Jg8RtpiEmK7XFU3e+xDak6LyV_We7yBQ@mail.gmail.com/
> Suggested-by: Yabin Cui <yabinc@google.com>
> Signed-off-by: Leo Yan <leo.yan@arm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-perf_aux_alloc_optimize_psi-v2-1-b2ac7ed12849@arm.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] perf/aux: Avoid reclaim for optional higher-order allocations
2026-11-25 11:54 [PATCH v2] perf/aux: Avoid reclaim for optional higher-order allocations Leo Yan
2026-11-25 12:03 ` sashiko-bot
@ 2026-11-25 18:13 ` Yabin Cui
2026-11-26 5:38 ` Dev Jain
2 siblings, 0 replies; 5+ messages in thread
From: Yabin Cui @ 2026-11-25 18:13 UTC (permalink / raw)
To: Leo Yan
Cc: Peter Zijlstra, Ingo Molnar, Will Deacon,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, Tamas Petz, Tamas Zsoldos, Michiel van Tol, Dev Jain,
linux-perf-users, linux-kernel
On Wed, 25 Nov 2026 11:54:53 +0000, Leo Yan <leo.yan@arm.com> wrote:
> PERF_AUX_GFP includes GFP_KERNEL, which contains __GFP_RECLAIM. On
> fragmented systems, costly AUX allocations can wake kswapd. When perf
> falls back to lower orders, the allocating task can stall in direct
> reclaim or compaction. Yabin Cui reported that the resulting memory
> pressure can trigger Android's lmkd to kill applications.
>
> [ ... ]
>
> Reported-by: Yabin Cui <yabinc@google.com>
> Link: https://lore.kernel.org/lkml/CALJ9ZPO9XxF-kz5K67Jg8RtpiEmK7XFU3e+xDak6LyV_We7yBQ@mail.gmail.com/
> Suggested-by: Yabin Cui <yabinc@google.com>
> Signed-off-by: Leo Yan <leo.yan@arm.com>
Thanks for updating v2, Leo!
Tested-by: Yabin Cui <yabinc@google.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] perf/aux: Avoid reclaim for optional higher-order allocations
2026-11-25 11:54 [PATCH v2] perf/aux: Avoid reclaim for optional higher-order allocations Leo Yan
2026-11-25 12:03 ` sashiko-bot
2026-11-25 18:13 ` Yabin Cui
@ 2026-11-26 5:38 ` Dev Jain
2026-11-26 9:20 ` Leo Yan
2 siblings, 1 reply; 5+ messages in thread
From: Dev Jain @ 2026-11-26 5:38 UTC (permalink / raw)
To: Leo Yan, Peter Zijlstra, Ingo Molnar, Will Deacon, Yabin Cui,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, Tamas Petz, Tamas Zsoldos, Michiel van Tol
Cc: linux-perf-users, linux-kernel
On 25/11/26 5:24 pm, Leo Yan wrote:
> PERF_AUX_GFP includes GFP_KERNEL, which contains __GFP_RECLAIM. On
> fragmented systems, costly AUX allocations can wake kswapd. When perf
> falls back to lower orders, the allocating task can stall in direct
> reclaim or compaction. Yabin Cui reported that the resulting memory
When perf falls back to lower orders, how can the allocating task stall
in direct reclaim? It stalls when it is performing the high order allocation.
So let us write this as:
"On fragmented systems, costly AUX allocations can wake kswapd/kcompactd,
or worse, they can stall in direct reclaim/compaction."
Reviewed-by: Dev Jain <dev.jain@arm.com>
> pressure can trigger Android's lmkd to kill applications.
>
> For PMUs that support scatter-gather, higher-order AUX allocations are
> optional. Clear __GFP_RECLAIM and set __GFP_NOMEMALLOC for these
> attempts. Perf can then use contiguous pages when available and fall
> back to smaller orders without reclaiming memory or drawing on emergency
> reserves for the larger allocation.
>
> The comparison is based on Yabin's result from an Android Pixel, a
> production phone with 4 KiB pages, 12 GiB of RAM and 6 GiB of zram.
>
> v7.4-rc3-sim
> Android baseline kernel with the v7.4-rc3 perf AUX and page
> allocator paths, including commit 526d945ad9c0 ("Revert "perf/aux:
> Allocate non-contiguous AUX pages by default"") and
> commit 0e05a469c294 ("mm/page_alloc: avoid direct reclaim and
> compaction for costly __GFP_NORETRY allocations").
>
> rc3 + [1]-noretry
> The same baseline with this patch's GFP flag changes applied only
> to optional higher-order AUX allocations.
>
> The test allocated 4 MiB AUX buffer per CPU while running Dev Jain's
> compact-bench [1] at 90%, 95% and 99% memory pressure. Both kernels
> completed ten runs at each level without an AUX buffer allocation
> failure. Across the 30 runs per kernel, system-wide memory stall time
> (PSI some) fell by 97.7%.
>
> Totals over 30 runs v7.4-rc3-sim rc3 + [1]-noretry
> Memory PSI some (ms) 1,840.29 41.78
> compact_stall 522 0
> allocstall 161 0
> compact_daemon_wake 14 0
> sp_kswapd_wk 21 1
>
> In a separate test with realistic Android memory fragmentation, lmkd
> killed an application during TRBE testing on the baseline kernel, and
> SPE allocations stalled in direct compaction and reclaim. Neither issue
> was observed with this patch applied. When memory was unfragmented,
> the patched kernel allocated AUX buffer chunks at order 9 (2 MiB).
>
> [1] https://lore.kernel.org/all/d2b8edf0-39ab-4a44-bd0d-58230dee2fad@arm.com/
>
> Reported-by: Yabin Cui <yabinc@google.com>
> Link: https://lore.kernel.org/lkml/CALJ9ZPO9XxF-kz5K67Jg8RtpiEmK7XFU3e+xDak6LyV_We7yBQ@mail.gmail.com/
> Suggested-by: Yabin Cui <yabinc@google.com>
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
> Changes in v2:
> - Dropped __GFP_RETRY_MAYFAIL and kept __GFP_NORETRY, as no allocation
> failures were observed in Android testing. (Dev/Yabin)
> - Updated the commit log based on Yabin's test results to reflect the
> benefits on Android. (Yabin)
> - Link to v1: https://lore.kernel.org/r/20261109-perf_aux_alloc_optimize_psi-v1-1-d56ac4bf3ef5@arm.com
> ---
> kernel/events/ring_buffer.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
> index 95f4fbdfd2764de5b72d901d778c46302f525fad..317a0454be8b26d60a14a5790a15625868836257 100644
> --- a/kernel/events/ring_buffer.c
> +++ b/kernel/events/ring_buffer.c
> @@ -619,7 +619,7 @@ long perf_output_copy_aux(struct perf_output_handle *aux_handle,
>
> #define PERF_AUX_GFP (GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY)
>
> -static struct page *rb_alloc_aux_page(int node, int order)
> +static struct page *rb_alloc_aux_page(int node, int order, bool no_sg)
> {
> struct page *page;
>
> @@ -627,7 +627,16 @@ static struct page *rb_alloc_aux_page(int node, int order)
> order = MAX_PAGE_ORDER;
>
> do {
> - page = alloc_pages_node(node, PERF_AUX_GFP, order);
> + gfp_t gfp = PERF_AUX_GFP;
> +
> + /*
> + * Don't reclaim or use emergency reserves for optional
> + * higher-order allocations.
> + */
> + if (order && !no_sg)
> + gfp = (gfp | __GFP_NOMEMALLOC) & ~__GFP_RECLAIM;
> +
> + page = alloc_pages_node(node, gfp, order);
> } while (!page && order--);
>
> if (page && order) {
> @@ -683,6 +692,7 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
> pgoff_t pgoff, int nr_pages, long watermark, int flags)
> {
> bool overwrite = !(flags & RING_BUFFER_WRITABLE);
> + bool no_sg = event->pmu->capabilities & PERF_PMU_CAP_AUX_NO_SG;
> int node = (event->cpu == -1) ? -1 : cpu_to_node(event->cpu);
> int ret = -ENOMEM, max_order;
>
> @@ -733,7 +743,7 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
> int last, order;
>
> order = min(max_order, ilog2(nr_pages - rb->aux_nr_pages));
> - page = rb_alloc_aux_page(node, order);
> + page = rb_alloc_aux_page(node, order, no_sg);
> if (!page)
> goto out;
>
> @@ -748,8 +758,7 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
> * buffering. In this case, the entire buffer has to be one contiguous
> * chunk.
> */
> - if ((event->pmu->capabilities & PERF_PMU_CAP_AUX_NO_SG) &&
> - overwrite) {
> + if (no_sg && overwrite) {
> struct page *page = virt_to_page(rb->aux_pages[0]);
>
> if (page_private(page) != max_order)
>
> ---
> base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
> change-id: 20261109-perf_aux_alloc_optimize_psi-c2f8ce2e9a0c
>
> Best regards,
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] perf/aux: Avoid reclaim for optional higher-order allocations
2026-11-26 5:38 ` Dev Jain
@ 2026-11-26 9:20 ` Leo Yan
0 siblings, 0 replies; 5+ messages in thread
From: Leo Yan @ 2026-11-26 9:20 UTC (permalink / raw)
To: Dev Jain
Cc: Peter Zijlstra, Ingo Molnar, Will Deacon, Yabin Cui,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, Tamas Petz, Tamas Zsoldos, Michiel van Tol,
linux-perf-users, linux-kernel
On Thu, Nov 26, 2026 at 11:08:10AM +0530, Dev Jain wrote:
>
>
> On 25/11/26 5:24 pm, Leo Yan wrote:
> > PERF_AUX_GFP includes GFP_KERNEL, which contains __GFP_RECLAIM. On
> > fragmented systems, costly AUX allocations can wake kswapd. When perf
> > falls back to lower orders, the allocating task can stall in direct
> > reclaim or compaction. Yabin Cui reported that the resulting memory
>
> When perf falls back to lower orders, how can the allocating task stall
> in direct reclaim? It stalls when it is performing the high order allocation.
>
> So let us write this as:
>
> "On fragmented systems, costly AUX allocations can wake kswapd/kcompactd,
> or worse, they can stall in direct reclaim/compaction."
Will do.
> Reviewed-by: Dev Jain <dev.jain@arm.com>
Thanks for review, Dev and Yabin!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-26 9:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 11:54 [PATCH v2] perf/aux: Avoid reclaim for optional higher-order allocations Leo Yan
2026-11-25 12:03 ` sashiko-bot
2026-11-25 18:13 ` Yabin Cui
2026-11-26 5:38 ` Dev Jain
2026-11-26 9:20 ` Leo Yan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox