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=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable 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 B37A1C4338F for ; Wed, 4 Aug 2021 01:40:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3C4ED60F6F for ; Wed, 4 Aug 2021 01:40:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3C4ED60F6F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 78A4F8D0015; Tue, 3 Aug 2021 21:40:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 738728D000F; Tue, 3 Aug 2021 21:40:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FFFD8D0015; Tue, 3 Aug 2021 21:40:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 41F1C8D000F for ; Tue, 3 Aug 2021 21:40:44 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C4354181BECC4 for ; Wed, 4 Aug 2021 01:40:43 +0000 (UTC) X-FDA: 78435693966.38.BA14E9B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 1D6B1802525A for ; Wed, 4 Aug 2021 01:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628041242; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=prEBRZoKY0mhe0m86DgKhDz/qFG3iaSQj/eiWjJyZK8=; b=aOyBhErZohEeqv230fCLLRUOlFio+3HprnRlk1WSsIvNxCuLZLnvqEoZzQf90d0eMBZ6Cx Po0jOCkm/5izENtTFeN5iBr9WK71uI04pLg1zJy0nc87lhU1ax3j2qrQOIpzCv2SoGjC/u d7+JOnXdKuiMmtFF6wi9qePuRYtCZiw= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-518-1cbTyOqmMKq_PL106DoWiA-1; Tue, 03 Aug 2021 21:40:38 -0400 X-MC-Unique: 1cbTyOqmMKq_PL106DoWiA-1 Received: by mail-qk1-f198.google.com with SMTP id s206-20020a3745d70000b02903b9207abc7bso1073409qka.4 for ; Tue, 03 Aug 2021 18:40:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=prEBRZoKY0mhe0m86DgKhDz/qFG3iaSQj/eiWjJyZK8=; b=mDjrNVHNTqDDPPTeqVNsJkLCuSeMwI6W8anpENKKW4lIXZDnyQJ8c0gysVVZpbbLr6 5EvMT6tYwObJDUWISV+hYs1sbqrlbWKrKY00gaQOoivuRNlOgTjQmxCY/ttSAPtxRG67 S+JLv+GUrlWtd/ylPXUVjoMFBFBfYlsVsS6RZ6KjcTsNtpJ2HXpqtaeaN3xulF0R7F9+ VoeOa12IhLuW/I7vR+tGwRwKQbp1OErCsRhusQKjSgQQlI4+ZEoArBBGID+SKo42OmUi 2bdGbthT21aktkPM4lBTffwOArjfOYtOHkXe+nqW0pXNvL3vWI2GQ3coU/6734lxZG9K nZZg== X-Gm-Message-State: AOAM533k4vVmTNjYu9dCNrrfEHr/eQ1mRMSMp5NLt42nFORWyicrYE5M RTx/yh3JqF92U1dAtLPBBjsuCn+d0d3WYnXgd1EQNoKEhGZPEPLpDE2nXCXStLoMcbjKhs6xNg8 KOhtiUJLNVkI= X-Received: by 2002:a05:6214:3a4:: with SMTP id m4mr24172393qvy.17.1628041238103; Tue, 03 Aug 2021 18:40:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8EWOBC1RHCyAbVwynmIEQicD29HOr33gfx2qHwud9l8mmYV9gdbAOwj5Mm31YWDE03ccxrg== X-Received: by 2002:a05:6214:3a4:: with SMTP id m4mr24172377qvy.17.1628041237922; Tue, 03 Aug 2021 18:40:37 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id b1sm306006qtq.12.2021.08.03.18.40.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Aug 2021 18:40:37 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH] mm/memcg: Disable task obj_stock for PREEMPT_RT To: Thomas Gleixner , 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 , Sebastian Andrzej Siewior , Daniel Bristot de Oliveira , Linus Torvalds References: <20210803175519.22298-1-longman@redhat.com> <87h7g62jxm.ffs@tglx> Message-ID: <8953e099-356e-ee09-a701-f4c7f4cda487@redhat.com> Date: Tue, 3 Aug 2021 21:40:35 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <87h7g62jxm.ffs@tglx> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1D6B1802525A Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aOyBhErZ; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf06.hostedemail.com: domain of llong@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=llong@redhat.com X-Stat-Signature: dj961a4hqt6fuujum8pn6by41fichbgp X-HE-Tag: 1628041242-152432 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: 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