linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: carver4lio@163.com
To: Mike Rapoport <rppt@kernel.org>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,
	Hailong Liu <liu.hailong6@zte.com.cn>
Subject: Re: [PATCH] mm/memblock:use a more appropriate order calculation when free memblock pages
Date: Sun, 6 Dec 2020 22:21:04 +0800	[thread overview]
Message-ID: <adfe7852-b390-b8c1-cd9f-36de00e5d882@163.com> (raw)
In-Reply-To: <20201206115517.GL751215@kernel.org>

On 12/6/20 7:55 PM, Mike Rapoport wrote:
> On Thu, Dec 03, 2020 at 11:23:10PM +0800, carver4lio@163.com wrote:
>> From: Hailong Liu <liu.hailong6@zte.com.cn>
>>
>> When system in the booting stage, pages span from [start, end] of a memblock
>> are freed to buddy in a order as large as possible (less than MAX_ORDER) at
>> first, then decrease gradually to a proper order(less than end) in a loop.
>>
>> However, *min(MAX_ORDER - 1UL, __ffs(start))* can not get the largest order
>> in some cases.
> 
> Do you have examples?
> What is the memory configration that casues suboptimal order selection
> and what is the order in this case?
> 
I'm sorry for my careless and inadequate testing(I just test it on my x86
machine with 8 cores).

On my x86_64 machine, the layout of RAM looks like:
/ # cat /proc/iomem
00000100-00000fff : reserved
00001000-0009c7ff : System RAM
0009c800-0009ffff : reserved
.....
100000000-22dffffff : System RAM
  22c600000-22d0e01c0 : Kernel code
  22d0e01c1-22d96af3f : Kernel data
  22dae5000-22dbdcfff : Kernel bss
22e000000-22fffffff : RAM buffer

On my machine, I noticed that when the order of an start pfn in is less than
MAX_ORDER, e.g: the start phy_addr 0x00001000, then the return value *order*
of *min(MAX_ORDER - 1UL, __ffs(start))* will be 1, but the free pages span
of the memblock is more than order 1, it's should be (end - start), I guess.

I tested my ideas with some record code like this:
diff --git a/mm/memblock.c b/mm/memblock.c
index b68ee86788af..b0143e3f75db 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1928,18 +1928,23 @@ early_param("memblock", early_memblock);

 static void __init __free_pages_memory(unsigned long start, unsigned long end)
 {
-       int order;
+       int order, loop_cnt, adjust_cnt;
+

        while (start < end) {
                order = min(MAX_ORDER - 1UL, __ffs(start));

-               while (start + (1UL << order) > end)
+               while (start + (1UL << order) > end) {
                        order--;
-
+                       adjust_cnt++;
+               }
                memblock_free_pages(pfn_to_page(start), start, order);

                start += (1UL << order);
+               loop_cnt++;
        }
+       pr_info("TST:[start %lu, end %lu]: loop cnt %d, adjust cnt %d\n",
+               loop_cnt++, adjust_cnt++);
 }

If I change __ffs(start) to __ffs(end - start), the print info show less
loop_cnt and adjust_cnt  on my machine.
 
>> Instead, *__ffs(end - start)* may be more appropriate and meaningful.
> 
> As several people reported using __ffs(end - start) is not correct.
> If the order selection is indeed suboptimal we'd need some better
> formula ;-)
> 
>> Signed-off-by: Hailong Liu <liu.hailong6@zte.com.cn>
>> ---
>>  mm/memblock.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/memblock.c b/mm/memblock.c
>> index b68ee8678..7c6d0dde7 100644
>> --- a/mm/memblock.c
>> +++ b/mm/memblock.c
>> @@ -1931,7 +1931,7 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
>>  	int order;
>>  
>>  	while (start < end) {
>> -		order = min(MAX_ORDER - 1UL, __ffs(start));
>> +		order = min(MAX_ORDER - 1UL, __ffs(end - start));
>>  
>>  		while (start + (1UL << order) > end)
>>  			order--;
>> -- 
>> 2.17.1
>>
>>
> 




      reply	other threads:[~2020-12-06 14:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 15:23 [PATCH] mm/memblock:use a more appropriate order calculation when free memblock pages carver4lio
2020-12-04 13:42 ` Qian Cai
     [not found]   ` <CGME20201204160751eucas1p13cc7aad8c68dd2a495c4bbf422c4228c@eucas1p1.samsung.com>
2020-12-04 16:07     ` Marek Szyprowski
2020-12-04 17:43       ` Jon Hunter
2020-12-05 17:09         ` Anders Roxell
2020-12-05 17:12           ` Anders Roxell
2020-12-06 11:55 ` Mike Rapoport
2020-12-06 14:21   ` carver4lio [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=adfe7852-b390-b8c1-cd9f-36de00e5d882@163.com \
    --to=carver4lio@163.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liu.hailong6@zte.com.cn \
    --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;
as well as URLs for NNTP newsgroup(s).