Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp346344rwe; Thu, 25 Aug 2022 01:05:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR7LVAmyPq7n0oqzuakg/ku2bH4oiGZbRy9q2SHDnEINKEqvpflJWysZs+UYuAHgeZnCPvlZ X-Received: by 2002:a05:6402:32a7:b0:446:e17f:111c with SMTP id f39-20020a05640232a700b00446e17f111cmr2220378eda.95.1661414708644; Thu, 25 Aug 2022 01:05:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661414708; cv=none; d=google.com; s=arc-20160816; b=A98H8WLwt5GqU+mnkGFmTp8yQrGMM5iep8/DB4G7xYZVyhiRwdmnvzKI/8cqK0+0b9 1NEEDPNG2vMZxawAMMJknazHNJw2nXBxrfj/DSykmNJQ9Vk2MQb83JsB5N2yuEW5Al3D UCsskAGKF30MuWFlzQvN7g2kcMpl9rBAAlXSlKgUIjfqXzKdVnOcaNK0A1m37sAQRUyN 3IbtK9K5vk7HJnNZ65aJ3VFMHfKbaMH7u40qObw5TMIN7xEJ1HWZf2GU5HoniYyhOJ08 BJu2/3Kti7gAhApSUp9SvUteoSdRxwqWYexGK9EVirFn9nrmwB8HBtNXKBXoKpDSWNQ+ 1+fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3Qj/G2DClTBDyDxLgwNY63LBJXmgLPhCgE3PiOW9WEs=; b=SSBagIaeaBvVGKKq0e1bctoU2/k9W/aRAMqwUI/rHxg6PTOguHTINDnpjjEErkfH/m 0MlU5x/3b2hlSuUjqEBRCR+wtwpb1dMrh4YWsOoLQpEZCAsc62SuD/DCxlL3ODpwmUSX psnc5MAqeQTpcq4OwRoFqOjL1PBcpAQefDc+eTrLq0qLE9o2k6BgSDN5lXTxxMeKDSGl dMrrmG7amoh8eA8pqhQ9XhbdeH8iVcHOSupRjbdnZLBLAqhU8pnyRAO1JDptNfldRjTJ i8VIyiD2SNWyo64dbRlt/I7Xo7wKUvvtUw4ZDNpKIGL/3vyEfPvllJ5GS8LgGbzSotRG 8nnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=pkOPSm7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e20-20020a056402191400b0043c19cd608dsi6830833edz.33.2022.08.25.01.04.42; Thu, 25 Aug 2022 01:05:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=pkOPSm7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233348AbiHYGnz (ORCPT + 99 others); Thu, 25 Aug 2022 02:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233141AbiHYGnv (ORCPT ); Thu, 25 Aug 2022 02:43:51 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33A7AA0306; Wed, 24 Aug 2022 23:43:49 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B92545C871; Thu, 25 Aug 2022 06:43:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1661409827; h=from:from:reply-to: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=3Qj/G2DClTBDyDxLgwNY63LBJXmgLPhCgE3PiOW9WEs=; b=pkOPSm7KZh7KiGtgBVxVig947gAUgLX0C96Gk0/bANJ02johnIDhHEuQe1pL0Ib271ELms reO9MbRbZCMLkrpO2rT2xDlx/qU4ieZZfpALWCZY4NgAnw3/JYSRHnJSbr8pYoxulznjLs f/m5yaMC6GaXOc1rCK9PXVNnuUvfWqo= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9245B13A47; Thu, 25 Aug 2022 06:43:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 1xVQISMaB2OKPAAAMHmgww (envelope-from ); Thu, 25 Aug 2022 06:43:47 +0000 Date: Thu, 25 Aug 2022 08:43:46 +0200 From: Michal Hocko To: Shakeel Butt Cc: Johannes Weiner , Roman Gushchin , Muchun Song , Michal =?iso-8859-1?Q?Koutn=FD?= , Eric Dumazet , Soheil Hassas Yeganeh , Feng Tang , Oliver Sang , Andrew Morton , lkp@lists.01.org, cgroups@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] mm: page_counter: remove unneeded atomic ops for low/min Message-ID: References: <20220825000506.239406-1-shakeelb@google.com> <20220825000506.239406-2-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220825000506.239406-2-shakeelb@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 Thu 25-08-22 00:05:04, Shakeel Butt wrote: > For cgroups using low or min protections, the function > propagate_protected_usage() was doing an atomic xchg() operation > irrespectively. We can optimize out this atomic operation for one > specific scenario where the workload is using the protection (i.e. > min > 0) and the usage is above the protection (i.e. usage > min). > > This scenario is actually very common where the users want a part of > their workload to be protected against the external reclaim. Though this > optimization does introduce a race when the usage is around the > protection and concurrent charges and uncharged trip it over or under > the protection. In such cases, we might see lower effective protection > but the subsequent charge/uncharge will correct it. Thanks this is much more useful > To evaluate the impact of this optimization, on a 72 CPUs machine, we > ran the following workload in a three level of cgroup hierarchy with top > level having min and low setup appropriately to see if this optimization > is effective for the mentioned case. > > $ netserver -6 > # 36 instances of netperf with following params > $ netperf -6 -H ::1 -l 60 -t TCP_SENDFILE -- -m 10K > > Results (average throughput of netperf): > Without (6.0-rc1) 10482.7 Mbps > With patch 14542.5 Mbps (38.7% improvement) > > With the patch, the throughput improved by 38.7% > > Signed-off-by: Shakeel Butt > Reported-by: kernel test robot > Acked-by: Soheil Hassas Yeganeh > Reviewed-by: Feng Tang > Acked-by: Roman Gushchin Acked-by: Michal Hocko Thanks! > --- > Changes since v1: > - Commit message update with more detail on which scenario is getting > optimized and possible race condition. > > mm/page_counter.c | 13 ++++++------- > 1 file changed, 6 insertions(+), 7 deletions(-) > > diff --git a/mm/page_counter.c b/mm/page_counter.c > index eb156ff5d603..47711aa28161 100644 > --- a/mm/page_counter.c > +++ b/mm/page_counter.c > @@ -17,24 +17,23 @@ static void propagate_protected_usage(struct page_counter *c, > unsigned long usage) > { > unsigned long protected, old_protected; > - unsigned long low, min; > long delta; > > if (!c->parent) > return; > > - min = READ_ONCE(c->min); > - if (min || atomic_long_read(&c->min_usage)) { > - protected = min(usage, min); > + protected = min(usage, READ_ONCE(c->min)); > + old_protected = atomic_long_read(&c->min_usage); > + if (protected != old_protected) { > old_protected = atomic_long_xchg(&c->min_usage, protected); > delta = protected - old_protected; > if (delta) > atomic_long_add(delta, &c->parent->children_min_usage); > } > > - low = READ_ONCE(c->low); > - if (low || atomic_long_read(&c->low_usage)) { > - protected = min(usage, low); > + protected = min(usage, READ_ONCE(c->low)); > + old_protected = atomic_long_read(&c->low_usage); > + if (protected != old_protected) { > old_protected = atomic_long_xchg(&c->low_usage, protected); > delta = protected - old_protected; > if (delta) > -- > 2.37.1.595.g718a3a8f04-goog -- Michal Hocko SUSE Labs