Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp936093pxb; Fri, 22 Apr 2022 14:47:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCYVtBmUQBTHIGGg5InSmL+Ht3kX26sL7U7d1ESDdqkQ0nLzBe3l+sL76YHDnTWowJWkim X-Received: by 2002:a17:903:1c9:b0:158:e1b9:b395 with SMTP id e9-20020a17090301c900b00158e1b9b395mr6852325plh.20.1650664021170; Fri, 22 Apr 2022 14:47:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650664021; cv=none; d=google.com; s=arc-20160816; b=P3YE2DFMpR4vqEIQf/W1U/9cRP8dfBXob9LrX00vJ/J8f6evsFrI71wl+KdJTzRW3w yKkZnp65LYWce1+K5TE29XqHEOjq6dIVIi7LVGv5BzTieYfZXZP0OwAIrssb8tPEK3Md odlvr4foOPSpp2XDFpRWUV//U9fb7gHT2M8KNbYSL4V1elQBzpvUthpsigJ1+N7supEk m9Tjt23VCtrBXIU5Gw8SKiH3rYAXqgpmcRuPFt/DuynT7CrZ6n8JtvkZ/3MeL8lYzy6w wcdILFdcIpGDQi+dQsF2HjEdZI9HetxeiWmolZsqgb3h2rKBpG4Km3AlWfef1WWtBlyy mEIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=kLshpcQDnpXfKVw8FlVeldYYjsS62gfK++RoyzE7fzI=; b=Z1IkoOWJDPLIyDSsgMjiHwbH3TchEVvSZvkOrzTBV5f6pyoKEXTTNSHUJ0DW/w7LcY LcZp+ykxjOeRvdcegc3IjviZXV3zjqKeL/gQU9CCuc5ENDuzIfmqmH6saKhUMh3EHDpp wDd6X8pHuXzEPVITAiKrhMYxBrjbybZQMKykm1MkGPq2b76/fyasjnmRfy/ZgGsUuFJu qvdu9p3hO12qI5de1Qj0GHI8cMpup09+Vz4ZsnMMRA9iYW11y14xBoGAHZJYJILgm0a1 WYdYOaf6Vpis6N5Sk5BT+fvXakSqXxQIM08sui5cQcyobbN5vEACjTRvUALuUDjPwLkE IMxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oN1RALox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ij1-20020a170902ab4100b001567cbd9a37si8797357plb.223.2022.04.22.14.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:47:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oN1RALox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A8153332FBB; Fri, 22 Apr 2022 12:54:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383231AbiDTXdg (ORCPT + 99 others); Wed, 20 Apr 2022 19:33:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231854AbiDTXdd (ORCPT ); Wed, 20 Apr 2022 19:33:33 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C5BB2ED42 for ; Wed, 20 Apr 2022 16:30:46 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id q1so2032212plx.13 for ; Wed, 20 Apr 2022 16:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kLshpcQDnpXfKVw8FlVeldYYjsS62gfK++RoyzE7fzI=; b=oN1RALoxj7uG5b822TkWSWP45NtB+Ln9k0aoSR3WnyYaApx1+JSppvo2ykhYM//PRc IN/5wlSvS2z2LAZkQ0diIyFPVUDxVUFtQBLURIZkvPbc7vELcQIxPiEEfjFMQ8UaHW/e lJXAfSbLS/qXG0XbLR8IGzvW5hdJ3jp3U8WYLfNWCll3eryaibcxuaZk+9cx2YtDGF67 Q8qqx4JyiXCv6/ReHHFjKo1mog3EnbwYvdv4EXin04QCPlsXvw6+pZekC9jpOZQ51V+s p1WLH0nBkaZaBXW+UKvJrB28hqIYVFXxZK6LaQeuuYDLxdD8Ngo2cOEnYwVr2d9nfkHE a4Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kLshpcQDnpXfKVw8FlVeldYYjsS62gfK++RoyzE7fzI=; b=bYEKbP0+FyOVub1AXeGmzQvNk9Soo8O9f9wJ2MYgF7qK2vvC2feZ4RihXL5CHsWFLF myHudzhxi3wwLRZdtbECqlSCC8F6o3LeBXn0U1bXMmaF5zi93QglcVTf/ySxyR4bJiq+ Y4HRwE7zd6yssVJb+zXknbnb1vPg3nk5Xuh4gOVtE+bWburfbivlnp4MEc/I6wnrQwHu VZucF9X6GC4w5uVPQq3Eu+KgFdP++0OL/dXfSEUYZzp8zajKv6/KU3yTVrIB8TRk25NO Vpew0lITpF2E3AXLo7DH3Fcjkf58ct7Sd5Voe+trqCRxdTW51x0+mg6XcWjmBQhxl02Y L0Jg== X-Gm-Message-State: AOAM533yN1YwDVHb1kpWnPZw+FagVB0x8uQ3lmGqlZOpDv893gJzzFj5 x4g6+2cXr7cxhGdw7IFVCAUthwK2GxwLstTWh+U= X-Received: by 2002:a17:90b:4a85:b0:1d2:aee9:23ce with SMTP id lp5-20020a17090b4a8500b001d2aee923cemr7161666pjb.99.1650497445807; Wed, 20 Apr 2022 16:30:45 -0700 (PDT) MIME-Version: 1.0 References: <20220416004104.4089743-1-roman.gushchin@linux.dev> <59404249-de0c-c569-d04a-9da38ed14b0a@redhat.com> In-Reply-To: From: Yang Shi Date: Wed, 20 Apr 2022 16:30:33 -0700 Message-ID: Subject: Re: [PATCH] mm: do not call add_nr_deferred() with zero deferred To: David Hildenbrand Cc: Roman Gushchin , Linux MM , Andrew Morton , Dave Chinner , Linux Kernel Mailing List , Johannes Weiner , Michal Hocko , Shakeel Butt Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 19, 2022 at 9:57 AM David Hildenbrand wrote: > > On 19.04.22 18:42, Roman Gushchin wrote: > > On Tue, Apr 19, 2022 at 02:56:06PM +0200, David Hildenbrand wrote: > >> On 16.04.22 02:41, Roman Gushchin wrote: > >>> add_nr_deferred() is often called with next_deferred equal to 0. > >>> For instance, it's happening under low memory pressure for any > >>> shrinkers with a low number of cached objects. A corresponding trace > >>> looks like: > >>> <...>-619914 [005] .... 467456.345160: mm_shrink_slab_end: \ > >>> super_cache_scan+0x0/0x1a0 0000000087027f06: nid: 1 \ > >>> unused scan count 0 new scan count 0 total_scan 0 \ > >>> last shrinker return val 0 > >>> > >>> <...>-619914 [005] .... 467456.345371: mm_shrink_slab_end: \ > >>> super_cache_scan+0x0/0x1a0 0000000087027f06: nid: 1 \ > >>> unused scan count 0 new scan count 0 total_scan 0 \ > >>> last shrinker return val 0 > >>> > >>> <...>-619914 [005] .... 467456.345380: mm_shrink_slab_end: \ > >>> super_cache_scan+0x0/0x1a0 0000000087027f06: nid: 1 unused \ > >>> scan count 0 new scan count 0 total_scan 0 \ > >>> last shrinker return val 0 > >>> > >>> This lead to unnecessary checks and atomic operations, which can be > >>> avoided by checking next_deferred for not being zero before calling > >>> add_nr_deferred(). In this case the mm_shrink_slab_end trace point > >>> will get a potentially slightly outdated "new scan count" value, but > >>> it's totally fine. > >> > >> Sufficient improvement to justify added complexity for anybody reading > >> that code? > > > > I don't have any numbers and really doubt the difference is significant, > > however the added complexity is also small: one "if" statement. > > Anyway, if you feel strongly against this change, I'm fine with dropping it. > > > > No strong opinion, naturally, more conditions make the code harder to > read -- that's why I'm asking. This is why that "if" was removed by commit 867508304685 ("mm: vmscan: use per memcg nr_deferred of shrinker") since it didn't bring in measurable performance improvement. TBH I'm not sure whether it is worth it with no measurable performance boost but harder to read code and potential outdated "new scan count". > > >> > >>> > >>> Signed-off-by: Roman Gushchin > >>> --- > >>> mm/vmscan.c | 5 ++++- > >>> 1 file changed, 4 insertions(+), 1 deletion(-) > >>> > >>> diff --git a/mm/vmscan.c b/mm/vmscan.c > >>> index d4a7d2bd276d..19d3d4fa1aad 100644 > >>> --- a/mm/vmscan.c > >>> +++ b/mm/vmscan.c > >>> @@ -808,7 +808,10 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, > >>> * move the unused scan count back into the shrinker in a > >>> * manner that handles concurrent updates. > >>> */ > >>> - new_nr = add_nr_deferred(next_deferred, shrinker, shrinkctl); > >>> + if (next_deferred) > >>> + new_nr = add_nr_deferred(next_deferred, shrinker, shrinkctl); > >>> + else > >>> + new_nr = nr; > >>> > >>> trace_mm_shrink_slab_end(shrinker, shrinkctl->nid, freed, nr, new_nr, total_scan); > >>> return freed; > >> > >> And if we still want to do this optimization, why not put it into > >> add_nr_deferred()? > > > > Because of the semantics of add_nr_deferred(), which returns the deferred value. > > It's not used for anything except tracing, so maybe it's a place for another > > change. > > Skimming over the code I somehow missed that add_nr_deferred() doesn't > have "nr" naturally available. > > LGTM > > Acked-by: David Hildenbrand > > > -- > Thanks, > > David / dhildenb >