Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7025595rwd; Tue, 6 Jun 2023 05:32:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7eKeyuVRv7nU9woWvBqa2pNUC/N/i+HgTW5AGKKB8TfkpAo1U5k8Q3D+7J3oVNOS0RzgHG X-Received: by 2002:a05:6214:482:b0:62b:68cb:cb9b with SMTP id pt2-20020a056214048200b0062b68cbcb9bmr669633qvb.35.1686054736404; Tue, 06 Jun 2023 05:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686054736; cv=none; d=google.com; s=arc-20160816; b=qGzTos1LB5uCtsziqKKDcgaf77ZrYdsnQFThFkdIqMKkMxqoS9woWVse38BJ/2uPRj iAu3dEcUp4OWyhCFQSSba3PfBTZdb1K48ozlpZ4K07kqTUnRD7GOIDX4KRVRvmPYXN8d IqRI4vTbqIbWmMrGjw29jhnjhBOZ1EEjp0dRG9Ed/lYE1nPhH5nF6ALybN8ecbDPd/rH P9AG2SVyHJkw0skNF/IjmvR/Ofc/2PndbLXLc1SW/nPXpbATZtcoBiaS+VnoE/kVvRJV rxhQJ9AtZjmJc6i22lC7rmet6JnYrv1rWhOuKp6uhBtybMUL1jWcEEJov+TpbUbkYMDR 6d3Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Q2aAEm3RCrH2+Fm2fUIX9OvNQBPnSzWJiGkYFYM/R84=; b=XF6ANqCISBqKv76nvVXTZi0D/c+ZsreUxLu2TEdRR58OFRgJu6mWQPnYzMLecPIuD7 lCIjnRjvh3CYXSJ5lgtSqoWjgk47HTwPqv6R/DzNIvsKIvbgKvvfwMtM70dNhqgK0u/B CmXVNYwcdJUeptO467vUIBnhOY4kOhMhagJDeFejsoyCYTbxnqsm+TcE7Mdro3HsVuot ei+Hz9yy11cDl/txF9x4mbSkhPK7nsfgMAGuysqxE98qoojFl2pdfMGRSHpSuVNpPLjr SuGs1yCDZ5DyFNsywn6fGVosL0tx+hcChj/1EgweYxQ4c+ltA6pn1GT9iSwmZ/WZswLo DL2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QgVSczTx; 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 e5-20020a0562140d8500b005a768be48f6si5997680qve.520.2023.06.06.05.32.00; Tue, 06 Jun 2023 05:32:16 -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=QgVSczTx; 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 S232631AbjFFMXG (ORCPT + 99 others); Tue, 6 Jun 2023 08:23:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230297AbjFFMXD (ORCPT ); Tue, 6 Jun 2023 08:23:03 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 244C510C6 for ; Tue, 6 Jun 2023 05:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686054182; x=1717590182; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RbqQ3EfGHI6UTyKDi2aKopvN4mTn1VMxbyOUyuWsAiY=; b=QgVSczTxWl41Z56LIzmb6QAiyEqSDMRfmC9fXS9NAhmZcdA4jimFvviC 0gVzhlhizqqVLf27SsTflOExB/LMx214ROjnezhcnTOGiJ4MWj3F8NUVl a5dk4EdS7U03jkfmjOW6CavrC/NIc/mpqXmZMfRufn/sh7matRXVoh55+ 0o8LD1xZF52SO3HehqBjpcU2pht7QYCQqEgNGaioigfsJ5+IakaP0D44o ukCe5iW0DXX2KGFpY5F9FzrhW7J/HPG5vl4vQXdFq7OmQ+yNEM5duwNp4 DA8oyyyk51OiRNsPPKP+J+1tnKqvuAH///k/XAHYF7++Z1RZMAgJ13glR A==; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="422478429" X-IronPort-AV: E=Sophos;i="6.00,221,1681196400"; d="scan'208";a="422478429" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2023 05:23:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="1039155849" X-IronPort-AV: E=Sophos;i="6.00,221,1681196400"; d="scan'208";a="1039155849" Received: from linux-pnp-server-20.sh.intel.com ([10.239.146.185]) by fmsmga005.fm.intel.com with ESMTP; 06 Jun 2023 05:22:58 -0700 From: Yu Ma To: akpm@linux-foundation.org, tim.c.chen@intel.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, dan.j.williams@intel.com, shakeelb@google.com, Liam.Howlett@Oracle.com, pan.deng@intel.com, tianyou.li@intel.com, lipeng.zhu@intel.com, tim.c.chen@linux.intel.com, yu.ma@intel.com Subject: [PATCH] mm/mmap: move vma operations to mm_struct out of the critical section of file mapping lock Date: Tue, 6 Jun 2023 08:49:39 -0400 Message-Id: <20230606124939.93561-1-yu.ma@intel.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 --- mm/mmap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 13678edaa22c..0e694a0433bc 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2711,12 +2711,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