From: Wei Yang <richard.weiyang@gmail.com>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>,
Michal Hocko <mhocko@suse.com>,
akpm@linux-foundation.org, linux-mm@kvack.org
Subject: Re: [PATCH] mm, sparse: drop pgdat_resize_lock in sparse_add/remove_one_section()
Date: Wed, 28 Nov 2018 08:47:29 +0000 [thread overview]
Message-ID: <20181128084729.jozab2gaej5vh7ig@master> (raw)
In-Reply-To: <20181128010112.5tv7tpe3qeplzy6d@master>
On Wed, Nov 28, 2018 at 01:01:12AM +0000, Wei Yang wrote:
>On Mon, Nov 26, 2018 at 11:17:40PM -0800, Dave Hansen wrote:
>>On 11/26/18 10:25 PM, Michal Hocko wrote:
>>> [Cc Dave who has added the lock into this path. Maybe he remembers why]
>>
>>I don't remember specifically. But, the pattern of:
>>
>> allocate
>> lock
>> set
>> unlock
>>
>>is _usually_ so we don't have two "sets" racing with each other. In
>>this case, that would have been to ensure that two
>>sparse_init_one_section()'s didn't race and leak one of the two
>>allocated memmaps or worse.
>>
>>I think mem_hotplug_lock protects this case these days, though. I don't
>>think we had it in the early days and were just slumming it with the
>>pgdat locks.
>>
>>I really don't like the idea of removing the lock by just saying it
>>doesn't protect anything without doing some homework first, though. It
>>would actually be really nice to comment the entire call chain from the
>>mem_hotplug_lock acquisition to here. There is precious little
>>commenting in there and it could use some love.
>
>Dave,
>
>Thanks for your comment :-)
>
>I should put more words to the reason for removing the lock.
>
>Here is a simplified call trace for sparse_add_one_section() during
>physical add/remove phase.
>
> __add_memory()
> add_memory_resource()
> mem_hotplug_begin()
>
> arch_add_memory()
> add_pages()
> __add_pages()
> __add_section()
> sparse_add_one_section(pfn)
>
> mem_hotplug_done()
>
>When we just look at the sparse section initialization, we can see the
>contention happens when __add_memory() try to add a same range or range
>overlapped in SECTIONS_PER_ROOT number of sections. Otherwise, they
>won't access the same memory.
>
>If this happens, we may face two contentions:
>
> * reallocation of mem_section[root]
> * reallocation of memmap and usemap
>
>While neither of them could be protected by the pgdat_resize_lock from
>my understanding. Grab pgdat_resize_lock just slow down the process,
>while finally they will replace the mem_section[root] and
>ms->section_mem_map with their own new allocated data.
>
Hmm... sorry, I am not correct here.
The pgdat_resize_lock do protect the second case.
But not the first one.
>Last bu not the least, to be honest, even the global mem_hotplug_lock
>doesn't help in this situation. In case __add_memory() try to add the
>same range twice, the sparse section would be initialized twice. Which
>means it will be overwritten with the new allocated memmap/usermap.
>
The mem_section[root] still has a chance to face the contention here.
>But maybe we have the assumption this reentrance will not happen.
>
>This is all what I understand, in case there is some misunderstanding,
>please let me know.
I will rewrite the changelog to emphasize this process is protected by
the global mem_hotplug_lock.
>
>--
>Wei Yang
>Help you, Help me
--
Wei Yang
Help you, Help me
next prev parent reply other threads:[~2018-11-28 8:47 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-27 2:36 Wei Yang
2018-11-27 6:25 ` Michal Hocko
2018-11-27 7:17 ` Dave Hansen
2018-11-27 7:30 ` Michal Hocko
2018-11-27 7:52 ` osalvador
2018-11-27 8:00 ` Michal Hocko
2018-11-27 8:18 ` osalvador
2018-11-28 0:29 ` Wei Yang
2018-11-28 8:19 ` Oscar Salvador
2018-11-28 8:41 ` Wei Yang
2018-11-28 1:01 ` Wei Yang
2018-11-28 8:47 ` Wei Yang [this message]
2018-11-28 9:17 ` Wei Yang
2018-11-28 12:34 ` Michal Hocko
2018-11-28 9:12 ` [PATCH v2] " Wei Yang
2018-11-28 10:28 ` David Hildenbrand
2018-11-29 8:54 ` Michal Hocko
2018-11-29 9:29 ` Wei Yang
2018-11-29 15:53 ` [PATCH v3 1/2] " Wei Yang
2018-11-29 15:53 ` [PATCH v3 2/2] mm, sparse: pass nid instead of pgdat to sparse_add_one_section() Wei Yang
2018-11-29 16:01 ` David Hildenbrand
2018-11-30 1:22 ` Wei Yang
2018-11-30 9:20 ` David Hildenbrand
2018-11-29 17:15 ` Michal Hocko
2018-11-29 23:57 ` Wei Yang
2018-11-29 16:06 ` [PATCH v3 1/2] mm, sparse: drop pgdat_resize_lock in sparse_add/remove_one_section() David Hildenbrand
2018-11-29 17:17 ` Michal Hocko
2018-11-30 4:28 ` Wei Yang
2018-11-30 9:19 ` David Hildenbrand
2018-11-30 9:52 ` Michal Hocko
2018-12-04 8:53 ` Wei Yang
2018-12-01 0:31 ` Wei Yang
2018-12-03 11:25 ` David Hildenbrand
2018-12-03 21:06 ` Wei Yang
2018-11-29 17:14 ` Michal Hocko
2018-12-04 8:56 ` [PATCH v4 " Wei Yang
2018-12-04 8:56 ` [PATCH v4 2/2] mm, sparse: pass nid instead of pgdat to sparse_add_one_section() Wei Yang
2018-12-04 9:24 ` [PATCH v4 1/2] mm, sparse: drop pgdat_resize_lock in sparse_add/remove_one_section() David Hildenbrand
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=20181128084729.jozab2gaej5vh7ig@master \
--to=richard.weiyang@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@intel.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.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