All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Add ACR_FLAGS_LAZY and use it in cma_range_alloc()
@ 2026-12-02 15:13 Daniel Scally
  2026-12-02 15:13 ` [PATCH 1/2] mm: page_alloc: Add a "lazy" flag for __alloc_contig_migrate_range() Daniel Scally
  2026-12-02 15:13 ` [PATCH 2/2] mm: cma: Pass ACR_FLAGS_LAZY to alloc_contig_frozen_range() Daniel Scally
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Scally @ 2026-12-02 15:13 UTC (permalink / raw)
  To: Vlastimil Babka, Johannes Weiner, Suren Baghdasaryan,
	Michal Hocko, Brendan Jackman, Zi Yan, David Hildenbrand,
	Liam R. Howlett, Mike Rapoport, Andrew Morton
  Cc: linux-mm, hughd, kieran.bingham, Daniel Scally

Hello all

I feel I should mention at the top that I think that this change is
ok and that it fixes a problem that we've been having, but I won't
pretend any expertise (or even experience) in mm/ so there may be
potential downsides for the change that I have not appreciated.

I'm working with an i.MX8MP board which has a dewarper device to
who's driver userspace queues memory buffers ultimately allocated
by the kernel calling cma_range_alloc(), which itself calls
alloc_contig_frozen_range() for different page ranges until it
manages to allocate the space it needs (or fails).

We're finding that the call to lru_cache_disable() within
__alloc_contig_migrate_range() comes with a severe performance hit on
a PREEMPT_RT kernel, and so we'd like to avoid it. This proposal adds
a new "lazy" flag, which __alloc_contig_migrate_range() will treat as
an instruction to skip the lru_cache_disable() call.

My understanding is that the impact of this would be that an
allocation that could have succeeded if pages within the LRU cache
had been flushed and migrated out of the region, will now fail with
-EBUSY. In an attempt to get the best of both worlds cma_range_alloc()
is changed to run its loop once with the new flag in the hopes of a
quick successful allocation, but if that fails to run again without
the flag. The impact should be that:

1. A successful allocation that did not need to migrate any pages
   that are in the LRU cache is faster.
2. A successful allocation that DID need to migrate a page that is in
   the LRU cache is slower.
3. A failure to allocate would be slower.

We did also come across Hugh's series [2] which removes the
lru_cache_disable() and lru_cache_enable() calls (and so fixes the
slowness we experience), but the changes are much more extensive, so
we preferred investigating a standalone mechanism to avoid the slow
path, and I think it would still be worth merging if it's correct,
even if Hugh's series will probably replace it when that is merged.

Thanks
Dan

[1] https://www.kernel.org/doc/html/v4.9/media/uapi/v4l/vidioc-reqbufs.html
[2] https://lore.kernel.org/lkml/e28f9a94-4339-f8ac-8301-6be3c9b5b7ce@google.com/

Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
Daniel Scally (2):
      mm: page_alloc: Add a "lazy" flag for __alloc_contig_migrate_range()
      mm: cma: Pass ACR_FLAGS_LAZY to alloc_contig_frozen_range()

 include/linux/gfp.h |  1 +
 mm/cma.c            | 24 ++++++++++++++++++++----
 mm/page_alloc.c     | 12 ++++++++----
 3 files changed, 29 insertions(+), 8 deletions(-)
---
base-commit: 1a7610248a3802e38124ce66b07eef12277be9a0
change-id: 20261202-lazy-cma-allocation-05dabbb8e9ff

Best regards,
-- 
Daniel Scally <dan.scally@ideasonboard.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-03 15:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 15:13 [PATCH 0/2] Add ACR_FLAGS_LAZY and use it in cma_range_alloc() Daniel Scally
2026-12-02 15:13 ` [PATCH 1/2] mm: page_alloc: Add a "lazy" flag for __alloc_contig_migrate_range() Daniel Scally
2026-12-02 15:13 ` [PATCH 2/2] mm: cma: Pass ACR_FLAGS_LAZY to alloc_contig_frozen_range() Daniel Scally
2026-12-03 15:14   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.