Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp997371pxb; Thu, 15 Apr 2021 11:15:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykTxQeBlOYWW2tT/pnGKGwEEot1e2CHFno1KQ41t/8lA+qXqDkrBi6LRE2VUsfmeH5qehL X-Received: by 2002:a17:906:ce23:: with SMTP id sd3mr4824097ejb.223.1618510533364; Thu, 15 Apr 2021 11:15:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618510533; cv=none; d=google.com; s=arc-20160816; b=0W+5/B3oZEaT+Ki1njuLwwP5PsZRvgoa/VPmfVMo20P2CI9k7GIYxXd/7EMvQGpLXR V3TK6S11GH+cp0pI/Tg2eJIuv71kZPqy+A8DDSW1S01QnNT4b+AQ6lXlfuLpTJFSPEsl nBqq8Gh3mZMO7j9/q57xTtr3O9IoswJkKm+qrremxkeQK7C7kRqZ7TSPQI6D51yqKgA3 kR4QMInYYD2x30P7LaJo8SutKsq0B80DkKFEzGBuJE1WsjuQgDWoypen4DkglUYwUHAW iDhUN9T3DpVdnm32yUNFOoSgvKP/TdPLdG0NSjkzZDzWFXEyZvdhtyLypoGbhSuWCU36 S+XA== 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=EO1ZRnRE5AIix1KmwKUfdGLcr4z4RBOaJpoQ33nEJcU=; b=wxCziLKVtpDJxNp2tQGnne86g80TiZmgf274sYs1+u/RhpQ7FUEorw62atFvNkh0Gl V7l74ZnGzdzxeHXaHsE4KsJ47RX7eE9N25bgayIu5N2WTXvrQ7QquOlSivoq5efNRyF7 PsBlkFcGI9e09pjasiv9mAO/BGTHrxlFpMfxz1HOo6+2leJV9evo0FhAlcXRRDGWTvIw Moq0Kbwxfrkne7SWI4vtxe/pA7wp7SEj0JIc8OY7WaPCr0aU4r+hdPZr638a+68vVPoD bevfUwrT/Dgw71m0SE04GbTKkRudSRe8o8bxtwF8I02RWDNsDVu+Sp9dVXWQBkuJbQTq ln6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=jcmAT3HP; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay5si2825958ejb.584.2021.04.15.11.15.08; Thu, 15 Apr 2021 11:15:33 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=jcmAT3HP; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232759AbhDOSOL (ORCPT + 99 others); Thu, 15 Apr 2021 14:14:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233595AbhDOSOG (ORCPT ); Thu, 15 Apr 2021 14:14:06 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFA4EC061574 for ; Thu, 15 Apr 2021 11:13:40 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id u8so18842296qtq.12 for ; Thu, 15 Apr 2021 11:13:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=EO1ZRnRE5AIix1KmwKUfdGLcr4z4RBOaJpoQ33nEJcU=; b=jcmAT3HPYBCrHP6jHCPcphUzr0fG91bIyePgBoblxnUY+uM+e0eGmbicEIUky5JdS0 3f+T18xTekj77ibaghPcyaYdxNQRjMPbL4Ntyc63OCy/SDczT2i+WSCRxh/sJc/Sb+jL zTGvaa45VbkcKTNF0+kZ/awf98n0XtQGdqXy5xnTcX+StcRGfboJyIAFPchfBTtSF5A9 VROXd7+VJIJA1jLng07E/m4Vx1z4MfGAhl74Z/6Z251sfegah5pmMek7SH5p2gLdC140 PPSH1qvSRmRMyxmzaa54BMa3AEJO4ukZlCVGoQ8YJmEH+HRKNHBmnXMdiv8fuv7DifI4 oqvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EO1ZRnRE5AIix1KmwKUfdGLcr4z4RBOaJpoQ33nEJcU=; b=RSRSnxsGrpW1DzJB0gO505M7Il4SIlsEBl9ctfx8e0ZgaThUup4mr/RB6cFW0Va+1U sp7iVdjLe/PtcUXx+xIEf3q+pzdcIwsnEADov0jo8KEmfFJ+iJppbKEPVEXkF8C3wwoE wngipGqR05UKKautAOaMH5rTmLjWDUM3+LeOeKrPq2N01+dMKWANlyyLuFLCa4t5mK+d Mqf6/JILiE762Y87bprpAZABzc9/w5LhVmk+EYdpmAzPlq6EBiwP//EN3bfu2kQbH1EQ 77Dl8BkzQQtx77DOjMtFvELg7IqIFY1PYGYvcQ242UpulFZXaqA2bKXNJvzNOQW3MRxL IsgA== X-Gm-Message-State: AOAM530bOEOkEYatvNozZgqXdiAC85y2w/wAJm3bFcw4BAHGudNqG81C bfBH5efgGjekJSbaPYy1//kRdQ== X-Received: by 2002:a05:622a:3c8:: with SMTP id k8mr4248564qtx.101.1618510419998; Thu, 15 Apr 2021 11:13:39 -0700 (PDT) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id 71sm2559708qkm.40.2021.04.15.11.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 11:13:39 -0700 (PDT) Date: Thu, 15 Apr 2021 14:13:38 -0400 From: Johannes Weiner To: Waiman Long Cc: Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Muchun Song , Alex Shi , Chris Down , Yafang Shao , Wei Yang , Masayoshi Mizuma , Xing Zhengjun Subject: Re: [PATCH v3 3/5] mm/memcg: Cache vmstat data in percpu memcg_stock_pcp Message-ID: References: <20210414012027.5352-1-longman@redhat.com> <20210414012027.5352-4-longman@redhat.com> <5abe499a-b1ad-fa22-3487-1a6e00e30e17@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5abe499a-b1ad-fa22-3487-1a6e00e30e17@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 01:08:29PM -0400, Waiman Long wrote: > On 4/15/21 12:50 PM, Johannes Weiner wrote: > > On Tue, Apr 13, 2021 at 09:20:25PM -0400, Waiman Long wrote: > > > Before the new slab memory controller with per object byte charging, > > > charging and vmstat data update happen only when new slab pages are > > > allocated or freed. Now they are done with every kmem_cache_alloc() > > > and kmem_cache_free(). This causes additional overhead for workloads > > > that generate a lot of alloc and free calls. > > > > > > The memcg_stock_pcp is used to cache byte charge for a specific > > > obj_cgroup to reduce that overhead. To further reducing it, this patch > > > makes the vmstat data cached in the memcg_stock_pcp structure as well > > > until it accumulates a page size worth of update or when other cached > > > data change. > > > > > > On a 2-socket Cascade Lake server with instrumentation enabled and this > > > patch applied, it was found that about 17% (946796 out of 5515184) of the > > > time when __mod_obj_stock_state() is called leads to an actual call to > > > mod_objcg_state() after initial boot. When doing parallel kernel build, > > > the figure was about 16% (21894614 out of 139780628). So caching the > > > vmstat data reduces the number of calls to mod_objcg_state() by more > > > than 80%. > > Right, but mod_objcg_state() is itself already percpu-cached. What's > > the benefit of avoiding calls to it with another percpu cache? > > > There are actually 2 set of vmstat data that have to be updated. One is > associated with the memcg and other one is for each lruvec within the > cgroup. Caching it in obj_stock, we replace 2 writes to two colder > cachelines with one write to a hot cacheline. If you look at patch 5, I > break obj_stock into two - one for task context and one for irq context. > Interrupt disable is no longer needed in task context, but that is not > possible when writing to the actual vmstat data arrays. Ah, thanks for the explanation. Both of these points are worth mentioning in the changelog of this patch.