/** Release any free memory back to the system,
 * but only if you are above a certain fraction of use of the
 * total available PHYSICAL memory.
 * Calling this could help the system avoid going into swap.
 *
 * NOTE: This only works if you linked against tcmalloc.
 * NOTE 2: This takes at least 0.1 ms on a Ubuntu 10.10 system, because of
 *      the call to MemoryStats.update().
 *
 * @param threshold :: multiplier (0-1.0) of the amount of physical
 *        memory used that has to be in use before the call to
 *        release memory is actually called.
 */
void MemoryManagerImpl::releaseFreeMemoryIfAbove(double threshold)
{
    UNUSED_ARG(threshold);
#ifdef USE_TCMALLOC
    Kernel::MemoryStats mem;
    mem.update();
    double fraction_available = static_cast<double>(mem.availMem())
                                / static_cast<double>(mem.totalMem());
    if (fraction_available < (1.0 - threshold))
    {
      // Make TCMALLOC release memory to the system
      MallocExtension::instance()->ReleaseFreeMemory();
    }
#endif
}