Downloading files=shrinking memory

Posted:
in Genius Bar edited January 2014
If I watch the 'Free Memory' read-out in Activity Monitor while I am downloading a large file I can see the memory dropping!



It looks like an amount of RAM equal to the file size of the file being downloaded is used up...



Quitting Safari does not recover the actual RAM lost, but deleting the downloaded file seems to.



DL a 60MB file and 60MB of RAM is lost.

Trash that file and 60MB of RAM is added to the "Free" memory reading in Activity Monitor.



This can't be an efficient use of memory...



10.4.9 PPC

Titanium PB 1Ghz/1GB

Comments

  • Reply 1 of 9
    lundylundy Posts: 4,466member
    I'm guessing that Safari assumes you will want to execute or load any file that you download, so it memory-maps it using the VM.



    Free memory is wasted memory. You do not want free memory.
  • Reply 2 of 9
    timmmytimmmy Posts: 68member
    I generally like to avoid having the free memory go to low, because then things start paging out and that means disk thrashing and slow down.



    Say I have 250MB free and I need to download a 300MB file. The free memory will gradually drop as the file is downloaded and then the pageouts will start - menus take a second or two to drop down and things get generally unpleasant....
  • Reply 3 of 9
    karl kuehnkarl kuehn Posts: 756member
    This is one of those cases where you don't understand what "free memory" means. Unless you really understand how the unix model of memory management works, then you will misunderstand it, like you are in this case.



    "Free" memory is not a good thing. "Free" memory is wasted. Unless you really understand that idea, ignore what you see as you don't understand what it means. This is normal and good behavior.
  • Reply 4 of 9
    timmmytimmmy Posts: 68member
    OK, I am willing to accept that I have been misinterpreting the memory readings



    But, are you also saying that it is good to have system slowdowns which seem to be related to pageouts (which seems to happen when the free memory gets very low)?
  • Reply 5 of 9
    lundylundy Posts: 4,466member
    It will only page out if the page is dirty, i.e. written to since it was allocated. Those pages of the downloaded file shouldn't be dirty, so if you see paging activity it should be something getting paged in.
  • Reply 6 of 9
    1337_5l4xx0r1337_5l4xx0r Posts: 1,558member
    What these guys are trying to say is that OS X has a very advanced memory management model, that works not by freeing memory but rather using it to it's fullest extent. Having very little 'free' memory is not cause for alarm. Excessive paging is, however, and if that's the case consider buying more ram.



    Freaking out over how little 'free' memory is left in OS X is a classic n00b mistake. OS X aggressively caches files read from the harddisk (as ram is exponentially faster) or downloaded from the net, but it frees those caches when that ram is needed for something else (say, photoshop).



    In essence, you can think of ram used for caching as being free, just put to use while waiting for something else to do.



    My harddisk gets about 37MB/sec, but my ram gets about 10GB/sec in a Macbook Pro. You can see the advantage of filling RAM as much as possible, especially for frequently accessed files.
  • Reply 7 of 9
    timmmytimmmy Posts: 68member
    Quote:
    Originally Posted by 1337_5L4Xx0R View Post


    What these guys are trying to say is that OS X has a very advanced memory management model, that works not by freeing memory but rather using it to it's fullest extent. Having very little 'free' memory is not cause for alarm. Excessive paging is, however, and if that's the case consider buying more ram.



    Well, my Titanium G4 PB is maxed out with 1GB of RAM.



    Perhaps I *am* freaking out and acting like a noob, but the scenario that I am seeing is always the same... Pageouts only seem to happen when Free Memory gets very very low.

    It seems to be that proper memory management would be to take some memory space from real RAM instead of pagingout...
  • Reply 8 of 9
    tankgunktankgunk Posts: 43member
    I want to take a shot at this...maybe you will get the concept.



    OS X doesn't like "free memory", because it isn't being used for anything. And if it isn't being used, it is wasted as a resource.



    So, OS X puts recently/commonly used files there untill there is a good use for that memory. When files are put in ram, you get a significant speed increase when you use them. Memory filled with cached files is just as ready to be used as "free memory".



    If you, for example, opened up photoshop, OS X would dump some of those files so that photoshop would have memory to work with. Just because you have no "free memory" doesn't mean that future memory use will go directly to the page file.





    In short, you shouldn't bother with "free memory". You should look at your page file's size.



    Quote:
    Originally Posted by Timmmy View Post


    Well, my Titanium G4 PB is maxed out with 1GB of RAM....



    Why are you worried about a "problem" you can't sove. Reminds me of myself...
  • Reply 9 of 9
    hirohiro Posts: 2,663member
    Quote:
    Originally Posted by Timmmy View Post


    Well, my Titanium G4 PB is maxed out with 1GB of RAM.



    Perhaps I *am* freaking out and acting like a noob, but the scenario that I am seeing is always the same... Pageouts only seem to happen when Free Memory gets very very low.

    It seems to be that proper memory management would be to take some memory space from real RAM instead of pagingout...



    That last sentence is completely incoherent. OS X only pages out when it needs to, which means there less than 10% of available RAM that isn't already used. That means both free and inactive lists are nearly zeroed out AND you have enough currently running applications with a collective memory requirement approaching that 90% of RAM used threshold. So the pageouts are happening EXACTLY when they are supposed to! Not a second earlier!



    Why? Some of those apps you are using may not have run in the immediate past, so the OS pages them out and then puts those backed-up RAM pages on the inactive list, not the free list. Then new memory requests will be fed by free list and if the free list goes below 10% some of the inactive will be converted to free.



    If you download a file the whole thing is read into RAM, streamed into the fiile container on disk and then "blessed" as a complete file when downloading is complete. The file will remain file mapped in inactive memory just in case you want to use it. If you delete the file the file mapping is tossed an it all goes to free. If you don't toss the file and don't use it, it will eventually be reclaimed into the free list, but that only happens when it has to, because the system actually needs that RAM, not when you seem to want it to because you like looking at numbers you only partially comprehend.



    This whole thing about waiting to reclaim memory until the 10% threshold is reached is a type of lazy evaluation. That's an actual technical term and gives the advantage of not accidentally throwing something out of RAM too early for no good reason.



    In summary, you aren't paging out because of those files you downloaded unless the pageout is happening during the actual download. Once the download is complete and the file is saved, OS X will fearlessly reclaim that RAM if it needs it, but not before. And that RAM will be fully reclaimed before the OS begins paging active memory out, since paging is a VERY expensive operation in comparison to the lazy evaluation of the free/inactive lists.



    I also hope you aren't talking about page-ins at all. That is a meaningless number unless you are doing some very carefully controlled benchmarking and/or performance comparisons. Like engineering quality research which we know you aren't doing.
Sign In or Register to comment.