From: Waiman Long <longman@redhat.com>
To: Qian Cai <cai@lca.pw>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Vladimir Davydov <vdavydov.dev@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, Juri Lelli <juri.lelli@redhat.com>
Subject: Re: [PATCH v2 3/4] mm/slub: Fix another circular locking dependency in slab_attr_store()
Date: Mon, 18 May 2020 18:05:00 -0400 [thread overview]
Message-ID: <638f59c0-60f1-2279-fea6-28b2980720f4@redhat.com> (raw)
In-Reply-To: <F1FA6654-C07C-42FD-B497-61EB635B264C@lca.pw>
On 5/16/20 10:19 PM, Qian Cai wrote:
>
>> On Apr 27, 2020, at 7:56 PM, Waiman Long <longman@redhat.com> wrote:
>>
>> It turns out that switching from slab_mutex to memcg_cache_ids_sem in
>> slab_attr_store() does not completely eliminate circular locking dependency
>> as shown by the following lockdep splat when the system is shut down:
>>
>> [ 2095.079697] Chain exists of:
>> [ 2095.079697] kn->count#278 --> memcg_cache_ids_sem --> slab_mutex
>> [ 2095.079697]
>> [ 2095.090278] Possible unsafe locking scenario:
>> [ 2095.090278]
>> [ 2095.096227] CPU0 CPU1
>> [ 2095.100779] ---- ----
>> [ 2095.105331] lock(slab_mutex);
>> [ 2095.108486] lock(memcg_cache_ids_sem);
>> [ 2095.114961] lock(slab_mutex);
>> [ 2095.120649] lock(kn->count#278);
>> [ 2095.124068]
>> [ 2095.124068] *** DEADLOCK ***
> Can you show the full splat?
>
>> To eliminate this possibility, we have to use trylock to acquire
>> memcg_cache_ids_sem. Unlikely slab_mutex which can be acquired in
>> many places, the memcg_cache_ids_sem write lock is only acquired
>> in memcg_alloc_cache_id() to double the size of memcg_nr_cache_ids.
>> So the chance of successive calls to memcg_alloc_cache_id() within
>> a short time is pretty low. As a result, we can retry the read lock
>> acquisition a few times if the first attempt fails.
>>
>> Signed-off-by: Waiman Long <longman@redhat.com>
> The code looks a bit hacky and probably not that robust. Since it is the shutdown path which is not all that important without lockdep, maybe you could drop this single patch for now until there is a better solution?
That is true. Unlike using the slab_mutex, the chance of failing to
acquire a read lock on memcg_cache_ids_sem is pretty low. Maybe just
print_once a warning if that happen.
Thanks,
Longman
next prev parent reply other threads:[~2020-05-18 22:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-27 23:56 [PATCH v2 0/4] mm/slub: Fix sysfs circular locking dependency Waiman Long
2020-04-27 23:56 ` [PATCH v2 1/4] mm, slab: Revert "extend slab/shrink to shrink all memcg caches" Waiman Long
2020-04-27 23:56 ` [PATCH v2 2/4] mm/slub: Fix slab_mutex circular locking problem in slab_attr_store() Waiman Long
2020-04-27 23:56 ` [PATCH v2 3/4] mm/slub: Fix another circular locking dependency " Waiman Long
[not found] ` <F1FA6654-C07C-42FD-B497-61EB635B264C@lca.pw>
2020-05-18 22:05 ` Waiman Long [this message]
2020-04-27 23:56 ` [PATCH v2 4/4] mm/slub: Fix sysfs shrink circular locking dependency Waiman Long
2020-04-28 0:13 ` Qian Cai
2020-04-28 1:39 ` Waiman Long
2020-04-28 2:11 ` Qian Cai
2020-04-28 14:06 ` Waiman Long
2020-04-29 2:52 ` Qian Cai
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=638f59c0-60f1-2279-fea6-28b2980720f4@redhat.com \
--to=longman@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=cai@lca.pw \
--cc=cgroups@vger.kernel.org \
--cc=cl@linux.com \
--cc=hannes@cmpxchg.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=vdavydov.dev@gmail.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;
as well as URLs for NNTP newsgroup(s).