commit ab7296331e49dd7f90c07c0c5562bcfd7265056a Author: overweight <5324761+overweight@user.noreply.gitee.com> Date: Mon Sep 30 10:56:32 2019 -0400 Package init diff --git a/0000-build_flags.patch b/0000-build_flags.patch new file mode 100644 index 0000000..19eced7 --- /dev/null +++ b/0000-build_flags.patch @@ -0,0 +1,13 @@ +--- libhugetlbfs-2.20/tests/Makefile 2018-04-10 02:00:33.613966578 +0200 ++++ libhugetlbfs-2.20/tests/Makefile 2015-12-04 03:04:07.000000000 +0100 +@@ -33,8 +33,8 @@ + HELPER_LIBS = libheapshrink.so + BADTOOLCHAIN = bad-toolchain.sh + +-CFLAGS = -O2 -Wall -g +-CPPFLAGS = -I.. ++CFLAGS ?= -O2 -Wall -g ++CPPFLAGS += -I.. + STATIC_LIBHUGE = -Wl,--whole-archive -lhugetlbfs -Wl,--no-whole-archive + STATIC_LDLIBS = -Wl,--no-as-needed -lpthread + LDLIBS = $(STATIC_LDLIBS) -ldl -lhugetlbfs_privutils diff --git a/0001-libhugetlbfs-2.15-fortify.patch b/0001-libhugetlbfs-2.15-fortify.patch new file mode 100644 index 0000000..8b505d6 --- /dev/null +++ b/0001-libhugetlbfs-2.15-fortify.patch @@ -0,0 +1,13 @@ +diff --git a/Makefile b/Makefile +index 73ebad7..3735440 100644 +--- a/Makefile ++++ b/Makefile +@@ -30,7 +30,7 @@ INSTALL = install + LDFLAGS += -Wl,-z,noexecstack -ldl + CFLAGS ?= -O2 -g + CFLAGS += -Wall -fPIC +-CPPFLAGS += -D__LIBHUGETLBFS__ ++CPPFLAGS += -D__LIBHUGETLBFS__ -DFORTIFY_SOURCE + + ARCH = $(shell uname -m | sed -e s/i.86/i386/) + CC ?= gcc diff --git a/0002-libhugetlbfs-2.16-makefile_cflags.patch b/0002-libhugetlbfs-2.16-makefile_cflags.patch new file mode 100644 index 0000000..de95b12 --- /dev/null +++ b/0002-libhugetlbfs-2.16-makefile_cflags.patch @@ -0,0 +1,12 @@ +diff -up libhugetlbfs-2.16/Makefile.orig libhugetlbfs-2.16/Makefile +--- libhugetlbfs-2.16/Makefile.orig 2014-03-03 12:50:43.408107252 +0100 ++++ libhugetlbfs-2.16/Makefile 2014-03-03 12:52:01.070230134 +0100 +@@ -29,7 +29,7 @@ INSTALL = install + + LDFLAGS += -Wl,-z,noexecstack -ldl + CFLAGS ?= -O2 -g +-CFLAGS += -Wall -fPIC ++CFLAGS += -Wall -fPIC -fstack-protector-strong + CPPFLAGS += -D__LIBHUGETLBFS__ -DFORTIFY_SOURCE + + ARCH = $(shell uname -m | sed -e s/i.86/i386/) diff --git a/0003-fix-behavior-while-shrinking.patch b/0003-fix-behavior-while-shrinking.patch new file mode 100644 index 0000000..051c88d --- /dev/null +++ b/0003-fix-behavior-while-shrinking.patch @@ -0,0 +1,80 @@ +From 26c6b9b99d8f8d7897687a2192be4920a44c1eff Mon Sep 17 00:00:00 2001 +From: Guillaume Morin +Date: Tue, 1 Nov 2016 22:41:22 +0100 +Subject: [PATCH 16/28] fix behavior while shrinking + +Adjust mapsize as we're unmapping pages. Do not lie to glibc about +shrinking by less than a page. It's unnecessary because we are not +giving back any memory to the kernel, but also it forces us to zero +out this memory because morecore() assumes by default that "new" +memory is already zero'd. + +Signed-off-by: Guillaume Morin +Signed-off-by: Eric B Munson +--- + morecore.c | 37 +++++++++++++++++++++++++++---------- + 1 file changed, 27 insertions(+), 10 deletions(-) + +diff --git a/morecore.c b/morecore.c +index 62ad252..6563bbd 100644 +--- a/morecore.c ++++ b/morecore.c +@@ -178,20 +178,37 @@ static void *hugetlbfs_morecore(ptrdiff_t increment) + if (ret) { + WARNING("Unmapping failed while shrinking heap: " + "%s\n", strerror(errno)); +- } else if (!__hugetlb_opts.map_hugetlb && !using_default_pagesize){ +- +- /* +- * Now shrink the hugetlbfs file. +- */ ++ } else { + mapsize += delta; +- ret = ftruncate(heap_fd, mapsize); +- if (ret) { +- WARNING("Could not truncate hugetlbfs file to " +- "shrink heap: %s\n", strerror(errno)); ++ /* ++ * the glibc assumes by default that newly allocated ++ * memory by morecore() will be zeroed. It would be ++ * wasteful to do it for allocation so we only shrink ++ * the top by the size of a page. ++ */ ++ increment = heapbase - heaptop + mapsize; ++ ++ if (!__hugetlb_opts.map_hugetlb && !using_default_pagesize){ ++ ++ /* ++ * Now shrink the hugetlbfs file. ++ */ ++ ret = ftruncate(heap_fd, mapsize); ++ if (ret) { ++ WARNING("Could not truncate hugetlbfs file to " ++ "shrink heap: %s\n", strerror(errno)); ++ } + } + } + + } ++ else if (increment < 0) { ++ /* Don't shrink by less than a page to avoid having to zero ++ * the memory. There is no point in lying to glibc since ++ * we're not freeing any memory. ++ */ ++ increment = 0; ++ } + + /* heap is continuous */ + p = heaptop; +@@ -355,7 +372,7 @@ void hugetlbfs_setup_morecore(void) + /* Set some allocator options more appropriate for hugepages */ + + if (__hugetlb_opts.shrink_ok) +- mallopt(M_TRIM_THRESHOLD, hpage_size / 2); ++ mallopt(M_TRIM_THRESHOLD, hpage_size + hpage_size / 2); + else + mallopt(M_TRIM_THRESHOLD, -1); + mallopt(M_TOP_PAD, hpage_size / 2); +-- +1.8.3.1 + diff --git a/0004-ld.hugetlbfs-pick-an-emulation-if-m-is-not-present.patch b/0004-ld.hugetlbfs-pick-an-emulation-if-m-is-not-present.patch new file mode 100644 index 0000000..4a14a3b --- /dev/null +++ b/0004-ld.hugetlbfs-pick-an-emulation-if-m-is-not-present.patch @@ -0,0 +1,42 @@ +From a979e0b01a76f199974c76c9799b0210562147ec Mon Sep 17 00:00:00 2001 +From: Jan Stancek +Date: Thu, 2 Feb 2017 11:04:08 +0100 +Subject: [PATCH 17/28] ld.hugetlbfs: pick an emulation if -m is not present + +If -m is not passed on command line $EMU ends up empty +and as result HPAGE_SIZE and SLICE_SIZE are left uninitialized. + +Try environment variable LDEMULATION and if it's not defined +pick first from "Supported emulations" list of ld -V. + +Signed-off-by: Jan Stancek +Signed-off-by: Eric B Munson +--- + ld.hugetlbfs | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/ld.hugetlbfs b/ld.hugetlbfs +index 32bc6fb..2dda451 100755 +--- a/ld.hugetlbfs ++++ b/ld.hugetlbfs +@@ -81,6 +81,17 @@ if [ -n "$HTLB_LINK" ]; then + HTLBOPTS="-T${HUGETLB_LDSCRIPT_PATH}/${LDSCRIPT}" + fi + ++# if -m is not present on command line ++if [ -z "$EMU" ]; then ++ if [ -n "$LDEMULATION" ]; then ++ # try env. variable ++ EMU="$LDEMULATION" ++ else ++ # pick first supported ++ EMU="$(ld -V | sed -n '/Supported emulations/{n;p}' | tr -d ' ')" ++ fi ++fi ++ + MB=$((1024*1024)) + case "$EMU" in + elf32ppclinux|elf64ppc) HPAGE_SIZE=$((16*$MB)) SLICE_SIZE=$((256*$MB)) ;; +-- +1.8.3.1 + diff --git a/0005-ld.hugetlbfs-support-512M-hugepages-on-aarch64.patch b/0005-ld.hugetlbfs-support-512M-hugepages-on-aarch64.patch new file mode 100644 index 0000000..7a18ad1 --- /dev/null +++ b/0005-ld.hugetlbfs-support-512M-hugepages-on-aarch64.patch @@ -0,0 +1,44 @@ +From ff12744922d0b13ef0373fb00ca057bb4424da23 Mon Sep 17 00:00:00 2001 +From: Jan Stancek +Date: Wed, 15 Feb 2017 14:10:19 +0100 +Subject: [PATCH 21/28] ld.hugetlbfs: support 512M hugepages on aarch64 + +aarch64 supports multiple hugepage sizes, if default is 512M, +then all linkhuge_rw tests segfault. This patch detects +default huge page size from /proc/meminfo output, rather than +using hardcoded value of 2M. + +Signed-off-by: Jan Stancek +Signed-off-by: Eric B Munson +--- + ld.hugetlbfs | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/ld.hugetlbfs b/ld.hugetlbfs +index 8ee917b..388f7b4 100755 +--- a/ld.hugetlbfs ++++ b/ld.hugetlbfs +@@ -109,7 +109,10 @@ elf32ppclinux|elf64ppc) HPAGE_SIZE=$((16*$MB)) SLICE_SIZE=$((256*$MB)) ;; + elf64lppc) HPAGE_SIZE=$((16*$MB)) SLICE_SIZE=$((256*$MB)) ;; + elf_i386|elf_x86_64) HPAGE_SIZE=$((4*$MB)) SLICE_SIZE=$HPAGE_SIZE ;; + elf_s390|elf64_s390) HPAGE_SIZE=$((1*$MB)) SLICE_SIZE=$HPAGE_SIZE ;; +-armelf*_linux_eabi|aarch64elf*|aarch64linux*) HPAGE_SIZE=$((2*$MB)) SLICE_SIZE=$HPAGE_SIZE ;; ++armelf*_linux_eabi|aarch64elf*|aarch64linux*) ++ hpage_kb=$(cat /proc/meminfo | grep Hugepagesize: | awk '{print $2}') ++ HPAGE_SIZE=$((hpage_kb * 1024)) ++ SLICE_SIZE=$HPAGE_SIZE ;; + esac + + if [ "$HTLB_ALIGN" == "slice" ]; then +@@ -119,7 +122,7 @@ if [ "$HTLB_ALIGN" == "slice" ]; then + # targeting the ARM platform one needs to explicitly set the text segment offset + # otherwise it will be NULL. + case "$EMU" in +- armelf*_linux_eabi) HTLBOPTS="$HTLBOPTS -Ttext-segment=$SLICE_SIZE" ;; ++ armelf*_linux_eabi|aarch64elf*|aarch64linux*) HTLBOPTS="$HTLBOPTS -Ttext-segment=$SLICE_SIZE" ;; + esac + fi + +-- +1.8.3.1 + diff --git a/0006-libhugetlbfs-fix-tests-with-heapshrink-fail.patch b/0006-libhugetlbfs-fix-tests-with-heapshrink-fail.patch new file mode 100644 index 0000000..9f907f0 --- /dev/null +++ b/0006-libhugetlbfs-fix-tests-with-heapshrink-fail.patch @@ -0,0 +1,65 @@ +From e1c5a625a5d82aed84fdd5db0643fb865d21b5bf Mon Sep 17 00:00:00 2001 +From: lihongjiang +Date: Mon, 22 Apr 2019 22:11:55 +0800 +Subject: [PATCH] libhugetlbfs: fix tests with heapshrink fail + +reason:fix tests with heapshrink fail + +Signed-off-by: lihongjiang +--- + tests/heapshrink.c | 12 +++++++++--- + tests/run_tests.py | 2 +- + 2 files changed, 10 insertions(+), 4 deletions(-) + +diff --git a/tests/heapshrink.c b/tests/heapshrink.c +index 0644c78..bd2e62b 100644 +--- a/tests/heapshrink.c ++++ b/tests/heapshrink.c +@@ -34,7 +34,7 @@ + + int main(int argc, char **argv) + { +- int is_huge, have_env, shrink_ok, have_helper; ++ int is_huge, have_env, shrink_ok, have_helper, tcache_enabled; + unsigned long long mapping_size; + void *p; + +@@ -45,6 +45,8 @@ int main(int argc, char **argv) + p = getenv("LD_PRELOAD"); + have_helper = p != NULL && strstr(p, "heapshrink") != NULL; + ++ p=getenv("GLIBC_TUNABLES"); ++ tcache_enabled = p != NULL && strstr(p, "malloc.tcache_count=0"); + p = malloc(SIZE); + if (!p) { + if (shrink_ok && have_helper) { +@@ -68,7 +70,11 @@ int main(int argc, char **argv) + + free(p); + mapping_size = get_mapping_page_size(p+SIZE-1); +- if (shrink_ok && mapping_size > MIN_PAGE_SIZE) +- FAIL("Heap did not shrink"); ++ if (shrink_ok && mapping_size > MIN_PAGE_SIZE) { ++ if (tcache_enabled) ++ FAIL("Heap did not shrink"); ++ else ++ FAIL("Heap didn't shrink. Check malloc.tcache_count=0"); ++ } + PASS(); + } +diff --git a/tests/run_tests.py b/tests/run_tests.py +index 22e74c8..8cc6d43 100755 +--- a/tests/run_tests.py ++++ b/tests/run_tests.py +@@ -575,7 +575,7 @@ def functional_tests(): + HUGETLB_MORECORE="yes") + do_test("heapshrink", LD_PRELOAD="libheapshrink.so", HUGETLB_MORECORE="yes", + HUGETLB_MORECORE_SHRINK="yes") +- do_test("heapshrink", LD_PRELOAD="libhugetlbfs.so libheapshrink.so", ++ do_test("heapshrink", GLIBC_TUNABLES="glibc.malloc.tcache_count=0", LD_PRELOAD="libhugetlbfs.so libheapshrink.so", + HUGETLB_MORECORE="yes", HUGETLB_MORECORE_SHRINK="yes") + do_test("heap-overflow", HUGETLB_VERBOSE="1", HUGETLB_MORECORE="yes") + +-- +1.8.3.1 + diff --git a/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch b/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch new file mode 100644 index 0000000..625296a --- /dev/null +++ b/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch @@ -0,0 +1,42 @@ +diff -Naur libhugetlbfs-2.16/elflink.c libhugetlbfs-2.16.new//elflink.c +--- libhugetlbfs-2.16/elflink.c 2017-11-09 20:30:38.000000000 -0500 ++++ libhugetlbfs-2.16.new//elflink.c 2017-11-09 22:36:56.000000000 -0500 +@@ -1131,7 +1131,10 @@ + start = ALIGN_DOWN((unsigned long)seg[i].vaddr, hpage_size); + offset = (unsigned long)(seg[i].vaddr - start); + mapsize = ALIGN(offset + seg[i].memsz, hpage_size); +- mmap_flags = MAP_SHARED|MAP_FIXED; ++ if(__hugetlb_opts.share_mapping) ++ mmap_flags = MAP_SHARED|MAP_FIXED; ++ else ++ mmap_flags = MAP_PRIVATE|MAP_FIXED; + + /* If requested, make no reservations */ + if (__hugetlb_opts.no_reserve) +diff -Naur libhugetlbfs-2.16/hugeutils.c libhugetlbfs-2.16.new//hugeutils.c +--- libhugetlbfs-2.16/hugeutils.c 2013-03-09 21:59:52.000000000 -0500 ++++ libhugetlbfs-2.16.new//hugeutils.c 2017-11-09 22:36:45.000000000 -0500 +@@ -387,6 +387,12 @@ + env = getenv("HUGETLB_NO_RESERVE"); + if (env && !strcasecmp(env, "yes")) + __hugetlb_opts.no_reserve = true; ++ ++ /* Determine if data segment share memory mapping */ ++ __hugetlb_opts.share_mapping = false; ++ env = getenv("HUGETLB_SHAREMAPPING"); ++ if (env && !strcasecmp(env, "yes")) ++ __hugetlb_opts.share_mapping = true; + } + + void hugetlbfs_setup_kernel_page_size() +diff -Naur libhugetlbfs-2.16/libhugetlbfs_internal.h libhugetlbfs-2.16.new//libhugetlbfs_internal.h +--- libhugetlbfs-2.16/libhugetlbfs_internal.h 2013-03-09 21:59:52.000000000 -0500 ++++ libhugetlbfs-2.16.new//libhugetlbfs_internal.h 2017-11-09 22:35:53.000000000 -0500 +@@ -73,6 +73,7 @@ + char *def_page_size; + char *morecore; + char *heapbase; ++ bool share_mapping; + }; + + /* diff --git a/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch b/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch new file mode 100644 index 0000000..0bee1e7 --- /dev/null +++ b/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch @@ -0,0 +1,31 @@ +From 7c371e7de53554166711e0bcc37df94d0a78edd3 Mon Sep 17 00:00:00 2001 +From: sangyan +Date: Fri, 21 Apr 2017 14:35:03 +0800 +Subject: [PATCH] elflink.c: remap segments with MAP_SHARED flag + +Mmapping segment with MAP_PRIVATE will create a private +copy-on-write mapping, as a result updates to the mapping +will cost extra pages. It will cost double number of pages +in the worst case, so we change to MAP_SHARED flag. + +It is also safe to mmap a unlinked file or a read-only file. +--- + elflink.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/elflink.c b/elflink.c +index b746b26..8187ee0 100644 +--- a/elflink.c ++++ b/elflink.c +@@ -1131,7 +1131,7 @@ static void remap_segments(struct seg_info *seg, int num) + start = ALIGN_DOWN((unsigned long)seg[i].vaddr, hpage_size); + offset = (unsigned long)(seg[i].vaddr - start); + mapsize = ALIGN(offset + seg[i].memsz, hpage_size); +- mmap_flags = MAP_PRIVATE|MAP_FIXED; ++ mmap_flags = MAP_SHARED|MAP_FIXED; + + /* If requested, make no reservations */ + if (__hugetlb_opts.no_reserve) +-- +1.8.3.1 + diff --git a/libhugetlbfs-2.20.tar.gz b/libhugetlbfs-2.20.tar.gz new file mode 100644 index 0000000..29b0046 Binary files /dev/null and b/libhugetlbfs-2.20.tar.gz differ diff --git a/libhugetlbfs.spec b/libhugetlbfs.spec new file mode 100644 index 0000000..d555941 --- /dev/null +++ b/libhugetlbfs.spec @@ -0,0 +1,111 @@ +%global ldscriptdir %{_datadir}/%{name}/ldscripts + +Name: libhugetlbfs +Version: 2.20 +Release: 11 +Summary: A library which provides easy access to huge pages of memory +License: LGPLv2+ +URL: https://github.com/libhugetlbfs/libhugetlbfs +Source0: https://www.mgebm.net/~emunson/%{name}-%{version}.tar.gz + +Patch0000: 0000-build_flags.patch +Patch0001: 0001-libhugetlbfs-2.15-fortify.patch +Patch0002: 0002-libhugetlbfs-2.16-makefile_cflags.patch +Patch0003: 0003-fix-behavior-while-shrinking.patch +Patch0004: 0004-ld.hugetlbfs-pick-an-emulation-if-m-is-not-present.patch +Patch0005: 0005-ld.hugetlbfs-support-512M-hugepages-on-aarch64.patch +Patch0006: 0006-libhugetlbfs-fix-tests-with-heapshrink-fail.patch + +Patch9000:libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch +Patch9001:libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch + +BuildRequires: gcc glibc-devel glibc-static + +%description +The libhugetlbfs package interacts with the Linux hugetlbfs to make large +pages available to applications in a transparent manner.The library also +comes with several userspace tools to help with huge page usability, +environment setup, and control. + +%package devel +Summary: The devel for %{name} +Requires: %{name} = %{version}-%{release} +%description devel +Header files for libhugetlbfs + +%package utils +Summary: The utils for %{name} +Requires: %{name} = %{version}-%{release} +%description utils +Userspace utilities for configuring the hugepage environment + +%package_help + +%prep +%autosetup -n %{name}-%{version} -p1 + +%build +%set_build_flags +make BUILDTYPE=NATIVEONLY + +%install +%make_install PREFIX=%{_prefix} LDSCRIPTDIR=%{ldscriptdir} BUILDTYPE=NATIVEONLY +make install-helper PREFIX=%{_prefix} DESTDIR=$RPM_BUILD_ROOT LDSCRIPTDIR=%{ldscriptdir} BUILDTYPE=NATIVEONLY +mkdir -p -m755 $RPM_BUILD_ROOT%{_sysconfdir}/security/limits.d +touch $RPM_BUILD_ROOT%{_sysconfdir}/security/limits.d/hugepages.conf + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%license LGPL-2.1 +%{_libdir}/libhugetlbfs.so* +%{_datadir}/%{name}/ +%ghost %config(noreplace) %{_sysconfdir}/security/limits.d/hugepages.conf +%exclude %{_libdir}/libhugetlbfs_privutils.so +%exclude %{_libdir}/*.a + +%files devel +%{_includedir}/hugetlbfs.h + +%files utils +%{_bindir}/hugeedit +%{_bindir}/hugeadm +%{_bindir}/hugectl +%{_bindir}/pagesize +%{_bindir}/huge_page_setup_helper.py +%exclude %{_bindir}/cpupcstat +%exclude %{_bindir}/oprofile_map_events.pl +%exclude %{_bindir}/oprofile_start.sh +%exclude %{_libdir}/perl5/TLBC + +%files help +%doc README HOWTO NEWS +%{_mandir}/man1/*.gz +%{_mandir}/man3/*.gz +%{_mandir}/man7/libhugetlbfs.7.gz +%{_mandir}/man8/*.gz + + +%changelog +* Mon Apr 22 2019 lihongjiang - 2.20-11 +- Type:enhancement +- ID:NA +- SUG:restart +- DESC:fix-tests-with-heapshrink-fail + +* Thu Mar 21 2019 lihongjiang - 2.20-10 +- Type:enhancement +- ID:NA +- SUG:restart +- DESC:backport patches + +* Tue Jan 22 2019 xiashuang - 2.20-9 +- Type:enhancement +- ID:NA +- SUG:restart +- DESC:sync patches from 7.3 + +* Sat Jul 18 2018 openEuler Buildteam - 2.20-8 +- Package init