linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: David Hildenbrand <david@redhat.com>
Cc: Wei Yang <richard.weiyang@gmail.com>,
	rppt@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Subject: Re: [PATCH] mm/mm_init.c: simplify logic of deferred_[init|free]_pages
Date: Thu, 13 Jun 2024 11:32:42 +0000	[thread overview]
Message-ID: <20240613113242.x2kenzoxjalk7j56@master> (raw)
In-Reply-To: <d5d75ca9-e5be-45a4-9ce8-1c46885c099b@redhat.com>

On Thu, Jun 13, 2024 at 10:21:08AM +0200, David Hildenbrand wrote:
>On 12.06.24 04:04, Wei Yang wrote:
>> Function deferred_[init|free]_pages are only used in
>> deferred_init_maxorder(), which makes sure the range to init/free is
>> within MAX_ORDER_NR_PAGES size.
>> 
>> With this knowledge, we can simplify these two functions. Since
>> 
>>    * only the first pfn could be IS_MAX_ORDER_ALIGNED()
>> 
>> Also since the range passed to deferred_[init|free]_pages is always from
>> memblock.memory for those we have already allocated memmap to cover,
>> pfn_valid() always return true. Then we can remove related check.
>> 
>
>I'm surprised that we can completely get rid if the pfn_valid checks (which
>is great!), trusting Mike's review that this is all sane :)
>

I'm surprised too :-)

>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> CC: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>> CC: Mike Rapoport (IBM) <rppt@kernel.org>
>> CC: David Hildenbrand <david@redhat.com>
>> ---
>
>[...]
>
>>   /*
>>    * Initialize struct pages.  We minimize pfn page lookups and scheduler checks
>>    * by performing it only once every MAX_ORDER_NR_PAGES.
>>    * Return number of pages initialized.
>>    */
>> -static unsigned long  __init deferred_init_pages(struct zone *zone,
>> -						 unsigned long pfn,
>> -						 unsigned long end_pfn)
>> +static unsigned long __init deferred_init_pages(struct zone *zone,
>> +						unsigned long pfn,
>> +						unsigned long end_pfn)
>
>We nowadays prefer double tabs for indentation for the second+ parameter line
>in MM, like
>
>static unsigned long __init deferred_init_pages(struct zone *zone,
>		unsigned long pfn, unsigned long end_pfn)
>
>Usually results in less churn when renaming functions ... and reduces the
>LOC.
>

Will adjust it.

>
>>   {
>>   	int nid = zone_to_nid(zone);
>> -	unsigned long nr_pages = 0;
>> +	unsigned long nr_pages = end_pfn - pfn;
>>   	int zid = zone_idx(zone);
>> -	struct page *page = NULL;
>> +	struct page *page = pfn_to_page(pfn);
>> -	for (; pfn < end_pfn; pfn++) {
>> -		if (!deferred_pfn_valid(pfn)) {
>> -			page = NULL;
>> -			continue;
>> -		} else if (!page || IS_MAX_ORDER_ALIGNED(pfn)) {
>> -			page = pfn_to_page(pfn);
>> -		} else {
>> -			page++;
>> -		}
>> +	for (; pfn < end_pfn; pfn++, page++)
>>   		__init_single_page(page, pfn, zid, nid);
>> -		nr_pages++;
>> -	}
>>   	return nr_pages;
>>   }
>> @@ -2096,7 +2049,7 @@ deferred_init_maxorder(u64 *i, struct zone *zone, unsigned long *start_pfn,
>>   			break;
>>   		t = min(mo_pfn, epfn);
>> -		deferred_free_pages(spfn, t);
>> +		deferred_free_pages(spfn, t - spfn);
>>   		if (mo_pfn <= epfn)
>>   			break;
>
>Looks like a really nice cleanup!
>

Glad you like it :-)

>-- 
>Cheers,
>
>David / dhildenb

-- 
Wei Yang
Help you, Help me


      parent reply	other threads:[~2024-06-13 11:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-12  2:04 Wei Yang
2024-06-13  6:07 ` Mike Rapoport
     [not found] ` <d5d75ca9-e5be-45a4-9ce8-1c46885c099b@redhat.com>
2024-06-13 11:32   ` Wei Yang [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=20240613113242.x2kenzoxjalk7j56@master \
    --to=richard.weiyang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-mm@kvack.org \
    --cc=rppt@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