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.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 5C1B3C64E7A for ; Tue, 1 Dec 2020 16:45:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0738420758 for ; Tue, 1 Dec 2020 16:45:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="gvfnhaSL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727193AbgLAQpW (ORCPT ); Tue, 1 Dec 2020 11:45:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:59542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728720AbgLAQpW (ORCPT ); Tue, 1 Dec 2020 11:45:22 -0500 Received: from kernel.org (unknown [87.71.85.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DAF89206B7; Tue, 1 Dec 2020 16:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606841081; bh=GUtX0hNx32YEEtCdAUkzC5OF7zPy+e78biDig6Frozg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gvfnhaSLv1jMRih6i9BkZFwqT83+9p5JD98gXcO7JIrkTzOBB+rRro5U9QgAxqQSV 7dt/xWjtLVQEVt1Ex5jrQh1zNLQMN4ovnZ42jokTz+d8CL1J4Neq9s1+q39AS5euFb +V52ld2bkVC2Nmbbgl6GFHYT0sShRwKokRlnOllM= Date: Tue, 1 Dec 2020 18:44:24 +0200 From: Mike Rapoport To: Shakeel Butt 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 Subject: Re: [PATCH v13 07/10] secretmem: add memcg accounting Message-ID: <20201201164424.GC751215@kernel.org> References: <20201201074559.27742-1-rppt@kernel.org> <20201201074559.27742-8-rppt@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Tue, Dec 01, 2020 at 08:26:28AM -0800, Shakeel Butt wrote: > On Mon, Nov 30, 2020 at 11:47 PM 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..5e3e5102ad4c 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_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, > > + PAGE_SIZE << order); > > + > > + 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); > > mod_lruvec_page_state() Argh... Will fix. > > + 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 > > -- Sincerely yours, Mike.