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.6 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_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 7AC02C433E2 for ; Thu, 16 Jul 2020 21:07:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3B8C8207DD for ; Thu, 16 Jul 2020 21:07:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="StyuY3xC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B8C8207DD 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 8CC0D8D0011; Thu, 16 Jul 2020 17:07:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87CAA8D0003; Thu, 16 Jul 2020 17:07:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76C2C8D0011; Thu, 16 Jul 2020 17:07:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0033.hostedemail.com [216.40.44.33]) by kanga.kvack.org (Postfix) with ESMTP id 5DFC48D0003 for ; Thu, 16 Jul 2020 17:07:27 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DD752127B for ; Thu, 16 Jul 2020 21:07:26 +0000 (UTC) X-FDA: 77045174892.19.jewel27_1e0b92a26f05 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id AE26F1AD1B7 for ; Thu, 16 Jul 2020 21:07:26 +0000 (UTC) X-HE-Tag: jewel27_1e0b92a26f05 X-Filterd-Recvd-Size: 7146 Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Thu, 16 Jul 2020 21:07:26 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id o4so4704681lfi.7 for ; Thu, 16 Jul 2020 14:07:26 -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=GhmDaILswOyhVmyQVKz/Z67YTyZBy2pEH48DYKPsglc=; b=StyuY3xC0ybEf9QINn+RLCRsWzzEN/szSnXWiOqdTmdW3ZAel0T/Sj3SEJBKB97mgj anlMNSLshuKogTtaoTG5cp+JfZ/3QcoR052KjfsH/tGzTh84cQG/fqKQSxaQHh0CDcog z+PXiPEBETIqEpFh+qwbaST05eRFXoWXt6YhcCvf9KsfmZzPfvEdXwYbnmqQ8jLyJlRz CCDpJsSJeB7LZH9gMUrJSVky6IAEw3NqNRinv9GmhlGUN1GdUzuUe3vKNQhqMjPOE8x+ iaDYXyHTDrsdZj4M9EjwhCejQQdE71k+YZ1/XFUaCiYpXlvL5bdm9aIrjrctvM1cp40o SKrA== 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=GhmDaILswOyhVmyQVKz/Z67YTyZBy2pEH48DYKPsglc=; b=jnXtITyzA/xoVBkMFlD7FfH1BmyKdt8QHaGUnazzhJBmuKauEtWLiZnHmt6BOZE2BR 4FH8uILQU8ldEisEDB2E6ENPOgtZdDMkhRQK1UePPQeq+PTNj1lohm3hRvRhrLuMVlsk u3qeKAQaEbaXTAxXR+HT+NYO0FWlOxXYPmE2/sTcqMpTeyFaCgr0Zd3UwLcHfcXtMAWk awZSNQY/Ne8dIQr84P515FnlP5ufhBwJHsICZLVQmGvuKk9v15qnAgyBEN7KF+eiClDf 5fRAqPCbMivDOGxFWSi/DTU1YjgNjEXCo90OHv6g0JBc3BVarMaTrPud7kEXuNzFP4ea MRbA== X-Gm-Message-State: AOAM533iOsKyAm13AECOuhZhGbCyOYzuwMeogvEqSs0B7p3UZASc+WUK 8dhXMnQFtAT9ykouRvIuQdgQ0PiHXNJBaBs9FCUMqQ== X-Google-Smtp-Source: ABdhPJxJ8X8NYyUdZh6Qz2L6YvnD2ZNiBBysvaXRqhZDv4vhxV1qwjb8wEgBFdcV/Jg8h1AkcYhYzCHH7gk1brgG0QM= X-Received: by 2002:ac2:4183:: with SMTP id z3mr241606lfh.3.1594933644436; Thu, 16 Jul 2020 14:07:24 -0700 (PDT) MIME-Version: 1.0 References: <20200715071522.19663-1-sjpark@amazon.com> In-Reply-To: From: Shakeel Butt Date: Thu, 16 Jul 2020 14:07:13 -0700 Message-ID: Subject: Re: [patch] mm, memcg: provide an anon_reclaimable stat To: David Rientjes Cc: SeongJae Park , Andrew Morton , Yang Shi , Michal Hocko , Yang Shi , Roman Gushchin , Greg Thelen , Johannes Weiner , Vladimir Davydov , Cgroups , Linux MM Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: AE26F1AD1B7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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, Jul 16, 2020 at 1:58 PM David Rientjes 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. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shakeel Butt Subject: Re: [patch] mm, memcg: provide an anon_reclaimable stat Date: Thu, 16 Jul 2020 14:07:13 -0700 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=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GhmDaILswOyhVmyQVKz/Z67YTyZBy2pEH48DYKPsglc=; b=StyuY3xC0ybEf9QINn+RLCRsWzzEN/szSnXWiOqdTmdW3ZAel0T/Sj3SEJBKB97mgj anlMNSLshuKogTtaoTG5cp+JfZ/3QcoR052KjfsH/tGzTh84cQG/fqKQSxaQHh0CDcog z+PXiPEBETIqEpFh+qwbaST05eRFXoWXt6YhcCvf9KsfmZzPfvEdXwYbnmqQ8jLyJlRz CCDpJsSJeB7LZH9gMUrJSVky6IAEw3NqNRinv9GmhlGUN1GdUzuUe3vKNQhqMjPOE8x+ iaDYXyHTDrsdZj4M9EjwhCejQQdE71k+YZ1/XFUaCiYpXlvL5bdm9aIrjrctvM1cp40o SKrA== In-Reply-To: Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: David Rientjes Cc: SeongJae Park , Andrew Morton , Yang Shi , Michal Hocko , Yang Shi , Roman Gushchin , Greg Thelen , Johannes Weiner , Vladimir Davydov , Cgroups , Linux MM On Thu, Jul 16, 2020 at 1:58 PM David Rientjes 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.