[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Memory usage - default X install can't use yum with 1GB RAM machine



Yesterday James Antill said:

On Thu, 2007-10-11 at 16:26 -0400, sean darcy wrote:
James Antill wrote:
................
 I've attached a simple python script I've used, it's not perfect but it
shows roughly how much dead memory you have and will kind of show where
it is.


Great script. But is rebooting the only answer?

So what it tries to show is how much memory is being "allocated" to
files that no longer exist. This _could_ be a normal thing, but is most
often due to shared libraries that have either been upgraded or changed
via. prelink ... but which are still mapped into another application.

So, yes, the only way to fix that is to "reboot" the application so it
uses the new version of the shared library instead of the old deleted
one. For some applications it's easy enough to just restart them, for
others you might as well just reboot the entire machine.


Yes way cool, James. That script hightlights a bunch of info I've been curious about and too lazy to RTF proc(5). Here's a little patch to make it disclose which processes are sitting on the deleted libs.

--- wasted-ram-updates.py.orig  2007-10-12 09:55:34.000000000 -0700
+++ wasted-ram-updates.py       2007-10-12 10:38:17.000000000 -0700
@@ -13,6 +13,7 @@ def loc_num(x):
     return locale.format("%d", int(x), True)

 pids = []
+cmds = {}
 for d in os.listdir("/proc/"):
     try:
         pid = int(d)
@@ -20,6 +21,14 @@ for d in os.listdir("/proc/"):
     except:
         pass

+def cmdFromPID(pid):
+    """fetch command line from a process id"""
+    try:
+        cmdline= open("/proc/%i/cmdline" %pid).readlines()[0]
+        return " ".join(cmdline.split("\x00")).rstrip()
+    except:
+        return ""
+
 def map_sz(x):
     (beg, end) = x.split('-')
     return (int(end, 16) - int(beg, 16))
@@ -38,10 +47,7 @@ for pid in pids:
         while off < len(lines):
             line = lines[off]
             off += 1
-            try:
-                int(line[0])
-            except:
-                continue
+            if line[0] in ["S", "R", "P"]: continue

             data = line.split(None, 5)
             try:
@@ -59,6 +65,8 @@ for pid in pids:
             if '(deleted)' not in data[5]:
                 continue

+            cmds[pid]= cmdFromPID(pid)
+
             key = "%s:%d" % (data[3], ino)
             if key not in files:
                 files[key] = lambda x: x # Hack
@@ -121,7 +129,9 @@ for x in files.values():
     s_private_dirty += x.s_private_dirty
     referenced      += x.referenced

-    print x.pids, loc_num(x.vsz), x.name,
+    print "%7sKB %s" %(loc_num(x.vsz/1024), x.name),
+    for p in frozenset(x.pids):
+        print "      %5i %s" %(p, cmds[p])
 print "\
 =============================================================================="
 print "num             = %-20s" % loc_num(len(files))

Note that it also attempts to fix a (possible?) bug of missing an address above 2.5GB. Although I dunno the likelyhood of this, the "fix" is neater though.

Thanks!
../C


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]