Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9613733ybl; Fri, 17 Jan 2020 15:24:17 -0800 (PST) X-Google-Smtp-Source: APXvYqxAzmSAQ7Ulb7yXbYzgW7Xd6hX1SXeCiMVm6YcKXjLMFXfrH3NIO32wCD4+ubZ2Ql98QNYb X-Received: by 2002:aca:4c9:: with SMTP id 192mr5583101oie.105.1579303457432; Fri, 17 Jan 2020 15:24:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579303457; cv=none; d=google.com; s=arc-20160816; b=jBI7fRupircJO07hCq+C9xqOl33mW2jOBw2sIUalOOTQZqUPQIaWMp2iiY8jszFgdr M+grDhFmmXuKsgvXCV72oBR9gYePxoEBKXJ9BmXtgje5NgdqwyGaH7Vnx3UAgllXaZD8 IaMMFTZl2EJJ9guomdAEZ9HidZpXbSBe0ATAybbJhNlzNWdJb7sYFMZJ1ebVYVoXeY+r pL5a1jjHDwmwpfTd/i5fBLBRl0sc+GuRyW1Sm16W5JyZjY51uCv8Lb9L6OSvHrIWQecQ J31y8MzYyvgGcqQMXMnJn8r+9JmZBnaqGjNCLjlzldhQm3AWFo4vYSRnCrC99PuRFrl4 +dGg== 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=iDOVjBHDPfFRzbq4FAtKc1GvRloE3f8Fcf77WQgy2V4=; b=kdiGYJyWqbQNE2zA+a9WcQaqUvZE7vZagM06fTg/0AezcixCdknahlZ4KLfveCrP7b ur2ZbZ6KlkhPPrTuhFhvCZpVOkr200/Mz2SWEyiv8Rim9cLplSTr7W8hPdSSoGlJ0pEv rXaVRkv/VLyCQTc+Ei9POl1olrYtqP4WlPZ2B4BnJZ+84/1rVIycuOttKFqPrNjNRVCb t4Ysel+AiQdbBNJpnIuSckeu4LCWX6abULXuKeKHE1un2MbKDc6VCTZP2gAUyGsAfDb/ hZFHKJuNdY+kFtxLx+aozMvvEMkZwEYwvgGzXmpLIgUIg6n7XOdbYHMwWCYUbQYZqZmN /bmQ== 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 m4si15786976otr.122.2020.01.17.15.24.06; Fri, 17 Jan 2020 15:24:17 -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 S1730320AbgAQXXH (ORCPT + 99 others); Fri, 17 Jan 2020 18:23:07 -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 S1729099AbgAQXXG (ORCPT ); Fri, 17 Jan 2020 18:23:06 -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:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,332,1574150400"; d="scan'208";a="306388163" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga001.jf.intel.com with ESMTP; 17 Jan 2020 15:23:04 -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 2/5] mm/mremap: it is sure to have enough space when extent meets requirement Date: Sat, 18 Jan 2020 07:22:51 +0800 Message-Id: <20200117232254.2792-3-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 old_end is passed to these two function to check whether there is enough space to do the move, while this check is done before invoking these functions. These two functions only would be invoked when extent meets the requirement and there is one check before invoking these functions: if (extent > old_end - old_addr) extent = old_end - old_addr; This implies (old_end - old_addr) won't fail the check in these two functions. Signed-off-by: Wei Yang --- include/linux/huge_mm.h | 2 +- mm/huge_memory.c | 7 ++----- mm/mremap.c | 11 ++++------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 0b84e13e88e2..2a5281ca46c8 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -42,7 +42,7 @@ extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr, unsigned long end, unsigned char *vec); extern bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr, - unsigned long new_addr, unsigned long old_end, + unsigned long new_addr, pmd_t *old_pmd, pmd_t *new_pmd); extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr, pgprot_t newprot, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 5b2876942639..8f1bbbf01f5b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1871,17 +1871,14 @@ static pmd_t move_soft_dirty_pmd(pmd_t pmd) } bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr, - unsigned long new_addr, unsigned long old_end, - pmd_t *old_pmd, pmd_t *new_pmd) + unsigned long new_addr, pmd_t *old_pmd, pmd_t *new_pmd) { spinlock_t *old_ptl, *new_ptl; pmd_t pmd; struct mm_struct *mm = vma->vm_mm; bool force_flush = false; - if ((old_addr & ~HPAGE_PMD_MASK) || - (new_addr & ~HPAGE_PMD_MASK) || - old_end - old_addr < HPAGE_PMD_SIZE) + if ((old_addr & ~HPAGE_PMD_MASK) || (new_addr & ~HPAGE_PMD_MASK)) return false; /* diff --git a/mm/mremap.c b/mm/mremap.c index bcc7aa62f2d9..c2af8ba4ba43 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -193,16 +193,13 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, #ifdef CONFIG_HAVE_MOVE_PMD static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr, - unsigned long new_addr, unsigned long old_end, - pmd_t *old_pmd, pmd_t *new_pmd) + unsigned long new_addr, pmd_t *old_pmd, pmd_t *new_pmd) { spinlock_t *old_ptl, *new_ptl; struct mm_struct *mm = vma->vm_mm; pmd_t pmd; - if ((old_addr & ~PMD_MASK) || - (new_addr & ~PMD_MASK) || - old_end - old_addr < PMD_SIZE) + if ((old_addr & ~PMD_MASK) || (new_addr & ~PMD_MASK)) return false; /* @@ -274,7 +271,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma, if (need_rmap_locks) take_rmap_locks(vma); moved = move_huge_pmd(vma, old_addr, new_addr, - old_end, old_pmd, new_pmd); + old_pmd, new_pmd); if (need_rmap_locks) drop_rmap_locks(vma); if (moved) @@ -294,7 +291,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma, if (need_rmap_locks) take_rmap_locks(vma); moved = move_normal_pmd(vma, old_addr, new_addr, - old_end, old_pmd, new_pmd); + old_pmd, new_pmd); if (need_rmap_locks) drop_rmap_locks(vma); if (moved) -- 2.17.1