LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-04-2005, 03:06 PM   #1
ruslan40321
LQ Newbie
 
Registered: Mar 2005
Location: New York
Distribution: Gentoo
Posts: 8

Rep: Reputation: 0
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.
 
Old 09-04-2005, 03:09 PM   #2
Linux~Powered
Member
 
Registered: Jan 2004
Location: /lost+found
Distribution: Slackware 14.2
Posts: 849

Rep: Reputation: 33
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.
 
Old 09-04-2005, 03:25 PM   #3
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
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!
 
Old 09-04-2005, 03:57 PM   #4
ruslan40321
LQ Newbie
 
Registered: Mar 2005
Location: New York
Distribution: Gentoo
Posts: 8

Original Poster
Rep: Reputation: 0
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.
 
Old 09-04-2005, 04:33 PM   #5
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
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?
 
Old 09-04-2005, 06:39 PM   #6
tkedwards
Senior Member
 
Registered: Aug 2004
Location: Munich, Germany
Distribution: Opensuse 11.2
Posts: 1,549

Rep: Reputation: 52
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.
 
Old 09-05-2005, 08:51 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,662
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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.
 
Old 09-28-2005, 03:46 PM   #8
NetRAVEN5000
Member
 
Registered: May 2005
Distribution: Ubuntu 9.04
Posts: 320

Rep: Reputation: 30
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?
 
Old 09-28-2005, 06:13 PM   #9
polypagan
LQ Newbie
 
Registered: Sep 2005
Location: Berea, Kentucky
Distribution: openSUSE
Posts: 22
Blog Entries: 3

Rep: Reputation: 0
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
 
Old 09-28-2005, 07:14 PM   #10
tkedwards
Senior Member
 
Registered: Aug 2004
Location: Munich, Germany
Distribution: Opensuse 11.2
Posts: 1,549

Rep: Reputation: 52
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.
 
Old 09-29-2005, 01:15 AM   #11
J.W.
LQ Veteran
 
Registered: Mar 2003
Location: Boise, ID
Distribution: Mint
Posts: 6,642

Rep: Reputation: 87
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.
 
Old 09-29-2005, 03:54 PM   #12
NetRAVEN5000
Member
 
Registered: May 2005
Distribution: Ubuntu 9.04
Posts: 320

Rep: Reputation: 30
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.
 
Old 09-29-2005, 06:59 PM   #13
tkedwards
Senior Member
 
Registered: Aug 2004
Location: Munich, Germany
Distribution: Opensuse 11.2
Posts: 1,549

Rep: Reputation: 52
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?
 
Old 09-29-2005, 09:32 PM   #14
NetRAVEN5000
Member
 
Registered: May 2005
Distribution: Ubuntu 9.04
Posts: 320

Rep: Reputation: 30
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).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
memory management navaladi Mandriva 2 02-18-2005 06:47 AM
memory management exigent Linux - General 1 08-17-2003 08:28 PM
memory management? snow Linux - Software 7 02-12-2003 01:57 PM
Memory Management hhegab Linux - General 3 08-07-2002 10:20 PM
Memory Management mrsolo Linux - General 7 06-26-2002 12:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration