Announcement

Collapse
No announcement yet.

Replacing Swap with ZRAM

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Replacing Swap with ZRAM

    I installed zram-config and created one zram for every CPU core (zram0, and zram1). I also booted to my Kubuntu 18.04 SDD then powered up the 14.04 SDD (unmounted) so I could delete the swap partition and extend the main partition which gave my drive 8GB more space.

    Then I modified my fstab file to rem out the swap line and add the two zram virtual drives:

    Code:
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    # / was on /dev/sdd1 during installation
    UUID=d8748971-a662-43a1-b178-e9e1dd6eae22 /               ext4    noatime,errors=remount-ro 0       1
    #
    # swap was on /dev/sdd5 during installation
    # UUID=6f9e8a0e-d718-45f0-9b17-318f23225be1 none            swap    sw                      0       0
    #
    # Common Data drive /dev/sdd1
    UUID=9d3f1ff1-99b4-418c-8dca-84916431f9d5  /media/Data    ext4    noatime                         0   1
    #
    # Using ZRAM instead of a Swap file. One zram virtual drive for every cpu core.
    /dev/zram0                              none              swap    SW,pri=10                 0         0
    /dev/zram1                              none              swap    SW,pri=10                 0         0
    I expected the zram vdrives to show up in the df output.

    Code:
    mark@AMD-64:/$ df -h                                                                                                 
    Filesystem      Size  Used Avail Use% Mounted on                                                                     
    udev            3.9G  4.0K  3.9G   1% /dev                                                                           
    tmpfs           799M  1.5M  797M   1% /run                                                                           
    /dev/sdc1       110G   13G   92G  12% /                                                                              
    none            4.0K     0  4.0K   0% /sys/fs/cgroup                                                                 
    none            5.0M     0  5.0M   0% /run/lock                                                                      
    none            3.9G   27M  3.9G   1% /run/shm                                                                       
    none            100M   20K  100M   1% /run/user                                                                      
    /dev/sdd1       459G  188G  248G  44% /media/Data
    I'm not confident that the zram drives are active and available to the OS.

    Code:
    mark@AMD-64:/$ free -m
                total       used       free     shared    buffers     cached
    Mem:          7983       1478       6504         37         60        669
    -/+ buffers/cache:        748       7235
    Swap:         3991          0       3991
    Why do I still see swap memory in the above readout?

    I know the drives exist:

    Code:
    mark@AMD-64:/dev$ ll zram*
    brw-rw---- 1 root disk 251, 0 Oct 28 11:21 zram0
    brw-rw---- 1 root disk 251, 1 Oct 28 11:21 zram1
    I also booted to my Kubuntu 18.04 SDD then powered up the 14.04 SDD (unmounted) so I could delete the swap partition and extend the main partition which gave my drive 8GB more space. Is there a way or perhaps something I forgot to do to activate the zram drives so Kubuntu can use them when necessary?
    "If you're in a room with another person who sees the world exactly as you do, one of you is redundant." Dr. Steven Covey, The 7-Habits of Highly Effective People

    #2
    Okay, I booted up my Ubuntu Server 18.04LTS and did a quick scan of dmesg. That led me to the syslog file and this is what I see in regards to zram:
    Code:
    Oct 29 14:56:26 nas-64 systemd[1]: Timed out waiting for device dev-disk-by\x2duuid-6b500932\x2db00d\x2d4f32\x2d85b1\x2d1075fed2fe7f.device.
    Oct 29 14:56:26 nas-64 systemd[1]: Dependency failed for /dev/disk/by-uuid/6b500932-b00d-4f32-85b1-1075fed2fe7f.
    Oct 29 14:56:26 nas-64 systemd[1]: dev-disk-by\x2duuid-6b500932\x2db00d\x2d4f32\x2d85b1\x2d1075fed2fe7f.swap: Job dev-disk-by\x2duuid-6b500932\x2db00d\x2d4f32\x2d85b1\x2d1075fed2fe7f.swap/start failed with result 'dependency'.
    Oct 29 14:56:26 nas-64 systemd[1]: dev-disk-by\x2duuid-6b500932\x2db00d\x2d4f32\x2d85b1\x2d1075fed2fe7f.device: Job dev-disk-by\x2duuid-6b500932\x2db00d\x2d4f32\x2d85b1\x2d1075fed2fe7f.device/start failed with result 'timeout'.
    Oct 29 14:56:26 nas-64 systemd[1]: dev-disk-by\x2duuid-3715d759\x2d431e\x2d4d7d\x2d814e\x2d8bad66ea5605.device: Job dev-disk-by\x2duuid-3715d759\x2d431e\x2d4d7d\x2d814e\x2d8bad66ea5605.device/start timed out.
    Oct 29 14:56:26 nas-64 systemd[1]: Timed out waiting for device dev-disk-by\x2duuid-3715d759\x2d431e\x2d4d7d\x2d814e\x2d8bad66ea5605.device.
    The UUIDs in question are the UUIDs of my zram0 and zram1 virtual swap drives. I did convert the fstab entries to UUID.
    Code:
    mark@nas-64:/var/log$ cat /etc/fstab
    # Customized fstab
    # This line mounts the Samsung 64GB Flash drive to the root directory /
    UUID=7d92d528-da4b-11e8-b61c-f46d040f477d   /     ext4     defaults  0 0
    #
    # This line mounts the RAID to /nas using the BTRFS
    UUID=44235f1e-bde3-4de4-b680-06536903ada1  /nas  btrfs    defaults  0 0
    #
    # Next 2 line mount the zram virtual drives instead of a swap file
    # 1st line is /dev/zram0, 2nd line is /dev/zram1
    UUID=6b500932-b00d-4f32-85b1-1075fed2fe7f none  swap     sw        0 0  
    UUID=3715d759-431e-4d7d-814e-8bad66ea5605 none  swap     sw        0 0
    Perhaps that's not a good idea for zram drives and I should change back as I had them in the first post. Please advise.
    "If you're in a room with another person who sees the world exactly as you do, one of you is redundant." Dr. Steven Covey, The 7-Habits of Highly Effective People

    Comment


      #3
      So what's zram?

      Please Read Me

      Comment


        #4
        See https://en.m.wikipedia.org/wiki/Zram
        Windows no longer obstructs my view.
        Using Kubuntu Linux since March 23, 2007.
        "It is a capital mistake to theorize before one has data." - Sherlock Holmes

        Comment


          #5
          Here's a little discussion of this, fwiw -- the guys there do seem to know what they are doing:
          https://askubuntu.com/questions/6254...swap-partition
          An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

          Comment


            #6
            Mmmm.... I had no clue, either. Another nifty Linux utility that snuck in through the back door! I found this article about it:
            https://www.cnx-software.com/2018/05...u-enable-zram/
            "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
            – John F. Kennedy, February 26, 1962.

            Comment


              #7
              I'm not sure where mhumm2s confusion comes from. I installed zram-config, rebooted (it's a kernel module and I read reboot was required to enable) and after reboot I had 24GB swap when my swap partition is only 16GB;
              Code:
              [FONT=monospace][COLOR=#54FF54][B]stuart@office[/B][/COLOR][COLOR=#000000]:[/COLOR][COLOR=#5454FF][B]~[/B][/COLOR][COLOR=#000000]$ swapon      [/COLOR]
              NAME           TYPE       SIZE USED PRIO
              /dev/nvme0n1p2 partition   16G   0B   -2
              /dev/zram0     partition 1000M   0B    5
              /dev/zram1     partition 1000M   0B    5
              /dev/zram2     partition 1000M   0B    5
              /dev/zram3     partition 1000M   0B    5
              /dev/zram4     partition 1000M   0B    5
              /dev/zram5     partition 1000M   0B    5
              /dev/zram6     partition 1000M   0B    5
              /dev/zram7     partition 1000M   0B    5
              [/FONT]
              So I disabed my swap partiton and rebooted and;
              Code:
              [FONT=monospace][COLOR=#54FF54][B]stuart@office[/B][/COLOR][COLOR=#000000]:[/COLOR][COLOR=#5454FF][B]~[/B][/COLOR][COLOR=#000000]$ swapon                      [/COLOR]
              NAME       TYPE       SIZE USED PRIO
              /dev/zram0 partition 1000M   0B    5
              /dev/zram1 partition 1000M   0B    5
              /dev/zram2 partition 1000M   0B    5
              /dev/zram3 partition 1000M   0B    5
              /dev/zram4 partition 1000M   0B    5
              /dev/zram5 partition 1000M   0B    5
              /dev/zram6 partition 1000M   0B    5
              /dev/zram7 partition 1000M   0B    5
              [COLOR=#54FF54][B]stuart@office[/B][/COLOR][COLOR=#000000]:[/COLOR][COLOR=#5454FF][B]~[/B][/COLOR][COLOR=#000000]$ free[/COLOR]
                            total        used        free      shared  buff/cache   available
              Mem:          15999         659       14527           7         812       15062
              Swap:          7999           0        7999
              [/FONT]
              Seems painfully obvious that each of my 8 cores now has 1GB of swap.

              This brings up some questions;
              1. I have tmpfs in RAM. This will auto-expand to SWAP if needed. Will it still work that way if I don't have a swap partition?
              2. BTRFS cannot use a swapfile thus must have a swap partition. Does this mean I no longer need my swap partition when using BTRFS?
              3. Can I configure (increase) the amount of zram available for swap and do I need to?
              4. How does zram effect usable RAM?
              5. Does zram handle hibernate/suspend or would a swap partition also be required for this?
              6. If a swap partition is still required for some of the above uses, is there any advantage to using both, and if YES whats the best way to do that (think the priority setting here)?


              Some more research is required.

              Please Read Me

              Comment


                #8
                Initial research from me and I've install zswap instead of zram, using this easy how-to;

                https://ubuntu-mate.community/t/enab...formance/11302

                Please Read Me

                Comment


                  #9
                  Originally posted by oshunluvr View Post
                  Initial research from me and I've install zswap instead of zram, using this easy how-to;

                  https://ubuntu-mate.community/t/enab...formance/11302
                  Interesting! It almost convinced me to shrink by Btrfs root_fs by 17GB, create a swap partion, and then install zswap.
                  But, with 16GB of RAM I've never hit the wall ... yet. IF I ever do then zswap will be my solution.
                  "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                  – John F. Kennedy, February 26, 1962.

                  Comment


                    #10
                    Originally posted by oshunluvr View Post
                    Initial research from me and I've install zswap instead of zram, using this easy how-to;

                    https://ubuntu-mate.community/t/enab...formance/11302
                    humm going to try that on this old laptop ,,,,,,,,,,,,

                    Code:
                    vinny@vinny-Aspire-V5-431:~$ inxi -Fzxx
                    System:    Host: vinny-Aspire-V5-431 Kernel: 4.15.0-38-generic x86_64 bits: 64 gcc: 7.3.0
                              Desktop: KDE Plasma 5.14.2 (Qt 5.11.2) dm: sddm,sddm Distro: KDE neon User Edition 5.14
                    Machine:   Device: laptop System: Acer product: Aspire V5-431 v: V1.12 serial: N/A
                              Mobo: Acer model: Aspire V5-431 v: V1.12 serial: N/A
                              UEFI [Legacy]: Phoenix v: V1.12 date: 06/12/2012
                    Battery    BAT0: charge: 0.0 Wh 0.0% condition: 32.3/37.0 Wh (87%) volts: 3.5/14.8
                              model: SANYO AL12A32 serial: <filter>status: N/A
                    CPU:       Dual core Intel Pentium 967 (-MCP-) arch: Sandy Bridge rev.7 cache: 2048 KB
                              flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 ssse3) bmips: 5187
                              clock speeds: min/max: 800/1300 MHz 1: 811 MHz 2: 834 MHz
                    Graphics:  Card: Intel 2nd Generation Core Integrated Graphics Controller
                              bus-ID: 00:02.0 chip-ID: 8086:0106
                              Display Server: x11 (X.Org 1.19.6 ) drivers: modesetting (unloaded: fbdev,vesa)
                              Resolution: 1366x768@60.10hz
                              OpenGL: renderer: Mesa DRI Intel Sandybridge Mobile
                              version: 3.3 Mesa 18.0.5 (compat-v: 3.0) Direct Render: Yes
                    Audio:     Card Intel 7 Series/C216 Family High Def. Audio Controller
                              driver: snd_hda_intel bus-ID: 00:1b.0 chip-ID: 8086:1e20
                              Sound: Advanced Linux Sound Architecture v: k4.15.0-38-generic
                    Network:   Card-1: Realtek RTL8111/8168/8411 PCIE Gigabit Ethernet Controller
                              driver: r8169 v: 2.3LK-NAPI port: 2000 bus-ID: 02:00.2 chip-ID: 10ec:8168
                              IF: enp2s0f2 state: down mac: <filter>
                              Card-2: Qualcomm Atheros AR9462 Wireless Network Adapter
                              driver: ath9k bus-ID: 03:00.0 chip-ID: 168c:0034
                              IF: wlp3s0 state: up mac: <filter>
                    Drives:    HDD Total Size: 320.1GB (4.3% used)
                              ID-1: /dev/sda model: ST320LT020 size: 320.1GB serial: <filter>
                    Partition: ID-1: / size: 20G used: 7.6G (42%) fs: btrfs dev: /dev/sda2
                              ID-2: /boot size: 2.9G used: 301M (12%) fs: ext4 dev: /dev/sda1
                              ID-3: /home size: 271G used: 366M (1%) fs: btrfs dev: /dev/sda4
                              ID-4: swap-1 size: 5.24GB used: 0.00GB (0%) fs: swap dev: /dev/sda3
                    RAID:      System: supported: N/A
                              No RAID devices: /proc/mdstat, md_mod kernel module present
                              Unused Devices: none
                    Sensors:   System Temperatures: cpu: 44.0C mobo: 41.0C
                              Fan Speeds (in rpm): cpu: N/A
                    Info:      Processes: 199 Uptime: 13 min Memory: 748.8/3739.8MB
                              Init: systemd v: 237 runlevel: 5 Gcc sys: N/A
                              Client: Shell (bash 4.4.191 running in konsole) inxi: 2.3.56
                    seems to loaded .

                    Code:
                    vinny@vinny-Aspire-V5-431:~$ cat /sys/module/zswap/parameters/enabled
                    Y
                    vinny@vinny-Aspire-V5-431:~$ dmesg | grep -i zswap
                    [    0.000000] Command line: BOOT_IMAGE=/vmlinuz-4.15.0-38-generic root=UUID=f8af6b27-e7bf-4a46-982b-95f0cb88836e ro rootflags=subvol=@ quiet splash zswap.enabled=1 zswap.compressor=lz4 vt.handoff=1
                    [    0.000000] Kernel command line: BOOT_IMAGE=/vmlinuz-4.15.0-38-generic root=UUID=f8af6b27-e7bf-4a46-982b-95f0cb88836e ro rootflags=subvol=@ quiet splash zswap.enabled=1 zswap.compressor=lz4 vt.handoff=1
                    [    1.873373] zswap: loaded using pool lz4/zbud


                    VINNY
                    i7 4core HT 8MB L3 2.9GHz
                    16GB RAM
                    Nvidia GTX 860M 4GB RAM 1152 cuda cores

                    Comment

                    Working...
                    X