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 A52EBC433EF for ; Fri, 22 Apr 2022 01:19:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DA4E6B0072; Thu, 21 Apr 2022 21:19:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28A346B0073; Thu, 21 Apr 2022 21:19:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12BE36B0074; Thu, 21 Apr 2022 21:19:15 -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 0076C6B0072 for ; Thu, 21 Apr 2022 21:19:14 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C66A622D1D for ; Fri, 22 Apr 2022 01:19:14 +0000 (UTC) X-FDA: 79382756628.07.63F099E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 8482210001F for ; Fri, 22 Apr 2022 01:19:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650590353; 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=70wGqlUOgWCDvNBVd6ZanDDxLxnP4j+Zj98awDX3AtQ=; b=bM4WfxEv7SPmjcxe9Tah3eN4iNiSJT0IEsDhcniZSWb9tfR0pT4g6ynP/NzapnNMtoDXu8 tCN4AP74fEdsoD68TgoWGhhK/EUDQDIxXb8uP1lTqyh/BzqCoCsVEghb9leHSquRwBoKkL tp5tkaRyE4l6w3UeUmjXyIs2yDOmigI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-541-J6j6l2JYOBqHPObQuPBd_Q-1; Thu, 21 Apr 2022 21:19:10 -0400 X-MC-Unique: J6j6l2JYOBqHPObQuPBd_Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 36E39299E745; Fri, 22 Apr 2022 01:19:10 +0000 (UTC) Received: from rh (vpn2-54-103.bne.redhat.com [10.64.54.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98324559209; Fri, 22 Apr 2022 01:19:09 +0000 (UTC) Received: from localhost ([::1] helo=rh) by rh with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nhhww-008TIa-TA; Fri, 22 Apr 2022 11:19:06 +1000 Date: Fri, 22 Apr 2022 11:19:05 +1000 From: Dave Chinner To: Roman Gushchin 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-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8482210001F X-Stat-Signature: zmogqdz78sgm41krtijuin9qrezigf8h Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bM4WfxEv; spf=none (imf14.hostedemail.com: domain of dchinner@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=dchinner@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1650590353-662161 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 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. > however the added complexity is also small: one "if" statement. Yeah, complexity is not the problem here - it's that accuracy of the tracepoints has actually mattered to me in the past... Cheers, DAve. -- Dave Chinner dchinner@redhat.com