On 2022/09/20 16:54, Nam Nguyen wrote: > Marc Espie writes: > > > Note that gimp itself has some control over memory used > > under various circumstances in its Preferences. > > > > I haven't seen any indication that authors in this thread > > are even aware those parameters exist. > > Here is a fresh diff providing conservative upper limits for > tile-cache-size and undo-size such that using basic tools won't crash > GIMP and no tweaks are required by the user. There is a MESSAGE to > optionally tweak limits if better performance is desired.
ahhhhhh. defaults are based on this in app/config/gimpgeglconfig.c 133 memory_size = gimp_get_physical_memory_size (); 134 135 /* limit to the amount one process can handle */ 136 memory_size = MIN (GIMP_MAX_MEM_PROCESS, memory_size); 137 138 if (memory_size > 0) 139 memory_size = memory_size / 2; /* half the memory */ 140 else 141 memory_size = 1 << 30; /* 1GB */ 142 143 GIMP_CONFIG_PROP_MEMSIZE (object_class, PROP_TILE_CACHE_SIZE, 144 "tile-cache-size", 145 "Tile cache size", 146 TILE_CACHE_SIZE_BLURB, 147 0, GIMP_MAX_MEM_PROCESS, 148 memory_size, 149 GIMP_PARAM_STATIC_STRINGS | 150 GIMP_CONFIG_PARAM_CONFIRM); and app/config/gimpcoreconfig.c 597 undo_size = gimp_get_physical_memory_size (); 598 599 if (undo_size > 0) 600 undo_size = undo_size / 8; /* 1/8th of the memory */ 601 else 602 undo_size = 1 << 26; /* 64GB */ 603 604 GIMP_CONFIG_PROP_MEMSIZE (object_class, PROP_UNDO_SIZE, 605 "undo-size", 606 "Undo size", 607 UNDO_SIZE_BLURB, 608 0, GIMP_MAX_MEMSIZE, undo_size, 609 GIMP_PARAM_STATIC_STRINGS | 610 GIMP_CONFIG_PARAM_CONFIRM); using this in app/core/gimp-utils.c 77 guint64 78 gimp_get_physical_memory_size (void) 79 { 80 #ifdef G_OS_UNIX 81 #if defined(HAVE_UNISTD_H) && defined(_SC_PHYS_PAGES) && defined (_SC_PAGE_SIZE) 82 return (guint64) sysconf (_SC_PHYS_PAGES) * sysconf (_SC_PAGE_SIZE); 83 #endif 84 #endif So it's the usual "software assumes it has the whole machine" problem, so the crash is easier to hit when you have lots of RAM. I think we should cap that based on rlimit rather than hardcoding to a fixed value in the config file, and probably also set to max like we do in various other programs in base and ports. How about this? Index: Makefile =================================================================== RCS file: /cvs/ports/graphics/gimp/stable/Makefile,v retrieving revision 1.154 diff -u -p -r1.154 Makefile --- Makefile 10 Sep 2022 12:49:22 -0000 1.154 +++ Makefile 21 Sep 2022 11:51:02 -0000 @@ -1,7 +1,7 @@ COMMENT= GNU Image Manipulation Program DISTNAME = gimp-2.10.32 -REVISION = 0 +REVISION = 1 .for i in gimp gimpbase gimpcolor gimpconfig gimpmath gimpmodule \ gimpthumb gimpui gimpwidgets Index: patches/patch-app_core_gimp-utils_c =================================================================== RCS file: patches/patch-app_core_gimp-utils_c diff -N patches/patch-app_core_gimp-utils_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-app_core_gimp-utils_c 21 Sep 2022 11:51:02 -0000 @@ -0,0 +1,29 @@ +cap memory size based on datasize limit; this is used to set the +default values for tile-cache-size (app/config/gimpgeglconfig.c) +and undo-size (app/config/gimpcoreconfig.c) + +Index: app/core/gimp-utils.c +--- app/core/gimp-utils.c.orig ++++ app/core/gimp-utils.c +@@ -17,6 +17,7 @@ + + #include "config.h" + ++#include <sys/resource.h> + #include <errno.h> + #include <stdlib.h> + #include <string.h> +@@ -79,7 +80,12 @@ gimp_get_physical_memory_size (void) + { + #ifdef G_OS_UNIX + #if defined(HAVE_UNISTD_H) && defined(_SC_PHYS_PAGES) && defined (_SC_PAGE_SIZE) +- return (guint64) sysconf (_SC_PHYS_PAGES) * sysconf (_SC_PAGE_SIZE); ++ struct rlimit limit; ++ guint64 mem, rlmem; ++ mem = sysconf (_SC_PHYS_PAGES) * sysconf (_SC_PAGE_SIZE); ++ if (getrlimit(RLIMIT_DATA, &limit) != -1) ++ return (limit.rlim_cur < mem) ? limit.rlim_cur : mem; ++ return mem; + #endif + #endif + Index: patches/patch-app_main_c =================================================================== RCS file: patches/patch-app_main_c diff -N patches/patch-app_main_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-app_main_c 21 Sep 2022 11:51:02 -0000 @@ -0,0 +1,29 @@ +raise datasize rlimit to max + +Index: app/main.c +--- app/main.c.orig ++++ app/main.c +@@ -17,6 +17,7 @@ + + #include "config.h" + ++#include <sys/resource.h> + #include <stdio.h> + #include <stdlib.h> + #include <string.h> +@@ -416,10 +417,15 @@ main (int argc, + GFile *user_gimprc_file = NULL; + gchar *backtrace_file = NULL; + gint i; ++ struct rlimit limit; + + #ifdef ENABLE_WIN32_DEBUG_CONSOLE + gimp_open_console_window (); + #endif ++ if (getrlimit (RLIMIT_DATA, &limit) != -1) { ++ limit.rlim_cur = limit.rlim_max; ++ (void)setrlimit (RLIMIT_DATA, &limit); ++ } + #if defined(ENABLE_RELOCATABLE_RESOURCES) && defined(__APPLE__) + /* remove MacOS session identifier from the command line args */ + gint newargc = 0;