Saturday, October 29, 2011

Understanding how windows uses RAM - Why you Want Loads of it!

 A history Of Ram Caches, prefetcher and superfetch!
Ever since the dawn of computing random access memory (RAM) has always been a limiting factor, it determines how much information  the cpu can "juggle  in the air" to keep a program open and to display its contents, early on programs were made to fit specific ram requirements (not to mention much earlier you only had around 600kb of base system memory to work with!!) because RAM was never cheap, at around  100$ for 4 megabytes (yes MegaBytes), windows 1.0 came and demanded for more, these where the days where you could only open 2 applications at much, before windows notified you ran out of memory!
 You could only run as many programs that the memory could handle 
these two are too big for the system memory!
you had to close a program in order to open another, such was the computing of old times

Hard Drive space as memory - slow virtual RAM!
When Windows 3.0 was released, microsoft managed to come up with the idea of  moving "unused" data from the physical RAM to the hard drive into a pagefile, so that more precious Ram was available to other programs, of course that meant that if you opened your word processor and then decided to hit paint, the contents in memory related to word, where swapped onto the hard drive, and paint had access to fast Ram. but if you switched back , then the system had to read from the hard drive , or swap out back the information, this in short fooled programs into thinking that a bigger amount of memory was available at all times, and made it possible to multitask.
the same case two programs cant fit into the system memory at same time but...
utilizing the hard drive as virtual memory, you could open as many programs as you wanted
 hard disk can be as 50 times slower than memory, but gets the job done

Introduction of Prefetcher cache   - windows XP is a  10 year OLD operating system
At the release of windows xp (windows 2000) Ram had a price of around 40$ for 128MB , and it was common to see computers with as low as that and up to 512MB.. which was quite a mile stone at the moment, windows xp, had a memory footprint of around 250-400MB (you could tweak it down to 120MB~)and so  virtual memory was still a common thing , if you where lucky to have 1Gig of ram at the time, you hardly ever needed to swap out to the hard disk, and in fact  you could benefit of the new Prefetcher technology, this basically loaded up at startup, any programs  that you frequently used into ram, so that whenever you opened them, they would be already "mounted" and would load up much faster, this of course added a delay at startup due to reading these programs.
 Prefetcher loads up every PROGRAM you use into ram regardless if youre gonna open it or not
its good to cache PROGRAMS but most times windows became slow due to using 
the page file  as well making windows take longer to boot up (hourglass lol)

Introduction of SuperFetch cache- its better because its super.. but it fails BIG TIME!
Microsoft Released Windows Vista in july 2005, with an even bigger memory footprint of around 750-1200Mb of ram to run smooth, memory prices for ram where of around 40$ for  512MB, so it was not so hard to have 1GB or more in your system at the time, a lot of windows Vista hate, comes from the fact that people insisted on using it on old hardware with 512MB or less of system memory, which forced the system to swap out heavily to the hard drive, microsoft was far too optimistic with its release, expecting people to have 2gigs of ram or more, they introduced Super Fetch on top of existing prefetcher, (prefetcher and superfetch are actually 2 different "programs" )the innovation comes that  just like prefetcher, superfetch made a list of your programs and files and loaded them up after startup in the "background" to lessen the sluggish startup but it still had some probs...

 prefetcher in action loading up only the usefull PROGRAM files and waiting for the system to go idle
superfetcher starts to slowly load PROGRAMS as well as FILES that you use daily
 unused ram is wasted ram, lets cram all the files you have there!!!
I sure need that huge file i never use mounted in ram! way to go vista!

Why SuperFetch in vista  Failed
the problem with Microsoft Vista's superfetch cache, is that it relies on your daily usage of files to create a list of what should be put onto ram at startup,  Remember that 300Mb video file you viewed two days ago?, yes superfetch loaded it up into ram, for no reason thinking you will use it soon, and the problem persists as such for the few next days until windows vista notices you really dont use the file often, and loads up other most recently used files instead, wasting read cycles off your hard drive, you have no control over what files get loaded, so when it loads up the right files, it does speed up your computing, also whenever a program needs the superfetch ram, windows just releases it for use.

At any point in time a program needs more RAM, superfetch data is
trashed out of the memory, releasing the Ram for use.

Windows 7 Superfetch "2.0" - actually helps if you got loads of ram!
Released on october 2009, windows 7 came into a world of 2-4Gb computers, priced at around 50$ for 2GBof ram, the OS was welcomed as fast and snappier,  with a memory footprint similar to that of windows vista, the operating system fixed several caching failures of Vista, and reworked a lot of the pre caching algorithms, it would no longer load up heaps of useless files into memory, and prioritize system files and other important ones, windows 7 truly is a better operating system if you let it swim in heaps of RAM
 11600 Mb of ram in use by my programs, and 4600 Mb of ram used by superfetch, loade dup in the course of several minutes, so you really dont feel the slowdown reading all those files!

Best Case Scenario 8GB of ram - windows 7 got it right! (kinda)
Operating systems a like have always put a copy of whatever file was just read into memory in order to have it cached, its a well functioning scheme, if you could manage to have infinite ammounts of ram, then at some point you would have everything cached  on ram,  Windows XP improved this with Prefetcher, but people felt it added a huge delay at start up, later in vista super fetch came to push the loading in the background and add superfetch, but then again people could tell windows kept reading the hard drive at alltime trying to predict the users usage.

Windows 7 managed to tweak the caching scheme  in such way that it doesnt bog you down at startup.. loading up in the idle  seconds right after boot, to slowly load your prefered applications, that is prefetchers work, and then after a little while, very slowly superfetcher loads up the files that you normaly use, the algorithim is good enough to NOT load up  big 200 500mb video files.

We can use a program like Sysinternals  Ram Map to verify this, loading it up in this example you can see my computer just as i booted it up, the memory area marked as "in use" is of course the memory that windows has allocated for its working open procceses, the  area that says "in standby" is whatever prefetcher and superfetch think i will use .

windows 7 resource monitor right after a fresh start
ram map, showing that mostly system files are cached into ram and standby memory


I then prooceed to load up a memory heavy game like APB reloaded , after about 30 minutes of gameplay this is how it looks like


 the increase of the "in use" ram signifies the resources APB took over (1.8 GB) also note now superfetcher loaded around 2 gigs of PROGRAMS and FILES it thinks i might use and open

 as you can see with RamMap we can see that it loaded up a lot of the game,
a few put there by having been read, and others by superfetch algorithm

This example is by far the best case scenario for windows 7 caching scheme, even if i manage to use and fill 6 gb of ram with my program and games, windows still has 2 GB left to use as spare ram for any other program i might use and or for caching favorite files, and indeed if i where to open my explorer which i use often it would load up pretty quickly.

Join me Next post as we improve Windows Caching system even more with a nifty program called Fancycache!till next time :D (caching hard drive sectors!)

26 comments:

  1. Well summarized!! Definitely cleared up some things for me ^_^

    ReplyDelete
  2. Ah, i remember learning about all this stuff in high school and university. Brings back good/bad memories...excuse the pun.

    ReplyDelete
  3. My father could use this information. If only he could understand what he'd be reading.

    ReplyDelete
  4. Yeah, nicely put since Windows 1.0 till 7.0

    ReplyDelete
  5. This reminds me even more I have to buy more RAM for my laptop! Informative post, as usual. I like you original drawings - brings distinguished style and accessible information to the article : )

    ReplyDelete
  6. Very well written thx for the nice info :)

    ReplyDelete
  7. That's quite handy information... Thanks!

    ReplyDelete
  8. I'll double my ram in my next build

    ReplyDelete
  9. Cool tips and information, I know where to come for help if I have problems with my pc!

    ReplyDelete
  10. ive always struggled with the RAM, i never bought enough, now that i got money to get 2GB, its not enough :/

    ReplyDelete
  11. Very cool post! Nothing better than learning something new daily :)

    ReplyDelete
  12. nice post man... working on a server atm that has 256 gb of ram.... is that enough? lol

    ReplyDelete
  13. I've always wondered how RAM worked, thanks for clearing that up.

    ReplyDelete
  14. Very compreensible stuff, keep up the good posts like this one.

    ReplyDelete
  15. You kinda summarized, and pretty well, a whole semester of Operative Systems in my Computer Science course! Well done!

    ReplyDelete
  16. i also need more memory... my son has 8g of ram and i have 512 :(

    ReplyDelete