Swap file remains unnecessarily large if system memory size decreases

Bug #2031345 reported by Mitchell Dzurick
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ec2-hibinit-agent (Ubuntu)
Fix Released
Undecided
Mitchell Dzurick
Focal
Fix Released
Undecided
Graham Inggs
Jammy
Fix Released
Undecided
Graham Inggs
Lunar
Fix Released
Undecided
Graham Inggs

Bug Description

Upstream Change - https://github.com/aws/amazon-ec2-hibinit-agent/commit/d2ce783d10d3a4437ebac468ed669666d8b6671b

[FFE]
====
This change includes a small optimization to resize the swap partition. On hibernation, the contents of RAM is put onto SWAP, so if the amount of RAM reduces, the SWAP file will be too large, and waste space.

[SRU]
====

[Impact]
If an AWS EC2 user decreases the amount of RAM on an instance, unnecessary disk space will be used.

[Test Case]
1. create & start a c5.xlarge instance.
2. Upgrade to the new ec2-hibinit-agent package.
3. Stop the instance.
4. Modified to a smaller instance (c5.large)
5. `journalctl -b | grep "Swap already exists!"` verify swap is recreated
Aug 04 18:19:03 ip-172-31-22-174.ec2.internal hibinit-agent[2457]: Swap already exists! (have 8011616256, need 4194304000), deleting existing swap file /swap since current swap is sufficiently large and wasting memory
7. Stop and restart the instance again
8. `journalctl -b | grep "There's sufficient swap available"` to verified no recreation. of swap occured.
Aug 04 18:23:17 ip-172-31-22-174.ec2.internal hibinit-agent[2452]: There's sufficient swap available (have 4194304000, need 4194304000)
9. Stop the instance
10. Modify to larger (c5.xlarge) instance.
11. Start the instance.
12. `journalctl -b | grep "Swap already exists!"` to verify swap is created due to larger swap required.
Aug 04 18:25:03 ip-172-31-22-174.ec2.internal hibinit-agent[2600]: Swap already exists! (have 4194304000, need 8011620352), deleting existing swap file /swap

[Where things could go wrong]
- If Dynamic swap allocation fails, then hibernation may not properly save the state of the machine.
- Perhaps the user relies on the bigger SWAP size for something else and dynamically resizing on instance change could cause issues? I'd say unlikely but could be a concern.
- [racb] I asked what might happen if a user has increased swap size manually and expects it to stay large. But I'm told that a specific swap filename is used that is specific to hibernation, so it seems reasonable that this would be automatically managed.

Related branches

Changed in ec2-hibinit-agent (Ubuntu):
assignee: nobody → Mitchell Dzurick (mitchdz)
summary: - Add Swap Optimization from upstream
+ Add recreating the swap file if the current size is sufficiently larger
Revision history for this message
Mitchell Dzurick (mitchdz) wrote : Re: Add recreating the swap file if the current size is sufficiently larger

I'm planning on doing an FFE for Mantic, and then start the SRU process to Focal.

summary: - Add recreating the swap file if the current size is sufficiently larger
+ FFE+SRU: Add recreating the swap file if the current size is
+ sufficiently larger
description: updated
description: updated
description: updated
Revision history for this message
Steve Langasek (vorlon) wrote : Re: FFE+SRU: Add recreating the swap file if the current size is sufficiently larger

This is ok from a FFe perspective for mantic.

Changed in ec2-hibinit-agent (Ubuntu):
status: New → Triaged
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ec2-hibinit-agent - 1.0.0-0ubuntu16

---------------
ec2-hibinit-agent (1.0.0-0ubuntu16) mantic; urgency=medium

  * d/p/lp2031345-recreate-swap-file.patch: Recreate the SWAP file if instance
    type changes (LP: #2031345)

 -- Mitchell Dzurick <email address hidden> Mon, 28 Aug 2023 07:23:22 -0700

Changed in ec2-hibinit-agent (Ubuntu):
status: Triaged → Fix Released
Graham Inggs (ginggs)
Changed in ec2-hibinit-agent (Ubuntu Focal):
assignee: nobody → Graham Inggs (ginggs)
Changed in ec2-hibinit-agent (Ubuntu Jammy):
assignee: nobody → Graham Inggs (ginggs)
Changed in ec2-hibinit-agent (Ubuntu Lunar):
assignee: nobody → Graham Inggs (ginggs)
Changed in ec2-hibinit-agent (Ubuntu Focal):
status: New → In Progress
Changed in ec2-hibinit-agent (Ubuntu Jammy):
status: New → In Progress
Changed in ec2-hibinit-agent (Ubuntu Lunar):
status: New → In Progress
Revision history for this message
Robie Basak (racb) wrote :

It looks like the code to expand the swap in case of a memory size increase is already present in the existing code, and what is being enhanced is the inverse - reducing swap to follow a memory size decrease.

Rejecting from the queue because the changelog implies that we are making a change that is partially already present. The user impact needs adjusting also please, since it describes a problem that does not currently exist in the series in question.

This also raises the question of what happens if a user deliberately increases their swap. Will this reduce it again contrary to their expectations, or is there protection against that?

Revision history for this message
Mitchell Dzurick (mitchdz) wrote :

Thanks Robie! I updated the description. To address the question on if the user is using swap, we carry an Ubuntu delta in debian/patches/0006-Use-swap-hibinit-instead-of-too-generic-swap.patch to use the swap-file /swap-hibinit instead of /swap. That way, users should just be using regular /swap if they need, and resizing shouldn't impact their use-case.

description: updated
summary: - FFE+SRU: Add recreating the swap file if the current size is
- sufficiently larger
+ Swap file remains unnecessarily large if system memory size decreases
Revision history for this message
Robie Basak (racb) wrote : Please test proposed package

Hello Mitchell, or anyone else affected,

Accepted ec2-hibinit-agent into lunar-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ec2-hibinit-agent/1.0.0-0ubuntu13.3 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-lunar to verification-done-lunar. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-lunar. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

description: updated
Changed in ec2-hibinit-agent (Ubuntu Lunar):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-lunar
Changed in ec2-hibinit-agent (Ubuntu Jammy):
status: In Progress → Fix Committed
tags: added: verification-needed-jammy
Revision history for this message
Robie Basak (racb) wrote :

Hello Mitchell, or anyone else affected,

Accepted ec2-hibinit-agent into jammy-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ec2-hibinit-agent/1.0.0-0ubuntu11.22.04.4 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-jammy to verification-done-jammy. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-jammy. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in ec2-hibinit-agent (Ubuntu Focal):
status: In Progress → Fix Committed
tags: added: verification-needed-focal
Revision history for this message
Robie Basak (racb) wrote :

Hello Mitchell, or anyone else affected,

Accepted ec2-hibinit-agent into focal-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ec2-hibinit-agent/1.0.0-0ubuntu9.5 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-focal to verification-done-focal. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-focal. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Revision history for this message
Mitchell Dzurick (mitchdz) wrote :

Testing this is a little involved, so I made this test script - https://github.com/mitchdz/ec2-hibinit-agent-lp2031345

I tested Lunar/Jammy/Focal

All have expected behavior of journalctl showing the SWAP size being reduced similar to

Sep 25 22:33:08 ip-172-31-18-186 hibinit-agent[935]: Found '/var/lib/hibinit-agent/hibernation-enabled', configuring hibernation
Sep 25 22:33:08 ip-172-31-18-186 hibinit-agent[935]: Will check if swap is at least: 4000 megabytes
Sep 25 22:33:08 ip-172-31-18-186 hibinit-agent[935]: Swap already exists! (have 16571219968, need 4194304000), deleting existing swap file /swap-hibinit since current swap is sufficiently large and wasting memory

tags: added: verification-done verification-done-focal verification-done-jammy verification-done-lunar
removed: verification-needed verification-needed-focal verification-needed-jammy verification-needed-lunar
Revision history for this message
Brian Murray (brian-murray) wrote :

I might be confused but the string says "deleting existing swap file /swap-hibinit since current swap is sufficiently large and wasting memory" but the description refers to "unnecessary disk space" being used. So "wasting memory" seems inaccurate to me.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ec2-hibinit-agent - 1.0.0-0ubuntu13.3

---------------
ec2-hibinit-agent (1.0.0-0ubuntu13.3) lunar; urgency=medium

  * d/p/lp2031345-recreate-swap-file.patch: Reduce SWAP size if current SWAP
    is larger than needed (LP: #2031345)

 -- Mitchell Dzurick <email address hidden> Mon, 28 Aug 2023 07:23:22 -0700

Changed in ec2-hibinit-agent (Ubuntu Lunar):
status: Fix Committed → Fix Released
Revision history for this message
Brian Murray (brian-murray) wrote : Update Released

The verification of the Stable Release Update for ec2-hibinit-agent has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ec2-hibinit-agent - 1.0.0-0ubuntu11.22.04.4

---------------
ec2-hibinit-agent (1.0.0-0ubuntu11.22.04.4) jammy; urgency=medium

  * d/p/lp2031345-recreate-swap-file.patch: Reduce SWAP size if current SWAP
    is larger than needed (LP: #2031345)

 -- Mitchell Dzurick <email address hidden> Mon, 28 Aug 2023 07:23:22 -0700

Changed in ec2-hibinit-agent (Ubuntu Jammy):
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ec2-hibinit-agent - 1.0.0-0ubuntu9.5

---------------
ec2-hibinit-agent (1.0.0-0ubuntu9.5) focal; urgency=medium

  * d/p/lp2031345-recreate-swap-file.patch: Reduce SWAP size if current SWAP
    is larger than needed (LP: #2031345)

 -- Mitchell Dzurick <email address hidden> Mon, 28 Aug 2023 07:23:22 -0700

Changed in ec2-hibinit-agent (Ubuntu Focal):
status: Fix Committed → Fix Released
Revision history for this message
Mitchell Dzurick (mitchdz) wrote :

Thanks Brian! I agree that wording can be misleading. I made a PR upstream[0] to address that.

[0] - https://github.com/aws/amazon-ec2-hibinit-agent/pull/33

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.