{"id":13653887,"url":"https://github.com/Nefelim4ag/systemd-swap","last_synced_at":"2025-04-23T06:32:08.376Z","repository":{"id":15840298,"uuid":"18580300","full_name":"nefelim4ag/systemd-swap","owner":"nefelim4ag","description":"Script for creating hybrid swap space from zram swaps, swap files and swap partitions.","archived":false,"fork":false,"pushed_at":"2022-01-19T12:12:28.000Z","size":397,"stargazers_count":540,"open_issues_count":15,"forks_count":79,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-08T20:54:10.617Z","etag":null,"topics":["btrfs","shell","swap","systemd","systemd-swap","zram","zswap"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"indutny/des.js","license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nefelim4ag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-09T00:51:38.000Z","updated_at":"2025-04-04T15:09:08.000Z","dependencies_parsed_at":"2022-07-21T11:59:52.213Z","dependency_job_id":null,"html_url":"https://github.com/nefelim4ag/systemd-swap","commit_stats":null,"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nefelim4ag%2Fsystemd-swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nefelim4ag%2Fsystemd-swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nefelim4ag%2Fsystemd-swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nefelim4ag%2Fsystemd-swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nefelim4ag","download_url":"https://codeload.github.com/nefelim4ag/systemd-swap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250385334,"owners_count":21421901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["btrfs","shell","swap","systemd","systemd-swap","zram","zswap"],"created_at":"2024-08-02T02:01:19.839Z","updated_at":"2025-04-23T06:32:03.360Z","avatar_url":"https://github.com/nefelim4ag.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# systemd-swap\n[![Code Style: Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n\n## ⚠️ Current code quality and commit frequency is low ⚠️\n\n### Users should migrate to [systemd/zram-generator](https://github.com/systemd/zram-generator) since zram should be enough in most systems\n\nScript to manage swap on:\n\n- [zswap](https://www.kernel.org/doc/Documentation/vm/zswap.txt) - Enable/Configure\n- [zram](https://www.kernel.org/doc/Documentation/blockdev/zram.txt) - Autoconfigurating for swap\n- files - (sparse files for saving space, supports btrfs)\n- block devices - auto find and do swapon\n\n:information_source: It is configurable in `/etc/systemd/swap.conf`.\n\nAdditional terms:\n\n- **SwapFC** (File Chunked) - provides a dynamic swap file allocation/deallocation\n\n## File location\n\n```text\n/etc/systemd/swap.conf\n/usr/lib/systemd/system/systemd-swap.service\n/usr/bin/systemd-swap\n```\n\n## Please don't forget to enable and start with\n\n```shell\nsudo systemctl enable --now systemd-swap\n```\n\n## Install\n\n- \u003cimg src=\"https://www.monitorix.org/imgs/archlinux.png\" weight=\"16\" height=\"16\"\u003e **Arch Linux**: in the [community](https://www.archlinux.org/packages/community/any/systemd-swap/) repo.\n\n- \u003cimg src=\"https://www.monitorix.org/imgs/debian.png\" weight=\"16\" height=\"16\"\u003e **Debian based distros**\n\n  ```shell\n  git clone https://github.com/Nefelim4ag/systemd-swap.git\n  cd systemd-swap\n  make deb\n  sudo apt install ./systemd-swap_*_all.deb\n  ```\n\n- \u003cimg src=\"https://www.monitorix.org/imgs/fedora.png\" weight=\"16\" height=\"16\"\u003e **Fedora based distros**\n\n  ```shell\n  sudo dnf copr enable zeno/systemd-swap\n  sudo dnf install systemd-swap\n  ```\n  \n  or\n  \n  ```shell\n  git clone https://github.com/Nefelim4ag/systemd-swap.git\n  cd systemd-swap\n  make rpm\n  sudo dnf install ./systemd-swap-*noarch.rpm\n\n- **Manual**\n\n  Install dependencies:\n  - `python3` \u003e= 3.7\n  - `python3` packages: `systemd-python` and `sysv_ipc`\n\n  ```shell\n  git clone https://github.com/Nefelim4ag/systemd-swap.git\n  cd systemd-swap\n  sudo make install\n\n  # or into /usr/local:\n  sudo make prefix=/usr/local install\n  ```\n\n## About configuration\n\n**Q**: Do we need to activate both zram and zswap?\\\n**A**: Nope, it's useless, as zram is a compressed RAM DISK, but zswap is a compressed _\"writeback\"_ CACHE on swap file/disk. Also having both activated can lead to inverse LRU as noted [here](https://askubuntu.com/questions/471912/zram-vs-zswap-vs-zcache-ultimate-guide-when-to-use-which-one/472227#472227)\n\n**Q**: Do I need to use `swapfc_force_use_loop` on swapFC?\\\n**A**: Nope, as you wish really, native swapfile should work faster and it's safer in OOM condition in comparison to loop backed scenario.\n\n**Q**: When would we want a certain configuration?\\\n**A**: In most cases zram is enough since it on average compresses 2-3x and is much faster than disk based swap.\n\n**Q**: How many zram devices should one use?\n**A**: If you are not using an ancient kernel (pre 4.7) there's no benefit from using multiple zram devices.\n\n**Q**: Can we use this to enable hibernation?\\\n**A**: Nope as hibernation wants a persistent fs blocks and wants access to swap data directly from disk, this will not work on: _swapfc_ (without some magic of course, see [#85](https://github.com/Nefelim4ag/systemd-swap/issues/85)).\n\n## Switch on systemd-swap:s automatic swap management\n\n- Enable swapfc if wanted (note, you should **never** use zram and zswap at the same time)\n\n  ```shell\n  vim /etc/systemd/swap.conf.d/overrides.conf\n  ```\n\n  ```ini\n  swapfc_enabled=1\n  ```\n\n- Stop any external swap:\n\n  ```shell\n  sudo swapoff -a\n  ```\n\n- Remove swap entry from fstab:\n\n  ```shell\n  vim /etc/fstab\n  ```\n\n- Remove your swap\n\n  ```shell\n  # For Ubuntu\n  sudo rm -f /swapfile\n\n  # For Centos 7 (if using a swap partition and lvm)\n  lvremove -Ay /dev/centos/swap\n  lvextend -l +100%FREE centos/root\n  ```\n\n- Remove swap from Grub:\n\n  ```shell\n  # For Ubuntu remove resume* in grub\n  vim /etc/default/grub\n\n  # For Centos 7 remove rd.lvm.lv=centos/swap*\n  vim /etc/default/grub\n\n  # For Manjaro remove resume* in grub \u0026 mkinitcpio\n  vim /etc/default/grub\n  vim /etc/mkinitcpio.conf\n  ```\n\n  ```shell\n  # For Ubuntu\n  update-grub\n\n  # For Centos 7\n  grub2-mkconfig -o /boot/grub2/grub.cfg\n\n  # For Manjaro\n  update-grub\n  mkinitcpio -P\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNefelim4ag%2Fsystemd-swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNefelim4ag%2Fsystemd-swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNefelim4ag%2Fsystemd-swap/lists"}