From: Matthew Wilcox <willy@infradead.org>
To: Tong Tiangen <tongtiangen@huawei.com>
Cc: Naoya Horiguchi <naoya.horiguchi@linux.dev>,
"Paul E. McKenney" <paulmck@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Naoya Horiguchi <naoya.horiguchi@nec.com>,
Miaohe Lin <linmiaohe@huawei.com>,
wangkefeng.wang@huawei.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mm: memory-failure: use rcu lock instead of tasklist_lock when collect_procs()
Date: Sat, 26 Aug 2023 21:28:12 +0100 [thread overview]
Message-ID: <ZOpgXCAAz7PAxT7b@casper.infradead.org> (raw)
In-Reply-To: <9e205429-1f27-4d18-faca-8a4fe9d429e3@huawei.com>
On Sat, Aug 26, 2023 at 09:46:53AM +0800, Tong Tiangen wrote:
> " the ``task_struct`` object is freed only after one or more
> grace periods elapse, with the help of call_rcu(), which is invoked via
> put_task_struct_rcu_user(). "
>
> Combined with the code,when the task exits:
>
> release_task()
> __exit_signal()
> __unhash_process()
> list_del_rcu(&p->tasks)
>
> put_task_struct_rcu_user()
> call_rcu(&task->rcu, delayed_put_task_struct);
>
> delayed_put_task_struct()
> put_task_struct()
> if (refcount_sub_and_test(nr, &t->usage))
> __put_task_struct()
> free_task()
>
> The code is consistent with the description in the document.
>
> According to this understanding, i think for_each_process() under the
> protection of rcu locl is safe, that is, task_struct in the list will not be
> destroyed, and get_task_struct() is also safe.
Aha! This is different from the usual pattern. What I'm used to seeing
is:
if (refcount_sub_and_test()) {
list_del_rcu();
rcu_free();
}
and then on the read side you need a refcount_inc_not_zero(), which we
didn't have here. Given this new information you've found, I withdraw
my objection. It'd be nice to include some of this analysis in an
updated changelog (and maybe improved documentation for tasklist?).
next prev parent reply other threads:[~2023-08-26 20:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-21 9:13 Tong Tiangen
2023-08-21 18:33 ` Matthew Wilcox
2023-08-22 3:41 ` Tong Tiangen
2023-08-22 12:08 ` Matthew Wilcox
2023-08-25 6:02 ` Naoya Horiguchi
2023-08-26 1:46 ` Tong Tiangen
2023-08-26 20:28 ` Matthew Wilcox [this message]
2023-08-28 2:36 ` Tong Tiangen
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=ZOpgXCAAz7PAxT7b@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=naoya.horiguchi@linux.dev \
--cc=naoya.horiguchi@nec.com \
--cc=paulmck@kernel.org \
--cc=tongtiangen@huawei.com \
--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