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=-13.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no 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 67F3EC433F5 for ; Thu, 9 Sep 2021 04:05:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F1BA161176 for ; Thu, 9 Sep 2021 04:05:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F1BA161176 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 73B65900002; Thu, 9 Sep 2021 00:05:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 712626B0072; Thu, 9 Sep 2021 00:05:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62820900002; Thu, 9 Sep 2021 00:05:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id 4EF266B0071 for ; Thu, 9 Sep 2021 00:05:13 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 073B43017D for ; Thu, 9 Sep 2021 04:05:13 +0000 (UTC) X-FDA: 78566694906.26.06BE9EC Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by imf21.hostedemail.com (Postfix) with ESMTP id B0CE1D02D826 for ; Thu, 9 Sep 2021 04:05:12 +0000 (UTC) Received: by mail-yb1-f178.google.com with SMTP id y16so1216447ybm.3 for ; Wed, 08 Sep 2021 21:05:12 -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=05Ca02pfZvMrXfNgNF9H2Jldx1Sa0htxtnSYmB+/GC4=; b=SgGkejg8RZ2dnBni6dl85OnH4iOIyLF/M6i7gPVENPUDCRUIk+yvWZAImRqtABeonR VAdcK4ErYk0Hk4/9PdgyesGnr6YgvqrA0/hkLVgH2AfKICiKuf7f54KkP1TVWkESDtWg z+AM6q2j2FivdWCjRrQWu8CopagTJZ+wu/IDCpTeB6qzZSMeREkeBaYCa08PHeb5g1xr VDcO2PkAKUPJo64vRLAAJJ7cQCiEVPDy//15HTO09nHUCz08onlbq/mpWC8VyTDqcAgA bpZ9oy79vhAOqkQmeThDkhPZp4PIUlv0Kncd+PBqELTtNT1RRckw3yN32Gj533cLWmvQ Su0w== 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=05Ca02pfZvMrXfNgNF9H2Jldx1Sa0htxtnSYmB+/GC4=; b=jIoAxA2CbBlrmAEm0ax9KhdkQv0GXmw9EnSq8vQvj0hKcLjxjsGIWZJLms8rYlR9HV TOyz6SxwEw8L3Qtgu3mQWnuVs2Z+H4DEMxjbsXGzfswT2SCTGipdOGZgzIWg366qGHIP At1/nLkH9yLq0a0Si7CMysegoJJC44HziQQN9pehYB07VeyZu7luChseGT8cUASSwQm/ CXHE3GoKiWhSvXSe71BXP7WFiBfuS1sBcOhqwijducWEeNuV57GN4sa9J+LoUWGDz+bT 4hGrL6WfniX5gy04MKVhjMv9O4+/sItflW4+wvFkWwK/w8wpAhNqXGYy6ImBiB2WtF/r jVsg== X-Gm-Message-State: AOAM532Mqp2OZES+K+EddvJEz/TiLjcsCt83WpDinSK4WDGWaET/8LXG 7jXitrua2tBH719dqvTzxMcrlMkPluPpFaWshQEcLA== X-Google-Smtp-Source: ABdhPJxuNY87tzok68GgeB3m1htJffEiGR2YFQ3UhtbaNUVg1oevrcc5jxFYrxHr29PrD7NwsKVz9p1BOps9N0WBCC0= X-Received: by 2002:a25:d04a:: with SMTP id h71mr1243688ybg.418.1631160311597; Wed, 08 Sep 2021 21:05:11 -0700 (PDT) MIME-Version: 1.0 References: <20210902231813.3597709-1-surenb@google.com> <20210902231813.3597709-2-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 8 Sep 2021 21:05:00 -0700 Message-ID: Subject: Re: [PATCH v9 2/3] mm: add a field to store names for private anonymous memory To: Matthew Wilcox Cc: Andrew Morton , Colin Cross , Sumit Semwal , Michal Hocko , Dave Hansen , Kees Cook , "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, John Hubbard , 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@oracle.com, 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, Rasmus Villemoes , LKML , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm , kernel-team Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B0CE1D02D826 X-Stat-Signature: nzpf6tuhowcbwwnzpts4ehoge1s3txhk Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=SgGkejg8; spf=pass (imf21.hostedemail.com: domain of surenb@google.com designates 209.85.219.178 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1631160312-332443 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Sep 6, 2021 at 9:57 AM Matthew Wilcox wrote: > > On Thu, Sep 02, 2021 at 04:18:12PM -0700, Suren Baghdasaryan wrote: > > On Android we heavily use a set of tools that use an extended version of > > the logic covered in Documentation/vm/pagemap.txt to walk all pages mapped > > in userspace and slice their usage by process, shared (COW) vs. unique > > mappings, backing, etc. This can account for real physical memory usage > > even in cases like fork without exec (which Android uses heavily to share > > as many private COW pages as possible between processes), Kernel SamePage > > Merging, and clean zero pages. It produces a measurement of the pages > > that only exist in that process (USS, for unique), and a measurement of > > the physical memory usage of that process with the cost of shared pages > > being evenly split between processes that share them (PSS). > > > > If all anonymous memory is indistinguishable then figuring out the real > > physical memory usage (PSS) of each heap requires either a pagemap walking > > tool that can understand the heap debugging of every layer, or for every > > layer's heap debugging tools to implement the pagemap walking logic, in > > which case it is hard to get a consistent view of memory across the whole > > system. > > > > Tracking the information in userspace leads to all sorts of problems. > > It either needs to be stored inside the process, which means every > > process has to have an API to export its current heap information upon > > request, or it has to be stored externally in a filesystem that > > somebody needs to clean up on crashes. It needs to be readable while > > the process is still running, so it has to have some sort of > > synchronization with every layer of userspace. Efficiently tracking > > the ranges requires reimplementing something like the kernel vma > > trees, and linking to it from every layer of userspace. It requires > > more memory, more syscalls, more runtime cost, and more complexity to > > separately track regions that the kernel is already tracking. > > I understand that the information is currently incoherent, but why is > this the right way to make it coherent? It would seem more useful to > use something like one of the tracing mechanisms (eg ftrace, LTTng, > whatever the current hotness is in userspace tracing) for the malloc > library to log all the useful information, instead of injecting a subset > of it into the kernel for userspace to read out again. Sorry, for the delay with the response. I'm travelling and my internet access is very patchy. Just to clarify, your suggestion is to require userspace to log any allocation using ftrace or a similar mechanism and then for the system to parse these logs to calculate the memory usage for each process? I didn't think much in this direction but I guess logging each allocation in the system and periodically collecting that data would be quite expensive both from memory usage and performance POV. I'll need to think a bit more but these are to me the obvious downsides of this approach.