mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-09-21 12:11:49 +08:00
79359d6d24
When adding hugetlb pages to the pool, we first create a list of the allocated pages before adding to the pool. Pass this list of pages to a new routine hugetlb_vmemmap_optimize_folios() for vmemmap optimization. Due to significant differences in vmemmmap initialization for bootmem allocated hugetlb pages, a new routine prep_and_add_bootmem_folios is created. We also modify the routine vmemmap_should_optimize() to check for pages that are already optimized. There are code paths that might request vmemmap optimization twice and we want to make sure this is not attempted. Link: https://lkml.kernel.org/r/20231019023113.345257-4-mike.kravetz@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: Joao Martins <joao.m.martins@oracle.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>
67 lines
1.9 KiB
C
67 lines
1.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* HugeTLB Vmemmap Optimization (HVO)
|
|
*
|
|
* Copyright (c) 2020, ByteDance. All rights reserved.
|
|
*
|
|
* Author: Muchun Song <songmuchun@bytedance.com>
|
|
*/
|
|
#ifndef _LINUX_HUGETLB_VMEMMAP_H
|
|
#define _LINUX_HUGETLB_VMEMMAP_H
|
|
#include <linux/hugetlb.h>
|
|
|
|
/*
|
|
* Reserve one vmemmap page, all vmemmap addresses are mapped to it. See
|
|
* Documentation/vm/vmemmap_dedup.rst.
|
|
*/
|
|
#define HUGETLB_VMEMMAP_RESERVE_SIZE PAGE_SIZE
|
|
#define HUGETLB_VMEMMAP_RESERVE_PAGES (HUGETLB_VMEMMAP_RESERVE_SIZE / sizeof(struct page))
|
|
|
|
#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
|
|
int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head);
|
|
void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head);
|
|
void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list);
|
|
|
|
static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h)
|
|
{
|
|
return pages_per_huge_page(h) * sizeof(struct page);
|
|
}
|
|
|
|
/*
|
|
* Return how many vmemmap size associated with a HugeTLB page that can be
|
|
* optimized and can be freed to the buddy allocator.
|
|
*/
|
|
static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h)
|
|
{
|
|
int size = hugetlb_vmemmap_size(h) - HUGETLB_VMEMMAP_RESERVE_SIZE;
|
|
|
|
if (!is_power_of_2(sizeof(struct page)))
|
|
return 0;
|
|
return size > 0 ? size : 0;
|
|
}
|
|
#else
|
|
static inline int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head)
|
|
{
|
|
}
|
|
|
|
static inline void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list)
|
|
{
|
|
}
|
|
|
|
static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h)
|
|
{
|
|
return 0;
|
|
}
|
|
#endif /* CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP */
|
|
|
|
static inline bool hugetlb_vmemmap_optimizable(const struct hstate *h)
|
|
{
|
|
return hugetlb_vmemmap_optimizable_size(h) != 0;
|
|
}
|
|
#endif /* _LINUX_HUGETLB_VMEMMAP_H */
|