Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp950565pxb; Thu, 15 Apr 2021 10:09:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw29CGI9m9jA6IGVUyLNBreeblqix8tn5aVofmge8P8eicyLFRABjfIUfXZW2Z9aiaC0/hG X-Received: by 2002:a17:90a:e28b:: with SMTP id d11mr5052047pjz.53.1618506594743; Thu, 15 Apr 2021 10:09:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618506594; cv=none; d=google.com; s=arc-20160816; b=j+h7mvFRCM+AYrTS/eqIKygm8FCkuCWpsQxio2t6U0yRAzFTl++H7V7wF4J3D5uQv/ lpd0dEM3FSuN7TzM+ve4wErgNh+rhCje8mrYlcKwzwm87J/5ehuRLboK3d/Qp+y6bBhq LzBvL9buV07dxmxY8xy7DS8BCiO72C6AI6s0mMWmlYEBBCsomrwjTf3c92dRRKbtjT0h gGighGM9jSSsTqw87TaN9CeoCBfCO2RiL4OzHOC9uc1RNEHsMvLWsEyzeV3PNPKWD2iT bbbA+0Sjk4IjBNNqINQficAkPl8fP0GIG0fKm318E5n4G5CTqYwI0Q2vRitZ93L10B5g AOxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from:dkim-signature; bh=c4bUwdWqx5JUrWJYR1rKkQlIPcDgNW5mI87L7J9m2Ko=; b=no3QK60d54xjSTEgEdeiUMzP699nq0DEJCZ3SxmZTsyPhr9+C2tot7Pi7s2xob2Z1Q 0hRDIEg10xe8r+oHwIDF+Yfmfvpd5E7oJ9jc+3z5L+wwOSSFMSB6O+/b4l1/VaOnPpks yzRZHUQa7UUMry7q6fiUFGMVn9+tl7pU18VhhT4iM8iRFC+FtCQb6tX8EysRerglB2A+ VCN0HYLisCQ5NxhBUwDTbqYi2FNlTEtSTauy/wEFB3AMZs6pbCNBnczVDNrukkLq0+Lc cQejuw3XsMWls8ubLjuh0ATkC52YsyT4Y4R3AnzshSdpdkf4SMkKd3KyZS3HTHrtdc7E uWRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cPfFTRNh; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l5si3733764pgn.335.2021.04.15.10.09.41; Thu, 15 Apr 2021 10:09:54 -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=@redhat.com header.s=mimecast20190719 header.b=cPfFTRNh; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234359AbhDORJA (ORCPT + 99 others); Thu, 15 Apr 2021 13:09:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24895 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbhDORI5 (ORCPT ); Thu, 15 Apr 2021 13:08:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618506513; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c4bUwdWqx5JUrWJYR1rKkQlIPcDgNW5mI87L7J9m2Ko=; b=cPfFTRNhSCEXmtPLmxTSsiEx5SDNvPZ+llFjaON/nLMgxaorLChekgF+Kt+tbihq7nXZLK hnBrXikii2IqjA4BlnNpR4XtqICm7vKLYnFKYHlUihfwviNW3CrJCQUXmpS+MxEBv3c1V6 1H9L6XhLlOFAAry3CEtvOADgOKDhmJA= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-132-OCKGBshbMKOgaNgfPICTlA-1; Thu, 15 Apr 2021 13:08:32 -0400 X-MC-Unique: OCKGBshbMKOgaNgfPICTlA-1 Received: by mail-qk1-f197.google.com with SMTP id h21so1954320qkl.12 for ; Thu, 15 Apr 2021 10:08:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=c4bUwdWqx5JUrWJYR1rKkQlIPcDgNW5mI87L7J9m2Ko=; b=s10wzVmDcHZPfL1D/xPkEir+4z3cBlWp5WHTruNPEDDmwsazeC75oc4h/TPvIpa7v+ LKCZNTiZJVZqr4L0kgZY/VUFK8VdFJjFLehJBTbSDl4U9HBKJOnctn2GaRBOfH0Do4zT ILkTbCI0D7PDNYtzrAAhn0y6jqLzcfBT5MjzMp0vYobAkVQtjXRTDJNGhow4nfhmhquE YpeNqTsmFhcWt2ogmkoNDXeyhIIa10JJg8q4ewh4k+b6rLIfj6roG/TjR4ovJQ22vl/i xJkAqL1PP8zKi8AaIaqVA2mgdFWZsDBxUZoFYXH7Lz39zYCUvtPUAYEk+SgxaUGXruSL 5tkg== X-Gm-Message-State: AOAM533B92A2y1faGMXk/BUuwjUzZGkvOqFy4Ok7fFEDKP+BOkmbuc9e BJ1X54ktT19qEdtpgVBo8hyp1to4D2nN5P0T0PjZZGpNrE9v6H2MnzT018eoc6DpOzlOtrPGdbT Qy9ZTJpkoi5j08+sgnLkC+i8D X-Received: by 2002:a0c:e601:: with SMTP id z1mr4249163qvm.62.1618506511987; Thu, 15 Apr 2021 10:08:31 -0700 (PDT) X-Received: by 2002:a0c:e601:: with SMTP id z1mr4249129qvm.62.1618506511823; Thu, 15 Apr 2021 10:08:31 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id u21sm2196347qtq.11.2021.04.15.10.08.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Apr 2021 10:08:31 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH v3 3/5] mm/memcg: Cache vmstat data in percpu memcg_stock_pcp To: Johannes Weiner 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 References: <20210414012027.5352-1-longman@redhat.com> <20210414012027.5352-4-longman@redhat.com> Message-ID: <5abe499a-b1ad-fa22-3487-1a6e00e30e17@redhat.com> Date: Thu, 15 Apr 2021 13:08:29 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cheers, Longman