Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2610584pxb; Tue, 12 Oct 2021 09:53:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw86dOsyB58G7nuS2E2n35OeGHkWbSAQActz1+ozlgnxZbjoRzOOLoFejpiPolNQkruqQkX X-Received: by 2002:a17:906:7f01:: with SMTP id d1mr34551480ejr.318.1634057581024; Tue, 12 Oct 2021 09:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634057581; cv=none; d=google.com; s=arc-20160816; b=PZOpfpVSiFhgC5zucLosgGo+JRkimKSCTbWAIcDjvVDrpxRRHxWhjFnSOhMZbcR43E Fz8VYHguSeAKhpd4e4GJAPb+yyUMdQjn+DSwrcLTeQ0+0h3KOw6+yaMCr5SsLU1vs/Ta kTQXp1HIyPK357Er2wfWYTpkncvBCTfznBfuIo3jine1v3xrsZ7Y1mvJ/yxQrCdj+1HN wTg3JrlVVbTp6p6QvDv+K9RNS6So8dN80xpasVHc6mA34LYnDXQy+DRoK9IbGNAqTPpD FQSljg3YTScRiF5qGJ8dnY6nJfqYULfKnQqIatjX1FHO6k9y+PzSJiJLQ0E5NfqUCSOf T5BQ== 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=Ar09QrWZPbtZ1MPFu1DvBkyuuQRpZh8UgkauKcNPOAM=; b=LUsnruVmD1IoqouRphLjStpkaT6MDZAdzDrro9XJlLfmdB4eT/63y5gAKZV+p6JZhh HUUIzGPXMgh4AlEvnimoAW4ZVcaOHrxfZtMMERYBZ1dePVy1PVDPpWILbnxTTgTwqAgJ qpEYayXX86zEhIIHUsyPgOeGI+H1jiGalN0Jb/EcMXtiamZrRQ/JDjopdHPG3INYEfMz TRJm+Uv0HT7FOfOfXXa0U5Cn7L5+1SBbiQwKV/GAy752i6bUls7BOEeSAzBDWpQHVLPf RGrycJHnfKVAKJLsG+9rsfi7yn9USxKRPtW5yrg6apH4DU8gKMoIy5zaqS+4k57Sr70o HQbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YaK6rwZT; 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 x15si16303721edi.576.2021.10.12.09.52.36; Tue, 12 Oct 2021 09:53:01 -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=YaK6rwZT; 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 S231352AbhJLQwu (ORCPT + 99 others); Tue, 12 Oct 2021 12:52:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229996AbhJLQwr (ORCPT ); Tue, 12 Oct 2021 12:52:47 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 173ADC061746 for ; Tue, 12 Oct 2021 09:50:46 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id u32so48019805ybd.9 for ; Tue, 12 Oct 2021 09:50:46 -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=Ar09QrWZPbtZ1MPFu1DvBkyuuQRpZh8UgkauKcNPOAM=; b=YaK6rwZTq4aRgarlqFIa1o4IaxOiXPj3qbCjvidENvw68SISlHG+ig7WWufPr7cyyc iLYpsHU9CVkCr3SrnNEDIABH0Rvvra4Y1Toyq7J1Hw07pRZXvbD3xXZu6kqc1t/0riCj XixP30thoEdXn7Fkf4PxSST9mYIrZ9voaWm4ID3wWTwToLSCDjdFU/NMr5IDC54RW4C7 GD6zFsvDMeMJ5L4mc1VIn6D0XScIOUYxYtsXyV2PD9x4hnEfH/EPSldRjaHYwQnzJeD6 ds9Pe3GqsmSNwVDVfAhhG+AElXJLhzNGpKcnTmrpxin8D6FZvzDX5HXboNHhFNyKmoP4 oSfA== 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=Ar09QrWZPbtZ1MPFu1DvBkyuuQRpZh8UgkauKcNPOAM=; b=UPPz3b5Tg5uwa66UYvjSmrZq8WPkvBDvKbenTxMlAyN8wku5bKH+3sA1XiPaKr1Tqt m1hIM3ihkJsx9hbfXl7tA8PUY+wHLYfyRXv+M1R5W7/oMzbPciMF+1vwfDL89w8pDTkk UKrbvI1lNSbWtOti/K47ygpzS9fhbb9ve7Ioj3oKWxFsq7DEBA9IlzTC/8qBRQQTgXqI 6U3GR7zx5jQ8okIykfg2OlCmyzNniOGQDdoZQhHJRxXFTBeiSCemruGY+Ym69UdzK7ic 8XWY9uTHXprvwQNg85PVejgse1uXzmYSBmJvnMUzA1U7+AAJFJfFHdpSEqG65N9zK698 j2GA== X-Gm-Message-State: AOAM5304Q0/kgFyNzmRyr15p9s+C/2qQMiUF0IBLnRnQvUSuTUK3ywJD VcFzAWLkAJ2wV8p05RDseWDoPtR5FmNrKP2rDOdOpg== X-Received: by 2002:a25:d1d3:: with SMTP id i202mr31604897ybg.487.1634057444798; Tue, 12 Oct 2021 09:50:44 -0700 (PDT) MIME-Version: 1.0 References: <202110071111.DF87B4EE3@keescook> <202110081344.FE6A7A82@keescook> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 12 Oct 2021 09:50:33 -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 Tue, Oct 12, 2021 at 12:37 AM Michal Hocko wrote: > > On Mon 11-10-21 18:20:25, Suren Baghdasaryan wrote: > > 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. > > OK, it would have been much more preferable to be explicit about this > main use case from the very beginning. Just to make sure we are at the > same page. Is the primary usecase usage and bug reporting? Sorry, I should have spent more time on patch #2 description. Yes, debugging memory issues is the primary usecase. In fact that's the only usecase in Android AFAIK. > > My initial understanding was that at userspace managed memory management > could make an educated guess about targeted reclaim (e.g. MADV_{FREE,COLD,PAGEOUT} > for cached data in memory like uncompressed images/data). Such a usecase > would clearly require a standardized id/naming convention to be > application neutral. Ah, now I understand your angle. Our prior work on process_madvise() probably helped in leading your thoughts in this direction :) Sorry about the confusion. > > > > 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. > > Whether you use ids or human readable strings you still have to > understand the underlying meaning to make any educated guess. Let me > give you an example. Say I have an application with a memory leak. Right > now I can only tell that it is anonymous memory growing but it is not > clear who uses that anonymous. You are adding a means to tell different > users appart. That is really helpful. Now I know this is an anon > user 1234 or MySuperAnonMemory. Neither of the will not tell me more > without a id/naming convention or reading the code. A convention can be > useful for the most common users (e.g. a specific allocator) but I am > rather dubious there are many more that would be _generally_ recognized > without some understanding of the said application. I guess an example would be better to clarify this. Here are some vma names from Google maps app: [anon:dalvik-main space (region space)] [anon:dalvik-/apex/com.android.art/javalib/boot.art] [anon:dalvik-/apex/com.android.art/javalib/boot-apache-xml.art] [anon:.bss] [anon:dalvik-zygote space] [anon:dalvik-non moving space] [anon:dalvik-free list large object space] [anon:dalvik-/product/app/Maps/oat/arm64/Maps.art] [anon:stack_and_tls:20792] [anon:stack_and_tls:20791] [anon:dalvik-LinearAlloc] [anon:dalvik-CompilerMetadata] [anon:dalvik-indirect ref table] [anon:dalvik-live stack] [anon:dalvik-allocation stack] [anon:dalvik-large object free list space allocation info map] [anon:scudo:primary] [anon:scudo:secondary] [anon:bionic_alloc_small_objects] Most of them have names standard for Android and can be recognized by developers and even Android framework (example where "anon:dalvik-main space" and other standard names are being parsed: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/jni/android_os_Debug.cpp;l=340). Names like "anon:dalvik-/apex/com.android.art/javalib/boot.art" help the developer to recognize the component responsible for the memory. Names like "anon:stack_and_tls:20792" include the TID of the thread which uses this memory. All this information can help in narrowing down memory consumption investigation. Hopefully these examples clarify the usage a bit better? > > Maybe the situation in Android is different because the runtime is more > coupled but is it reasonable to expect any common naming conventions for > general Linux platforms? Well, to be useful the system would have to agree to *some* convention I guess. > > I am slightly worried that we have spent way too much time talking > specifics about id->name translation rather than the actual usability > of the token. Agree. I'll try to avoid further confusions. Thanks! > -- > Michal Hocko > SUSE Labs