Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp12880iog; Tue, 28 Jun 2022 13:46:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1um+2z/AsXFv+k1cc3HNHGHdPhmRPYq20uwwNo8M86mwgaXpM6trUl58Of72BB5u7dBZnSa X-Received: by 2002:a17:907:1b0c:b0:6fe:25bf:b3e5 with SMTP id mp12-20020a1709071b0c00b006fe25bfb3e5mr18660825ejc.689.1656449218773; Tue, 28 Jun 2022 13:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656449218; cv=none; d=google.com; s=arc-20160816; b=0vs6b9TJhWFvsKcXvmHREj5ve7jTzry+DpwST19jNEOKD6luDkE9nB3Cd1F69IySsV 7a4fLz3hNO34qmUpXG4uvx+KsuExuJek7luk4s7yatCKwDOhjqgRcEFuUDj6XAsNbf4J tiyN0+BHa3NrJLvgFoClIVdH8qxWyijjn12R0+1Vm1/aZm8Rb6J4COVXvV+PnpTzjW28 TpQcuvOVK/xWV/8lYBrDSH90A47qqhPJWz5VwxUiXwuzV4kxJt+PQoDNU8/NxGqR1Z2n iE67Itsruw16EXOO0FrsV0nUcXI3wVhVa9B5ZypKKdOxaJ54x8fCDLoB6qC/I/d9LKVv t2pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2jLxzzGBS8SBXC6kEJLju797m9m9QFRVwbOOwePPZP8=; b=xQttgwhNQY2dPplGDlnrwmpbbWrsO0LwiXUfXXwcrJjd+AXD6HcgB86EOu8lSRuLe9 75GXgf2hq3swSkQalfyCGIJhS4PQnc0CT+40pLmkTKH0e+J1Rp04auhminD8ftFzzklh Vk7nVLhokPkj1sp7nW/fmJi0oaMqF7Z6Ol/PfgxdPkEmzXyGOzmJXwOUzV8azGXLksnA pi/IzxHUrFz/CHau7SNfu2ffoEOJfusC4E5gopskShfzGuMxk1N/pAE3ad3MK+e8FicS eBKYiAwqFeGJT1+SpuRcjcR6XT9sjZgv7xD508+p4BJJhKs/IBSHVgD9hVc0gme6YCuS oL1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FXKxKU9S; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i18-20020a1709064fd200b007121c97d1d4si1790045ejw.947.2022.06.28.13.46.09; Tue, 28 Jun 2022 13:46:58 -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=@google.com header.s=20210112 header.b=FXKxKU9S; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232440AbiF1U3S (ORCPT + 99 others); Tue, 28 Jun 2022 16:29:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232533AbiF1U3A (ORCPT ); Tue, 28 Jun 2022 16:29:00 -0400 Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 807001A5 for ; Tue, 28 Jun 2022 13:27:57 -0700 (PDT) Received: by mail-vs1-xe36.google.com with SMTP id q28so917818vsp.7 for ; Tue, 28 Jun 2022 13:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2jLxzzGBS8SBXC6kEJLju797m9m9QFRVwbOOwePPZP8=; b=FXKxKU9S+Ca0kD67fbB4DM3QhjswVAkP5EfG/bmwZd9+oS/viVeF0g3nMSgjbgBjQD BTm0nkhvSHeFop49uJLDPAH+QUnh6aSOMJA/pNg4SqNw0RnB/Pve0FNEiGCmoamXZ7qw CxodY02mcA0FwKCgEdmRhHse5+Oa/5nLGexobXlYHnZc+NDAbkWkwT05Cwd8JVb5kxRK h9htBiCNZp0kHS0yI7m32r4d9Wlsrv4v3yobGATxY9IKnHeZriW6HpjtIHCvDDj27Kjs Cm16lEcK50A6DI2PZRLp35l58GgOGYxYbqd2FoFliqSp2toRJeSPuLGP2Wt2LpJVXe11 0NXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2jLxzzGBS8SBXC6kEJLju797m9m9QFRVwbOOwePPZP8=; b=XdnWnMEt7TErX3JFXxcJN1KS4VBNB6tH6X8yBtplzwMZg158mzlChSq0ui9Aik2NMN Lo48aW8HAb6BcpKAXM6NUOXwolByN6JxT/BVxQc4e98u7981A4JpKhBM4jl5SMv7Oh7Q ZadshySFjsyA/38B1bAusGaNzB1F1S1isH1Uhg76gARiOO9AQ1HhK0udOaaX4lKiKSP8 d99I9wd8ybQv2aapnmTga0lsfPqS4vKBQNgbo9vCdudaw7QWyONDzA6tVet83KH5/Hb4 mak8xTM/0pIotOpKWm0xf1dWJxBlXztjuypxLRX3lgRuyRqciJb1Ylz8Mxaefmm5dzpy fDGg== X-Gm-Message-State: AJIora/P9o3ZFOqzFGS1pyUctCfoX0PTt1tOui4wRhPrfzujFD/1ecrT yv+o03pxDDEsQiLxC2g28kVVlOWIovVaat6KM+ViCw== X-Received: by 2002:a05:6102:101:b0:354:355b:711b with SMTP id z1-20020a056102010100b00354355b711bmr2710147vsq.61.1656448076572; Tue, 28 Jun 2022 13:27:56 -0700 (PDT) MIME-Version: 1.0 References: <20220624173656.2033256-1-jthoughton@google.com> <20220624173656.2033256-9-jthoughton@google.com> In-Reply-To: <20220624173656.2033256-9-jthoughton@google.com> From: Mina Almasry Date: Tue, 28 Jun 2022 13:27:44 -0700 Message-ID: Subject: Re: [RFC PATCH 08/26] hugetlb: add hugetlb_free_range to free PT structures To: James Houghton Cc: Mike Kravetz , Muchun Song , Peter Xu , David Hildenbrand , David Rientjes , Axel Rasmussen , Jue Wang , Manish Mishra , "Dr . David Alan Gilbert" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Fri, Jun 24, 2022 at 10:37 AM James Houghton wrote: > > This is a helper function for freeing the bits of the page table that > map a particular HugeTLB PTE. > > Signed-off-by: James Houghton > --- > include/linux/hugetlb.h | 2 ++ > mm/hugetlb.c | 17 +++++++++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index 1d4ec9dfdebf..33ba48fac551 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -107,6 +107,8 @@ bool hugetlb_pte_none_mostly(const struct hugetlb_pte *hpte); > pte_t hugetlb_ptep_get(const struct hugetlb_pte *hpte); > void hugetlb_pte_clear(struct mm_struct *mm, const struct hugetlb_pte *hpte, > unsigned long address); > +void hugetlb_free_range(struct mmu_gather *tlb, const struct hugetlb_pte *hpte, > + unsigned long start, unsigned long end); > > struct hugepage_subpool { > spinlock_t lock; > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 1a1434e29740..a2d2ffa76173 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1120,6 +1120,23 @@ static bool vma_has_reserves(struct vm_area_struct *vma, long chg) > return false; > } > > +void hugetlb_free_range(struct mmu_gather *tlb, const struct hugetlb_pte *hpte, > + unsigned long start, unsigned long end) > +{ > + unsigned long floor = start & hugetlb_pte_mask(hpte); > + unsigned long ceiling = floor + hugetlb_pte_size(hpte); > + > + if (hugetlb_pte_size(hpte) >= PGDIR_SIZE) { > + free_p4d_range(tlb, (pgd_t *)hpte->ptep, start, end, floor, ceiling); > + } else if (hugetlb_pte_size(hpte) >= P4D_SIZE) { > + free_pud_range(tlb, (p4d_t *)hpte->ptep, start, end, floor, ceiling); > + } else if (hugetlb_pte_size(hpte) >= PUD_SIZE) { > + free_pmd_range(tlb, (pud_t *)hpte->ptep, start, end, floor, ceiling); > + } else if (hugetlb_pte_size(hpte) >= PMD_SIZE) { > + free_pte_range(tlb, (pmd_t *)hpte->ptep, start); > + } Same as the previous patch: I wonder about >=, and if possible calculate hugetlb_pte_size() once, or use *_SHIFT comparison. > +} > + > bool hugetlb_pte_present_leaf(const struct hugetlb_pte *hpte) > { > pgd_t pgd; > -- > 2.37.0.rc0.161.g10f37bed90-goog >