Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4082440pxb; Tue, 26 Jan 2021 11:55:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzW2zoMu0lbDIwUmlIWy331wvpq3/E5tUXGmTszXs9pNEs7PrpAkLv6v8bSnEMdQmzcHVtI X-Received: by 2002:a17:906:1741:: with SMTP id d1mr4647494eje.182.1611690940281; Tue, 26 Jan 2021 11:55:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611690940; cv=none; d=google.com; s=arc-20160816; b=e4l0yP2m4rNk6u4yOSk+4wEwbLUwo1Szs51QjXva6edm6wUFMoz06kUt0hVJTeobP2 /a6hYykcFJihzO340J10eJt85Imi+f6eupwniTjmKkTmmawbnU8K0XmvtxFkY0AUUnB2 8MZfDwQX6nOh7l17w7dBWzBr+qid/gjypgC/+CxMtnVP9sxc4VUNFzknVwygx8k2XEAz 5Cq3RHmJ0/G1m1zDtvs5y1SX7045RY20xkA+oOS5GZRNPwcpB312HitApITWwrtiZeyt mPrYQSOtHz61O14LM0ugjLBc8ZtT58Sj4P3yarQbotBXlpeR0XC1xuqEGUwb4xs1SL90 pfhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7zMRtj92K4aLVsKF/LtuTzpzMNc9rmo/TxWykS3K0E0=; b=McFeWdMDi0TanyevZOelgr4Jk8bDSAOGlXYkyD6cQq2oNk68x/ZFUigc7iPFG9207O NEY2KHAauWbaS39dbE70shezs7WSFXeWtTGOwZP3JgnN3Tj1bi4A/bZgc4yRIHKgbaHS 652BA584N1Uv/NGtdjfG3depwEq4O8t1/Qa1NqOUYV8FCXyYyofu3itM9Hv3nOmLIYJZ 88D3O2eZsFYYosKvZ3XBqLNb9pULekFTNtI+411Re82ksafN1wugofD7RvzqGxYG/zGN T8TaipjTd0duDYAzkejs8jihThl/z3wr/kCzvztHa9xO8CV3L4L4HIwlryyjBOujgopB KOmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fbzVzS60; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z1si9114214edp.150.2021.01.26.11.55.13; Tue, 26 Jan 2021 11:55:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fbzVzS60; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727342AbhAZR2G (ORCPT + 99 others); Tue, 26 Jan 2021 12:28:06 -0500 Received: from mx2.suse.de ([195.135.220.15]:53364 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729658AbhAZHfy (ORCPT ); Tue, 26 Jan 2021 02:35:54 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1611646304; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7zMRtj92K4aLVsKF/LtuTzpzMNc9rmo/TxWykS3K0E0=; b=fbzVzS60+bW4/eLvVlMg8GidpFB1jBrR7hcptqrY8DOrxY95Wqr6BYjafHEM6FDX7G5i/a 47NUGFfcrm6l+Of7J1sWw4Lzuue/Bl54LKMg59hi6hWCs5djiniqInQ7mh6N/vOqeVmO+1 dcHiiymtcGUHsS6UXafRNc9p1dmXURc= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3F491AE61; Tue, 26 Jan 2021 07:31:44 +0000 (UTC) Date: Tue, 26 Jan 2021 08:31:42 +0100 From: Michal Hocko 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 , Shakeel Butt , 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@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-nvdimm@lists.01.org, linux-riscv@lists.infradead.org, x86@kernel.org, Hagen Paul Pfeifer , Palmer Dabbelt Subject: Re: [PATCH v16 08/11] secretmem: add memcg accounting Message-ID: <20210126073142.GY827@dhcp22.suse.cz> References: <20210121122723.3446-1-rppt@kernel.org> <20210121122723.3446-9-rppt@kernel.org> <20210125165451.GT827@dhcp22.suse.cz> <20210125213817.GM6332@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210125213817.GM6332@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 25-01-21 23:38:17, Mike Rapoport wrote: > On Mon, Jan 25, 2021 at 05:54:51PM +0100, Michal Hocko wrote: > > On Thu 21-01-21 14:27:20, 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. > > > > What does this mean? > > That means that the accounting is updated when secretmem does cma_alloc() > and cma_relase(). > > > What are the lifetime rules? > > Hmm, what do you mean by lifetime rules? OK, so let's start by reservation time (mmap time right?) then the instantiation time (faulting in memory). What if the calling process of the former has a different memcg context than the later. E.g. when you send your fd or inherited fd over fork will move to a different memcg. What about freeing path? E.g. when you punch a hole in the middle of a mapping? Please make sure to document all this. > > [...] > > > > > +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); > > > > A lot of memcg accounted memory is not reclaimable. Why do you abuse > > SLAB counter when this is not a slab owned memory? Why do you use the > > kmem accounting API when __GFP_ACCOUNT should give you the same without > > this details? > > I cannot use __GFP_ACCOUNT because cma_alloc() does not use gfp. Other people are working on this to change. But OK, I do see that this can be done later but it looks rather awkward. > Besides, kmem accounting with __GFP_ACCOUNT does not seem > to update stats and there was an explicit request for statistics: > > https://lore.kernel.org/lkml/CALo0P13aq3GsONnZrksZNU9RtfhMsZXGWhK1n=xYJWQizCd4Zw@mail.gmail.com/ charging and stats are two different things. You can still take care of your stats without explicitly using the charging API. But this is a mere detail. It just hit my eyes. > As for (ab)using NR_SLAB_UNRECLAIMABLE_B, as it was already discussed here: > > https://lore.kernel.org/lkml/20201129172625.GD557259@kernel.org/ Those arguments should be a part of the changelof. > I think that a dedicated stats counter would be too much at the moment and > NR_SLAB_UNRECLAIMABLE_B is the only explicit stat for unreclaimable memory. Why do you think it would be too much? If the secret memory becomes a prevalent memory user because it will happen to back the whole virtual machine then hiding it into any existing counter would be less than useful. Please note that this all is a user visible stuff that will become PITA (if possible) to change later on. You should really have strong arguments in your justification here. -- Michal Hocko SUSE Labs