6

I have a real-time application running on a server with terrible disk IO access times (the actual transfer speed is great, but requesting disk-access can take seconds before being granted).

Windows moves memory into the page-file even when there's lots of physical memory available, and so ordinary applications can require disk-access even if they never explicitly try to access the disk.

Is there a way I can disable the page-file for an application pragmatically, rather than disabling the page file system wide?

Mr. Smith
  • 4,288
  • 7
  • 40
  • 82
  • 1
    I only know of VirtualLock http://msdn.microsoft.com/en-us/library/windows/desktop/aa366895(v=vs.85).aspx which allows you to lock regions of memory into physical memory. – Eelke Feb 12 '13 at 06:15
  • Have you run some performance monitoring to make sure that page faults are the underlying performance bottleneck? – Michael Feb 12 '13 at 09:21
  • Windows may _copy_ memory into the page file, speculatively. Doesn't mean the RAM is discarded, or that an application would require disk access. This preemptive copy is the only reason why modern versions will write to the pagefile, and it's a background write. Agree with Michael, premature optimization. – MSalters Feb 12 '13 at 09:32
  • @MSalters I can't find any web sources that state that the copy is performed on a separate thread. – Mr. Smith Feb 12 '13 at 09:54
  • @Mr.Smith: That's because it won't be done using a user-mode thread in your process. – MSalters Feb 12 '13 at 10:46

2 Answers2

5

You can use VirtualLock to lock a specified region of the process's virtual address space into physical memory, ensuring that subsequent access to the region will not incur a page fault.

Richard Harrison
  • 19,247
  • 4
  • 40
  • 67
2

We experienced similar behaviour recently, with a process being paged out to the swap file, even though there was stacks of RAM still available.

The problem turned out to be the process priority. Firstly in Task Manager it was showing as Below Normal:

Below Normal priority

However it was more useful to check the Memory Priority from Process Explorer (from SysInternals). This shows on the Performance tab of the process properties:

Memory Priority

(A higher number is higher priority here).

When this was below 5, Windows would naturally start to page the process out if it was quiet for about 2 minutes. This was confirmed by watching the Page File usage percentage in Performance Monitor - the green line here: Page File usage


In our case, the cause was the default priority given to a task by the Task Scheduler in Windows. This defaults to Below Normal, and is also not visible in the UI. Instead you must export the task definition to XML, edit and re-import - as described here.

As that mentions, the default priority given to a task is 7. When that was changed to 4 in the XML, and re-imported:

<Priority>4</Priority>

... this was enough to stop the paging. In Task Manager the priority showed as Normal, in Process Explorer the Memory Priority went from 2 to 5.

(Look out, these numbers go in opposite directions).

It's worth noting, a <Priority> of 5 or 6 also showed as Normal in Task Manager, but the Memory Priority was still too low to prevent Windows pre-emptively paging.

df778899
  • 10,703
  • 1
  • 24
  • 36