MongoDB page faults even when all data is in resident in RAM I have made a sample app that emulates what my real one does. It simply iterates over all documents of a specific collection over and over.

I start mongo (as a windows service) and mongostat shows almost no resident memory.

insert  query update delete getmore command flushes mapped  vsize    res faults  locked db idx miss %     qr|qw   ar|aw  netIn netOut  conn       time
*0     *0     *0     *0       0     1|0       0      6.03g  6.12g    71m      0 local:0.0%          0       0|0     0|0    62b     3k     3   09:35:11


I use the touch command on the single collection I have (which is about 2GB in size) and mongostat shows:

insert  query update delete getmore command flushes mapped  vsize    res faults          locked db idx miss %     qr|qw   ar|aw  netIn netOut  conn       time
*0     *0     *0     *0       0     5|0       0      6.03g  6.12g   2.1g 427937 HamsterSchool:0.0%          0       0|0     0|0   408b     4k     3   09:39:59
*0     *0     *0     *0       0     1|0       0      6.03g  6.12g   2.1g      0         local:0.0%          0       0|0     0|0    62b     3k     3   09:40:00


Which seems as though the entire collection is now resident in memory, but when I run the sample app, no matter how long, there are always a lot of page faults:

insert  query update delete getmore command flushes mapped  vsize    res faults          locked db idx miss %     qr|qw   ar|aw  netIn netOut  conn       time
*0     68     *0     *0       0     1|0       0      6.03g  6.12g   2.1g  35616 HamsterSchool:0.0%          0       0|0     1|0     6k    74m     4   09:43:15
*0     68     *0     *0       0     4|0       0      6.03g  6.12g   2.1g  36068 HamsterSchool:0.0%          0       0|0     0|0     6k    75m     5   09:43:16


So, why are there any page faults at all if everything was already "touched"?. It's important to note that mongo runs on a 32GB RAM 64bit windows machine and 27GB of RAM is free at all times.
The page faults metric for MongoDB on Windows essentially contains hard (actually hitting disk) and soft (reallocating a pointer in memory) page faults.  If you run the same experiment on Linux, the page fault metric only reports hard page faults and you will see the behavior you expect.

This is a known issue with the Windows version and the relevant issue for tracking/voting is SERVER-5799