From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
Andrew Morton <akpm@linux-foundation.org>,
kasan-dev <kasan-dev@googlegroups.com>,
Greg Thelen <gthelen@google.com>
Subject: Re: [PATCH] kasan: fix races in quarantine_remove_cache()
Date: Thu, 9 Mar 2017 14:09:24 +0300 [thread overview]
Message-ID: <6b83d94d-3b73-4ba5-d8f0-16e19786a88c@virtuozzo.com> (raw)
In-Reply-To: <CACT4Y+aZLKnmUw-R-SEzCaYbBnrYx--g8q_yW8Z+Qk=CQcQqFQ@mail.gmail.com>
On 03/09/2017 01:43 PM, Dmitry Vyukov wrote:
> On Thu, Mar 9, 2017 at 11:29 AM, Andrey Ryabinin
> <aryabinin@virtuozzo.com> wrote:
>> On 03/09/2017 12:37 PM, Dmitry Vyukov wrote:
>>>>> void quarantine_reduce(void)
>>>>> {
>>>>> size_t total_size, new_quarantine_size, percpu_quarantines;
>>>>> unsigned long flags;
>>>>> + int srcu_idx;
>>>>> struct qlist_head to_free = QLIST_INIT;
>>>>>
>>>>> if (likely(READ_ONCE(quarantine_size) <=
>>>>> READ_ONCE(quarantine_max_size)))
>>>>> return;
>>>>>
>>>>> + /*
>>>>> + * srcu critical section ensures that quarantine_remove_cache()
>>>>> + * will not miss objects belonging to the cache while they are in our
>>>>> + * local to_free list. srcu is chosen because (1) it gives us private
>>>>> + * grace period domain that does not interfere with anything else,
>>>>> + * and (2) it allows synchronize_srcu() to return without waiting
>>>>> + * if there are no pending read critical sections (which is the
>>>>> + * expected case).
>>>>> + */
>>>>> + srcu_idx = srcu_read_lock(&remove_cache_srcu);
>>>>
>>>> I'm puzzled why is SRCU, why not RCU? Given that we take spin_lock in the next line
>>>> we certainly don't need ability to sleep in read-side critical section.
>>>
>>> I've explained it in the comment above.
>>
>> I've read it. It doesn't explain to me why is SRCU is better than RCU here.
>> a) We can't sleep in read-side critical section. Given that RCU is almost always
>> faster than SRCU, RCU seem preferable.
>> b) synchronize_rcu() indeed might take longer to complete. But does it matter?
>> We to synchronize_[s]rcu() only on cache destruction which relatively rare operation and
>> it's not a hotpath. Performance of the quarantine_reduce() is more important
>
>
> As far as I understand container destruction will cause destruction of
> a bunch of caches. synchronize_sched() caused serious problems on
> these paths in the past, see 86d9f48534e800e4d62cdc1b5aaf539f4c1d47d6.
> srcu_read_lock/unlock are not too expensive, that's some atomic
> operations on per-cpu variables, so cheaper than the existing
> spinlock. And this is already not the fast-fast-path (which is
> kmalloc/free). But hundreds of synchronize_rcu in a row can cause
> hangup and panic. The fact that it's a rare operation won't help. Also
> if we free a substantial batch of objects under rcu lock, it will
> affect latency of all rcu callbacks in kernel which can have undesired
> effects.
> I am trying to make this more predictable and tolerant to unexpected
> workloads, rather than sacrifice everything in the name of fast path
> performance.
>
Ok, fair enough.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2017-03-09 11:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 15:15 Dmitry Vyukov
2017-03-08 23:11 ` Andrew Morton
2017-03-09 8:52 ` Dmitry Vyukov
2017-03-09 9:25 ` Andrey Ryabinin
2017-03-09 9:37 ` Dmitry Vyukov
2017-03-09 10:29 ` Andrey Ryabinin
2017-03-09 10:43 ` Dmitry Vyukov
2017-03-09 11:09 ` Andrey Ryabinin [this message]
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=6b83d94d-3b73-4ba5-d8f0-16e19786a88c@virtuozzo.com \
--to=aryabinin@virtuozzo.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=gthelen@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-mm@kvack.org \
/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