Does Memory Management Suck or What?

jzdziarski

Registered
I'm somewhat unfamiliar with how OSX deals with memory. In most *nixes, when an application exits, the entire process image (including all allocated memory) are unlinked completely and returned back to the operating system. I've noticed OSX seems to act more like windows, however, and when you quit an application the pages never get removed - they're just part of the "inactive" memory pool.

I realized this after upgrading my powerbook to 2GB of RAM, thinking I was running low. I can reboot now and have almost 90% of the memory free, play a game of UT2004, and only a mere 30% or so will be free after that - the rest "inactive". I can think of a number of reasons having inactive pages just sitting in memory would be a bad thing, so why does OSX seem to do this? Or is this whole thing one huge bug that needs to get sorted out in Tiger?

Finally, are there any tools someone can recommend that will flush inactive memory?

Jonathan
 
1. I'm somewhat unfamiliar with how OSX deals with memory. In most *nixes, when an application exits, the entire process image (including all allocated memory) are unlinked completely and returned back to the operating system. I've noticed OSX seems to act more like windows, however, and when you quit an application the pages never get removed - they're just part of the "inactive" memory pool.

2. I realized this after upgrading my powerbook to 2GB of RAM, thinking I was running low. I can reboot now and have almost 90% of the memory free, play a game of UT2004, and only a mere 30% or so will be free after that - the rest "inactive". I can think of a number of reasons having inactive pages just sitting in memory would be a bad thing, so why does OSX seem to do this? Or is this whole thing one huge bug that needs to get sorted out in Tiger?

3. Finally, are there any tools someone can recommend that will flush inactive memory?
1. Having things in inactive memory is to your advantage. OS X is predicting that [i.e., allowing for the idea that] your next request for instructions is likely to come from certain recently accessed instructions. There is ... [not necessarily a] problem in having a low amount of free memory in OS X. OS X has stored many instructions in RAM (in its file system buffer cache) and in inactive memory. Doing both means better performance [i.e., less disk/VM usage]--[assuming that one has no evidence of a physical RAM shortage].

EDIT: Given the intensity of this discussion and what had been said before I posted originally, I edited the above comments to make precise some things I was assuming implicitly when I first posted.


2. There are no reasons that having inactive memory are bad. Inactive is as good, and often better than, free from an operating perspective. Restarting to free memory is a mistake. Doing so will purge the file system buffer cache, as well as inactive memory and, thus, decrease performance.

3. You don't want to do that unless you want slower performance.[/quote]
 
use panther. it's perfect. memory management was something to tell people about - it WAS macos. it was why macos X was so good. in tiger, its just SO poor. it is like windows, you're right! i hope they don't think this is how it should be from now on....
 
1. Having things in inactive memory is to your advantage. OS X is predicting that your next request for instructions is likely to come from certain recently accessed instructions. There is no problem in having a low amount of free memory in OS X. OS X has stored many instructions in RAM (in its file system buffer cache) and in inactive memory. Doing both means better performance--less disk access.


It's not a good thing. It's a very, very stupid thing. When memory gets full, all of that has to be paged out to make room for the new applications. This takes resources. I suppose this is fine behavior for people who open and close the same applications repeatedly, but let them run Windows. On top of this, I suspect this makes it much easier for a worm or malicious hacker to use a memory scanner and find what they're looking for.

It's bad programming. It's crap like this that makes windows suck on performance as well as philosophy. Stupid move, Apple.
 
Apparently the algorithm needs work. For example, I spend about an hour playing UT2K4 around 6pm or so. I play it exactly once a day, yet OSX keeps all 700MB or so of memory used on the inactive list, when it should be flushed. It also should have flushed out all the programs I don't use after 6pm.

No algorithm is smart enough to manage memory, and if it is, then it takes up too many resources anyway. This should be a preference. I should be able to manage memory how I want. The growing lack of control over OSX is leading me back towards Linux.
 
Here's the thing. If I want to keep apps resident in memory, I'll leave them open. That's one of the beautiful things about OSX is that you can have something like Safari open without actually using it. Adding the overhead of all this post-release memory management is just another annoying operating system feature that eventually just wastes cycles.
 
jzdziarski said:
It's not a good thing. It's a very, very stupid thing. When memory gets full, all of that has to be paged out to make room for the new applications. This takes resources. I suppose this is fine behavior for people who open and close the same applications repeatedly, but let them run Windows. On top of this, I suspect this makes it much easier for a worm or malicious hacker to use a memory scanner and find what they're looking for.

It's bad programming. It's crap like this that makes windows suck on performance as well as philosophy. Stupid move, Apple.

You are in error Grasshopper. Control your vitriol and think how might I be the one that is in error. Leaving out the windows comparisons for clarity...

You are right that keeping dirty pages in memory that have to be written to disk would be bad for performance and reliability reasons. Given this - and the fact that not all people are as dumb as you think - what might you suspect is going on here?

The inactive memory only contains clean pages. The OS then can use these pages to avoid rereading the data from the disk. If a fresh page is needed one of the inactive pages can be instantly zeroed out and used, the disk is never touched. It is very fast and Linux does the same thing.

Have you learned Grasshopper?

;)
 
I think you just have a misunderstanding of the implementation on your Linux system, then. The memory manager there has an active and inactive page cache, just like the Darwin kernel OS X is using. Don't assume that just because you see "227996k free" on a user mode app like top that everything is in the "free list."

I'm still wondering why you think the inactive list is a bad thing. Apps get memory off the list as they need it. It's not expensive to pull it off the list. If you load something huge like that game just once a day, the pages will get flushed out and replaced as they are needed, so there is no real problem. Are you seeing real issues on your box, or are you just irritated that the "Free" list statistic isn't as large as you think it should be?
 
And the overhead of clearing another gig of pages while in the middle of a 3D first person shooter is enough to kill your frame rate.
 
There is effectively no cost to clearing so you need to look elsewhere. The contents of the inactive pages are just forgotten. Blip... gone...

The slowdown is because of whatever just allocated and used all that memory.

It is really comic to hear you go on with this because this is almost the most inexpensive part of the allocation process. Do you know how virtual memory and logical addressing works? Even vaguely?

If so let me know and I will take the time to explain in detail.
 
Yes, being a software developer I think I understand it. Funny how if I reboot before playing, everything runs smooth. On the other hand, if I kill everything after a day of work (including the dashboard), and play, it's jerky. I didn't have this problem in panther.
 
i think i agree with some of what jzdziarski is saying. macos may be very good at managing memory theoretically, but in a real-world environment, there seems to be a very direct link between the two (the problem and the "cause") - it's like the q2dx benchmarking - yes, as fps goes, it is sometimes faster - but i don't see any difference. benchmarks are theory, as is this memory management problem.

i personally can see instability in tiger - it doesn't feel solid or as dependable as panther. panther, IMO was like running a seperate computer for each program - they all seemed to be runnig as fast as each other - simultaneously. i could be rendering an A3, 300dpi inmage in photoshop (huge) and while it was doing that, macos, safari, itunes, all worked as if they were the only programs running. it was as if the pro-app wasn't there, yet the process was still very fast to render. perfect. if the process got too much, and decided to crash (p-shops fault) panther wouldn't faulter - it would stay final. alpha and omega

not in tiger though. i've wanted a way to "flush" the ram, or the caches or whatever ever since upgrading. i now realise these were related
 
Hehehe. You're a programmer jzdziarski? Make a call to malloc() for whatever size buffer you want and tell me if it's zero'ed out. It is not. I really don't think the kernel sits there zeroing out gigs of pages in the inactive pool. It will give your programs whatever memory they ask for and it's up to the individual program to make sure that buffer is clean before using it.

The words "dirty" and "clean" mean different things and I believe we're dealing with 2 different contexts here. If you're talking about a block of memory that's being used or is available to be used, I'd agree with lurk, the inactive pool is "clean" in the sense that it's ready to be used. There's no need to cache that to disk. In fact I've seen each OS have its own "system cache" that's seperate from the memory pool available to running processes. That cache shrinks/grows but it's not one and the same as the inactive figure we're discussing.

Then there's the issue of the actual contents of the memory buffers, and like I said, it's up to the app developer to make sure the buffers are clean before his app goes to use it.

I think that's where the real slow down is: when the kernel has to manage memory and make distinctions between what is/isn't available to give to apps.
 
Lt Major Burns said:
use panther. it's perfect. memory management was something to tell people about - it WAS macos. it was why macos X was so good. in tiger, its just SO poor. it is like windows, you're right! i hope they don't think this is how it should be from now on....

Panther does the same thing so that's not right. And it does speed up application launch for one thing. Open something for the first time after a reboot and then quit. Relaunch it and it'll be faster. This is an advantage and is the reason that the OS does it.
 
jzdziarski said:
Here's the thing. If I want to keep apps resident in memory, I'll leave them open. That's one of the beautiful things about OSX is that you can have something like Safari open without actually using it. Adding the overhead of all this post-release memory management is just another annoying operating system feature that eventually just wastes cycles.

Actually leaving lots of programs open all day will cause potential decrease in performance because THEN they will have to be paged out if you load some memory intensive program.

Inactive memory isn't paged out if the program is closed or quit when you launch some memory intensive program. The OS will release memory when it's needed and page out only programs that are actually open.
 
Back
Top