From: Miklos Szeredi <miklos@szeredi.hu>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Miklos Szeredi <mszeredi@redhat.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] dcache: fix quadratic behavior with parallel shrinkers
Date: Thu, 3 May 2018 09:44:34 +0200 [thread overview]
Message-ID: <CAJfpegvMYGt-Mo2LmZVXHDd1KhxqS+iWNKfO7xCUhA1ZcG7KyQ@mail.gmail.com> (raw)
In-Reply-To: <20180502224533.GW30522@ZenIV.linux.org.uk>
On Thu, May 3, 2018 at 12:45 AM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Thu, May 03, 2018 at 12:26:35AM +0200, Miklos Szeredi wrote:
>> When multiple shrinkers are operating on a directory containing many
>> dentries, it takes much longer than if only one shrinker is operating on
>> the directory.
>>
>> Call the shrinker instances A and B, which shrink DIR containing NUM
>> dentries.
>>
>> Assume A wins the race for locking DIR's d_lock, then it goes onto moving
>> all unlinked dentries to its dispose list. When it's done, then B will
>> scan the directory once again, but will find that all dentries are already
>> being shrunk, so it will have an empty dispose list. Both A and B will
>> have found NUM dentries (data.found == NUM).
>>
>> Now comes the interesting part: A will proceed to shrink the dispose list
>> by killing individual dentries and decrementing the refcount of the parent
>> (which is DIR). NB: decrementing DIR's refcount will block if DIR's d_lock
>> is held. B will shrink a zero size list and then immediately restart
>> scanning the directory, where it will lock DIR's d_lock, scan the remaining
>> dentries and find no dentry to dispose.
>>
>> So that results in B doing the directory scan over and over again, holding
>> d_lock of DIR, while A is waiting for a chance to decrement refcount of DIR
>> and making very slow progress because of this. B is wasting time and
>> holding up progress of A at the same time.
>>
>> Proposed fix is to check this situation in B (found some dentries, but
>> all are being shrunk already) and just sleep for some time, before retrying
>> the scan. The sleep is proportional to the number of found dentries.
>
> The thing is, the majority of massive shrink_dcache_parent() can be killed.
> Let's do that first and see if anything else is really needed.
>
> As it is, rmdir() and rename() are ridiculously bad - they should only call
> shrink_dcache_parent() after successful ->rmdir() or ->rename(). Sure,
> there are other places where we do large shrink_dcache_parent() runs,
> but those won't trigger in parallel on the same tree.
I think we are cat hit this also with lru pruner (prune_dcache_sb(),
shrink_dcache_sb()) running in parallel with shrink_dcache_parent().
Although shrink_dcache_sb() looks better in this regard, since it will
only hold up to 1024 dentries in the dispose list.
I'm open to a better solution, but keep in mind that it will also need
backporting.
Thanks,
Miklos
next prev parent reply other threads:[~2018-05-03 7:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 22:26 [PATCH] dcache: fix quadratic behavior with parallel shrinkers Miklos Szeredi
2018-05-02 22:45 ` Al Viro
2018-05-03 7:44 ` Miklos Szeredi [this message]
2018-05-03 8:18 ` Miklos Szeredi
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=CAJfpegvMYGt-Mo2LmZVXHDd1KhxqS+iWNKfO7xCUhA1ZcG7KyQ@mail.gmail.com \
--to=miklos@szeredi.hu \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mszeredi@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/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).