Skip to content

Commit 35f08b1

Browse files
mjkravetzopsiff
authored andcommitted
hugetlb: batch TLB flushes when restoring vmemmap
mainline inclusion from mainline-v6.7-rc1 category: performance 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. Link: https://lkml.kernel.org/r/20231019023113.345257-9-mike.kravetz@oracle.com Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com> Reviewed-by: Muchun Song <songmuchun@bytedance.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Barry Song <21cnbao@gmail.com> Cc: David Hildenbrand <david@redhat.com> Cc: David Rientjes <rientjes@google.com> Cc: James Houghton <jthoughton@google.com> Cc: Konrad Dybcio <konradybcio@kernel.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Miaohe Lin <linmiaohe@huawei.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Naoya Horiguchi <naoya.horiguchi@linux.dev> Cc: Oscar Salvador <osalvador@suse.de> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Usama Arif <usama.arif@bytedance.com> Cc: Xiongchun Duan <duanxiongchun@bytedance.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit c24f188) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 6e00350 commit 35f08b1

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

mm/hugetlb_vmemmap.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,19 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end,
461461
* @end: end address of the vmemmap virtual address range that we want to
462462
* remap.
463463
* @reuse: reuse address.
464+
* @flags: modifications to vmemmap_remap_walk flags
464465
*
465466
* Return: %0 on success, negative error code otherwise.
466467
*/
467468
static int vmemmap_remap_alloc(unsigned long start, unsigned long end,
468-
unsigned long reuse)
469+
unsigned long reuse, unsigned long flags)
469470
{
470471
LIST_HEAD(vmemmap_pages);
471472
struct vmemmap_remap_walk walk = {
472473
.remap_pte = vmemmap_restore_pte,
473474
.reuse_addr = reuse,
474475
.vmemmap_pages = &vmemmap_pages,
475-
.flags = 0,
476+
.flags = flags,
476477
};
477478

478479
/* See the comment in the vmemmap_remap_free(). */
@@ -494,17 +495,7 @@ EXPORT_SYMBOL(hugetlb_optimize_vmemmap_key);
494495
static bool vmemmap_optimize_enabled = IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON);
495496
core_param(hugetlb_free_vmemmap, vmemmap_optimize_enabled, bool, 0);
496497

497-
/**
498-
* hugetlb_vmemmap_restore - restore previously optimized (by
499-
* hugetlb_vmemmap_optimize()) vmemmap pages which
500-
* will be reallocated and remapped.
501-
* @h: struct hstate.
502-
* @head: the head page whose vmemmap pages will be restored.
503-
*
504-
* Return: %0 if @head's vmemmap pages have been reallocated and remapped,
505-
* negative error code otherwise.
506-
*/
507-
int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head)
498+
static int __hugetlb_vmemmap_restore(const struct hstate *h, struct page *head, unsigned long flags)
508499
{
509500
int ret;
510501
unsigned long vmemmap_start = (unsigned long)head, vmemmap_end;
@@ -525,7 +516,7 @@ int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head)
525516
* When a HugeTLB page is freed to the buddy allocator, previously
526517
* discarded vmemmap pages must be allocated and remapping.
527518
*/
528-
ret = vmemmap_remap_alloc(vmemmap_start, vmemmap_end, vmemmap_reuse);
519+
ret = vmemmap_remap_alloc(vmemmap_start, vmemmap_end, vmemmap_reuse, flags);
529520
if (!ret) {
530521
ClearHPageVmemmapOptimized(head);
531522
static_branch_dec(&hugetlb_optimize_vmemmap_key);
@@ -534,6 +525,21 @@ int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head)
534525
return ret;
535526
}
536527

528+
/**
529+
* hugetlb_vmemmap_restore - restore previously optimized (by
530+
* hugetlb_vmemmap_optimize()) vmemmap pages which
531+
* will be reallocated and remapped.
532+
* @h: struct hstate.
533+
* @head: the head page whose vmemmap pages will be restored.
534+
*
535+
* Return: %0 if @head's vmemmap pages have been reallocated and remapped,
536+
* negative error code otherwise.
537+
*/
538+
int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head)
539+
{
540+
return __hugetlb_vmemmap_restore(h, head, 0);
541+
}
542+
537543
/**
538544
* hugetlb_vmemmap_restore_folios - restore vmemmap for every folio on the list.
539545
* @h: hstate.
@@ -557,7 +563,8 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h,
557563

558564
list_for_each_entry_safe(folio, t_folio, folio_list, lru) {
559565
if (folio_test_hugetlb_vmemmap_optimized(folio)) {
560-
ret = hugetlb_vmemmap_restore(h, &folio->page);
566+
ret = __hugetlb_vmemmap_restore(h, &folio->page,
567+
VMEMMAP_REMAP_NO_TLB_FLUSH);
561568
if (ret)
562569
break;
563570
restored++;
@@ -567,6 +574,8 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h,
567574
list_move(&folio->lru, non_hvo_folios);
568575
}
569576

577+
if (restored)
578+
flush_tlb_all();
570579
if (!ret)
571580
ret = restored;
572581
return ret;

0 commit comments

Comments
 (0)