From Fedora Project Wiki
No edit summary
Line 2: Line 2:


== Summary ==
== Summary ==
<!-- A sentence or two summarizing what this change is and what it will do. This information is used for the overall changeset summary page for each release.
Note that motivation for the change should be in the Benefit to Fedora section below, and this part should answer the question "What?" rather than "Why?". -->
Swap is good, unless it's slow. ZRAM is a compressed RAM disk, a kernel feature that presents a /dev/zramX block device that can be formatted as a swap device. The ZRAM block device can be assigned a size, but the actual RAM consumption is dynamically allocated and deallocated on demand.


This change will result in the inclusion of an upstream systemd rust-zram-generator on Fedora (all editions and spins). The presence of the generator will not enable swap-on-zram. Enabling swap-on-ZRAM will further require presence of a properly formatted configuration file.
Swap is useful, except when slow.[1] ZRAM is a RAM disk that uses always-on compression [2]. It has a size assigned at create time, but the RAM usage is dynamically allocated and deallocated, on demand. This ZRAM block device behaves like any other, it can be formatted with a file system or mkswap, which is the intention with this change proposal.


This change proposal recommends all Fedora editions and spins opt into the feature. But at the time of this proposal the opt in candidates are:
There is more than one change indicated in this proposal. Each is opt-in (owner assumes editions/spins are to be excluded unless they ask to be included):


- Fedora Workstation edition
1. Include systemd rust-zram-generator[3]. This does not enable swap-on-ZRAM. It only makes the generator available.</br >
- All Fedora install ISOs
2. Include a default zram-generator configuration. If present, it enables swap-on-ZRAM during startup.</br >
3. Do not create swap partition/LV for default installations.


Fedora installation ISOs have been using an Anaconda provided systemd service unit and script, to setup swap-on-ZRAM, for several years. Likewise, Fedora IoT uses swap-on-ZRAM since inception, using its own systemd unit and script (functionally similar to Anaconda but in its own package). This proposal recommends converging on a single implementation.


The kernel supports multiple (up to 32) swap devices. The
[1]</br >
There is a tl;dr section at the top. Highly recommend reading the whole article.</br >
In defence of swap: common misconceptions</br >
https://chrisdown.name/2018/01/02/in-defence-of-swap.html
 
[2]</br >
https://www.kernel.org/doc/Documentation/blockdev/zram.txt
 
[3]</br >
https://github.com/systemd/zram-generator
 




== Owner ==
== Owner ==
* Name: [[User:chrismurphy| Chris Murphy]]
* Name: [[User:chrismurphy| Chris Murphy]]
* Email: chris@fedoraproject.org
* Email: chrismurphy@fedoraproject.org
<!--- UNCOMMENT only for Changes with assigned Shepherd (by FESCo)
<!--- UNCOMMENT only for Changes with assigned Shepherd (by FESCo)
* FESCo shepherd: [[User:FASAccountName| Shehperd name]] <email address>
* FESCo shepherd: [[User:FASAccountName| Shehperd name]] <email address>
Line 31: Line 38:
== Current status ==
== Current status ==
[[Category:ChangePageIncomplete]]
[[Category:ChangePageIncomplete]]
<!-- When your change proposal page is completed and ready for review and announcement -->
<!-- remove Category:ChangePageIncomplete and change it to Category:ChangeReadyForWrangler -->
<!-- remove Category:ChangePageIncomplete and change it to Category:ChangeReadyForWrangler -->
<!-- The Wrangler announces the Change to the devel-announce list and changes the category to Category:ChangeAnnounced (no action required) -->
<!-- After review, the Wrangler will move your page to Category:ChangeReadyForFesco... if it still needs more work it will move back to Category:ChangePageIncomplete-->


[[Category:SystemWideChange]]
[[Category:SystemWideChange]]


* Targeted release: [[Releases/<number> | Fedora <number> ]]  
* Targeted release: [[Releases/33 | Fedora 33 ]]  
* Last updated: <!-- this is an automatic macro — you don't need to change this line -->  {{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}  
* Last updated: <!-- this is an automatic macro — you don't need to change this line -->  {{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}  
<!-- After the change proposal is accepted by FESCo, tracking bug is created in Bugzilla and linked to this page
Bugzilla states meaning as usual:
ASSIGNED -> accepted by FESCo with on going development
MODIFIED -> change is substantially done and testable
ON_QA -> change is code completed and could be tested in the Beta release (optionally by QA)
CLOSED as NEXTRELEASE -> change is completed and verified and will be delivered in next release under development
-->
* FESCo issue: <will be assigned by the Wrangler>
* FESCo issue: <will be assigned by the Wrangler>
* Tracker bug: <will be assigned by the Wrangler>
* Tracker bug: <will be assigned by the Wrangler>
Line 53: Line 50:
== Detailed Description ==
== Detailed Description ==


<!-- Expand on the summary, if appropriateA couple sentences suffices to explain the goal, but the more details you can provide the better. -->
==== Basic function: ====
 
The system will use RAM normally up until it's full, and then start paging out to the swap-on-ZRAM device, just as if it were a real swap. But, there is no free lunch. The ZRAM driver starts to allocate memory at roughly 1/2 the rate of page outs, due to compression. This means swap is not as effective at page eviction, the rate is ~50% instead of 100%. But it is orders of magnitude faster that disk based swap.
 
ZRAM has about 0.1% overhead or ~1MiB/1GiB. If the workload never touches swap, living entirely inside RAM, the overhead is the sole cost, there is no preallocation of RAM.
 
==== Default configuration: ====
 
Always create a ZRAM device regardless, of RAM size, using a ZRAM to RAM ratio of 1:2, and capped to 4GiB [4], with a higher than typical swap priority [5].
 
 
[4]</br >
RFE: should be able to set a cap on zram device size</br >
https://github.com/systemd/zram-generator/issues/10
 
[5]</br >
RFE: should set priority #8 </br >
https://github.com/systemd/zram-generator/issues/8
 
These values seem reasonable, based on prior work. Anaconda has two examples in which it sets swap size to 50% RAM: the no hibernation case, common outside x86; and it's own current swap-on-ZRAM implementation. Fedora IoT's implementation uses a ZRAM to RAM ratio of 1:2, or 50% as well.  
   
 
==== In the summary, three changes are listed. What does the opt in look like for these? What's the benefit of this apparent complexity? ====
 
(1) only = generator present, users can enable by creating a configuration file. No other changes. Ideally FESCo approves this Fedora wide so that the generator is available everywhere without exception. Makes it easier to converge on to reduce user confusion,
 
(1) + (2) = swap-on-ZRAM is enabled, and with a higher priority than default for swap-on-drive. Both co-exist, but swap-on-ZRAM is favored first. Hibernation is still possible if the swap-on-drive partition is big enough and all other requirements are met.
 
(1) + (2) + (3) = swap-on-ZRAM is enabled, no disk-based swap present. Fedora Workstation edition plans on doing this (pending test day results and feedback). [6]
 
 
[6]</br >
Pending test day results, Fedora Workstation Edition anticipates proceeding with full opt in: swap-on-ZRAM is enabled. New default installs will not have a swap-on-disk present. If the user opts to create swap via Custom partitioning at installation time, the installation will have two swaps: swap-on-ZRAM, swap-on-disk. The swap-on-ZRAM will have higher priority, thus being favored over disk based swap. The kernel is smart enough to know it can't hibernation to a ZRAM device, and will instead use disk based swap. This works reliably in testing so far, and we'll want to thoroughly beat it up during the test day.
 
 
 
==== Test Day: ====
 
Change owner recommends all editions/spins opt in and participate in the soon to be scheduled test day. The defaults will be conservative. e.g. 50% RAM used for the ZRAM device with a cap of 4GiB. Test day will help fine tune this.
 
 


== Feedback ==
== Feedback ==


<!-- Summarize the feedback from the community and address why you chose not to accept proposed alternatives. This section is optional for all change proposals, but is strongly suggested. Incorporating feedback here as it is raised gives FESCo a clearer view of your proposal and leaves a good record for the future. If you get no feedback, that is useful to note in this section as well. For innovative or possibly controversial ideas, consider collecting feedback before you file the change proposal. -->
==== Why not zswap? ====
 
Zswap is a similar idea, similar "z" affection, but with a totally different implementation. It is swap specific, uses a RAM cache, and requires a conventional swap partition existing already. It might be true certain workloads are better suited for using zswap. But swap-on-ZRAM depends only on volatile storage. This is simpler and it's more secure. Whereas zswap "spilling over" into the real swap on disk can leak user data if that swap device isn't encrypted. This is certainly a valid future feature for a new generator, or possibly zram-generator could be extended to include support for zswap via the configuration file.
 
 
https://www.kernel.org/doc/Documentation/vm/zswap.txt
 
==== You're enabling it on upgrades? ====
 
That's the current plan. There are some difficulties with this right now in Fedora, needing to use Supplements to cause new things to be dragged in on upgrades. As a technical matter, feature owner is confident it will improve the experience of users who have configured their systems with no swap. As a non-technical matter, it's recognized that (a) hey pal, you're messing with my customizations, not cool! and (b) swap always sucks I don't care if it has a 'Z' in the name! The dilemma is that not applying it to upgrades fragments the Fedora user base, and the overall experience people are having, and giving feedback on to make Fedora better. So all of this has to be balanced out.
 
 
 
==== Why systemd zram-generator? ====
 
It's the most upstream implementation to date, and leverages existing systemd infrastructure setup the ZRAM block device, format it as swap, and swapon - all during early boot. There are also systemd-fstab-generator
 
Also the idea is to converge on one particular implementation to avoid user confusion. And while the alternatives are nice and work fine, using a systemd generator rather than a systemd service unit is ideal.</br >
https://www.freedesktop.org/software/systemd/man/systemd.generator.html</br >
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/TCY534JPIMZ3OXM5Q5E2ZH5PSAKQNGP7/
 
 
 
==== Why not a bigger ZRAM device? ====
 
It's possible some workloads will have data that doesn't compress well. Hence not going with a 1:1 ZRAM to RAM ratio. Even a 2:1 ratio is not unreasonable *if* the compression ratio is 2:1. However, it's possible a system can actually get "wedged in" to a kind of swap thrashing very similar to conventional swap-on-disk, except it becomes CPU and memory bound, rather than IO bound. Feature owner thinks it's better to just oom than get overly aggressive with the ZRAM device size. And this feature is already well tested with earlyoom used by default on Fedora Workstation since Fedora 32.
 
 


== Benefit to Fedora ==
== Benefit to Fedora ==


<!-- What is the benefit to the distribution?  Will the software we generate be improved? How will the process of creating Fedora releases be improved?
- significantly improves system responsiveness, especially when swap is under pressure;
 
- complements on-going resource control work;
      Be sure to include the following areas if relevant:
- further reduces the time to out-of-memory kill, when workloads exceed limits;
      If this is a major capability update, what has changed?
- improves both the "no swap" and "existing swap" setups;
          For example: This change introduces Python 5 that runs without the Global Interpreter Lock and is fully multithreaded.
      If this is a new functionality, what capabilities does it bring?
          For example: This change allows package upgrades to be performed automatically and rolled-back at will.
      Does this improve some specific package or set of packages?
          For example: This change modifies a package to use a different language stack that reduces install size by removing dependencies.
      Does this improve specific Spins or Editions?
          For example: This change modifies the default install of Fedora Workstation to be more in line with the base install of Fedora Server.
      Does this make the distribution more efficient?
          For example: This change replaces thousands of individual %post scriptlets in packages with one script that runs at the end.
      Is this an improvement to maintainer processes?
          For example: Gating Fedora packages on automatic QA tests will make rawhide more stable and allow changes to be implemented more smoothly.
      Is this an improvement targeted as specific contributors?
          For example: Ensuring that a minimal set of tools required for contribution to Fedora are installed by default eases the onboarding of new contributors.


    When a Change has multiple benefits, it's better to list them all.


    Consider these Change pages from previous editions as inspiration:
    https://fedoraproject.org/wiki/Changes/Annobin (low-level and technical, invisible to users)
    https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo (low-level, but visible to advanced users)
    https://fedoraproject.org/wiki/Changes/VirtualBox_Guest_Integration (primarily a UX change)
    https://fedoraproject.org/wiki/Changes/NoMoreAlpha (an improvement to distro processes)
    https://fedoraproject.org/wiki/Changes/perl5.26 (major upgrade to a popular software stack, visible to users of that stack)
-->


== Scope ==
== Scope ==
* Proposal owners:
<!-- What work do the feature owners have to accomplish to complete the feature in time for release?  Is it a large change affecting many parts of the distribution or is it a very isolated change? What are those changes?-->


* Other developers: N/A (not a System Wide Change) <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
* Proposal owners:  
<!-- What work do other developers have to accomplish to complete the feature in time for release?  Is it a large change affecting many parts of the distribution or is it a very isolated change? What are those changes?-->
** add zram-generator package to comps for the editions/spins opting in
** means of per edition/spin configurations, if needed
** coordinate a test day
 
* Other developers:
**RFE's for zram-generator: users are not worse off if they don't happen</br >
https://github.com/systemd/zram-generator/issues/10</br >
https://github.com/systemd/zram-generator/issues/8


* Release engineering: [https://pagure.io/releng/issues #Releng issue number] (a check of an impact with Release Engineering is needed) <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
** Anaconda is agreeable to deprecating their built-in implementation in favor of swap-on-ZRAM
<!-- Does this feature require coordination with release engineering (e.g. changes to installer image generation or update package delivery)?  Is a mass rebuild required?  include a link to the releng issue.
The issue is required to be filed prior to feature submission, to ensure that someone is on board to do any process development work and testing, and that all changes make it into the pipeline; a bullet point in a change is not sufficient communication -->


* Policies and guidelines: N/A (not a System Wide Change) <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
<!-- Do the packaging guidelines or other documents need to be updated for this feature?  If so, does it need to happen before or after the implementation is done?  If a FPC ticket exists, add a link here. -->


* Trademark approval: N/A (not needed for this Change)
<!-- If your Change may require trademark approval (for example, if it is a new Spin), file a ticket ( https://fedorahosted.org/council/ ) requesting trademark approval from the Fedora Council. This approval will be done via the Council's consensus-based process. -->


== Upgrade/compatibility impact ==
== Upgrade/compatibility impact ==
<!-- What happens to systems that have had a previous versions of Fedora installed and are updated to the version containing this change? Will anything require manual configuration or data migration? Will any existing functionality be no longer supported? -->


<!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
If all editions/spins opt in, add Supplements:fedora-release to zram-generator to pull it in on upgrades.
N/A (not a System Wide Change)
 
Existing systems with no swap will have swap-on-ZRAM enabled.
Existing systems with conventional swap-on-disk, will also have swap-on-ZRAM enabled (two swap devices), with higher priority for the ZRAM device. Existing swap-on-disk will not be removed.


== How To Test ==
<!-- This does not need to be a full-fledged document. Describe the dimensions of tests that this change implementation is expected to pass when it is done.  If it needs to be tested with different hardware or software configurations, indicate them.  The more specific you can be, the better the community testing can be.


Remember that you are writing this how to for interested testers to use to check out your change implementation - documenting what you do for testing is OK, but it's much better to document what *I* can do to test your change.


A good "how to test" should answer these four questions:
== How To Test ==


0. What special hardware / data / etc. is needed (if any)?
Any hardware. Any version of Fedora.
1. How do I prepare my system to test this change? What packages
need to be installed, config files edited, etc.?
2. What specific actions do I perform to check that the change is
working like it's supposed to?
3. What are the expected results of those actions?
-->


<!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
1. dnf install zram-generator
N/A (not a System Wide Change)
2. cp /usr/share/doc/zram-generator/zram-generator.conf.example /etc/systemd/zram-generator.conf
3. Edit the configuration
4. Reboot
5. Check that swap is on a ZRAM device
zramctl
swapon
6. Detailed check: journalctl -b -o short-monotonic | grep 'swap\|zram'
7. Check that priority is higher than existing swap if two or more are listed.


== User Experience ==
== User Experience ==
<!-- If this change proposal is noticeable by users, how will their experiences change as a result?


This section partially overlaps with the Benefit to Fedora section above. This section should be primarily about the User Experience, written in a way that does not assume deep technical knowledge. More detailed technical description should be left for the Benefit to Fedora section.
The user won't notice anything. If their usual workload causes them to dread swap thrashing, they'll be surprised this doesn't happen. The user might get curious if they don't find a swap entry in /etc/fstab. Or they might get curious if they 'swapon' and see swap pointing to /dev/zram0 instead of a disk partition or LV.


Describe what Users will see or notice, for example:
== Dependencies ==
  - Packages are compressed more efficiently, making downloads and upgrades faster by 10%.
  - Kerberos tickets can be renewed automatically. Users will now have to authenticate less and become more productive. Credential management improvements mean a user can start their work day with a single sign on and not have to pause for reauthentication during their entire day.
- Libreoffice is one of the most commonly installed applications on Fedora and it is now available by default to help users "hit the ground running".
- Green has been scientifically proven to be the most relaxing color. The move to a default background color of green with green text will result in Fedora users being the most relaxed users of any operating system.
-->


== Dependencies ==
N/A
<!-- What other packages (RPMs) depend on this package?  Are there changes outside the developers' control on which completion of this change depends?  In other words, completion of another change owned by someone else and might cause you to not be able to finish on time or that you would need to coordinate?  Other upstream projects like the kernel (if this is not a kernel change)? -->


<!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
N/A (not a System Wide Change)


== Contingency Plan ==
== Contingency Plan ==


<!-- If you cannot complete your feature by the final development freeze, what is the backup plan?  This might be as simple as "Revert the shipped configuration".  Or it might not (e.g. rebuilding a number of dependent packages).  If you feature is not completed in time we want to assure others that other parts of Fedora will not be in jeopardy.  -->
* Contingency mechanism: Don't ship the generator = big hammer but easy. Also possible to ship the generator, but only selectively ship configuration files = scalpel, pretty easy.
* Contingency mechanism: (What to do?  Who will do it?) N/A (not a System Wide Change)  <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
* Contingency deadline: Beta freeze
<!-- When is the last time the contingency mechanism can be put in place?  This will typically be the beta freeze. -->
* Blocks release? No.
* Contingency deadline: N/A (not a System Wide Change)  <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
* Blocks product? No.
<!-- Does finishing this feature block the release, or can we ship with the feature in incomplete state? -->
 
* Blocks release? N/A (not a System Wide Change), Yes/No <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
 
* Blocks product? product <!-- Applicable for Changes that blocks specific product release/Fedora.next -->


== Documentation ==
== Documentation ==
<!-- Is there upstream documentation on this change, or notes you have written yourself?  Link to that material here so other interested developers can get involved. -->


<!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
Fedora could consider adding a hint in an /etc/fstab comment? There is no man page for this, and the documentation is also minimal besides what's in this feature proposal. So it's an open question how the user should get more information on how to configure and tweak it. But then, they don't have that for swap today either. They just have institutional knowledge.
N/A (not a System Wide Change)
 
Hence, a strong test day with a lot of people and press coverage of the feature might help spread the word for institutional knowledge changes coming.
 
Ideas welcome.
 
 


== Release Notes ==
== Release Notes ==
<!-- The Fedora Release Notes inform end-users about what is new in the release.  Examples of past release notes are here: http://docs.fedoraproject.org/release-notes/ -->
<!-- The release notes also help users know how to deal with platform changes such as ABIs/APIs, configuration or data file formats, or upgrade concerns.  If there are any such changes involved in this change, indicate them here.  A link to upstream documentation will often satisfy this need.  This information forms the basis of the release notes edited by the documentation team and shipped with the release.


Release Notes are not required for initial draft of the Change Proposal but has to be completed by the Change Freeze.  
Pending feedback and test day.
-->

Revision as of 12:20, 30 May 2020

swap on ZRAM

Summary

Swap is useful, except when slow.[1] ZRAM is a RAM disk that uses always-on compression [2]. It has a size assigned at create time, but the RAM usage is dynamically allocated and deallocated, on demand. This ZRAM block device behaves like any other, it can be formatted with a file system or mkswap, which is the intention with this change proposal.

There is more than one change indicated in this proposal. Each is opt-in (owner assumes editions/spins are to be excluded unless they ask to be included):

1. Include systemd rust-zram-generator[3]. This does not enable swap-on-ZRAM. It only makes the generator available.
2. Include a default zram-generator configuration. If present, it enables swap-on-ZRAM during startup.
3. Do not create swap partition/LV for default installations.


[1]
There is a tl;dr section at the top. Highly recommend reading the whole article.
In defence of swap: common misconceptions
https://chrisdown.name/2018/01/02/in-defence-of-swap.html

[2]
https://www.kernel.org/doc/Documentation/blockdev/zram.txt

[3]
https://github.com/systemd/zram-generator


Owner

Current status

  • Targeted release: Fedora 33
  • Last updated: 2020-05-30
  • FESCo issue: <will be assigned by the Wrangler>
  • Tracker bug: <will be assigned by the Wrangler>
  • Release notes tracker: <will be assigned by the Wrangler>

Detailed Description

Basic function:

The system will use RAM normally up until it's full, and then start paging out to the swap-on-ZRAM device, just as if it were a real swap. But, there is no free lunch. The ZRAM driver starts to allocate memory at roughly 1/2 the rate of page outs, due to compression. This means swap is not as effective at page eviction, the rate is ~50% instead of 100%. But it is orders of magnitude faster that disk based swap.

ZRAM has about 0.1% overhead or ~1MiB/1GiB. If the workload never touches swap, living entirely inside RAM, the overhead is the sole cost, there is no preallocation of RAM.

Default configuration:

Always create a ZRAM device regardless, of RAM size, using a ZRAM to RAM ratio of 1:2, and capped to 4GiB [4], with a higher than typical swap priority [5].


[4]
RFE: should be able to set a cap on zram device size
https://github.com/systemd/zram-generator/issues/10

[5]
RFE: should set priority #8
https://github.com/systemd/zram-generator/issues/8

These values seem reasonable, based on prior work. Anaconda has two examples in which it sets swap size to 50% RAM: the no hibernation case, common outside x86; and it's own current swap-on-ZRAM implementation. Fedora IoT's implementation uses a ZRAM to RAM ratio of 1:2, or 50% as well.


In the summary, three changes are listed. What does the opt in look like for these? What's the benefit of this apparent complexity?

(1) only = generator present, users can enable by creating a configuration file. No other changes. Ideally FESCo approves this Fedora wide so that the generator is available everywhere without exception. Makes it easier to converge on to reduce user confusion,

(1) + (2) = swap-on-ZRAM is enabled, and with a higher priority than default for swap-on-drive. Both co-exist, but swap-on-ZRAM is favored first. Hibernation is still possible if the swap-on-drive partition is big enough and all other requirements are met.

(1) + (2) + (3) = swap-on-ZRAM is enabled, no disk-based swap present. Fedora Workstation edition plans on doing this (pending test day results and feedback). [6]


[6]
Pending test day results, Fedora Workstation Edition anticipates proceeding with full opt in: swap-on-ZRAM is enabled. New default installs will not have a swap-on-disk present. If the user opts to create swap via Custom partitioning at installation time, the installation will have two swaps: swap-on-ZRAM, swap-on-disk. The swap-on-ZRAM will have higher priority, thus being favored over disk based swap. The kernel is smart enough to know it can't hibernation to a ZRAM device, and will instead use disk based swap. This works reliably in testing so far, and we'll want to thoroughly beat it up during the test day.


Test Day:

Change owner recommends all editions/spins opt in and participate in the soon to be scheduled test day. The defaults will be conservative. e.g. 50% RAM used for the ZRAM device with a cap of 4GiB. Test day will help fine tune this.


Feedback

Why not zswap?

Zswap is a similar idea, similar "z" affection, but with a totally different implementation. It is swap specific, uses a RAM cache, and requires a conventional swap partition existing already. It might be true certain workloads are better suited for using zswap. But swap-on-ZRAM depends only on volatile storage. This is simpler and it's more secure. Whereas zswap "spilling over" into the real swap on disk can leak user data if that swap device isn't encrypted. This is certainly a valid future feature for a new generator, or possibly zram-generator could be extended to include support for zswap via the configuration file.


https://www.kernel.org/doc/Documentation/vm/zswap.txt


You're enabling it on upgrades?

That's the current plan. There are some difficulties with this right now in Fedora, needing to use Supplements to cause new things to be dragged in on upgrades. As a technical matter, feature owner is confident it will improve the experience of users who have configured their systems with no swap. As a non-technical matter, it's recognized that (a) hey pal, you're messing with my customizations, not cool! and (b) swap always sucks I don't care if it has a 'Z' in the name! The dilemma is that not applying it to upgrades fragments the Fedora user base, and the overall experience people are having, and giving feedback on to make Fedora better. So all of this has to be balanced out.


Why systemd zram-generator?

It's the most upstream implementation to date, and leverages existing systemd infrastructure setup the ZRAM block device, format it as swap, and swapon - all during early boot. There are also systemd-fstab-generator

Also the idea is to converge on one particular implementation to avoid user confusion. And while the alternatives are nice and work fine, using a systemd generator rather than a systemd service unit is ideal.
https://www.freedesktop.org/software/systemd/man/systemd.generator.html
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/TCY534JPIMZ3OXM5Q5E2ZH5PSAKQNGP7/


Why not a bigger ZRAM device?

It's possible some workloads will have data that doesn't compress well. Hence not going with a 1:1 ZRAM to RAM ratio. Even a 2:1 ratio is not unreasonable *if* the compression ratio is 2:1. However, it's possible a system can actually get "wedged in" to a kind of swap thrashing very similar to conventional swap-on-disk, except it becomes CPU and memory bound, rather than IO bound. Feature owner thinks it's better to just oom than get overly aggressive with the ZRAM device size. And this feature is already well tested with earlyoom used by default on Fedora Workstation since Fedora 32.


Benefit to Fedora

- significantly improves system responsiveness, especially when swap is under pressure; - complements on-going resource control work; - further reduces the time to out-of-memory kill, when workloads exceed limits; - improves both the "no swap" and "existing swap" setups;


Scope

  • Proposal owners:
    • add zram-generator package to comps for the editions/spins opting in
    • means of per edition/spin configurations, if needed
    • coordinate a test day
  • Other developers:
    • RFE's for zram-generator: users are not worse off if they don't happen

https://github.com/systemd/zram-generator/issues/10
https://github.com/systemd/zram-generator/issues/8

    • Anaconda is agreeable to deprecating their built-in implementation in favor of swap-on-ZRAM


Upgrade/compatibility impact

If all editions/spins opt in, add Supplements:fedora-release to zram-generator to pull it in on upgrades.

Existing systems with no swap will have swap-on-ZRAM enabled. Existing systems with conventional swap-on-disk, will also have swap-on-ZRAM enabled (two swap devices), with higher priority for the ZRAM device. Existing swap-on-disk will not be removed.


How To Test

Any hardware. Any version of Fedora.

1. dnf install zram-generator 2. cp /usr/share/doc/zram-generator/zram-generator.conf.example /etc/systemd/zram-generator.conf 3. Edit the configuration 4. Reboot 5. Check that swap is on a ZRAM device zramctl swapon 6. Detailed check: journalctl -b -o short-monotonic | grep 'swap\|zram' 7. Check that priority is higher than existing swap if two or more are listed.


User Experience

The user won't notice anything. If their usual workload causes them to dread swap thrashing, they'll be surprised this doesn't happen. The user might get curious if they don't find a swap entry in /etc/fstab. Or they might get curious if they 'swapon' and see swap pointing to /dev/zram0 instead of a disk partition or LV.

Dependencies

N/A


Contingency Plan

  • Contingency mechanism: Don't ship the generator = big hammer but easy. Also possible to ship the generator, but only selectively ship configuration files = scalpel, pretty easy.
  • Contingency deadline: Beta freeze
  • Blocks release? No.
  • Blocks product? No.


Documentation

Fedora could consider adding a hint in an /etc/fstab comment? There is no man page for this, and the documentation is also minimal besides what's in this feature proposal. So it's an open question how the user should get more information on how to configure and tweak it. But then, they don't have that for swap today either. They just have institutional knowledge.

Hence, a strong test day with a lot of people and press coverage of the feature might help spread the word for institutional knowledge changes coming.

Ideas welcome.


Release Notes

Pending feedback and test day.