Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1111056pxb; Thu, 7 Oct 2021 00:36:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1zYOvwlfOax1nFGpXZeaOZIJ+KfJepGkSFF2+oQrYYp9yIPgHNFn8vZ0PLsebiKnPAlfP X-Received: by 2002:a17:906:a3c3:: with SMTP id ca3mr3749735ejb.337.1633592203296; Thu, 07 Oct 2021 00:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633592203; cv=none; d=google.com; s=arc-20160816; b=S9IwbPvXkZRSV7MyI2ek1nl3nt9BrxmSrwW0Ta8Mk+kFm51dAJSg1lQfxcaZ6vAhX/ P+WA2m/KMm6WNXu6+/e7MWAYtD2rTEkc4Z71YuP0LgAXtMOyMYixedTeUrvMRjhawyzv X+qYxLgOocTfd+Yd9H3G6w12KAZGyMTEXhR8gm/50g/tTvs0OPOCDRLoSMHKJzX3Zvr8 lM4Ul5ubWsZRkJcbXtT9UhuwCMEN7J0WmdbdtK7ZFLZ3M26Fytgj02mfi44mFgylZRAB afMoXdmh4WckeCRWCrPAEgJXTw4vMo09RPEX2eC5eflpPDrY/mBiFDN1qY7m3O8ByW2v JjYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=IcGgFJhn+URtM5zX70uUXK5bzpT3Lent47sXcqP2HJM=; b=RQfcu4/HsaRrmocU3jSv8KLzgw6sVLFCV4Lyap5WDzGIRwJxHs6P0Y+9tB3YVNUwhW 0KDKTN3DCFu6S3mOLwohcf5uceJgt/Cb9X+PrNuqYDRrQesKQcVwNqTNLC0cyngIq/FE iNk7dgJsbSEdCXw1ZOMFYBfbEsG/adnr3D92e1mq5fC4Xkpwtn5PaYqRf1eMKgxmoX7E 1v5gvH/2f3Nqvhy/2SfkKtoHsEFA0QNyg7+VlY3UMPFQSO9/jSw/Xj8Ro/9ySJTdF8FW AG0hGjgAnsWNf4UsBnGVmX/fUR+9VENFOFTLHvZpsL9V6hrWgiN2ORYeFd8HQju8X5s3 K2PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FyCFxfne; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x10si27964033edj.155.2021.10.07.00.36.08; Thu, 07 Oct 2021 00:36:43 -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=@redhat.com header.s=mimecast20190719 header.b=FyCFxfne; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240410AbhJGHfK (ORCPT + 99 others); Thu, 7 Oct 2021 03:35:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27884 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232512AbhJGHfJ (ORCPT ); Thu, 7 Oct 2021 03:35:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633591996; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IcGgFJhn+URtM5zX70uUXK5bzpT3Lent47sXcqP2HJM=; b=FyCFxfnezggtY0IafaJ94a8W1eIWRINWWJcM+nt/ate+7i22ctDm9ufzfNluR4j+iATvnG kMH4otrrnoWb9d+xPaQiTzwNRw52XOXbYoG0c27ybxbzBGIzlifxs4nsKx//BL6uZdAXF0 RvgudLW3PTDOlNJQ3Meje+LjjgAdSfI= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-283-CSMZqewAOZeqKKLZSBeUKA-1; Thu, 07 Oct 2021 03:33:14 -0400 X-MC-Unique: CSMZqewAOZeqKKLZSBeUKA-1 Received: by mail-wr1-f70.google.com with SMTP id h11-20020adfa4cb000000b00160c791a550so3768564wrb.6 for ; Thu, 07 Oct 2021 00:33:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=IcGgFJhn+URtM5zX70uUXK5bzpT3Lent47sXcqP2HJM=; b=PZYcuTgubJT3sOScdViNtnW4Yiyx5XIoVtih+73CmI3w/l/KSFlYZIK5RYzU/1Y+X3 DDsniqCtjStxaL2d7ivssolIVdiw6zbs/Y2aRlm43QkFiTg+7dkiBRIHrNkJs9BRMLr1 DSP3adGGjlm3YwKpEBbtVzJce5Xfo3cpIqsdSav8QyV1ReUAk2evu6ufrf9QzsFNuiMq YqlT1Mi8Z/M+IUZ+bEgseSWKoob7WKeWzF8dkfQ3SMN5eLifSdyycSu7bj43TJvINqXS IHCn5XowTujZ207TbXRp65Xtrtxy3fbqUgcjVBkeMqGUCMDj1pcwnbswMEfU3ApFjy6g foGw== X-Gm-Message-State: AOAM532Aalg4aVR5hgbmT276JegLS4Rc57zLejuwO03bWBX7DemL36va CrpbfZFMvgxU0SXYcuGAV2gI1WI2XZzUUKXHlzvtpDW1OeQM1eIvPBsDckfAsOMsc82YwuRU3+r vWLOtI4kK+MN2GJSRqDnkvUiq X-Received: by 2002:a1c:7dc8:: with SMTP id y191mr2863370wmc.181.1633591993768; Thu, 07 Oct 2021 00:33:13 -0700 (PDT) X-Received: by 2002:a1c:7dc8:: with SMTP id y191mr2863339wmc.181.1633591993537; Thu, 07 Oct 2021 00:33:13 -0700 (PDT) Received: from [192.168.3.132] (p5b0c6886.dip0.t-ipconnect.de. [91.12.104.134]) by smtp.gmail.com with ESMTPSA id l124sm7732468wml.8.2021.10.07.00.33.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Oct 2021 00:33:13 -0700 (PDT) Subject: Re: [PATCH v10 3/3] mm: add anonymous vma name refcounting To: Suren Baghdasaryan 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 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> From: David Hildenbrand Organization: Red Hat Message-ID: Date: Thu, 7 Oct 2021 09:33:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Thanks, David / dhildenb