zRAM on hot using a udev rule

This post explains how to configure zRAM on a Linux system running systemd using udev rules. In the case of wanting to know internally the operation of zRAM visit: Gentoo Wiki

Basically the things we have to keep in mind are the following. Each zRAM device is limited to being managed by 1 CPU core, so we will have to create a device for each core in case we want to make the most of a CPU with multiple cores.

This technology, which is available since version 3.15 of the Linux kernel, can not only be used to store the well-known swap that is typically stored on the hard disk, but can also be used as a reserved temporary storage device. This is a good practice for temporary folders of the system, such as temporary compilation folders, volatile data (/tmp), web cache, etc …

Before making the new zram devices permanent in our system, we will load the zram module already included in the kernel of our distribution (in case you have a custom kernel visit the link to the Gentoo wiki).

My CPU has 4 cores, so I’m going to create the same blocks in RAM. Edit: /etc/modprobe.d/zram.conf

options zram num_devices=4

Create the rules. Edit: /etc/udev/rules.d/99-zram.rules

KERNEL==”zram0″, ATTR{disksize}=”512M” RUN=”/usr/bin/mkswap /dev/zram0″, TAG+=”systemd”
KERNEL==”zram1″, ATTR{disksize}=”512M” RUN=”/usr/bin/mkswap /dev/zram1″, TAG+=”systemd”
KERNEL==”zram2″, ATTR{disksize}=”512M” RUN=”/usr/bin/mkswap /dev/zram2″, TAG+=”systemd”
KERNEL==”zram3″, ATTR{disksize}=”512M” RUN=”/usr/bin/mkswap /dev/zram3″, TAG+=”systemd”

Load the module, you will se the new devices created on /dev/zram*

modprobe zram

Now you can swap devices, do the same on the rest of devices 1, 2, 3

swapon /dev/zram0

To see if we have configured the swap in zRAM correctly, we execute:

free -h

For loading the module on systemd boot automatically:

/etc/modules-load.d/zram.conf

Finally add to the end of the file /etc/fstab

/dev/zram0              none            swap            defaults        0 0
/dev/zram1              none            swap            defaults        0 0
/dev/zram2              none            swap            defaults        0 0
/dev/zram3              none            swap            defaults        0 0

Be good guys!

Join the Conversation

23 Comments

  1. I do not even understand how I ended up right here, but I believed this submit used to be good.

    I do not recognise who you might be however definitely you are going to a well-known blogger if
    you happen to are not already. Cheers!

  2. Definitely imagine that that you stated. Your favorite reason appeared to
    be on the internet the easiest thing to remember of.
    I say to you, I definitely get annoyed even as other folks
    consider concerns that they just do not know about.
    You controlled to hit the nail upon the top as smartly as defined out the whole thing with
    no need side-effects , people can take a signal. Will likely be again to get more.

    Thank you

  3. Hiya very nice web site!! Guy .. Beautiful .. Amazing .. I will bookmark your site and take the
    feeds also? I’m satisfied to search out numerous helpful
    information right here in the publish, we need work out extra strategies in this regard, thanks for sharing.
    . . . . .

  4. Thanks for your personal marvelous posting! I definitely enjoyed reading
    it, you are a great author. I will be sure to bookmark your blog and will come back in the future.
    I want to encourage yourself to continue your great posts,
    have a nice weekend!

  5. You really make it seem so easy along with your presentation but I
    to find this matter to be really one thing that
    I believe I might by no means understand. It seems too complex and
    extremely huge for me. I am looking ahead for your subsequent submit,
    I’ll try to get the hold of it!

  6. I’m extremely pleased to find this great
    site. I wanted to thank you for ones time for this wonderful read!!
    I definitely really liked every part of it and i also have you book marked to
    check out new stuff in your site.

  7. You actually make it seem so easy with your presentation but I
    find this matter to be actually something which I think I would never understand.
    It seems too complex and extremely broad for
    me. I’m looking forward for your next post, I’ll try to get the
    hang of it!

  8. First of all I would like to say terrific blog!
    I had a quick question that I’d like to ask if you do not mind.
    I was curious to know how you center yourself and clear your head prior to writing.
    I have had a hard time clearing my thoughts in getting my ideas out
    there. I truly do enjoy writing however it
    just seems like the first 10 to 15 minutes tend to be lost simply
    just trying to figure out how to begin. Any suggestions or tips?
    Kudos!

  9. I’m gone to say to my little brother, that he should also go to
    see this blog on regular basis to get updated from hottest news update.

  10. Wow, marvelous blog format! How lengthy have you ever been running a
    blog for? you make blogging look easy. The full glance of your website
    is wonderful, let alone the content material!

  11. I am really glad to glance at this website posts which carries plenty of
    helpful facts, thanks for providing these kinds of statistics.

  12. Howdy! This post couldn’t be written any better!
    Reading through this post reminds me of my previous room
    mate! He always kept chatting about this. I will forward this page
    to him. Pretty sure he will have a good read.
    Many thanks for sharing!

  13. Thanks for a marvelous posting! I truly enjoyed reading it, you’re a great author.
    I will make certain to bookmark your blog and will often come back sometime soon. I want to encourage you
    to definitely continue your great work, have a nice afternoon!

  14. First off I want to say superb blog! I had a quick question which
    I’d like to ask if you don’t mind. I was curious to know how you center yourself and clear your thoughts prior to writing.
    I’ve had trouble clearing my mind in getting my thoughts
    out. I truly do take pleasure in writing however it just
    seems like the first 10 to 15 minutes are wasted just trying to
    figure out how to begin. Any ideas or tips? Kudos!

  15. I have been browsing on-line greater than three hours lately,
    yet I never found any interesting article like yours.

    It is pretty price sufficient for me. Personally, if all web
    owners and bloggers made excellent content material as you probably did, the web shall be much more helpful than ever before.

Leave a comment

Your email address will not be published. Required fields are marked *