linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Frank van der Linden <fvdl@google.com>
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: Wed, 24 Jul 2024 12:48:45 -0700	[thread overview]
Message-ID: <20240724124845.614c03ad39f8af3729cebee6@linux-foundation.org> (raw)
In-Reply-To: <20240709163053.2514760-1-fvdl@google.com>

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?

> -	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?

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



  parent reply	other threads:[~2024-07-24 19:49 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 [this message]
2024-07-25 16:18   ` Frank van der Linden

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=20240724124845.614c03ad39f8af3729cebee6@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=fvdl@google.com \
    --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