views:

57

answers:

1

I've written a little VBScript program to query the page file usage under Windows XP (eventually 2003/2008 Server as well) but the figures I seem to be getting are bizarre.

This is the program:

Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
for i = 1 to 10
    Set qry1 = wmi.ExecQuery ("Select * from Win32_PageFileSetting")
    Set qry2 = wmi.ExecQuery ("Select * from Win32_PerfRawData_PerfOS_PagingFile")
    initial = 0
    maximum = 0
    For Each obj in qry1
        initial = initial + obj.InitialSize
        maximum = maximum + obj.MaximumSize
    Next
    For Each obj in qry2
        if obj.Name = "_Total" then
            Wscript.Echo _
                " Initial size: " & initial & _
                " Maximum size: " & maximum & _
                " Percent used: " & obj.PercentUsage & _
                ""
        end if
    Next
    qry1 = none
    qry2 = none
    WScript.sleep (1000)
Next

which outputs:

Initial size: 1512 Maximum size: 3024 Percent used: 21354
Initial size: 1512 Maximum size: 3024 Percent used: 21354
Initial size: 1512 Maximum size: 3024 Percent used: 21354
Initial size: 1512 Maximum size: 3024 Percent used: 21354
Initial size: 1512 Maximum size: 3024 Percent used: 21354
Initial size: 1512 Maximum size: 3024 Percent used: 21354
Initial size: 1512 Maximum size: 3024 Percent used: 21354
Initial size: 1512 Maximum size: 3024 Percent used: 21354
Initial size: 1512 Maximum size: 3024 Percent used: 21354
Initial size: 1512 Maximum size: 3024 Percent used: 21354

The doco on MSDN states:

PercentUsage
    Data type: uint32
    Access type: Read-only
    Qualifiers:
        DisplayName ("% Usage")
        CounterType (537003008)
        DefaultScale (0)
        PerfDetail (200)
    Percentage of the page file instance in use. For more information,
    see the PageFileBytes property in Win32_PerfRawData_PerfProc_Process.

Now that seems pretty straight-forward. Why is my 3G page file using 21000% of it's allocated space? That would be about 630G but pagefile.sys is only about 1.5G (and my entire hard disk is only 186G).


Update:

When I get the same field from Win32_PerfFormattedData_PerfOS_PagingFile, I get a more reasonable value of 5 but that still doesn't seem to coincide with Task Manager, which shows 1.06G usage out of the 3G maximum.

+1  A: 

You can't operate with the value directly like that.

The CounterType of the ProcessUsage property is 537003008, which according to this table corresponds to the PERF_RAW_FRACTION counter. Given the formula from the second link, we end up with something like this:

" Percent used: " & ((obj.PercentUsage * 100) / obj.PercentUsage_Base) & _
arul
That's better. With that formula, I get 5.77... which is in the ballpark of the formatted data. I'm just wondering why Task Manager states 1.06G is used out of the 3G. I may just end up using the formatted data.
paxdiablo
I get 41.591 ... Performance counter shows ~42%, Task Manager ~50% ... now we can only guess who's lying to us. (I'm leaning towards the Task manager being the bad guy here, does it take into account the maximum size of the virtual memory? ...)
arul
@arul, I think I found the solution. If you add up CommittedBytes from Win32_PerfFormattedData_PerfOS_Memory, you get the same value (about 1.1G at the moment). That's all the memory reserved in the paging file(s) for active processes to write out their pages. So we'll probably report that and the percent figure. Thanks and accept.
paxdiablo