From patchwork Wed Apr 7 03:05:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xu, Yanfei" X-Patchwork-Id: 12186633 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 E975DC43460 for ; Wed, 7 Apr 2021 03:06:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6135561369 for ; Wed, 7 Apr 2021 03:06:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6135561369 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=windriver.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 41F586B0081; Tue, 6 Apr 2021 23:06:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CEC86B0082; Tue, 6 Apr 2021 23:06:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F9536B0083; Tue, 6 Apr 2021 23:06:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id EC95B6B0081 for ; Tue, 6 Apr 2021 23:06:08 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B703D8249980 for ; Wed, 7 Apr 2021 03:06:08 +0000 (UTC) X-FDA: 78004082016.02.194D2F6 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2075.outbound.protection.outlook.com [40.107.243.75]) by imf21.hostedemail.com (Postfix) with ESMTP id 96458E0001AC for ; Wed, 7 Apr 2021 03:06:07 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VLJd4QgG47xXEXoo8c+TgKAYX+Tr12EdUKd096p4a8BP2BvpebuNRho+y+SLDxLUOvjD8wUPbfyChp2OC4WwubfBKo+YJDtfHdgzj8phpmag/DkBY8TDLNtdwqlNE5D4DdpNitd9Qdw38iD+qGGQkJC07UMOSlZONGGBQFdNkP9wYjSMvXqhBuiFXMGwNHbLw94Tsehd3PAQNa6/yp2Vf7/QXBws9NiM6fcU6oLzLxaCdPLqKQnSxo6mWujgFBf9wnmaXh6TfCv2crbqmP0qyxVmurH+lJKU0a4HCkJPLMyxn45jdsc/FUJCVwrrEda6oA02YlK3I/N9t9xl7wTaEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PHshhN4h6TRXXAwkAbo7pnyPuGjnlVA8bSZADuaCnEI=; b=Cb5J3WeB2pH0f7KzwEV6GYZuM+lII3fP+FCb03zU6GGGNj0ewTHzYGXiH6gW2b+qEsHK73Fa9QGZeHZch6WpvCHfvOwhkFiDziJ7cVBxytyJdik0S5beycrq/DiNv0/YaHc0tVpGjpQ5/c0DeyTg3hPpXWvyoT1yyVNdMi+ygBcwD/DLk/bpQb/85twy7AGsHF/H7pasU+dPscbEwEWhxbyHR5FlLj3A1TwCWRDtIUPVPSTRWA5uJEAn4OXB3V/N0m6cEf63sbjExwHRii+QDzWsC1NKZkobnXXgGT9QjRFQrqSTIdAhjbn/rMfCp0olGKAJZTNlID5x/T4LngvGSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PHshhN4h6TRXXAwkAbo7pnyPuGjnlVA8bSZADuaCnEI=; b=fyuOxjIr6HCFpXth4H6U6lMF5W6kzJIzwqa/O2bW56IBuJTsX24Zj721QloX7237AWGc+9IxhVcbjicj8BKYiPDFUvhte3Z4BLWjmC/hCnnSzkKYYZO7ruObVLA9mMlPe25om9Ys7LE59Kw1rhAOPZvzgQGblYffL+jfRAe1jb8= Authentication-Results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=windriver.com; Received: from BY5PR11MB4241.namprd11.prod.outlook.com (2603:10b6:a03:1ca::13) by SJ0PR11MB4864.namprd11.prod.outlook.com (2603:10b6:a03:2d4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Wed, 7 Apr 2021 03:06:06 +0000 Received: from BY5PR11MB4241.namprd11.prod.outlook.com ([fe80::551b:e310:2ae4:3011]) by BY5PR11MB4241.namprd11.prod.outlook.com ([fe80::551b:e310:2ae4:3011%6]) with mapi id 15.20.3999.032; Wed, 7 Apr 2021 03:06:06 +0000 From: yanfei.xu@windriver.com To: shy828301@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] mm: khugepaged: use macro to align addresses Date: Wed, 7 Apr 2021 11:05:47 +0800 Message-Id: <20210407030548.189104-2-yanfei.xu@windriver.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210407030548.189104-1-yanfei.xu@windriver.com> References: <20210407030548.189104-1-yanfei.xu@windriver.com> X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK0PR03CA0104.apcprd03.prod.outlook.com (2603:1096:203:b0::20) To BY5PR11MB4241.namprd11.prod.outlook.com (2603:10b6:a03:1ca::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-lpggp1.wrs.com (60.247.85.82) by HK0PR03CA0104.apcprd03.prod.outlook.com (2603:1096:203:b0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Wed, 7 Apr 2021 03:06:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4aaf2817-be1a-4ca1-0e56-08d8f97215cb X-MS-TrafficTypeDiagnostic: SJ0PR11MB4864: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yKNWN7ELdpmQ4pluAPbTPRdCkIJb+KJ3HgePG2kyowc3KbNyA3vocH9/Ev0jk++om6zv55qNQruMan7z8WH+WO8acpBIDmhXAhHVCC8ZrgcQFKLMWOy5Ce6sqPXCt6Tw9rQSljnKQrI+LBNEkVPO16/HhYSHWm1nUsfalifs1a85FclC/wDceBTumT7UQi6Mvag1Ef4ElbDcblmU1/QdIMVB3xb6gwzBx3fN8cjioK/6+RmUG1Ehp0P96WIj9I4ASA2eauWOz4FS5u9cNUvHAu45BL62pYoMXM/UO7FZ2oUWHYRBnaN97u4DaCC0wMm5NBgrHkC2kHZJe03p6l/YZVlpIgTfZtRks83PFVQGwfImcLnLEVv2ZdNmQ0z0N2ZsFt5ZXUtuX9XJ3/UXK6nn6MqTsyzWW+eyibEmT2gzPsur8MA74WoBLusKvab/cFiz0uzjFN2de8xw16n4pdjsd9/6KTM7ImGz98ggId5mTTjuJOZbm2aMQX5F2k12g8qKpGr/Oo9k4Bdh5kZhfhMNk8wJ+nFMQXGj3wGOLSPw86WV9qViL29l9JPN6ngXMHrUftzF47g/sHJJ0KPRklj7cgeeaO0J3P6AIUTf65ZdCBXPIO512pKTqLNipn2QCTJUJQwPl7Er3tyBDiBp29wQrGIhM6/JaS1923C8LZoP01iGgohoZ8RYbsx8Bo29p7MK X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR11MB4241.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(346002)(39850400004)(136003)(396003)(4326008)(26005)(6916009)(52116002)(38350700001)(66476007)(38100700001)(83380400001)(2616005)(8936002)(316002)(9686003)(6506007)(16526019)(86362001)(66946007)(6512007)(5660300002)(36756003)(6666004)(2906002)(478600001)(6486002)(1076003)(956004)(8676002)(66556008)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: o+Z73QgMbMp99mL97bkQ1QfkJkh/aV4iJw65hub7miIKZnTdviMXNRD3diLDraDLH5U0UJV8pSJ0Wl6YfuYB3HyUOf68j74FVu9OzkqTpQ1+ympl/E8d82uHXuXe3HfcSVVifxbu89jKgMBoJ4XJPi5Wk4MoJ+IMcIcUZYaL/RXB5NiXagwTeDqbDxjxlRhrpJf167a+jD+O2YfTcO/0R3LvEAXAeBlSeS6iD2GhKW8PfdH3SV57Kh2cN10wvb6uJGTTmMBoRdvnBLinYQ+crZqFLOcmr3tEPdRN11jt5UaPSphmLDMkeRUUT2h4M3HCt3HJ09g6pm6j4stlZmXcC65C2LGzcA+NKExSe1WmMy9BW8RAJqb2+J/ZB+BBHXmhC728og5s64dVIdha1cW/Gp6YSCbw+kUesyc5OS7eS9K1uZhHZHecc78/5hMnTykB0FRsMxrnhIUQ7lCvTkt7pAzgAfU3zmqRZXeJ80h82p6Gam4kBS3ozGVcNvYqqfuNoMcTU9UzUzWYzYvlegcq3eslyjpvBp0nAKNdOtaDv4Gzi14+bUM+60oxP17WSTgbPlSxyExkYWHWdz7wCJDChLP+hsbfP5g0jk7VYYMfAhamH56aecfJElMocdZMA4BsaVPzcfOZgaf16ddAw5DQK4j9wkbBOn0aOcgleObUzUuFHgIWiSgOX73gQA1P8Wil6JqbPj37t+s8wBFaA8adZvKglb+e4fc/FpwMmkxnCd6HFNUKDiFurqtrxWDpgiIVN3L0C67QpjfJJR38dU91c5BY7wcjsgKplihMT5g4veOkIGtdgrFgaeOGODB9kMFwpQHN3GwunyRr6UR90cWUMHiLR3yntUTxiL3nhQSCU6l6D4xWz7myO0L3mnbrGH6IzoD97gwiZjZFlKIBZ8P10EXX1wSOE4PMJzt7DAFtO9eAVDJf1r6HtBm2b/aD836CB5xtF9l0TmRmYsyp/yaHuTgsh7mbn+f/5ZfQIACDeLqnwc5DVvGlRussN26SnG5aypLiJ1P2xW77DgwZGIC6wBjWTiM+qWjB65YbshN5Pn0mSS4OQAM7/COoKlVtaR8zy8CrgsqVjV7Ooa5YZNO68GCrBV8zJ89fJ5a5QPihV5JlqlrtmUyu0OtnHJUyZijefG+qiDWw3HzI2YU+5o23OmsPvgKODY4R7z9z7Ms+2yhWK/MtqodUXx0Y0OXwduN42j9jX61tyYhhla71WibXY551L7OYY8rqpuYJX+r1yseoIK25nC2fj7dzTyHME745YUYGice9ft2vXeAlRzQItXj8itrD13KRaNHnQlIkpYdExt8rBQ4bhdEc6+uFfxRt X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4aaf2817-be1a-4ca1-0e56-08d8f97215cb X-MS-Exchange-CrossTenant-AuthSource: BY5PR11MB4241.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2021 03:06:06.2730 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: okxn5FPZvd3RGo0nmr9usWlNVAaUt7DTqqFDLBcAPentzo+1yd0/aO/oxJ1dvLTyk90qQ1Gf+m9QgMpE/ZKdvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB4864 X-Rspamd-Queue-Id: 96458E0001AC X-Stat-Signature: xjd96sqep3fywsqyd7f3r4zkzhoqtd4d X-Rspamd-Server: rspam02 Received-SPF: none (windriver.com>: No applicable sender policy available) receiver=imf21; identity=mailfrom; envelope-from=""; helo=NAM12-DM6-obe.outbound.protection.outlook.com; client-ip=40.107.243.75 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617764767-280716 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: From: Yanfei Xu We could use macro to deal with the addresses which need to be aligned to improve readability of codes. Signed-off-by: Yanfei Xu Reviewed-by: Yang Shi --- 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;