Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2427207pxb; Sat, 28 Aug 2021 14:29:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyPxLkt96F4qbTEo816i1URP3WxEaXEuRcZnD7l4j57MlX1p/XSpQe12w3x+ejeOUO05lf X-Received: by 2002:a92:c848:: with SMTP id b8mr10821868ilq.54.1630186154252; Sat, 28 Aug 2021 14:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630186154; cv=none; d=google.com; s=arc-20160816; b=flScUOrHwxZm0j/mfaOA/QGSGtHUC4ku7pIR7zcwFinCz3GK4AQFHp//WcVoRJoT0O oO4a0UNj9FIAZYUqftTgYa9Eyi+SbFbdnSLOUFWEcWKc6JzJrtJ8eGmROmf6ZSoi7fya 2Gu2lpfK8IJo8OwBcKs6bVPloewbRCBCJXPIepq4Gkjxz3/MU4YnycmvPIU7pz3h9w9t SRbCSfH1plg2fakFzIkVpKNvQxN0Pcj2MEuZmvdPoHUbz5uwFlREqf4P6uZHOLakzzHx VwwSKMfYF7ULrB6wGPfqGo11ZuXDgYgmHg1/dPNGlVivG7egwp/ZT5v2XlqfKMn9V1u7 jLdw== 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=ICcSCFexjhpp8PBl0tQjqKkSyaD0mJsG1uKHkuscRbw=; b=eYxotd6EnuqhGY55Hyyn8LVjnp7onupX7QtRRf8HCGpvfO4k7Kr65kI91GYRd2LL5L h0qi5jLvwi6KND78/J+KEwgxlf1GhyeMJfzF2WL9wsLyLH4/ta8OuPa7EWWrrbSyJK3l 9HtoY67BfjzKxrnqLTSrXi9R13Z3WKB98kwu7ENNmEnMBYFNXesJdmp5TxVYMoBy69Xi wQFjflamXaHJQ0dKHcFY7TvS2ZEwJiKkcx+Qy32CGYAiar7QVcqd71g1Opyg4TJjqthB 0i3zCvH3V6QocIc73Cfh6dIcWZ6X7eIDOEnDDipaKkhy1C6pBu358ODkjqGWdeDrZxRK nIXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="gV1T+5i/"; 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 n20si9863337iod.5.2021.08.28.14.29.02; Sat, 28 Aug 2021 14:29:14 -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="gV1T+5i/"; 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 S232383AbhH1VOv (ORCPT + 99 others); Sat, 28 Aug 2021 17:14:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbhH1VOt (ORCPT ); Sat, 28 Aug 2021 17:14:49 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD55BC061756 for ; Sat, 28 Aug 2021 14:13:58 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id z18so19731924ybg.8 for ; Sat, 28 Aug 2021 14:13:58 -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=ICcSCFexjhpp8PBl0tQjqKkSyaD0mJsG1uKHkuscRbw=; b=gV1T+5i/k5S8ZzJnpNhMlyvXxAUnUgvbFDNvQcSjiLmWAm+5RMKOptlxPVAbDSB9y5 DjNRnN5aBxTyw4/H75I2FCH88Zwihmjf9TpcXO0SJAX0UN8e8SIAlqjOOjkIanqGlbTY RMI8YRMNYv2G0S6FVFQCX5uNDAR2kKbD92SjaqnfnhfD0tQqLs3X8CtGg8rjSdEceQ6S MvJcXW+AL/eJW0wFEQvZwnxxN6qjnabEpuE4gDcxYezkBmtBq4lWKff5KT71Tk38dlWf Y6FEywUwpOgKyVBbSlLlUHSK8Ky94Q6eoOfKdGBLWf3OAxCQyDjyLfUl+Mam1YIEpNhr GF+A== 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=ICcSCFexjhpp8PBl0tQjqKkSyaD0mJsG1uKHkuscRbw=; b=ACbSfkJACqi4wUh/Pa4ApS4M2qt8F5H/2pbtrNjvyh1hL16qv4SPpqAVhU8U1JXgfE qXfJwuv7JvFdyIPr9EJLwQtcItfo6PwbpMcoqFOjYIcbz6Gsyk3FguS9Fogucd113bMc VHK6mZDFSb/zArrpEMVKEFXkYsHCnwMrBgbAcg6yq9Lx8TW9lFDciXcl/SWPF4RjSa4w na3OTqZYD4w1WDkQo6w/lnxQDV4UWTMuCYGQgpS1sY/4TuB+23COvim6iJPyzDEOiZv8 9aQEWTWlqS1MtPGy89s5GKlxJrImG2gycV+RsSJ0hYGKawV18HDUKlNtViQeYKeINTFN kMyQ== X-Gm-Message-State: AOAM532fDfLqpCfxSorzgOdTBF14E2/jVIOHIaeWeRJaQEs9YCU5GD9s eu/oh5M/1titiS1D48lQ0pXKU9oOvwAsRW59HysHaw== X-Received: by 2002:a25:810c:: with SMTP id o12mr14438431ybk.250.1630185237477; Sat, 28 Aug 2021 14:13:57 -0700 (PDT) MIME-Version: 1.0 References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-4-surenb@google.com> <202108271746.F444DA6C9@keescook> In-Reply-To: <202108271746.F444DA6C9@keescook> From: Suren Baghdasaryan Date: Sat, 28 Aug 2021 14:13:46 -0700 Message-ID: Subject: Re: [PATCH v8 3/3] mm: add anonymous vma name refcounting To: Kees Cook Cc: Andrew Morton , Colin Cross , Sumit Semwal , Michal Hocko , Dave Hansen , 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 Fri, Aug 27, 2021 at 10:28 PM Kees Cook wrote: > > On Fri, Aug 27, 2021 at 12:18:58PM -0700, Suren Baghdasaryan wrote: > > While forking a process with high number (64K) of named anonymous vmas the > > overhead caused by strdup() is noticeable. Experiments with ARM64 Android > > device show up to 40% performance regression when forking a process with > > 64k unpopulated anonymous vmas using the max name lengths vs the same > > process with the same number of anonymous vmas having no name. > > Introduce anon_vma_name refcounted structure to avoid the overhead of > > copying vma names during fork() and when splitting named anonymous vmas. > > When a vma is duplicated, instead of copying the name we increment the > > refcount of this structure. Multiple vmas can point to the same > > anon_vma_name as long as they increment the refcount. The name member of > > anon_vma_name structure is assigned at structure allocation time and is > > never changed. If vma name changes then the refcount of the original > > structure is dropped, a new anon_vma_name structure is allocated > > to hold the new name and the vma pointer is updated to point to the new > > structure. > > With this approach the fork() performance regressions is reduced 3-4x > > times and with usecases using more reasonable number of VMAs (a few > > thousand) the regressions is not measurable. > > I like the refcounting; thank you! > > Since patch2 adds a lot of things that are changed by patch3; maybe > combine them? I thought it would be easier to review with the main logic being written using a basic type (string) first and then replace the basic type with a more complex refcounted structure. Also, if someone would like to rerun the tests and measure the regression of strdup vs refcounting approach, keeping this patch separate makes it easier to set up these tests. If that's not convenient I can absolutely squash them together. > > -- > Kees Cook