summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch65
-rw-r--r--meta/recipes-devtools/rpm/rpm_4.14.2.bb1
2 files changed, 66 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch b/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch
new file mode 100644
index 0000000000..6454785254
--- /dev/null
+++ b/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch
@@ -0,0 +1,65 @@
1From 0066b862bb3a09f39295abd5d972a53ac8dc1555 Mon Sep 17 00:00:00 2001
2From: Peter Bergin <peter@berginkonsult.se>
3Date: Wed, 19 Sep 2018 15:12:31 +0200
4Subject: [PATCH] rpm/rpmio.c: restrict virtual memory usage if limit set
5
6A solution to avoid OOM situation when the virtual memory is restricted
7for a user (ulimit -v). As the lzopen_internal function is run in parallel
8one instance per CPU thread the available virtual memory is limited per
9CPU thread.
10
11Upstream-Status: Pending [merge of multithreading patches to upstream]
12
13Signed-off-by: Peter Bergin <peter@berginkonsult.se>
14---
15 rpmio/rpmio.c | 34 ++++++++++++++++++++++++++++++++++
16 1 file changed, 34 insertions(+)
17
18diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c
19index e051c98..b3c56b6 100644
20--- a/rpmio/rpmio.c
21+++ b/rpmio/rpmio.c
22@@ -845,6 +845,40 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz)
23 }
24 #endif
25
26+ struct rlimit virtual_memory;
27+ getrlimit(RLIMIT_AS, &virtual_memory);
28+ if (virtual_memory.rlim_cur != RLIM_INFINITY) {
29+ const uint64_t virtual_memlimit = virtual_memory.rlim_cur;
30+ const uint64_t virtual_memlimit_per_cpu_thread =
31+ virtual_memlimit / lzma_cputhreads();
32+ uint64_t memory_usage_virt;
33+ rpmlog(RPMLOG_NOTICE, "XZ: virtual memory restricted to %lu and "
34+ "per CPU thread %lu\n", virtual_memlimit, virtual_memlimit_per_cpu_thread);
35+ /* keep reducing the number of compression threads until memory
36+ usage falls below the limit per CPU thread*/
37+ while ((memory_usage_virt = lzma_stream_encoder_mt_memusage(&mt_options)) >
38+ virtual_memlimit_per_cpu_thread) {
39+ /* If number of threads goes down to zero lzma_stream_encoder will
40+ * will return UINT64_MAX. We must check here to avoid an infinite loop.
41+ * If we get into situation that one thread requires more virtual memory
42+ * than available we set one thread, print error message and try anyway. */
43+ if (--mt_options.threads == 0) {
44+ mt_options.threads = 1;
45+ rpmlog(RPMLOG_WARNING,
46+ "XZ: Could not adjust number of threads to get below "
47+ "virtual memory limit %lu. usage %lu\n",
48+ virtual_memlimit_per_cpu_thread, memory_usage_virt);
49+ break;
50+ }
51+ }
52+ if (threads != (int)mt_options.threads)
53+ rpmlog(RPMLOG_NOTICE,
54+ "XZ: Adjusted the number of threads from %d to %d to not "
55+ "exceed the memory usage limit of %lu bytes\n",
56+ threads, mt_options.threads, virtual_memlimit);
57+
58+ }
59+
60 ret = lzma_stream_encoder_mt(&lzfile->strm, &mt_options);
61 }
62 #endif
63--
642.7.4
65
diff --git a/meta/recipes-devtools/rpm/rpm_4.14.2.bb b/meta/recipes-devtools/rpm/rpm_4.14.2.bb
index 46f88375ff..200fe4da26 100644
--- a/meta/recipes-devtools/rpm/rpm_4.14.2.bb
+++ b/meta/recipes-devtools/rpm/rpm_4.14.2.bb
@@ -39,6 +39,7 @@ SRC_URI = "git://github.com/rpm-software-management/rpm;branch=rpm-4.14.x \
39 file://0003-rpmstrpool.c-make-operations-over-string-pools-threa.patch \ 39 file://0003-rpmstrpool.c-make-operations-over-string-pools-threa.patch \
40 file://0004-build-pack.c-remove-static-local-variables-from-buil.patch \ 40 file://0004-build-pack.c-remove-static-local-variables-from-buil.patch \
41 file://0001-perl-disable-auto-reqs.patch \ 41 file://0001-perl-disable-auto-reqs.patch \
42 file://0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch \
42 " 43 "
43 44
44PE = "1" 45PE = "1"