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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47738EB64DD for ; Wed, 5 Jul 2023 19:06:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0E198D0006; Wed, 5 Jul 2023 15:06:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBE318D0001; Wed, 5 Jul 2023 15:06:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C60828D0006; Wed, 5 Jul 2023 15:06:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B35708D0001 for ; Wed, 5 Jul 2023 15:06:10 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 57AE51C8F15 for ; Wed, 5 Jul 2023 19:06:10 +0000 (UTC) X-FDA: 80978488500.08.552E00F Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by imf23.hostedemail.com (Postfix) with ESMTP id 77370140002 for ; Wed, 5 Jul 2023 19:06:07 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=shutemov.name header.s=fm1 header.b=fqQ5HCng; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="e jdVqcI"; dmarc=none; spf=pass (imf23.hostedemail.com: domain of kirill@shutemov.name designates 66.111.4.25 as permitted sender) smtp.mailfrom=kirill@shutemov.name ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688583967; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FdlxGSSLp6tolBO74VVirW7wUfppCI5xiiKHdFx4B08=; b=XjExc5XMqzeTVQz51jIF9fcdV9nwVVQlSnR25x9888yCFj7YlL1SNdzU9QhJEviRlzLNmx vgQi1Wwxl3OVSAl6dyrv4Ez9XNvJDMuT+xoIAaVk8a8V4GhCnUBi59P7QmfF5v8kjNZaKE NgPFKk9cNasGUk0GC+1HvHib6my4k6U= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=shutemov.name header.s=fm1 header.b=fqQ5HCng; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="e jdVqcI"; dmarc=none; spf=pass (imf23.hostedemail.com: domain of kirill@shutemov.name designates 66.111.4.25 as permitted sender) smtp.mailfrom=kirill@shutemov.name ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688583967; a=rsa-sha256; cv=none; b=aPSoNiDf6t9AGj6CJ1b6gwEOKAUelH7WqYJJHGx6NEX5ZSlQomCyzEyhyBrh17gMqC/LGL uxuw/z+GcScHLDIlC57miz+3LcZ/NWQsNZdZ7KW7HTeL5aOJFM8MGy3njhgpk57jmb+vYw bEm8qhtIPTqhdGeOya0owXCArdyaQuM= Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id AA03F5C023D; Wed, 5 Jul 2023 15:06:06 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 05 Jul 2023 15:06:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1688583966; x=1688670366; bh=FdlxGSSLp6tolBO74VVirW7wUfppCI5xiiK HdFx4B08=; b=fqQ5HCngeeqMUvgN9JYDZ8MpBBrq2mZr1ijbXp14mORAzg7+56Z XjSU07H5y4aV7ZcrCJEUHCUZh1GCim5OqouXGdOjl9ri4hHAnmi5og0WMs+v/j6j XpK9OFe6XRBAxH0f54fQUoDqCdAaXthsYlmuYteQqevk3aXacDJYQjjzU9l041OR 6tZNY37pMRQTs5597hhDLWolawstqjQintOH6Re56wfqKyMMYxt6nn9vvtxZKpEk 9LREF/rhBwWjxlUvo2E70DX76Bh55CDcU1FURTzMayf04u3Qw9+D0LQcPziaq2sH T07ZXBB1sNCNVCMzP76ccc5+9bY2P3ad06g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1688583966; x= 1688670366; bh=FdlxGSSLp6tolBO74VVirW7wUfppCI5xiiKHdFx4B08=; b=e jdVqcIoJpVJYBoS+XpO5O2iVG97y6Mhf98eZz+7dYWmOpDH5qms3qAF7nIA/BgDe glzBwYY/z82g52hFhfPbfFThDJ06TUK+FdIcjNwFsqhwWBJ+rUG+E0nZlIuigqcK rS6gIqxsF4YNK9oAzVatxRsVZyO6B9Fly465Ad7r5WRXZ7w6IMTa4g0Oeivhu26c es14adEDT72nfqca7R58n7/xZn7KvhUEAQKQn8aPA6gF4dP+fpfQI8pUjO381CuE pnV27LcnuqKI7lWUGkaGHN35twAAylA48W8IFRL95NWAEcXBLfCgipfcgfaiDt6A D8XUA6m20hv6IGQS6ccBA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudejgdekiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggugfgjsehtkedttddttdejnecuhfhrohhmpedfmfhirhhi lhhlucetrdcuufhhuhhtvghmohhvfdcuoehkihhrihhllhesshhhuhhtvghmohhvrdhnrg hmvgeqnecuggftrfgrthhtvghrnhepveettdeuleduveekgfeiudeftdeugfelfeffffek keetieevieeiieeiteetheevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepkhhirhhilhhlsehshhhuthgvmhhovhdrnhgrmhgv X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jul 2023 15:06:05 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id E54EE1095F9; Wed, 5 Jul 2023 22:06:01 +0300 (+03) Date: Wed, 5 Jul 2023 22:06:01 +0300 From: "Kirill A. Shutemov" To: "Liam R. Howlett" , Yu Ma , akpm@linux-foundation.org, tim.c.chen@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, dan.j.williams@intel.com, shakeelb@google.com, pan.deng@intel.com, tianyou.li@intel.com, lipeng.zhu@intel.com, tim.c.chen@linux.intel.com Subject: Re: [PATCH] mm/mmap: move vma operations to mm_struct out of the critical section of file mapping lock Message-ID: <20230705190601.4atlxzh2wxc7zlu6@box.shutemov.name> References: <20230606124939.93561-1-yu.ma@intel.com> <20230606192013.viiifjcgb6enyilx@revolver> <20230705165411.tfqqipcla7exkb7k@box.shutemov.name> <20230705173348.rxgzxge6ipb4hapy@revolver> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230705173348.rxgzxge6ipb4hapy@revolver> X-Rspamd-Queue-Id: 77370140002 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ytwka4aqx6rzp9jh5u9qkqtu5ym6f3dk X-HE-Tag: 1688583967-646621 X-HE-Meta: U2FsdGVkX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03PTSZvJEtH9/+jZiMIAkNSgt5hgBwYDIBqfm/b9J30ducM7JnHg7UobnLDXXretRN8BQY0tNKfZqSv2VWRClPhPTci8HZ8zPEeBYnGlAw2O5gETXCkvDE7dmkmGdQ7OB6XsSDn/Y1m7ICIXPVvJCnv8RYLctVbZYPIxqQX/IJ1vhU9XfSpQ9HoZ3gL9KRj9fmj0dSoXJNtrB7L+u9i4T+wcfdp6QlMdZwj7fcYjvTAeIJfUxHR6f9U8zqh3jEh9vKTMVu6oRiF5OPYU+wT5lGnWMWzWftjPAnINm98q3Wq1ISRIyTuafDIPukg== 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 Wed, Jul 05, 2023 at 01:33:48PM -0400, Liam R. Howlett wrote: > * Kirill A. Shutemov [230705 12:54]: > > On Tue, Jun 06, 2023 at 03:20:13PM -0400, Liam R. Howlett wrote: > > > * Yu Ma [230606 08:23]: > > > > UnixBench/Execl represents a class of workload where bash scripts are > > > > spawned frequently to do some short jobs. When running multiple parallel > > > > tasks, hot osq_lock is observed from do_mmap and exit_mmap. Both of them > > > > come from load_elf_binary through the call chain > > > > "execl->do_execveat_common->bprm_execve->load_elf_binary". In do_mmap,it will > > > > call mmap_region to create vma node, initialize it and insert it to vma > > > > maintain structure in mm_struct and i_mmap tree of the mapping file, then > > > > increase map_count to record the number of vma nodes used. The hot osq_lock > > > > is to protect operations on file’s i_mmap tree. For the mm_struct member > > > > change like vma insertion and map_count update, they do not affect i_mmap > > > > tree. Move those operations out of the lock's critical section, to reduce > > > > hold time on the lock. > > > > > > > > With this change, on Intel Sapphire Rapids 112C/224T platform, based on > > > > v6.0-rc6, the 160 parallel score improves by 12%. The patch has no > > > > obvious performance gain on v6.4-rc4 due to regression of this benchmark > > > > from this commit f1a7941243c102a44e8847e3b94ff4ff3ec56f25 (mm: convert > > > > mm's rss stats into percpu_counter). > > > > > > I didn't think it was safe to insert a VMA into the VMA tree without > > > holding this write lock? We now have a window of time where a file > > > mapping doesn't exist for a vma that's in the tree? Is this always > > > safe? Does the locking order in mm/rmap.c need to change? > > > > We hold mmap lock on write here, right? > > Yes. > > >Who can observe the VMA until the > > lock is released? > > With CONFIG_PER_VMA_LOCK we can have the VMA read under the rcu > read lock for page faults from the tree. I am not sure if the vma is > initialized to avoid page fault issues - vma_start_write() should either > be taken or initialise the vma as this is the case. Right, with CONFIG_PER_VMA_LOCK the vma has to be unusable until it is fully initialized, effectively providing the same guarantees as mmap write lock. If it is not the case, it is CONFIG_PER_VMA_LOCK bug. > There is also a possibility of a driver mapping a VMA and having entry > points from other locations. It isn't accessed through the tree though > so I don't think this change will introduce new races? Right. > > It cannot be retrieved from the VMA tree as it requires at least read mmap > > lock. And the VMA doesn't exist anywhere else. > > > > I believe the change is safe. > > I guess insert_vm_struct(), and vma_link() callers should be checked and > updated accordingly? Yep. -- Kiryl Shutsemau / Kirill A. Shutemov