use mlock to determine hugepage RLIMIT_MEMLOCK soft resource limit is valid
Signed-off-by: Lv Ying <lvying6@huawei.com> (cherry picked from commit e2b1c096a33d8130e739a6800ebae38db80a6346)
This commit is contained in:
parent
cd7af16a04
commit
3579b038ab
@ -66,7 +66,7 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
Name: glibc
|
Name: glibc
|
||||||
Version: 2.34
|
Version: 2.34
|
||||||
Release: 71
|
Release: 72
|
||||||
Summary: The GNU libc libraries
|
Summary: The GNU libc libraries
|
||||||
License: %{all_license}
|
License: %{all_license}
|
||||||
URL: http://www.gnu.org/software/glibc/
|
URL: http://www.gnu.org/software/glibc/
|
||||||
@ -229,6 +229,7 @@ Patch9016: 0001-elf-dynamic-linker-load-shared-object-use-hugepage-a.patch
|
|||||||
Patch9017: 0002-elf-ld.so-add-testcase-for-ld.so-load-shared-object-.patch
|
Patch9017: 0002-elf-ld.so-add-testcase-for-ld.so-load-shared-object-.patch
|
||||||
Patch9018: 0003-elf-ld.so-use-special-mmap-for-hugepage-to-get-symbo.patch
|
Patch9018: 0003-elf-ld.so-use-special-mmap-for-hugepage-to-get-symbo.patch
|
||||||
Patch9019: malloc-use-__get_nprocs-replace-__get_nprocs_sched.patch
|
Patch9019: malloc-use-__get_nprocs-replace-__get_nprocs_sched.patch
|
||||||
|
Patch9020: use-mlock-to-determine-hugepage-RLIMIT_MEMLOCK-soft-.patch
|
||||||
|
|
||||||
Obsoletes: nscd < 2.35
|
Obsoletes: nscd < 2.35
|
||||||
Provides: ldconfig rtld(GNU_HASH) bundled(gnulib)
|
Provides: ldconfig rtld(GNU_HASH) bundled(gnulib)
|
||||||
@ -1300,6 +1301,9 @@ fi
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Mar 30 2022 Lv Ying <lvying6@huawei.com> - 2.34-72
|
||||||
|
- use mlock to determine hugepage RLIMIT_MEMLOCK soft resource limit is valid
|
||||||
|
|
||||||
* Tue Mar 29 2022 Yang Yanchao <yangyanchao@huawei.com> - 2.34-71
|
* Tue Mar 29 2022 Yang Yanchao <yangyanchao@huawei.com> - 2.34-71
|
||||||
- mv libc.info.gz* to the package glibc-help
|
- mv libc.info.gz* to the package glibc-help
|
||||||
|
|
||||||
|
|||||||
73
use-mlock-to-determine-hugepage-RLIMIT_MEMLOCK-soft-.patch
Normal file
73
use-mlock-to-determine-hugepage-RLIMIT_MEMLOCK-soft-.patch
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
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