Is it possible something similar to zRam in FreeBSD?

Good day!

I have some experience of using linux zram on a machine with low memory and it gives absolutely good results when memory is not enough and it starts swap. Is FreeBSD has something like zram and if not, is it may be developed or it is a denied by a core developers?
 
It would help if you'd be a bit more specific. We claim to know FreeBSD here but not necessarily Linux, and quite frankly I have no idea what zram is supposed to be. Alas, I found this:

https://en.wikipedia.org/wiki/Zram

FreeBSD can also do this (assuming I understand what you're after), but in a different way. It supports virtual memory and can also use files for swap. For regular usage (such as temporary files in /tmp) the tmpfs is often used (see tmpfs(5)).

Then memory disk support is provided through the md driver, see also mdconfig(8). This is most often used to gain access to images such as ISO files.

However, I'm not fully sure what you're after here. If this is about adding more swap space then you can also simply use dd to create an imagefile and then use swapon to initialize swap space on it. It works but I wouldn't recommend this.

Note that all this doesn't use any compressed images or such.

(edit): But when used on a compressed filesystem then I suppose you'll get somewhat of the same results. Though I wouldn't count on optimal performance though.

Hope this somewhat answers your question.
 
I think zram actually compress the data on ram, and keep it in there as long as possible before start swapping.

I may be confusing but I think I already seen something similar on DragonFly.
 
Best reply for the bad question :)

I think zram actually compress the data on ram, and keep it in there as long as possible before start swapping.
Yes and not. As I understand, when zram configured you set maximum amount data stored on zram device, for example 300MB.
And that amount of data stored with compression will eats from real memory less than allocated amount. Let's compress ratio will be 3x, so 300MB will eats 100MB, and there will be + 200MB virtually to RAM without swapping on a slow drive.
So there is a benefit in memory with cost of some CPU for compression\decompression.

When system has a very low RAM (as my old laptop with 256MB), that trick sufficiently improves desktop tasks.

However, I'm not fully sure what you're after here. If this is about adding more swap space then you can also simply use dd to create an imagefile and then use swapon to initialize swap space on it. It works but I wouldn't recommend this.
There is not only used as additional swap, mainly as fastest compressed swap and also it has ability to press non-compressed blocks to backed swap (hdd based swap)

Guys, sorry for my english, I know that it is very brain destructed :)
 
My laptop swaps on a compressed file, works great. Once the data is compressed in the ZFS write cache, memory pressure is a lot lower and it might newer been written out. So yes, we have something like that.
 
My laptop swaps on a compressed file, works great. Once the data is compressed in the ZFS write cache, memory pressure is a lot lower and it might newer been written out. So yes, we have something like that.
How You do that? If this is based on ZFS compression, so it is not solution for me, because my laptop has only 256MB RAM and I think that ZFS is not a option for it :)
 
because my laptop has only 256MB RAM and I think that ZFS is not a option for it
I tend to keep a minimum of 2GB before using ZFS. Anything less and it's probably going to be somewhat problematic, ZFS really likes RAM. And prefers to have lots of it.
 
Ok found something like this https://wiki.freebsd.org/SummerOfCode2019Projects/VirtualMemoryCompression It seems like implemenation of zswap concept in free bsd was rejected.
Keeping swap on spinning drives, server grade sata ssd or nvme is not a problem probably. But... I have drive for mere mortals SSD ADATA XPG SX8200 PRO 2TB M.2 2280 PCI-E x4 Gen3 NVMe.
So is there a way to put my swap in to ram or ram tmpfs instead of setting it up as a swap partition or swap file on a disk it self.
So basicaly is there a some kind of eqivalent of zswap (ram-swap) from linux for free bsd.

Is using this

# mdconfig -a -t malloc -o compress -o reserve -s 512m -u 7
# newfs -U /dev/md7
mount /dev/md7 /mnt/ramdrive
and creating swap on a ramdrive maybe a good solution, or complite BS

PS im primarily a linux user I do not have deep understending of bsd ways of handling things. That's why im asking
PS.2 My english sucks ... Sorry
PS.3 Do I even need swap with zfs or ufs when i have 64 GB of ram?
 
So is there a way to put my swap in to ram or ram tmpfs instead of setting it up as a swap partition
This is what you want to try.

You add it to your /etc/fstab and it uses ram as /tmp

It should also help reduce any disk writing of swap on SSD/NVMe

Especially read Second Example. No setup needed. Just add fstab entry.
Configure a tmpfs mount via fstab(5):

tmpfs /tmp tmpfs rw 0 0
 
Do I even need swap with zfs or ufs when i have 64 GB of ram?
No. It is not needed for UFS. It does reduce time of compiling in building from source on low memory machines.
I can't speak for ZFS.
FreeBSD doesn't require swap. Useful yes but required no. If unsure leave some Gigs empty on install and you can add it later.
 
Swap? It depends on the use of the system, and the user's expectations. Without swap, if you run out of RAM, something crashes. Usually an application, but often that de-facto means the machine is useless and has to be rebooted. This is particularly true if you run a GUI (which uses a lot more memory), or if you run buggy software that leaks memory (which is sadly not uncommon). If you have swap, the machine will stay up longer, but it will get slower when swapping is needed.

One scenario: Your intended usage's "working set" (the amount of memory it needs to operate) is a little bigger than the RAM you have. In that case, swap allows you to work productively, although not at top speed. Another scenario: Your working set is smaller than RAM; in that case, swap is at best useless. At worst, it will delay and slow down finding out that some program is leaking RAM, by making the inevitable crash take longer. There are many other possible scenarios.

I run my servers with some swap (about 1/4 of RAM); like that the slowdown when running out of memory gives me advance warning that something is breaking.
 
This is what you want to try.

You add it to your /etc/fstab and it uses ram as /tmp

It should also help reduce any disk writing of swap on SSD/NVMe

Especially read Second Example. No setup needed. Just add fstab entry.

Excuse my for probably being as thick as a brick in matter how bsd handles things, but if i understand correctly,
if i put this tmpfs /tmp tmpfs rw 0 0 to my fstab it will throw /tmp to ram which is great i do that on my linux machines also.

From what you have said, it seems like on bsd tmpfs works also as a quasi swap, or my assumption is just totally wrong and tmpfs is tmpfs period?
If that is the case there is no way to put swap to ram on bsd systems.

I really do not try to be pain in a but here, I just really want to sort things out for myself
A habit is a second nature of a man. On any given linux i do both those things
my tmpfs in fstab looks like this tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=512M 0 0
and my swap goes to zram0.

Im happy if i can achieve even one of those on bsd

Thank you all for the patience for suborn linux user who is a bsd green horn :)
Take care and God bless you people
 
Also, ZFS will compress the ARC, basically giving you a compressed disc cache. My swap was set up on a compressed vdev, worked like a charm. So basically it will compress memory about to be paged out (difference between swapping and paging, you see?) and this will free up RAM in the process. So, IMHO, zswap is not needed because better solutions are already available.
 
Back
Top