From 70eeedff7c588c0de85b6df561bb4683fb71e28a Mon Sep 17 00:00:00 2001
From: Qingqing Li <liqingqing3@huawei.com>
Date: Wed, 20 Nov 2024 14:43:42 +0800
Subject: [PATCH] try to enable system thp ability when LD_HUGEPAGE_LIB=2

---
 elf/dl-load.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 063548ac..6c2eec09 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -75,6 +75,7 @@ struct filebuf
 #include <dl-prop.h>
 #include <not-cancel.h>
 #ifdef HUGEPAGE_SHARED_LIB
+#include <sys/prctl.h>
 #include <dl-map-segments-hugepage.h>
 #endif
 
@@ -1310,6 +1311,12 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
 	(GLRO(dl_hugepage_mask) & DL_HUGEPAGE_LIB_THP_IN_FLAG) ||
             ((GLRO(dl_hugepage_mask) & DL_HUGEPAGE_PROBE_FLAG) && use_hugepage))
       {
+	/* try to enable thp manually */
+	if (GLRO(dl_hugepage_mask) & DL_HUGEPAGE_LIB_THP_IN_FLAG)
+	  {
+	    (void)prctl(PR_SET_THP_DISABLE, 0, 0, 0, 0);
+	  }
+
         _llvm_ld_relro_hp_fallback(phdr, relro_ph, l, hp_bitmap);
         errstring = _dl_map_segments_largein (l, fd, header, type, loadcmds, nloadcmds,
             maplength, hp_bitmap);
-- 
2.27.0

