From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AFD6C432BE for ; Tue, 3 Aug 2021 23:22:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9C0A560F93 for ; Tue, 3 Aug 2021 23:22:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9C0A560F93 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linutronix.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C6A676B0083; Tue, 3 Aug 2021 19:22:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF4176B0085; Tue, 3 Aug 2021 19:22:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A95206B0087; Tue, 3 Aug 2021 19:22:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 8B3896B0083 for ; Tue, 3 Aug 2021 19:22:01 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1FA50231AA for ; Tue, 3 Aug 2021 23:22:01 +0000 (UTC) X-FDA: 78435344442.25.73FB0B6 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 8AD645030BEA for ; Tue, 3 Aug 2021 23:22:00 +0000 (UTC) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628032918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3sppHzO4nBHPNEurHXyRq4J2sD5L0/H0qJdAyUdF9AE=; b=OlCy9rBC6qHUV5lBzNzwO1zPZHPcdt/yuNv8KWZWSkX9IMEIHqv+Hqr4GtF9SS/T2hZY2K gRY92Lt3kL5GM04i6itLfA9ABSgbFKwZV+UcIBoS/r6q4t5oeLbFr6/B5xk7x/JdThhzMr AqXcsvc+wJVObdT3YIERe+xExSko/aROavBF6owO2eTsorS1LL4SAwpzkOFhatR7WeK4Tc liTjOwZ9BfwlKtjRFtTL+UujCKGeEW2bx9To1qAr4ohVgdyaEBfCWDxqcxRePdZjiHl4jF qzVjPEnxdnPlX/p0doCUUxATrDU9axWUlfkD3epp/mqV5UEhrf2Kib34gk5/Eg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628032918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3sppHzO4nBHPNEurHXyRq4J2sD5L0/H0qJdAyUdF9AE=; b=F0gwUPlbBiVah6TihUcuwDEdd9xE5yjQzfsNoszSmqtS4PVc3AMwNgtD1olZ7vk6z7hq2Y DI82mdchpqgvkTBw== To: Waiman Long , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Vlastimil Babka , Roman Gushchin Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Muchun Song , Luis Goncalves , Waiman Long ,Sebastian Andrzej Siewior ,Daniel Bristot de Oliveira , Linus Torvalds Subject: Re: [PATCH] mm/memcg: Disable task obj_stock for PREEMPT_RT In-Reply-To: <20210803175519.22298-1-longman@redhat.com> References: <20210803175519.22298-1-longman@redhat.com> Date: Wed, 04 Aug 2021 01:21:57 +0200 Message-ID: <87h7g62jxm.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=OlCy9rBC; dkim=pass header.d=linutronix.de header.s=2020e header.b=F0gwUPlb; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf05.hostedemail.com: domain of tglx@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=tglx@linutronix.de X-Stat-Signature: 9arkmqwxzykx34fpbmrdz95k3esxdfqw X-Rspamd-Queue-Id: 8AD645030BEA X-Rspamd-Server: rspam01 X-HE-Tag: 1628032920-900387 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > These two variants of local_lock() are essentially > the same. Only on RT kernels. > + * 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. > */ > +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: > @@ -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); /* * 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. 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. 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 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. Thanks, tglx