Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1051706pxb; Thu, 28 Jan 2021 07:02:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbnruvx+25KzadnEpHKLSuj6CJFw1VBN/YCGj662D4xPBXyCxuaa/apDbpW80iPAOROICS X-Received: by 2002:a5d:5112:: with SMTP id s18mr16576398wrt.267.1611846159050; Thu, 28 Jan 2021 07:02:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611846159; cv=none; d=google.com; s=arc-20160816; b=0v5PF3t/AabOSCvkh7Pw3yGe7/YPoixe9MFY6gycO4hPlPfglhtvjXF07enUJGliaU 0F6f0RjwmN/XqNzg5yoYt5nOiJZx63MkEgq2Q1UswQgXB4UZcDYcnVqg1p1qi9wKwoyB q93LHES86+sV9Q+4EVGlEvfUrg4EV8sFHExBFu9UYZ3BCMoFteTxqs8qIS3vwNOsbjBM yeYBcElVzKuByoKXP7pmimFKT232tJsyhVtgTcJIc39XdSoiBydUuhYfkj4cKfV5reMI Mu5NExzpLKJuiypDdESgrWtZZtr4mTKZC+xU8yvalkKMaxFfCM2SB+KX+uwLHFP+0zyU xmFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=6JeWN8a5WUkyxnK36YoF5ECUYQ0YQQyZ8/Qna1NsShQ=; b=HiyLkXLgf+ai5kWEwqUhzzoBRf0tjUyCQq2jJN/hQWfRk6hUTmchRG6z1f+lDFQkWE 0K5IMLi2fbLdA6sSiS9TA6n4Wm9sz7QA6W6+x5/kvRN3k2GJdIV9biHLG8dSQZaQxVRk WUhfXy+bCoI+Yg2i1sowG9LP3Lcy0rDF+06RmdMc5Hc6xm5SiPH7c5YXeqCJWah/wMuc NDAAEERjtPvL1ea3M9/HcYLsYPEVo29Q9FCr/Faa8CXLa67/u7JhsEK2IxYeV183CmMb aulTi7dVPPI8d4ZrjTpy8xBT6buEBQfZUW1W2Wrl9Qug+y2STTv7+UpQZW/wUQ+Xra0/ zqow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=As0f3Zjd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n16si3139695edt.539.2021.01.28.07.02.13; Thu, 28 Jan 2021 07:02:39 -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=@google.com header.s=20161025 header.b=As0f3Zjd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231866AbhA1O6w (ORCPT + 99 others); Thu, 28 Jan 2021 09:58:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231932AbhA1O6Z (ORCPT ); Thu, 28 Jan 2021 09:58:25 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6A9CC061786 for ; Thu, 28 Jan 2021 06:57:44 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id h12so7947218lfp.9 for ; Thu, 28 Jan 2021 06:57:44 -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=6JeWN8a5WUkyxnK36YoF5ECUYQ0YQQyZ8/Qna1NsShQ=; b=As0f3ZjdzvdCwifWZLl1QKfjKa8UOgbj+P2sZklA3JeJHRBFMWu0H5wiflr7/g1HdC 3EjIecN6Px4mzk2ZBILkQfelKQTbnGwSzIocfdSMYIkirHo9CBbLzSIMXutUiAf6vvRc O/x3qpP8hsiEOTbNWqSjQJEQy2deXqGIeKK1Eiy110fgfCnqxwFB41oeOrAJr2xWvT1q RtaTVjDEtI0m7Z5lSQoJRTOt4f3/Vop3rVyNg7HaTwp/ta+UInes3JfxoRBzhApQcJVC zRX0Gbp2enO00BN0CoZKSrEiJpykCEajRuhij0lcxoYUBrveBZExa8KzS9ylf7cYTei3 czvA== 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=6JeWN8a5WUkyxnK36YoF5ECUYQ0YQQyZ8/Qna1NsShQ=; b=H42f1eYvN21K0ZQf9pvEmTDEafgRT3q+UwJmi8tm+b0JkPg4+lbY6HH62+gEuVqsD4 jPj5ZRvxSSMNb3aJSdrsgvy0ajzLfg4AHGjDORCw8L9a+OEGP0HxvyOooGVCfHHq0ZSB ULV3y0evmNZ96OLEqiH1ZLRl9k3eop9j63cDQvx7LnmDWARfja7dQQPnmt0wYiU/YOng gmFjkiejNTLCwkh96FuA4jGTknAZ+khekj15Q9GiWEqAuk9hWg0nQJ11ct4VgzxNKKF3 iRrwDhQIY0MCT1/k4jqCShFe0bFTNepnyCGB4gMOoganENmyAE/+iaPWVSquJFQM5+Aq 5vGA== X-Gm-Message-State: AOAM533PZPpHY3QCBvvwCt9+Dip04q0aqW92tPo9RfQMvI+3GSfL78W6 rG3q+J73eg0/4pvV6lU1mPCOxjP4kvxuEl/5hB7w1w== X-Received: by 2002:ac2:4c26:: with SMTP id u6mr7622497lfq.347.1611845862683; Thu, 28 Jan 2021 06:57:42 -0800 (PST) MIME-Version: 1.0 References: <20210121122723.3446-1-rppt@kernel.org> <20210121122723.3446-9-rppt@kernel.org> <20210125165451.GT827@dhcp22.suse.cz> <20210125213817.GM6332@kernel.org> <20210126144838.GL308988@casper.infradead.org> <20210126150555.GU827@dhcp22.suse.cz> <20210127184213.GA919963@carbon.dhcp.thefacebook.com> In-Reply-To: From: Shakeel Butt Date: Thu, 28 Jan 2021 06:57:31 -0800 Message-ID: Subject: Re: [PATCH v16 08/11] secretmem: add memcg accounting To: Michal Hocko Cc: Roman Gushchin , Matthew Wilcox , Mike Rapoport , 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" , Mark Rutland , Mike Rapoport , Michael Kerrisk , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rick Edgecombe , 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, Hagen Paul Pfeifer , Palmer Dabbelt Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 28, 2021 at 6:22 AM Michal Hocko wrote: > > On Thu 28-01-21 06:05:11, Shakeel Butt wrote: > > On Wed, Jan 27, 2021 at 11:59 PM Michal Hocko wrote: > > > > > > On Wed 27-01-21 10:42:13, Roman Gushchin wrote: > > > > On Tue, Jan 26, 2021 at 04:05:55PM +0100, Michal Hocko wrote: > > > > > On Tue 26-01-21 14:48:38, Matthew Wilcox wrote: > > > > > > On Mon, Jan 25, 2021 at 11:38:17PM +0200, Mike Rapoport wrote: > > > > > > > I cannot use __GFP_ACCOUNT because cma_alloc() does not use gfp. > > > > > > > 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/ > > > > > > > > > > > > > > As for (ab)using NR_SLAB_UNRECLAIMABLE_B, as it was already discussed here: > > > > > > > > > > > > > > https://lore.kernel.org/lkml/20201129172625.GD557259@kernel.org/ > > > > > > > > > > > > > > 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. > > > > > > > > > > > > That's not true -- Mlocked is also unreclaimable. And doesn't this > > > > > > feel more like mlocked memory than unreclaimable slab? It's also > > > > > > Unevictable, so could be counted there instead. > > > > > > > > > > yes, that is indeed true, except the unreclaimable counter is tracking > > > > > the unevictable LRUs. These pages are not on any LRU and that can cause > > > > > some confusion. Maybe they shouldn't be so special and they should live > > > > > on unevistable LRU and get their stats automagically. > > > > > > > > > > I definitely do agree that this would be a better fit than NR_SLAB > > > > > abuse. But considering that this is somehow even more special than mlock > > > > > then a dedicated counter sounds as even better fit. > > > > > > > > I think it depends on how large these areas will be in practice. > > > > If they will be measured in single or double digits MBs, a separate entry > > > > is hardly a good choice: because of the batching the displayed value > > > > will be in the noise range, plus every new vmstat item adds to the > > > > struct mem_cgroup size. > > > > > > > > If it will be measured in GBs, of course, a separate counter is preferred. > > > > So I'd suggest to go with NR_SLAB (which should have been named NR_KMEM) > > > > as now and conditionally switch to a separate counter later. > > > > > > I really do not think the overall usage matters when it comes to abusing > > > other counters. Changing this in future will be always tricky and there > > > always be our favorite "Can this break userspace" question. Yes we dared > > > to change meaning of some counters but this is not generally possible. > > > Just have a look how accounting shmem as a page cache has turned out > > > being much more tricky than many like. > > > > > > Really if a separate counter is a big deal, for which I do not see any > > > big reason, then this should be accounted as unevictable (as suggested > > > by Matthew) and ideally pages of those mappings should be sitting in the > > > unevictable LRU as well unless there is a strong reason against. > > > > > > > Why not decide based on the movability of these pages? If movable then > > unevictable LRU seems like the right way otherwise NR_SLAB. > > I really do not follow. If the page is unevictable then why movability > matters? My point was if these pages are very much similar to our existing definition of unevictable LRU pages then it makes more sense to account for these pages into unevictable stat. > I also fail to see why NR_SLAB is even considered considering > this is completely outside of slab proper. > > Really what is the point? What are we trying to achieve by stats? Do we > want to know how much secret memory is used because that is an > interesting/important information or do we just want to make some > accounting? > > Just think at it from a practical point of view. I want to know how much > slab memory is used because it can give me an idea whether kernel is > consuming unexpected amount of memory. Now I have to subtract _some_ > number to get that information. Where do I get that some number? > > We have been creative with counters and it tends to kick back much more > often than it helps. > > I really do not want this to turn into an endless bike shed but either > this should be accounted as a general type of memory (unevictable would > be a good fit because that is a userspace memory which is not > reclaimable) or it needs its own counter to tell how much of this > specific type of memory is used for this purpose. > I suggested having a separate counter in the previous version but got shot down based on the not-yet-clear benefit of a separate stat for it. There is also an option to not add new or use existing stat at this moment. As there will be more clear use-cases and usage of secretmem, adding a new stat at that time would be much simpler than changing the definition of existing stats.