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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 5E53EC432BE for ; Mon, 30 Aug 2021 07:03:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 87E8360FC3 for ; Mon, 30 Aug 2021 07:03:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 87E8360FC3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=emlix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C54F88D0001; Mon, 30 Aug 2021 03:03:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDE046B0071; Mon, 30 Aug 2021 03:03:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACCEE8D0001; Mon, 30 Aug 2021 03:03:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id 998226B006C for ; Mon, 30 Aug 2021 03:03:45 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 457A425F51 for ; Mon, 30 Aug 2021 07:03:45 +0000 (UTC) X-FDA: 78530856810.04.ECA2284 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by imf27.hostedemail.com (Postfix) with ESMTP id BDBD4700009B for ; Mon, 30 Aug 2021 07:03:44 +0000 (UTC) Received: from mailer.emlix.com (unknown [81.20.119.6]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id AD3BD5F830; Mon, 30 Aug 2021 09:03:42 +0200 (CEST) From: Rolf Eike Beer To: akpm@linux-foundation.org, Suren Baghdasaryan Cc: 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, songmuchun@bytedance.com, viresh.kumar@linaro.org, thomascedeno@google.com, sashal@kernel.org, cxfcosmos@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.ker nel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, surenb@google.com Subject: Re: [PATCH v8 3/3] mm: add anonymous vma name refcounting Date: Mon, 30 Aug 2021 09:03:37 +0200 Message-ID: <15537178.k4V9gYNSIy@devpool47> Organization: emlix GmbH In-Reply-To: <20210827191858.2037087-4-surenb@google.com> References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-4-surenb@google.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart7924556.MAaWd901kX"; micalg="pgp-sha256"; protocol="application/pgp-signature" Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: BDBD4700009B X-Stat-Signature: sou6hqrdutmetux78wopjrzp7q636gww X-HE-Tag: 1630307024-178858 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: --nextPart7924556.MAaWd901kX Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8"; protected-headers="v1" From: Rolf Eike Beer To: akpm@linux-foundation.org, Suren Baghdasaryan Cc: 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, songmuchun@bytedance.com, viresh.kumar@linaro.org, thomascedeno@google.com, sashal@kernel.org, cxfcosmos@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.ker nel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, surenb@google.com Subject: Re: [PATCH v8 3/3] mm: add anonymous vma name refcounting Date: Mon, 30 Aug 2021 09:03:37 +0200 Message-ID: <15537178.k4V9gYNSIy@devpool47> Organization: emlix GmbH In-Reply-To: <20210827191858.2037087-4-surenb@google.com> References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-4-surenb@google.com> Am Freitag, 27. August 2021, 21:18:58 CEST schrieb Suren Baghdasaryan: > 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. >=20 > Signed-off-by: Suren Baghdasaryan > --- > include/linux/mm_types.h | 9 ++++++++- > mm/madvise.c | 42 +++++++++++++++++++++++++++++++++------- > 2 files changed, 43 insertions(+), 8 deletions(-) >=20 > diff --git a/mm/madvise.c b/mm/madvise.c > index bc029f3fca6a..32ac5dc5ebf3 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -63,6 +63,27 @@ static int madvise_need_mmap_write(int behavior) > } > } >=20 > +static struct anon_vma_name *anon_vma_name_alloc(const char *name) > +{ > + struct anon_vma_name *anon_name; > + size_t len =3D strlen(name); > + > + /* Add 1 for NUL terminator at the end of the anon_name->name */ > + anon_name =3D kzalloc(sizeof(*anon_name) + len + 1, > + GFP_KERNEL); > + kref_init(&anon_name->kref); > + strcpy(anon_name->name, name); > + > + return anon_name; > +} Given that you overwrite anything in that struct anyway this could be reduc= ed=20 to kmalloc(), no? And it definitely needs a NULL check. Eike =2D-=20 Rolf Eike Beer, emlix GmbH, http://www.emlix.com =46on +49 551 30664-0, Fax +49 551 30664-11 Gothaer Platz 3, 37083 G=C3=B6ttingen, Germany Sitz der Gesellschaft: G=C3=B6ttingen, Amtsgericht G=C3=B6ttingen HR B 3160 Gesch=C3=A4ftsf=C3=BChrung: Heike Jordan, Dr. Uwe Kracke =E2=80=93 Ust-IdNr= =2E: DE 205 198 055 emlix - smart embedded open source --nextPart7924556.MAaWd901kX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iLMEAAEIAB0WIQQ/Uctzh31xzAxFCLur5FH7Xu2t/AUCYSyCyQAKCRCr5FH7Xu2t /NTBA/4w0Kyux1kZmQldKJbME0UYvkgufssyGT64trylJ9vimg5BqpnDovDsqJ95 kkdFhKDf92sGd40RHaODdfH3ibw/VLG1mwXA1qYB00oGJLKu+Mp6RJqUrWiQoLSf 9ejd24XMNMD0bdqxOCgb7uSm87o1PRDAfP8u6l6dgeyvk5mAgw== =fael -----END PGP SIGNATURE----- --nextPart7924556.MAaWd901kX--