Memory caching in Windows (7)

Started by DeadHead, January 13, 2012, 12:58:50 PM

Previous topic - Next topic

DeadHead

I'd like to ask a few questions about Windows (7) memory caching and Windows memory management in general.

I recently upgraded my computer (I7 920@3.6 GHz, Windows 7 Pro) from 6 gigabyte memory to 24 gigabyte memory. Yes, this is a *total* overkill for me as a regular homeuser, but since the upgrade was so cheap (less money than I spend on my original 6 gig!) I thought - why not?

Anyway, since I now have this huge amount of memory to play with, I naturally want to make as much use of it as possible.

The first thing I did was to install a ramdisk from company X. This particular ramdisk is most unique, because it has dynamic memory management. In short, this means that I can set it up to any size I want, depending only on the license I bought and the actual amount of physical ram memory that I have. So, I set this ramdisk up to use 8 gigabyte of ram. However, this ramdisk will only use the amount that is actually stored on the ramdisk. Also, if I delete files from the ramdisk, memory will be released! Not since the glorious days of the Amiga have I been able to find a ramdisk for Windows that has this ability.

Well, that right there is a nice way to utilize the huge amount of ram I have at my disposal. I can store "crap"-files on the ramdisk, use it for temporary files, extract archives, set junction points for games and so on.

What would be of more interest to me though, is the ability to cache more things from the harddrive into physical ram for blistering fast file access. I know that Windows by itself uses a number of techniques to cache files to ram, through prefetch and also when I run an application, it will store (some) of that data needed to run that particular application.

If I don't turn off my computer, but instead use the Power saving mode, that file cache will continue to grow, and after several days of use, opening different applications, eventually I will fill up all available memory with cached data - which is a good thing!

What I miss in Windows though, is a simple way to cache on demand! For example, I got this rather crappy coded mmo that is extremely disk intesive. It takes up +14 gigabyte of harddisk space. Due to the crappy coding, this game constantly reads from the harddisk, which leads to stuttering gameplay, even though I got a computer that crushes even the recommended specs for this particular game. Clearly, in this case, harddisk activity is the culprit for crappy performance.

So, sitting there with 24 gigabytes of ram to spare, playing a 32 bit game that won't use more than 2 gigabytes of memory, I see all this performance this game *could and should* utilize in a system like mine simply go to waste.

I guess I could of course copy the entire game to the ramdisk and run it from there, but that's not a very neat solution to this problem imho. What I would *really* like to be able to do, would be to precache the entire game/application on demand, OR (depending on actual ram any user might have) precache as much as the system would allow - on demand!

So, Jeremy or anyone else, can you see the issue(s) here, and see the need for solution to this?
Windows 10 Pro 64 (swedish) || Xeon 5650 @ +4 GHz || 24 gig ram || R9280 Toxic

Jeremy Collake

#1
First, although you know, let me clear up some some possible misconceptions for readers. The Windows file/disk cache is kept in what is considered 'free' RAM. It is *never* paged out, except in the new SuperFetch technology, which still isn't paged out, but is written to disk. When RAM containing disk/file cache is needed, this cache is just 'tossed out', as its just a cache and can go be retrieved again later. Well, assuming it isn't a write-back cache, then it needs flushed to disk.

So, don't worry about your cache 'filling up' or 'wasting' RAM, that's just not how it works. You want your RAM used 100% because that's the fastest storage you have on your PC. Now, most older task managers, and Process Lasso, show you X% used, and the rest as Free RAM. This area of Free RAM is where the file/disk cache is, as I mentioned, and something you can see more visibly in the new Resource Monitor of Vista+. If this RAM were NOT filled with anything, then you'd just be wasting it.

SuperFetch, on the other hand, is a different technology. It tries to gather what you most commonly use and *does* write them to disk so that it can keep a 'collection'. However, this 'smart cache' should always help and never hurt, in theory. On high end machines where it isn't needed, perhaps it is best to turn off. Do not confuse SuperFetch with ReadyBoost. ReadyBoost uses the smart cache of SuperFetch to know what stuff it should put on the USB key or other (faster) media.

Could there be situations where the standard disk/file cache or SuperFetch malfunctions, to the detriment of the system? ... possibly. I can not rule this out.
Software Engineer. Bitsum LLC.

DeadHead

Thanks Jeremy, but what I'm after here is a way to, on occasion, cache-on-demand (or should i say PREcache-on-demand) a particular application and/or folder. This should of course go to the standard memory cache like Windows already do by itself.
Windows 10 Pro 64 (swedish) || Xeon 5650 @ +4 GHz || 24 gig ram || R9280 Toxic

Jeremy Collake

Quote from: DeadHead on January 14, 2012, 01:35:58 AM
Thanks Jeremy, but what I'm after here is a way to, on occasion, cache-on-demand (or should i say PREcache-on-demand) a particular application and/or folder. This should of course go to the standard memory cache like Windows already do by itself.

Sorry, I misunderstood in my speed-reading.

User requested caching isn't available, indeed... I dunno about that, you'd have to do lots of mods to the system to create such a thing. The pre-fetch is what SuperFetch does, theoretically. It builds that list of common stuff, then loads them up into memory when you boot your PC.

Now, it might be possible to force something to be put into the cache by frequently accessing it. However, if you frequently access it, then surely it is in the cache. Selectively telling Windows not to cache stuff would be nice, but there's no current way to do that, and it would require lots of low-level and tightly coupled code to work. Very difficult.
Software Engineer. Bitsum LLC.

Jeremy Collake

Thinking about it further, there might be some way to rig up a system to force Windows to cache only what you want, but it isn't trivial stuff ... I will have to think on it. Ideally, it would be nice to have an interface into SuperFetch, so you could tell SuperFetch what you want in its prefetch/smart cache.
Software Engineer. Bitsum LLC.

edkiefer

Maybe this might help .
I did quick search and this seems to give path of data files in OS .

MS may have a doc/info too but this seems good info (i think ).


http://www.osnews.com/story/21471/SuperFetch_How_it_Works_Myths
Bitsum QA Engineer

Jeremy Collake

Yes, it says what I was trying to say, that SuperFetch stores its cached data on disk (in those .pf files), so that it can readily pre-fetch them into RAM on boot or user login... or slap them on a new ReadyBoost storage device inserted into the PC.

However, there's no high level interface to tell SuperFetch what to cache and what not to. You can delete it's .pf files, but the behavior then is unpredictable - and it'd likely just refill them. It most likely has a database (update: I see it does, in .db files stores in the same location). These need modified, and the format of such likely isn't documented anywhere. I would have to really dig into this. It is an interesting topic, though I must admit that I have doubts about user-controlled caching being more effective than smart caching based on what is accessed most frequently.

An ideal compromise would be 'sets' of SuperFetch caches. For instance, you might have a 'game' SuperFetch cache and a 'work' SuperFetch cache. Selecting between them would allow you to choose which cache is applicable, which I believe is your goal here.
Software Engineer. Bitsum LLC.

edkiefer

Yes, I have XP and looks like ini file is whats loaded and then you have the app .PF files .

There would need to be a way to have multiple db files and then added PF files and way to switch without windows altering any of the user edited "app profiles db ' . I am not sure this would work, meaning if your able to change how OS default does things .
Bitsum QA Engineer

Jeremy Collake

Quote from: edkiefer on January 14, 2012, 06:56:35 PM
Yes, I have XP and looks like ini file is whats loaded and then you have the app .PF files .

In XP this prefetching is not the same as SuperFetch. They use a different technology to try to boost the speed of system boot by prefetching files accessed during bootup, but its very similar, SuperFetch in Vista was a (large) extension of it.

Quote
There would need to be a way to have multiple db files and then added PF files and way to switch without windows altering any of the user edited "app profiles db ' . I am not sure this would work, meaning if your able to change how OS default does things .

Yes, but this may or may not work. More study would have to be done, much more study. SuperFetch is very tightly integrated into the system at a very low level. The effects of suddenly swapping out the storage directory (or files) is unknown.
Software Engineer. Bitsum LLC.

edkiefer

right , I know XP is like first version and vista/win7 superFetch is more advanced/broader system (its what I have to look at at moment) .

I assume this data gets loaded at bootup or is it updated over time (dynamically loaded) ,if system is not rebooted a lot , if it can do dynamically then it might work if you could get info or what makes it work in detail .

And of course if it is worth it , performance wise .
Bitsum QA Engineer

Jeremy Collake

The entire mechanism, and file formats, could be reverse engineered and documented. However, I'm just not sure of its utility. I mean, what more do you want cached that 'all my recently and frequently used stuff'? In certain situations, SuperFetch profiles might be useful, but only if there is a limited amount of RAM. Also, we don't know how smart SuperFetch is for sure, it might even already use a type of profile system. If it does, that could be a point of potential failure, as it introduces additional complexity.
Software Engineer. Bitsum LLC.

DeadHead

I would rather see another solution than superfetch. If I had my way with something like this, it would be being able to right-click a folder and choose something like "cache this folder into ram", perhaps with the option to store caching profiles that I could load, so that I wouldn't have to dig through explorer each and every time to find the particular folder of "game x the disk hog" ;)
Since I think the built in cache-system in Windows do a very good job on it's own, it's only under certain circumstances that I would like to be able to override what it is caching, like I mentioned in my first post.
Windows 10 Pro 64 (swedish) || Xeon 5650 @ +4 GHz || 24 gig ram || R9280 Toxic

DeadHead

Old topic, but still have interest in this, and am still looking for solutions. If you could ever come up with something like this Jeremy, I can guarantee there would be a lot of interest from gamers at least! :)
Windows 10 Pro 64 (swedish) || Xeon 5650 @ +4 GHz || 24 gig ram || R9280 Toxic

edkiefer

I ran across reading this tweak and it "may" help you with amount ram you have.

http://www.computingunleashed.com/how-to-make-windows-7-faster-and-responsive-by-2x.html

Generally these kinds of tweaks don't give much improvement and this one form what I saw actually slowed down some systems in benchmarks but these systems were mostly 8gig or less . So YMMV, its easy to test and try .
Bitsum QA Engineer

BenYeeHua

Quote from: DeadHead on December 12, 2012, 01:46:34 PM
Old topic, but still have interest in this, and am still looking for solutions. If you could ever come up with something like this Jeremy, I can guarantee there would be a lot of interest from gamers at least! :)
Same, the only way I found is using the fancycache to hold the file in the memory more.
But the bad is, it has causing lag when playing game, so I just uninstall it and don't using it now.
I will try other software that similar to ReadyBoost, but it can be choosing the file and using it on RAM.
----
Just Google a while, the solution is
1.Buy a SSD
2.Using Ramdisk, and using the ReadyBoost on it
3.Using Ramdisk, and copy the folder into it ;)
Quote from: edkiefer on December 12, 2012, 01:57:46 PM
I ran across reading this tweak and it "may" help you with amount ram you have.

http://www.computingunleashed.com/how-to-make-windows-7-faster-and-responsive-by-2x.html

Generally these kinds of tweaks don't give much improvement and this one form what I saw actually slowed down some systems in benchmarks but these systems were mostly 8gig or less . So YMMV, its easy to test and try .
Nope, the default setting is 0(server is 1, windows 7/8 is 0), it means not set.
And the SuperFetch is working, just the first load of game is slow.
----
http://www.techradar.com/news/software/operating-systems/10-windows-speedup-myths-to-avoid-686087
The wrong tweak. ;D

DeadHead

Quote from: BenYeeHua on December 13, 2012, 06:56:37 AMJust Google a while, the solution is
1.Buy a SSD
2.Using Ramdisk, and using the ReadyBoost on it
3.Using Ramdisk, and copy the folder into it ;)

1. Yes, a decent option. Not as fast as ram though.
2. You have no real control over readyboost, and it still won't cache exactly what I want, so no solution either.
3. Works of course, but a hazzle. Still not as easy as right clicking a folder to force Windows to "cache this folder", or "cache these files" - on demand.

I still think this should be doable, just not by me since I'm not a programmer! ;)

I've tried Fancycache, and while it looks good in benchmarks and such, I can't really say I've seen that big of peformance increase with that program either, and it also locks a set amount of memory for its caching, which in many cases I guess it caches the same things Windows is already caching by itself.

I think the better solution, in this case, would be to allow manual forcing of files into Windows normally used filecache - see attached image! :)

Actually, just by copying files from one disk to another seems to add these files into Windows cache. I want the same thing, except I don't want to actually copy anything!
Windows 10 Pro 64 (swedish) || Xeon 5650 @ +4 GHz || 24 gig ram || R9280 Toxic

BenYeeHua

Quote3. Works of course, but a hazzle. Still not as easy as right clicking a folder to force Windows to "cache this folder", or "cache these files" - on demand.
Create a right menu with a entry to move the folder into Ramdisk and run it/create a shortcut on desktop. ;D
----
QuoteI think the better solution, in this case, would be to allow manual forcing of files into Windows normally used filecache - see attached image! :)

Actually, just by copying files from one disk to another seems to add these files into Windows cache. I want the same thing, except I don't want to actually copy anything!
So just start up the game, and it will cache what the game loading for speedup the second time loading.
And they need tweak the cache more, like when copying big file on the same disk, extract the RAR.
Or using the FILE_FLAG_RANDOM_ACCESS, to force the windows cache the file more.

edkiefer

these caching SSD seem to get better reviews than I would think, performance increase across the board.
Seems to be good with HDD's .

http://www.hardocp.com/article/2012/08/15/corsair_accelerator_30gb_60gb_caching_ssd_review/1

Primary SSD would of course be better .
Bitsum QA Engineer

Jeremy Collake

#18
Simply installing an SSD and having ReadyBoost use that SSD does a good bit for the system, though I'm sure better solutions can be developed. SuperFetch (the part that decides what should be cached onto ReadyBoost) is fairly intelligent. I can do *whatever* [other question is if I do ;p], if you guys give me a concise description of the requirements you'd like to see.
Software Engineer. Bitsum LLC.

Hotrod

Quote from: edkiefer on December 12, 2012, 01:57:46 PM
I ran across reading this tweak and it "may" help you with amount ram you have.

http://www.computingunleashed.com/how-to-make-windows-7-faster-and-responsive-by-2x.html

Generally these kinds of tweaks don't give much improvement and this one form what I saw actually slowed down some systems in benchmarks but these systems were mostly 8gig or less . So YMMV, its easy to test and try .

Quote from: BenYeeHua on December 13, 2012, 06:56:37 AM
Nope, the default setting is 0(server is 1, windows 7/8 is 0), it means not set.
And the SuperFetch is working, just the first load of game is slow.
----
http://www.techradar.com/news/software/operating-systems/10-windows-speedup-myths-to-avoid-686087
The wrong tweak. ;D

OK I think I need some help :(

I tried this tweak to see if it worked. It didn't seem to help. Then I saw Ben's post after I had already made the change.

Quote
Right Click the cmd icon and choose “Run as Administrator“.
Now in the command prompt windows type in the following command.> fsutil behavior set memoryusage 2
Now restart windows 7.
Using the following query will give you the current value.<blockquote>fsutil behavior query memoryusage </blockquote>


Before running the set command, I had run the query command and indeed the default was 0. I ran the set command with a value of 2 as instructed, rebooted, and ran the query again to find it changed to 2. So far so good. Upon running my regular routine of apps and processes, I found things actually a bit slower so I decided to change it back. When I attempted to run the set command again with a value of 0, I get the standard response telling me the command syntax along with the statement that allowed values for this are 1 or 2. So how do I set it back to the default 0?? Or have i just made a mistake that can't be fixed?

edkiefer

#20
I believe default =1 . If you don't edit it it shows 0 , which AFAIK is non edited setting but 0=1 AFAIK .

I haven't done this but I did some reading on it  and that was what I remember .

Set it to 1 and see if performance comes back the same as before .

here straight from MS .

http://technet.microsoft.com/en-us/library/cc785435%28v=ws.10%29.aspx

I have unmodified value which show this in registry of win7 64bit
HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsMemoryUsage = registry key Dword =0
Bitsum QA Engineer

Hotrod

Thanks Ed,

That document gave me exactly what I needed. I used regedit in admin mode to change that dword to 0. A subsequent reboot and now I get a query value of 0. It seems they didn't allow for this in the command line structuring. All is back as it was now, thanks to your diligent work. :)

BenYeeHua

So you can know you has tweak it and restore to default. ;D

edkiefer

Quote from: Jeremy Collake on December 13, 2012, 06:02:21 PM
Simply installing an SSD and having ReadyBoost use that SSD does a good bit for the system, though I'm sure better solutions can be developed. SuperFetch (the part that decides what should be cached onto ReadyBoost) is fairly intelligent. I can do *whatever* [other question is if I do ;p], if you guys give me a concise description of the requirements you'd like to see.
Being able to have some user control over what apps get cached seems like common sense and maybe even have some rules if possible .
Like if x is running remove or don't load these exe into cache (if that can be done dynamically ) . for example you might have many app/exe loaded into cache but if you run one very memory dependent app, like say photoshop then you may need all free memory for photo editing .

I read somewhere MS superfetch also doesn't put the whole exe into memory, just parts . Dam , forget were I just read that .
Bitsum QA Engineer

BenYeeHua

Quote from: edkiefer on December 14, 2012, 08:00:11 AM
Being able to have some user control over what apps get cached seems like common sense and maybe even have some rules if possible .
Like if x is running remove or don't load these exe into cache (if that can be done dynamically ) . for example you might have many app/exe loaded into cache but if you run one very memory dependent app, like say photoshop then you may need all free memory for photo editing .

I read somewhere MS superfetch also doesn't put the whole exe into memory, just parts . Dam , forget were I just read that .
Try RamMap? :)
-----
I think the answer is unknown for me, just using RamMap to check, the PlanetSide2.exe is in the Ram, but don't know it is whole or part of it.
The game resource is inside the Ram also. ;)
PS:Superfetch cache the data that only read by the software(exist in Ram with most reading count), and the system cache the writing too(but will holding it sometimes with <100MB).

DeadHead

#25
Quote from: Jeremy Collake on December 13, 2012, 06:02:21 PM
Simply installing an SSD and having ReadyBoost use that SSD does a good bit for the system, though I'm sure better solutions can be developed. SuperFetch (the part that decides what should be cached onto ReadyBoost) is fairly intelligent. I can do *whatever* [other question is if I do ;p], if you guys give me a concise description of the requirements you'd like to see.

Well the first thing I'd like to see, without making this harder than it have to be (to begin with at least!), is a way to force caching of selected files into the area in ram where Windows normally caches files, IF this is at all possible to begin with ofc!

Once that works, the possibilities for expanding are endless! :)

About readyboost on ssd... do readyboost cache really big files - at all? When it comes to games, it's common for some to have all assets packed into one big file, for example Guild Wars 2 has all assets stored in one file; Gw2.dat (currently @ 15 gig!).
Windows 10 Pro 64 (swedish) || Xeon 5650 @ +4 GHz || 24 gig ram || R9280 Toxic

BenYeeHua

Maybe Readyboost cache part of the file just like Superfetch?

quinreitz


BenYeeHua

Prefetch your software file into the Ram when/before it open.
But we don't how "smart" it is. :P

Jeremy Collake

#29
Software Engineer. Bitsum LLC.

BenYeeHua

Ya, but most useful one is after the first load of the software, it cache it. ;D

Jeremy Collake

The thing about SuperFetch and its storage ReadyBoost devices is that - at least ReadyBoost - relies on the premise that FLASH memory has lower access times than do HDDs. This makes it ideal to retrieve common things fast. For systems with an SSD as the primary drive, there is little use unless you have limited RAM. Limited RAM and an SSD would be an odd combination.

It does help a bit with boot speed.

I long ago proposed that Microsoft take a snapshot of all virtual memory, so it could quickly copy it back (instead of dynamically restore it). This idea was laughed off by famous person X. Just goes to show you: Listen to nobody ;)
Software Engineer. Bitsum LLC.

BenYeeHua

Who know, but it has improve, right? :)