Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9613883ybl; Fri, 17 Jan 2020 15:24:28 -0800 (PST) X-Google-Smtp-Source: APXvYqzw8GbMIpZpXU71u3xH8j2g6sbPLFQ9eXGzi7gIgFmzCjCMXtFR0JFTlXCTqXGijR/FZ6u+ X-Received: by 2002:a05:6830:1e99:: with SMTP id n25mr8207183otr.67.1579303468596; Fri, 17 Jan 2020 15:24:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579303468; cv=none; d=google.com; s=arc-20160816; b=jrVdRdd63Gi0Hr2DBOn3JukKRTQuOtGp7tHN3nHD0zeLhLeYg92L4zl8HnV/IcD5q0 tpPKExQIpWYBxaZZWOS3Fbr5DuuQzl0MFL7N3Xu384yW2imGZoCBlVSwBpVU1D6IMPNh rDAneA9Qm58vl50Y7B5aB3SsoJ9TBfYSM+U+kJ/taOGmHp5l1ikRuOm16njspF5KRXBY UYT6i5K5I/TKAbexti1rYuARf/Xak/m0S7E84eIdRd/pMn+bG/hrFyei5NncnArqc8Oz Ak4m2x5u2uje1aENXU3Rfj14ul7mzacnTfa1SBJfzVgU8ApMOy113Ebdl+smH6jzj9oG llhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=fOwCYG1EXY5557Vzug/aJx0HM2H0qhua/eMLpnWSgSE=; b=RkCKOoRELV7gRUTVgSYCJmj94dWpL1OtLrosgiGtpEC8zBT818U7l1ndotZZz2GJpt qC6UOrGP27VT90rUypQRcnvySEDpJLC4RMO8STeFjljurNvz5NKiwzo03zWJTIaktMzg u8fAyfCA4dGnM12oGt7jKfXGNik7EJidO65L7DWYkhTpWqlLlRBeYj1PtvB9ARdGjnF8 1wOKrIsCDjXLh2Anvq8o7Jinl4Fh6MfUs16tMk+joNaY/ISXsfWRDMO5gPEk49YICwfy svW0uAAyVACUsusm0EUvvi2Kj4eZU7+0byQ+K31Ni5PVuAomMb1tdMtNrcaeeFFkIoJm +CDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b10si15452542otp.124.2020.01.17.15.24.17; Fri, 17 Jan 2020 15:24:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730355AbgAQXXL (ORCPT + 99 others); Fri, 17 Jan 2020 18:23:11 -0500 Received: from mga06.intel.com ([134.134.136.31]:9953 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729099AbgAQXXL (ORCPT ); Fri, 17 Jan 2020 18:23:11 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jan 2020 15:23:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,332,1574150400"; d="scan'208";a="306388179" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga001.jf.intel.com with ESMTP; 17 Jan 2020 15:23:09 -0800 From: Wei Yang To: akpm@linux-foundation.org, dan.j.williams@intel.com, aneesh.kumar@linux.ibm.com, kirill@shutemov.name, yang.shi@linux.alibaba.com, richardw.yang@linux.intel.com, thellstrom@vmware.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/5] mm/mremap: calculate extent in one place Date: Sat, 18 Jan 2020 07:22:53 +0800 Message-Id: <20200117232254.2792-5-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200117232254.2792-1-richardw.yang@linux.intel.com> References: <20200117232254.2792-1-richardw.yang@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Page tables is moved on the base of PMD. This requires both source and destination range should meet the requirement. Current code works well since move_huge_pmd() and move_normal_pmd() would check old_addr and new_addr again. And then return to move_ptes() if the either of them is not aligned. In stead of calculating the extent separately, it is better to calculate in one place, so we know it is not necessary to try move pmd. By doing so, the logic seems a little clear. Signed-off-by: Wei Yang --- mm/mremap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index a258914f3ee1..37335a10779d 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -240,7 +240,7 @@ 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; struct mmu_notifier_range range; pmd_t *old_pmd, *new_pmd; @@ -253,8 +253,9 @@ unsigned long move_page_tables(struct vm_area_struct *vma, for (; old_addr < old_end; old_addr += extent, new_addr += extent) { cond_resched(); - next = pmd_addr_end(old_addr, old_end); - extent = next - old_addr; + old_next = pmd_addr_end(old_addr, old_end); + new_next = pmd_addr_end(new_addr, new_addr + len); + extent = min((old_next - old_addr), (new_next - new_addr)); old_pmd = get_old_pmd(vma->vm_mm, old_addr); if (!old_pmd) continue; @@ -298,9 +299,6 @@ unsigned long move_page_tables(struct vm_area_struct *vma, if (pte_alloc(new_vma->vm_mm, new_pmd)) break; - next = pmd_addr_end(new_addr, new_addr + len); - if (extent > next - new_addr) - extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma, new_pmd, new_addr, need_rmap_locks); } -- 2.17.1