title: mongodb memory confusion. page fault and index size
body: <p>I'm utterly confused on how much actual memory is being used by my mongodb..</p>
  
  <p>issuing db.stats(1024*1024) i get an output </p>
  
  <pre><code>&gt; db.stats(1024*1024)
  {
      "db" : "test",
      "collections" : 9,
      "objects" : 38035503,
      "avgObjSize" : 535.2138471259339,
      "dataSize" : 19414,
      "storageSize" : 22280,
      "numExtents" : 62,
      "indexes" : 12,
      "indexSize" : 4039,
      "fileSize" : 30642,
      "nsSizeMB" : 16,
      "ok" : 1
  }
  </code></pre>
  
  <p>So i have a little less then 40 million objects and an index size of 4GB.
  Running this on a windows server with 17GB RAM, looking at the Resource Monitor and task manager, my mongodb instance have a working set of 17GB and a Shareable of the same amount.</p>
  
  <p>My first though was that "ok so it has pre-allocated datafiles so that there will be faster inserts when it actually needs the space".</p>
  
  <p>But then i started mongostat and could clearly see a very much to high page fault:</p>
  
  <pre><code>insert  query update delete getmore command flushes mapped  vsize    res faults
   time
     220   2419      0      0       0     221       0  27.9g  56.1g  16.8g   2659
  </code></pre>
  
  <p>So im guessing that it actually has run out of memory and is now swapping and picking up directly from disk.</p>
  
  <p>My question basically is how can i actually determine the amount of data that i will be able to store before i run out of RAM?. The stats tell me that it only has 4GB worth of index, but mongo seems to be choked,swapping and consuming all 17GB. What am i missing?</p>