Skip to content

Commit

Permalink
Try to consider ZFS cache in MemAvailable
Browse files Browse the repository at this point in the history
  • Loading branch information
hakavlad committed May 2, 2020
1 parent 7c62a54 commit 16f7db1
Showing 1 changed file with 90 additions and 1 deletion.
91 changes: 90 additions & 1 deletion nohang/nohang
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,43 @@ def memload():
os.kill(self_pid, SIGUSR1)


def arcstats():
"""
"""
with open(arcstats_path, 'rb') as f:
a_list = f.read().decode().split('\n')

for n, line in enumerate(a_list):
if n == c_min_index:
c_min = int(line.rpartition(' ')[2]) / 1024
elif n == size_index:
size = int(line.rpartition(' ')[2]) / 1024

elif n == arc_meta_used_index:
arc_meta_used = int(line.rpartition(' ')[2]) / 1024

elif n == arc_meta_min_index:
arc_meta_min = int(line.rpartition(' ')[2]) / 1024

else:
continue

c_rec = size - c_min

if c_rec < 0:
c_rec = 0

meta_rec = arc_meta_used - arc_meta_min

if meta_rec < 0:
meta_rec = 0
zfs_available = c_rec + meta_rec

# return c_min, size, arc_meta_used, arc_meta_min, zfs_available

return zfs_available


def exe(cmd):
""" execute cmd in subprocess.Popen()
"""
Expand Down Expand Up @@ -1292,7 +1329,7 @@ def find_psi_metrics_value(psi_path, psi_metrics):
return float(psi_list[1].split(' ')[3].split('=')[1])


def check_mem_and_swap():
def check_mem_and_swap0():
"""
"""
fd['mi'].seek(0)
Expand All @@ -1302,6 +1339,23 @@ def check_mem_and_swap():
int(m_list[swap_free_index].split(':')[1]))


def check_mem_and_swap():
"""
"""
fd['mi'].seek(0)

m_list = fd['mi'].read().decode().split(' kB\n')

ma = int(m_list[mem_available_index].split(':')[1])
st = int(m_list[swap_total_index].split(':')[1])
sf = int(m_list[swap_free_index].split(':')[1])

if ZFS:
ma += arcstats()

return ma, st, sf


def meminfo():
"""
"""
Expand All @@ -1323,6 +1377,11 @@ def meminfo():
md['used'] = mem_total - mem_free - buffers - cached - sreclaimable
md['free'] = mem_free
md['available'] = mem_available

if ZFS:
z = arcstats()
mem_available += z

md['shared'] = shmem
md['buffers'] = buffers
md['cache'] = cached + sreclaimable
Expand Down Expand Up @@ -3721,6 +3780,36 @@ fd = dict()
fd['mi'] = open('/proc/meminfo', 'rb', buffering=0)


arcstats_path = '/proc/spl/kstat/zfs/arcstats'
# arcstats_path = './arcstats'

ZFS = os.path.exists(arcstats_path)


if ZFS:
try:
# find indexes
with open(arcstats_path, 'rb') as f:
a_list = f.read().decode().split('\n')
for n, line in enumerate(a_list):
if line.startswith('c_min '):
c_min_index = n

elif line.startswith('size '):
size_index = n

elif line.startswith('arc_meta_used '):
arc_meta_used_index = n

elif line.startswith('arc_meta_min '):
arc_meta_min_index = n

else:
continue
except Exception as e:
log(e)


m0 = monotonic()
pt0 = process_time()

Expand Down

0 comments on commit 16f7db1

Please sign in to comment.