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 X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD593C433ED for ; Mon, 12 Apr 2021 19:30:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6F61E61358 for ; Mon, 12 Apr 2021 19:30:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F61E61358 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 058D06B0070; Mon, 12 Apr 2021 15:30:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 009816B0071; Mon, 12 Apr 2021 15:30:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D50496B0072; Mon, 12 Apr 2021 15:30:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id B6EAF6B0070 for ; Mon, 12 Apr 2021 15:30:09 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 75ECC582B for ; Mon, 12 Apr 2021 19:30:09 +0000 (UTC) X-FDA: 78024705738.05.FA453E9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 1364480192E5 for ; Mon, 12 Apr 2021 19:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618255808; 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=g6Ynsmxxkwh+nxh0otIklQ6uU+PBKwuJrjfFSi5KMSM=; b=FyFgGS4XmUTfRktJfTFad8vsZ3f0jOBN3kxMogDBowIH+juxha658TJLSjjLOUnFldvaGx Arl2qtHH3a5g5Rrevx6t1VpdyQeRdyhEpyJW7qkWcTAMb4gp8vTRquIz4Gr/2QLx4Jb3s+ 8pf6Y62TSYwX3bUDBfyRYSBn4BO7+lQ= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-JjadCcVzPnK3gplKulunjA-1; Mon, 12 Apr 2021 15:30:07 -0400 X-MC-Unique: JjadCcVzPnK3gplKulunjA-1 Received: by mail-qk1-f200.google.com with SMTP id o4so1075959qkg.2 for ; Mon, 12 Apr 2021 12:30:07 -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=g6Ynsmxxkwh+nxh0otIklQ6uU+PBKwuJrjfFSi5KMSM=; b=bU/ofhtATU7eHtGS27hYUTbeWZqy999pfww0Ev5PEubradPKqvi4UMjo80a0/iTkVr iNszVqd90eYYY64aYeAQVPU0E1pLxRpF/TOV9X9dppxqzHTUxO59w0FRlNZps5YaDuQt rijjIZH4+reGg886nwWUK63NdXN258pzIZ2iI00d7CwBtBCSOKWBgRSwDBdXUhS0LRG1 1/4j2IxUwEKyYHPwb1imhoOPMyS8AxrFAjFWlz009B609Fvbku4L1W5QkzQVLOSKEu+6 BTW3b1v+sUPilx+3gWyuKbW1FO7ETbyLTS4AgBtm+FL+8EzUJvxTplSv7iQnCmb2q4Sr xQJA== X-Gm-Message-State: AOAM531CclbMmiLP0GNN7I8NQCJ8FYTntE9PTtIwbs373/JVg6ZXW416 HSfinnADMWdg44H9E3L5iFIiyttoTO3f9/95M9FTh86GdFlzBzKYZH2A/d1BHGOziacxkh2ixVN L3zfcPOHc4no= X-Received: by 2002:a05:620a:133b:: with SMTP id p27mr30028345qkj.382.1618255806689; Mon, 12 Apr 2021 12:30:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/0ZhcohubWOy2Odk9W0Je22ttvn2Xb+0qT9mcE7do92RYBiLJoRTivziK/j0RC5FuoUOAEw== X-Received: by 2002:a05:620a:133b:: with SMTP id p27mr30028309qkj.382.1618255806482; Mon, 12 Apr 2021 12:30:06 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id i22sm2868262qko.135.2021.04.12.12.30.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Apr 2021 12:30:06 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH 3/5] mm/memcg: Cache vmstat data in percpu memcg_stock_pcp To: Roman Gushchin Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Muchun Song , Alex Shi , Chris Down , Yafang Shao , Alexander Duyck , Wei Yang , Masayoshi Mizuma References: <20210409231842.8840-1-longman@redhat.com> <20210409231842.8840-4-longman@redhat.com> Message-ID: <16af80a2-30a0-06da-9fd1-8d5101398fb9@redhat.com> Date: Mon, 12 Apr 2021 15:30:04 -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: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=llong@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 1364480192E5 X-Stat-Signature: rkdfjd9w76a1o3mssjni18anr7tgz7cm Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf08; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618255796-124921 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 4/12/21 2:22 PM, Roman Gushchin wrote: > On Fri, Apr 09, 2021 at 07:18:40PM -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. > The idea makes total sense to me and also gives a hope to remove > byte-sized vmstats in the long-term. > >> 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%. >> >> Signed-off-by: Waiman Long >> --- >> mm/memcontrol.c | 78 +++++++++++++++++++++++++++++++++++++++++++------ >> mm/slab.h | 26 +++++++---------- >> 2 files changed, 79 insertions(+), 25 deletions(-) >> >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c >> index b19100c68aa0..539c3b632e47 100644 >> --- a/mm/memcontrol.c >> +++ b/mm/memcontrol.c >> @@ -2220,7 +2220,10 @@ struct memcg_stock_pcp { >> >> #ifdef CONFIG_MEMCG_KMEM >> struct obj_cgroup *cached_objcg; >> + struct pglist_data *cached_pgdat; >> unsigned int nr_bytes; >> + int vmstat_idx; >> + int vmstat_bytes; >> #endif > Because vmstat_idx can realistically take only 3 values (slab_reclaimable, > slab_unreclaimable and percpu), I wonder if it's better to have > vmstat_bytes[3] and save a bit more on the reduced number of flushes? > It must be an often case when a complex (reclaimable) kernel object has > non-reclaimable parts (e.g. kmallocs) or percpu counters. > If the difference will be too small, maybe the current form is better. I have thought about that too. However, that will make the code more complex. So I decided to cache just one for now. We can certainly play around with caching more in a later patch. Cheers, Longman