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=-20.5 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_IN_DEF_DKIM_WL 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 436D0C3E8C5 for ; Sun, 29 Nov 2020 15:54:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AF1392084C for ; Sun, 29 Nov 2020 15:54:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="isTAhbDa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF1392084C 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 E2B0D6B005C; Sun, 29 Nov 2020 10:53:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDAE16B005D; Sun, 29 Nov 2020 10:53:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF4146B0068; Sun, 29 Nov 2020 10:53:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id BB36A6B005C for ; Sun, 29 Nov 2020 10:53:59 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 77B968249980 for ; Sun, 29 Nov 2020 15:53:59 +0000 (UTC) X-FDA: 77537901798.22.bike50_3c007882739a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 4A10018038E6A for ; Sun, 29 Nov 2020 15:53:59 +0000 (UTC) X-HE-Tag: bike50_3c007882739a X-Filterd-Recvd-Size: 8102 Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Sun, 29 Nov 2020 15:53:58 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id d20so15591322lfe.11 for ; Sun, 29 Nov 2020 07:53:58 -0800 (PST) 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=3PuJ9ydxTViJxhC8bUeJS1Nnpydv/VEM9Wi1gMrMaBs=; b=isTAhbDaUuUXk1VQ3ndJOQ/CuS5MKUiZU9CQF6PymdXpFUOWrtmdwQbOetQXqfuYcu DN+OBA9qL3A9IiYDok2MOFG354WJgz9qAUvm/bYWWVPi9WyZ1PJ1lNfGjJRLoAZLO2Vg uRTzD4pVG+cV2/ymy6+tsxqoVguJfYNDW/2RvIvgoZeWEzlw11EW3XkkvoYk35tVWwPn HfZCQVeqGtpyFhpd4OUy9FJVmyQdiOL8EaFCqmL+9cNs+NvTNNL4303WZgB9szddFdV8 BfgLnmnM0DdbVQ1i8kfeHCJ1NEzilifWALzo17ajgIx/BZAN0Q0Iv6ejITAt4NtpIu5W GSXQ== 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=3PuJ9ydxTViJxhC8bUeJS1Nnpydv/VEM9Wi1gMrMaBs=; b=Id/qReyvrsjSqRMb7BpGvMlK3IojKhP0KWUhMpfnmeGOvkfcbf5QUNqh5VxGELkMim dltiNsyjKVPRq2bwzDf0rUX+WmEHo9/xREPZ4j6PwFXe0+CS4acgs3vIJpWdDd857jtK bDQYWUeS97i/bT6EsFLePaOWA8MYYGwlGuAJlUa/WFor4ip3h8xnMJdCFpRz1Ak8tHRZ psElktFSIdkvEq9eRXwB4RcpSxtlZD9+fZsLcvqDvAD+1nv7BBI8B4uBZDNl/h2giBmP vcOYXIduTZHVkaio4slbWjbrfLhXGLnAfs3EVmEiNfJFvnp3+0riShleuQ2qCZu4+Gh7 gjMw== X-Gm-Message-State: AOAM531JlLFYRrr7k3WujDfc9/+kqTbmB2ZeKfgsZCrv36lfmnm52a8z 5IflyQ0YVZUe9YcMwHVcW53P13WhRbxJF9LHQ86MOA== X-Google-Smtp-Source: ABdhPJzudR+9Ib3gs3Y02i4BAQQW5kNsVm6Yid+szIpP/1AQJ9ils7ZN++n24NpQOPLTFTgkysS30jlcr9Wp5KFuvz0= X-Received: by 2002:ac2:43b1:: with SMTP id t17mr7446330lfl.385.1606665236632; Sun, 29 Nov 2020 07:53:56 -0800 (PST) MIME-Version: 1.0 References: <20201125092208.12544-1-rppt@kernel.org> <20201125092208.12544-8-rppt@kernel.org> In-Reply-To: <20201125092208.12544-8-rppt@kernel.org> From: Shakeel Butt Date: Sun, 29 Nov 2020 07:53:45 -0800 Message-ID: Subject: Re: [PATCH v12 07/10] secretmem: add memcg accounting To: Mike Rapoport Cc: Andrew Morton , Alexander Viro , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christopher Lameter , Dan Williams , Dave Hansen , David Hildenbrand , Elena Reshetova , "H. Peter Anvin" , Ingo Molnar , James Bottomley , "Kirill A. Shutemov" , Matthew Wilcox , Mark Rutland , Mike Rapoport , Michael Kerrisk , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rick Edgecombe , Roman Gushchin , Shuah Khan , Thomas Gleixner , Tycho Andersen , Will Deacon , linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel , Linux MM , LKML , linux-kselftest@vger.kernel.org, linux-nvdimm@lists.01.org, linux-riscv@lists.infradead.org, x86@kernel.org 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 Wed, Nov 25, 2020 at 1:51 AM Mike Rapoport wrote: > > From: Mike Rapoport > > Account memory consumed by secretmem to memcg. The accounting is updated > when the memory is actually allocated and freed. > > Signed-off-by: Mike Rapoport > Acked-by: Roman Gushchin > --- > mm/filemap.c | 3 ++- > mm/secretmem.c | 36 +++++++++++++++++++++++++++++++++++- > 2 files changed, 37 insertions(+), 2 deletions(-) > > diff --git a/mm/filemap.c b/mm/filemap.c > index 249cf489f5df..cf7f1dc9f4b8 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -42,6 +42,7 @@ > #include > #include > #include > +#include > #include "internal.h" > > #define CREATE_TRACE_POINTS > @@ -844,7 +845,7 @@ static noinline int __add_to_page_cache_locked(struct page *page, > page->mapping = mapping; > page->index = offset; > > - if (!huge) { > + if (!huge && !page_is_secretmem(page)) { > error = mem_cgroup_charge(page, current->mm, gfp); > if (error) > goto error; > diff --git a/mm/secretmem.c b/mm/secretmem.c > index 52a900a135a5..eb6628390444 100644 > --- a/mm/secretmem.c > +++ b/mm/secretmem.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -44,6 +45,32 @@ struct secretmem_ctx { > > static struct cma *secretmem_cma; > > +static int secretmem_account_pages(struct page *page, gfp_t gfp, int order) > +{ > + int err; > + > + err = memcg_kmem_charge_page(page, gfp, order); > + if (err) > + return err; > + > + /* > + * seceremem caches are unreclaimable kernel allocations, so treat > + * them as unreclaimable slab memory for VM statistics purposes > + */ > + mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE_B, > + PAGE_SIZE << order); Please use mod_lruvec_page_state() instead, so we get the memcg stats too. BTW I think secretmem deserves a vmstat entry instead of overloading NR_SLAB_UNRECLAIMABLE_B. > + > + return 0; > +} > + > +static void secretmem_unaccount_pages(struct page *page, int order) > +{ > + > + mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE_B, > + -PAGE_SIZE << order); > + memcg_kmem_uncharge_page(page, order); > +} > + > static int secretmem_pool_increase(struct secretmem_ctx *ctx, gfp_t gfp) > { > unsigned long nr_pages = (1 << PMD_PAGE_ORDER); > @@ -56,10 +83,14 @@ static int secretmem_pool_increase(struct secretmem_ctx *ctx, gfp_t gfp) > if (!page) > return -ENOMEM; > > - err = set_direct_map_invalid_noflush(page, nr_pages); > + err = secretmem_account_pages(page, gfp, PMD_PAGE_ORDER); > if (err) > goto err_cma_release; > > + err = set_direct_map_invalid_noflush(page, nr_pages); > + if (err) > + goto err_memcg_uncharge; > + > addr = (unsigned long)page_address(page); > err = gen_pool_add(pool, addr, PMD_SIZE, NUMA_NO_NODE); > if (err) > @@ -76,6 +107,8 @@ static int secretmem_pool_increase(struct secretmem_ctx *ctx, gfp_t gfp) > * won't fail > */ > set_direct_map_default_noflush(page, nr_pages); > +err_memcg_uncharge: > + secretmem_unaccount_pages(page, PMD_PAGE_ORDER); > err_cma_release: > cma_release(secretmem_cma, page, nr_pages); > return err; > @@ -302,6 +335,7 @@ static void secretmem_cleanup_chunk(struct gen_pool *pool, > int i; > > set_direct_map_default_noflush(page, nr_pages); > + secretmem_unaccount_pages(page, PMD_PAGE_ORDER); > > for (i = 0; i < nr_pages; i++) > clear_highpage(page + i); > -- > 2.28.0 >