Swap & zram to improve performance

Forum Forums New users New Users and General Questions Swap & zram to improve performance

Tagged: ,

  • This topic has 16 replies, 3 voices, and was last updated Dec 21-3:39 am by SamK.
Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #3956
    Member
    andfree

      I’m trying to follow this tip:

    • Use one or more swap areas. Combining a disk based swap with a zram one can produce a worthwhile increase in performance. Additionally, adjusting the way in swap space is used can make a difference to the system responsiveness. This post might be a starting point: ZRAM Swap Activation
    • I ran these commands:

      sudo cp /usr/local/bin/zram  /etc/init.d/zram
      sudo update-rc.d zram defaults

      I rebooted and:

      $ lsmod | grep zram
      zram                   12902  0 
      lz4_compress            2442  1 zram
      $ sudo swapon --summary
      Filename				Type		Size	Used	Priority
      /dev/sda2                              	partition	2120576	0	-1

      And now, what?

      $ inxi -Fxz
      System:    Host: antix1 Kernel: 4.0.5-antix.3-486-smp i686 bits: 32 gcc: 4.9.3
                 Desktop: IceWM 1.3.8
                 Distro: antiX-15.1_386-full Killah P 18 February 2016
      Machine:   Device: laptop System: TOSHIBA product: Satellite 2450 v: PS245E-03TE0-GK serial: N/A
                 Mobo: TOSHIBA model: Portable PC v: Version A0 serial: N/A
                 BIOS: TOSHIBA v: Version 1.30 date: 03/20/2003
      CPU:       Single core Intel Pentium 4 (-UP-) 
                 arch: Netburst Willamette rev.7 cache: 512 KB
                 flags: (pae sse sse2) bmips: 5586 speed: 2793 MHz (max)
      Graphics:  Card: NVIDIA NV17M [GeForce4 420 Go] bus-ID: 01:00.0
                 Display Server: X.Org 1.16.4
                 drivers: nouveau (unloaded: modesetting,fbdev,vesa)
                 Resolution: 1024x768@60.00hz
                 OpenGL: renderer: Mesa DRI nv17 x86/MMX/SSE2
                 version: 1.2 Mesa 10.3.2 Direct Render: Yes
      Audio:     Card Intel 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) AC'97 Audio Controller
                 driver: snd_intel8x0 ports: be00 bdc0 bus-ID: 00:1f.5
                 Sound: Advanced Linux Sound Architecture v: k4.0.5-antix.3-486-smp
      Network:   Card: Realtek RTL-8100/8101L/8139 PCI Fast Ethernet Adapter
                 driver: 8139too v: 0.9.28 port: ce00 bus-ID: 02:09.0
                 IF: eth0 state: unknown speed: 100 Mbps duplex: full mac: <filter>
      Drives:    HDD Total Size: 100.0GB (81.7% used)
                 ID-1: /dev/sda model: TOSHIBA_MK1032GA size: 100.0GB
      Partition: ID-1: / size: 90G used: 75G (88%) fs: ext4 dev: /dev/sda1
                 ID-2: swap-1 size: 2.17GB used: 0.00GB (0%) fs: swap dev: /dev/sda2
      Sensors:   System Temperatures: cpu: 59.0C mobo: N/A
                 Fan Speeds (in rpm): cpu: N/A
      Info:      Processes: 106 Uptime: 29 min Memory: 309.6/1005.2MB
                 Init: SysVinit runlevel: 5 Gcc sys: 4.9.2
                 Client: Shell (bash 4.3.301) inxi: 2.3.43 
      #3961
      Forum Admin
      SamK
        Helpful
        Up
        0
        ::

        I cannot reproduce your results. The outcome of copying and pasting the commands from your post work OK here using the shipped zram file, as shown below.

        Booted live on a system that has no swap space.

        sudo swapon --summary
        nothing returned

        Copy and setup zram in init.d.

        sudo cp /usr/local/bin/zram  /etc/init.d/zram
        nothing returned
        
        sudo update-rc.d zram defaults
        nothing returned

        zram started via manual command to simulate reboot.

        sudo /etc/init.d/zram start
        zram devices probed successfully
        Setting up swapspace version 1, size = 204 MiB (213909504 bytes)
        no label, UUID=blah
        Setting up swapspace version 1, size = 204 MiB (213909504 bytes)
        no label, UUID=blahblah
        Setting up swapspace version 1, size = 204 MiB (213909504 bytes)
        no label, UUID=blahblahblah.

        Verify zram swapspaces are available.

        sudo swapon --summary
        Filename				Type		Size	Used	Priority
        /dev/zram1                             	partition	208896	0	100
        /dev/zram2                             	partition	208896	0	100
        /dev/zram3                             	partition	208896	0	100

        After a shutdown and cold boot.
        Reported during boot-up text phase.

        ...
        zram devices probed successfully
        Setting up swapspace version 1, size = 204 MiB (213909504 bytes)
        no label, UUID=blah
        Setting up swapspace version 1, size = 204 MiB (213909504 bytes)
        no label, UUID=blahblah
        Setting up swapspace version 1, size = 204 MiB (213909504 bytes)
        no label, UUID=blahblahblah.
        ...

        After completion of boot-up.

        sudo swapon --summary
        Filename				Type		Size	Used	Priority
        /dev/zram1                             	partition	208896	0	100
        /dev/zram2                             	partition	208896	0	100
        /dev/zram3                             	partition	208896	0	100

        So my results show zram swapspaces can be activated manually, and automatically during boot-up.

        Things to look at…
        Try to start zram manually

        If starting manually works, check the update-rc.d command created the appropriate links.

        ls -1lh --recursive /etc/*/*zram 
        -rwxr-xr-x 1 root root 2.8K Dec 18 13:45 /etc/init.d/zram
        lrwxrwxrwx 1 root root   14 Dec 18 13:46 /etc/rc0.d/K01zram -> ../init.d/zram
        lrwxrwxrwx 1 root root   14 Dec 18 13:46 /etc/rc1.d/K01zram -> ../init.d/zram
        lrwxrwxrwx 1 root root   14 Dec 18 13:46 /etc/rc2.d/S02zram -> ../init.d/zram
        lrwxrwxrwx 1 root root   14 Dec 18 13:46 /etc/rc3.d/S02zram -> ../init.d/zram
        lrwxrwxrwx 1 root root   14 Dec 18 13:46 /etc/rc4.d/S02zram -> ../init.d/zram
        lrwxrwxrwx 1 root root   14 Dec 18 13:46 /etc/rc5.d/S02zram -> ../init.d/zram
        lrwxrwxrwx 1 root root   14 Dec 18 13:46 /etc/rc6.d/K01zram -> ../init.d/zram

        If starting manually fails, check that zram is configured in your version of the kernel.This is what is returned for the kernel used here.

        zgrep ZRAM /boot/config-4.10.5-antix.1-486-smp 
        CONFIG_ZRAM=m
        #3963
        Member
        andfree
          Helpful
          Up
          0
          ::
          $ sudo /etc/init.d/zram start
          zram devices probed successfully
          $ ls -1lh --recursive /etc/*/*zram
          -rwxr-xr-x 1 root root 2.8K Dec 18 12:41 /etc/init.d/zram
          lrwxrwxrwx 1 root root   14 Dec 18 12:41 /etc/rc0.d/K01zram -> ../init.d/zram
          lrwxrwxrwx 1 root root   14 Dec 18 12:41 /etc/rc1.d/K01zram -> ../init.d/zram
          lrwxrwxrwx 1 root root   14 Dec 18 12:41 /etc/rc2.d/S01zram -> ../init.d/zram
          lrwxrwxrwx 1 root root   14 Dec 18 12:41 /etc/rc3.d/S01zram -> ../init.d/zram
          lrwxrwxrwx 1 root root   14 Dec 18 12:41 /etc/rc4.d/S01zram -> ../init.d/zram
          lrwxrwxrwx 1 root root   14 Dec 18 12:41 /etc/rc5.d/S01zram -> ../init.d/zram
          lrwxrwxrwx 1 root root   14 Dec 18 12:41 /etc/rc6.d/K01zram -> ../init.d/zram
          $ zgrep ZRAM /boot/config-4.0.5-antix.3-486-smp
          CONFIG_ZRAM=m
          CONFIG_ZRAM_LZ4_COMPRESS=y
          # CONFIG_ZRAM_DEBUG is not set
          #3972
          Forum Admin
          SamK
            Helpful
            Up
            0
            ::

            I have never tested zram on a P4 CPU so have no notes on it. Here is a link to reporting a problem on P4 but it is unresolved.
            https://mxlinux.org/forum/viewtopic.php?t=40334

            Your results show:
            • The kernel is configured for zram,
            • The links exist to start zram automatically during boot-up,
            • The script /etc/init.d/zram is being run when you issue the start command manually, i.e. it returns a message from that script.

            So we know the zram script is getting as far as the message “zram devices probed successfully

            After starting manually, and receiving the message “zram devices probed successfully“, is the file /dev/zram0 present?

            #3975
            Member
            andfree
              Helpful
              Up
              0
              ::

              After starting manually, and receiving the message “zram devices probed successfully“, is the file /dev/zram0 present?

              I’ll see tomorrow, when I’ll be at the toshiba laptop. Now, about the compaq laptop:

              $ inxi -Fxz
              System:    Host: antix1 Kernel: 4.4.10-antix.1-486-smp i686
                         bits: 32 gcc: 4.9.3
                         Desktop: IceWM 1.3.8
                         Distro: antiX-16_386-full Berta Cáceres 26 June 2016
              Machine:   Device: laptop System: Hewlett-Packard product: Presario 2100 v: KE.M1.54 serial: N/A
                         Mobo: Hewlett-Packard model: 002A v: NS570 Version PQ1A74 serial: N/A
                         BIOS: Phoenix v: KE.M1.54 date: 12/17/20022
              CPU:       Single core Mobile Intel Celeron (-UP-) 
                         arch: Netburst Willamette rev.7 cache: 256 KB
                         flags: (pae sse sse2) bmips: 3189 speed: 1594 MHz (max)
              Graphics:  Card: Advanced Micro Devices [AMD/ATI] RS200M [Radeon IGP 330M/340M/345M/350M]
                         bus-ID: 01:05.0
                         Display Server: X.Org 1.16.4
                         drivers: ati,radeon (unloaded: modesetting,fbdev,vesa)
                         Resolution: 1024x768@60.00hz
                         OpenGL: renderer: Gallium 0.4 on llvmpipe (LLVM 3.5, 128 bits)
                         version: 3.0 Mesa 10.3.2 Direct Render: Yes
              Audio:     Card ULi M5451 PCI AC-Link Controller Audio Device
                         driver: snd_ali5451 port: 1000 bus-ID: 00:06.0
                         Sound: ALSA v: k4.4.10-antix.1-486-smp
              Network:   Card-1: National DP83815 (MacPhyter) Ethernet Controller
                         driver: natsemi port: 2400 bus-ID: 00:12.0
                         IF: eth0 state: down mac: <filter>
                         Card-2: Atheros TP-Link TL-WN821N v2 802.11n [Atheros AR9170]
                         driver: carl9170 usb-ID: 001-002
                         IF: wlan0 state: N/A mac: N/A
              Drives:    HDD Total Size: 60.0GB (41.6% used)
                         ID-1: /dev/sda model: TOSHIBA_MK6025GA size: 60.0GB
              Partition: ID-1: / size: 53G used: 22G (43%) fs: ext4 dev: /dev/sda1
                         ID-2: swap-1 size: 2.18GB used: 0.00GB (0%) fs: swap dev: /dev/sda2
              Sensors:   System Temperatures: cpu: 45.0C mobo: N/A
                         Fan Speeds (in rpm): cpu: N/A
              Info:      Processes: 131 Uptime: 6 min Memory: 139.1/488.4MB
                         Init: SysVinit runlevel: 5 Gcc sys: 4.9.2
                         Client: Shell (bash 4.3.301) inxi: 2.3.43
              $ sudo /etc/init.d/zram start 
              zram devices probed successfully
              $ ls -1lh --recursive /etc/*/*zram
              -rwxr-xr-x 1 root root 2.8K Dec 18 08:44 /etc/init.d/zram
              lrwxrwxrwx 1 root root   14 Dec 18 08:44 /etc/rc0.d/K01zram -> ../init.d/zram
              lrwxrwxrwx 1 root root   14 Dec 18 08:44 /etc/rc1.d/K01zram -> ../init.d/zram
              lrwxrwxrwx 1 root root   14 Dec 18 08:44 /etc/rc2.d/S01zram -> ../init.d/zram
              lrwxrwxrwx 1 root root   14 Dec 18 08:44 /etc/rc3.d/S01zram -> ../init.d/zram
              lrwxrwxrwx 1 root root   14 Dec 18 08:44 /etc/rc4.d/S01zram -> ../init.d/zram
              lrwxrwxrwx 1 root root   14 Dec 18 08:44 /etc/rc5.d/S01zram -> ../init.d/zram
              lrwxrwxrwx 1 root root   14 Dec 18 08:44 /etc/rc6.d/K01zram -> ../init.d/zram
              $ zgrep ZRAM /boot/config-4.4.10-antix.1-486-smp
              CONFIG_ZRAM=m
              CONFIG_ZRAM_LZ4_COMPRESS=y
              $ lsmod | grep zram
              zram                   17197  0 
              lz4_compress            2606  1 zram
              $ sudo swapon --summary
              Filename				Type		Size	Used	Priority
              /dev/sda2                              	partition	2128608	0	-1

              A zram0 file exists in the /dev directory. What about these results?

              • This reply was modified 5 years, 4 months ago by andfree.
              #3979
              Forum Admin
              SamK
                Helpful
                Up
                0
                ::

                Now, about the compaq laptop:
                What about these results?

                The results are the same as those of the Toshiba.

                A test bed system here is a single core Celeron from about 1997 which is running zram without a problem, and I can’t replicate the problem on that system either. Its beginning to look like the problem may be local to you in some way.

                This command output might be helpful.
                nproc --all
                On the Celeron here it returns “1

                #3994
                Member
                andfree
                  Helpful
                  Up
                  0
                  ::

                  Its beginning to look like the problem may be local to you in some way.

                  I suppose I do something wrong.

                  About the celeron laptop:

                  $ nproc --all
                  1
                  • This reply was modified 5 years, 4 months ago by andfree.
                  • This reply was modified 5 years, 4 months ago by andfree.
                  #4012
                  Forum Admin
                  SamK
                    Helpful
                    Up
                    0
                    ::

                    It might be worth trying the attached zram file to replace the one that ships in antiX. I wrote it some years back to use instead of the one in the antiX ISO, which sets up an incorrect number of zram swapspaces. It is used on the Celeron system here (and others).

                    Before testing

                    Verify the status of zram
                    lsmod | grep zram
                    
                    Identify running swapspaces
                    swapon --show
                    
                    Turn off all swapspaces
                    sudo swapoff --all
                    
                    Stop zram
                    sudo /etc/init.d/zram stop
                    
                    Verify the status of zram
                    lsmod | grep zram
                    expected to return nothing
                    
                    Identify running swapspaces
                    swapon --show
                    expected to return nothing

                    To test
                    (Re)move /etc/init.d/zram to get it out of the way

                    Extract the replacement file from the zip file

                    Copy the extracted file to /etc/init.d/zram
                    Ownership: root:root
                    Permissions: rwxr-xr-x

                    Start zram
                    sudo /etc/init.d/zram start
                    expected to return "Loading zram kernel module succeeded" + list of zram swapspaces created.
                    
                    Verify the status of zram
                    lsmod | grep zram
                    expected to return zram module details
                    
                    Identify running swapspaces
                    swapon --show
                    expected to return list of zram devices and details
                    Attachments:
                    #4035
                    Member
                    andfree
                      Helpful
                      Up
                      0
                      ::

                      Now, about the P4 laptop:

                      A zram0 file already exists in the /dev directory, too.

                      xxx@antix1:~
                      $ nproc --all
                      1
                      xxx@antix1:~
                      $ lsmod | grep zram
                      zram                   12902  0 
                      lz4_compress            2442  1 zram
                      xxx@antix1:~
                      $ swapon --show
                      NAME      TYPE      SIZE USED PRIO
                      /dev/sda2 partition   2G   0B   -1
                      xxx@antix1:~
                      $ sudo swapoff --all 
                      xxx@antix1:~
                      $ sudo /etc/init.d/zram stop
                      xxx@antix1:~
                      $ lsmod | grep zram
                      xxx@antix1:~
                      $ swapon --show
                      xxx@antix1:~
                      $ sudo rm /etc/init.d/zram
                      xxx@antix1:~ 
                      $ sudo cp zram /etc/init.d/zram
                      xxx@antix1:~
                      $ sudo /etc/init.d/zram start
                      Loading zram kernel module succeeded
                      Setting up swapspace version 1, size = 148568 KiB
                      LABEL=SWAP_ZRAM0, UUID=9a557970-a8a9-4b47-bec7-9a504a5228fe
                      xxx@antix1:~
                      $ lsmod | grep zram
                      zram                   12902  1 
                      lz4_compress            2442  1 zram
                      xxx@antix1:~
                      $ swapon --show
                      NAME       TYPE        SIZE USED PRIO
                      /dev/zram0 partition 145.1M   0B  100
                      xxx@antix1:~
                      $ 

                      About the celeron laptop, later.

                      #4047
                      Member
                      andfree
                        Helpful
                        Up
                        0
                        ::

                        And now, about the celeron laptop:

                        yyy@antix1:~
                        $ lsmod | grep zram
                        zram                   17197  0 
                        lz4_compress            2606  1 zram
                        yyy@antix1:~
                        $ swapon --show
                        NAME      TYPE      SIZE USED PRIO
                        /dev/sda2 partition   2G   0B   -1
                        yyy@antix1:~
                        $ sudo swapoff --all
                        [sudo] password for yyy: 
                        yyy@antix1:~
                        $ sudo /etc/init.d/zram stop
                        yyy@antix1:~
                        $ lsmod | grep zram
                        yyy@antix1:~
                        $ swapon --show
                        yyy@antix1:~
                        $ sudo rm /etc/init.d/zram
                        yyy@antix1:~
                        $ sudo cp zram /etc/init.d/zram
                        yyy@antix1:~
                        $ sudo /etc/init.d/zram start
                        Loading zram kernel module succeeded
                        Setting up swapspace version 1, size = 28448 KiB
                        LABEL=SWAP_ZRAM0, UUID=6ea6a8fc-1106-4234-a41a-08e9ff63fbfd
                        yyy@antix1:~
                        $ lsmod | grep zram
                        zram                   17197  1 
                        lz4_compress            2606  1 zram
                        yyy@antix1:~
                        $ swapon --show
                        NAME       TYPE       SIZE USED PRIO
                        /dev/zram0 partition 27.8M   0B  100
                        yyy@antix1:~
                        $ 
                        #4061
                        Forum Admin
                        SamK
                          Helpful
                          Up
                          0
                          ::

                          So with my version of the zram script installed you have working zram swapspaces on both the P4 and Celeron when you start the swapspaces manually.

                          Now you just need to confirm the zram swapspace is automatically available after a reboot i.e. without starting it manually.

                          Explanation:
                          The default action of zram is to set up a swapspace per CPU e.g. 4 swapspaces for a quad core, 1 swapspace for a single core, etc.

                          The version of the zram script shipped in the ISO does not hounour the zram default action. It sets up 1 fewer swapspaces than the number of CPUs i.e. 3 for a quad core. That is a problem when the system has only a single CPU.

                          My version of the zram script honours the zram default action. It sets up 1 swapspace per CPU for single and multiple CPU systems e.g. 4 swapspaces for a quad core, 1 swapspace for a single core, etc.

                          #4062
                          Forum Admin
                          anticapitalista
                            Helpful
                            Up
                            0
                            ::

                            As soon as it is confirmed that Samk’s version works for you, I’ll replace the existing one with Sam’s.

                            Philosophers have interpreted the world in many ways; the point is to change it.

                            antiX with runit - leaner and meaner.

                            #4080
                            Member
                            andfree
                              Helpful
                              Up
                              0
                              ::

                              After rebooting the P4 system, without starting the zram swapspace manually:

                              xxx@antix1:~
                              $ sudo swapon --summary
                              [sudo] password for xxx: 
                              Filename				Type		Size	Used	Priority
                              /dev/sda2                              	partition	2120576	0	-1
                              /dev/zram0                             	partition	237872	0	100
                              xxx@antix1:~
                              $ 

                              Have we finished with it? Is this a nice swapspace?

                              #4086
                              Forum Admin
                              SamK
                                Helpful
                                Up
                                0
                                ::

                                Have we finished with it? Is this a nice swapspace?

                                That report shows everything is working as expected. So yes, we have finished.

                                You have 2 swapspaces, on both the P4 and Celeron. On each machine, 1 is disk based, 1 is RAM based. Both disk swapspace (/dev/sda2) and the RAM swapspace (/dev/zram0) are made available automatically as part of the boot process, so you do not need to do anything manually.

                                Now you can go and explore what degree of benefit you get, which is largely dependent on the capability of your kit, the software you run and the tasks you use the software for. It is different for every user because everyone has different hardware, working patterns, and habits.

                                A couple of links that might be helpful to you:
                                Tips for Improving Performance on Ancient Kit
                                ZRAM Misconceptions and Doubts

                                In the longer term future you might want to think about whether the disk swapspace partition suits your needs e.g. does it use too much of your overall disk space? It is possible to use a swap file instead of a swap partition but there are lots of things to think about before going along that route. So these type of ideas are for another time and place.

                                #4097
                                Forum Admin
                                anticapitalista
                                  Helpful
                                  Up
                                  0
                                  ::

                                  SamK’s zram now in the antix-goodies package. Already in the repos.

                                  Philosophers have interpreted the world in many ways; the point is to change it.

                                  antiX with runit - leaner and meaner.

                                Viewing 15 posts - 1 through 15 (of 17 total)
                                • You must be logged in to reply to this topic.