elf: refactor for ld.so use hugepage
LD_HUGEPAGE_LIB HUGEPAGE_PROBE and LD_DEBUG no longer share GLRO(dl_debug_mask) remove use-mlock-to-determine-hugepage-RLIMIT_MEMLOCK-soft-.patch Signed-off-by: lvying6 <lvying6@huawei.com>
This commit is contained in:
parent
6599b8835b
commit
98bfe82501
@ -1,4 +1,4 @@
|
||||
From 0e86566343057fc021a6d82fe2b6be8651e51b3e Mon Sep 17 00:00:00 2001
|
||||
From d3a58c218f2c1605499be11a4b3a21f8ef133180 Mon Sep 17 00:00:00 2001
|
||||
From: Lv Ying <lvying6@huawei.com>
|
||||
Date: Mon, 7 Mar 2022 03:28:33 +0000
|
||||
Subject: [PATCH] elf: dynamic linker load shared object use hugepage as much
|
||||
@ -29,11 +29,12 @@ as much as possible. This means:
|
||||
elf/dl-load.c | 38 +++
|
||||
elf/dl-load.h | 16 +
|
||||
elf/dl-map-segments-hugepage.h | 593 +++++++++++++++++++++++++++++++++
|
||||
elf/dl-support.c | 4 +
|
||||
elf/elf.h | 2 +
|
||||
elf/hugepageedit.c | 169 ++++++++++
|
||||
elf/rtld.c | 63 ++++
|
||||
sysdeps/generic/ldsodefs.h | 6 +-
|
||||
12 files changed, 938 insertions(+), 1 deletion(-)
|
||||
sysdeps/generic/ldsodefs.h | 11 +-
|
||||
13 files changed, 947 insertions(+), 1 deletion(-)
|
||||
create mode 100644 elf/dl-map-segments-hugepage.h
|
||||
create mode 100644 elf/hugepageedit.c
|
||||
|
||||
@ -166,7 +167,7 @@ index 31c1c09f..ac70c9ab 100644
|
||||
&& (*current)[1] == 'D' && (*current)[2] == '_')
|
||||
{
|
||||
diff --git a/elf/dl-load.c b/elf/dl-load.c
|
||||
index 0976977f..57d5754e 100644
|
||||
index 0976977f..f4b5c4a7 100644
|
||||
--- a/elf/dl-load.c
|
||||
+++ b/elf/dl-load.c
|
||||
@@ -73,6 +73,9 @@ struct filebuf
|
||||
@ -209,8 +210,8 @@ index 0976977f..57d5754e 100644
|
||||
+#define ERRSTRING_BUF_LEN 1024
|
||||
+ int hp_errcode = 0;
|
||||
+ char hp_buf[ERRSTRING_BUF_LEN];
|
||||
+ if ((GLRO(dl_debug_mask) & DL_HUGEPAGE_LIB_LARGE_IN_FLAG) ||
|
||||
+ ((GLRO(dl_debug_mask) & DL_HUGEPAGE_PROBE_FLAG) && use_hugepage))
|
||||
+ if ((GLRO(dl_hugepage_mask) & DL_HUGEPAGE_LIB_LARGE_IN_FLAG) ||
|
||||
+ ((GLRO(dl_hugepage_mask) & DL_HUGEPAGE_PROBE_FLAG) && use_hugepage))
|
||||
+ {
|
||||
+ errstring = _dl_map_segments_largein (l, fd, header, type, loadcmds, nloadcmds,
|
||||
+ maplength, has_holes);
|
||||
@ -866,6 +867,21 @@ index 00000000..cd7b6d79
|
||||
+
|
||||
+ return errstring;
|
||||
+}
|
||||
diff --git a/elf/dl-support.c b/elf/dl-support.c
|
||||
index d8c06ba7..f6ab2627 100644
|
||||
--- a/elf/dl-support.c
|
||||
+++ b/elf/dl-support.c
|
||||
@@ -166,6 +166,10 @@ size_t _dl_phnum;
|
||||
uint64_t _dl_hwcap;
|
||||
uint64_t _dl_hwcap2;
|
||||
|
||||
+#ifdef HUGEPAGE_SHARED_LIB
|
||||
+int _dl_hugepage_mask;
|
||||
+#endif
|
||||
+
|
||||
/* The value of the FPU control word the kernel will preset in hardware. */
|
||||
fpu_control_t _dl_fpu_control = _FPU_DEFAULT;
|
||||
|
||||
diff --git a/elf/elf.h b/elf/elf.h
|
||||
index 4738dfa2..c5315d1b 100644
|
||||
--- a/elf/elf.h
|
||||
@ -1055,7 +1071,7 @@ index 00000000..14a91a4b
|
||||
+ return exit_status;
|
||||
+}
|
||||
diff --git a/elf/rtld.c b/elf/rtld.c
|
||||
index a8ae8b31..242b47e3 100644
|
||||
index a8ae8b31..85596ee4 100644
|
||||
--- a/elf/rtld.c
|
||||
+++ b/elf/rtld.c
|
||||
@@ -2543,6 +2543,40 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
@ -1090,7 +1106,7 @@ index a8ae8b31..242b47e3 100644
|
||||
+ for (size_t cnt = 0; cnt < nhpopts; ++cnt)
|
||||
+ if (val == hpopts[cnt].option)
|
||||
+ {
|
||||
+ GLRO(dl_debug_mask) |= hpopts[cnt].flag;
|
||||
+ GLRO(dl_hugepage_mask) |= hpopts[cnt].flag;
|
||||
+ break;
|
||||
+ }
|
||||
+}
|
||||
@ -1133,7 +1149,7 @@ index a8ae8b31..242b47e3 100644
|
||||
+#ifdef HUGEPAGE_SHARED_LIB
|
||||
+ if (memcmp (envline, "HUGEPAGE_PROBE", 14) == 0 &&
|
||||
+ envline[15] != '\0')
|
||||
+ GLRO(dl_debug_mask) |= DL_HUGEPAGE_PROBE_FLAG;
|
||||
+ GLRO(dl_hugepage_mask) |= DL_HUGEPAGE_PROBE_FLAG;
|
||||
+#endif
|
||||
+
|
||||
break;
|
||||
@ -1145,9 +1161,9 @@ index a8ae8b31..242b47e3 100644
|
||||
|
||||
+#ifdef HUGEPAGE_SHARED_LIB
|
||||
+ /* LIB_HUGEPAGE_LIB and HUGEPAGE_PROBE are both set. use LIB_HUGEPAGE_LIB */
|
||||
+ if ((GLRO(dl_debug_mask) & DL_HUGEPAGE_PROBE_FLAG) && hugepage_lib_env)
|
||||
+ if ((GLRO(dl_hugepage_mask) & DL_HUGEPAGE_PROBE_FLAG) && hugepage_lib_env)
|
||||
+ {
|
||||
+ GLRO(dl_debug_mask) &= ~DL_HUGEPAGE_PROBE_FLAG;
|
||||
+ GLRO(dl_hugepage_mask) &= ~DL_HUGEPAGE_PROBE_FLAG;
|
||||
+ }
|
||||
+ /* unsetenv LD_HUGEPAGE_LIB, child process should not get this env */
|
||||
+ unsetenv("LD_HUGEPAGE_LIB");
|
||||
@ -1157,7 +1173,7 @@ index a8ae8b31..242b47e3 100644
|
||||
variables. */
|
||||
if (__builtin_expect (__libc_enable_secure, 0))
|
||||
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
|
||||
index a1d70ce7..3328fd9b 100644
|
||||
index a1d70ce7..a9fffd66 100644
|
||||
--- a/sysdeps/generic/ldsodefs.h
|
||||
+++ b/sysdeps/generic/ldsodefs.h
|
||||
@@ -549,7 +549,11 @@ struct rtld_global_ro
|
||||
@ -1173,6 +1189,18 @@ index a1d70ce7..3328fd9b 100644
|
||||
/* OS version. */
|
||||
EXTERN unsigned int _dl_osversion;
|
||||
/* Platform name. */
|
||||
--
|
||||
2.33.0
|
||||
@@ -672,6 +676,11 @@ struct rtld_global_ro
|
||||
platforms. */
|
||||
EXTERN uint64_t _dl_hwcap2;
|
||||
|
||||
+#ifdef HUGEPAGE_SHARED_LIB
|
||||
+ /* Mask for how to use hugepage */
|
||||
+ EXTERN int _dl_hugepage_mask;
|
||||
+#endif
|
||||
+
|
||||
#ifdef SHARED
|
||||
/* We add a function table to _rtld_global which is then used to
|
||||
call the function instead of going through the PLT. The result
|
||||
--
|
||||
2.37.3
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@
|
||||
##############################################################################
|
||||
Name: glibc
|
||||
Version: 2.34
|
||||
Release: 97
|
||||
Release: 98
|
||||
Summary: The GNU libc libraries
|
||||
License: %{all_license}
|
||||
URL: http://www.gnu.org/software/glibc/
|
||||
@ -257,8 +257,7 @@ Patch9017: 0001-elf-dynamic-linker-load-shared-object-use-hugepage-a.patch
|
||||
Patch9018: 0002-elf-ld.so-add-testcase-for-ld.so-load-shared-object-.patch
|
||||
Patch9019: 0003-elf-ld.so-use-special-mmap-for-hugepage-to-get-symbo.patch
|
||||
Patch9020: malloc-use-__get_nprocs-replace-__get_nprocs_sched.patch
|
||||
Patch9021: use-mlock-to-determine-hugepage-RLIMIT_MEMLOCK-soft-.patch
|
||||
Patch9022: x86-use-total-l3cache-for-non_temporal_threshold.patch
|
||||
Patch9021: x86-use-total-l3cache-for-non_temporal_threshold.patch
|
||||
|
||||
Provides: ldconfig rtld(GNU_HASH) bundled(gnulib)
|
||||
|
||||
@ -1417,6 +1416,10 @@ fi
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Sun Oct 10 2022 Lv Ying <lvying6@huawei.com>- 2.34-98
|
||||
- elf: LD_HUGEPAGE_LIB HUGEPAGE_PROBE and LD_DEBUG no longer share GLRO(dl_debug_mask)
|
||||
elf: remove use-mlock-to-determine-hugepage-RLIMIT_MEMLOCK-soft-.patch
|
||||
|
||||
* Sun Oct 9 2022 Zhen Chen <chenzhen126@huawei.com> - 2.34-97
|
||||
- socket: Fix mistyped define statement in socket/sys/socket.h(BZ #29225)
|
||||
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
From 3d68198a71050e5f96df0ac41bb1877e22240717 Mon Sep 17 00:00:00 2001
|
||||
From: Lv Ying <lvying6@huawei.com>
|
||||
Date: Tue, 21 Dec 2021 03:27:07 +0800
|
||||
Subject: [PATCH] use mlock to determine hugepage RLIMIT_MEMLOCK soft resource
|
||||
limit is valid
|
||||
|
||||
Signed-off-by: Lv Ying <lvying6@huawei.com>
|
||||
---
|
||||
elf/dl-load.c | 1 -
|
||||
elf/dl-map-segments-hugepage.h | 23 ++++++++++++++++++++++-
|
||||
2 files changed, 22 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/elf/dl-load.c b/elf/dl-load.c
|
||||
index 1aa77fa2..2691eefa 100644
|
||||
--- a/elf/dl-load.c
|
||||
+++ b/elf/dl-load.c
|
||||
@@ -1219,7 +1219,6 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
|
||||
maplength = loadcmds[nloadcmds - 1].allocend - loadcmds[0].mapstart;
|
||||
|
||||
#ifdef HUGEPAGE_SHARED_LIB
|
||||
-#define ERRSTRING_BUF_LEN 1024
|
||||
int hp_errcode = 0;
|
||||
char hp_buf[ERRSTRING_BUF_LEN];
|
||||
if ((GLRO(dl_debug_mask) & DL_HUGEPAGE_LIB_LARGE_IN_FLAG) ||
|
||||
diff --git a/elf/dl-map-segments-hugepage.h b/elf/dl-map-segments-hugepage.h
|
||||
index 37788ef9..ef36f9ad 100644
|
||||
--- a/elf/dl-map-segments-hugepage.h
|
||||
+++ b/elf/dl-map-segments-hugepage.h
|
||||
@@ -22,6 +22,7 @@
|
||||
#define SIZE_2MB 0x200000
|
||||
#define MASK_2MB 0x1FFFFF
|
||||
#define THRESHOLD 16
|
||||
+#define ERRSTRING_BUF_LEN 1024
|
||||
|
||||
/*
|
||||
* Find the first PT_LOAD segment with execute permission
|
||||
@@ -57,12 +58,32 @@ __mmap_reserved_area(const struct loadcmd loadcmds[], size_t nloadcmds,
|
||||
/*
|
||||
* Get 2MB aligned contiguous va space
|
||||
* This va space can not be munmap in case of multi thread dlopen concurrently
|
||||
+ * the prot can not be PROT_NONE, otherwise mlock always failed
|
||||
*/
|
||||
- void *map_area_start = __mmap(0, *maparealen, PROT_NONE,
|
||||
+ void *map_area_start = __mmap(0, *maparealen, PROT_READ,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB|(SHFIT_2MB << MAP_HUGE_SHIFT), -1, 0);
|
||||
if (__glibc_unlikely (map_area_start == MAP_FAILED))
|
||||
return MAP_FAILED;
|
||||
|
||||
+ /*
|
||||
+ * use mlock to see if hugepage is beyond the RLIMIT_MEMLOCK soft resource limit
|
||||
+ * when hugepage feature is enabled, however cgroup hugetlb.2MB.limit_in_bytes
|
||||
+ * is set 0, subsequent hugepage mmap will return 0, actual page fault will
|
||||
+ * send sigbus to this process
|
||||
+ * the next mmap with MAP_FIXED flag will munlock this area
|
||||
+ */
|
||||
+ int mlock_errcode = 0;
|
||||
+ char mlock_buf[ERRSTRING_BUF_LEN];
|
||||
+ if (mlock(map_area_start, *maparealen) != 0)
|
||||
+ {
|
||||
+ mlock_errcode = errno;
|
||||
+ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
+ _dl_debug_printf("mlock failed: [%lx-%lx) :%s\n", (unsigned long)map_area_start,
|
||||
+ (unsigned long)map_area_start + *maparealen,
|
||||
+ mlock_errcode ? __strerror_r (mlock_errcode, mlock_buf, sizeof mlock_buf) : "");
|
||||
+ goto unmap_reserved_area;
|
||||
+ }
|
||||
+
|
||||
/*
|
||||
* Remap 2MB aligned contiguous va space into 4KB contiguous va space
|
||||
* to avoid the tedious work of splitting hugepage into 4KB page
|
||||
--
|
||||
2.27.0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user