Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2438083pxb; Sat, 28 Aug 2021 14:55:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz2+wJCqfd8Yu97Lv2gwFWw3h+2jnXmu5JKyQx7GS5XPronwP1by1iTkdT+jnTEZBeqKkN X-Received: by 2002:a17:906:7302:: with SMTP id di2mr17082547ejc.409.1630187741403; Sat, 28 Aug 2021 14:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630187741; cv=none; d=google.com; s=arc-20160816; b=OX+zo/GTs1VLIJ3wtqMoVez6y5Y4HKST2cMbYCc9T1No8xDeRHuAt86iULO459gik6 MzIJ0/1END/S/I+54CO7YFb1tZQj9sQ9nnJzUnrRtYj1r8blqrd22961lPf5W/+y6d1i 8MFiquwkjU9gROjgRfuidOLkxZSBBrDN18ogKSddEYkaO53I6ufc+DAhk7NyZ5eHHA5J 9w908msZG8HvJhpOPj7URHNL/2u6iQtfqFKNy6sqYbueKV9C5ZC1gVMl5KUY7DTfTfTA UvXAptOfpES1pEARjiyWqW0ZPBWFabKHkmIPeeqh3UmIEjp7c5ROBFHW6AK8Y1pqipmD 4utQ== 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=3ZLoRc8zgP/v6fBuiK/r7V3fCb7OpEy1oLfRJgXAgFE=; b=rFLCtlbnKlae6TtgTNUMUYt83WWDon5jUymbcLx+cQfN2V/XpSlXvpSxbjDEIt8lI1 5+ax9iGGGqT42Ey9WCGM0/AcQEfHDOvySlpxg9tvt/8Aa9wffHZxcp8qIZk09OK7CZaV LwdHN418dyOsNvFpsmGZdnKt5S8+PbXExNnI5JXahMJCFH76pxhq5w//OFdouHjUGMAR yDTfUEgaUmk0FttuwDxbvqvZ4igeH1FhMHRsb5fXwGPjmJzcfcSYcVv00hO5rKMHoNam R93V//ZM3tvE4F0UT/L+9yTbKmQTKavqDo3lAeaO5I5zgMjucrCAAvX/XLUxxSzDn5cy 68XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=iNAUMJ1E; 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 mp29si2330797ejc.290.2021.08.28.14.55.17; Sat, 28 Aug 2021 14:55:41 -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=20161025 header.b=iNAUMJ1E; 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 S232902AbhH1VyZ (ORCPT + 99 others); Sat, 28 Aug 2021 17:54:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbhH1VyX (ORCPT ); Sat, 28 Aug 2021 17:54:23 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71E3DC0613D9 for ; Sat, 28 Aug 2021 14:53:32 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id f15so19881478ybg.3 for ; Sat, 28 Aug 2021 14:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3ZLoRc8zgP/v6fBuiK/r7V3fCb7OpEy1oLfRJgXAgFE=; b=iNAUMJ1E+h3PcgTBuph6t34O4/GYB/x8t0AN3XLJYkzHXbSc+tcQQ+H6MHV4sZPerj Q5mSmXK7+qv3SX0wC+Z685Um9F5pgv/lIEZp511W1EZlAkLDGSnm2NFnsGYifzyyVj3k Jc2mIcY1g6wXGKMPg5v9NThOG24wc18zFxjqxaEul8Ody4x2qxR/y4CWpsADRayNckfJ DpxlTyHyTneIHkDURMtCvfp9/ofDgt+0KHIl/dwBauup9r4BEbGEQfWFDXMbNUgp8MB3 aUKRlenZuGE/uEWidqXa/rS9Q6tcRXasRykFO0mGYSEsWITy9kxk+EONJAwoV/XdoFmF cNPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3ZLoRc8zgP/v6fBuiK/r7V3fCb7OpEy1oLfRJgXAgFE=; b=P0gTqHXHtMWZB/Dk/O8tJ7pVXkuivgdgyr04JrncYGAkKbuz/4TOQ9povPoaXYuqwt qXtyRDbeHgcH5p+s1fZrDxmZnN5cN7IO1232/PGHZMgHNYy3DD1Ca6T2niJZzP8ZBZmV CcLK/EeYDfgMgT9V7gjtHS0I7698DTjp3ZLDIihajp9L5tgg+j1+JM2hGeTyYNo/gQlb CIgjOOhZudwJlGty611DC/NyiqWnmP+PvlTarXVfbN2DSWP+NO5kQ8PAwUvhImqSGZPs R2wNQzxBsUDy5hXjflBMRjTVAUmFvfG0SM8woXy0IejWV8dz6hqBZUA0Ab822DzREHg2 P0GQ== X-Gm-Message-State: AOAM531K73o9fS1bXnWd+Eju5JrfqrsUkkG9Vknnwxm2a4yjDxPIfJ8c gegJEqxvjjd7B2cwCm72jeho/gmmMdWPjD+B6akFRQ== X-Received: by 2002:a25:21c5:: with SMTP id h188mr13130824ybh.23.1630187611436; Sat, 28 Aug 2021 14:53:31 -0700 (PDT) MIME-Version: 1.0 References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-3-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Sat, 28 Aug 2021 14:53:20 -0700 Message-ID: Subject: Re: [PATCH v8 2/3] mm: add a field to store names for private anonymous memory To: Cyrill Gorcunov Cc: Andrew Morton , Colin Cross , Sumit Semwal , Michal Hocko , 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, 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, eb@emlix.com, Muchun Song , Viresh Kumar , thomascedeno@google.com, sashal@kernel.org, cxfcosmos@gmail.com, linux@rasmusvillemoes.dk, 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 Sat, Aug 28, 2021 at 2:28 PM Cyrill Gorcunov wrote: > > 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? Hi Cyrill, Correct, this is a known drawback of naming an anonymous VMA. I think I'll need to document this in prctl(2) manpage, which I should update to include this new PR_SET_VMA_ANON_NAME option. Thanks for pointing it out! Suren.