Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2249693pxb; Sun, 17 Oct 2021 09:37:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwgenxIKvBP5riFey4VFZVEXG2jaC8w/r1U9dr5bYugqi9caS6L1hI9pBDAaL7p/VH0XVv X-Received: by 2002:a17:903:124f:b0:13e:25e6:f733 with SMTP id u15-20020a170903124f00b0013e25e6f733mr22509497plh.42.1634488654331; Sun, 17 Oct 2021 09:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634488654; cv=none; d=google.com; s=arc-20160816; b=UFk5XlivJ/whQ85gAmu/stZpFxSKo4nyazA6mTleFYnWckzxAkfoIPLoK2Q7C8890W LV4r2W1bP9BsAjrRR5gOLcnGT/4xYyUagZp3d5MuaSKUU3nxZSCPMjd5fNO/egM8vCCp k4fMnKmtELliwZQ8Pr3rY0TWhKY7W3J0qV28t1NUZnVe2bj7OLpTn2ibnvSrojnBkD1f ZeP5gx071pt1Wf9qlvUnzswMsYCz35troSOLL4/BtB1QzY5BPdOii3pVk403ztq0J+/X Gw4oUNdLUfZMvGQg+E16VSxI7IAEuFggnjllx0o1NfklecSjSOW7YVSyqAxJQog582Dn 8cyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=4jBn2VNfaCZDHefss5Z1r9mqIdP3xRVwotwlK+Rm7xY=; b=g+g6uJjB0REacpFp15ge0e8r00f4Z4XWO8c/UfjMHnbim7LKKw6aEpX7PvMHdfgTpC x1oXM559ygqhAnoviOI1+BJLR66Lo3DjBgdkmKkeQ6YdTyWSIEHVok/1O6FNUPAApW3R 2UuR7CdxE5lDpaM+dPciGe+K6/Nshd6Q6XFjQgcqmG4ih933nSP7b3zR5T6nwj+X0x1A KFdIUgGnQZjeO2kaOrfTGR2i4TyrvqiytWukQG0GvbALXQD/Pn/6JUEK5wkzYeOWs04n VFGgQSeGrTbqfTwphvutBB/nVyfmh379CnTu4q1V+moZKOMWsVWr00nw8D+hiPKuBcF+ kyxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=n1K8M3Dt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c9si9523004pfr.13.2021.10.17.09.37.10; Sun, 17 Oct 2021 09:37:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=n1K8M3Dt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242374AbhJOR5n (ORCPT + 99 others); Fri, 15 Oct 2021 13:57:43 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:48750 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242303AbhJOR5l (ORCPT ); Fri, 15 Oct 2021 13:57:41 -0400 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 17DF21FD4F; Fri, 15 Oct 2021 17:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1634320533; 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=4jBn2VNfaCZDHefss5Z1r9mqIdP3xRVwotwlK+Rm7xY=; b=n1K8M3Dt3d5TeTHwFKotWO6NgpCUxVj9yloDRCzY2ACk+N04k0IsJk9kqYAIr5CkXCtahO nlU9a0EBiwuhBPySCxctmkoH2iaJWzcfoYspQAfFg6jbjBTLBTW345dDdKwJR+lFFJ2ZBN k3qq64TE8yeQUYARubZvGlGdIcnGP1c= 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 F13F413C6F; Fri, 15 Oct 2021 17:55:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id d+pMOpTAaWHgJQAAMHmgww (envelope-from ); Fri, 15 Oct 2021 17:55:32 +0000 Date: Fri, 15 Oct 2021 19:55:31 +0200 From: Michal =?iso-8859-1?Q?Koutn=FD?= To: Shakeel Butt Cc: akpm@linux-foundation.org, cgroups@vger.kernel.org, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org Subject: Re: [PATCH v2 1/2] memcg: flush stats only if updated Message-ID: <20211015175531.GB46263@blackbody.suse.cz> References: <20211013180130.GB22036@blackbody.suse.cz> <20211014163146.2177266-1-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211014163146.2177266-1-shakeelb@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 14, 2021 at 09:31:46AM -0700, Shakeel Butt wrote: > Thanks for your review. This forces me to think more on this because each > update does not necessarily be a single page sized update e.g. adding a hugepage > to an LRU. Aha, hugepages... (I also noticed that on the opposite size scale are NR_SLAB_{UN,}RECLAIMABLE_B, the complementary problem to too big error would be too frequent flushes.) > Though I think the error is time bounded by 2 seconds but in those 2 seconds > mathematically the error can be large. Honestly, I can't tell how much the (transient) errors in various node_stat_item entries will or won't affect MM behavior. But having some guards on it sounds practical when some problems to troubleshoot arise. > What do you think of the following change? It will bound the error > better within the 2 seconds window. > [...] > -static inline void memcg_rstat_updated(struct mem_cgroup *memcg) > +static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val) > { > + unsigned int x; > + > cgroup_rstat_updated(memcg->css.cgroup, smp_processor_id()); > - if (!(__this_cpu_inc_return(stats_updates) % MEMCG_CHARGE_BATCH)) > - atomic_inc(&stats_flush_threshold); > + > + x = abs(__this_cpu_add_return(stats_diff, val)); > + if (x > MEMCG_CHARGE_BATCH) { > + atomic_add(x / MEMCG_CHARGE_BATCH, &stats_flush_threshold); > + __this_cpu_write(stats_diff, 0); > + } > } Looks better wrt meaningful error calculation (and hopefully still doesn't add too much to the hot path). > @@ -807,7 +813,7 @@ void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx, > return; > > __this_cpu_add(memcg->vmstats_percpu->events[idx], count); > - memcg_rstat_updated(memcg); > + memcg_rstat_updated(memcg, val); s/val/count/ (Just thinking loudly.) At one moment I thought, it could effectively be even s/val/0/ since events aren't(?) inputs for reclaim calculations. But with the introduced stats_diff it may happen stats_diff flickers (its abs value) within the MEMCG_CHARGE_BATCH and stats_flush_threshold would never be incremented. Basically disabling the periodic flush. Therefore the events must also increment the stats_diff.