Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * HugeTLB Vmemmap Optimization (HVO)
0004  *
0005  * Copyright (c) 2020, ByteDance. All rights reserved.
0006  *
0007  *     Author: Muchun Song <songmuchun@bytedance.com>
0008  */
0009 #ifndef _LINUX_HUGETLB_VMEMMAP_H
0010 #define _LINUX_HUGETLB_VMEMMAP_H
0011 #include <linux/hugetlb.h>
0012 
0013 #ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
0014 int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head);
0015 void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head);
0016 
0017 /*
0018  * Reserve one vmemmap page, all vmemmap addresses are mapped to it. See
0019  * Documentation/vm/vmemmap_dedup.rst.
0020  */
0021 #define HUGETLB_VMEMMAP_RESERVE_SIZE    PAGE_SIZE
0022 
0023 static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h)
0024 {
0025     return pages_per_huge_page(h) * sizeof(struct page);
0026 }
0027 
0028 /*
0029  * Return how many vmemmap size associated with a HugeTLB page that can be
0030  * optimized and can be freed to the buddy allocator.
0031  */
0032 static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h)
0033 {
0034     int size = hugetlb_vmemmap_size(h) - HUGETLB_VMEMMAP_RESERVE_SIZE;
0035 
0036     if (!is_power_of_2(sizeof(struct page)))
0037         return 0;
0038     return size > 0 ? size : 0;
0039 }
0040 #else
0041 static inline int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head)
0042 {
0043     return 0;
0044 }
0045 
0046 static inline void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head)
0047 {
0048 }
0049 
0050 static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h)
0051 {
0052     return 0;
0053 }
0054 #endif /* CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP */
0055 
0056 static inline bool hugetlb_vmemmap_optimizable(const struct hstate *h)
0057 {
0058     return hugetlb_vmemmap_optimizable_size(h) != 0;
0059 }
0060 #endif /* _LINUX_HUGETLB_VMEMMAP_H */