From: Wei Yang <richard.weiyang@gmail.com>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>,
akpm@linux-foundation.org, mhocko@suse.com, rientjes@google.com,
linux-mm@kvack.org, kirill.shutemov@linux.intel.com
Subject: Re: [PATCH 1/3] mm/sparse: add likely to mem_section[root] check in sparse_index_init()
Date: Sun, 9 Sep 2018 01:38:07 +0000 [thread overview]
Message-ID: <20180909013807.6ux4cidt3nehofz5@master> (raw)
In-Reply-To: <20180903222732.v52zdya2c2hkff7n@master>
On Mon, Sep 03, 2018 at 10:27:32PM +0000, Wei Yang wrote:
>On Fri, Aug 24, 2018 at 11:07:17PM +0800, Wei Yang wrote:
>>On Thu, Aug 23, 2018 at 05:11:48PM -0700, Dave Hansen wrote:
>>>On 08/23/2018 06:07 AM, Wei Yang wrote:
>>>> --- a/mm/sparse.c
>>>> +++ b/mm/sparse.c
>>>> @@ -78,7 +78,7 @@ static int __meminit sparse_index_init(unsigned long section_nr, int nid)
>>>> unsigned long root = SECTION_NR_TO_ROOT(section_nr);
>>>> struct mem_section *section;
>>>>
>>>> - if (mem_section[root])
>>>> + if (likely(mem_section[root]))
>>>> return -EEXIST;
>>>
>>>We could add likely()/unlikely() to approximately a billion if()s around
>>>the kernel if we felt like it. We don't because it's messy and it
>>>actually takes away choices from the compiler.
>>>
>>>Please don't send patches like this unless you have some *actual*
>>>analysis that shows the benefit of the patch. Performance numbers are best.
>>
>
>Hi,
>
>Is my analysis reasonable? Or which part is not valid?
>
Would someone share some idea on my analysis?
>>Thanks all for your comments, Michal, Dave and Oscar.
>>
>>Well, maybe I took it for granted, so let me put more words on this. To be
>>honest, my analysis maybe partially effective, so if the cost is higher than
>>the gain, please let me know.
>>
>>Below is my analysis and test result for this patch.
>>------------------------------------------------------
>>
>>During bootup, the call flow looks like this.
>>
>> sparse_memory_present_with_active_regions()
>> memory_present()
>> sparse_index_init()
>>
>>sparse_memory_present_with_active_regions() iterates on pfn continuously for
>>the whole system RAM, which leads to sparse_index_init() will iterate
>>section_nr continuously. Usually, we don't expect many large holes, right?
>>
>>Each time when mem_section[root] is null, SECTIONS_PER_ROOT number of
>>mem_section will be allocated. This means, for SECTIONS_PER_ROOT number of
>>check, only the first check is false. So the possibility to be false is
>>(1 / SECTIONS_PER_ROOT).
>>
>>SECTIONS_PER_ROOT is defined as (PAGE_SIZE / sizeof (struct mem_section)).
>>
>>On my x86_64 machine, PAGE_SIZE is 4KB and mem_section is 16B.
>>
>> SECTIONS_PER_ROOT = 4K / 16 = 256.
>>
>>So the check for mem_section[root] is (1 / 256) chance to be invalid and
>>(255 / 256) valid. In theory, this value seems to be a "likely" to me.
>>
>>In practice, when the system RAM is multiple times of
>>((1 << SECTION_SIZE_BITS) * SECTIONS_PER_ROOT), the "likely" chance is
>>(255 / 256), otherwise the chance would be less.
>>
>>On my x86_64 machine, SECTION_SIZE_BITS is defined to 27.
>>
>> ((1 << SECTION_SIZE_BITS) * SECTIONS_PER_ROOT) = 32GB
>>
>> System RAM size 32G 16G 8G 4G
>> Possibility (255 / 256) (127 / 128) (63 / 64) (31 / 32)
>>
>>Generally, in my mind, if we iterate pfn continuously and there is no large
>>holes, the check on mem_section[root] is likely to be true.
>>
>>At last, here is the test result on my 4G virtual machine. I added printk
>>before and after sparse_memory_present_with_active_regions() and tested three
>>times with/without "likely".
>>
>> without with
>> Elapsed 0.000252 0.000250 -0.8%
>>
>>The benefit seems to be too small on a 4G virtual machine or even this is not
>>stable. Not sure we can see some visible effect on a 32G machine.
>>
>>
>>Well, above is all my analysis and test result. I did the optimization based
>>on my own experience and understanding. If this is not qualified, I am very
>>glad to hear from your statement, so that I would learn more from your
>>experience.
>>
>>Thanks all for your comments again :-)
>>
>>
>>--
>>Wei Yang
>>Help you, Help me
>
>--
>Wei Yang
>Help you, Help me
--
Wei Yang
Help you, Help me
next prev parent reply other threads:[~2018-09-09 1:38 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-23 13:07 [PATCH 0/3] trivial code refine for sparsemem Wei Yang
2018-08-23 13:07 ` [PATCH 1/3] mm/sparse: add likely to mem_section[root] check in sparse_index_init() Wei Yang
2018-08-23 13:13 ` Michal Hocko
2018-08-23 22:57 ` Wei Yang
2018-08-24 7:31 ` Michal Hocko
2018-08-24 0:11 ` Dave Hansen
2018-08-24 15:07 ` Wei Yang
2018-09-03 22:27 ` Wei Yang
2018-09-09 1:38 ` Wei Yang [this message]
2018-09-10 20:30 ` Dave Hansen
2018-09-11 15:00 ` Wei Yang
2018-08-23 13:07 ` [PATCH 2/3] mm/sparse: expand the CONFIG_SPARSEMEM_EXTREME range in __nr_to_section() Wei Yang
2018-08-23 13:21 ` Michal Hocko
2018-08-23 23:03 ` Wei Yang
2018-08-24 0:09 ` Dave Hansen
2018-08-24 15:24 ` Wei Yang
2018-08-23 13:07 ` [PATCH 3/3] mm/sparse: use __highest_present_section_nr as the boundary for pfn check Wei Yang
2018-08-23 13:25 ` Michal Hocko
2018-08-23 14:00 ` Oscar Salvador
2018-08-23 19:17 ` Michal Hocko
2018-08-23 20:52 ` Oscar Salvador
2018-08-24 0:15 ` Dave Hansen
2018-08-24 18:11 ` Wei Yang
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=20180909013807.6ux4cidt3nehofz5@master \
--to=richard.weiyang@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@intel.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=rientjes@google.com \
/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