From: Waiman Long <llong@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Vladimir Davydov <vdavydov.dev@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@suse.cz>, Roman Gushchin <guro@fb.com>
Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
linux-mm@kvack.org, Shakeel Butt <shakeelb@google.com>,
Muchun Song <songmuchun@bytedance.com>,
Luis Goncalves <lgoncalv@redhat.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] mm/memcg: Disable task obj_stock for PREEMPT_RT
Date: Tue, 3 Aug 2021 21:40:35 -0400 [thread overview]
Message-ID: <8953e099-356e-ee09-a701-f4c7f4cda487@redhat.com> (raw)
In-Reply-To: <87h7g62jxm.ffs@tglx>
On 8/3/21 7:21 PM, Thomas Gleixner wrote:
> Waiman,
>
> On Tue, Aug 03 2021 at 13:55, Waiman Long wrote:
>
> please Cc RT people on RT related patches.
>
>> For PREEMPT_RT kernel, preempt_disable() and local_irq_save()
>> are typically converted to local_lock() and local_lock_irqsave()
>> respectively.
> That's just wrong. local_lock has a clear value even on !RT kernels. See
>
> https://www.kernel.org/doc/html/latest/locking/locktypes.html#local-lock
>
I understand what local_lock is for. For !RT kernel, local_lock() still
requires the use of a pseudo_lock which is not the goal of this patch to
put one there.
>> These two variants of local_lock() are essentially
>> the same.
> Only on RT kernels.
That is right. So this is a change aimed for easier integration with RT
kernel.
>
>> + * For PREEMPT_RT kernel, preempt_disable() and local_irq_save() may have
>> + * to be changed to variants of local_lock(). This eliminates the
>> + * performance advantage of using preempt_disable(). Fall back to always
>> + * use local_irq_save() and use only irq_obj for simplicity.
> Instead of adding that comment you could have just done the full
> conversion, but see below.
Well, I can do that if you want me to.
>
>> */
>> +static inline bool use_task_obj_stock(void)
>> +{
>> + return !IS_ENABLED(CONFIG_PREEMPT_RT) && likely(in_task());
>> +}
>> +
>> static inline struct obj_stock *get_obj_stock(unsigned long *pflags)
>> {
>> struct memcg_stock_pcp *stock;
>>
>> - if (likely(in_task())) {
>> + if (use_task_obj_stock()) {
>> *pflags = 0UL;
>> preempt_disable();
>> stock = this_cpu_ptr(&memcg_stock);
> This is clearly the kind of conditional locking which is frowned upon
> rightfully.
>
> So if we go to reenable memcg for RT we end up with:
>
> if (use_task_obj_stock()) {
> preempt_disable();
> } else {
> local_lock_irqsave(memcg_stock_lock, flags);
> }
>
> and further down we end up with:
The purpose of this series is to improve kmem_cache allocation and free
performance for non-RT kernel. So not disabling/enabling interrupt help
a bit in this regard.
>
>> @@ -2212,7 +2222,7 @@ static void drain_local_stock(struct work_struct *dummy)
>>
>> stock = this_cpu_ptr(&memcg_stock);
>> drain_obj_stock(&stock->irq_obj);
>> - if (in_task())
>> + if (use_task_obj_stock())
>> drain_obj_stock(&stock->task_obj);
>> drain_stock(stock);
>> clear_bit(FLUSHING_CACHED_CHARGE, &stock->flags);
>> Thanks,
>>
>> tglx
>>
>
> /*
> * The only protection from memory hotplug vs. drain_stock races is
> * that we always operate on local CPU stock here with IRQ disabled
> */
> - local_irq_save(flags);
> + local_lock_irqsave(memcg_stock_lock, flags);
> ...
> if (use_task_obj_stock())
> drain_obj_stock(&stock->task_obj);
>
> which is incomprehensible garbage.
>
> The comment above the existing local_irq_save() is garbage w/o any local
> lock conversion already today (and even before the commit which
> introduced stock::task_obj) simply because that comment does not explain
> the why.
That comment was added by commit 72f0184c8a00 ("mm, memcg: remove
hotplug locking from try_charge"). It was there before my commits.
>
> I can just assume that for stock->task_obj the IRQ protection is
> completely irrelevant. If not and _all_ members of stock have to be
> protected against memory hotplug by disabling interrupts then any other
> function which just disables preemption is broken.
That is correct specifically for task_obj, but not for other data.
>
> To complete the analysis of drain_local_stock(). AFAICT that function
> can only be called from task context. So what is the purpose of this
> in_task() conditional there?
>
> if (in_task())
> drain_obj_stock(&stock->task_obj);
I haven't done a full analysis to see if it can be called from task
context only. Maybe in_task() check isn't needed, but having it there
provides the safety that it will still work in case it can be called
from interrupt context.
>
> I assume it's mechanical conversion of:
>
> - drain_obj_stock(stock);
> + drain_obj_stock(&stock->irq_obj);
> + if (in_task())
> + drain_obj_stock(&stock->task_obj);
>
> all over the place without actually looking at the surrounding code,
> comments and call sites.
>
> This patch is certainly in line with that approach, but it's just adding
> more confusion.
What is your suggestion for improving this patch?
Cheers,
Longman
next prev parent reply other threads:[~2021-08-04 1:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-03 17:55 [PATCH] mm/memcg: Disable task obj_stock for PREEMPT_RT Waiman Long
2021-08-03 23:21 ` Thomas Gleixner
2021-08-04 1:40 ` Waiman Long [this message]
2021-08-04 8:52 ` Michal Hocko
2021-08-04 16:00 ` Waiman Long
2021-08-04 7:39 ` Vlastimil Babka
2021-08-04 8:33 ` Michal Hocko
2021-08-09 9:07 ` Michal Hocko
2021-08-09 9:28 ` Vlastimil Babka
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=8953e099-356e-ee09-a701-f4c7f4cda487@redhat.com \
--to=llong@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bigeasy@linutronix.de \
--cc=bristot@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=lgoncalv@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=shakeelb@google.com \
--cc=songmuchun@bytedance.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
--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).