def calculate_avail_vmem(mems):
 free = mems['MemFree:']
 fallback = (free + mems.get('Cached:', 0))
 try:
  lru_active_file = mems['Active(file):']
  lru_inactive_file = mems['Inactive(file):']
  slab_reclaimable = mems['SReclaimable:']
 except KeyError:
  return fallback
 try:
  f = open_binary(('%s/zoneinfo' % get_procfs_path()))
 except IOError:
  return fallback
 watermark_low = 0
 with f:
  for line in f:
   line = line.strip()
   if line.startswith('low'):
    watermark_low += int(line.split()[1])
 watermark_low *= PAGESIZE
 watermark_low = watermark_low
 avail = (free - watermark_low)
 pagecache = (lru_active_file + lru_inactive_file)
 pagecache -= min((pagecache / 2), watermark_low)
 avail += pagecache
 avail += (slab_reclaimable - min((slab_reclaimable / 2.0), watermark_low))
 return int(avail)

def calculate_avail_vmem ( mems ) : free = mems [ 'MemFree:' ] fallback = ( free + mems . get ( 'Cached:' , 0 ) ) try : lru_active_file = mems [ 'Active(file):' ] lru_inactive_file = mems [ 'Inactive(file):' ] slab_reclaimable = mems [ 'SReclaimable:' ] except KeyError : return fallback try : f = open_binary ( ( '%s/zoneinfo' % get_procfs_path ( ) ) ) except IOError : return fallback watermark_low = 0 with f : for line in f : line = line . strip ( ) if line . startswith ( 'low' ) : watermark_low += int ( line . split ( ) [ 1 ] ) watermark_low *= PAGESIZE watermark_low = watermark_low avail = ( free - watermark_low ) pagecache = ( lru_active_file + lru_inactive_file ) pagecache -= min ( ( pagecache / 2 ) , watermark_low ) avail += pagecache avail += ( slab_reclaimable - min ( ( slab_reclaimable / 2.0 ) , watermark_low ) ) return int ( avail )
fallback for kernels < 3 .