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=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no 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 CCB49C55186 for ; Thu, 23 Apr 2020 22:59:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5413220CC7 for ; Thu, 23 Apr 2020 22:59:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lBCPgL3X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5413220CC7 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E1CDF8E0005; Thu, 23 Apr 2020 18:59:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA60D8E0003; Thu, 23 Apr 2020 18:59:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C94D88E0005; Thu, 23 Apr 2020 18:59:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id B3A218E0003 for ; Thu, 23 Apr 2020 18:59:54 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 708298248068 for ; Thu, 23 Apr 2020 22:59:54 +0000 (UTC) X-FDA: 76740639108.21.birds10_738d2a410f84b X-HE-Tag: birds10_738d2a410f84b X-Filterd-Recvd-Size: 6875 Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Apr 2020 22:59:53 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id r17so6131538lff.2 for ; Thu, 23 Apr 2020 15:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ymB7zugngWO+i0v75OQaFojbIXokcEX7m4aPDvGIWpA=; b=lBCPgL3X0d4c8Vmo0ZuZWTRWW3WIapxdSRAQnvoHI2Sxxv3DtX2hDX2KjZfWH4Trgn 0rKE6UY1uD5gBMTCJSY6d3fSeOcLWzeabq0kEF6JY/6yyFVsb8UAz9ogDtk2KmsFkQcs aZhgr6bUO3xkkIR8udvJdu2N4gGyBGVNOcyOcSgm53FIJ7XX3Tt0vDRUxeTEaC95jixe 3pHodPB6LWadvt7gTvtDUuM6Y6ko76UoEe6yAAFEZ/ahng/EFnIL58my4FEZUkgJtY7E 0ohXBKNPdSlRlySgFl283dOIbOgQ/rp21RfU4aAEzmKQFZv3LOaWlsHErKzQCu0r1BId Pi3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ymB7zugngWO+i0v75OQaFojbIXokcEX7m4aPDvGIWpA=; b=iB7H2ZjFsOMdCZsOipH+hFM1QazLqTLROvU0aSRppRA4MKaV6k1+GvLZlXFrmB2GuG TC2HDN3kEgUo7F6qsF96zb2EW7gsVtvFf89ubffBwDZ1H4djLpdtnhEauV/5pKqcx0yq L8dzocJm14tbqdzBAvfzlHQpBvUORCWGmdSD6ec0qAk1U32mheaUNhlKJ+q+iv/bjWZg TDpr/pAXlhNqIehN/tgT6WPSIg3QcjvyhSt5DhVHtMj2dL2J/zWyv/z6ZudrvcpqWwUj vkkomMUBfSStwPVVKDhzRt1l6XpV4KJd1h5nUfnR8WgW+2qUnLmx+0oM+5UHoQtlxAF3 5R8w== X-Gm-Message-State: AGi0PuZjHV5z9SKwadTU20mYFYppnaHM2+QAOXsXhDCOf5D7QGL9FedW gJqQpNmvTPV/1tAl6mi6GqcFFTz+Hjhkgc/ccsoXGg== X-Google-Smtp-Source: APiQypLQKfsxTw6oNEQ0/qCrbY9Z9lKEm3CAkv02dnCdQhWbO0Sk1oxdeIuoUcw+Jv233nfZDRqMtu3HZ9BpOGNcM+o= X-Received: by 2002:ac2:5dcf:: with SMTP id x15mr3861021lfq.3.1587682792002; Thu, 23 Apr 2020 15:59:52 -0700 (PDT) MIME-Version: 1.0 References: <20200304022058.248270-1-shakeelb@google.com> <20200305204109.be23f5053e2368d3b8ccaa06@linux-foundation.org> In-Reply-To: From: Shakeel Butt Date: Thu, 23 Apr 2020 15:59:41 -0700 Message-ID: Subject: Re: [PATCH] memcg: optimize memory.numa_stat like memory.stat To: Andrew Morton Cc: Johannes Weiner , Roman Gushchin , Michal Hocko , Linux MM , Cgroups , LKML Content-Type: text/plain; charset="UTF-8" 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 Thu, Mar 5, 2020 at 8:54 PM Shakeel Butt wrote: > > On Thu, Mar 5, 2020 at 8:41 PM Andrew Morton wrote: > > > > On Tue, 3 Mar 2020 18:20:58 -0800 Shakeel Butt wrote: > > > > > Currently reading memory.numa_stat traverses the underlying memcg tree > > > multiple times to accumulate the stats to present the hierarchical view > > > of the memcg tree. However the kernel already maintains the hierarchical > > > view of the stats and use it in memory.stat. Just use the same mechanism > > > in memory.numa_stat as well. > > > > > > I ran a simple benchmark which reads root_mem_cgroup's memory.numa_stat > > > file in the presense of 10000 memcgs. The results are: > > > > > > Without the patch: > > > $ time cat /dev/cgroup/memory/memory.numa_stat > /dev/null > > > > > > real 0m0.700s > > > user 0m0.001s > > > sys 0m0.697s > > > > > > With the patch: > > > $ time cat /dev/cgroup/memory/memory.numa_stat > /dev/null > > > > > > real 0m0.001s > > > user 0m0.001s > > > sys 0m0.000s > > > > > > > Can't you do better than that ;) > > > > > > > > + page_state = tree ? lruvec_page_state : lruvec_page_state_local; > > > ... > > > > > > + page_state = tree ? memcg_page_state : memcg_page_state_local; > > > > > > > All four of these functions are inlined. Taking their address in this > > fashion will force the compiler to generate out-of-line copies. > > > > If we do it the uglier-and-maybe-a-bit-slower way: > > > > --- a/mm/memcontrol.c~memcg-optimize-memorynuma_stat-like-memorystat-fix > > +++ a/mm/memcontrol.c > > @@ -3658,17 +3658,16 @@ static unsigned long mem_cgroup_node_nr_ > > struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid)); > > unsigned long nr = 0; > > enum lru_list lru; > > - unsigned long (*page_state)(struct lruvec *lruvec, > > - enum node_stat_item idx); > > > > VM_BUG_ON((unsigned)nid >= nr_node_ids); > > > > - page_state = tree ? lruvec_page_state : lruvec_page_state_local; > > - > > for_each_lru(lru) { > > if (!(BIT(lru) & lru_mask)) > > continue; > > - nr += page_state(lruvec, NR_LRU_BASE + lru); > > + if (tree) > > + nr += lruvec_page_state(lruvec, NR_LRU_BASE + lru); > > + else > > + nr += lruvec_page_state_local(lruvec, NR_LRU_BASE + lru); > > } > > return nr; > > } > > @@ -3679,14 +3678,14 @@ static unsigned long mem_cgroup_nr_lru_p > > { > > unsigned long nr = 0; > > enum lru_list lru; > > - unsigned long (*page_state)(struct mem_cgroup *memcg, int idx); > > - > > - page_state = tree ? memcg_page_state : memcg_page_state_local; > > > > for_each_lru(lru) { > > if (!(BIT(lru) & lru_mask)) > > continue; > > - nr += page_state(memcg, NR_LRU_BASE + lru); > > + if (tree) > > + nr += memcg_page_state(memcg, NR_LRU_BASE + lru); > > + else > > + nr += memcg_page_state_local(memcg, NR_LRU_BASE + lru); > > } > > return nr; > > } > > > > Then we get: > > > > text data bss dec hex filename > > now: 106705 35641 1024 143370 2300a mm/memcontrol.o > > shakeel: 107111 35657 1024 143792 231b0 mm/memcontrol.o > > shakeel+the-above: 106805 35657 1024 143486 2307e mm/memcontrol.o > > > > Which do we prefer? The 100-byte patch or the 406-byte patch? > > I would go with the 100-byte one. The for-loop is just 5 iteration, so > doing a check in each iteration should not be an issue. > Andrew, anything more needed for this patch to be merged? Shakeel