xref: /aosp_15_r20/external/ltp/include/tst_hugepage.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 Red Hat, Inc.
4  */
5 
6 #ifndef TST_HUGEPAGE__
7 #define TST_HUGEPAGE__
8 
9 #define PATH_HUGEPAGES	"/sys/kernel/mm/hugepages/"
10 #define PATH_NR_HPAGES	"/proc/sys/vm/nr_hugepages"
11 #define PATH_OC_HPAGES "/proc/sys/vm/nr_overcommit_hugepages"
12 
13 #define MEMINFO_HPAGE_TOTAL  "HugePages_Total:"
14 #define MEMINFO_HPAGE_FREE   "HugePages_Free:"
15 #define MEMINFO_HPAGE_RSVD   "HugePages_Rsvd:"
16 #define MEMINFO_HPAGE_SURP   "HugePages_Surp:"
17 #define MEMINFO_HPAGE_SIZE   "Hugepagesize:"
18 
19 extern char *nr_opt; /* -s num   Set the number of the been allocated hugepages */
20 extern char *Hopt;   /* -H /..   Location of hugetlbfs, i.e.  -H /var/hugetlbfs */
21 
22 enum tst_hp_policy {
23 	TST_REQUEST,
24 	TST_NEEDS,
25 };
26 
27 #define TST_NO_HUGEPAGES ((unsigned long)-1)
28 
29 struct tst_hugepage {
30 	const unsigned long number;
31 	enum  tst_hp_policy policy;
32 };
33 
34 /*
35  * Get the default hugepage size. Returns 0 if hugepages are not supported.
36  */
37 size_t tst_get_hugepage_size(void);
38 
39 /*
40  * Try the best to request a specified number of huge pages from system,
41  * it will store the reserved hpage number in tst_hugepages.
42  *
43  * Note: this depend on the status of system memory fragmentation.
44  */
45 unsigned long tst_reserve_hugepages(struct tst_hugepage *hp);
46 
47 /*
48  * This variable is used for recording the number of hugepages which system can
49  * provides. It will be equal to 'hpages' if tst_reserve_hugepages on success,
50  * otherwise set it to a number of hugepages that we were able to reserve.
51  *
52  * If system does not support hugetlb, then it will be set to 0.
53  */
54 extern unsigned long tst_hugepages;
55 
56 #endif /* TST_HUGEPAGE_H */
57