LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Why such horrible memory management? (https://www.linuxquestions.org/questions/linux-general-1/why-such-horrible-memory-management-360160/)

ruslan40321 09-04-2005 03:06 PM

Why such horrible memory management?
 
Hello. I am not new to Linux I was using it as my primary OS for about 4 years, and although I already learned a lot, I still could not understand one thing. Why does Linux not free up memory? I know this is not a memory leak, because it happened every time I installed Linux (even on different distros), and it is not a hardware problem because it happens on all computers where I installed Linux throughout 3 years. For example, now I am using a computer with the following specifications: Intel P4 3.0Ghz, 1Gb RAM. I compiled my own Gentoo (newest). Why is it when I boot up into KDE, my mem usage is 175mb, and after using some programs - opera, konqueror, gaim, tuxracer, etc, i close them, but my memory usage stays at ~960mb! Why is this? I looked at the memory diagram in KDE, and it says memory is used for disk buffers? How do I free it up? Why doesnt it automatically go down after I am done using these applications? Is there a kernel patch or a daemon that can do this for me? I view my mem usage by the following applications: KDE information, top, cat /proc/meminfo, and a superkaramba applet. Please explain wat is going on and tell me how I fight this issue? cuz b4 i had 256mb and memory didnt go higher than 240mb, now i got 1 gig and it goes to 940.. so what if i get 4 gb will it be used at 3900mb? is there such thing as "enough" memory for linux or am i doing something wrong?? thank you.

Linux~Powered 09-04-2005 03:09 PM

Linux uses memory like that. Why would you want your memory wiped out if you closed one of those programs only to have to reload it back into memory when you want to use it again? It's faster and makes use of your memory. Why have all that memory if you're not going to use it? It's fine.

Komakino 09-04-2005 03:25 PM

Linux-Powered is right. Just because it's not shown as free doesn't mean it isn't available. Try running a large KDE based app once and see how long it takes, then close it and open it again. It will load much faster the second time!

ruslan40321 09-04-2005 03:57 PM

oh so ur saying that in real life it is free but only reserved? and so if i use an pplication the next time it will just use the reserved area of mem that shows up as used? ok maybe that is a good feature. thanks. but is there any way that I can see exactly how much of the mem is being used by apps at the moment (excluding the reserved memory)? Cuz the thing is, i used to think 256 or 512 megs is not enough for linux because it always showed it as used memory, so i bought 1 gig and i was surprised to see that it showed it as used up. so is 1 gig enough for linux? or should i buy more? thanks a lot for ur answers.

Komakino 09-04-2005 04:33 PM

Quote:

Originally posted by ruslan40321
oh so ur saying that in real life it is free but only reserved? and so if i use an pplication the next time it will just use the reserved area of mem that shows up as used? ok maybe that is a good feature. thanks. but is there any way that I can see exactly how much of the mem is being used by apps at the moment (excluding the reserved memory)? Cuz the thing is, i used to think 256 or 512 megs is not enough for linux because it always showed it as used memory, so i bought 1 gig and i was surprised to see that it showed it as used up. so is 1 gig enough for linux? or should i buy more? thanks a lot for ur answers.
I have 256MB and I find that to be enough. Everything still runs fine and I play UT at 1024x768 res with no probs. I just don't worry about the amount of free memory. As long as stuff works, why concern yourself with it?

tkedwards 09-04-2005 06:39 PM

Quote:

oh so ur saying that in real life it is free but only reserved? and so if i use an pplication the next time it will just use the reserved area of mem that shows up as used? ok maybe that is a good feature. thanks.
The Linux kernel uses available memory to cache the most used files off the disk. It can be instantly made available for use by applications because it doesn't matter if it gets overwritten - the kernel will just fall back to reading that file off the disk next time its accessed. So you can think of any memory that's in the cache like this as 'free' or 'available'.

Quote:

but is there any way that I can see exactly how much of the mem is being used by apps at the moment (excluding the reserved memory)?
Code:

free -m
Look in the +/- buffers cache column. Also I believe the GNOME system monitor reports memory usage minus the cache as well.

Quote:

Cuz the thing is, i used to think 256 or 512 megs is not enough for linux because it always showed it as used memory, so i bought 1 gig and i was surprised to see that it showed it as used up. so is 1 gig enough for linux? or should i buy more? thanks a lot for ur answers.
8MB or less would probably be enough for a cut-down Linux in an embedded system so it depends what you're using it for wether 1GB is enough. But for most gamers or desktop uses I'd say 1GB is plenty.

sundialsvcs 09-05-2005 08:51 AM

Linux does this, and recent Windows versions do it, too: ever noticed that a program starts much faster the second time you run it in the space of a few minutes?

When a program finishes executing, and absent any other memory-pressures, Linux will happily be "lazy." Why rush to free-up memory when there's no demand to do so? Won't do any good, and may even be bad: maybe you'll want to use the same data again, soon. The odds are quite good... so why throw it away just to get it right back?

Buffers are the lowest-priority use of memory... cacheing recently-used information in an area that is otherwise not being used. When new demands for memory arise, the buffers are among the first to go.

Linux wants to keep all RAM full at all times, if it can. After all, "it's there, it's free, it's faster than anything else, so why not use it?"

What you want to watch out for is swapping. It's fine for a certain amount of swap-space to be used, but when "swaps per second" starts going up and staying up, it's a sign of memory contention.

NetRAVEN5000 09-28-2005 03:46 PM

Can you force it to clear the cache?
 
Just wondering. . . is there any way to FORCE it to clear the cache (ie any commands you can type or anything)? I left my computer on overnight, and I was surfing the Web last night after playing some DOOM 3 online. Today when I played it I noticed it was a lot choppier. I guess it's possible I was just really, really laggy but I don't think so. . . anyways, is there a way to clean this cache out?

polypagan 09-28-2005 06:13 PM

Thanks for this thread
 
I learned a bit about what I have been observing on my own machines using Linux.

I have DamnSmall 1.4 on an IBM thinkpad with 24 MB of RAM! It has (and uses) a swap partition, but I can run Firefox and a bunch of other stuff all at once. It ain't exactly fast, but much more usable than it ever was with win95!

Damn Small has that nice asmem tool, from afterstep, I think. It shows memory usage in different colors for programs and cache as well as swap usage.

It looks a lot different on my Dell Inspiron 1100 with 512 MB (no swap). I have a bunch of stuff open and it says 85% available! WinXP really lags on this machine, but maybe that's 'cause it lacks hdparm!

I am loving linux. I have a lot to learn and I thank you all for the discussion.

Daniel

tkedwards 09-28-2005 07:14 PM

There's no point trying to clear the disk cache - as soon as a program starts up memory is cleared from the disk cache and given to that program. Your problems are caused by something else or some other aspect of memory management.

J.W. 09-29-2005 01:15 AM

There's a very informative article by Sapphirecat that does a nice job explaining how Linux memory management works, and why it appears that so much RAM is typically "in use" -- J.W.

NetRAVEN5000 09-29-2005 03:54 PM

Quote:

Originally posted by tkedwards
There's no point trying to clear the disk cache - as soon as a program starts up memory is cleared from the disk cache and given to that program. Your problems are caused by something else or some other aspect of memory management.
I did just recompile my kernel and then my network card didn't work, maybe I enabled something that slowed the kernel down a bit when I tried to make it work (I definitely added support for some cards I don't have). Or maybe the graphics settings are too high.

tkedwards 09-29-2005 06:59 PM

Quote:

I did just recompile my kernel and then my network card didn't work, maybe I enabled something that slowed the kernel down a bit when I tried to make it work
Yeah most distro makers do a fair bit of research and have a fair bit of experience in knowing what options to enable when they build their kernel. Do the problems happen with the latest verison of the kernel from your distro maker?

NetRAVEN5000 09-29-2005 09:32 PM

Quote:

Originally posted by tkedwards
Yeah most distro makers do a fair bit of research and have a fair bit of experience in knowing what options to enable when they build their kernel. Do the problems happen with the latest verison of the kernel from your distro maker?
Yes. I think my NIC's kind of an odd one, though - the option is in there for the kernel, but for both Slack 10.1 and Slack 10.2 it wasn't enabled in the 2.6.x packages, although it was enabled in the 2.4.x kernel packages. Maybe it's because 2.4 is the one installed by default and 2.6 is more "try it at your own risk" and is meant for newer technology (even though my PC is less than 1 year old, the NIC I've used in the two PCs I used before this one).


All times are GMT -5. The time now is 09:48 PM.