Skip to content

Automatically configure zram as swap on a machine, using sensible defaults, with the ability to tweak it to your needs.

License

Notifications You must be signed in to change notification settings

ksandom/auto-zram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

auto-zram

Automatically configure zram as swap on a machine, using sensible defaults, with the ability to tweak it to your needs. You shouldn't need to modify anything, but can if you want to.

Originally inspired by this gist which configures zram on a Raspberry Pi with exact specifications.

Install

Currently the install method is assumed to be systemd, however the script has been structured to be easy to slot right in to a traditional init.d style service management.

sudo make install

Uninstall

Once again, this is assumed to be on a systemd system, but could easily be adapted.

sudo make uninstall

Using it

All the normal systemd stuff

What state is is in right now?

sudo systemctl status auto-zram.service

Start it. (Configure zram as swap.)

sudo systemctl start auto-zram.service

Stop it. (Revert to what ever settings you would have if auto-zram was not in use.)

sudo systemctl stop auto-zram.service

Scroll through logs of what state it was in at various points in time. You'll probably want to press END on your keyboard to see the latest run.

journalctl -u auto-zram.service

Figuring out what state stuff is in, or would be

What state does the current config produce?

$ auto-zram status
Config
  % of memory to use    80
  device                zram0
  device config         /sys/devices/virtual/block/zram0
  used config file      true
  config file           /etc/auto-zram.sh
Derived config/knowledge
  Memory (MB)
    total               7977
    maxPhysicalUsage    6381
    virtualSize         12762
    uncompressed        1596
    ---
    totalPossible       14358

  CPU
    coresAvailable      2
    coresToUse          1

State
  General
    module              loaded
    device              mounted

  Mount
    NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    zram0                  252:0    0 12,6G  0 disk [SWAP]

  Swap
                  total        used        free      shared  buff/cache   available
    Swap:         12921           0       12921

NOTE that this is not necessarily what is in memory at this moment. For that use the journalctl -u auto-zram.service command above.

Or via systemd

journalctl -u auto-zram.service

See what the state of the machine would look like if you specified 40 as your percentageOfRamToUse.

auto-zram prototype 40

Special notes

  • You should only start or stop auto-zram when you have enough physical RAM to spare to cover everything that is currently in swap. If you don't, you'll probably have one of those "Remember that time when..." stories to tell.
  • If you'd like to experiment with compression ratios, please read here first.

Contributions

Pull requests welcome :)

About

Automatically configure zram as swap on a machine, using sensible defaults, with the ability to tweak it to your needs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published