Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp487119rdb; Tue, 19 Sep 2023 01:04:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHurewCSHHKDe7hwpK/TRzWGORgbErWnl+rZfby2G15aTF/i+XeGyC+ONuSDehIwQW+fdsH X-Received: by 2002:a17:902:e841:b0:1bc:422a:b9fd with SMTP id t1-20020a170902e84100b001bc422ab9fdmr14890959plg.13.1695110684487; Tue, 19 Sep 2023 01:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695110684; cv=none; d=google.com; s=arc-20160816; b=jInKI6smHpCnc9icipdNVErK7POES6xzBNUBaSTNHNlLOla8bv/SOreMMDjhuNuT2j o2bRhzYRJU88GSx20tD+umxIu0JEdkkGnspakxCSnsrs42JPcT11MhX8GMaomhBLSmgX fWKnzB5h6XIu1fQJ1aC9BcYqM7Cly8DuRJNggOBHPK9EynFtV7iykG2HSZDexN2r1Vz8 EX6gZ4hKDWNi6TyErS20gtJcw8nG4VdqtFLy4SQuN83Hybw0KhmXIeS7qzQ9GDeee10N J3ZSSnM+D6ZxyC10ttlXCFqTrOuMIN+wT+hQY7ckNtU2A4xBcxB23/KvV/jB4x64nNwj Gleg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:mime-version:date:dkim-signature :message-id; bh=zv2mbCenM93IUHoZmD+q2RXYKs9LyiPjrfSBHDb0DlM=; fh=NUOR0A7/p2+R3cB1wb12E2b6kjxRBAzeNIsekrHm1DI=; b=dx4cOk5qqA1dcsOf+XU15ljTh0OC4Sl0nHzYcGE9Wu9pX29IBfxae8RBFi/C6CY1xO XZBqxm7z42hRiRKy2DlbCsyfbUq97IYHkwVVY5fgkah9H60w84NSnGAcePiBRvC8gAGj Q1UwUYVIO2JzvpAxzRH75JWtSq2iN+z/au9XrtPgrewGly5p1tVK9N1mbVk+CXMaK8Lf vRCEFuCOM+PhPVyVszq8BR8BQkCgMXPBoob3e2NO0++MqwjMazGWZmntd94CptuHBaRp F8yEOwkKk+wtXijxaTYalg+EgpnLRWz5JsNWG1YZpH3F73hdnRaq+72mici+PzENkLWL 4Wzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=VwPyHKdm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id e11-20020a17090301cb00b001b7eb771d5esi9779913plh.527.2023.09.19.01.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 01:04:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=VwPyHKdm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C4CB2833CE1B; Mon, 18 Sep 2023 23:49:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231594AbjISGta (ORCPT + 99 others); Tue, 19 Sep 2023 02:49:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231597AbjISGt3 (ORCPT ); Tue, 19 Sep 2023 02:49:29 -0400 Received: from out-222.mta1.migadu.com (out-222.mta1.migadu.com [95.215.58.222]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFF02116 for ; Mon, 18 Sep 2023 23:49:21 -0700 (PDT) Message-ID: <1ffd72f1-7345-1d31-ea6f-77bec83cb570@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1695106159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zv2mbCenM93IUHoZmD+q2RXYKs9LyiPjrfSBHDb0DlM=; b=VwPyHKdmYl8UKS/ID54rvHNcMiruPgRN4Z/mOdEpJsuOPUoyU1v7D2KEbEwHLVKkOmoDlw p6OrgiKBFjbeQmEEcMT357XxgsGPme5LgPM+fWAFH3y8klSutcW5Di/UizOC1dZiZeeNGW xefkh8AuvrDB/l+/GMQNGYSTMYqcqlk= Date: Tue, 19 Sep 2023 14:48:54 +0800 MIME-Version: 1.0 Subject: Re: [PATCH v4 8/8] hugetlb: batch TLB flushes when restoring vmemmap To: Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , Joao Martins , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Naoya Horiguchi , Barry Song <21cnbao@gmail.com>, Michal Hocko , Matthew Wilcox , Xiongchun Duan , Andrew Morton References: <20230918230202.254631-1-mike.kravetz@oracle.com> <20230918230202.254631-9-mike.kravetz@oracle.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20230918230202.254631-9-mike.kravetz@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 23:49:33 -0700 (PDT) On 2023/9/19 07:02, Mike Kravetz wrote: > Update the internal hugetlb restore vmemmap code path such that TLB > flushing can be batched. Use the existing mechanism of passing the > VMEMMAP_REMAP_NO_TLB_FLUSH flag to indicate flushing should not be > performed for individual pages. The routine hugetlb_vmemmap_restore_folios > is the only user of this new mechanism, and it will perform a global > flush after all vmemmap is restored. > > Signed-off-by: Joao Martins > Signed-off-by: Mike Kravetz > --- > mm/hugetlb_vmemmap.c | 39 ++++++++++++++++++++++++--------------- > 1 file changed, 24 insertions(+), 15 deletions(-) > > diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c > index a6c356acb1fc..ae2229f19158 100644 > --- a/mm/hugetlb_vmemmap.c > +++ b/mm/hugetlb_vmemmap.c > @@ -460,18 +460,19 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end, > * @end: end address of the vmemmap virtual address range that we want to > * remap. > * @reuse: reuse address. > + * @flags: modify behavior for bulk operations Please keep the comment consistent with vmemmap_remap_split(), which says: "@flags:    modifications to vmemmap_remap_walk flags". Thanks. > * > * Return: %0 on success, negative error code otherwise. > */ > static int vmemmap_remap_alloc(unsigned long start, unsigned long end, > - unsigned long reuse) > + unsigned long reuse, unsigned long flags) > { > LIST_HEAD(vmemmap_pages); > struct vmemmap_remap_walk walk = { > .remap_pte = vmemmap_restore_pte, > .reuse_addr = reuse, > .vmemmap_pages = &vmemmap_pages, > - .flags = 0, > + .flags = flags, > }; > > /* See the comment in the vmemmap_remap_free(). */ > @@ -493,17 +494,7 @@ EXPORT_SYMBOL(hugetlb_optimize_vmemmap_key); > static bool vmemmap_optimize_enabled = IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON); > core_param(hugetlb_free_vmemmap, vmemmap_optimize_enabled, bool, 0); > > -/** > - * hugetlb_vmemmap_restore - restore previously optimized (by > - * hugetlb_vmemmap_optimize()) vmemmap pages which > - * will be reallocated and remapped. > - * @h: struct hstate. > - * @head: the head page whose vmemmap pages will be restored. > - * > - * Return: %0 if @head's vmemmap pages have been reallocated and remapped, > - * negative error code otherwise. > - */ > -int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) > +static int __hugetlb_vmemmap_restore(const struct hstate *h, struct page *head, unsigned long flags) > { > int ret; > unsigned long vmemmap_start = (unsigned long)head, vmemmap_end; > @@ -524,7 +515,7 @@ int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) > * When a HugeTLB page is freed to the buddy allocator, previously > * discarded vmemmap pages must be allocated and remapping. > */ > - ret = vmemmap_remap_alloc(vmemmap_start, vmemmap_end, vmemmap_reuse); > + ret = vmemmap_remap_alloc(vmemmap_start, vmemmap_end, vmemmap_reuse, flags); > if (!ret) { > ClearHPageVmemmapOptimized(head); > static_branch_dec(&hugetlb_optimize_vmemmap_key); > @@ -533,6 +524,21 @@ int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) > return ret; > } > > +/** > + * hugetlb_vmemmap_restore - restore previously optimized (by > + * hugetlb_vmemmap_optimize()) vmemmap pages which > + * will be reallocated and remapped. > + * @h: struct hstate. > + * @head: the head page whose vmemmap pages will be restored. > + * > + * Return: %0 if @head's vmemmap pages have been reallocated and remapped, > + * negative error code otherwise. > + */ > +int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) > +{ > + return __hugetlb_vmemmap_restore(h, head, 0); > +} > + > /** > * hugetlb_vmemmap_restore_folios - restore vmemmap for every folio on the list. > * @h: struct hstate. > @@ -557,7 +563,8 @@ int hugetlb_vmemmap_restore_folios(const struct hstate *h, > num_restored = 0; > list_for_each_entry(folio, folio_list, lru) { > if (folio_test_hugetlb_vmemmap_optimized(folio)) { > - t_ret = hugetlb_vmemmap_restore(h, &folio->page); > + t_ret = __hugetlb_vmemmap_restore(h, &folio->page, > + VMEMMAP_REMAP_NO_TLB_FLUSH); > if (t_ret) > ret = t_ret; > else > @@ -565,6 +572,8 @@ int hugetlb_vmemmap_restore_folios(const struct hstate *h, > } > } > > + flush_tlb_all(); > + > if (*restored) > *restored = num_restored; > return ret;