Bug 104338

Summary: Need to limit memory usage
Product: [Applications] konqueror Reporter: Aaron Williams <aaronw>
Component: nspluginviewerAssignee: George Staikos <staikos>
Status: RESOLVED FIXED    
Severity: wishlist CC: lisaelimarie, Marcin.Kasperski
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Aaron Williams 2005-04-21 20:12:15 UTC
Version:           unknown (using KDE 3.4.0 Level "b" , SUSE 9.3 UNSUPPORTED)
Compiler:          gcc version 3.3.5 20050117 (prerelease) (SUSE Linux)
OS:                Linux (i686) release 2.6.11.4-20a-athlon-preempt

One of the plugins running suddenly consumed all available memory (over 1.1GB!) causing my system to swap like crazy.  I don't know which plugin caused the problem, or even if I can reproduce it, but it would be a good feature if nspluginviewer could limit the amount of memory it is allowed to use, similar to how it can run at a nice CPU level.

I would much rather have nspluginviewer crash due to a buggy plugin than take down the whole machine.
Comment 1 George Staikos 2005-05-19 16:37:51 UTC
SVN commit 415756 by staikos:

add support for memory limits with hidden config variable.  I may add a
UI option if and when I receive positive feedback that this code works.
I haven't tested it.
FEATURE: 104338


 M  +11 -0     trunk/KDE/kdebase/nsplugins/viewer/viewer.cpp  


--- trunk/KDE/kdebase/nsplugins/viewer/viewer.cpp #415755:415756
@@ -37,6 +37,8 @@
 #include <qptrlist.h>
 #include <qsocketnotifier.h>
 #include <stdlib.h>
+#include <sys/resource.h>
+#include <sys/time.h>
 #include <unistd.h>
 
 #ifdef Bool
@@ -249,6 +251,15 @@
       if (v > 0) {
          nice(v);
       }
+      v = cfg.readNumEntry("Max Memory", 0);
+      if (v > 0) {
+         rlimit rl;
+         memset(&rl, 0, sizeof(rl));
+         if (0 == getrlimit(RLIMIT_AS, &rl)) {
+            rl.rlim_cur = kMin(v, int(rl.rlim_max));
+            setrlimit(RLIMIT_AS, &rl);
+         }
+      }
    }
 
    // initialize the dcop client
Comment 2 George Staikos 2005-05-31 01:20:46 UTC
*** Bug 106507 has been marked as a duplicate of this bug. ***
Comment 3 Marcel Partap 2008-01-26 23:13:49 UTC
Hey George, I see this nice little setting is still in the 4SVN source.. you might think about that visible config option because my guess is noone ever found this ;)