From patchwork Sat Apr 16 00:41:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 12815545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7618EC433EF for ; Sat, 16 Apr 2022 00:41:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E49236B0072; Fri, 15 Apr 2022 20:41:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF84B6B0073; Fri, 15 Apr 2022 20:41:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBF9F6B0074; Fri, 15 Apr 2022 20:41:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id B9BE46B0072 for ; Fri, 15 Apr 2022 20:41:21 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7FCFD26326 for ; Sat, 16 Apr 2022 00:41:21 +0000 (UTC) X-FDA: 79360888362.22.36FCED5 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf19.hostedemail.com (Postfix) with ESMTP id CC2991A0002 for ; Sat, 16 Apr 2022 00:41:20 +0000 (UTC) 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 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspam-User: X-Rspamd-Queue-Id: CC2991A0002 X-Stat-Signature: baz9fcdpapcmjuop6j7mee5c75zuzkna Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Jo2/gZ05"; spf=pass (imf19.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspamd-Server: rspam01 X-HE-Tag: 1650069680-131517 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: 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 Acked-by: David Hildenbrand --- 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;