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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E8E2C433EF for ; Fri, 22 Apr 2022 02:36:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D60F6B0072; Thu, 21 Apr 2022 22:36:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 05E236B0073; Thu, 21 Apr 2022 22:36:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1B426B0074; Thu, 21 Apr 2022 22:36:53 -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 D0A196B0072 for ; Thu, 21 Apr 2022 22:36:53 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9EEBB2062F for ; Fri, 22 Apr 2022 02:36:53 +0000 (UTC) X-FDA: 79382952306.21.5F69072 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf26.hostedemail.com (Postfix) with ESMTP id B0628140018 for ; Fri, 22 Apr 2022 02:36:51 +0000 (UTC) Date: Thu, 21 Apr 2022 19:36:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1650595010; 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: in-reply-to:in-reply-to:references:references; bh=Zo2fUmTVY98S/ssCWYYXtGvtMEnD9SsQzaQapZz/cs0=; b=SAFLUdVggf+g1vIuiTaQiZr3jWAW76MR5zoqV4rcAKalfTWS5qHymitEV5P9GaU9AmoZhc n/hZNQAW6s028uurJW0SQ7tUXc0oaQpRWi4YZVQCgZw49RDsqlE0gTU2qRlkEg233zCAWx vfI13w3z1v6nsWsNFucnN2jQb68vlTU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Dave Chinner Cc: David Hildenbrand , linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Yang Shi Subject: Re: [PATCH] mm: do not call add_nr_deferred() with zero deferred Message-ID: References: <20220416004104.4089743-1-roman.gushchin@linux.dev> <59404249-de0c-c569-d04a-9da38ed14b0a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspam-User: X-Rspamd-Queue-Id: B0628140018 X-Stat-Signature: 8mwd9maw3xoagojp3a6faj6dp3nzdfrp Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SAFLUdVg; spf=pass (imf26.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: 1650595011-784065 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 Fri, Apr 22, 2022 at 11:19:05AM +1000, Dave Chinner wrote: > On Tue, Apr 19, 2022 at 09:42:30AM -0700, 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, > > Never been able to measure it myself. > > HwoeverI'd much prefer the tracepoint output stays accurate - I've had to > post-process and/or graph the shrinker progress as reported by the > start/end tracpoints to find problems in the algorithms in the past. > That's why there is the additional complexity in the code to make > sure the coutners are accurate in the first place. Sure, no problems. Andrew, can you, please, drop this patch? Thanks!