mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Frank van der Linden <fvdl@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Ivy Lopez <skunkolee@gmail.com>, Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/cma: simplify cma_declare_contiguous_multi()
Date: Sat, 7 Nov 2026 13:21:24 +0200	[thread overview]
Message-ID: <au8JtLx7T0r9ihPP@kernel.org> (raw)
In-Reply-To: <CAPTztWYzN1mkADOAJ3bskqpsv9c7qXNSMUdj_Ovg-aDQJDDmow@mail.gmail.com>

On Fri, Nov 06, 2026 at 02:30:38PM -0800, Frank van der Linden wrote:
> On Fri, Nov 6, 2026 at 4:56 AM Mike Rapoport (Microsoft)
> <rppt@kernel.org> wrote:
> >
> > When cma_declare_contiguous_multi() cannot allocate a CMA area as a
> > single range, it falls back to collecting a list of up to CMA_MAX_RANGES
> > largest free ranges above 4G, reserves them in memblock and adds them to
> > cma->ranges.
> >
> > Replace the current code with a loop that finds the largest free range
> > above 4G, reserves as much of it as needed and repeats until the entire
> > area is reserved or CMA_MAX_RANGES ranges are used.
> >
> > After successful alocation sort the cma->ranges by their base address.
> >
> > The new code scans free memory once for every range rather than once
> > for all ranges, so it is slightly slower, but it is way simpler and more
> > robust.
> 
> Thanks for cleaning this up. You're right, what I did with the list
> sorting was too much, and it contained some bugs too.
> 
> Just one remark here: I don't think you need to sort the ranges by
> base address at the end, I am not aware of anything relying on the CMA
> ranges being sorted. The sorting was just there to mimic bottom-up
> memblock allocations while acquiring the ranges, but the eventual
> result doesn't need to be sorted. I'm not aware of any CMA code that
> relies on this.

The bottom-up was added by the commit df2ff39e78da7 ("mm: cma: allocate cma
areas bottom-up")

	"... to guarantee that the compaction is moving pages out of the
	cma area and not into it".

I think sorting an array of up to 8 entries is not too costly to keep it
that way.
 
> - Frank
> 

-- 
Sincerely yours,
Mike.

      reply	other threads:[~2026-11-07 11:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 12:56 Mike Rapoport (Microsoft)
2026-11-06 22:30 ` Frank van der Linden
2026-11-07 11:21   ` Mike Rapoport [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=au8JtLx7T0r9ihPP@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=fvdl@google.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=skunkolee@gmail.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®