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 A5391C48297 for ; Wed, 7 Feb 2024 02:23:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 191546B007E; Tue, 6 Feb 2024 21:23:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 141846B0081; Tue, 6 Feb 2024 21:23:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 009316B0082; Tue, 6 Feb 2024 21:23:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E5CAD6B007E for ; Tue, 6 Feb 2024 21:23:31 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BBE2A120BE7 for ; Wed, 7 Feb 2024 02:23:31 +0000 (UTC) X-FDA: 81763411422.06.98D31FC Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by imf09.hostedemail.com (Postfix) with ESMTP id 9FB0D140015 for ; Wed, 7 Feb 2024 02:23:29 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=He7hg3oB; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.19 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707272609; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZiZatWIFKYpaFw65AGoqJm0OVmf1hjJxvX/6hQK2IY0=; b=uqkoN/dWxPO+60cySPDHkHOo0g8Aogm3EDWNYv5qvZ+Zo2qqyRtWPCC2x/WGJEL+TkD61E J8wJxiJbs6k5kjiEFG3g41dm/jEF/3SRTi09m1K1Fu8MdfHNAKqHMyY2sFRv7FbPlnNaWb oXzydjFxM6kAJr2pWj+apvydoAne1NQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=He7hg3oB; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.19 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707272609; a=rsa-sha256; cv=none; b=gGDuFrPapZx5Jy7VeaB/QPypCf+Kin67gp7yGplE3/CUeRDwVQJYUVugmewRj67kD9nGtL yfO30VPs31FSQD7eZaemcHweB04shXER3X1LvJPubeaRIMCQbiQQQf6EP/BTwc3TIf68qx PzCJ1PuJH/Kld5upJcYWL136IY4i+HQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707272610; x=1738808610; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=4N/5tP5iMHWmFVdx1HRYIF5wy7QwMIH1xbJY0jDg6SY=; b=He7hg3oBDxnRR3qV3uBjjbPzD3IuW04WlGYT/wqVvJER89cQGFJSzTkD ecoZe7l7ldmFGJ7qdaio2hD6Fllsz2aIad7HwWkuufYhkhKgJo7e2+Gs8 R5DtVOXxnd7A7HJbrBiMT5ht1TKLPcksw7a6sSZCLanbF60FIf15Vey1F bG2cCnTGJ7WzpNSVn0W4jjw1GwAyqncPGJ2Lzg20LYmXUS0JpV7QgCeUJ YhS7+zFj27bVkmvQ5aSOMsocfKS7HVwkLjMLiQ9Amjfu9sIK8IZgAswBs N/xkP/stEkOJDZrI8rDY+ugz8JCvOSOExcU0KmD0fBkwUKgXWUXFU1zTw A==; X-IronPort-AV: E=McAfee;i="6600,9927,10976"; a="780227" X-IronPort-AV: E=Sophos;i="6.05,248,1701158400"; d="scan'208";a="780227" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 18:23:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,248,1701158400"; d="scan'208";a="1421154" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 18:23:25 -0800 From: "Huang, Ying" To: Peng Zhang Cc: , , , , , , , , , Subject: Re: [PATCH v2] filemap: avoid unnecessary major faults in filemap_fault() In-Reply-To: <20240206092627.1421712-1-zhangpeng362@huawei.com> (Peng Zhang's message of "Tue, 6 Feb 2024 17:26:27 +0800") References: <20240206092627.1421712-1-zhangpeng362@huawei.com> Date: Wed, 07 Feb 2024 10:21:29 +0800 Message-ID: <87jznhypxy.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspamd-Queue-Id: 9FB0D140015 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ktk6x75f64pgtynzknc5rkhdau3b6ybb X-HE-Tag: 1707272609-86098 X-HE-Meta: U2FsdGVkX19QNoArmgy8n33oL1zsSSK5sYOKmrd/ZSHyScfkL6C+Ja1TsRbXWJkyVBXD86rb3Z3GbTB2KaSXdoZc63yW2JUzxwbGrhnVaqDYnLp+Gly2E8S/2eOYcCuMwYW/wWq0ZCSqyrFZdtynJDxeb5s3KHumOc/GFLBrvkSYdDrD5qzq0i2nSj3pI70cv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I83FKcR+EJAu7CS7/6A2lznIDe3LSXgz3AVQLeIGCq52Ltw3VZlXoLb0P+av43SIzl/2t/3dE+HbAcb/ZGQbD1o4J1 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: List-Subscribe: List-Unsubscribe: Peng Zhang writes: > From: ZhangPeng > > The major fault occurred when using mlockall(MCL_CURRENT | MCL_FUTURE) > in application, which leading to an unexpected performance issue[1]. > > This caused by temporarily cleared PTE during a read+clear/modify/write > update of the PTE, eg, do_numa_page()/change_pte_range(). > > For the data segment of the user-mode program, the global variable area > is a private mapping. After the pagecache is loaded, the private anonymous > page is generated after the COW is triggered. Mlockall can lock COW pages > (anonymous pages), but the original file pages cannot be locked and may > be reclaimed. If the global variable (private anon page) is accessed when > vmf->pte is zeroed in numa fault, a file page fault will be triggered. > > At this time, the original private file page may have been reclaimed. > If the page cache is not available at this time, a major fault will be > triggered and the file will be read, causing additional overhead. > > Fix this by rechecking the PTE without acquiring PTL in filemap_fault() > before triggering a major fault. > > Testing file anonymous page read and write page fault performance in ext4 > and ramdisk using will-it-scale[2] on a x86 physical machine. The data > is the average change compared with the mainline after the patch is > applied. The test results are within the range of fluctuation, and there > is no obvious difference. The test results are as follows: You still claim that there's no difference in the test results. If so, why do you implement the patch? IMHO, you need to prove your patch can improve the performance in some cases. > processes processes_idle threads threads_idle > ext4 private file write: -1.14% -0.08% -1.87% 0.13% > ext4 shared file write: 0.14% -0.53% 2.88% -0.77% > ext4 private file read: 0.03% -0.65% -0.51% -0.08% > tmpfs private file write: -0.34% -0.11% 0.20% 0.15% > tmpfs shared file write: 0.96% 0.10% 2.78% -0.34% > ramdisk private file write: -1.21% -0.21% -1.12% 0.11% > ramdisk private file read: 0.00% -0.68% -0.33% -0.02% > > [1] https://lore.kernel.org/linux-mm/9e62fd9a-bee0-52bf-50a7-498fa17434ee@huawei.com/ > [2] https://github.com/antonblanchard/will-it-scale/ > > Suggested-by: "Huang, Ying" > Suggested-by: Yin Fengwei > Signed-off-by: ZhangPeng > Signed-off-by: Kefeng Wang > --- > v1->v2: > - Add more test results per Huang, Ying > - Add more comments before check PTE per Huang, Ying, David Hildenbrand > and Yin Fengwei > - Change pte_offset_map_nolock to pte_offset_map as the ptl lock won't > be used > > RFC->v1: > - Add error handling when ptep == NULL per Huang, Ying and Matthew > Wilcox > - Check the PTE without acquiring PTL in filemap_fault(), suggested by > Huang, Ying and Yin Fengwei > - Add pmd_none() check before PTE map > - Update commit message and add performance test information > > mm/filemap.c | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/mm/filemap.c b/mm/filemap.c > index 142864338ca4..a2c1a98bc771 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -3238,6 +3238,40 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) > mapping_locked = true; > } > } else { > + if (!pmd_none(*vmf->pmd)) { > + pte_t *ptep; > + > + ptep = pte_offset_map(vmf->pmd, vmf->address); > + if (unlikely(!ptep)) > + return VM_FAULT_NOPAGE; > + /* > + * Recheck PTE as the PTE can be cleared temporarily > + * during a read+clear/modify/write update of the PTE, > + * eg, do_numa_page()/change_pte_range(). This will > + * trigger a major fault, even if we use mlockall, > + * which may affect performance. > + * We don't hold PTL here as acquiring PTL hurts > + * performance. So the check is still racy, but > + * the race window seems small enough. > + * > + * If we lose the race during the check, the page_fault > + * will be triggered. Butthe page table entry lock > + * still make sure the correctness: > + * - If the page cache is not reclaimed, the page_fault > + * will work like the page fault was served already > + * and bail out. > + * - If the page cache is reclaimed, the major fault > + * will be triggered, page cache is filled, > + * page_fault also work like the page fault was > + * served already and bail out. > + */ IMHO, this is too long. It can be shorten to like, If we lose the race, major fault may be triggered unnecessary. This hurts performance but not functionality. > + if (unlikely(!pte_none(ptep_get_lockless(ptep)))) > + ret = VM_FAULT_NOPAGE; > + pte_unmap(ptep); > + if (unlikely(ret)) > + return ret; > + } > + > /* No page in the page cache at all */ > count_vm_event(PGMAJFAULT); > count_memcg_event_mm(vmf->vma->vm_mm, PGMAJFAULT); -- Best Regards, Huang, Ying