From c3965dbdb3d756d051bd14c2728f48ef640107b7 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Wed, 3 Jul 2024 14:37:02 +0200 Subject: [PATCH] Allow MemorySwapMax be specified as a percentage 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 * https://github.com/systemd/systemd/pull/33593 --- REFERENCE.md | 2 +- spec/type_aliases/systemd_unit_service_spec.rb | 2 ++ types/unit/service.pp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 21c7feb9..14988442 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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, diff --git a/spec/type_aliases/systemd_unit_service_spec.rb b/spec/type_aliases/systemd_unit_service_spec.rb index fa31128e..971ed3cc 100644 --- a/spec/type_aliases/systemd_unit_service_spec.rb +++ b/spec/type_aliases/systemd_unit_service_spec.rb @@ -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' }) } diff --git a/types/unit/service.pp b/types/unit/service.pp index 9a24f198..b6bb83c1 100644 --- a/types/unit/service.pp +++ b/types/unit/service.pp @@ -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,