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; From patchwork Wed Apr 7 03:05:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xu, Yanfei" X-Patchwork-Id: 12186635 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 E652EC433ED for ; Wed, 7 Apr 2021 03:06:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7BC3F613D1 for ; Wed, 7 Apr 2021 03:06:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BC3F613D1 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 F1B706B0082; Tue, 6 Apr 2021 23:06:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECB906B0083; 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 D1D826B0085; Tue, 6 Apr 2021 23:06:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id B02C26B0082 for ; Tue, 6 Apr 2021 23:06:09 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 67AB5180ACF8B for ; Wed, 7 Apr 2021 03:06:09 +0000 (UTC) X-FDA: 78004082058.15.32175A2 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 38C26E0001AC for ; Wed, 7 Apr 2021 03:06:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nLDQwyj+kgHZMEwpZ9pD8j+MekRXvEi5vOUCgCIV3d8bD//MpnT6VuIDcC4z1V/d03D53Ibxq7Gpqpaa9PxVQ5jtrShMkV7ntJBl6TTzihs6YxM9fcPf4YWXCQHfJr4djo41PYMhH04hLAqk6CNPwNnyOgnaivzZmTRRFbYXl5dproaTRplpzxPmVRf3AACSTvmbvf5LpQoS5IEYxAxpQTpqvvZx91Uro+Q8MsZRXUkw2v2D2LDRCRE8bADe2FTPx1e/wvCOYwOaH0Ta5TCTf015j31xBCbvSxOA0Pn3ZSRMYNhRMY1tgRBUI8k2+KoRSCNDYj7ESjWv35Llq08CSQ== 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=5PxYS/FOxV9IHr5Qx1bG4OJDt+34SM/KiBs+qc7GLJE=; b=IaP8zBfoipSyjhFAfKl17QiVIcFDbJrEDIMLyVbio5osTmX3UZiwJnNAKIn2pPGhvVMjLzL8FGuXuI+w34jjCvE6IKD160cX7Q5VH3afrCvWygLB9MhEu6Wzs+4qCli6ldeSFPXvciJc0PZPvLo+/DnxZ+jE7GisshiGM8tM+Ly8K99i/Cbb6Cb/rFnCnK30xhAZprvqikpsltH0mBOocivnvJqezZF7BND9lKczK2V7JFIPQAGu2fkSXGoTwj/13ks335Jtgf/QQcjPsMTWA/1DP8IDX7958TqC2/kyVMk07GYfEZHnNokof2SrNlwYH2NYIyUF/RnF9CpluWotsA== 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=5PxYS/FOxV9IHr5Qx1bG4OJDt+34SM/KiBs+qc7GLJE=; b=I3hvMXYdUXJzvg5P2jf7VTOdPuKQouXUQxNUBQcA1lMqzkPN6+x5mHTKJT4ElJq9++cS1+RYFn5OUUb52X09pvgVvsjmdjG9Jwk6O4TWprFbWF1IiGMaF8Hl4rE2Ldfi6aFwxfvYJaabTCLn1jgG7+NWByTeU7raWxxtMe/MU2E= 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:08 +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:08 +0000 From: yanfei.xu@windriver.com To: shy828301@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] mm: khugepaged: check MMF_DISABLE_THP ahead of iterating over vmas Date: Wed, 7 Apr 2021 11:05:48 +0800 Message-Id: <20210407030548.189104-3-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:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5b550e14-64c7-4ad9-ca96-08d8f97216e5 X-MS-TrafficTypeDiagnostic: SJ0PR11MB4864: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:669; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gWmiQuzEMIv/aRZOeen4969lp/b5wLYA0lYpLSzuzSARGz+1pE02MHR75msgmJ3XD25XwBgCzeaCW6PxXdB/WUwlwllq2dQUDD34KL2zlKIAITBnJrSE938TmhfwcoMmvG0/QpexdGyelMxWAyD6j/gu+NLzhHyP43TtpfPNGYYydpnyZsNezcE5TBOFsrRmB2PjfLgpJgVTWdcuvnIei6HahB8sH/rf7F69R1L7nztcsOuuKVU2osMPpvcsjqkisArnFd0KXsPc4X4BQvRmBLXyXvmtEcoRiggUGRgIj52jnOlSwnBtcE6SgZ0iQghMV/O68VsBdHkgZNgFU+4ZyvcRxKgumMJdvJbj8aI9Mf5haBCyGqgJbkM5ELW31mRnx66pgSnUF9ouQpcta2chs5hsXRfinoY83T/OvZGuZsxnOH3BEBIm3j+OH1UADkIMsdhWbeUxlQ0cL0oYzXJDUYYYFfc79PRPoOkcxok0hPVvd6ls+AsCAq3G0GtyjBXQDErHZ7QvmHEsD6Z2cKm+nljmfHldZ3Aci62Zer9KP3S3PSqMQT3QLsxvbVGRbkiZ4LzJKiKWuArpiIgaNpE+csX5fmf1inUKrF6SxLXMeq44MoPyfLoT5KHL/zWvKRQpMzxvHN/KFVN2TATQL0U/zrGQIyebrsGj07xlEGtp2weRRKV6j6XCu2kw87xe+2aP 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)(4744005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 231G/Gypk3dILe2Ktudwlp1hDzCEquZS9a9u0Hg5v9Q5iJxZmCwLnlzZoE1Enk8vXl7fN+Pu+iXAJliUZ7dTw/ko/m5HdNLxdOGsxBMVMCu1+MI6p7+sPJGSXUOdxMBJMMVlEYq/NE9NibMPeqb2yNHYScXy3x600wtsJm1gFUGyxxJCs2V0aA2gDt0Bo+MirL5c+DDCtotNIDPAsE6zL4FGc6++6xzPII4aO14DR27WxPYvoe3dHIKCtkCMDRWDGwnGFe+3o6nnZPa011cFpeeEbHeVdXjHehShI6FS02FVazksMNL5Y3R2A5+6Ea9z8SdRABT8wNx+a2aJOva0CbiCijGkb3ey1kvELTiUOznwYUjVld+ROzlPnceXr3in0mSsPmpTw8wvzEb2nUqkODY4uimwmiVjDuv1MdvP2S0Y37oVb8yNOTFmjTPfGRT3qVfUxDdNkeyAQjyIqnMcTVERNri8AmwDhPrQXFtSr/jRAeoB5oG//xNXFSFS+eQKrgrRs6tmNaW1HojZRX1J482Q5LAZU9s1TSgN2KWZmtA6q/vHAPzZz8j6GuEwLwyZe4x4F2F7OrXBc/6STbTvudLvaOaYGruLdoSR1UaeAHIs6dDS+5Y7LmjXm6/7fWS8sjYFVaiEkZcJIpTDdd8Mt5PmORAsvPTo5/v2IABQke4haJ2315LT8hUNr7/w9oDsdSMQOS82UxHiGHhnYUDW9SOuTS3Ui1Cm0OKBHMzBxQaYN7APxeceWemlfNn06dw7mzxuY9hHr3NIXrAZRtNwwBOAZ+CyaklHaMZrGRwzma7R3NahKT8o+e8wNeuH1zFTKX9pW6/Hb2M/ZknKivDK7pTy74E5ntfPuAKZy/P/Xws185hZKHrHgog1Ta+8xqApqJzuN7pGSoE0hDIz6rk6eiXbDhLexbYWyf54r2M0eDTpdIcHmOXHrZZ4jDdy0TufurhfoCfzYLOu+QQ6k0/Y0uKXmoxU8OVXvhTHBC/HSAc/3GVpxavnOEGytQ00YLWKtD58pbhGAk3M7nXCyZpJt6updIBBUj1BiHK55EWDzOi1shAXZQvPkGYJrJ7xfMVYBvo5wfN+oZrYqZPYD/0VeRFsnY3tgw3GQz6kliel7YAnziy7RBhoW6Bf9g9Pw1iX16e/1J7yDC0VJdRnboLlqAnzPy6iDhKSExhslfuK/H74HnKPYl/06RxRZ6AO3ESIcxNP1UFxQr+HUcV1IW0bRy8XpwtuPtmfVVbeAerszt0iS9d/lm7hat4r6dzZYqMMbGtq/zZnrcgR1ztm3O4077/q2MIvraMxukg1K2CSNSgAKJH8s5GIgxxqNNJAJbfL X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b550e14-64c7-4ad9-ca96-08d8f97216e5 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:08.2729 (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: 1koOiV3sbaqJn251g30YrwiFYbSQ5sKZ4XbqfbtIfiUb1UJSVT4+yU31qUi+wFFzC0pUKAgdAGts4+/nOIIK0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB4864 X-Rspamd-Queue-Id: 38C26E0001AC X-Stat-Signature: ijoifxganyhd5nsgx9h5qrdswpu35zqc 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: 1617764768-427294 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 check MMF_DISABLE_THP ahead of iterating over all of vma. Otherwise if some mm_struct contain a large number of vma, there will be amounts meaningless cpu cycles cost. Signed-off-by: Yanfei Xu Reviewed-by: Yang Shi --- mm/khugepaged.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a6012b9259a2..f4ad25a7db55 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2094,6 +2094,8 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, */ if (unlikely(!mmap_read_trylock(mm))) goto breakouterloop_mmap_lock; + if (test_bit(MMF_DISABLE_THP, &mm->flags)) + goto breakouterloop; if (likely(!khugepaged_test_exit(mm))) vma = find_vma(mm, khugepaged_scan.address);