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 185A0C48BF6 for ; Mon, 26 Feb 2024 06:06:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 621C2940008; Mon, 26 Feb 2024 01:06:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D1BF6B0165; Mon, 26 Feb 2024 01:06:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4993A940008; Mon, 26 Feb 2024 01:06:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3A2966B0164 for ; Mon, 26 Feb 2024 01:06:41 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0777B160680 for ; Mon, 26 Feb 2024 06:06:41 +0000 (UTC) X-FDA: 81832921002.12.71F1736 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by imf12.hostedemail.com (Postfix) with ESMTP id D20F94000D for ; Mon, 26 Feb 2024 06:06:37 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ORjYR0uK; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.16 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=1708927598; 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=YH8gxChvx1IC/D7c280KuxAG+iJIyzI+oVnHVOaOUjY=; b=7SnQrKBre+B6gNhYh9j9Yj+HerQjtgnCvrGBlf8jbekQrZUkGJS2dfrUzEFgNTxXfeRXPe hTyaTzoZhvJpGYuwAtEJ9tH0VuCJxhUljzJBjK9G7shESFhDxze1RafUjh5jfoshq9hVQv WlMQwQyF6FMl14PbzMsP3xlAVUzQJ0Q= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ORjYR0uK; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.16 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708927598; a=rsa-sha256; cv=none; b=SYTUqFhK2O+w9fonDAgUN81nlXH4YEMHTzwWcxobDOr65gWXvT/16xDck7L4PZ6Sg7nBbe t2tVKvN/T9LDgoQn2rkZtqbabTyX5f4m7+gd0ADFYweMQEWmDq+EDyv/3FyGVF5KCKG5t2 SSteB0rsU9wkxNdIWEDcd3MS4Z6VPdg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708927598; x=1740463598; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=IWRwZUmQYBIgvXHr5gj3H8ECbGXuQbEwHNX97+KVQBY=; b=ORjYR0uKMm+I+o3nQbqrD7eCFOoEfBvwri8gDYmNJBSqeQ3N6rRB3xdN ROkn6qzOEYufn3usB0s0U74CxCE1nn8rIWfz5t+bkqajM9z5Be7OCVC4z kNFoUu4ERluiBr2oqUj0NSL5LX+cMKp9qCgzYmEwJx5KjJEtML89Tfwvp qkitDVXNefvsTGgcEa/JaeQH6upDDOOiDC1wqMDuYVQVSm87gHZTseYf4 CzIWWK/cF/+gGnGqqcBPA9uVgwrkRQkJ06psDZamN5yIrQyez9AN+EMpN 47KD/rdWoZIP+s82J0GlRdPBm3eq0f4oatCYYSpnEIKhLi8V6QcyzSyr/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="3737683" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="3737683" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2024 22:06:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="11128153" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2024 22:06:33 -0800 From: "Huang, Ying" To: "zhangpeng (AS)" Cc: , , , , , , , , , , Nanyong Sun Subject: Re: [PATCH v2] filemap: avoid unnecessary major faults in filemap_fault() In-Reply-To: (zhangpeng's message of "Mon, 26 Feb 2024 10:55:43 +0800") References: <20240206092627.1421712-1-zhangpeng362@huawei.com> <87jznhypxy.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Mon, 26 Feb 2024 14:04:38 +0800 Message-ID: <87frxfhibt.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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D20F94000D X-Stat-Signature: dhwjxq1cmad33ssqo54jkbnghtr5kw4o X-HE-Tag: 1708927597-267610 X-HE-Meta: U2FsdGVkX19oY2m0gPOWff3DFkNfhQbgWl5Ehcdk26JlS7+MHbIc1z3gGyrKkU0eRSCZUf5V+hhnwefxtbYQ0TjnwS5kzg9CtcAN1VtlzKd+PW+akDwQlwRxcM42cuk6ZKnKEVG+NRrKj3Oxy3Ioz7s6jx4NRQTyakG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uXejLu0VVw3R1yhIULLa6lizi405pUAhTSa7j2vwPXFQ2qwsRdnY4HoexoemVnGuS/c1oyhRCZjKYKbo5CstU1fEJXxztv9g9k3STskOpxwuDIBNRdL8 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: "zhangpeng (AS)" writes: > On 2024/2/7 10:21, Huang, Ying wrote: > >> 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. > > I'm sorry that maybe I didn't express myself clearly. > > The purpose of this patch is to fix the issue that major fault may still be triggered > with mlockall(), thereby improving a little performance. This patch is more of a bugfix > than a performance improvement patch. > > This issue affects our traffic analysis service. The inbound traffic is heavy. If a major > fault occurs, the I/O schedule is triggered and the original I/O is suspended. Generally, > the I/O schedule is 0.7 ms. If other applications are operating disks, the system needs > to wait for more than 10 ms. However, the inbound traffic is heavy and the NIC buffer is > small. As a result, packet loss occurs. The traffic analysis service can't tolerate packet > loss. > > To prevent packet loss, we use the mlockall() function to prevent I/O. It is unreasonable > that major faults will still be triggered after mlockall() is used. > > In our service test environment, the baseline is 7 major faults/12 hours. After applied the > unlock patch, the probability of triggering the major fault is 1 major faults/12 hours. After > applied the lock patch, no major fault will be triggered. So only the locked patch can actually > solve our problem. This is the data I asked for. But, you said that this is a feature bug fix instead of performance improvement. So, I checked the mlock(2), and found the following words, " mlockall() locks all pages mapped into the address space of the calling process. This includes the pages of the code, data, and stack segment, as well as shared libraries, user space kernel data, shared memory, and memory-mapped files. All mapped pages are guaranteed to be resident in RAM when the call returns successfully; the pages are guaranteed to stay in RAM until later unlocked. " In theory, the locked page are in RAM. So, IIUC, we don't violate the ABI. But, in effect, we does do that. But, from git history, we have cleared the PTE during modification from 2.6.12-rc2 at least. I guess that because Linux isn't a hard real time OS, users don't expect that too. -- Best Regards, Huang, Ying > The test data provided is intended to prove that the patch does not have a major impact > on the performance of the page fault itself. > >>> 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. > > OK, I'll fix it in the next version. > >>> + 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