Slashdot Mirror


Understanding Memory Usage On Linux

Percy_Blakeney writes "Have you ever wondered why a simple text editor on Linux can use dozens of megabytes of memory? A recent blog posting explains how the output of the ps tool is misleading and how you can get a better idea of how much memory a process really uses."

14 of 248 comments (clear)

  1. The only thing running by 0xABADC0DA · · Score: 4, Insightful

    Try statically linking a program that uses just a few glibc calls and it's pushing 800k. Now add in libc++, Qt/gtk, Xlib, kde, boost, xml, etc and you're talking a lot of memory. This is what gets me about people who say "well Java performs okay now, but it uses so much memory".

    A typical C/C++ based app uses just as much memory, it's just shared between processes. And for that matter, startup time of the first thing using kde/gnome isn't all that great either. Isn't it about time some effort was put into making Java or Mono part of the system, so it can be shared like C apps do?

    1. Re:The only thing running by CyricZ · · Score: 3, Insightful

      What do you mean, making it "part of the system"? Are you suggesting that they be embedded within the Linux or BSD kernels, for instance? I would hope not, because for serious use that is a recipe for disaster.

      Part of the problem with Java is that each VM has traditionally had its own copy of the Java class library. When you consider how huge the standard library is these days for Java, it's no wonder that even a small Java program consumes so much memory. And running several programs, each duplicating data from the others, is wasteful.

      Apple has had for years a JVM that shares classes between numerous virtual machine instances. It thus reduces unnecessary memory consumption.

      --
      Cyric Zndovzny at your service.
    2. Re:The only thing running by mi · · Score: 2, Insightful
      Update your knowledge. Java has concurrent GCs now that do not freeze the entire VM while being run.
      The latest 1.4.2 still freezes the entire VM. I support a Java application for a living -- keep your evangelism to newbies...

      May be, 1.5 will bring some wonderful improvements in this area, but so far it, apparently, has not -- see another response to your posting.

      And I've never seen the GC go "out of whack" and hang permanently (though I've seen many apps do this due to poor thread/resource management).
      Of course, anything GC does is triggered by the application, and some apps are better than others with resource management.

      But the "you need not worry about memory management" was one of the top items in Java evangelism, and now the 'net is full of advice on how to manage memory in Java to avoid GC-related problems. Oops.

      Some developers, though, continue to believe that "don't worry" hype. Hard to blame them, because without it, there are even fewer advantages to Java.

      --
      In Soviet Washington the swamp drains you.
  2. Re:My own favorite is 'top'. by bumby · · Score: 5, Insightful

    ...no process is using more than 10% of the available resources...

    But hey, 10 processes are using 10%...

    --
    Hey! That's my sig you're smoking there!
  3. man page update by suso · · Score: 4, Insightful

    How about going one step further than just blogging about it and actually submitting a documentation update to the ps man page. That way future confusion of the ps output could be avoided. Of course I guess people have to actually read the man page (In honor of slashdot, I didn't read it before posting this comment ;-)

  4. Re:Before you start bitch about Firefox memory lea by Anonymous Coward · · Score: 5, Insightful

    Typical Slashdot response, blame the users for the browser's bloat. 99% of the users of Firefox are not programmers and wouldn't have the slightest clue what is going on. They just want to look at porn without popups or getting infected with spyware via IE's ActiveX vulnerabilities. Asking them to download some script, set environment variables, and then file bug reports is unrealistic since most of them can't even tell the difference between a web browser and a web site. That's what beta testers are supposed to be doing but we all know that 90% of the beta testers never bother to file any bug reports, even when the browser crashes.

  5. Forgot to mention startup times... by soboroff · · Score: 2, Insightful

    All those shared libraries are also part of the reason that KDE and GNOME can take so long to start up, and why more memory and a higher-RPM hard disk can speed things up. It does make me laugh sometimes that Emacs is now one of Linux's fastest-starting desktop apps.

  6. Re:My own favorite is 'top'. by Splab · · Score: 5, Insightful

    Top will show you the same as ps does, ps calls /proc//statm and asks whats going on. The problem on linux is the copy on write principle wich saves heaps of memmory, but makes it virtually impossible to figure out what belongs to what. The thing is, when you fork it maps the memmory and marks everything as copy on write, when something needs to write to part of the memmory, then it will make the copy for each process.
    However asking the process how much memory it has allocated will show all memory including stuff that is marked copy on write - that is, I could have 100 processes showing they each use 1.4MB of memory, because they all share the same libray, but in fact, its the same copy they are all using so I'm only using 1.4 MB instead of 140MB (+PCB et. al)

  7. A practical measure and perspective. by twitter · · Score: 2, Insightful
    Using the pmap -d trick gives some insight but the amount of swap space used is what actually slows down system response. The author notes that a user who mostly runs either KDE or Gnome will pay a greater marginal cost for running the one Gnome or KDE application that's different. That's true, but it's also hard to avoid and it often does not matter, even on a modest system with 256 MB RAM. You would think that running konqueror, kontact, gimp and gnumeric on Enlightenment or Window Maker would suck down resources. It does, but it might not be enough to get you into swap space. Just run top and see. A low resource window manager can use fewer resources than a full Gnome or KDE Window Manager, despite the magic of shared libraries. DSL and Feather GNU Linux distributions run on P1s because they come with very low resource programs, which may or may not share many libraries. A little swap use does not hurt, but things get slow when too much gets in there.

    The whole discussion should be grounded in the reality of alternatives. A typical M$ system will grind it's way into swap space on start up, before the user loads anything! The very latest and greatest Linux distros run well on Pentium IIs and the like, which XP refuses to install on.

    --

    Friends don't help friends install M$ junk.

    1. Re:A practical measure and perspective. by Lussarn · · Score: 2, Insightful

      Sure, I've been running both Linux and Windows for quite some time. And I've NEVER encountered a 1 minut swap session after closing an application in Linux. On windows it happens everyday if I run a big program like a new game (As thats what I have windows for).

      I can only imagine those swap sessions on a 233Mhz machine. Linux does handle memory way better.

  8. Re:My own favorite is 'top'. by diegocgteleline.es · · Score: 3, Insightful

    Is not that there's not a perfect tool, the problem is that it's a problem which is impossible to solve properly as I see it

    Take a shared library. For whatever reason, process 1 uses only the first half of the library. Thanks to demand-loading, only that half is loaded in mem, and that's what accounts as RSS for that process, say 10 MB.

    Now a process 2 is launched and it uses the other half of the library. Now, all the library is loading in memory, and even if the first process is not using and has not requested to use the second half, its RSS will grown because somebody else use other parts of the library.

    I don't think it's something you can or want to "solve": That's a consequence of the design ideas behind shared libraries. Deal with it.

  9. Re:Extra, extra, read all about it by lasindi · · Score: 5, Insightful

    So, people don't know how to interpret the output of ps? And that's a Slashdot frontpage story?

    Slashdot isn't only about breaking tech news; it's about keeping geeks generally informed. Many Linux geeks (including myself) probably learned something from the article that they didn't know. It's a well-written, informative article, and I'm glad Slashdot posted it because otherwise I probably would have never seen it. Not every Slashdotter already knows everything there is to know about Linux like you apparently do, and I imagine this isn't quite "common knowledge," so it's helpful for some of us.

    What have I done wrong in my settings to deserve such trivial items?

    No one forced you to click on "Read More." Sorry that you wasted a couple seconds reading the summary and realizing you already knew all about ps, but you didn't need to waste even more of your time trolling.

    --
    I have discovered a truly remarkable proof of this theorem that this sig is too small to contain.
  10. Also applies to shared memory segments by AtariDatacenter · · Score: 2, Insightful

    Because there is nothing quite like seeing you've got 20 Oracle instances at 1gb each on a 4gb box. :)

  11. Aren't they still resource hogs? by dzfoo · · Score: 2, Insightful

    >> Have you ever wondered why a simple text editor on Linux can use dozens of megabytes of memory?

    Correct me if I'm wrong but... doesn't the fact that KEdit uses a lot of libraries that consume resources and impact system performance -- whether shared or not -- still means that it is a hog? I mean, if a seemingly simple application is consuming "dozens of megabytes of memory", saying "oh, it's OK, because most of it is being shared and already commited", does not really excuse it. What if those libraries are not currently being used by any other process?

    In order for the shared memory to lessen the impact on the system, the user must be running some other processes that share the same libraries. This to me is a *BIG*, and unwarranted, assumption by the developer, as evidenced by his example of someone running the Gnome environment but running a single KDE application.

          -dZ.

    --
    Carol vs. Ghost
    ...Can you save Christmas?