From patchwork Tue Jun 21 23:56:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12889944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 231E4CCA481 for ; Tue, 21 Jun 2022 23:57:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354360AbiFUX5R (ORCPT ); Tue, 21 Jun 2022 19:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbiFUX5O (ORCPT ); Tue, 21 Jun 2022 19:57:14 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5101C186CA; Tue, 21 Jun 2022 16:57:13 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25LJHFt2012606; Tue, 21 Jun 2022 23:56:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=I9VUsXTeCErywBNKneFYp5mpvZSZCqFWtRZtD7nEsHo=; b=UgUqMr6yBExSvhRm5IWJFlwgnYompsYX+wxLJ7qimAs+Q7Vk0xZaRQODUQYiFarqU6+N ZTarSr2bvWej74X5pe6Mht6YXlQgP3b7lz80/XtGiHvNRew57/kjQs56l60wToAIvwrQ FbEo9e7CrnXpBUQDIVKPNySDx/2TCf3otGrJ4VLu+3cWPwroXQeYx3HUN5ChwCdXtMQO ZDQlVzB1ZVuxv60clqi7d3OrGLQei8CZ6fq8e4RBI536afRI7YhWUUCT7E2WFFO3pFp+ OjvKpVb+rS8g1JzDtm4Ae7Z1hXUsgzIFGVNkVBLxw8vHYgv5r37n0ujIgfywZARK4PrG Pg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gs6kf6vnb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jun 2022 23:56:35 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25LNok7c039924; Tue, 21 Jun 2022 23:56:34 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2175.outbound.protection.outlook.com [104.47.59.175]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gtf5cysds-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jun 2022 23:56:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oXRxeAxcKG5xZ5wuSJtvW88NPu69qSjuurV/FW0XF2z4jvOyE45Z2U18SzHTb9h9cqnb/knSHhOzQRXIS4v1jzEdvKDQW9ZwaHfTdSFbqpiIhpnuHq7ka/CWjViMMObCvbXJy47xgqveLFC4srXgG6aZkFzSfs5jLGebNzloUTV8GGQH00lq7WmtWMFx6gbOU0fBU4T7rR0AafZGMmWGzzKoWOR6n03N5LgMiSg6w+fobnHCJnSNAcnqNpq9C6/IBUO4MS2EhZ4UqE0mHpXos0bU/IU3JLvWdb7eQJQ9i7czTE/WndUAvhyFbHnwG5lLp7TOZ5vEyDBtIK+norUipw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I9VUsXTeCErywBNKneFYp5mpvZSZCqFWtRZtD7nEsHo=; b=dfvRA3Rd+PPIcMLdq6s4t8z9QcZNo96rAQ+9SLwCKqEmgLNerHWVoqboNqNF/93cBXExbh5vBbkbK99SX84sjxuQ53SPnwHjNwkNXY/f/3JIFAwUlaphP0Y3vYdMZyFOs/dq31J7bxGTPsg3foTK2bCC+TkREO5QNkDLK/a9XrCayPHfmZ92z5D4gvsRiWKtf5oRw6g9fQqd+n9B9OARAcQN9G1cxHd7lyXjX8QBmVLRgOyHhDyfbiSPTfQNhhgHxR8egcGYD8VMwCg0KqtcH8GO/jp1gPD5ziLWBkpdhL/Wd4Sj6/MrJn+UDlYThSVA96u1Khd6hd0nb+MXOCpthg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=I9VUsXTeCErywBNKneFYp5mpvZSZCqFWtRZtD7nEsHo=; b=qa7c+sMlHj+C/E80zr++3XHS4l/O9sAs0Yt349zvO3FtLL2dVBRpaUzhryiQgJjgrylrMpn2GpZHuiOtFcODdVXv8F33j/jhebxeclfhOAv2Hh2firUgyR7M+mGtixnhXFrsPUE2RT87IL+0qumtrPpNz0znNwnl36QmkmZbyZ8= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by MWHPR10MB1501.namprd10.prod.outlook.com (2603:10b6:300:24::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Tue, 21 Jun 2022 23:56:32 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::2125:9bb7:bfeb:81f9]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::2125:9bb7:bfeb:81f9%8]) with mapi id 15.20.5353.022; Tue, 21 Jun 2022 23:56:31 +0000 From: Mike Kravetz To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Muchun Song , Baolin Wang , Michal Hocko , Peter Xu , Naoya Horiguchi , James Houghton , Mina Almasry , "Aneesh Kumar K . V" , Anshuman Khandual , Paul Walmsley , Christian Borntraeger , catalin.marinas@arm.com, will@kernel.org, Rolf Eike Beer , Andrew Morton , Mike Kravetz , kernel test robot Subject: [PATCH v2 1/4] hugetlb: skip to end of PT page mapping when pte not present Date: Tue, 21 Jun 2022 16:56:17 -0700 Message-Id: <20220621235620.291305-2-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621235620.291305-1-mike.kravetz@oracle.com> References: <20220621235620.291305-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR04CA0283.namprd04.prod.outlook.com (2603:10b6:303:89::18) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 74ce3319-f277-4cbc-519a-08da53e1aa55 X-MS-TrafficTypeDiagnostic: MWHPR10MB1501:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5dPWq6OKGgc3xc6Jm8BtQlAAgsjKh4XmdKVRfk6Ni+fak1qympT0LLgQpDSw4/+bAvqEiaPyzVZmYIfnRyUyAcFkQfNKnGQvtpnGFT2uGvVytgheVRzhCgJJnQ6CZTf2quazgmjqgjSuTLxobSmMAiiaArmtsH50gOlXYBBQ7dVzOFiU530HdBwOLwKJTeZz9pOeEEGjIX0jbvcPmoXo0kTeC1ZWzAufQPaNgXSIwbSqDXEBpr1LTvYF6CfaSpCyY46FCh2y7/txFgIx2Vf16/O+OANF03FS4Y/ejl48NVtYKWh8J+GXZJpNitcN7q+fGlUhW2PGry3ofomZM6bdpNNnB+kl3ACrs0k/RnmyS85hCxEom0bK/+ByEj2lGJ6NCBWpJne/QObS5o9OT2wYcojKo+qtRJ6kG6zN9kKR0tVXj9oAnZAReYkjuTN6TgT9pRnmMj3KtlALYNYgTF1o9dCY20qJk/vwvQLznlhaQmlw9GYdvgo3aJ37UbcEAD0bCcaXOGHFZjVN/MEJpew7r0J/T9gvnVuXh47gGW1QiZfha03X9keX1AsLl542KP1OBDdJkafYm5zxAv8O05AXAZE43dBQtRLgKPGCAtjetIaYFiUZu9ny4z6ktrRpSkC/9puf1Il6uY8y9J2V0Wv+MWc0AznoVm1C57y6L81h0L8QCsm0Dtw54aHbBvgEcFZv X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(376002)(346002)(366004)(136003)(39860400002)(396003)(7416002)(38100700002)(478600001)(316002)(6666004)(186003)(5660300002)(8936002)(2616005)(1076003)(83380400001)(41300700001)(2906002)(86362001)(8676002)(66556008)(26005)(6512007)(66946007)(36756003)(66476007)(44832011)(6486002)(4326008)(54906003)(921005)(6506007);DIR:OUT;SFP:1101; X-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HuuqQPhgzDakmvcUhKtgYQ0jl3sNvoLGEzq1H8QtQTn0OiGhdQrWgivFOuO/oNFgD4hsCiNqmfvLI7Dqh57wz12QmtaA+2aCHn/VdBBYzZBtGfI/usWHV6Jt1dmuOT1qgehzE6oKqx98OS/isF09HyHk/lCJdWqVaHGnuN7rX050E7P3HTrzyfX+/b1vAfwBGWpRhsm7lQPKl5KuHfsS0fFvsFtuPu9f9xYbd2kb6Oim7q9UINqWRvQl68Ykab/N2/HJbuDyYs1kIwoOeOt2F4XOm1LpuQTeVjnYW8DBhZcNMS2wvYO9ebTLXAeOA6kF9lctG6NoHDJrnbZ2Wi0MC+AwDAqdx+5VGSoi0CYN9HKSMaVCZ5+irvcBMJOCXIpehpvcytPu78UXWflYv4Y2fKq/u0GAo2fOCvn3UCuBQxtc+pKa+kHyjZ+xAU0cGmpDeGSGDqfkjHJKKt6WhbDOrMUI+snw+4YA8Uta+JEbTOe39Cc+rrvwEnRauXBjcecOJmMqg4qETXpKO7ghriRpriZUVg0YUmSCCLGj0Ulevun04dUodI4UmMRBfvVr5yNI/WBgkF4ijq5DncUQafahqdH0yxzcMu/1Z+q+pjK9S6w26sN4wnNjGk2YyQ0FsLg96IQ0Tp2zK4T8tFomoe7h5UgbgamELZxTVBQHOc0906hYNwvc+9D+fP2sTaUK3sCKM6wAZ9KpJd9PM73ptIp++7cKoMY7wkCOdWc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74ce3319-f277-4cbc-519a-08da53e1aa55 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2022 23:56:31.8228 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TnenMtLhFQvsRoyj6PsZOaQIIGuSvM2sH/xaUCUggf0nmQqCY9FAwxv5gbk+17LNAtAqWRxWDbkM+dTXUo++7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1501 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-06-21_10:2022-06-21,2022-06-21 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206210105 X-Proofpoint-ORIG-GUID: wYEz4IocbbzavqKo51z_zKs0l33aQYzr X-Proofpoint-GUID: wYEz4IocbbzavqKo51z_zKs0l33aQYzr Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org HugeTLB address ranges are linearly scanned during fork, unmap and remap operations. If a non-present entry is encountered, the code currently continues to the next huge page aligned address. However, a non-present entry implies that the page table page for that entry is not present. Therefore, the linear scan can skip to the end of range mapped by the page table page. This can speed operations on large sparsely populated hugetlb mappings. Create a new routine hugetlb_mask_last_page() that will return an address mask. When the mask is ORed with an address, the result will be the address of the last huge page mapped by the associated page table page. Use this mask to update addresses in routines which linearly scan hugetlb address ranges when a non-present pte is encountered. hugetlb_mask_last_page is related to the implementation of huge_pte_offset as hugetlb_mask_last_page is called when huge_pte_offset returns NULL. This patch only provides a complete hugetlb_mask_last_page implementation when CONFIG_ARCH_WANT_GENERAL_HUGETLB is defined. Architectures which provide their own versions of huge_pte_offset can also provide their own version of hugetlb_mask_last_page. Signed-off-by: Mike Kravetz Tested-by: Baolin Wang Reviewed-by: Baolin Wang Acked-by: Muchun Song Reported-by: kernel test robot --- include/linux/hugetlb.h | 1 + mm/hugetlb.c | 56 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 642a39016f9a..e37465e830fe 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -197,6 +197,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, unsigned long sz); pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr, unsigned long sz); +unsigned long hugetlb_mask_last_page(struct hstate *h); int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long *addr, pte_t *ptep); void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 98492733cc64..0e4877cea62e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4736,6 +4736,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, unsigned long npages = pages_per_huge_page(h); struct address_space *mapping = src_vma->vm_file->f_mapping; struct mmu_notifier_range range; + unsigned long last_addr_mask; int ret = 0; if (cow) { @@ -4755,11 +4756,14 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, i_mmap_lock_read(mapping); } + last_addr_mask = hugetlb_mask_last_page(h); for (addr = src_vma->vm_start; addr < src_vma->vm_end; addr += sz) { spinlock_t *src_ptl, *dst_ptl; src_pte = huge_pte_offset(src, addr, sz); - if (!src_pte) + if (!src_pte) { + addr |= last_addr_mask; continue; + } dst_pte = huge_pte_alloc(dst, dst_vma, addr, sz); if (!dst_pte) { ret = -ENOMEM; @@ -4776,8 +4780,10 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, * after taking the lock below. */ dst_entry = huge_ptep_get(dst_pte); - if ((dst_pte == src_pte) || !huge_pte_none(dst_entry)) + if ((dst_pte == src_pte) || !huge_pte_none(dst_entry)) { + addr |= last_addr_mask; continue; + } dst_ptl = huge_pte_lock(h, dst, dst_pte); src_ptl = huge_pte_lockptr(h, src, src_pte); @@ -4938,6 +4944,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, unsigned long sz = huge_page_size(h); struct mm_struct *mm = vma->vm_mm; unsigned long old_end = old_addr + len; + unsigned long last_addr_mask; unsigned long old_addr_copy; pte_t *src_pte, *dst_pte; struct mmu_notifier_range range; @@ -4953,12 +4960,16 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, flush_cache_range(vma, range.start, range.end); mmu_notifier_invalidate_range_start(&range); + last_addr_mask = hugetlb_mask_last_page(h); /* Prevent race with file truncation */ i_mmap_lock_write(mapping); for (; old_addr < old_end; old_addr += sz, new_addr += sz) { src_pte = huge_pte_offset(mm, old_addr, sz); - if (!src_pte) + if (!src_pte) { + old_addr |= last_addr_mask; + new_addr |= last_addr_mask; continue; + } if (huge_pte_none(huge_ptep_get(src_pte))) continue; @@ -5003,6 +5014,7 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct struct hstate *h = hstate_vma(vma); unsigned long sz = huge_page_size(h); struct mmu_notifier_range range; + unsigned long last_addr_mask; bool force_flush = false; WARN_ON(!is_vm_hugetlb_page(vma)); @@ -5023,11 +5035,14 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct end); adjust_range_if_pmd_sharing_possible(vma, &range.start, &range.end); mmu_notifier_invalidate_range_start(&range); + last_addr_mask = hugetlb_mask_last_page(h); address = start; for (; address < end; address += sz) { ptep = huge_pte_offset(mm, address, sz); - if (!ptep) + if (!ptep) { + address |= last_addr_mask; continue; + } ptl = huge_pte_lock(h, mm, ptep); if (huge_pmd_unshare(mm, vma, &address, ptep)) { @@ -6301,6 +6316,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, unsigned long pages = 0, psize = huge_page_size(h); bool shared_pmd = false; struct mmu_notifier_range range; + unsigned long last_addr_mask; bool uffd_wp = cp_flags & MM_CP_UFFD_WP; bool uffd_wp_resolve = cp_flags & MM_CP_UFFD_WP_RESOLVE; @@ -6317,12 +6333,15 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, flush_cache_range(vma, range.start, range.end); mmu_notifier_invalidate_range_start(&range); + last_addr_mask = hugetlb_mask_last_page(h); i_mmap_lock_write(vma->vm_file->f_mapping); for (; address < end; address += psize) { spinlock_t *ptl; ptep = huge_pte_offset(mm, address, psize); - if (!ptep) + if (!ptep) { + address |= last_addr_mask; continue; + } ptl = huge_pte_lock(h, mm, ptep); if (huge_pmd_unshare(mm, vma, &address, ptep)) { /* @@ -6873,6 +6892,33 @@ pte_t *huge_pte_offset(struct mm_struct *mm, return (pte_t *)pmd; } +/* + * Return a mask that can be used to update an address to the last huge + * page in a page table page mapping size. Used to skip non-present + * page table entries when linearly scanning address ranges. Architectures + * with unique huge page to page table relationships can define their own + * version of this routine. + */ +unsigned long hugetlb_mask_last_page(struct hstate *h) +{ + unsigned long hp_size = huge_page_size(h); + + if (hp_size == PUD_SIZE) + return P4D_SIZE - PUD_SIZE; + else if (hp_size == PMD_SIZE) + return PUD_SIZE - PMD_SIZE; + else + return 0UL; +} + +#else + +/* See description above. Architectures can provide their own version. */ +__weak unsigned long hugetlb_mask_last_page(struct hstate *h) +{ + return 0UL; +} + #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */ /* From patchwork Tue Jun 21 23:56:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12889943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D616CC43334 for ; Tue, 21 Jun 2022 23:57:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352628AbiFUX5Q (ORCPT ); Tue, 21 Jun 2022 19:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233682AbiFUX5O (ORCPT ); Tue, 21 Jun 2022 19:57:14 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DA9518E2A; Tue, 21 Jun 2022 16:57:13 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25LJ4NE8004714; Tue, 21 Jun 2022 23:56:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=/njx8tIRQlEKSacMJRax+vR+jPe8iUR+lMo6N8dU5mE=; b=T18rVsD1HFWCVvUX7/Fg2Sk2hozGFobULjXSBPVBzoY2aBPQ5WXRqNr5j0FXsF0ii0pj B1gWNxHSa+Vfoe4evs9rMpdFMBAh00JYNOJn/ZQJ+LaJjrwpQo4T/4xsYbQ9jvMKeS3q U4UzZUMBvgnSh0QMEUyx0MDkVdfd/hLUut+KFvMwnfEFilJr851DH8WhywdbfGWoXoQV pw1o0Zo3iYD1fm5vWQL5jvHo+GOWnO8NKMPLs91Lw83myYamHcn3VoEaP2mpiRXIKrZf ZX5BYvP9G9NVmQsNvmP+HvrH7BYwWBaP8vLb4cUv/gXn5UNxfaFfFKmYjx345ci0j0aE 3A== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gs54cpxte-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jun 2022 23:56:36 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25LNoZ7P027173; Tue, 21 Jun 2022 23:56:36 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gtd9uq3gu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jun 2022 23:56:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EcEX+UF5Wvp9A/f2DcGTBV97d+fawlqV/BBfDeo8yMvkXcIRh9/MntIGaZNYaAhYW62iqtQuLzFTcUnubLh8R1a0f5BeSVR02WWigW6q80b2sc4BEFT90TfIRFVSAgRjCoROveEPJyb6O77UCp2W+yKQCd+fFybCVnFmxYv/S1FwWBpMRvy0vtsa38j5rzXr2zn7dF5XMnbrPelWguO2ESA+aJfWsRIbo9/97yiEC9x5CznyQpB7ahatEeX1wQATsQVFvowDAZzxeTorBqh0L0VkmeJuw57DAZ3dTEe8fGxesa9vTlbThSLvIcx3rLoHjgyYSRcPq5hXmtfKoATkYA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/njx8tIRQlEKSacMJRax+vR+jPe8iUR+lMo6N8dU5mE=; b=S0zR5G27MVpOqQoAHt69GpDMEgqkAPZxFJsqLFi90mlAdtHjp7UTm74V7FkwNXzF+SufUm4upllP/bPWNW+jEOuHgVJvt4/JBHG0kHe8ailVnI/eJj5O2LkjYLM4fmbgYWRGaB7A0RQ262NMsvskZBl725PTH0W5XC+VhxfvhdCPXwBxAIHc5pcusbEQX/sh8n4nLAAfLsnL32qp/nQdvcIMe8S+sA8WRTJXg6d4IYRFmkJEeSfyLI9aJKBFok7xPfbQVy57JLE6oYP1q2h3+2XNnZp45o9En/uKFR+ev78iV23oWphpBB0I4tRuBQrLMto7Lfz/ky+1ndw2cT9C1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/njx8tIRQlEKSacMJRax+vR+jPe8iUR+lMo6N8dU5mE=; b=mKEijmcMKu1+rpUiJqYFCtaqURyKB4at/cuOHfJ++RCrVunocl3L7b7ppEgSGFutoojW3hxzltwiT5fWy9pVSKIzeXefaTrUDVUGKgWgI/xAs3bgqzFeXMB4zhw6eYynXBNjQZ6ShOS4+reyB562OeEa9VrjvSvzAH7RFmq76Gs= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by MWHPR10MB1501.namprd10.prod.outlook.com (2603:10b6:300:24::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Tue, 21 Jun 2022 23:56:34 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::2125:9bb7:bfeb:81f9]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::2125:9bb7:bfeb:81f9%8]) with mapi id 15.20.5353.022; Tue, 21 Jun 2022 23:56:34 +0000 From: Mike Kravetz To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Muchun Song , Baolin Wang , Michal Hocko , Peter Xu , Naoya Horiguchi , James Houghton , Mina Almasry , "Aneesh Kumar K . V" , Anshuman Khandual , Paul Walmsley , Christian Borntraeger , catalin.marinas@arm.com, will@kernel.org, Rolf Eike Beer , Andrew Morton , Mike Kravetz Subject: [PATCH v2 2/4] arm64/hugetlb: Implement arm64 specific hugetlb_mask_last_page Date: Tue, 21 Jun 2022 16:56:18 -0700 Message-Id: <20220621235620.291305-3-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621235620.291305-1-mike.kravetz@oracle.com> References: <20220621235620.291305-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR03CA0298.namprd03.prod.outlook.com (2603:10b6:303:b5::33) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d3db7010-cb91-40f3-4755-08da53e1ab9c X-MS-TrafficTypeDiagnostic: MWHPR10MB1501:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VgBSYfnlIkwMdOsK5c5KxW+zFR8mpyB0ugs/TjE+WOVMlBid0oaEIePiV0zLqpqQRbPjH0tK3CXBbSB63Z6OXt6j+KM54LJChvmedxKuo1yUXI3iE+gj6G4H8MYsbLCaVH743oOfnOX+YHPV6FkEWJeKgIDCaTXhIyIGTWNDbXLcOPhjMszbF2oS63taXSfnjrzc1QoxfwaZQHtuR3wQfQMxzffWkYHVRUMdbsnx1Kblac6FbqTXfS6JcXTit6nVLrBdCTFyGfm6ffyxdR14WSwZAb5bK03k17zlY4N9AZWORTyX7DUA4q6KfKFc4Krvpb0IdycW9vIVTD+xrykF7eCZ+KD+1nLaSnmP8XfGlg0aCrXuMaE23/cshO5NVu5uxV8sd0PDxDBcVp5CfQhPL4nH1F+XS6smgA31/RSuDFhLJcfxWHbXLUnoPF6e8rOspNOv5z6+ub/E0W5nFDkFRC9CdpDJmH2FzUBRIZ40U1/31DYMcYcCXVtYJXbhtVE4V5uYGjCD6Nwx0ae3R8qJG6K1U1FHbOmDEJABlHo5evUXEjBTt0DxQX14/6ox2bCTfMKGwYTHmHUf+xxb3iNANirTQPTcDPLXa4ZQv1tHrM6fUC2Vq6mcTvAuaGhuttDj3GKjLu902qHCZ0fS7LOVYABlbfwdGSiA2rKc+y0NAcao1r5glPYnsmBLwFSkBTEd6od1dl8shVKWFUbYVfSUt9zWojnULne9oySmwfugfMx7CYxvPP6KbBGs3oNxjFvAsF1RnmNmvF402ZqjVIZNjg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(376002)(346002)(366004)(136003)(39860400002)(396003)(7416002)(38100700002)(478600001)(316002)(6666004)(186003)(5660300002)(8936002)(2616005)(1076003)(107886003)(83380400001)(41300700001)(2906002)(86362001)(966005)(8676002)(66556008)(26005)(6512007)(66946007)(36756003)(66476007)(44832011)(6486002)(4326008)(54906003)(921005)(6506007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UjSIQb5u+M7qVdrndS2qe/bIojB1qsKEwubvBV4oyvGfhhjYBOIcumAlb0kTJvxGdKrNGdyRtAYsyWOsOqKSCfFy6i15HoxuvYN1XC9sqf93F3BiUuI2chdmvPshj+BIu7TvNXy9rCxb4vFq+6LPFvpLfHgJUBg5g4743y4uaL5JERe0ZwRFc2kRk1a/0K+Zmc3RVhIJiSBnTjXM/zDuGMqE8ddyT0Ymz6mFVOdm2id1oT6IL7EY2nTBTcESNZcw2HaSy8qYf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SRXnKfhoz1TeKqT/qXwhtOevua336rbZw9rNGmiE66kJ8VnjUAbugdq2kZu0mCJ2Y138k/0KiCRtwJf/oFKwnUSTkiWeRukUJH7Z1J96LrLjHaHLQYFahcMIbZOeI7tfYVe1iYrPNWpHM9v4dduLxR+MjgzJj7e9ED7G+7dkyROf9jif+I/g4vPWsjOjgSYdiuWh8kU9bFeiqpQHMinXfbBoSheAa3IZs10TClvsAPPUW84KlYKAUOhOTA7xIv3NLCYdwskUSZv6QPy4JdRc+u/lzzquRxKFNfVm4/nyEBAVfsAc88waWFLXc3UCtgJ6Vreze+Kdq07hxjzZU8LWQTUlhqtL4Qu1LPvizPuHcOYgRpg+W9B9+j4zUsGyfVXapjuWc0dmZ0Dyr7fpLLsMLGOORpgbXzOoqwDfSA6gTA34= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3db7010-cb91-40f3-4755-08da53e1ab9c X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2022 23:56:34.0114 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Nt0D8F8wiDpq/bJoOnEkUETD5iOcYRFeD96r1TgtXT/4dkqZFYGaKR347PJ8eQM66s72cflgnCVGRf9j7Phusw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1501 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-06-21_10:2022-06-21,2022-06-21 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206210105 X-Proofpoint-GUID: 49wNhCOG5H4MhZkQsuD4KvT3K_VsaFs_ X-Proofpoint-ORIG-GUID: 49wNhCOG5H4MhZkQsuD4KvT3K_VsaFs_ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Baolin Wang The HugeTLB address ranges are linearly scanned during fork, unmap and remap operations, and the linear scan can skip to the end of range mapped by the page table page if hitting a non-present entry, which can help to speed linear scanning of the HugeTLB address ranges. So hugetlb_mask_last_page() is introduced to help to update the address in the loop of HugeTLB linear scanning with getting the last huge page mapped by the associated page table page[1], when a non-present entry is encountered. Considering ARM64 specific cont-pte/pmd size HugeTLB, this patch implemented an ARM64 specific hugetlb_mask_last_page() to help this case. [1] https://lore.kernel.org/linux-mm/20220527225849.284839-1-mike.kravetz@oracle.com/ Signed-off-by: Baolin Wang Signed-off-by: Mike Kravetz Acked-by: Muchun Song --- arch/arm64/mm/hugetlbpage.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index e2a5ec9fdc0d..c9e076683e5d 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -368,6 +368,26 @@ pte_t *huge_pte_offset(struct mm_struct *mm, return NULL; } +unsigned long hugetlb_mask_last_page(struct hstate *h) +{ + unsigned long hp_size = huge_page_size(h); + + switch (hp_size) { + case PUD_SIZE: + return PGDIR_SIZE - PUD_SIZE; + case CONT_PMD_SIZE: + return PUD_SIZE - CONT_PMD_SIZE; + case PMD_SIZE: + return PUD_SIZE - PMD_SIZE; + case CONT_PTE_SIZE: + return PMD_SIZE - CONT_PTE_SIZE; + default: + break; + } + + return 0UL; +} + pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) { size_t pagesize = 1UL << shift; From patchwork Tue Jun 21 23:56:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12889946 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 296D2CCA489 for ; Tue, 21 Jun 2022 23:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354627AbiFUX5T (ORCPT ); Tue, 21 Jun 2022 19:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234114AbiFUX5O (ORCPT ); Tue, 21 Jun 2022 19:57:14 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BB9218B28; Tue, 21 Jun 2022 16:57:13 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25LJ1TjA009747; Tue, 21 Jun 2022 23:56:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=H8vBK/cfd2DyRppzomYXVb7VYoZJawa6OPvFwFWS3TU=; b=l9YIxHFOTAcUYdaBCChirKaJxbci0AoMb3b6adeRx8c2cksZJOZ405ENMzHRLnXtd60l FhXTy4TbHew4Wch/jLpjenl09FbXNLIDGLyaCLI1/gDmLZ8bwsjxz8EuYk+oOMZImgWt j99PcFlMbQMVmQs6EWNb0gjfSoSyLf5f/7KP4lSd1t9cMbIVmNjSNk59NJehlmRWZ7F8 0CiWx3zWKRU6KICXMuHhTX+uVX7CG7eVey0IDiDbLeAW57n5pAu4njhEkjQSM8XQbvU0 Nufk4LkwivYUJ05PWte9C5qbx6++exL0FrRSowWlyA3f6m0g3TeGmQbZZirkD+h9Vu7e Tw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gs78txyk3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jun 2022 23:56:39 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25LNoXqh013303; Tue, 21 Jun 2022 23:56:39 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gth8wwujv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jun 2022 23:56:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ognY+BLxOmmvk8sUFG2/OMR0BoufWuoSSa7Amr8+2D+CjhI3Ts9e6/VkFXZtakyrGeRO6BSCjOmYfzeZmrjzlJ75U21yGVA+RQnxgxiQS9Idx/MxsgjlY5z/Q7nZY5Y8mJPlcPX+gkKocwtIYxpf/qW/228n1/juYdtV3tfhzD4kaghkD1hGUekIIyGeXuu3QDaEstUxCGf6VMPaWGdIUe5MfD85ek8ElC65CHlfwUt0cPn2e994Ru9IKYUYhlTXmXF3+ot/jxBRMw5bRGzAoS+jeI1XcC03fctiVP+OfFuu4HS7fc52H2HtiaiUO+rp9ZWCiCv6HGPO/+cD1DbUQQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H8vBK/cfd2DyRppzomYXVb7VYoZJawa6OPvFwFWS3TU=; b=AZW8MCqlhlBsn8LQRTE2tWFkTBCrr/Szau/8la2VhFn56ai3pt4pbGurB2TltC4R6zwF2HLE5MkTiseQhbtLzl5Vr4NTyfkj+T9LrUhI384g9QDbd32ceyuLoHBH6yhKR6jMKesRefOuUSRsG6wCUqHtv9ErZ35YC4M4imtMalD8opE8ZtUaCHxdZNaXQs0HS4sNSUAHhcMWqv/4BGoxzBzAKz+nzd6bCvGYqsfGUu7itQEGe3VfHzYjwB2EMX3q35HZmTqxXYyrzT9oPd0kJcsgy1caa36DJFOYVKyn5ODeXPV+F7pfGs4/SFIU5vxdP43pf30YqWYTwknVT8U4mw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H8vBK/cfd2DyRppzomYXVb7VYoZJawa6OPvFwFWS3TU=; b=c1Ok8HtoSQDESjkKLBCdf4hQVWcoVTxFblxp2MyWHrAt1uPRtrz8C5LsG8pGuvFITBg3FddVL5HthGxAXr1i2/P/Ff6ADIoDBN/MEBbJ3GvP00hiQNpbv7IbMsLiSIgAN7u7jlBYCD7T94MQpemkt0vcZVRilAMVS7bPTB/NeNc= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by MWHPR10MB1501.namprd10.prod.outlook.com (2603:10b6:300:24::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Tue, 21 Jun 2022 23:56:36 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::2125:9bb7:bfeb:81f9]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::2125:9bb7:bfeb:81f9%8]) with mapi id 15.20.5353.022; Tue, 21 Jun 2022 23:56:36 +0000 From: Mike Kravetz To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Muchun Song , Baolin Wang , Michal Hocko , Peter Xu , Naoya Horiguchi , James Houghton , Mina Almasry , "Aneesh Kumar K . V" , Anshuman Khandual , Paul Walmsley , Christian Borntraeger , catalin.marinas@arm.com, will@kernel.org, Rolf Eike Beer , Andrew Morton , Mike Kravetz Subject: [PATCH v2 3/4] hugetlb: do not update address in huge_pmd_unshare Date: Tue, 21 Jun 2022 16:56:19 -0700 Message-Id: <20220621235620.291305-4-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621235620.291305-1-mike.kravetz@oracle.com> References: <20220621235620.291305-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MWHPR02CA0020.namprd02.prod.outlook.com (2603:10b6:300:4b::30) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e24b1717-31a2-443b-7779-08da53e1ad3d X-MS-TrafficTypeDiagnostic: MWHPR10MB1501:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jVoGeoikeK2VKH8UQgKT+OM9PjsZuNpHTTDnY6Fsz+y7FEYX6VxacfAklWvMdnTIf0iAau3sUnDOpLSCoshfRb3bxaUuDzVFRHduvgx0Y3CoYgdISPqJhvAarInFkRma879/zw01r9l390zpwNecZWHpcz3zgoxLj6QrUvppXFi72/fdULGZp41TU3u3UenONRk7CAvdXX/kL2NnmWZ8OnLI6B0ueSygtJu98QcpqGATT88Ar5nehw0oUyXZMNLSCs0PzSucWvhO/NVse074JiVNsXicFxE+CutcPSVqtyJQBDNIjeACtOsHjWU/3B6z7IoUBbQw2oY58+2tij6ntOL+lHUbSLiBKuDgvvFt9C2jpHw2xwd/nvlBYXxa+IbCOXsVY/6XAfQzo85My82YXWuAGs8f2E6vWDqEaxq5F0U/2IrZFsqIUPnOl0WOgBw/qEW5nPnMzSszoXZTtlFTAVVYWm2fSCPejTbqQyqCQZUZ3FmYG0Mvxv0niIYkoBidifdOqEowfLDsm/O6stBHcXIdmAnSzNbKkTymqgBX5UlKhHQLdGJZm29fMvD6hUFAj+gmr1BoNdStLQr7vRyDeOQj+jojV5ghERjsOzV9IM0de9Ced4EI22gR+YOrvMCFjrh3hJ7mdBhODmsswVnRJA6HCrdE+BoH0Z0F/XnoI1EUqEvQpsoJGxay2YzPHUP1dcw2CNY4XGQ7wu5xtc/jEw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(366004)(396003)(136003)(39860400002)(346002)(376002)(2906002)(86362001)(4326008)(6486002)(44832011)(6506007)(15650500001)(54906003)(921005)(8676002)(36756003)(66476007)(66556008)(26005)(6512007)(66946007)(186003)(6666004)(38100700002)(7416002)(316002)(478600001)(1076003)(8936002)(2616005)(41300700001)(107886003)(83380400001)(5660300002)(14583001);DIR:OUT;SFP:1101; X-MS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AwIZVm0p3j0YzJJJPI+tQ4AQC7ii2jBiTKDiwnEWErUwMj7o4Oo0tpBv6HBiTopvgCxqJv68rPnDNJRUsBHYSJMIIDTLr+NTUBqTh5oZsU4wd2oagO5IcCzNAA0cte3hnWRoSSLu7iDTcZjkHIDbNcvGPA/k0qvHYgbPxuCwnyQrxS6NJd3/d+TuslpsfOg0eXNhYNj9ddJp3PJphaHzU/Ql9HuOS0B7WL4qAODZt6MHdQvZycchcLjbNXh2Mm1pPJt9lj4EUFuUxQ+9rukZG/zNFYxQuA6Q0yk+TDsqoEpQAC+UZ1b+lnYWfs0vven9904m2YJsdVjeE4K7/skv+at1iEdVEqMPjj/95ARKjhyUTQxryuDIWk0Eu/LMZnF/0jwvdYv7NZjAd8hVANLropm/uLnIz0aUAotZGc8u0EJc/FO7hADv2enTxGuHbaAojMAJ4itn1RXP7ERffQ9M1w29FvyTOESLzU4gXPCT+SpOgQl6/+wNEgINY0lGgdDrzK7/eHd6kWHiSpZUO/T2qNXMQutVX532Uswi9IfW+s1AalOmV266y8hS2/SEPk029G7YSsPUdg0UNQLgOdfENVd0LJLapmDKlzJHto8p6YkBjtPIbnCyy1rSE1hxSNhIcDg7Qcn5HG+bMIz5a0WUrCoWAoflyz1hnTUj11XFvXzBcbgEq/3lowhCdzmyDqZiZH6EbNNFiz90yi44zykMJ+GfpEZXkn4bbsr3yr3SWKWUc4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e24b1717-31a2-443b-7779-08da53e1ad3d X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2022 23:56:36.6986 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ggK8pdO7VUGzi54icS8cjPuLhE/OPYoFu+WWw4h6k6C8QcEigc4yGMgtHGGlD/qwEKfoPDlpio2k2MFZ0Q1WOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1501 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-06-21_10:2022-06-21,2022-06-21 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206210105 X-Proofpoint-GUID: b-YWIN4qsZl4phYCYBaRfSUkplTOj4iG X-Proofpoint-ORIG-GUID: b-YWIN4qsZl4phYCYBaRfSUkplTOj4iG Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org As an optimization for loops sequentially processing hugetlb address ranges, huge_pmd_unshare would update a passed address if it unshared a pmd. Updating a loop control variable outside the loop like this is generally a bad idea. These loops are now using hugetlb_mask_last_page to optimize scanning when non-present ptes are discovered. The same can be done when huge_pmd_unshare returns 1 indicating a pmd was unshared. Remove address update from huge_pmd_unshare. Change the passed argument type and update all callers. In loops sequentially processing addresses use hugetlb_mask_last_page to update address if pmd is unshared. Signed-off-by: Mike Kravetz Acked-by: Muchun Song Reviewed-by: Baolin Wang --- include/linux/hugetlb.h | 4 ++-- mm/hugetlb.c | 46 +++++++++++++++++------------------------ mm/rmap.c | 4 ++-- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index e37465e830fe..ee9a28ef26ee 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -199,7 +199,7 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr, unsigned long sz); unsigned long hugetlb_mask_last_page(struct hstate *h); int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma, - unsigned long *addr, pte_t *ptep); + unsigned long addr, pte_t *ptep); void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma, unsigned long *start, unsigned long *end); struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address, @@ -246,7 +246,7 @@ static inline struct address_space *hugetlb_page_mapping_lock_write( static inline int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma, - unsigned long *addr, pte_t *ptep) + unsigned long addr, pte_t *ptep) { return 0; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0e4877cea62e..2e4a92cebd9c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4945,7 +4945,6 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, struct mm_struct *mm = vma->vm_mm; unsigned long old_end = old_addr + len; unsigned long last_addr_mask; - unsigned long old_addr_copy; pte_t *src_pte, *dst_pte; struct mmu_notifier_range range; bool shared_pmd = false; @@ -4973,14 +4972,10 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, if (huge_pte_none(huge_ptep_get(src_pte))) continue; - /* old_addr arg to huge_pmd_unshare() is a pointer and so the - * arg may be modified. Pass a copy instead to preserve the - * value in old_addr. - */ - old_addr_copy = old_addr; - - if (huge_pmd_unshare(mm, vma, &old_addr_copy, src_pte)) { + if (huge_pmd_unshare(mm, vma, old_addr, src_pte)) { shared_pmd = true; + old_addr |= last_addr_mask; + new_addr |= last_addr_mask; continue; } @@ -5045,10 +5040,11 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct } ptl = huge_pte_lock(h, mm, ptep); - if (huge_pmd_unshare(mm, vma, &address, ptep)) { + if (huge_pmd_unshare(mm, vma, address, ptep)) { spin_unlock(ptl); tlb_flush_pmd_range(tlb, address & PUD_MASK, PUD_SIZE); force_flush = true; + address |= last_addr_mask; continue; } @@ -6343,7 +6339,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, continue; } ptl = huge_pte_lock(h, mm, ptep); - if (huge_pmd_unshare(mm, vma, &address, ptep)) { + if (huge_pmd_unshare(mm, vma, address, ptep)) { /* * When uffd-wp is enabled on the vma, unshare * shouldn't happen at all. Warn about it if it @@ -6353,6 +6349,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, pages++; spin_unlock(ptl); shared_pmd = true; + address |= last_addr_mask; continue; } pte = huge_ptep_get(ptep); @@ -6776,11 +6773,11 @@ pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma, * 0 the underlying pte page is not shared, or it is the last user */ int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma, - unsigned long *addr, pte_t *ptep) + unsigned long addr, pte_t *ptep) { - pgd_t *pgd = pgd_offset(mm, *addr); - p4d_t *p4d = p4d_offset(pgd, *addr); - pud_t *pud = pud_offset(p4d, *addr); + pgd_t *pgd = pgd_offset(mm, addr); + p4d_t *p4d = p4d_offset(pgd, addr); + pud_t *pud = pud_offset(p4d, addr); i_mmap_assert_write_locked(vma->vm_file->f_mapping); BUG_ON(page_count(virt_to_page(ptep)) == 0); @@ -6790,14 +6787,6 @@ int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma, pud_clear(pud); put_page(virt_to_page(ptep)); mm_dec_nr_pmds(mm); - /* - * This update of passed address optimizes loops sequentially - * processing addresses in increments of huge page size (PMD_SIZE - * in this case). By clearing the pud, a PUD_SIZE area is unmapped. - * Update address to the 'last page' in the cleared area so that - * calling loop can move to first page past this area. - */ - *addr |= PUD_SIZE - PMD_SIZE; return 1; } @@ -6809,7 +6798,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma, } int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma, - unsigned long *addr, pte_t *ptep) + unsigned long addr, pte_t *ptep) { return 0; } @@ -6916,6 +6905,12 @@ unsigned long hugetlb_mask_last_page(struct hstate *h) /* See description above. Architectures can provide their own version. */ __weak unsigned long hugetlb_mask_last_page(struct hstate *h) { + unsigned long hp_size = huge_page_size(h); + +#ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE + if (hp_size == PMD_SIZE) + return PUD_SIZE - PMD_SIZE; +#endif return 0UL; } @@ -7142,14 +7137,11 @@ void hugetlb_unshare_all_pmds(struct vm_area_struct *vma) mmu_notifier_invalidate_range_start(&range); i_mmap_lock_write(vma->vm_file->f_mapping); for (address = start; address < end; address += PUD_SIZE) { - unsigned long tmp = address; - ptep = huge_pte_offset(mm, address, sz); if (!ptep) continue; ptl = huge_pte_lock(h, mm, ptep); - /* We don't want 'address' to be changed */ - huge_pmd_unshare(mm, vma, &tmp, ptep); + huge_pmd_unshare(mm, vma, address, ptep); spin_unlock(ptl); } flush_hugetlb_tlb_range(vma, start, end); diff --git a/mm/rmap.c b/mm/rmap.c index 04fac1af870b..1c22e5e1219a 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1559,7 +1559,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, */ VM_BUG_ON(!(flags & TTU_RMAP_LOCKED)); - if (huge_pmd_unshare(mm, vma, &address, pvmw.pte)) { + if (huge_pmd_unshare(mm, vma, address, pvmw.pte)) { flush_tlb_range(vma, range.start, range.end); mmu_notifier_invalidate_range(mm, range.start, range.end); @@ -1923,7 +1923,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, */ VM_BUG_ON(!(flags & TTU_RMAP_LOCKED)); - if (huge_pmd_unshare(mm, vma, &address, pvmw.pte)) { + if (huge_pmd_unshare(mm, vma, address, pvmw.pte)) { flush_tlb_range(vma, range.start, range.end); mmu_notifier_invalidate_range(mm, range.start, range.end); From patchwork Tue Jun 21 23:56:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12889964 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53B82CCA473 for ; Wed, 22 Jun 2022 00:20:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354275AbiFVAUN (ORCPT ); Tue, 21 Jun 2022 20:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354006AbiFVAUM (ORCPT ); Tue, 21 Jun 2022 20:20:12 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 986FE24BC7; Tue, 21 Jun 2022 17:20:11 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25M0JD02004543; Wed, 22 Jun 2022 00:19:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=gVCgyGS215qeuzVyh3NQ1QmLGn7c+lAD2oWKU3YYHCU=; b=dvYTpi2KO0H7AYAKJEd5OB0Hxx6hl3skv5Qg51vCWo/9f80z3o3/UHUEvIa+nF8uRXln wtMcz9S2d3VesV6EutRxAYzF0TBTaakaiXLfNdY99D5J40vc1psxjXHTs1C4P0f8f6YY GGgwKay1vHqL5ys5BqfO2bmuDl4GE/5J77OmeKvamfWsAX2Hfd7EUv2zjV9idtEE/ne0 EfWG2o903joIpoGT0ZUefYeVkXCZEL6z4Xw5vZPnHbFmPE2kSlLvFiFUGwClRQqg3xde JIDLQtZyVSyv32lpGWgLVo+DDSLL58SQSoZ5SUzchIZbf9tLqCo3iShcKoTG1CmtHX7n cg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gs54cpyun-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 22 Jun 2022 00:19:14 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25LNoaFl013391; Tue, 21 Jun 2022 23:56:41 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gtg3vqywj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jun 2022 23:56:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AXvRpOqTnS13F3ZbGoSjJ8JhQr7xmBGHb8RYC7AbW+vYrkYRAXPo997g01OLL77KdY7B4c1Y7e/W1bXa3mmh12RCTGaTp4lDHNEi5+B6RFrWmrDm4eEY2Q/TeETrtAuk+qocTkbQkd8uHublF1qy6M/mDG5vDMhPx7+RIa4Bx/leZ4+DLxNnUEvc1kXPfNDmGogdUqLeATP4pyQN3mAOwknkxdYRneaF/0GWYpP/BuvNFKgJ5gxENEuZsdwacFW9lwBLzcsCfSMLw6nAfNeEhBbz1mR+9wJ7/LP6tHQxoymfiUyobQSR0Hf441h9hE1UpkWTPr9a1Aw8Qg0WSjbgKg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gVCgyGS215qeuzVyh3NQ1QmLGn7c+lAD2oWKU3YYHCU=; b=ZooVdaMO6lQRv+09OAur/bK2hK6WbvvD3YcyicOPWjohfxwRruIUCBH25W/1PWGDLJ+vsQFfRQc614FABF+qlaa78u883x7YJQLJCq7m9LCaxhwKXboMJWHZ6snMgDj5VTOHgMPZe7Tt9c2xaORqI4iPg0khWulEAX3PVv6zqoOTTk2cosH//ysq7CIltLRk3nKlHtgcrZoz4x8W0Sp8EoZ9b8Fpw6G73us/1+UC/UttlZ05VKiot5Wl1KNQkO13vokgaD3d2AbFQ6QLAEnQfuDg6l8hDMvwlcu37/Hvh0psMkf0B2zwLqYdUMkNEGLD/iQCudn7D90ffCmy+QhN7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gVCgyGS215qeuzVyh3NQ1QmLGn7c+lAD2oWKU3YYHCU=; b=I2OjtEAMjpJfcn+KxqTZbFfzYyM3dG/SlosbEVW7CARxHw4+zPvJiEn5SaduKIuTU5Cf0BFJ2iwcNUrcv35YLU+XWxFrdKHtfj7L13MJ5iu58HoMqTZTjP8OqJdkKwAmT+LpGsDV7rMcCDhriw/LmI7YUnLeOyP+gRbk4elLvPo= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by MWHPR10MB1501.namprd10.prod.outlook.com (2603:10b6:300:24::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Tue, 21 Jun 2022 23:56:40 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::2125:9bb7:bfeb:81f9]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::2125:9bb7:bfeb:81f9%8]) with mapi id 15.20.5353.022; Tue, 21 Jun 2022 23:56:39 +0000 From: Mike Kravetz To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Muchun Song , Baolin Wang , Michal Hocko , Peter Xu , Naoya Horiguchi , James Houghton , Mina Almasry , "Aneesh Kumar K . V" , Anshuman Khandual , Paul Walmsley , Christian Borntraeger , catalin.marinas@arm.com, will@kernel.org, Rolf Eike Beer , Andrew Morton , Mike Kravetz , David Hildenbrand Subject: [PATCH v2 4/4] hugetlb: Lazy page table copies in fork() Date: Tue, 21 Jun 2022 16:56:20 -0700 Message-Id: <20220621235620.291305-5-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621235620.291305-1-mike.kravetz@oracle.com> References: <20220621235620.291305-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MWHPR15CA0066.namprd15.prod.outlook.com (2603:10b6:301:4c::28) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dcafded0-41c6-4927-404e-08da53e1af1a X-MS-TrafficTypeDiagnostic: MWHPR10MB1501:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s9Ix0Q0WjEyHx3o1CIVwKZPZa5eEwG/qDjXsyMIqzrcYKO7J25YRBYHN6yiMeyN/0+rIfqrEODucNANWNcf9firw2GxDlFgtba0/qy0DquthtnDgMzFtLYg39yPV/nIRC3Hk/Y3BZiogQjMYcsOnl/wWApK+x121xRhee9F+G3fCSBz19sJ3Wb+k2JiihT/20uFnxRekXill8+9kz+ss9Jb7oBPBVT8jik4SLf29AmeuNBn1K092frsD23sVfBFigi8O3zVAwURvdDvlSjfM4Hdi1egYiHfmMZG9DIjhGvSdI8M6sRNKsqJnWVh2nIqIcoZB8b3wu/iRX04t5cAn/nnARByzNF3Rg6ugExORt12f8ICFLeGH8d/e8pBVhWPoS470tuoTM46YnZU64oCvBVHYOFn0q/MIUjjEelfybe3krYV+0S/arGahRDkbtxp8eNsOtoSZPjlwk9DFZlVCbyhAmmzbwEp3cMF5u6k+cqEnUJkgcehg4tIKeZgfbq5ERN7jOo6iDbxeaGV00wnT3f2QFQvxa3li9dqpMMGcxTlI10PODG3pg+4tNU+6pNwiJ55AZxaVKAQaxHNlX2y4StUDaBaoSgXEGltWdXrhhKQLuHVe/wBqFmqPxGMip3R/GSstmSLxn4rqULWE4MLadkQ7i+kLSeXQ2U097AaJ4qyzI5DlibbcZzUAJcUDLQ5V X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(366004)(396003)(136003)(39860400002)(346002)(376002)(2906002)(86362001)(4326008)(6486002)(44832011)(6506007)(54906003)(921005)(8676002)(36756003)(66476007)(66556008)(26005)(6512007)(66946007)(186003)(6666004)(38100700002)(7416002)(316002)(478600001)(1076003)(8936002)(2616005)(41300700001)(83380400001)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TlPjM4obrF6PM8hCyNaTJwD0HbbSMvxJ/Y+ivR3qBy/GrkX2KHcMP9Lq0KVB4V7/aNt1eBOgIbGB7uZ/GhLf56ElWlPad3feEk05SjPqflFzDGfA7MzFLw2B/IJR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ASlDtlz4PDu765CLyL8T5XWprpaEpRsfUtxHIN6yO/mjbv0z5yzcVe9W+nO7zbS00qf6iVgtySNn2pfGImfXBT/ASX0DvddfMyFEiZnzMrgixPJVS8qijaNiIYkAnP+YD95J7CTk6V+XdGM9AQWZEXldu7DPOBWN4O8JrkOLwLqIiceOsmj7KTGFFd78xFRqX6VZoXvx27pZIC6wPtfjH93rg9p+fSgqyQ8QlFIg8n3Cmd4NgLCZUso7k3lNNEXYrdyK8s9xOFnQLuTirmM/dwV/j53kaeGxuT72kmp3V3bp+QoANYA+7FM2QqfY6UtxtaU4csYX+6c+mUMLItxvmQvitTv8m2nlVoQ77eUtBFbEu0ss0TcpAFKQXNN5qo1bAVS3WA1dyYa11mfPNnhQPHCvfoHGpjLWS9lJGrA5S7ARa2qObQ8wy9+1Ds/gvBNa2wzoxlU1F2efj30L7xB1JPz8/lcH3vYhrNqSz0pdDvib7fqRECuihjrxbEQGU9oE2U0n8G9GLygCBK6NFqwv8kumfYQSxbQDWsBt7FWBvVbQtCgwlri+w= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: dcafded0-41c6-4927-404e-08da53e1af1a X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2022 23:56:39.8076 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: r98VtNgmrYghT2NI87WKK3IrU8gNeo9TSUm3gAK4NPDQpZ7ShdRVyVVGE3uBRBSzdbEvE2ccn98MqtUA/U24rg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1501 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-06-21_10:2022-06-21,2022-06-21 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206210105 X-Proofpoint-GUID: HkzJfwX2EwmDyf35LBsT6Gri-nMPTsN7 X-Proofpoint-ORIG-GUID: HkzJfwX2EwmDyf35LBsT6Gri-nMPTsN7 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Lazy page table copying at fork time was introduced with commit d992895ba2b2 ("[PATCH] Lazy page table copies in fork()"). At the time, hugetlb was very new and did not support page faulting. As a result, it was excluded. When full page fault support was added for hugetlb, the exclusion was not removed. Simply remove the check that prevents lazy copying of hugetlb page tables at fork. Of course, like other mappings this only applies to shared mappings. Lazy page table copying at fork will be less advantageous for hugetlb mappings because: - There are fewer page table entries with hugetlb - hugetlb pmds can be shared instead of copied In any case, completely eliminating the copy at fork time should speed things up. Signed-off-by: Mike Kravetz Acked-by: Muchun Song Acked-by: David Hildenbrand --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index fee2884481f2..90d2a614b2de 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1262,7 +1262,7 @@ vma_needs_copy(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) if (userfaultfd_wp(dst_vma)) return true; - if (src_vma->vm_flags & (VM_HUGETLB | VM_PFNMAP | VM_MIXEDMAP)) + if (src_vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP)) return true; if (src_vma->anon_vma)