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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 4F5D5C433E4 for ; Thu, 16 Jul 2020 21:28:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0C72A207DD for ; Thu, 16 Jul 2020 21:28:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XGXkGoQr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C72A207DD 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 4A5506B0005; Thu, 16 Jul 2020 17:28:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 455BD6B0006; Thu, 16 Jul 2020 17:28:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 346826B0007; Thu, 16 Jul 2020 17:28:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 1C00C6B0005 for ; Thu, 16 Jul 2020 17:28:48 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9AF04181AEF00 for ; Thu, 16 Jul 2020 21:28:47 +0000 (UTC) X-FDA: 77045228694.29.silk94_0a060a226f05 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 6960918086E25 for ; Thu, 16 Jul 2020 21:28:47 +0000 (UTC) X-HE-Tag: silk94_0a060a226f05 X-Filterd-Recvd-Size: 8122 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Thu, 16 Jul 2020 21:28:46 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id m16so4433070pls.5 for ; Thu, 16 Jul 2020 14:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=VIlti4DdqvC4yQ4DwI6JLsQiEiXC5SNQn8TNQgd556Q=; b=XGXkGoQrH8BP+NW2bw4rDZtLLTOshTUmtiwOatXYDziroYOltnjs4mO+hzUACJMr68 94AeisgKn+w2GWwwkg+O4hPuA2EeL0vq3n5GoSuvCteQF2K7mCQCfzP88WPHY3eoDx8V zGU0BfgWnAeurO6c53/vu6bsJhz3e1ZME0E6I/EcJukxapq1BAPkBcQLKOeQDfWdBYRl vxI4R4/odoFjBs/HtyPKO182ZWO1AVmViDDefMo+FMiPQaDBCmzrjpfEj4UvaiS3mjDc d0tWqb2BH4Hxe6AYcefKCvKC7WqqbeyKUH4/I7UB29TGsC4LAU8EsnXumob7k674zw6A HLCw== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=VIlti4DdqvC4yQ4DwI6JLsQiEiXC5SNQn8TNQgd556Q=; b=KhTgCXWU46fBTOBbdXrZDpgV5Yi5jZxsP2yIIkCuC+RaOpkZhLg7/lg1EU8/YtIfiC jB3Kg+5jxEJ/Oy1U9JGkSf7E0QZ3fca+o8MyW7mSEbZlotFCITvFT6GWQWMD2goA99wy IHa5pznhibZKQMxv1ttQHWoqtomKoy9OKbdfMAml5BcTbiDZrcw21+Rd5etJ4pMP7N90 AyAoNBdlLsY7HJVX7rjpPsKcaCh9pR69xXzFftGLUFI7rB9Ze764N0CYiGWZkQ63qdHp 1xz5C1XHmL5xM0nS+n7h6M2Ouqvn42Ohdl8WIYgbxcJ5LG4/Jxq9jTXQvJAA5hbk2u20 k4yA== X-Gm-Message-State: AOAM533be18atzXB7Jp+e6FOjM+rBkhkFBvRpygOg0gosl71Z06iKDXb zioxEcY4TWEeSZFZ1hib2ZksMw== X-Google-Smtp-Source: ABdhPJxnZqE0IUw08hXKrX+JTvko046ieCDFS0+HatbRMRkZjlkI9ZeY+HG2qRZamdtBQcCO4uNF3Q== X-Received: by 2002:a17:902:b706:: with SMTP id d6mr5094119pls.244.1594934925673; Thu, 16 Jul 2020 14:28:45 -0700 (PDT) Received: from [2620:15c:17:3:4a0f:cfff:fe51:6667] ([2620:15c:17:3:4a0f:cfff:fe51:6667]) by smtp.gmail.com with ESMTPSA id y20sm5473104pfo.170.2020.07.16.14.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 14:28:45 -0700 (PDT) Date: Thu, 16 Jul 2020 14:28:44 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Shakeel Butt cc: SeongJae Park , Andrew Morton , Yang Shi , Michal Hocko , Yang Shi , Roman Gushchin , Greg Thelen , Johannes Weiner , Vladimir Davydov , Cgroups , Linux MM Subject: Re: [patch] mm, memcg: provide an anon_reclaimable stat In-Reply-To: Message-ID: References: <20200715071522.19663-1-sjpark@amazon.com> User-Agent: Alpine 2.23 (DEB 453 2020-06-18) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 6960918086E25 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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, 16 Jul 2020, Shakeel Butt wrote: > > Userspace can lack insight into the amount of memory that can be reclaimed > > from a memcg based on values from memory.stat. Two specific examples: > > > > - Lazy freeable memory (MADV_FREE) that are clean anonymous pages on the > > inactive file LRU that can be quickly reclaimed under memory pressure > > but otherwise shows up as mapped anon in memory.stat, and > > > > - Memory on deferred split queues (thp) that are compound pages that can > > be split and uncharged from the memcg under memory pressure, but > > otherwise shows up as charged anon LRU memory in memory.stat. > > > > Both of this anonymous usage is also charged to memory.current. > > > > Userspace can currently derive this information but it depends on kernel > > implementation details for how this memory is handled for the purposes of > > reclaim (anon on inactive file LRU or unmapped anon on the LRU). > > > > For the purposes of writing portable userspace code that does not need to > > have insight into the kernel implementation for reclaimable memory, this > > exports a stat that reveals the amount of anonymous memory that can be > > reclaimed and uncharged from the memcg to start new applications. > > > > As the kernel implementation evolves for memory that can be reclaimed > > under memory pressure, this stat can be kept consistent. > > > > Signed-off-by: David Rientjes > > --- > > Documentation/admin-guide/cgroup-v2.rst | 6 +++++ > > mm/memcontrol.c | 31 +++++++++++++++++++++++++ > > 2 files changed, 37 insertions(+) > > > > diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst > > --- a/Documentation/admin-guide/cgroup-v2.rst > > +++ b/Documentation/admin-guide/cgroup-v2.rst > > @@ -1296,6 +1296,12 @@ PAGE_SIZE multiple when read back. > > Amount of memory used in anonymous mappings backed by > > transparent hugepages > > > > + anon_reclaimable > > + The amount of charged anonymous memory that can be reclaimed > > + under memory pressure without swap. This currently includes > > + lazy freeable memory (MADV_FREE) and compound pages that can be > > + split and uncharged. > > + > > inactive_anon, active_anon, inactive_file, active_file, unevictable > > Amount of memory, swap-backed and filesystem-backed, > > on the internal memory management lists used by the > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -1350,6 +1350,32 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg) > > return false; > > } > > > > +/* > > + * Returns the amount of anon memory that is charged to the memcg that is > > + * reclaimable under memory pressure without swap, in pages. > > + */ > > +static unsigned long memcg_anon_reclaimable(struct mem_cgroup *memcg) > > +{ > > + long deferred, lazyfree; > > + > > + /* > > + * Deferred pages are charged anonymous pages that are on the LRU but > > + * are unmapped. These compound pages are split under memory pressure. > > + */ > > + deferred = max_t(long, memcg_page_state(memcg, NR_ACTIVE_ANON) + > > + memcg_page_state(memcg, NR_INACTIVE_ANON) - > > + memcg_page_state(memcg, NR_ANON_MAPPED), 0); > > Please note that the NR_ANON_MAPPED does not include tmpfs memory but > NR_[IN]ACTIVE_ANON does include the tmpfs. > > > + /* > > + * Lazyfree pages are charged clean anonymous pages that are on the file > > + * LRU and can be reclaimed under memory pressure. > > + */ > > + lazyfree = max_t(long, memcg_page_state(memcg, NR_ACTIVE_FILE) + > > + memcg_page_state(memcg, NR_INACTIVE_FILE) - > > + memcg_page_state(memcg, NR_FILE_PAGES), 0); > > Similarly NR_FILE_PAGES includes tmpfs memory but NR_[IN]ACTIVE_FILE does not. > Ah, so this adds to the motivation of providing the anon_reclaimable stat because the calculation becomes even more convoluted and completely based on the kernel implementation details for both lazyfree memory and deferred split queues. Did you have a calculation in mind for memcg_anon_reclaimable()? From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Rientjes Subject: Re: [patch] mm, memcg: provide an anon_reclaimable stat Date: Thu, 16 Jul 2020 14:28:44 -0700 (PDT) Message-ID: References: <20200715071522.19663-1-sjpark@amazon.com> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=VIlti4DdqvC4yQ4DwI6JLsQiEiXC5SNQn8TNQgd556Q=; b=XGXkGoQrH8BP+NW2bw4rDZtLLTOshTUmtiwOatXYDziroYOltnjs4mO+hzUACJMr68 94AeisgKn+w2GWwwkg+O4hPuA2EeL0vq3n5GoSuvCteQF2K7mCQCfzP88WPHY3eoDx8V zGU0BfgWnAeurO6c53/vu6bsJhz3e1ZME0E6I/EcJukxapq1BAPkBcQLKOeQDfWdBYRl vxI4R4/odoFjBs/HtyPKO182ZWO1AVmViDDefMo+FMiPQaDBCmzrjpfEj4UvaiS3mjDc d0tWqb2BH4Hxe6AYcefKCvKC7WqqbeyKUH4/I7UB29TGsC4LAU8EsnXumob7k674zw6A HLCw== In-Reply-To: Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Shakeel Butt Cc: SeongJae Park , Andrew Morton , Yang Shi , Michal Hocko , Yang Shi , Roman Gushchin , Greg Thelen , Johannes Weiner , Vladimir Davydov , Cgroups , Linux MM On Thu, 16 Jul 2020, Shakeel Butt wrote: > > Userspace can lack insight into the amount of memory that can be reclaimed > > from a memcg based on values from memory.stat. Two specific examples: > > > > - Lazy freeable memory (MADV_FREE) that are clean anonymous pages on the > > inactive file LRU that can be quickly reclaimed under memory pressure > > but otherwise shows up as mapped anon in memory.stat, and > > > > - Memory on deferred split queues (thp) that are compound pages that can > > be split and uncharged from the memcg under memory pressure, but > > otherwise shows up as charged anon LRU memory in memory.stat. > > > > Both of this anonymous usage is also charged to memory.current. > > > > Userspace can currently derive this information but it depends on kernel > > implementation details for how this memory is handled for the purposes of > > reclaim (anon on inactive file LRU or unmapped anon on the LRU). > > > > For the purposes of writing portable userspace code that does not need to > > have insight into the kernel implementation for reclaimable memory, this > > exports a stat that reveals the amount of anonymous memory that can be > > reclaimed and uncharged from the memcg to start new applications. > > > > As the kernel implementation evolves for memory that can be reclaimed > > under memory pressure, this stat can be kept consistent. > > > > Signed-off-by: David Rientjes > > --- > > Documentation/admin-guide/cgroup-v2.rst | 6 +++++ > > mm/memcontrol.c | 31 +++++++++++++++++++++++++ > > 2 files changed, 37 insertions(+) > > > > diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst > > --- a/Documentation/admin-guide/cgroup-v2.rst > > +++ b/Documentation/admin-guide/cgroup-v2.rst > > @@ -1296,6 +1296,12 @@ PAGE_SIZE multiple when read back. > > Amount of memory used in anonymous mappings backed by > > transparent hugepages > > > > + anon_reclaimable > > + The amount of charged anonymous memory that can be reclaimed > > + under memory pressure without swap. This currently includes > > + lazy freeable memory (MADV_FREE) and compound pages that can be > > + split and uncharged. > > + > > inactive_anon, active_anon, inactive_file, active_file, unevictable > > Amount of memory, swap-backed and filesystem-backed, > > on the internal memory management lists used by the > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -1350,6 +1350,32 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg) > > return false; > > } > > > > +/* > > + * Returns the amount of anon memory that is charged to the memcg that is > > + * reclaimable under memory pressure without swap, in pages. > > + */ > > +static unsigned long memcg_anon_reclaimable(struct mem_cgroup *memcg) > > +{ > > + long deferred, lazyfree; > > + > > + /* > > + * Deferred pages are charged anonymous pages that are on the LRU but > > + * are unmapped. These compound pages are split under memory pressure. > > + */ > > + deferred = max_t(long, memcg_page_state(memcg, NR_ACTIVE_ANON) + > > + memcg_page_state(memcg, NR_INACTIVE_ANON) - > > + memcg_page_state(memcg, NR_ANON_MAPPED), 0); > > Please note that the NR_ANON_MAPPED does not include tmpfs memory but > NR_[IN]ACTIVE_ANON does include the tmpfs. > > > + /* > > + * Lazyfree pages are charged clean anonymous pages that are on the file > > + * LRU and can be reclaimed under memory pressure. > > + */ > > + lazyfree = max_t(long, memcg_page_state(memcg, NR_ACTIVE_FILE) + > > + memcg_page_state(memcg, NR_INACTIVE_FILE) - > > + memcg_page_state(memcg, NR_FILE_PAGES), 0); > > Similarly NR_FILE_PAGES includes tmpfs memory but NR_[IN]ACTIVE_FILE does not. > Ah, so this adds to the motivation of providing the anon_reclaimable stat because the calculation becomes even more convoluted and completely based on the kernel implementation details for both lazyfree memory and deferred split queues. Did you have a calculation in mind for memcg_anon_reclaimable()?