Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1996043pxb; Mon, 11 Oct 2021 18:24:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy28rRFizeR0oxZQrrq5s0OpvgQDs0tUFDhoId2NMPe/vW+H4XG1jsT0KCKHf1zYbPG8od8 X-Received: by 2002:a05:6402:5249:: with SMTP id t9mr47282445edd.135.1634001895003; Mon, 11 Oct 2021 18:24:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634001894; cv=none; d=google.com; s=arc-20160816; b=ma92btMTphJJtLALGDhmHao63OMwsn24ebjCU+5pf1FZVkct8MZ6PfaXSXx4UN9NuH mQFkSvTeuFQ0nnEY3JxFDN6N8PbGtCS+Htrps7SKDR9LtEZ5vaDudxeWLQaaxDqcUyBi GJ2lY6XuOZWQCr8/aFuL9gqjuiwcqaQSu4wE9Dcv8Tay6q+qXujLvX459DwpbFXBZ3Wd HOEY/jMHYCmAUS4E955AtRrt4X5AVXo8PHV9jlr40upHwGIJ927YXuIeMLSyNSfr1wT9 lDuHGS1OPoS6X91fu1S4sb31Nk7H+iwsvIn3bgA+J6XMm6v9IrhhUCM1X8DXNaDSYcSE JV1w== 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=T0rvH8tccG1GCW1xVscvfSQVrt0Y/dmYu+9N0LqR3IU=; b=LzbvByqVViQ4c1J24xTb9vij6qi3qo25CUkL8Q09Wh+RghOmujqi2qZVzMyoPKoUph eMgJGz/p4/CB7C2uRam2bQyBM7wAoYMmdQ60vmDj/FmokSZf1dioCaYdV6DraivePnxr qDBrWlpBRl0aAau3MHMnkJiyrirwuCkgPH4Fr1VDYvgJNa90Zn+aD8EPV0VmMRmv89XF 8sKWnJbm2a7gKf5XUZJXt6q0X5izOMXra6GRAiaKvRSCohs+dc1N9ahvjKsOLu1wzSOG 6SmoPzG0uihVGPe6D3hT+UCpoY9CYKIgu4AwyGLKcDPXKLsrEigGm5z+JEmaPlZJ/ZYz q3DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ozWNgkyP; 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 kz7si13669246ejc.714.2021.10.11.18.24.11; Mon, 11 Oct 2021 18:24:54 -0700 (PDT) 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=20210112 header.b=ozWNgkyP; 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 S235257AbhJLBWk (ORCPT + 99 others); Mon, 11 Oct 2021 21:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234902AbhJLBWj (ORCPT ); Mon, 11 Oct 2021 21:22:39 -0400 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A84DC061570 for ; Mon, 11 Oct 2021 18:20:38 -0700 (PDT) Received: by mail-yb1-xb36.google.com with SMTP id z5so43045917ybj.2 for ; Mon, 11 Oct 2021 18:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T0rvH8tccG1GCW1xVscvfSQVrt0Y/dmYu+9N0LqR3IU=; b=ozWNgkyPQ6g2Pb6GhDQaCx4ZxPKDrBt5s2ggV9Ns3aDuMRwgN/pb8qCCc75VBqb19f OghPvT9NZ3DJ8gXsGqPKYt6+SQFN/ApQF6XXqcBQDxiC5rgqd0w20vWV7y/3n/HBX73A mYHYuTI/yuzdz6aA8LJWPIynztB+pp8z1VmlcJSARvWWwH3sjX/rD1nXx/GWDMfJbRiY onfCMl0VsmdBL4rZnW+ek3I+1+Sk62K28tZE0iSXgGlhh5683azjY2imwUSYEYfhUaqE 8T9k1TImgSZOiUTnlqCMBWhndlrEIqEIpm5qjv40lClFReap2zuQBi62mOwgtVEqrVGk z2Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T0rvH8tccG1GCW1xVscvfSQVrt0Y/dmYu+9N0LqR3IU=; b=H6Ei9ZLAWoGeptDx6dZG1bSLsBOU7UhMo6iFeEONAaQu8Xq57+kYDbAML6ypIMZyE1 VC/y7kbn5N6RVbw56FtqdlRuPOnhmg7w4t08Cst3bbN7gqMMTvosJJRJzneLJSRBHYsC WHq7tH6y6ezjv8pq5znhqAK1eZLjFaLyVPHDQaDDN9M4DqSZYc6DD1jcwMs6+Lut1kjW oF/RKTW/zWHI7mIo+s+2wnmwqC7gx0yXt0xupnp/TiJKDHeZiAS6eZdyce1xclMwQ3Gg j4SYrtAg7Ibe8vr8CyhEvukIY981hXH4JP0nyGDr+xpWvsjPAQ23Y5SsLATbcZNWwpRP IJZg== X-Gm-Message-State: AOAM533+iow0DiE4yz46f5f9f45NwvIdN6mmqg+mVUTHJTEgEPu9goUl Nw0o/t4RG6zC0l3k0CBxGAfRc6WjISsBDnE5TxA0mg== X-Received: by 2002:a25:8411:: with SMTP id u17mr25321543ybk.376.1634001636162; Mon, 11 Oct 2021 18:20:36 -0700 (PDT) MIME-Version: 1.0 References: <92cbfe3b-f3d1-a8e1-7eb9-bab735e782f6@rasmusvillemoes.dk> <20211007101527.GA26288@duo.ucw.cz> <202110071111.DF87B4EE3@keescook> <202110081344.FE6A7A82@keescook> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 11 Oct 2021 18:20:25 -0700 Message-ID: Subject: Re: [PATCH v10 3/3] mm: add anonymous vma name refcounting To: Michal Hocko Cc: Kees Cook , Pavel Machek , Rasmus Villemoes , David Hildenbrand , John Hubbard , Andrew Morton , Colin Cross , Sumit Semwal , Dave Hansen , Matthew Wilcox , "Kirill A . Shutemov" , Vlastimil Babka , Johannes Weiner , Jonathan Corbet , Al Viro , Randy Dunlap , Kalesh Singh , Peter Xu , rppt@kernel.org, Peter Zijlstra , Catalin Marinas , vincenzo.frascino@arm.com, =?UTF-8?B?Q2hpbndlbiBDaGFuZyAo5by16Yym5paHKQ==?= , Axel Rasmussen , Andrea Arcangeli , Jann Horn , apopple@nvidia.com, Yu Zhao , Will Deacon , fenghua.yu@intel.com, thunder.leizhen@huawei.com, Hugh Dickins , feng.tang@intel.com, Jason Gunthorpe , Roman Gushchin , Thomas Gleixner , krisman@collabora.com, Chris Hyser , Peter Collingbourne , "Eric W. Biederman" , Jens Axboe , legion@kernel.org, Rolf Eike Beer , Cyrill Gorcunov , Muchun Song , Viresh Kumar , Thomas Cedeno , sashal@kernel.org, cxfcosmos@gmail.com, LKML , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm , kernel-team , Tim Murray Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 11, 2021 at 6:18 PM Suren Baghdasaryan wrote: > > On Mon, Oct 11, 2021 at 1:36 AM Michal Hocko wrote: > > > > On Fri 08-10-21 13:58:01, Kees Cook wrote: > > > - Strings for "anon" specifically have no required format (this is good) > > > it's informational like the task_struct::comm and can (roughly) > > > anything. There's no naming convention for memfds, AF_UNIX, etc. Why > > > is one needed here? That seems like a completely unreasonable > > > requirement. > > > > I might be misreading the justification for the feature. Patch 2 is > > talking about tools that need to understand memeory usage to make > > further actions. Also Suren was suggesting "numbering convetion" as an > > argument against. > > > > So can we get a clear example how is this being used actually? If this > > is just to be used to debug by humans than I can see an argument for > > human readable form. If this is, however, meant to be used by tools to > > make some actions then the argument for strings is much weaker. > > The simplest usecase is when we notice that a process consumes more > memory than usual and we do "cat /proc/$(pidof my_process)/maps" to > check which area is contributing to this growth. The names we assign > to anonymous areas are descriptive enough for a developer to get an > idea where the increased consumption is coming from and how to proceed > with their investigation. > There are of course cases when tools are involved, but the end-user is > always a human and the final report should contain easily > understandable data. > > IIUC, the main argument here is whether the userspace can provide > tools to perform the translations between ids and names, with the > kernel accepting and reporting ids instead of strings. Technically > it's possible, but to be practical that conversion should be fast > because we will need to make name->id conversion potentially for each > mmap. On the consumer side the performance is not as critical, but the > fact that instead of dumping /proc/$pid/maps we will have to parse the > file, do id->name conversion and replace all [anon:id] with > [anon:name] would be an issue when we do that in bulk, for example > when collecting system-wide data for a bugreport. > > I went ahead and implemented the proposed userspace solution involving > tmpfs as a repository for name->id mapping (more precisely > filename->inode mapping). Profiling shows that open()+fstat()+close() > takes: > - roughly 15 times longer than mmap() with 1000 unique names each > being reused 50 times. > - roughly 3 times longer than mmap() with 100 unique names each being > reused 500 times. This is due to lstat() optimization suggested by > Rasmus which avoids open() and close(). > For comparison, proposed prctl() takes roughly the same amount of time > as mmap() and does not depend on the number of unique names. > > I'm still evaluating the proposal to use memfds but I'm not sure if > the issue that David Hildenbrand mentioned about additional memory > consumed in pagecache (which has to be addressed) is the only one we > will encounter with this approach. If anyone knows of any potential > issues with using memfds as named anonymous memory, I would really > appreciate your feedback before I go too far in that direction. > Thanks, > Suren. Just noticed that timmurray@ was dropped from the last reply. Adding him back. > > > -- > > Michal Hocko > > SUSE Labs