Public bug reported:

**Environment**

- Ubuntu 26.04.1 LTS (arm64)
- Package: ec2-hibinit-agent 1.0.9-0ubuntu1
- AWS EC2 instance: m9g.8xlarge (128 GiB RAM)

**Description**

The hibernation agent correctly calculates the required swap size during
validation but ignores the calculated value when allocating the swap
file.

With the default configuration:

```
[swap]
percentage-of-ram = 100
target-size-mb = 4000
```

The agent calculates a requirement of 126466 MiB but allocates only 4000
MiB.

**Root cause**

In `/usr/bin/hibinit-agent`, `validate_system_requirements()` (lines
447–492) calculates the required swap size as the maximum of the
configured target size and the specified percentage of physical RAM.

However, this calculated value is not passed to
`SwapInitializer.__init__()`, which independently calculates the
allocation size at line 247:

```python
self.swap_size = config.swap_mb * KB * KB
```

Consequently, the percentage-of-ram setting is ignored during
allocation.

**Actual behaviour**

- A 4000 MiB swap file is allocated instead of approximately 123.5 GiB.
- On every boot, the existing swap file is identified as undersized, deleted 
and recreated at the same incorrect size.
- The resume offset is unnecessarily recalculated and GRUB configuration 
regenerated.
- Hibernation may fail when the memory image exceeds the available swap 
capacity.

**Expected behaviour**

The allocated swap file size should match the size calculated by
`validate_system_requirements()`.

**Proposed fix**

Use a shared swap-size calculation in both validation and allocation:

```python
ram_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
self.swap_size = max(
    config.swap_mb * KB * KB,
    ram_bytes * config.swap_percentage // 100)
```

**Suggested workaround**

Explicitly set `target-size-mb = 131072` in `/etc/hibinit-config.cfg` on
a 128 GiB instance.

This workaround has not yet been tested.

ProblemType: Bug
DistroRelease: Ubuntu 26.04
Package: ec2-hibinit-agent 1.0.9-0ubuntu1
ProcVersionSignature: Ubuntu 7.0.0-1018.19-aws 7.0.14
Uname: Linux 7.0.0-1018-aws aarch64
ApportVersion: 2.34.1-0ubuntu0.1
Architecture: arm64
CasperMD5CheckResult: unknown
CloudArchitecture: aarch64
CloudBuildName: server
CloudID: aws
CloudName: aws
CloudPlatform: ec2
CloudRegion: eu-central-1
CloudSerial: 20250305
CloudSubPlatform: metadata (http://169.254.169.254)
Date: Mon Nov 30 23:38:42 2026
Ec2Architecture: arm64
Ec2Imageid: ami-0695412883235225c
Ec2Instancetype: m9g.8xlarge
Ec2Region: eu-central-1
PackageArchitecture: all
ProcEnviron:
 LANG=en_GB.UTF-8
 PATH=(custom, no user)
 SHELL=/bin/zsh
 TERM=xterm-256color
 XDG_RUNTIME_DIR=<set>
SourcePackage: ec2-hibinit-agent
UpgradeStatus: No upgrade log present (probably fresh install)

** Affects: ec2-hibinit-agent (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: apport-bug arm64 cloud-image resolute

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2178491

Title:
  ec2-hibinit-agent 1.0.9 ignores percentage-of-ram when allocating
  hibernation swap file

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/ec2-hibinit-agent/+bug/2178491/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to