Можно ли вручную отправлять программы в виртуальную память в Windows?

1144
Pietro Doninelli

Если у вас много открытых программ, и ваша машина слишком загружена памятью / процессором, вы можете закрыть программу, не теряя ее состояния (отправив ее в виртуальную память), а затем возобновить работу программы позже. Это автоматически выполняется ОС, но ОС не знает, сколько времени вы хотите приостановить свою программу, поэтому в конечном итоге она становится очень медленной, пытаясь сохранить фрагменты каждой программы в памяти и перенести другие фрагменты в виртуальную память. Вручную отправка всей программы в виртуальную память, а затем извлечение ее в том же состоянии, когда это желательно, было бы хорошей функцией, есть ли инструмент для этого? или это можно написать?

2
запустите processHacker, выберите процесс, щелкните его правой кнопкой мыши и выберите «misc» -> «уменьшить рабочий набор», нажмите «Systeminfo-> Memory» и выберите «пустой измененный список» magicandre1981 8 лет назад 2

1 ответ на вопрос

3
Jamie Hanrahan

Your programs are always running in virtual memory all the time. (Windows' terminology in that dialog where you set the pagefile size is grossly misleading.)

What you are asking for is the ability to force a program to be paged out. There is no way to do that directly.

so it eventually becomes really slow by trying to keep pieces of every program on memory and swapping other pieces to virtual memory.

That doesn't happen. Memory pages that are not being accessed are always available to be released for other uses (and written to disk as necessary); the OS doesn't "try to keep pieces of every program" in memory regardless of whether they're being accessed. If they're not being accessed, which is normally the case for private pages of an idle program, they will only stay in memory until there's pressure caused by other programs' needs. (Until then there's no point in paging them out, right?)

Through Windows XP, minimizing an app's Windows would force a working set purge, but I think XP was the last where this was true.

If you really want to do this, though, you can use the VMmap tool from SysInternals. When it starts up it will ask you to select a process. Do that, then select View | Empty Working Set.

Note however that this only releases pages to the modified or standby page list. (And that only for pages that aren't in the working sets of any other processes.) Pages dropped to the modified list will be written to the pagefile and then moved to the standby list. Pages on the standby list are considered "available" but until they are repurposed for some other use they will still contain the contents from the original process.

The net result is exactly the same as what Windows will do if there is pressure for available memory - you're just doing it sooner, before such demands actually exist.

Full details are of course in the Memory Management chapter of Windows Internals by Solomon, Russinovich, and Ionescu.