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=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 CA67EC4338F for ; Wed, 4 Aug 2021 01:40:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA4F960F58 for ; Wed, 4 Aug 2021 01:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233335AbhHDBkx (ORCPT ); Tue, 3 Aug 2021 21:40:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60186 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbhHDBkw (ORCPT ); Tue, 3 Aug 2021 21:40:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628041239; 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=AeGb706gsOlnqpA0U6aFrZxBFoVossX+31dgBxHLzYFamSRzwlO+hpZngv5dSN+EbSjzFe Pw0M03Zs+Ihvk34/txxBq4raI0TEIv+tpwPkjcKC9DHnRJ3VC3Zg3M7YUakbHRoQAFU4zU /K85QhFBnFU5HlIws9mwLiGpEc0NlWM= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-518-Sp5vX1L7PPO3LesPARcp3g-1; Tue, 03 Aug 2021 21:40:38 -0400 X-MC-Unique: Sp5vX1L7PPO3LesPARcp3g-1 Received: by mail-qt1-f198.google.com with SMTP id y12-20020ac8524c0000b029028acd693c6bso476961qtn.20 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=XB4mYiPCapTr9I3/i0w39MV0+2tA+5zYGoiDIp8I1SExV8YMnj0OmTIWzAPJhO37DN SKyX4mf58btnAipovx3PKHGXkXgqtKya8MFzR2EcJ1XJ5BQuls85DeQPEomN27TjkhhS wy9gNdkaaZH+zhk7MjgZJAQJh2NHJwlxloO245mzfVe3U/uB+lx9V1VGSC05fj5TnCHK 0dM8TqNUeOwlchBFa0VqZoHsw67GvGNcijRaeMiAI7LvETZPwGEwm8US5lrJ/daPVUkW KHHIEJiQc7V5drdnaGeaidnc//NgEPxeaMPN1N32x6mtBh1Q8189zFpPxbdP1nZxG3lE BvbQ== X-Gm-Message-State: AOAM531Ynd+g6lw3jgXGKM8WFcDx1OENUT5ivllkcmMEaFwinNJ1H3Dd ChByaejpZ1DyWuZrmvIb4ZXRcekpJOKuMmI9l53LuEZxGc3C2WU3d8TWi17qmhDCZ1ZgQhoYbRD tw8IKlyD14DPcGU14UQO9dymI X-Received: by 2002:a05:6214:3a4:: with SMTP id m4mr24172392qvy.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> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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