Ignore disksize: check only /sys/block/zramX/mem_used_total
This commit is contained in:
parent
daca5ccf1e
commit
37807b4157
@ -1347,31 +1347,18 @@ def check_mem_and_swap():
|
|||||||
|
|
||||||
|
|
||||||
def check_zram():
|
def check_zram():
|
||||||
"""Find MemUsedZram."""
|
"""Find MemUsedZram (mem_used_total)."""
|
||||||
disksize_sum = 0
|
if os.path.exists('/sys/block/zram0/mem_used_total'):
|
||||||
mem_used_total_sum = 0
|
summa = 0
|
||||||
|
for dev in os.listdir('/sys/block'):
|
||||||
for dev in os.listdir('/sys/block'):
|
try:
|
||||||
if dev.startswith('zram'):
|
with open('/sys/block/{}/mem_used_total'.format(
|
||||||
stat = zram_stat(dev)
|
dev), 'rb', buffering=0) as f:
|
||||||
disksize_sum += int(stat[0])
|
summa += int(f.read())
|
||||||
mem_used_total_sum += int(stat[1])
|
except FileNotFoundError:
|
||||||
|
continue
|
||||||
# Means that when setting zram disksize = 1 GiB available memory
|
return summa / 1024
|
||||||
# decrease by 0.0042 GiB.
|
return 0
|
||||||
# Found experimentally, requires clarification with different kernaels and
|
|
||||||
# architectures.
|
|
||||||
# On small disk drives (up to gigabyte) it can be more, up to 0.0045.
|
|
||||||
# The creator of the zram module claims that ZRAM_DISKSIZE_FACTOR should
|
|
||||||
# be 0.001:
|
|
||||||
# ("zram uses about 0.1% of the size of the disk"
|
|
||||||
# - https://www.kernel.org/doc/Documentation/blockdev/zram.txt),
|
|
||||||
# but this statement contradicts the experimental data.
|
|
||||||
# ZRAM_DISKSIZE_FACTOR = deltaMemAvailavle / disksize
|
|
||||||
# Found experimentally.
|
|
||||||
ZRAM_DISKSIZE_FACTOR = 0.0042
|
|
||||||
|
|
||||||
return (mem_used_total_sum + disksize_sum * ZRAM_DISKSIZE_FACTOR) / 1024.0
|
|
||||||
|
|
||||||
|
|
||||||
def format_time(t):
|
def format_time(t):
|
||||||
@ -1480,31 +1467,6 @@ def human(num, lenth):
|
|||||||
return str(round(num / 1024)).rjust(lenth, ' ')
|
return str(round(num / 1024)).rjust(lenth, ' ')
|
||||||
|
|
||||||
|
|
||||||
def zram_stat(zram_id):
|
|
||||||
"""
|
|
||||||
Get zram state.
|
|
||||||
|
|
||||||
zram_id: str zram block-device id
|
|
||||||
returns bytes disksize, str mem_used_total
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
disksize = rline1('/sys/block/' + zram_id + '/disksize')
|
|
||||||
except FileNotFoundError:
|
|
||||||
return '0', '0'
|
|
||||||
if disksize == ['0\n']:
|
|
||||||
return '0', '0'
|
|
||||||
try:
|
|
||||||
mm_stat = rline1('/sys/block/' + zram_id + '/mm_stat').split(' ')
|
|
||||||
mm_stat_list = []
|
|
||||||
for i in mm_stat:
|
|
||||||
if i != '':
|
|
||||||
mm_stat_list.append(i)
|
|
||||||
mem_used_total = mm_stat_list[2]
|
|
||||||
except FileNotFoundError:
|
|
||||||
mem_used_total = rline1('/sys/block/' + zram_id + '/mem_used_total')
|
|
||||||
return disksize, mem_used_total # BYTES, str
|
|
||||||
|
|
||||||
|
|
||||||
def is_alive(pid):
|
def is_alive(pid):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user