Skip to contentSkip to conversation

hugemmap32: release mem caches and prepare for hugepage

PATCH In review Li Wang 1 participant 4 messages May 29, 2023 – Jun 22, 2023 Library code

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/2 hugemmap32: release mem caches and prepare for hugepage

As Martin pointed that mem caches count as available, we'd better release them for huge page use.

---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c +1 -0
index 36a426a09..76b790a95 100644
@@ -64,6 +64,7 @@ static void setup(void)
 
 	SAFE_CLOSEDIR(dir);
 
+	SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
 	if (tst_available_mem() < (long long)hpage_size) {
 		g_hpage_path[0] = '\0';
 		tst_brk(TCONF, "No enough memory for gigantic hugepage reservation");
Signature · 5 lines
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#1 lore raw

PATCH 2/2 hugetlb: compacting memory to reduce fragmental pages

Kernel memory compaction is a process that helps to reduce fragmentation and optimize memory allocation by compacting memory pages.

echo 1 > /proc/sys/vm/compact_memory

When 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible.

This can be important for example in the allocation of huge pages although processes will also directly compact memory as required.

As this introduced since v2.6.35, we could safely use it via SAFE_FILE_PRINT() in LTP lib:

commit 76ab0f530e4a01d4dc20cdc1d5e87753c579dc18
Author: Mel Gorman <[email protected]>
Date: Mon May 24 14:32:28 2010 -0700

mm: compaction: add /proc trigger for memory compaction

---
 lib/tst_hugepage.c                                 | 1 +
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c | 2 ++
 2 files changed, 3 insertions(+)
lib/tst_hugepage.c +1 -0
index 728a8c3ec..d2e70a955 100644
@@ -47,6 +47,7 @@ unsigned long tst_reserve_hugepages(struct tst_hugepage *hp)
 	}
 
 	SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
+	SAFE_FILE_PRINTF("/proc/sys/vm/compact_memory", "1");
 	if (hp->policy == TST_NEEDS) {
 		tst_hugepages += SAFE_READ_MEMINFO("HugePages_Total:");
 		goto set_hugepages;
testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c +2 -0
index 76b790a95..d27e5b8b2 100644
@@ -65,6 +65,8 @@ static void setup(void)
 	SAFE_CLOSEDIR(dir);
 
 	SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
+	SAFE_FILE_PRINTF("/proc/sys/vm/compact_memory", "1");
+
 	if (tst_available_mem() < (long long)hpage_size) {
 		g_hpage_path[0] = '\0';
 		tst_brk(TCONF, "No enough memory for gigantic hugepage reservation");
Signature · 5 lines
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw
In reply to Li Wang

ping~

If nobody objects to these two simple improvements, I would push both the next day.

Quoted 30 lines · Li Wang

As Martin pointed that mem caches count as available, we'd better release them for huge page use.

---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c +1 -0
index 36a426a09..76b790a95 100644
@@ -64,6 +64,7 @@ static void setup(void)
 
        SAFE_CLOSEDIR(dir);
 
+       SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
        if (tst_available_mem() < (long long)hpage_size) {
                g_hpage_path[0] = '\0';
                tst_brk(TCONF, "No enough memory for gigantic hugepage

reservation");
--
2.40.1

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#3 lore raw
Quoted 5 lines · Li Wang

ping~

If nobody objects to these two simple improvements, I would push both the next day.

Both pushed, thanks!

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp