From patchwork Wed Jul 8 01:24:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11650545 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CD5013B6 for ; Wed, 8 Jul 2020 01:25:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 74590207C4 for ; Wed, 8 Jul 2020 01:25:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74590207C4 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 8072B8D0010; Tue, 7 Jul 2020 21:25:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7B97B8D0003; Tue, 7 Jul 2020 21:25:51 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A71B8D0010; Tue, 7 Jul 2020 21:25:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id 474678D0003 for ; Tue, 7 Jul 2020 21:25:51 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 09847181AEF09 for ; Wed, 8 Jul 2020 01:25:51 +0000 (UTC) X-FDA: 77013166902.02.range13_070198226eb9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id CFB69600018EC22E for ; Wed, 8 Jul 2020 01:25:50 +0000 (UTC) X-Spam-Summary: 1,0,0,05c86e343259f9c8,d41d8cd98f00b204,richard.weiyang@linux.alibaba.com,,RULES_HIT:41:355:379:541:960:973:988:989:1260:1261:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:2693:2898:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3871:4321:5007:6261:6737:10004:11026:11473:11658:11914:12043:12048:12295:12297:12438:12555:12895:12986:13069:13161:13229:13311:13357:13894:14096:14181:14384:14721:21080:21451:21627:30012:30054:30065:30070,0,RBL:115.124.30.42:@linux.alibaba.com:.lbl8.mailshell.net-64.201.201.201 62.20.2.100;04yf7uokrbk6ygd3gm4r8kue11famypyp7ed1c6pifzrfhrwwzyozp7km8yb4np.1kpkh5swk7cis1r4gerobmir4camiimy5b9ewgk89jqmr4pz73neubqtrapextj.y-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: range13_070198226eb9 X-Filterd-Recvd-Size: 3277 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Wed, 8 Jul 2020 01:25:49 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04397;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0U23pI3U_1594171545; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0U23pI3U_1594171545) by smtp.aliyun-inc.com(127.0.0.1); Wed, 08 Jul 2020 09:25:45 +0800 From: Wei Yang To: akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, vbabka@suse.cz, yang.shi@linux.alibaba.com, thomas_os@shipmail.org, anshuman.khandual@arm.com, sean.j.christopherson@intel.com, richard.weiyang@linux.alibaba.com, peterx@redhat.com, aneesh.kumar@linux.ibm.com, willy@infradead.org, thellstrom@vmware.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, digetx@gmail.com Subject: [Patch v3 4/4] mm/mremap: use pmd_addr_end to simplify the calculate of extent Date: Wed, 8 Jul 2020 09:24:53 +0800 Message-Id: <20200708012453.36588-5-richard.weiyang@linux.alibaba.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20200708012453.36588-1-richard.weiyang@linux.alibaba.com> References: <20200708012453.36588-1-richard.weiyang@linux.alibaba.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: CFB69600018EC22E X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: The purpose of this code is to calculate the smaller extent in old and new range. Let's leverage pmd_addr_end() to do the calculation. Hope this would make the code easier to read. Signed-off-by: Wei Yang --- mm/mremap.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index f5f17d050617..76e7fdf567c3 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -237,11 +237,12 @@ unsigned long move_page_tables(struct vm_area_struct *vma, unsigned long new_addr, unsigned long len, bool need_rmap_locks) { - unsigned long extent, next, old_end; + unsigned long extent, old_next, new_next, old_end, new_end; struct mmu_notifier_range range; pmd_t *old_pmd, *new_pmd; old_end = old_addr + len; + new_end = new_addr + len; flush_cache_range(vma, old_addr, old_end); mmu_notifier_range_init(&range, MMU_NOTIFY_UNMAP, 0, vma, vma->vm_mm, @@ -250,14 +251,11 @@ unsigned long move_page_tables(struct vm_area_struct *vma, for (; old_addr < old_end; old_addr += extent, new_addr += extent) { cond_resched(); - next = (old_addr + PMD_SIZE) & PMD_MASK; - /* even if next overflowed, extent below will be ok */ - extent = next - old_addr; - if (extent > old_end - old_addr) - extent = old_end - old_addr; - next = (new_addr + PMD_SIZE) & PMD_MASK; - if (extent > next - new_addr) - extent = next - new_addr; + + old_next = pmd_addr_end(old_addr, old_end); + new_next = pmd_addr_end(new_addr, new_end); + extent = min((old_next - old_addr), (new_next - new_addr)); + old_pmd = get_old_pmd(vma->vm_mm, old_addr); if (!old_pmd) continue;