Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp663155iog; Wed, 29 Jun 2022 07:50:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbpmhDwp5R//h+/I1vXwBbXxmVc1AY0Wc03GEYRKteXVcEd9apmG+VAE3BlSYnxWtLp98D X-Received: by 2002:a50:eb45:0:b0:437:7686:6048 with SMTP id z5-20020a50eb45000000b0043776866048mr4933636edp.264.1656514244854; Wed, 29 Jun 2022 07:50:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1656514244; cv=pass; d=google.com; s=arc-20160816; b=wKxT05IhKwaS8dqQrhRxIUhqxyIInIkMSEMwWVadxWwgz0X07N0reuSfFVB2QFX0Kb Jw8GVAIFMDLQl2jcCeFN2+Gsht/NxB7CiejAyG4zi2+cxzGfSni318MoaZMgQrjEQSt9 23I9Nk4q0FCpkkUqAcS5tgJE3HY3oWBVpEu8QttpOivhoySrnvs+QrxOsa6JVopCPOdw X4Ys6Ck4JJK88J1tHBJ+uGnlAgTkrB4tlSkPRFYv+2YEl6zTdr2ytNvRn7r0BzmB7EVM l1ory1faEeVPSBR13p3NwhbM7Si5GRGTZEVKW6Hjs8BfiCYpBLMVHkcTL6GcvXCmVS5T pXTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:subject:user-agent:date :message-id:dkim-signature; bh=NRHi5PXfqcURXdm+wG+KHaCJ5jWvHG7qokRuQFumo3A=; b=TWnCkMJE7q6aY3CVCQdvOHQ5B8+JRsyOW+nV9IehOxQYYMfDPydZsPImkEKWJ54/0I WLLsVkMWtGGqY+BjIiJ4aBh9BRUmKA/oz/go9nYwRiVhf9NGDuYpjUHB8/BBn8O7wpr9 IGMxq6lAqG5OXqEEB2LcpnRnnZCH4sv7ED5buBohSYepep59TT1FWeWqaRaRaQN8o4BI bHut0cs+cIssbcF5rNZBRQ3em0iWsmu56zUIfe8913zhPifCguREyHEwv3O6ynhLrpYy /27I7Tl5ST48S5v611AenWr/Y2hMyuqgWQDaUqL7BrXeQ1jA2WlgT14SnR1DpVkbK+5H Rvxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nutanix.com header.s=proofpoint20171006 header.b=LAVpNjxX; arc=pass (i=1 spf=pass spfdomain=nutanix.com dkim=pass dkdomain=nutanix.com dmarc=pass fromdomain=nutanix.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nutanix.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc4-20020a1709071c0400b00711988b5913si4741439ejc.804.2022.06.29.07.50.15; Wed, 29 Jun 2022 07:50:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nutanix.com header.s=proofpoint20171006 header.b=LAVpNjxX; arc=pass (i=1 spf=pass spfdomain=nutanix.com dkim=pass dkdomain=nutanix.com dmarc=pass fromdomain=nutanix.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nutanix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232466AbiF2Odv (ORCPT + 99 others); Wed, 29 Jun 2022 10:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232925AbiF2Odr (ORCPT ); Wed, 29 Jun 2022 10:33:47 -0400 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FA211E3D2 for ; Wed, 29 Jun 2022 07:33:46 -0700 (PDT) Received: from pps.filterd (m0127839.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25TCUXRa031333; Wed, 29 Jun 2022 07:33:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=NRHi5PXfqcURXdm+wG+KHaCJ5jWvHG7qokRuQFumo3A=; b=LAVpNjxX2aMWQDd/UYYtxbV6mDrz9heORDl9vl3eIMtBeytZVdVpbAZg+5okI5YHJf+k cJv5eVdWrWhgVCzDd1VL+nb56e/c430GqU2diAe5RtcwhEv7GgyfuHBTUaLFCQW3W6I4 NIWC7yPtaKDTIAfOLmNM3NLttFHKf+owSYX/8jFBV0a/+TK6v3qVxX4gvWH3QZ7wXaFQ X2uzj+zujLRw4UUgKwDeUcBurQWkwrb8LgCeFknQww9ob4sGQsQvMMHJg4ln4AkBmMNx PtXKigjRbvALEy6B3acAsW8mYRfMjLOWa7+hxy7Ls6iNowRf6G4blTNfvk0RfKX74nWH 6A== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2175.outbound.protection.outlook.com [104.47.55.175]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3gx1eh0w5a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 Jun 2022 07:33:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DqqkcwK/RBmyAVy5/3MDBVBMFy5dJL/vFOrHHj4vjxKQ6yJoJ+en5uF+d4c4hHtxeLOt6XEkCuVCHGDDRJnCT6NAKsiVr0XvxItgWgzGDcITanaNRprgJ4hqgTCdrhRmZeW+xVbmrBuwdjuNQSPjtKOmK33zARNeaEfvLOrUEztizEguTjGj+I98lTrHNi82vkDeE2wGwkqQRFaRQttHytVnpN++6dWVKhPTz8VqqfJNQyAYjYJRnf6RkjGL5m4dAgLWbriLFMbcSbiTicIenFk0srUOjkYOWtWnCw28cWUzAGJSj+3DY2baUj3RPi/wef8O5bRe9ILDco9U8jBbpQ== 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=NRHi5PXfqcURXdm+wG+KHaCJ5jWvHG7qokRuQFumo3A=; b=aibACFTrvKh8U/XiCcdu7nqu6bZcgGBS6HWGCWxlnOm5fqSM+/24S7GBZ7yiTcIhAMh6qvqgCllslv8EGQN7b4p/aOFXWW1RCD+jdfsXDQeOAzYUeNePHJdo+SEjv6R421MPtYzPNfsu9xjA7qnPREVdPTKrBEz+GhqTVycQifCLCk3e+B7Bgo7YPaIOlPx99Z5QUN08GN6vY5WxHztMxrd+Fb3oZMjAzaymzBphdLW7BMqMrnG9PX2GZOizWO9G3VJkD+81HjK+cBGELCkSzT8qOG64UDUkVIemRpbFluvUogj2UWFe5uIpb60CJgt7FprFEhJftI7crEKo5h4SwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from PH0PR02MB7384.namprd02.prod.outlook.com (2603:10b6:510:12::12) by CH0PR02MB7963.namprd02.prod.outlook.com (2603:10b6:610:104::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Wed, 29 Jun 2022 14:33:30 +0000 Received: from PH0PR02MB7384.namprd02.prod.outlook.com ([fe80::898c:892a:2385:3df6]) by PH0PR02MB7384.namprd02.prod.outlook.com ([fe80::898c:892a:2385:3df6%4]) with mapi id 15.20.5395.014; Wed, 29 Jun 2022 14:33:30 +0000 Message-ID: <54e46486-8886-f5d4-4900-8a250bb5e805@nutanix.com> Date: Wed, 29 Jun 2022 20:03:16 +0530 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [RFC PATCH 12/26] hugetlb: add HugeTLB splitting functionality To: James Houghton , Mike Kravetz , Muchun Song , Peter Xu Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , Jue Wang , "Dr . David Alan Gilbert" , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220624173656.2033256-1-jthoughton@google.com> <20220624173656.2033256-13-jthoughton@google.com> From: "manish.mishra" In-Reply-To: <20220624173656.2033256-13-jthoughton@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BYAPR04CA0035.namprd04.prod.outlook.com (2603:10b6:a03:40::48) To PH0PR02MB7384.namprd02.prod.outlook.com (2603:10b6:510:12::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3906e10a-98ba-415e-e019-08da59dc5633 X-MS-TrafficTypeDiagnostic: CH0PR02MB7963:EE_ x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JDlCampNp3jK99+H69xjodPe5rLk9WmYfNKkmn2+ZdKSZ7fCxQsdKSJgUVBHQym6BBKC/4LH2TOh7V6n1Q0azBrAWfWN3EJMk0O1nkSKBMaU1ygxOfj6rDA2JwkdQB4D9Aepot+a+rvrbEovXNax3WbtsAlxrHGvEb82IGowiXOCbj1Wls0Pip1yPt5+O808NyZoGbJCQn7RQE7woREjMYH/EsFSZ6SnVL3ECwKHbY4JH5+1iJ5QNoV/yNIwGuo5MpU1+Xf5OGgVGFEkBGVOQMIOUtNk+OKFC7h+sxfGD4NQGTbonQavk2//MnjV0jlnlZ8nEnCTmyZQvVMimCCXChIFIoCLEeIXaisP7F3obhE5w0ITSKzGxlbubu7ahtmPY76GhflILJp+Rcce/SgTxKAhsGb+FqVVuHFmds9B5lqc5mAdPysMzrQHmGnwL4ncn2u18MSQvc4WJqWeR0ltgIrz/DIFPan8vuuteP5BCCRPH22BxldlCna8r/hho+JbqVQ31EmzcybITohpJGPK+Jp4mQRe7wTtFYuH6lQQEJjKS+6Hq7qT0b9SvpGBM2mreN/yiLurE3R4Q/ACH+E/aNKwxk0oTRZ3P6B9Y8emmYsAvR4h2CgcnJ6kDraJgDjmjJNH3KaBCPtBaux3NYEIbtHSqz5aw8w9jOu384aItjeu5UALs6hL2saoCOLK2pGEfXj/wnduEk01pDNj+bTBaJEMitgKTxKR680W0rp3u0mhdtxGQVoIqXNmYALKCi5noSPbuZWDkIH0tc11diahva1+Tlw3W4qmeluldfGQ+bg/73MYChVc0S7R9FuiAFcN X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR02MB7384.namprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(346002)(376002)(366004)(136003)(396003)(39860400002)(86362001)(66476007)(66946007)(66556008)(8676002)(8936002)(478600001)(2616005)(36756003)(7416002)(5660300002)(316002)(54906003)(31686004)(110136005)(4326008)(6486002)(41300700001)(6666004)(6506007)(2906002)(26005)(53546011)(6512007)(38100700002)(186003)(83380400001)(31696002)(43740500002)(45980500001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?U004TEdoVHJNdzBrMlVsTlUwNzJscG5PNnhEbkVoellzN0lHQ0JMWTYx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VNCRFJGeWF2OWZrbFFyMGNlVXdDNGtFTFp0TytJc1JKYU1W?= =?utf-8?B?Wjc4clZGSm9ML2MrTWlILzlvMG5venNGU0ZqeFN0OW1LUGZyajRyTDdXS1U5?= =?utf-8?B?YjNVTUVVb2ZzZEJNbTFuSGplZzVSMVJJaHNWMUFqbTJyRDhiZU9uQ3Z3Y2U1?= =?utf-8?B?d1FrR05GUnpGM3Zjc1V2SGNaSk1JTnVod1YvMXhCUWtNb29TVXVSN0V3V1JO?= =?utf-8?B?bm53RnNMdXVsT0QzelpaRHJRRkgzV0NGbE5QekkrdVh2VDhpQVZ1M3h5VUZj?= =?utf-8?B?aDNsdGlSRWlwazZUOFZxQjlJdXQrVy81S2hNcmdzdFM1Z2duODhiaGlPMVY4?= =?utf-8?B?TkE9PQ==?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3906e10a-98ba-415e-e019-08da59dc5633 X-MS-Exchange-CrossTenant-AuthSource: PH0PR02MB7384.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 14:33:30.2153 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QQy+ifkFx8qzEJQ0/dzunRJg06u3VAyPvVDjsR3Sq53gxLPvaJsE2WF/aG/TAHQ2+L+VxmAqnNlrFD2wxDTbqlZLBl+U9HgAhgRy4iymyxA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR02MB7963 X-Proofpoint-GUID: V_sg5qgX2uGKR9Zr1oD6V3msqafxhy1J X-Proofpoint-ORIG-GUID: V_sg5qgX2uGKR9Zr1oD6V3msqafxhy1J X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-29_17,2022-06-28_01,2022-06-22_01 X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/06/22 11:06 pm, James Houghton wrote: > The new function, hugetlb_split_to_shift, will optimally split the page > table to map a particular address at a particular granularity. > > This is useful for punching a hole in the mapping and for mapping small > sections of a HugeTLB page (via UFFDIO_CONTINUE, for example). > > Signed-off-by: James Houghton > --- > mm/hugetlb.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 122 insertions(+) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 3ec2a921ee6f..eaffe7b4f67c 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -102,6 +102,18 @@ struct mutex *hugetlb_fault_mutex_table ____cacheline_aligned_in_smp; > /* Forward declaration */ > static int hugetlb_acct_memory(struct hstate *h, long delta); > > +/* > + * Find the subpage that corresponds to `addr` in `hpage`. > + */ > +static struct page *hugetlb_find_subpage(struct hstate *h, struct page *hpage, > + unsigned long addr) > +{ > + size_t idx = (addr & ~huge_page_mask(h))/PAGE_SIZE; > + > + BUG_ON(idx >= pages_per_huge_page(h)); > + return &hpage[idx]; > +} > + > static inline bool subpool_is_free(struct hugepage_subpool *spool) > { > if (spool->count) > @@ -7044,6 +7056,116 @@ static unsigned int __shift_for_hstate(struct hstate *h) > for ((tmp_h) = hstate; (shift) = __shift_for_hstate(tmp_h), \ > (tmp_h) <= &hstates[hugetlb_max_hstate]; \ > (tmp_h)++) > + > +/* > + * Given a particular address, split the HugeTLB PTE that currently maps it > + * so that, for the given address, the PTE that maps it is `desired_shift`. > + * This function will always split the HugeTLB PTE optimally. > + * > + * For example, given a HugeTLB 1G page that is mapped from VA 0 to 1G. If we > + * call this function with addr=0 and desired_shift=PAGE_SHIFT, will result in > + * these changes to the page table: > + * 1. The PUD will be split into 2M PMDs. > + * 2. The first PMD will be split again into 4K PTEs. > + */ > +static int hugetlb_split_to_shift(struct mm_struct *mm, struct vm_area_struct *vma, > + const struct hugetlb_pte *hpte, > + unsigned long addr, unsigned long desired_shift) > +{ > + unsigned long start, end, curr; > + unsigned long desired_sz = 1UL << desired_shift; > + struct hstate *h = hstate_vma(vma); > + int ret; > + struct hugetlb_pte new_hpte; > + struct mmu_notifier_range range; > + struct page *hpage = NULL; > + struct page *subpage; > + pte_t old_entry; > + struct mmu_gather tlb; > + > + BUG_ON(!hpte->ptep); > + BUG_ON(hugetlb_pte_size(hpte) == desired_sz); > + > + start = addr & hugetlb_pte_mask(hpte); > + end = start + hugetlb_pte_size(hpte); > + > + i_mmap_assert_write_locked(vma->vm_file->f_mapping); > + > + BUG_ON(!hpte->ptep); > + /* This function only works if we are looking at a leaf-level PTE. */ > + BUG_ON(!hugetlb_pte_none(hpte) && !hugetlb_pte_present_leaf(hpte)); > + > + /* > + * Clear the PTE so that we will allocate the PT structures when > + * walking the page table. > + */ > + old_entry = huge_ptep_get_and_clear(mm, start, hpte->ptep); Sorry missed it last time, what if hgm mapping present here and current hpte is at higher level. Where we will clear and free child page-table pages. I see it does not happen in huge_ptep_get_and_clear. > + > + if (!huge_pte_none(old_entry)) > + hpage = pte_page(old_entry); > + > + BUG_ON(!IS_ALIGNED(start, desired_sz)); > + BUG_ON(!IS_ALIGNED(end, desired_sz)); > + > + for (curr = start; curr < end;) { > + struct hstate *tmp_h; > + unsigned int shift; > + > + for_each_hgm_shift(h, tmp_h, shift) { > + unsigned long sz = 1UL << shift; > + > + if (!IS_ALIGNED(curr, sz) || curr + sz > end) > + continue; > + /* > + * If we are including `addr`, we need to make sure > + * splitting down to the correct size. Go to a smaller > + * size if we are not. > + */ > + if (curr <= addr && curr + sz > addr && > + shift > desired_shift) > + continue; > + > + /* > + * Continue the page table walk to the level we want, > + * allocate PT structures as we go. > + */ > + hugetlb_pte_copy(&new_hpte, hpte); > + ret = hugetlb_walk_to(mm, &new_hpte, curr, sz, > + /*stop_at_none=*/false); > + if (ret) > + goto err; > + BUG_ON(hugetlb_pte_size(&new_hpte) != sz); > + if (hpage) { > + pte_t new_entry; > + > + subpage = hugetlb_find_subpage(h, hpage, curr); > + new_entry = make_huge_pte_with_shift(vma, subpage, > + huge_pte_write(old_entry), > + shift); > + set_huge_pte_at(mm, curr, new_hpte.ptep, new_entry); > + } > + curr += sz; > + goto next; > + } > + /* We couldn't find a size that worked. */ > + BUG(); > +next: > + continue; > + } > + > + mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm, > + start, end); > + mmu_notifier_invalidate_range_start(&range); > + return 0; > +err: > + tlb_gather_mmu(&tlb, mm); > + /* Free any newly allocated page table entries. */ > + hugetlb_free_range(&tlb, hpte, start, curr); > + /* Restore the old entry. */ > + set_huge_pte_at(mm, start, hpte->ptep, old_entry); > + tlb_finish_mmu(&tlb); > + return ret; > +} > #endif /* CONFIG_HUGETLB_HIGH_GRANULARITY_MAPPING */ > > /*