Skip to main content
Welcome guest. | Register | Login | Post

minimizing memory usage

20 replies [Last post]
libervisco's picture
Offline
Joined: 2006-05-04

I think my computer is fairly strong. It has a good Athlon XP 2000+ processor. However, the weak point appears to be memory, considering that apparently one needs alot of memory these days to intensively work with modern applications such as for example firefox.

I have 256 MB total of real RAM, but 16 MB of that is allocated to the onboard graphics subsystem (savage) leaving me with 240 MB of overall system memory. Now, when I start my Arch system up and enter even the minimal openbox window manager I still have more than 90% of system memory already taken up basically leaving barely 10% of it for whatever programs I intend to use.

You can imagine that after having alot of tabs open in firefox for a while performance starts to drop dramatically, especially when being in firefox for a while and then switching to another app running in another workspace or vice versa. It sometimes takes more than a minute just to load the application I'm switching to. The suspect, of course, is simply lack of memory and too much disk swapping (which is much slower than memory).

So, does anyone has ideas on how to minimize memory usage and increase performace? Also, do you think that having a too big swap partition (like I have 2 GB of swap) can make a computer fill in the real system memory faster than it should, for whatever reason therefore moving to swap faster? Is it generally good to have a big swap partition anyway, or is it better to stick with standard 512 MB swap partition that seems to be standard?

What is your memory setup and how does it work for you?

Thanks
Daniel

dylunio's picture
Offline
Joined: 2005-12-20

You should check that you don't have any programs that leak memory, so check that the memory usage doesn't increase a lot while your not doing anything. I've had mem leak problems with programs like Amarok in the past.

You should also have a look at what are the main applications that use you memory, by using the top command, and then scrolling using the > and < keys so you get a list of apps in the order of memory usage (Big -> Small). This will give you an idea of what exactly is using your memory.

I've found the best way to help with memory usage is to cut out any fancy desktop monitors etc. which can use memory, I tend to use the much lighter tormso monitor on my desktop which seems fast and not to slow things down.

I have 502MB of memory (I don't know where the other 10MB went, but I think it's due to some electrical faults). I seem to run well with 1004MB swap, and Fluxbox WM. Though I try to keep the number of QT apps down, and prefer GTK based apps since they seem faster/use less memory.

Maybe if you have a number of virtual desktops it takes more memory to remember how each one looks (thoug I'm not sure of this), you might want to cut slightly the number of VD's you have.

I hope this helps a bit.

dylunio

libervisco's picture
Offline
Joined: 2006-05-04
Thanks dylunio. I've looked

Thanks dylunio.

I've looked closer to what top shows and here's the general current memory info:

Mem&#58;    239048k total,   233008k used,     6040k free,    14612k buffers
Swap&#58;  1951856k total,   303160k used,  1648696k free,    18440k cached

The biggest memory consumers are firefox (whole 50 MB), X (around 8 to 9MB), mono (3.5 MB), terminal (2.9), Xfce-panel (2.5 MB), krusader (2 MB, I use this often)..

Nothing of the above is really something I can live without.. the firefox is definitely eating up alot. I wonder if it is normal or firefox still has memory issues.

The mono above is required by tomboy, a great wiki-like notes program that I find very useful..

Something is still strange here though, the sum of all of the above ends up at around 85MB and the rest shown in top can't amount to much more than 5 or 10 MB at best, so where did the rest almost 150 MB go? Can memory be just lost somewhere in bits not shown by top or I'm missing something...

Thanks

tbuitenh's picture
Offline
Joined: 2005-12-21

Firefox has a reputation for being full of memory leaks. Use a session saving extension, and restart firefox when things get slow. I don't have that problem with my 512MB abyss, though.

There's a really neat version of top called htop.

Offline
Joined: 2005-12-20

I don't really understand memory leaks, what are they?

tbuitenh's picture
Offline
Joined: 2005-12-21
Okay, here comes an ascii
Okay, here comes an ascii art explanation.

A program creates a new object, for which some memory is allocated&#58;

pointer1 -&gt; &#91;memoryA&#93;

In many cases, it's useful to have multiple pointers to the same bit of memory&#58;

pointer1 -&gt; &#91;memoryA&#93;
pointer2 -----^

For this reason, memory is often not deallocated when a pointer is &#40;re&#41;moved&#58;

pointer1 -&gt; &#91;memoryB&#93;
pointer2 -&gt; &#91;memoryA&#93;

If there is a mistake in the program, you might end up in a situation like this&#58;

pointer1 -&gt; &#91;memoryB&#93;
pointer2 -&gt; &#91;memoryC&#93;
            &#91;memoryA&#93;

There is no pointer to memoryA anymore, so there is no way the program can find it and deallocate it. Repeat this a few times, and the program will use more and more memory for nothing. It happens much more easily than you would think, because there can also be situations like this&#58;

pointer1 -&gt; &#91;pointer2&#93;
                  '-&gt; &#91;memory&#93;

&#40;memory is allowed to contain pointers to more memory...&#41;

There are ways to undo the effects of memory leaks, such tree-walking garbage collection &#40;periodically following all pointers from a starting point, marking all the pieces of memory that are found, then deallocating all unmarked memory&#41; or reference counters &#40;adding a counter containing the number of pointers to each piece of memory, dellocating it if the counter reaches zero&#41;.

Tree walking takes a lot of time. Reference counters don't always work, because this might happen&#58;

   .-----------------v
&#91;pointer1&#58; 1&#93;  &#91;pointer2&#58; 1&#93;
    ^---------------'

Some languages clean up memory for the programmer &#40;Java&#58; treewalking, python&#58; reference counting&#41;. Others &#40;c, c++&#41; expect the programmer to do it. It's a tradeoff&#58; do you want to be limited to better programmers, or get slower software?

Offline
Joined: 2005-12-20

Ah, that is great, thanks tbuitneh

supermike's picture
Offline
Joined: 2006-02-17

I have a huge swap on my Ubuntu system because I don't have enough RAM yet. I don't use swap partitions, but use a swap file instead. I also, just in case, have bounceswap.sh and bounceweb.sh scripts that I created that drop and restart my swapfile and apache/postgresql at 4am every morning. This helps with performance. But I noticed that bounceswap.sh doesn't run properly if I have a lot of apps open -- I have to shut them down at night, which I do.

libervisco's picture
Offline
Joined: 2006-05-04

It seems to be mostly firefox's fault. I guess I'll just be restarting it more often.

I tried htop and it's awesome. I'll use that instead of top from now on. Thanks for suggesting it Taco. Also thanks for the explanation on memory leaks. Smiling

supermike: That's a rather interesting setup. Isn't it less reliable to use swap files instead of fixed swap partitions though?

supermike's picture
Offline
Joined: 2006-02-17

It's hard to add a swap partition after you've built a system. Unfortunately in Ubuntu's installer, when you tell it to do a custom partition, and you define /home in a separate partition, and /boot in another, and then the rest (/) in the final partition, if you don't go back to redefine one more partition for /swap, you'll discover that it doesn't warn you. In fact, I found after the fact on a separate system that in Ubuntu's installer, in the custom partition section, if you define / in slightly less space, then go back to allocate another partition, it AUTOMATICALLY puts in /swap for you out of assumption once you have put /boot and /home and / somewhere else and have available disk space. But if, instead, you direct it to use all the rest of the space on /, you won't get a swap file and Ubuntu's installer won't remind you.

Therefore, I had no choice after I built my system (without a lot of pain), to create a swapfile. Besides, I like the fact that I can load and unload my swap file on a whim and its speeds up my system from time to time.

Now is it slower? No, not really. I used to have Fedora before Ubuntu, and it had a /swap partition before I blew my hard drive away and redid it. When I was working in those days, sure, I was on an earlier kernel, but I didn't notice that much difference in speed.

I probably should go to ReiserFS instead of EXT3 for even more speed, but that may come on another day. I wonder why Ubuntu doesn't use this by default yet? (Perhaps they do in Dapper Dan.)

Offline
Joined: 2006-01-31

"The X server has to be the biggest program I've ever seen that doesn't do anything for you."
--Kenneth Thompson, co-creator of Unix

Simple: don't use X. Wink

libervisco's picture
Offline
Joined: 2006-05-04

Heh I missed that last post here. Quite funny. Laughing out loud

I don't agree though it doesn't do anything for you. It draws all those pretty graphics, right? Eye

Anyway, I got another little question about memory stuff. Is it possible to clear swap memory when you see there's no use for it, like when top or htop shows you that some swap is used while there's still space left within real memory?

Is that even safe?

Thanks

tbuitenh's picture
Offline
Joined: 2005-12-21
"libervisco" wrote:

Anyway, I got another little question about memory stuff. Is it possible to clear swap memory when you see there's no use for it, like when top or htop shows you that some swap is used while there's still space left within real memory?

Why would you want to do that? It will get moved back into real memory as soon as it's needed. Swap isn't used in the same way as real memory, if data in swap needs to be accessed it's moved into real memory first, and if real memory is full, the swap data is swapped with real memory data that hasn't been used for a while. That's why it's called swap.

libervisco's picture
Offline
Joined: 2006-05-04

Ah I must have had a wrong picture about swap memory and how it works (should read more on that).

It's not a big deal anyway actually. GNOME 2.14 is impressive. It doesn't seem to be any slower and consuming than my openbox with xfce4-panel. Smiling

What about clearing unused pockets of memory though or anything that may be hanging there while it really shouldn't?

Offline
Joined: 2005-12-20

You could always think of using gnome with openbox, I did that once and it was really quite fast, as well as having libs and things open, so the gnome apps run quite speedily

libervisco's picture
Offline
Joined: 2006-05-04

Yeah, that crossed my mind. I like it integrated the way it is now though, but I might replace metacity with openbox at some point (when I maybe get bored with this). Openbox does have some features I like such as making windows borderless.

But metacity works great too..

Offline
Joined: 2006-03-28

My experience is that swap is only used when the physical memory is full.
I have each 1GB.
What really fills up memory is disk operation. Linux likes to utilize a lot of memory as disk cache.
I have just booted a couple of minutes ago, only launched KDE and Konqueror (with 5 tabs right now) and 8% of my physical memory is used as disk cache. Another 8 percent are application memory. That leaves around 82% free, around 820MB.
I think the best thing for you would be upgrading your memory to at least 512MB, so that swapping isn't necessary so soon and so much.
When you transfer what I'm currently running (only KDE and Konqueror) to your mem-config there would be around 40MB left. Most propably this would mean that for the next application you start you need to swap out some stuff.
You could say you have just enough memory for the WM and one program.

By the way, a couple of days I tried to compile Pixie (the open-source renderman-implementation) and it failed because of a lack of memory, although I already added 2GB of extra swap-space. Meaning that this monster eats up more than 4GB of memory while being compiled.

As I said, my experience is that swap is only used when necessary. I really need to do quite a lot before swap is used. Before that usually the disk-cache (which after a while really gets quite big) is reduced.

[Edit]And what, as far as I observe, really reduced memory-usage, was replacing Slackware with LFS. My memory is really a lot more relaxed that it was with Slackware.

libervisco's picture
Offline
Joined: 2006-05-04
"reptiler" wrote:

I think the best thing for you would be upgrading your memory to at least 512MB, so that swapping isn't necessary so soon and so much.

I agree. That's definitely on the agenda for when I'm gonna have enough money to put into that too.

"reptiler" wrote:

You could say you have just enough memory for the WM and one program.

Well, that still depends on which WM or DE I use, but in GNOME 2.14 I can actually have around three extra programs open without swapping, like for example nautilus (one window or so open), firefox (but with only few tabs) and xchat.

"reptiler" wrote:

By the way, a couple of days I tried to compile Pixie (the open-source renderman-implementation) and it failed because of a lack of memory, although I already added 2GB of extra swap-space. Meaning that this monster eats up more than 4GB of memory while being compiled.

Wow, that's really monstrous!

I also have 2GB dedicated as swap memory, though most of the time only little of it is actually used (not that it doesn't slow down when it starts to swap considerably). The biggest memory hog so far for me has still been firefox. I've also noticed konqueror tends to be pretty heavy compared to even nautilus, but only firefox needs to be actually restarted sometimes to get it back to speed.

Offline
Joined: 2005-12-20

No, i didnt mean just use gnome with metacity, I mean, you can use an WM with the gnome de, with the simple command:
openbox --replace
fluxbox --replace

that sort of thing, then save session when yoou leave

libervisco's picture
Offline
Joined: 2006-05-04
"onlinebacon" wrote:

No, i didnt mean just use gnome with metacity, I mean, you can use an WM with the gnome de, with the simple command:
openbox --replace
fluxbox --replace

that sort of thing, then save session when yoou leave

Yeah, I got that actually.. maybe I phrazed my post badly. Thanks though! Smiling

Offline
Joined: 2005-12-20

Ah, sorry, could have been me too Smiling

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.