Skip to content

Commit

Permalink
Allow MemorySwapMax be specified as a percentage
Browse files Browse the repository at this point in the history
A configuration of:

```config
[Service]
MemoryMax=80%
MemorySwapMax=20%
```

seems to work:

```
systemctl status autofs.service
Memory: 134.6M (max: 2.6G swap max: 336.2M available: 2.4G)
```

The systemd documentation was lacking this information so I've corrected
that also.

* https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html#MemorySwapMax=bytes
* systemd/systemd#33593
  • Loading branch information
traylenator committed Jul 3, 2024
1 parent aea425a commit c3965db
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2888,7 +2888,7 @@ Struct[{
Optional['MemoryHigh'] => Systemd::Unit::AmountOrPercent,
Optional['MemoryMax'] => Systemd::Unit::AmountOrPercent,
Optional['MemoryLimit'] => Systemd::Unit::Amount,
Optional['MemorySwapMax'] => Systemd::Unit::Amount,
Optional['MemorySwapMax'] => Systemd::Unit::AmountOrPercent,
Optional['TasksAccounting'] => Boolean,
Optional['TasksMax'] => Systemd::Unit::AmountOrPercent,
Optional['IOAccounting'] => Boolean,
Expand Down
2 changes: 2 additions & 0 deletions spec/type_aliases/systemd_unit_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
)
}

it { is_expected.to allow_value({ 'MemorySwapMax' => '80%' }) }

it { is_expected.not_to allow_value({ 'CPUQuota' => 50 }) }
it { is_expected.not_to allow_value({ 'CPUQuota' => '0%' }) }
it { is_expected.not_to allow_value({ 'MemoryHigh' => '1Y' }) }
Expand Down
2 changes: 1 addition & 1 deletion types/unit/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
Optional['MemoryHigh'] => Systemd::Unit::AmountOrPercent,
Optional['MemoryMax'] => Systemd::Unit::AmountOrPercent,
Optional['MemoryLimit'] => Systemd::Unit::Amount,
Optional['MemorySwapMax'] => Systemd::Unit::Amount,
Optional['MemorySwapMax'] => Systemd::Unit::AmountOrPercent,
Optional['TasksAccounting'] => Boolean,
Optional['TasksMax'] => Systemd::Unit::AmountOrPercent,
Optional['IOAccounting'] => Boolean,
Expand Down

0 comments on commit c3965db

Please sign in to comment.