Skip to content

Instantly share code, notes, and snippets.

Created March 3, 2021 18:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Quick script to find out how much RAM is being used inefficiently or wasted.
#!/bin/env python3
# Requires
# Requires pip install
from bloom_filter import BloomFilter #
import re
import hashlib
def allRamPages():
with open('/proc/iomem', 'r') as iomemfile:
for iomemline in iomemfile:
# iomemline looks like "ca30c000-cd820fff : System RAM"
x ="^([0-9a-f]*)-([0-9a-f]*) : System RAM$", iomemline)
if not x: continue
low = int(, 16)
high = int(, 16)
low = low
while low < high:
yield low
low = low + 4096
devmem = open('/dev/mem', 'rb')
bloom = BloomFilter(max_elements=2**34/2**12, error_rate=0.001)
same = 0
notsame = 0
fail = 0
zerohash = hashlib.md5(b'\x00'*4096).digest()
for pagenum in allRamPages():
data =
data = hashlib.md5(data).digest()
if (data==zerohash):
if data in bloom:
same = same+1
notsame = notsame+1
except PermissionError:
fail = fail+1
if (pagenum%(1024*4096)==0): print(f'{pagenum:02X} done. {zerocount} zero, {same} same, {notsame} not the same, {fail} failed.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment