Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUESTION: Any way to release OS memory after files getting removed from the zram devices? #220

Open
amit-gshe opened this issue Dec 23, 2024 · 3 comments

Comments

@amit-gshe
Copy link

I removed all files from the zram device, but it still occupying muth of memory. How to release these memory back to OS?

image

@nabijaczleweli
Copy link
Collaborator

Probably blkdiscard for the raw blockdev and fstrim for the filesystem? Try running fstrim -v /mnt/zram2.

@amit-gshe
Copy link
Author

I tried triming but it seems not work:
image

@nabijaczleweli
Copy link
Collaborator

I can repro this, fstrim and blkdiscard don't seem to do anything (except zeroing the data):

/sys/block/zram0# tee disksize
4000000000
4000000000
/sys/block/zram0# mkfs.ext4 /dev/zram0
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 976563 4k blocks and 244320 inodes
Filesystem UUID: a00a7e82-d052-4ce9-9196-4db4539c560f
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

/sys/block/zram0# mount /dev/zram0 trace
/sys/block/zram0$ cd trace/
/sys/block/zram0/trace$ l
total 16k
drwx------ 2 root root 16k 12-24 15:28 lost+found
/sys/block/zram0/trace$ zramctl --output-all
NAME       DISKSIZE DATA COMPR ALGORITHM STREAMS ZERO-PAGES TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0     3.7G   2M 39.9K lzo-rle        24          0  100K        0B     100K       0B /sys/devices/virtual/block/zram0/trace
/sys/block/zram0/trace# head -c 500M < /dev/urandom | sudo tee rand > /dev/null
/sys/block/zram0/trace$ zramctl --output-all
NAME       DISKSIZE  DATA COMPR ALGORITHM STREAMS ZERO-PAGES  TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0     3.7G  430M  428M lzo-rle        24          0 428.1M        0B   428.1M       0B /sys/devices/virtual/block/zram0/trace
/sys/block/zram0/trace# rm rand
/sys/block/zram0/trace$ zramctl --output-all
NAME       DISKSIZE  DATA COMPR ALGORITHM STREAMS ZERO-PAGES  TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0     3.7G  430M  428M lzo-rle        24          1 428.2M        0B   428.2M       0B /sys/devices/virtual/block/zram0/trace
/sys/block/zram0/trace# fstrim -v $PWD
/sys/block/zram0/trace: 3.2 GiB (3405623296 bytes) trimmed
/sys/block/zram0/trace$ zramctl --output-all
NAME       DISKSIZE  DATA COMPR ALGORITHM STREAMS ZERO-PAGES  TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0     3.7G  430M  428M lzo-rle        24          1 428.2M        0B   428.2M       0B /sys/devices/virtual/block/zram0/trace
/sys/block/zram0/trace$ cd ..
/sys/block/zram0# umount trace
/sys/block/zram0$ zramctl --output-all
NAME       DISKSIZE   DATA COMPR ALGORITHM STREAMS ZERO-PAGES  TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0     3.7G 430.1M  428M lzo-rle        24          3 428.2M        0B   428.2M       0B
/sys/block/zram0# blkdiscard /dev/zram0
blkdiscard: /dev/zram0 contains existing file system (ext4).
blkdiscard: This is destructive operation, data will be lost! Use the -f option to override.
/sys/block/zram0# blkdiscard /dev/zram0 -f
blkdiscard: Operation forced, data will be lost!
/sys/block/zram0$ zramctl --output-all
NAME       DISKSIZE DATA COMPR ALGORITHM STREAMS ZERO-PAGES TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0     3.7G   0B    0B lzo-rle        24          0    0B        0B   428.2M       0B

Except blkdiscard changes TOTAL... but doesn't change MEM-USED. So. idk. This seems like a linux bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants