From patchwork Wed Jul 12 14:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yu Ma X-Patchwork-Id: 13310462 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 D14DCEB64DD for ; Wed, 12 Jul 2023 14:30:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CBAD6B0072; Wed, 12 Jul 2023 10:30:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 57B266B0075; Wed, 12 Jul 2023 10:30:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 443356B0078; Wed, 12 Jul 2023 10:30:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 381566B0072 for ; Wed, 12 Jul 2023 10:30:59 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 072381602A5 for ; Wed, 12 Jul 2023 14:30:58 +0000 (UTC) X-FDA: 81003196638.25.022A2BD Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf13.hostedemail.com (Postfix) with ESMTP id 53C1E2001B for ; Wed, 12 Jul 2023 14:30:46 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="UL1pEJ/Y"; spf=pass (imf13.hostedemail.com: domain of yu.ma@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=yu.ma@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689172248; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=AB5+NLcCXnzaRvbPgiz6n5N6dMyIeHmGAZh6vW2zkuk=; b=TUBsl1KEFa99loXv9/lzTS3Q0fIRwmRAc2iU4FrC0MC2ys4pfnfR/OT9wEtjf9Q+oXuzAg ySz2WZAUpA3uRMC1+mSYLga34UjTredJOy3J84t73lVHIH1HWv/CVwniNWXpQ6yY6CVxfF okYI209b3KG7S7dH6DRnanVZsSThB30= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="UL1pEJ/Y"; spf=pass (imf13.hostedemail.com: domain of yu.ma@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=yu.ma@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689172248; a=rsa-sha256; cv=none; b=tFISNqo6QumlfrOOmn48UkXuoPfTsZnUOjYLv0m7Ny71Gam/tm5C5xj1ZBIDJjr8RDspA1 aCMjyHxhKueDVoZZgjs0HScSaqYw+JBariotu6kioxEcy1Yzd/daHQ6U+VQ3lye7jWXlwT wB+KYCAgMESjvay6SQ3lRgYjUjwEdFA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689172247; x=1720708247; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5HuHECwAhlLAZmEKECs99DXvcfxOeVUXcj3HB1kzxlY=; b=UL1pEJ/YKzo0Y4UGb1DzYz47J4HmXaeANvwq/ZEKGwmWCiqo1yBITNtJ ExVG8jCu2Nw6TQYi7eG/wTfgl1WDIy3CDl8xc1L5SsDBuI80Xlf4iye+B j6VeYo7NlBUji86b2OxtJUyYpmqRh9oSzPNeylh+WfvQQhw3dN7QH+BSy GXcVJiE6EgWTxUNycC4oKGTB7aKMRTtcNynfjj7FOczXEPjWCToeLai7p AuIdjPqwAoMd42BRZFiqIUbQuS+d4KuTcWVYKm214C8HdVTut0uZfsicO 57D+2SFIu+lL11g0uPgtS0T3xQsQay7V4j733mElESkZFy7zNV6rVvvIn w==; X-IronPort-AV: E=McAfee;i="6600,9927,10769"; a="363768526" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="363768526" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 07:30:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10769"; a="724893684" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="724893684" Received: from linux-pnp-server-20.sh.intel.com ([10.239.146.185]) by fmsmga007.fm.intel.com with ESMTP; 12 Jul 2023 07:30:39 -0700 From: Yu Ma To: akpm@linux-foundation.org, Liam.Howlett@Oracle.com, kirill@shutemov.name, yu.ma@intel.com Cc: dan.j.williams@intel.com, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, lipeng.zhu@intel.com, pan.deng@intel.com, shakeelb@google.com, tianyou.li@intel.com, tim.c.chen@intel.com, tim.c.chen@linux.intel.com Subject: [PATCH v3] mm/mmap: move vma operations to mm_struct out of the critical section of file mapping lock Date: Wed, 12 Jul 2023 10:57:39 -0400 Message-Id: <20230712145739.604215-1-yu.ma@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230711112824.e559065488b08ce649cccfd7@linux-foundation.org> References: <20230711112824.e559065488b08ce649cccfd7@linux-foundation.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 53C1E2001B X-Rspam-User: X-Stat-Signature: 7j15iokk93ku5bfa1srtgmz4hoxsnkfn X-Rspamd-Server: rspam01 X-HE-Tag: 1689172246-81581 X-HE-Meta: U2F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zyTjHHMDloU1iDZAW44n/foY7AM+Fl/ajQKeBaSIiNjSyloqJMiRThnJsk0grFG1ParmZb6Rc1RdqfzzxuEcrYC5oTShmS38Ws2Ot+DRpw5FXa1trloJxUaMbwT96CsCstC932fv9/Axk62NEHe/W5g03AvFWqC4XzCauTTaS0s3hzNM= 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: 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.5-rc1 due to regression of this benchmark from this commit f1a7941243c102a44e8847e3b94ff4ff3ec56f25 (mm: convert mm's rss stats into percpu_counter). Related discussion and conclusion can be referred at the mail thread initiated by 0day as below: Link: https://lore.kernel.org/linux-mm/a4aa2e13-7187-600b-c628-7e8fb108def0@intel.com/ Reviewed-by: Tim Chen Signed-off-by: Yu Ma --- v2 -> v3: Rebase the patch to v6.5-rc1, which includes 1c7873e3364 (mm: lock newly mapped VMA with corrected ordering), and update commit message to status on v6.5-rc1 v1 -> v2: Update vma_link() to reduce the hold time on file mapping lock as well. Based on v6.5-rc1, vma_link() is only called by insert_vm_struct () and copy_vma(), which are both protected by mmap_lock. --- --- mm/mmap.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 3eda23c9ebe7..ce31aec82e82 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -412,14 +412,11 @@ static int vma_link(struct mm_struct *mm, struct vm_area_struct *vma) if (vma_iter_prealloc(&vmi)) return -ENOMEM; + vma_iter_store(&vmi, vma); + if (vma->vm_file) { mapping = vma->vm_file->f_mapping; i_mmap_lock_write(mapping); - } - - vma_iter_store(&vmi, vma); - - if (mapping) { __vma_link_file(vma, mapping); i_mmap_unlock_write(mapping); } @@ -2811,12 +2808,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Lock the VMA since it is modified after insertion into VMA tree */ vma_start_write(vma); - if (vma->vm_file) - i_mmap_lock_write(vma->vm_file->f_mapping); - vma_iter_store(&vmi, vma); mm->map_count++; if (vma->vm_file) { + i_mmap_lock_write(vma->vm_file->f_mapping); if (vma->vm_flags & VM_SHARED) mapping_allow_writable(vma->vm_file->f_mapping);