From: David Hildenbrand <david@redhat.com>
To: Kefeng Wang <wangkefeng.wang@huawei.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org
Cc: muchun.song@linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] mm: slince possible data races about pgdat->kswapd
Date: Thu, 25 Aug 2022 10:22:19 +0200 [thread overview]
Message-ID: <76d906e8-4c2b-0832-dc43-5fb49b5c6cc5@redhat.com> (raw)
In-Reply-To: <fe06a35b-229f-c143-0200-33dbb315f0fe@huawei.com>
On 25.08.22 04:34, Kefeng Wang wrote:
>
> On 2022/8/24 16:24, David Hildenbrand wrote:
>> On 24.08.22 09:19, Kefeng Wang wrote:
>>> The pgdat->kswapd could be accessed concurrently by kswapd_run() and
>>> kcompactd(), it don't be protected by any lock, which could leads to
>>> data races, adding READ/WRITE_ONCE() to slince it.
>> Okay, I think this patch here makes it clearer that we really just want
>> proper synchronization instead of hacking around it.
>>
>> What speaks against protecting pgdat->kswapd this using some proper
>> locking primitive?
>
> as comments about kswapd in struct pglist_data, pgdat->kswapd should be
>
> protected by mem_hotplug_begin/done(), how about this way?
>
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 640fa76228dd..62018f35242a 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -1983,7 +1983,13 @@ static inline bool is_via_compact_memory(int order)
>
> static bool kswapd_is_running(pg_data_t *pgdat)
> {
> - return pgdat->kswapd && task_is_running(pgdat->kswapd);
> + bool running;
> +
> + mem_hotplug_begin();
> + running = pgdat->kswapd && task_is_running(pgdat->kswapd);
> + mem_hotplug_end();
> +
> + return running;
> }
I'd much rather just use a dedicated lock that does not involve memory
hotplug.
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2022-08-25 8:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-24 7:19 [PATCH 1/2] mm: fix null-ptr-deref in kswapd_is_running() Kefeng Wang
2022-08-24 7:19 ` [PATCH 2/2] mm: slince possible data races about pgdat->kswapd Kefeng Wang
2022-08-24 8:24 ` David Hildenbrand
2022-08-24 9:51 ` Kefeng Wang
2022-08-25 2:34 ` Kefeng Wang
2022-08-25 8:22 ` David Hildenbrand [this message]
2022-08-25 9:48 ` Kefeng Wang
2022-08-24 7:56 ` [PATCH 1/2] mm: fix null-ptr-deref in kswapd_is_running() 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=76d906e8-4c2b-0832-dc43-5fb49b5c6cc5@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=wangkefeng.wang@huawei.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