Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp943764pxf; Wed, 7 Apr 2021 15:43:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpUXjpcxDBVGO0cQPwFlivoqgSxToU535PZ5M0Z/FovEo9Xdq72sHOlmAl4CZxNCSU9tcu X-Received: by 2002:a17:902:bd8f:b029:e6:ec5a:3a6 with SMTP id q15-20020a170902bd8fb02900e6ec5a03a6mr5190070pls.31.1617835390034; Wed, 07 Apr 2021 15:43:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617835390; cv=none; d=google.com; s=arc-20160816; b=iipeCoLsxjQQWTp99WPEvvWn1KuctnbVOOKlMaoTBZInRp6JJ5QaYz+sJBfmFYJRgz xAcbVaxmeh9ZxElv10J/9cBDSyEvlcuHadmRm74UdlIn2HFm9i8AF51wBEHVuw57MLYk 5auq2IT0fJdaHpFZfOjLMaD6BZ0Dtyace0GPyZFpZrDzHo3EDkHUduWRnWq6k7pdB8kT NYjPORtFdNZ4SzndAuk+N1Emr7GPUhsMsxoJR4lcOThRGIOtzfdw4FR590CvD5ebonr8 pLbRWuyYSexiE+eQ/HTwpV6blW7+cMabLvOsrCq9xZtTYhuHT+UnUx/3K0oMXxK2ihRc 2xig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Xcr7lkbzXaoQQpjftuqW3C9GNiBJ/UK2Pd0JhhADfVc=; b=Iy8xb0J6o+SM7pG0OwcHzm5T9yz3HVv/ojmejo/MYw++7G+2GgARsArogEKX2a/Z/Y ISnSJmO62qxSfAfQGofawuCbeTBtCe40JuWzA2b8XjsifhShsCqLoDQdxDRqAPG3MHw+ AtfqQwE5tMYnbmxnxAqfdstDsxfPgel/pznvAEn+q4BojhLfpDV+UTqjaBRziLaLwZPm q/GtbWfP2Na/6K/JJ0Rr42r28nD7QqJnciZWWuiEyPfimoH/NFyPBKzuM23tnf/iPtaP T7/0XhOTwCCD7V20oGSQIGx99/FXWi033dM1vpxVw6aFbwCl74s1fiBHWrCUwgoHygYc V4dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jBIJI4Ca; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r31si2183223pgk.493.2021.04.07.15.42.58; Wed, 07 Apr 2021 15:43:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jBIJI4Ca; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233872AbhDGVkx (ORCPT + 99 others); Wed, 7 Apr 2021 17:40:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233744AbhDGVkw (ORCPT ); Wed, 7 Apr 2021 17:40:52 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74928C061760 for ; Wed, 7 Apr 2021 14:40:42 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id u21so30049639ejo.13 for ; Wed, 07 Apr 2021 14:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Xcr7lkbzXaoQQpjftuqW3C9GNiBJ/UK2Pd0JhhADfVc=; b=jBIJI4CajgIYTLrsGgHZPCltrspIBa9ahPXL/098Ibl5qMITduKF13NU/xadSZUgsM O1YNdcqhimuxaPNp019e4WXYfA1NppYy9HdRf2pDugPB8pPUjgZyPbmK/0ghJmkNhm7F EgDFbX8l2jlZ43QCH8pyx0clmmhB1jkCqzhXwhUL0GuxPMdDR6+0f7J6Mr1XIOCMrs0Z e9xXvn6axD8MSguM8kbutN45Ffd4DlNyEeOb19t1FweGN+lcll2hi7yk5qoLHl1uV9Vi YBMcJjHJAkCl7h8F8KQzCTvX29hhrJnZH/61TTzy++MturPeVrdPfVCg0BcbMretMnSG rp0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Xcr7lkbzXaoQQpjftuqW3C9GNiBJ/UK2Pd0JhhADfVc=; b=V2hvn1Lj3IR+45hBSvaKy+4lxo9QYm7dEdgIQsoGJk8AwU07h0+hP6OZs49nFXwBBH PhBmz8PgtCgje10pmvWJpYNdQBqBUwgOCMGtlceOPQzQL80bywsW8Is1TGmiFxjW6TKZ GwkKfw92fFevTzGs/lnEZVTZXAOg5MGY1T5/9qXoj1XYV/FMQjafMBsYDF3kumv2ILRJ AfTCv+2viSNEavsdy+OleJAfDclxvk7RFOW5OVg5bw3KMxJsrmi8lpyhNfREZUfEW4uN NB/k7X2CKzbBb1IIcl8ojoK2aR/ap5rxU5+HGImd7Fic6hcfz6yEk7zi1HuqL6TDGri9 mhEA== X-Gm-Message-State: AOAM533X2tu6a1tBWC21paHs5LZpJub6Igdrse3+rA6MnU4FXPLN+wHq pUdhR5mAKbqXCrS6mSAf0FJvk6AXhudb8qb3nRE= X-Received: by 2002:a17:906:4bce:: with SMTP id x14mr6056959ejv.383.1617831641231; Wed, 07 Apr 2021 14:40:41 -0700 (PDT) MIME-Version: 1.0 References: <20210407030548.189104-1-yanfei.xu@windriver.com> <20210407030548.189104-2-yanfei.xu@windriver.com> In-Reply-To: <20210407030548.189104-2-yanfei.xu@windriver.com> From: Yang Shi Date: Wed, 7 Apr 2021 14:40:29 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] mm: khugepaged: use macro to align addresses To: yanfei.xu@windriver.com Cc: Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 6, 2021 at 8:06 PM wrote: > > From: Yanfei Xu > > We could use macro to deal with the addresses which need to be aligned > to improve readability of codes. Reviewed-by: Yang Shi > > Signed-off-by: Yanfei Xu > --- > mm/khugepaged.c | 27 +++++++++++++-------------- > 1 file changed, 13 insertions(+), 14 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index a7d6cb912b05..a6012b9259a2 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -517,8 +517,8 @@ int khugepaged_enter_vma_merge(struct vm_area_struct *vma, > if (!hugepage_vma_check(vma, vm_flags)) > return 0; > > - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; > - hend = vma->vm_end & HPAGE_PMD_MASK; > + hstart = ALIGN(vma->vm_start, HPAGE_PMD_SIZE); > + hend = ALIGN_DOWN(vma->vm_end, HPAGE_PMD_SIZE); > if (hstart < hend) > return khugepaged_enter(vma, vm_flags); > return 0; > @@ -979,8 +979,8 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, > if (!vma) > return SCAN_VMA_NULL; > > - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; > - hend = vma->vm_end & HPAGE_PMD_MASK; > + hstart = ALIGN(vma->vm_start, HPAGE_PMD_SIZE); > + hend = ALIGN_DOWN(vma->vm_end, HPAGE_PMD_SIZE); > if (address < hstart || address + HPAGE_PMD_SIZE > hend) > return SCAN_ADDRESS_RANGE; > if (!hugepage_vma_check(vma, vma->vm_flags)) > @@ -1070,7 +1070,7 @@ static void collapse_huge_page(struct mm_struct *mm, > struct mmu_notifier_range range; > gfp_t gfp; > > - VM_BUG_ON(address & ~HPAGE_PMD_MASK); > + VM_BUG_ON(!IS_ALIGNED(address, HPAGE_PMD_SIZE)); > > /* Only allocate from the target node */ > gfp = alloc_hugepage_khugepaged_gfpmask() | __GFP_THISNODE; > @@ -1235,7 +1235,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, > int node = NUMA_NO_NODE, unmapped = 0; > bool writable = false; > > - VM_BUG_ON(address & ~HPAGE_PMD_MASK); > + VM_BUG_ON(!IS_ALIGNED(address, HPAGE_PMD_SIZE)); > > pmd = mm_find_pmd(mm, address); > if (!pmd) { > @@ -1414,7 +1414,7 @@ static int khugepaged_add_pte_mapped_thp(struct mm_struct *mm, > { > struct mm_slot *mm_slot; > > - VM_BUG_ON(addr & ~HPAGE_PMD_MASK); > + VM_BUG_ON(!IS_ALIGNED(addr, HPAGE_PMD_SIZE)); > > spin_lock(&khugepaged_mm_lock); > mm_slot = get_mm_slot(mm); > @@ -1437,7 +1437,7 @@ static int khugepaged_add_pte_mapped_thp(struct mm_struct *mm, > */ > void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr) > { > - unsigned long haddr = addr & HPAGE_PMD_MASK; > + unsigned long haddr = ALIGN_DOWN(addr, HPAGE_PMD_SIZE); > struct vm_area_struct *vma = find_vma(mm, haddr); > struct page *hpage; > pte_t *start_pte, *pte; > @@ -1584,7 +1584,7 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff) > if (vma->anon_vma) > continue; > addr = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); > - if (addr & ~HPAGE_PMD_MASK) > + if (!IS_ALIGNED(addr, HPAGE_PMD_SIZE)) > continue; > if (vma->vm_end < addr + HPAGE_PMD_SIZE) > continue; > @@ -2070,7 +2070,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, > { > struct mm_slot *mm_slot; > struct mm_struct *mm; > - struct vm_area_struct *vma; > + struct vm_area_struct *vma = NULL; > int progress = 0; > > VM_BUG_ON(!pages); > @@ -2092,7 +2092,6 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, > * Don't wait for semaphore (to avoid long wait times). Just move to > * the next mm on the list. > */ > - vma = NULL; > if (unlikely(!mmap_read_trylock(mm))) > goto breakouterloop_mmap_lock; > if (likely(!khugepaged_test_exit(mm))) > @@ -2112,15 +2111,15 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, > progress++; > continue; > } > - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; > - hend = vma->vm_end & HPAGE_PMD_MASK; > + hstart = ALIGN(vma->vm_start, HPAGE_PMD_SIZE); > + hend = ALIGN_DOWN(vma->vm_end, HPAGE_PMD_SIZE); > if (hstart >= hend) > goto skip; > if (khugepaged_scan.address > hend) > goto skip; > if (khugepaged_scan.address < hstart) > khugepaged_scan.address = hstart; > - VM_BUG_ON(khugepaged_scan.address & ~HPAGE_PMD_MASK); > + VM_BUG_ON(!IS_ALIGNED(khugepaged_scan.address, HPAGE_PMD_SIZE)); > if (shmem_file(vma->vm_file) && !shmem_huge_enabled(vma)) > goto skip; > > -- > 2.27.0 >