diff options
| -rw-r--r-- | meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch | 25 |
1 files changed, 14 insertions, 11 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 index 6454785254..dc3f74fecd 100644 --- 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 | |||
| @@ -11,36 +11,39 @@ CPU thread. | |||
| 11 | Upstream-Status: Pending [merge of multithreading patches to upstream] | 11 | Upstream-Status: Pending [merge of multithreading patches to upstream] |
| 12 | 12 | ||
| 13 | Signed-off-by: Peter Bergin <peter@berginkonsult.se> | 13 | Signed-off-by: Peter Bergin <peter@berginkonsult.se> |
| 14 | Signed-off-by: Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com> | ||
| 14 | --- | 15 | --- |
| 15 | rpmio/rpmio.c | 34 ++++++++++++++++++++++++++++++++++ | 16 | rpmio/rpmio.c | 36 ++++++++++++++++++++++++++++++++++++ |
| 16 | 1 file changed, 34 insertions(+) | 17 | 1 file changed, 36 insertions(+) |
| 17 | 18 | ||
| 18 | diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c | 19 | diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c |
| 19 | index e051c98..b3c56b6 100644 | 20 | index e051c98..b3c56b6 100644 |
| 20 | --- a/rpmio/rpmio.c | 21 | --- a/rpmio/rpmio.c |
| 21 | +++ b/rpmio/rpmio.c | 22 | +++ b/rpmio/rpmio.c |
| 22 | @@ -845,6 +845,40 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) | 23 | @@ -845,6 +845,42 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) |
| 23 | } | 24 | } |
| 24 | #endif | 25 | #endif |
| 25 | 26 | ||
| 26 | + struct rlimit virtual_memory; | 27 | + struct rlimit virtual_memory = {RLIM_INFINITY , RLIM_INFINITY}; |
| 27 | + getrlimit(RLIMIT_AS, &virtual_memory); | 28 | + int status = getrlimit(RLIMIT_AS, &virtual_memory); |
| 28 | + if (virtual_memory.rlim_cur != RLIM_INFINITY) { | 29 | + if ((status != -1) && (virtual_memory.rlim_cur != RLIM_INFINITY)) { |
| 29 | + const uint64_t virtual_memlimit = virtual_memory.rlim_cur; | 30 | + const uint64_t virtual_memlimit = virtual_memory.rlim_cur; |
| 31 | + uint32_t threads_max = lzma_cputhreads(); | ||
| 30 | + const uint64_t virtual_memlimit_per_cpu_thread = | 32 | + const uint64_t virtual_memlimit_per_cpu_thread = |
| 31 | + virtual_memlimit / lzma_cputhreads(); | 33 | + virtual_memlimit / ((threads_max == 0) ? 1 : threads_max); |
| 32 | + uint64_t memory_usage_virt; | ||
| 33 | + rpmlog(RPMLOG_NOTICE, "XZ: virtual memory restricted to %lu and " | 34 | + rpmlog(RPMLOG_NOTICE, "XZ: virtual memory restricted to %lu and " |
| 34 | + "per CPU thread %lu\n", virtual_memlimit, virtual_memlimit_per_cpu_thread); | 35 | + "per CPU thread %lu\n", virtual_memlimit, virtual_memlimit_per_cpu_thread); |
| 36 | + uint64_t memory_usage_virt; | ||
| 35 | + /* keep reducing the number of compression threads until memory | 37 | + /* keep reducing the number of compression threads until memory |
| 36 | + usage falls below the limit per CPU thread*/ | 38 | + usage falls below the limit per CPU thread*/ |
| 37 | + while ((memory_usage_virt = lzma_stream_encoder_mt_memusage(&mt_options)) > | 39 | + while ((memory_usage_virt = lzma_stream_encoder_mt_memusage(&mt_options)) > |
| 38 | + virtual_memlimit_per_cpu_thread) { | 40 | + virtual_memlimit_per_cpu_thread) { |
| 39 | + /* If number of threads goes down to zero lzma_stream_encoder will | 41 | + /* If number of threads goes down to zero or in case of any other error |
| 40 | + * will return UINT64_MAX. We must check here to avoid an infinite loop. | 42 | + * lzma_stream_encoder_mt_memusage will return UINT64_MAX. We must check |
| 43 | + * for both the cases here to avoid an infinite loop. | ||
| 41 | + * If we get into situation that one thread requires more virtual memory | 44 | + * 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. */ | 45 | + * than available we set one thread, print error message and try anyway. */ |
| 43 | + if (--mt_options.threads == 0) { | 46 | + if ((--mt_options.threads == 0) || (memory_usage_virt == UINT64_MAX)) { |
| 44 | + mt_options.threads = 1; | 47 | + mt_options.threads = 1; |
| 45 | + rpmlog(RPMLOG_WARNING, | 48 | + rpmlog(RPMLOG_WARNING, |
| 46 | + "XZ: Could not adjust number of threads to get below " | 49 | + "XZ: Could not adjust number of threads to get below " |
