Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1507247pxb; Thu, 7 Oct 2021 09:05:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVtDa8c0IKJq105Y8Q+GBG4YafUlsELUgw6enefR5lY3z9jLZGn6pASGQ+kimYENoayr71 X-Received: by 2002:a50:9d85:: with SMTP id w5mr7413870ede.268.1633622719547; Thu, 07 Oct 2021 09:05:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633622719; cv=none; d=google.com; s=arc-20160816; b=xmGG0KY7Thwu1ZxpPk2e2Jeh5srmF/5ka/1biWF9eEhacoh+HbyaWEDrOimal+fY7k peWOp1vBZfdzxciU7dxT0FMUwhMdTz/4uMRn14GFagKxtZ+tCpjwTfIEiA+lfmaHMuBb 1GnPDovDS8EDnqyVMY++4Yb7PPIZ8jjHHhkgDRfxx+N8GbwlRSlDYWhspUmNlhCF9W8U wXdQqfTpbPC+JNB4SAYOMcjzGPz6ZywYO59DwXO+umJbhWVThbNXetPNOz+hQYvmNwUV 5LUUsXn5UhLVAw0O/Jjr3tZBEI6Of3Mj2VCC6faowMHQAtxsdf4OMM+9P46D/m39H4CE bVtw== 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=Vlar6Cpk8FMyDmzR6kojX5u1Q4wI3iurHkOrDEyZ+tg=; b=fMy4e5ZV+1ecrur7CDVc6WuB18vVKfNJro4amtU/okHibmFUolbYkZMI9Icb9GWygB xhMfF6D3B+xun8KZAYR2VkODmG5/W0RYJIlEv7mbQKSwaYH2OUc3pmEx2BnYd3dwzM7F jImId07gUkT0wYLDnkMy/SRjz5+7tJdQeJoTzHv/ZST4Vru85Njf0LV+Ip1xxoctdUaD kvVhuXINwMmuE773j/B0+322VTlHxO+SB81hQ7FO5hNmNOQ6dkXiTth9VMe2UxN1XHsB VUKADAqxEZ0cwc0bC+MOAZkey3bQFzT70t4yiYA6x3tHfQJBzyqt4HHtiO38TkLHrPkx kEXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cmq4sjqD; 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 di18si3576622edb.289.2021.10.07.09.04.47; Thu, 07 Oct 2021 09:05:19 -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=cmq4sjqD; 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 S230452AbhJGPo1 (ORCPT + 99 others); Thu, 7 Oct 2021 11:44:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233463AbhJGPo0 (ORCPT ); Thu, 7 Oct 2021 11:44:26 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CF44C061746 for ; Thu, 7 Oct 2021 08:42:32 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id n65so14338513ybb.7 for ; Thu, 07 Oct 2021 08:42:32 -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=Vlar6Cpk8FMyDmzR6kojX5u1Q4wI3iurHkOrDEyZ+tg=; b=cmq4sjqDQok/4KxsFCxUkk9uUjfHlLxtyjWkxHQGtzIBTrIVFFXA500G7/LK7k7nIk BUEvNt+xYoyFPujGUFiJkIoJi9W7SAaP0mDoD5meAKh2lS6Zh1XOCzznx2FfZg0FT7Ag 2SEatuWQgxkri0VXJyfyrvf2M+deg74+qLz/0sJ9/FZMYVg2yn5ELyHbB2qDZakEpPis UHlTiPe/EvNXYM9rke+8CesJrIiYoJytR6Poemu3GuEBZa0t3XJzK98fjNFXYGa4SmBs 2lWzudueNw2yi3ebMwzZ3btjk6rGEmlA1IMYTdO4GbR8ClQKqrYfN9AkVxUs7UGy58C6 +ycw== 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=Vlar6Cpk8FMyDmzR6kojX5u1Q4wI3iurHkOrDEyZ+tg=; b=XKPIZq5hTgfi/GWeW6FsVUPX1bJax7OzT1oja6dOlcozjTqzyZWSjzl81YhCt9MsLZ 5sVk6EHNXBI/oOJ5EBCZvOfZLSGf/EKE+XRSzLgeh5TBjIIbu4QyfNXdYqXANfogry+I KY3oNF/P/usQybMRbq4FQUH95HVU2OoXRCU2lxOecxc6GSgeLSaj6Yv9kQb84AhwQMnq nA4BgrZcbV1s5o3a7QN0AlOuahUeYq5pZjFKgT0aZUizKGHESSSMVAiyppXfYaUCnOYL 8fxpuks7voPdyBRL8eK7s6b01edclPjvMDRwVQvTAZAes5gj9TCJvPw1y97+ZJTWc9yB CvWA== X-Gm-Message-State: AOAM530Ss7uj7xLV1gXEp5Oo6h6xCrMjErc+aO7KVJYndFDq8r95GQuS nO2azW+fLpPuBySPE9fY14WA9sPRBk8/pObfJrK61g== X-Received: by 2002:a25:3:: with SMTP id 3mr5602512yba.418.1633621351461; Thu, 07 Oct 2021 08:42:31 -0700 (PDT) MIME-Version: 1.0 References: <20211001205657.815551-1-surenb@google.com> <20211001205657.815551-3-surenb@google.com> <20211005184211.GA19804@duo.ucw.cz> <20211005200411.GB19804@duo.ucw.cz> <6b15c682-72eb-724d-bc43-36ae6b79b91a@redhat.com> <192438ab-a095-d441-6843-432fbbb8e38a@redhat.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 7 Oct 2021 08:42:20 -0700 Message-ID: Subject: Re: [PATCH v10 3/3] mm: add anonymous vma name refcounting To: David Hildenbrand Cc: Michal Hocko , John Hubbard , Pavel Machek , Andrew Morton , Colin Cross , Sumit Semwal , Dave Hansen , Kees Cook , 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@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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 7, 2021 at 12:33 AM David Hildenbrand wrote: > > On 06.10.21 17:20, Suren Baghdasaryan wrote: > > On Wed, Oct 6, 2021 at 8:08 AM David Hildenbrand wrote: > >> > >> On 06.10.21 17:01, Suren Baghdasaryan wrote: > >>> On Wed, Oct 6, 2021 at 2:27 AM David Hildenbrand wrote: > >>>> > >>>> On 06.10.21 10:27, Michal Hocko wrote: > >>>>> On Tue 05-10-21 23:57:36, John Hubbard wrote: > >>>>> [...] > >>>>>> 1) Yes, just leave the strings in the kernel, that's simple and > >>>>>> it works, and the alternatives don't really help your case nearly > >>>>>> enough. > >>>>> > >>>>> I do not have a strong opinion. Strings are easier to use but they > >>>>> are more involved and the necessity of kref approach just underlines > >>>>> that. There are going to be new allocations and that always can lead > >>>>> to surprising side effects. These are small (80B at maximum) so the > >>>>> overall footpring shouldn't all that large by default but it can grow > >>>>> quite large with a very high max_map_count. There are workloads which > >>>>> really require the default to be set high (e.g. heavy mremap users). So > >>>>> if anything all those should be __GFP_ACCOUNT and memcg accounted. > >>>>> > >>>>> I do agree that numbers are just much more simpler from accounting, > >>>>> performance and implementation POV. > >>>> > >>>> +1 > >>>> > >>>> I can understand that having a string can be quite beneficial e.g., when > >>>> dumping mmaps. If only user space knows the id <-> string mapping, that > >>>> can be quite tricky. > >>>> > >>>> However, I also do wonder if there would be a way to standardize/reserve > >>>> ids, such that a given id always corresponds to a specific user. If we > >>>> use an uint64_t for an id, there would be plenty room to reserve ids ... > >>>> > >>>> I'd really prefer if we can avoid using strings and instead using ids. > >>> > >>> I wish it was that simple and for some names like [anon:.bss] or > >>> [anon:dalvik-zygote space] reserving a unique id would work, however > >>> some names like [anon:dalvik-/system/framework/boot-core-icu4j.art] > >>> are generated dynamically at runtime and include package name. > >> > >> Valuable information > > > > Yeah, I should have described it clearer the first time around. > > > >> > >>> Packages are constantly evolving, new ones are developed, names can > >>> change, etc. So assigning a unique id for these names is not really > >>> feasible. > >> > >> So, you'd actually want to generate/reserve an id for a given string at > >> runtime, assign that id to the VMA, and have a way to match id <-> > >> string somehow? > > > > If we go with ids then yes, that is what we would have to do. > > > >> That reservation service could be inside the kernel or even (better?) in > >> user space. The service could for example de-duplicates strings. > > > > Yes but it would require an IPC call to that service potentially on > > every mmap() when we want to name a mapped vma. This would be > > prohibitive. Even on consumption side, instead of just dumping > > /proc/$pid/maps we would have to parse the file and convert all > > [anon:id] into [anon:name] with each conversion requiring an IPC call > > (assuming no id->name pair caching on the client side). > > mmap() and prctl() already do take the mmap sem in write, so they are > not the "most lightweight" operations so to say. > > We already to have two separate operations, first the mmap(), then the > prctl(). IMHO you could defer the "naming" part to a later point in > time, without creating too many issues, moving it out of the > "hot/performance critical phase" > > Reading https://lwn.net/Articles/867818/, to me it feels like the use > case could live with a little larger delay between the mmap popping up > and a name getting assigned. That might be doable if occasional inconsistency can be tolerated (we can't guarantee that maps won't be read before the deferred work name the vma). However I would prefer an efficient solution vs the one which is inefficient but can be deferred. > > -- > Thanks, > > David / dhildenb >