title: Virtual memory space not cleared even after direct byte buffers are deallocated
body: <p>RAM: 30 GB</p>
  
  <p>Relevant JVM options: -Xms21182m -Xmx21182m -XX:CMSInitiatingOccupancyFraction=70</p>
  
  <p>I have an application where we don't have -XX:MaxDirectMemorySize set. I am tracking the direct memory usage using the following MBean criteria</p>
  
  <pre><code>java.nio:type=BufferPool,name=direct
  </code></pre>
  
  <p>Once my heap usage hit 70%, major GC was triggered and direct memory usage as reported by the MBean decreased from 7 GB to 300 MB. Heap utilization also came down to 10%</p>
  
  <p>When i run <strong>top</strong> command on this host, i still see memory consumed by the system as 80%</p>
  
  <pre><code>  PID   USER      PR   NI    VIRT     RES    SHR   S  %CPU %MEM     TIME+    COMMAND
    10000 root      20   0     34.017g  0.023t 25836 S  97.3 79.6     21243:55 java
  </code></pre>
  
  <p>I ran <strong>pmap</strong> for this process id, following is the summary</p>
  
  <pre><code>                 Kbytes   RSS      Dirty
  total kB         37058940 24714848 24688904
  </code></pre>
  
  <p>Total RAM usage hasn't changed even though direct memory usage has decreased. Is it possible that resident memory is not being freed even though JVM has freed up direct byte buffers?</p>
  
  <p>java.nio.DirectByteBuffer.Deallocator#run</p>
  
  <pre><code>        public void run() {
              if (address == 0) {
                  // Paranoia
                  return;
              }
              unsafe.freeMemory(address);
              address = 0;
              Bits.unreserveMemory(size, capacity);
          }
  </code></pre>