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=-4.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 7081AC4320E for ; Sat, 28 Aug 2021 21:28:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 02F2860E99 for ; Sat, 28 Aug 2021 21:28:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 02F2860E99 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5E2E48D0001; Sat, 28 Aug 2021 17:28:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56AB66B0071; Sat, 28 Aug 2021 17:28:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E5138D0001; Sat, 28 Aug 2021 17:28:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id 29BE76B006C for ; Sat, 28 Aug 2021 17:28:37 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C84C98249980 for ; Sat, 28 Aug 2021 21:28:36 +0000 (UTC) X-FDA: 78525778632.19.2773EEB Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by imf25.hostedemail.com (Postfix) with ESMTP id 8A6C1B000180 for ; Sat, 28 Aug 2021 21:28:36 +0000 (UTC) Received: by mail-lj1-f180.google.com with SMTP id i28so18244270ljm.7 for ; Sat, 28 Aug 2021 14:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=XXM23t7nGqJTGllQ0GBo3dDWWAdzVbWZALkyemvhWNo=; b=YO9S1CFPlYJXAsTzQEafWFpbtOf5hUDAUwwUDT6po2a6SrE4m/UaIhw+YovOop+y/8 3zEPZWSEpENbiTKkvzsaIqWMkahjmgO5s+mB3dT/j+GtvX58cEEbFW2Mbk99VjPMyYZg mI+W4uJjaEwa83Tue6rQc6P5Rnk/AeUI+U9z1M3+8zxE8R893EoaFLhn/w3SCrQ/xmD8 yd1umBxzRx8IaLfLbIcaMf9+mUpQ8v1vT+1WfHDshQgyzWRGCScShh3BJg5puQ/+dgcM FnK1xYckrS5f7Hy0ZzBHagJgEL4g8S31rneCVsFGG8ccwa5CfBAlwpGE/p4AsDetysOv Lojw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=XXM23t7nGqJTGllQ0GBo3dDWWAdzVbWZALkyemvhWNo=; b=mfkuJ/k4xV84cZKpvJ7bavo5fdd7pkOcYJ+mEUXatD8dvRT3/CWboGgfuWDDgYeSv/ VmiL9p0h4+Psw6Wkoi4K8wDgT9/y3yPcEf9a58n5/NkaN6Tyom1hhrRWpN7nvT1Dsj2B RYQjf9i5BdZwU7CRgZRyPEsKIgUQ4tC59lS/IQo+2qV2dgXz01e3dDOlUsVTDK4KQaJb BAOkqvE/bJW8H2R4SsM7szSslL06u5tjHPYNqWCCodTzOPK3Y5Ft4zF5xGI8SqttmxQw icnBzpGzXvfFEEyv0NHmqyz/2QpL/GHSCy7O78OjAJUfG1vM6rjY9ZH7OH1I6qDrSTz1 0Mxg== X-Gm-Message-State: AOAM532yKQqNKMuZb2rlOuWWVKafmLa2yON+I5fcml4rnA5rUOtXKRen nGACPcZNtGGRCzMl+4jBXew= X-Google-Smtp-Source: ABdhPJxEQbKglQZ/sIqsMfNEKtgB/wPaaCRyWOxraQzixjbdnPWF4zSNUzJOVcUYPxwIPDYxrr9jjg== X-Received: by 2002:a2e:804a:: with SMTP id p10mr13718369ljg.216.1630186114923; Sat, 28 Aug 2021 14:28:34 -0700 (PDT) Received: from grain.localdomain ([5.18.253.97]) by smtp.gmail.com with ESMTPSA id bp10sm1045767lfb.130.2021.08.28.14.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Aug 2021 14:28:33 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id D5EE95A001E; Sun, 29 Aug 2021 00:28:32 +0300 (MSK) Date: Sun, 29 Aug 2021 00:28:32 +0300 From: Cyrill Gorcunov To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, ccross@google.com, sumit.semwal@linaro.org, mhocko@suse.com, dave.hansen@intel.com, keescook@chromium.org, willy@infradead.org, kirill.shutemov@linux.intel.com, vbabka@suse.cz, hannes@cmpxchg.org, corbet@lwn.net, viro@zeniv.linux.org.uk, rdunlap@infradead.org, kaleshsingh@google.com, peterx@redhat.com, rppt@kernel.org, peterz@infradead.org, catalin.marinas@arm.com, vincenzo.frascino@arm.com, chinwen.chang@mediatek.com, axelrasmussen@google.com, aarcange@redhat.com, jannh@google.com, apopple@nvidia.com, jhubbard@nvidia.com, yuzhao@google.com, will@kernel.org, fenghua.yu@intel.com, thunder.leizhen@huawei.com, hughd@google.com, feng.tang@intel.com, jgg@ziepe.ca, guro@fb.com, tglx@linutronix.de, krisman@collabora.com, chris.hyser@oracle.com, pcc@google.com, ebiederm@xmission.com, axboe@kernel.dk, legion@kernel.org, eb@emlix.com, songmuchun@bytedance.com, viresh.kumar@linaro.org, thomascedeno@google.com, sashal@kernel.org, cxfcosmos@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com Subject: Re: [PATCH v8 2/3] mm: add a field to store names for private anonymous memory Message-ID: References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-3-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210827191858.2037087-3-surenb@google.com> User-Agent: Mutt/2.0.7 (2021-05-04) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=YO9S1CFP; spf=pass (imf25.hostedemail.com: domain of gorcunov@gmail.com designates 209.85.208.180 as permitted sender) smtp.mailfrom=gorcunov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: fyzeg5418pegfq19di1hynkjdrxppp7j X-Rspamd-Queue-Id: 8A6C1B000180 X-Rspamd-Server: rspam04 X-HE-Tag: 1630186116-11303 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 Fri, Aug 27, 2021 at 12:18:57PM -0700, Suren Baghdasaryan wrote: > > The name is stored in a pointer in the shared union in vm_area_struct > that points to a null terminated string. Anonymous vmas with the same > name (equivalent strings) and are otherwise mergeable will be merged. > The name pointers are not shared between vmas even if they contain the > same name. The name pointer is stored in a union with fields that are > only used on file-backed mappings, so it does not increase memory usage. > > The patch is based on the original patch developed by Colin Cross, more > specifically on its latest version [1] posted upstream by Sumit Semwal. > It used a userspace pointer to store vma names. In that design, name > pointers could be shared between vmas. However during the last upstreaming > attempt, Kees Cook raised concerns [2] about this approach and suggested > to copy the name into kernel memory space, perform validity checks [3] > and store as a string referenced from vm_area_struct. > One big concern is about fork() performance which would need to strdup > anonymous vma names. Dave Hansen suggested experimenting with worst-case > scenario of forking a process with 64k vmas having longest possible names > [4]. I ran this experiment on an ARM64 Android device and recorded a > worst-case regression of almost 40% when forking such a process. This > regression is addressed in the followup patch which replaces the pointer > to a name with a refcounted structure that allows sharing the name pointer > between vmas of the same name. Instead of duplicating the string during > fork() or when splitting a vma it increments the refcount. > > [1] https://lore.kernel.org/linux-mm/20200901161459.11772-4-sumit.semwal@linaro.org/ > [2] https://lore.kernel.org/linux-mm/202009031031.D32EF57ED@keescook/ > [3] https://lore.kernel.org/linux-mm/202009031022.3834F692@keescook/ > [4] https://lore.kernel.org/linux-mm/5d0358ab-8c47-2f5f-8e43-23b89d6a8e95@intel.com/ ... > + > +/* mmap_lock should be read-locked */ > +static inline bool is_same_vma_anon_name(struct vm_area_struct *vma, > + const char *name) > +{ > + const char *vma_name = vma_anon_name(vma); > + > + if (likely(!vma_name)) > + return name == NULL; > + > + return name && !strcmp(name, vma_name); > +} Hi Suren! There is very important moment with this new feature: if we assign a name to some VMA it won't longer be mergeable even if near VMA matches by all other attributes such as flags, permissions and etc. I mean our vma_merge() start considering the vma namings and names mismatch potentially blocks merging which happens now without this new feature. Is it known behaviour or I miss something pretty obvious here?