linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Frank van der Linden <fvdl@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/cma: export total and free number of pages for CMA areas
Date: Thu, 25 Jul 2024 09:18:33 -0700	[thread overview]
Message-ID: <CAPTztWaCFYgQo1Bk6w-f_2=aYBbYfXeLy_WPw3XRJ+a3RDwnzg@mail.gmail.com> (raw)
In-Reply-To: <20240724124845.614c03ad39f8af3729cebee6@linux-foundation.org>

On Wed, Jul 24, 2024 at 12:49 PM Andrew Morton
<akpm@linux-foundation.org> wrote:
>
> On Tue,  9 Jul 2024 16:30:53 +0000 Frank van der Linden <fvdl@google.com> wrote:
>
> > In addition to the number of allocations and releases, system
> > management software may like to be aware of the size of CMA
> > areas, and how many pages are available in it. This information
> > is currently not available, so export it in total_page and
> > available_pages, respectively.
> >
> > The name 'available_pages' was picked over 'free_pages' because
> > 'free' implies that the pages are unused. But they might not
> > be, they just haven't been used by cma_alloc
> >
> > The number of available pages is tracked regardless of
> > CONFIG_CMA_SYSFS, allowing for a few minor shortcuts in
> > the code, avoiding bitmap operations.
> >
> > ...
> >
> > @@ -382,7 +383,7 @@ static void cma_debug_show_areas(struct cma *cma)
> >  {
> >       unsigned long next_zero_bit, next_set_bit, nr_zero;
> >       unsigned long start = 0;
> > -     unsigned long nr_part, nr_total = 0;
> > +     unsigned long nr_part;
> >       unsigned long nbits = cma_bitmap_maxno(cma);
> >
> >       spin_lock_irq(&cma->lock);
> > @@ -394,12 +395,12 @@ static void cma_debug_show_areas(struct cma *cma)
> >               next_set_bit = find_next_bit(cma->bitmap, nbits, next_zero_bit);
> >               nr_zero = next_set_bit - next_zero_bit;
> >               nr_part = nr_zero << cma->order_per_bit;
> > -             pr_cont("%s%lu@%lu", nr_total ? "+" : "", nr_part,
> > +             pr_cont("%s%lu@%lu", start ? "+" : "", nr_part,
> >                       next_zero_bit);
> > -             nr_total += nr_part;
> >               start = next_zero_bit + nr_zero;
> >       }
>
> Can you please explain the above change?

Sure - there's no need anymore to keep a count of available pages for
the debug output, since that's already tracked in the available_count
field. So, 'nr_total' can be removed. But you still need to check for
this being the first instance of the loop, so use 'start' for that
instead.
>
> > -     pr_cont("=> %lu free of %lu total pages\n", nr_total, cma->count);
> > +     pr_cont("=> %lu free of %lu total pages\n", cma->available_count,
> > +                     cma->count);
> >       spin_unlock_irq(&cma->lock);
> >  }
> >
> > @@ -446,6 +447,10 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
> >
> >       for (;;) {
> >               spin_lock_irq(&cma->lock);
> > +             if (count > cma->available_count) {
>
> Right here would be a nice place for a comment?
>
Yes, I'll add one.

> > +                     spin_unlock_irq(&cma->lock);
> > +                     break;
> > +             }
> >               bitmap_no = bitmap_find_next_zero_area_off(cma->bitmap,
> >                               bitmap_maxno, start, bitmap_count, mask,
> >                               offset);
>

I'll re-send a v2 with some Cc: lines added.

Thanks!

- Frank


      reply	other threads:[~2024-07-25 16:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-09 16:30 Frank van der Linden
2024-07-22 16:24 ` Frank van der Linden
2024-07-24 19:50   ` Andrew Morton
2024-07-24 19:48 ` Andrew Morton
2024-07-25 16:18   ` Frank van der Linden [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='CAPTztWaCFYgQo1Bk6w-f_2=aYBbYfXeLy_WPw3XRJ+a3RDwnzg@mail.gmail.com' \
    --to=fvdl@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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