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 X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DADEC433E0 for ; Fri, 24 Jul 2020 04:41:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 37971206E3 for ; Fri, 24 Jul 2020 04:41:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37971206E3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4CE308D0017; Fri, 24 Jul 2020 00:41:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47F8E8D0007; Fri, 24 Jul 2020 00:41:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36D8F8D0017; Fri, 24 Jul 2020 00:41:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 1DAC18D0007 for ; Fri, 24 Jul 2020 00:41:00 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A4CC08248047 for ; Fri, 24 Jul 2020 04:40:59 +0000 (UTC) X-FDA: 77071719438.23.kite20_180df4026f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 0F44E163DC for ; Fri, 24 Jul 2020 04:38:28 +0000 (UTC) X-HE-Tag: kite20_180df4026f44 X-Filterd-Recvd-Size: 5402 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 04:38:26 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0U3dLuJ4_1595565494; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0U3dLuJ4_1595565494) by smtp.aliyun-inc.com(127.0.0.1); Fri, 24 Jul 2020 12:38:20 +0800 Subject: Re: [patch 01/15] mm/memory.c: avoid access flag update TLB flush for retried page fault To: Andrew Morton , catalin.marinas@arm.com, hannes@cmpxchg.org, hdanton@sina.com, hughd@google.com, josef@toxicpanda.com, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, will.deacon@arm.com, willy@infradead.org, xuyu@linux.alibaba.com References: <20200724041508.QlTbrHnfh%akpm@linux-foundation.org> From: Yang Shi Message-ID: <30cf7356-bef1-c621-60cb-e12a8bd9111d@linux.alibaba.com> Date: Thu, 23 Jul 2020 21:38:10 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20200724041508.QlTbrHnfh%akpm@linux-foundation.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Queue-Id: 0F44E163DC X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: On 7/23/20 9:15 PM, Andrew Morton wrote: > From: Yang Shi > Subject: mm/memory.c: avoid access flag update TLB flush for retried page fault > > Recently we found regression when running will_it_scale/page_fault3 test > on ARM64. Over 70% down for the multi processes cases and over 20% down > for the multi threads cases. It turns out the regression is caused by > commit 89b15332af7c0312a41e50846819ca6613b58b4c ("mm: drop mmap_sem before > calling balance_dirty_pages() in write fault"). > > The test mmaps a memory size file then write to the mapping, this would > make all memory dirty and trigger dirty pages throttle, that upstream > commit would release mmap_sem then retry the page fault. The retried page > fault would see correct PTEs installed by the first try then update dirty > bit and clear read-only bit and flush TLBs for ARM. The regression is > caused by the excessive TLB flush. It is fine on x86 since x86 doesn't > clear read-only bit so there is no need to flush TLB for this case. > > The page fault would be retried due to: > 1. Waiting for page readahead > 2. Waiting for page swapped in > 3. Waiting for dirty pages throttling > > The first two cases don't have PTEs set up at all, so the retried page > fault would install the PTEs, so they don't reach there. But the #3 case > usually has PTEs installed, the retried page fault would reach the dirty > bit and read-only bit update. But it seems not necessary to modify those > bits again for #3 since they should be already set by the first page fault > try. > > Of course the parallel page fault may set up PTEs, but we just need care > about write fault. If the parallel page fault setup a writable and dirty > PTE then the retried fault doesn't need do anything extra. If the > parallel page fault setup a clean read-only PTE, the retried fault should > just call do_wp_page() then return as the below code snippet shows: > > if (vmf->flags & FAULT_FLAG_WRITE) { > if (!pte_write(entry)) > return do_wp_page(vmf); > } > > With this fix the test result get back to normal. > > Link: http://lkml.kernel.org/r/1594148072-91273-1-git-send-email-yang.shi@linux.alibaba.com > Signed-off-by: Yang Shi > Reported-by: Xu Yu > Debugged-by: Xu Yu > Tested-by: Xu Yu > Cc: Johannes Weiner > Cc: Matthew Wilcox (Oracle) > Cc: Kirill A. Shutemov > Cc: Josef Bacik > Cc: Hillf Danton > Cc: Hugh Dickins > Cc: Catalin Marinas > Cc: Will Deacon > Signed-off-by: Andrew Morton > --- > > mm/memory.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > --- a/mm/memory.c~mm-avoid-access-flag-update-tlb-flush-for-retried-page-fault > +++ a/mm/memory.c > @@ -4241,8 +4241,13 @@ static vm_fault_t handle_pte_fault(struc > if (vmf->flags & FAULT_FLAG_WRITE) { > if (!pte_write(entry)) > return do_wp_page(vmf); > - entry = pte_mkdirty(entry); > } > + > + if ((vmf->flags & FAULT_FLAG_WRITE) && !(vmf->flags & FAULT_FLAG_TRIED)) > + entry = pte_mkdirty(entry); > + else if (vmf->flags & FAULT_FLAG_TRIED) > + goto unlock; Hi Andrew, It looks you forgot fold v2 update? v2 is here https://lore.kernel.org/linux-mm/1594848990-55657-1-git-send-email-yang.shi@linux.alibaba.com/ and in -mm tree too. > + > entry = pte_mkyoung(entry); > if (ptep_set_access_flags(vmf->vma, vmf->address, vmf->pte, entry, > vmf->flags & FAULT_FLAG_WRITE)) { > _