Commit 8093b8b0 authored by Martyn Russell's avatar Martyn Russell

libtracker-common: Re-instate setrlimit()

Previously it was disabled due to GStreamer constantly causing high memory use.

Now we have re-enabled it and instead of a flat 512Mb (or 80Mb for 64bit) limit,
we use 50% of memory capping at MAXLONG (2Gb on 32bit machines) and using
at least 256Mb as a minimum.

This was done to fix my desktop with 4Gb going OOM from a broken PNG file
parent e0beee6c
...@@ -34,17 +34,13 @@ ...@@ -34,17 +34,13 @@
/* Maximum here is a G_MAXLONG, so if you want to use > 2GB, you have /* Maximum here is a G_MAXLONG, so if you want to use > 2GB, you have
* to set MEM_LIMIT to RLIM_INFINITY * to set MEM_LIMIT to RLIM_INFINITY
*/ */
#ifdef __x86_64__ #define MEM_LIMIT_MIN 256 * 1024 * 1024
#define MEM_LIMIT 512 * 1024 * 1024
#else
#define MEM_LIMIT 80 * 1024 * 1024
#endif
#if defined(__OpenBSD__) && !defined(RLIMIT_AS) #if defined(__OpenBSD__) && !defined(RLIMIT_AS)
#define RLIMIT_AS RLIMIT_DATA #define RLIMIT_AS RLIMIT_DATA
#endif #endif
#define DISABLE_MEM_LIMITS #undef DISABLE_MEM_LIMITS
gboolean gboolean
tracker_spawn (gchar **argv, tracker_spawn (gchar **argv,
...@@ -280,12 +276,16 @@ gboolean ...@@ -280,12 +276,16 @@ gboolean
tracker_memory_setrlimits (void) tracker_memory_setrlimits (void)
{ {
#ifndef DISABLE_MEM_LIMITS #ifndef DISABLE_MEM_LIMITS
struct rlimit rl; struct rlimit rl = { 0 };
glong total; glong total;
glong limit; glong total_halfed;
glong limit;
total = get_memory_total (); total = get_memory_total ();
limit = CLAMP (MEM_LIMIT, 0, total); total_halfed = total / 2;
/* Clamp memory between 50% of total and MAXLONG (2Gb) */
limit = CLAMP (total_halfed, MEM_LIMIT_MIN, G_MAXLONG);
/* We want to limit the max virtual memory /* We want to limit the max virtual memory
* most extractors use mmap() so only virtual memory can be * most extractors use mmap() so only virtual memory can be
...@@ -318,9 +318,8 @@ tracker_memory_setrlimits (void) ...@@ -318,9 +318,8 @@ tracker_memory_setrlimits (void)
str1 = g_format_size_for_display (total); str1 = g_format_size_for_display (total);
str2 = g_format_size_for_display (limit); str2 = g_format_size_for_display (limit);
g_message ("Setting memory limitations: total is %s, virtual/heap set to %s", g_message ("Setting memory limitations: total is %s, minimum is 256 MB, recommended is ~1 GB", str1);
str1, g_message (" Virtual/Heap set to %s (50%% of total or MAXLONG)", str2);
str2);
g_free (str2); g_free (str2);
g_free (str1); g_free (str1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment