Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp37193102rwd; Tue, 11 Jul 2023 10:37:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlFsPK1wlPgnrhQJDJY9/lF5bvPMbCJwkhDSMsGPqeLvYg0C1T5Q7hkzIWwjxA9FHNFQsEyY X-Received: by 2002:a05:6512:3a82:b0:4f9:cd02:4af1 with SMTP id q2-20020a0565123a8200b004f9cd024af1mr13468685lfu.34.1689097060369; Tue, 11 Jul 2023 10:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689097060; cv=none; d=google.com; s=arc-20160816; b=WBe/NukZwGmgKpZfWNnDsbakQ7bHwzs8yRERyupydbKnIR0YVW3LafdAagxf7+p9S5 Hq8KHua10UFTmXMS04NJVoDG+wdJVkA6cV7Gf0Oz54ShXEKkSi8HcoGuq5KcX0ef+7C3 tu6VwCffdPvNYuu/cQHOTxRR1F1PHvJNIRqqrifKQjBCyE/t3L6J5++D04SY7scMMWAe uyo2MSwCuGoIz+g5V7qFwG3hL5wwPqpdyf42Ntnj++NhuPsVB7hjwb1pdG4ESC2VSvkU 7Ydb9H25hZC6vA9eeSHRWlJO7WjcFxJ9CoUyt/kKX/ovA0Rz1YfJpn0OncaIdl/ZC/Ee uwmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bpZKN3VukyMZTGQwqbuxnMeKA14E4h8FT0XV8eGRPsA=; fh=3gGOp/b1pmcQocWUY8sjRDW9xA1UARaIfltGM31Av6Y=; b=k0/uLyo+MvmnAf1SXSDl09IfdN18VMPSykGBL/C82qqb/bC+A0l/mx6ak5oPivyCO1 ejKO+gM9DKCoxt1//soY2E71NNnhae2iH4TUPFnqotxMzYlkupZ6XaMbL/Fxir/zC3Rm pmBCoks9z51Chc/9e200Uzxaeq45tyPEcPtEg8g7JiON3ay/SNxTlfSd5N8LhSEotdsH SCFIb3DMs4cMs2k1eDe2CM2mhdJX+x1enWMpyaOxeRsQMWqmccPnUdidGStW8ZmiXjJr XhMrEoXvzAHXqfYoWI9aowE9n26uD9pkF4NQh8++3v7Yq7lHjuSxJcE2w9esg1V8X6fM AwHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kumpe81S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x12-20020aa7dacc000000b0051e19bf1f79si2912733eds.481.2023.07.11.10.37.16; Tue, 11 Jul 2023 10:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kumpe81S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231210AbjGKQx3 (ORCPT + 99 others); Tue, 11 Jul 2023 12:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230155AbjGKQx2 (ORCPT ); Tue, 11 Jul 2023 12:53:28 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 966CDE75 for ; Tue, 11 Jul 2023 09:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689094407; x=1720630407; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TrplBJ3bzzs7m5iDqf6Oh6aYMUB0SNPyHYHI7Jj6/7o=; b=kumpe81S7q6IbG60XE0ZyNYdohOfCvobQ1eIJxAv9SfczYKlaFTrr1Mb eq5T7Ov1TElsuiyIiS2EZOcPrROUGZqwwAsrvzgxaumydWsVDf9wCIrEF XkGWq303G3K+5L6NG+frQI1USFPIjRTAe0l/IbaTJ+wSTR0rgeFezJsW4 TjQbL7NEVMrF8faVbOhgxL7SKtexZ3IOt/+lT6xEpn6NLUyKrC1bwBBLt +0+0X/FwEM9okUiBXeE1j0FMHx8RKgjGFXj2OC1G7QiQsyzCz2DBgVOwZ UL0DBw52CUH9itgVuf1ZSEbq+Hdwf54EX66jZpC52naVOpuvlVIyCmSxD A==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="354539101" X-IronPort-AV: E=Sophos;i="6.01,197,1684825200"; d="scan'208";a="354539101" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2023 09:53:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="967873360" X-IronPort-AV: E=Sophos;i="6.01,197,1684825200"; d="scan'208";a="967873360" Received: from linux-pnp-server-20.sh.intel.com ([10.239.146.185]) by fmsmga006.fm.intel.com with ESMTP; 11 Jul 2023 09:53:18 -0700 From: Yu Ma To: yu.ma@intel.com, Liam.Howlett@Oracle.com, kirill@shutemov.name, akpm@linux-foundation.org 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 v2] mm/mmap: move vma operations to mm_struct out of the critical section of file mapping lock Date: Tue, 11 Jul 2023 13:20:20 -0400 Message-Id: <20230711172020.562250-1-yu.ma@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). 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 --- v1 -> v2: - Update vma_link() to reduce the hold time on file mapping lock as well. Based on v6.4-rc7, 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 d600404580b2..6f42ca2ab84a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -444,14 +444,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); } @@ -2708,12 +2705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (vma_iter_prealloc(&vmi)) goto close_and_free_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); -- 2.39.3