Windows and Virtual Memory Usage

I’ve always felt that virtual memory in Windows could be done better, and lately I’ve been noticing it more than usual.


When you do something that uses a lot of memory (like play a game, compile a large program, etc), it seems that Windows doesn’t do a very good job of figuring out what to swap out and when to swap it back in.  The problem is especially noticeable once the memory hogging application is done.


I’ve created a simple program that demonstrates the problem nicely.  It’s called ForceSwap.cpp and the source is here: 



http://www.stevex.org/code/ForceSwap.cpp.txt


There’s a compiled binary here if you prefer.


This program simulates a program that uses a lot of memory.  It does this by continually allocating 64k chunks, and then walking through them after it’s allocated them, forcing them all to be in main memory.  This is a worst case scenario for the memory manager – an application wants a LOT of memory, and wants it all in physical memory because it’s using all of it.  This isn’t that far off from how a compiler, or a game behaves.


Run this program, and it will print the available physical memory after each allocation and walk of the allocated chunks of memory.  Once the available physical memory drops to near 0, it will continue to run, but will start hitting the disk, paging other applications out to make room for this program’s memory requirements and eventually thrashing virtual memory on each pass through the allocated chunks.


Let it run this way for a while, and then stop it (Ctrl-C) - this is the situation I want to look at.  Windows is now in a state where everything that can be paged out, has been.  Sometimes when you stop the program, the disk will continue to grind for a while – I’m not sure what that is, but I’m guessing that Windows started swapping stuff out and is continuing to do so. 


Anyway, once your system settles and seems to be idle again, try to use it.  Everything you do will be frustratingly slow.


For example, on my system, bringing up the Task Manager took 7 seconds.  Opening the My Documents folder took almost 30 seconds!  Right-clicking on a folder took 8 seconds.


These delays are because the virtual memory manager has to page a lot of stuff back in.  Opening the My Documents folder means much of the Windows Explorer, the Common Controls library, the icons, and many other things have to be fetched from the page file.  That’s understandable.


My point here isn’t that it’s wrong that the applications were swapped out.  The memory manager was doing it’s best to satisfy the requirements of this application.  But, I have a gig of RAM, and I absolutely hate the huge drop in performance for things that I expect to be instant, like clicking on the Start menu, hitting Windows-R to bring up the Run dialog, or opening a folder.


So what I want to do is find a way to lock into memory things that are part of maintaining UI responsiveness.  Explorer, for example, and all the memory it’s allocated.  The task manager.  Maybe even Outlook.


It would probably cost me 10% of my available RAM to do this, but to me, it’s worth it. 


The question is how.  The VirtualLock function is what I want to call, but I need to inject calls to it into the process whose memory I want to lock.  This isn’t so difficult for Explorer since there are lots of ways to write plugins for it that get called at various times; but is there a general way of getting code to run inside another process?


Another option would be to have the virtual memory manager notice that the memory shortage no longer exists, and start lazily bringing pages back into memory.  This would be a good solution I think but it would be helped a lot by having some way to prioritize what gets swapped in.


Anyone have any other thoughts on this?


 

Leave a Reply

 




 
buy cheap Endep online buy cheapest Endep and Endep how to order Amitriptyline online without prescription buy Amitriptyline without rx from us pharmacy online Amitriptyline purchase purchase online prescription Amitriptyline without purchasing Amitriptyline online without prescription order generic Amitriptyline buy Endep no prescriptions how to order Endep online without prescription comprare Endep generico Endep online buy Endep in england buy cheap Endep online free consult Endep purchased online without prescription what is Endep Endep tabletten buy Endep no perscription cod Endep non rx fedex overnight free want to buy Anafranil in usa Aricept overdose buy discount Aricept on line Aricept buy Aricept online Aricept order buy Aricept pills Nizoral suppliers cheap order rx Nizoral canada Nizoral order Nizoral usa cod comprar Nizoral generico buy Nizoral 200 mg buy cheap Nizoral under without rx buy cheap Nizoral with dr. prescription Prozac 200 mg buy Lisinopril australia el Nizoral generico buy Lisinopril tablets without rx next day delivery Lisinopril with no script buy Lisinopril c o d purchase arimidex no scams order Arimidex order amex Arimidex canadian pharmacy buy Arimidex without doctor order rx free Arimidex buy Abilify with american express buy Abilify cod order Finpecia without a prescription cheap order rx Finpecia purchase Famvir no visa online without prescription buy Famvir paypal without rx buy Famvir without Famvir without prescription medications Famvir without persription purchase Famvir online no membership overnight shipping Famvir no physician approval Amitriptyline purchase order Amitriptyline free next day airAmitriptyline on line Valtrex no rx needed cod accepted buy next day Fluoxetine buy Fluoxetine line purchase Fluoxetine cod delivery buy Fluoxetine 20 mg purchase Fluoxetine buy cheap Fluoxetine under without rx purchase Fluoxetine visa without prescription Fluoxetine by mail Fluoxetine for pets Fluoxetine 10mg Amitriptyline purchase online how to order Famvir online without a rx Prozac Amitriptyline no perscription Famvir next day purchase Anafranil no prescription cheap buy cheapest Anafranil next day delivery on Anafranil saturday Anafranil buy Anafranil buy Anafranil overnight where to purchase Anafranil no prescription no fees Anafranil drug buy Lisinopril where Lisinopril buy on line order Lisinopril online no membership overnight shipping no prescription required for Lisinopril order maxalt cash on delivery Maxalt from canada buy cheapest Maxalt purchase Maxalt visa without prescription buy Maxalt uk Maxalt 10 mg purchase Maxalt no visa online without prescription purchase generic Lisinopril online Lisinopril no prescription to buy maxalt order online no membership overnight how to get a arimidex rx Aricept without a perscription fedex Aricept overnight without a prescription Donepezil prescription order buy genuine Aricept Aricept uk sales prescription Proscar buy Proscar pay cod Maxalt apotheke buy no perscription Proscar purchase Proscar online buy cheap fedex Prednisone maxalt with no presciption buy Maxalt shipped cod Proscar online Prednisone order buy Amitriptyline with amex Accutane 40 mg delivered overnight buy brand Accutane 40 mg Accutane 40 mg orderd online without prescription where to purchase generic Accutane 40 mg online without a rx how to get 40 mg Accutane without next day delivery 40 mg Accutane with no script buy Amitriptyline online Accutane 40 mg online no prescription buy Accutane 40 mg online us pharmacy Accutane 40 mg best buy buy Accutane 40 mg c o d order 40 mg Accutane cash on delivery no presciption 40 mg Accutane