The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Mr Earl on January 03, 2007, 10:09:26 AM

Title: Clear Page Cache
Post by: Mr Earl on January 03, 2007, 10:09:26 AM
How do you clear the Page Cache, other than rebooting.
Title: Re: Clear Page Cache
Post by: stanhebben on January 03, 2007, 10:15:16 PM
What if you read and write CR3:


mov eax, CR3
mov CR3, eax

Title: Re: Clear Page Cache
Post by: Mr Earl on January 03, 2007, 11:04:42 PM
Thanks Stan, but that didn't do it.  I'm timing how long it takes to read a large group of files using different code and I don't want to have to keep rebooting between tests.  I was hoping there was an easy way, such as you offered, but since it's only for a test I can live with the reboots.
Title: Re: Clear Page Cache
Post by: dsouza123 on January 04, 2007, 01:59:52 AM
Try setting the Virtual Memory to the minimum 2 MB (for XP),
if you have a good amount of RAM (ie 512 MB), XP wont use
the virtual memory unless absolutely needed.

You could also use a RAMDisk to hold the files or even
the Virtual Memory page file.
Title: Re: Clear Page Cache
Post by: Mark_Larson on January 06, 2007, 02:42:47 PM
Quote from: Mr Earl on January 03, 2007, 11:04:42 PM
Thanks Stan, but that didn't do it.  I'm timing how long it takes to read a large group of files using different code and I don't want to have to keep rebooting between tests.  I was hoping there was an easy way, such as you offered, but since it's only for a test I can live with the reboots.

  Actually Stan was correct.  It's a privileged instruction under Windows, so you have to do it in a driver.  Also keep in mind when you do that it has to clear the entire TLB cache which may take time.  A similar instruction for clearing the L1/L2 caches is wbinvd.  And it's really slow, but it has to clear a lot more cache.

Mark
Title: Re: Clear Page Cache
Post by: hutch-- on January 08, 2007, 12:56:33 AM
Something I remember in the win9x days was the problems of effective memory loss due to fragmentation but it was a reasonable simple problem to solve. I simply allocated just over all of the ram I had on the machine, then deallocated it all and suddenly the machine had all of its memory available again. Back in those days it saved a reboot as the memory fragmentation got worse.