Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp65498lfe; Fri, 15 Apr 2022 19:46:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTfQokiN1sZJ0D+4VVqVYyoNcXO1dPKk+uRoZA1PeOlgRmfIRqPf+Cs2Is6K0eheS/vD6W X-Received: by 2002:a17:902:bcca:b0:153:88c7:a02 with SMTP id o10-20020a170902bcca00b0015388c70a02mr1855286pls.112.1650077189740; Fri, 15 Apr 2022 19:46:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650077189; cv=none; d=google.com; s=arc-20160816; b=spTA/64IF530cDCk9Zo93p+xzdoIOm/HZIv3GB4eVNMpRptrBWzfOr5a/QcdJqVGy1 hUeuJN/NhTXo2FEA9kh+1Fs6ZhhfGsqgggz5Y2xyJlhXeWOyN4CeqS60vG7+hKgxFwcC C1OkbmkR24HntTSLlB8i67xr9uMuqG2jaJyPmpF096l0DIzkRH45+19NSqnCuXgLzzmB HdSv7bufU1qHNPC0+ujQDcDckltjIEaosSQNxhYyjPtkjnlBTBJmo4ZH2lo03vBSs44U 7Kyd2ZUuMx+9bDsXX8U7MUd+fDyGSaAG7a0cSJhtWIfIusKpFxpbj3Z2pxRXj9Z7PpUH h+og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=C5nkTrq4xMgYIDmhUhVhC2Dq7TG9dRaDSUT0wVRb144=; b=QruaKQx6OQmB++HH9bcqpOolNkdDikLruFZb+mBllKJUUrLrzg8nAkJayYtSOac3Zs /O7i+wCGcj7DAJRjE1444J2wc79beyTEXA6+3ZjJHzAdFL+SzJy7TKRMUVS7j+zBvUtB g5lbKkJn1BA8HCiorTtLGbtNxlcDJzbvpDWCtMNA1ajEbSqDrf6qFFW7eRtTo5FTzjJT Mar9vrLcBT5VcERy8mLYD7DzMFBQ4kgS9MQ3ey4D3reDrMaC9C7iHYygfIERPhLNlP9l 7RqQIRH3VS2GjxMAuH92q2zNzsCEK6xD7BE/XWCjrS5H7TpIw3LxzALnoZCQOTMPAcFT b4TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Jo2/gZ05"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o17-20020a056a0015d100b00505b18d2a3esi2819498pfu.297.2022.04.15.19.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:46:29 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Jo2/gZ05"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 11ADB136FD9; Fri, 15 Apr 2022 18:54:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229540AbiDPBKT (ORCPT + 99 others); Fri, 15 Apr 2022 21:10:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbiDPBKS (ORCPT ); Fri, 15 Apr 2022 21:10:18 -0400 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B39516665B for ; Fri, 15 Apr 2022 18:07:42 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1650069678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=C5nkTrq4xMgYIDmhUhVhC2Dq7TG9dRaDSUT0wVRb144=; b=Jo2/gZ05dZmfC/MFjPD+Ds9RazbpGZ3I7R9PcnlMSTwT7x2TY0Hg3IsG8oiZff1gW75ZYv tfWe7WPDHcAf/j2xhHdyc+Jg5hRoAz9OgqZlsX81+XLBSBBRonAbTz29hjw51prfNIvNSN ei8ecQgEloMgkibAiWOgzN6iNK2LOsA= From: Roman Gushchin To: linux-mm@kvack.org Cc: Andrew Morton , Dave Chinner , linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Yang Shi , Roman Gushchin Subject: [PATCH] mm: do not call add_nr_deferred() with zero deferred Date: Fri, 15 Apr 2022 17:41:04 -0700 Message-Id: <20220416004104.4089743-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 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. 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; -- 2.35.1