Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
zram will back up files if there was enough space to do that. Otherwise it will keep only the compressed data and will uncompress files on demand.
In your case you can check the compression ratio by manually compressing your binaries. As far as I see you will not be able to save huge amount of ram using zram.
"zram will back up files if there was enough space to do that. Otherwise it will keep only the compressed data and will uncompress files on demand. " - This is a news to me !
Neither the Linux documentation (https://www.kernel.org/doc/Documenta...ckdev/zram.txt) talks about it nor I don't see this info in the internet as well. Can you please point out to me where this is documented/discussed ?
If this is true, can you suggest an alternate way to save store and retrieve binaries like tmpfs , but can save memory ?
"zram will back up files if there was enough space to do that. Otherwise it will keep only the compressed data and will uncompress files on demand. " - This is a news to me !
Neither the Linux documentation (https://www.kernel.org/doc/Documenta...ckdev/zram.txt) talks about it nor I don't see this info in the internet as well. Can you please point out to me where this is documented/discussed ?
If this is true, can you suggest an alternate way to save store and retrieve binaries like tmpfs , but can save memory ?
http://www.robert-franz.com/2015/12/...ressed-memory/
probably here you can find a better explanation: http://superuser.com/questions/45098...che-swapcached, look for the long answer.
Unfortunately I cannot suggest any other solution. Probably using (more) shared objects may lower the required space, but we need to know much more about your configuration to give you any hint. Probably you can optimize your apps to use disk instead of ram...
Did you resolve the problem? Now I face the same problem when I try to use zram as block devices.
The zram block devices seem like normal tmpfs without any compress.
Hi Sundialsvcs,
Actually, it's hard for me to add more memory into motherboard, because I try to run my customize OS on embedded systems currently.
All I want is use the limited memory(1GB) as effective as I can.
I use the following commands to create a zram devices and format it as ext4 fs then mount it.
After that I use dd to create many dummy files, however, it seems not compress at all.
I don't see anything in the post showing the commands to create the zram device, but it looks like the size of the ext4 file system is 1.0G in size. Considering the default settings and typical overhead, 917M of data is a reasonable limit on how much stuff could fit in there (the uncompressed size).
It looks like the compressed size is 568K, but I'm not positive. The output of zramctl is not immediately obvious in meaning.
If you want to store more than 1GB in an ext4 file system, you must make the zram block device larger than 1GB (the uncompressed size).
I stopped experimenting with using ext4 on zram when it became obvious that it was hideously inefficient for my uses. It's okay if you mostly just write once, or the total disk usage is consistently near the maximum. But otherwise, you end up with a lot of dirty blocks which are merely deallocated rather than wiped clean. Zram has no way to know thse blocks can be safely discarded, so they continue to consume ram.
My preference is to just use tmpfs, because it is aware when data can be discarded. Of course, it's not compressed, but I like how the ram usage doesn't grow and grow.
OTOH, my issue could be solved by setting up something like zerofree to run periodically - zeroing out freed blocks.
Hi IsaacKuo,
Thanks for ur reply. I add the commands above how I create, format and mount zram device.
It's ok for me to use any other file system rather than ext4 if another one can satisfy what I need (store more data/files than 1GB through compressing them).
Hi IsaacKuo,
Thanks for ur reply. I add the commands above how I create, format and mount zram device.
It's ok for me to use any other file system rather than ext4 if another one can satisfy what I need (store more data/files than 1GB through compressing them).
Or is there any way to achieve this except zram?
ext4 is fine. Your main problem is the first command:
sudo zramctl -f --size 1G
This will create a block device with a size of 1G (uncompressed). It will never be able to store more than 1G of data. The file system overhead and default settings will limit you to some amount a bit less than that.
If you want to store more data than that, you must create the zram block device with a larger size. Note that the compressed size will still need to fit in ram, so there's not much point to making this size bigger than, say, twice the amount of physical ram. This depends on how well it compresses, of course. Depending on the exact nature of the data being stored, you might get higher compression rates. Or you might get hardly any compression. For example, if the bulk of your data is jpg files, then you're better off just using ordinary tmpfs (no compression).
As you say
> This depends on how well it compresses, of course.... you might get higher compression rates
I just want to clarify my understanding of zram block deivce. In my cognition, when I restore the files/data into zram device, the zram device will help me to compress(LZO OR LZ4) them at first and write into block device later.
For example, there are two file
PHP Code:
$ ls -lh |grep rootfs -rw-r--r--. 1 root root 54M May 5 01:18 rootfs.tar -rw-r--r--. 1 root root 21M May 5 01:17 rootfs.tar.gz $ df -h|grep zram Filesystem Size Used Avail Use% Mounted on /dev/zram0 1.0G 17M 899M 2% /mnt/zram
The rootfs.tar is the file I want to restore in zram and the rootfs.tar.gz is the compressed one by gzip.
If I cp the rootfs.tar to the normal tmpfs, the total size of course will be 17M(Used) + 54M(rootfs.tar) = 71M .
But if I cp the rootfs.tar to the zram device, I expect the size of "Used" should be much less then 71M, because zram will help me to compress rootfs.tar automatically.
However, the result is not my result, it seems not compress rootfs.tar at all.
Or what's the right method to use zram?
df will only report the uncompressed sizes, because it is telling you about what the ext4 filesystem layer sees. The ext4 filesystem knows nothing about the fact that the block device it's writing to/from is a zram device.
In order to determine how much ram is consumed by the zram block device, you need to use zramctl.
I don't know ZRAM, but I ponder if it is trying to tell you the uncompressed data size . . . ?
Also, it might have to hold the data briefly in order to compress it, and perhaps it does not (seem to) release that space right away. Unless something is exerting pressure on the memory subsystem, it tends to be very "lazy."
The df command knows nothing about zram, and will never report the compressed sizes. It is only reporting what the ext4 file system reports to it (the ext4 file system knows nothing about the fact that the block device it is using is compressed or is in ram).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.