Cannot change MemoryKSM in systemd units

Bug #2081192 reported by Pierre-Olivier Vallès
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
systemd (Ubuntu)
Fix Released
Undecided
Unassigned
Noble
Fix Released
Medium
Nick Rosbrook

Bug Description

[Impact]

Units with MemoryKSM=yes setting will fail to start with an "Invalid argument" error. This makes the setting unusable on Noble.

[Test Plan]

On Noble, start a systemd service with MemoryKSM=yes:

$ systemd-run -u test-memory-ksm.service --wait -p MemoryKSM=yes /usr/bin/true

On an affected system, this will fail immediately. Inspecting the journal will show why, e.g.:

$ journalctl -u test-memory-ksm.service
Oct 17 10:37:20 six (sleep)[1494131]: test-memory-ksm.service: Failed to set KSM: Invalid argument
Oct 17 10:37:20 six systemd[1]: Started test-memory-ksm.service - /usr/bin/sleep infinity.
Oct 17 10:37:20 six systemd[1]: test-memory-ksm.service: Main process exited, code=exited, status=245/KSM
Oct 17 10:37:20 six systemd[1]: test-memory-ksm.service: Failed with result 'exit-code'.

On a patched system, the unit should start/exit normally.

[Where problems could occur]

This patch simply adds missing arguments to the prctl call for PR_SET_MEMORY_MERGE. Problems would be isolated to the MemoryKSM= setting.

[Other information]

The patch is from upstream: https://github.com/systemd/systemd/commit/9bb89a55a235a3c64ec099bb86296d7fd1bb3302

[Original Description]

In one of my working unit (service), I try to toggle the MemoryKSM boolean setting.

Using any of:

MemoryKSM=yes
MemoryKSM=on
MemoryKSM=true
MemoryKSM=1

Results in:

Sep 19 16:16:56 systemd[1]: Started XXX.service - XXX service.
Sep 19 16:16:56 (e_server)[4487]: XXX.service: Failed to set KSM: Invalid argument
Sep 19 16:16:56 systemd[1]: XXX.service: Main process exited, code=exited, status=245/KSM
Sep 19 16:16:56 systemd[1]: XXX.service: Failed with result 'exit-code'.

The following lines allow the service to start:

MemoryKSM="yes"
MemoryKSM="on"
MemoryKSM="true"
MemoryKSM="1"

but still, MemoryKSM stays off:

# systemctl show XXX.service | grep MemoryKSM
MemoryKSM=no

KSM is activated in my running kernel:
# cat /boot/config-$(uname -r) | grep KSM
CONFIG_KSM=y

Using prctl (libc6 2.39-0ubuntu8.3) to toggle KSM inside a running process also works. I can read and set the memory_merge switch.

ProblemType: Bug
DistroRelease: Ubuntu 24.04
Package: systemd 255.4-1ubuntu8.4
ProcVersionSignature: Ubuntu 6.8.0-45.45-generic 6.8.12
Uname: Linux 6.8.0-45-generic x86_64
ApportVersion: 2.28.1-0ubuntu3.1
Architecture: amd64
CasperMD5CheckResult: unknown
CloudArchitecture: x86_64
CloudBuildName: server
CloudID: openstack
CloudName: openstack
CloudPlatform: openstack
CloudSerial: 20240612
CloudSubPlatform: metadata (http://169.254.169.254)
Date: Thu Sep 19 16:06:51 2024
Lsusb:
 Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd QEMU Tablet
 Bus 001 Device 003: ID 0627:0001 Adomax Technology Co., Ltd QEMU Tablet
Lsusb-t:
 /: Bus 001.Port 001: Dev 001, Class=root_hub, Driver=uhci_hcd/2p, 12M
     |__ Port 001: Dev 002, If 0, Class=Human Interface Device, Driver=usbhid, 12M
     |__ Port 002: Dev 003, If 0, Class=Human Interface Device, Driver=usbhid, 12M
MachineType: OpenStack Foundation OpenStack Nova
ProcKernelCmdLine: BOOT_IMAGE=/vmlinuz-6.8.0-45-generic root=UUID=1c5e2fdc-a746-403d-9fc0-71af31bc9c19 ro console=tty1 console=ttyS0
SourcePackage: systemd
UpgradeStatus: No upgrade log present (probably fresh install)
dmi.bios.date: 02/06/2015
dmi.bios.release: 0.0
dmi.bios.vendor: EFI Development Kit II / OVMF
dmi.bios.version: 0.0.0
dmi.chassis.type: 1
dmi.chassis.vendor: QEMU
dmi.chassis.version: pc-q35-4.2
dmi.modalias: dmi:bvnEFIDevelopmentKitII/OVMF:bvr0.0.0:bd02/06/2015:br0.0:svnOpenStackFoundation:pnOpenStackNova:pvr26.2.3:cvnQEMU:ct1:cvrpc-q35-4.2:sku:
dmi.product.family: Virtual Machine
dmi.product.name: OpenStack Nova
dmi.product.version: 26.2.3
dmi.sys.vendor: OpenStack Foundation

Revision history for this message
Pierre-Olivier Vallès (povalles) wrote :
Revision history for this message
Nick Rosbrook (enr0n) wrote :

Thanks for reporting this. I can reproduce as well. It appears this was fixed upstream in https://github.com/systemd/systemd/pull/31683.

It should already be fixed in Oraculr, but we will backport this to Noble.

Changed in systemd (Ubuntu):
status: New → Fix Released
Changed in systemd (Ubuntu Noble):
status: New → Triaged
assignee: nobody → Nick Rosbrook (enr0n)
importance: Undecided → Medium
tags: added: foundations-todo systemd-sru-next
Revision history for this message
Pierre-Olivier Vallès (povalles) wrote :

Thank you very much for the quick reply and pointing to the PR.

We are launching hundreds of similar processes on this server ; we migrated to Noble especially for this new feature (MemoryKSM).

Any idea when the backport will occur? We're eager to try it out.

Nick Rosbrook (enr0n)
description: updated
Revision history for this message
Nick Rosbrook (enr0n) wrote :

I have uploaded the proposed fix to noble-proposed. It needs to be reviewed by the SRU team, then tested, and eventually released to noble-updates. This process overall can take a couple of weeks depending on how busy the SRU team is.

Changed in systemd (Ubuntu Noble):
status: Triaged → In Progress
Revision history for this message
Timo Aaltonen (tjaalton) wrote : Please test proposed package

Hello Pierre-Olivier, or anyone else affected,

Accepted systemd into noble-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/systemd/255.4-1ubuntu8.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-noble to verification-done-noble. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-noble. 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 systemd (Ubuntu Noble):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-noble
Revision history for this message
Nick Rosbrook (enr0n) wrote :
Download full text (13.3 KiB)

I have verified the fix using systemd 255.4-1ubuntu8.5 from noble-proposed:

$ cat > /etc/apt/sources.list.d/proposed.sources << EOF
> Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
> EOF
$ apt update
Hit:1 http://us.archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Get:3 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Get:4 http://archive.ubuntu.com/ubuntu noble-proposed InRelease [265 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [663 kB]
Hit:7 https://ppa.launchpadcontent.net/enr0n/systemd/ubuntu noble InRelease
Get:8 http://us.archive.ubuntu.com/ubuntu noble-updates/main Translation-en [156 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu noble-updates/main amd64 Components [120 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu noble-updates/main Icons (48x48) [32.4 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu noble-updates/main Icons (64x64) [47.0 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu noble-updates/main amd64 c-n-f Metadata [10.4 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Packages [473 kB]
Get:14 http://us.archive.ubuntu.com/ubuntu noble-updates/restricted Translation-en [91.2 kB]
Get:15 http://us.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Components [212 B]
Get:16 http://us.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 c-n-f Metadata [424 B]
Get:17 http://us.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [718 kB]
Get:18 http://us.archive.ubuntu.com/ubuntu noble-updates/universe Translation-en [213 kB]
Get:19 http://us.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Components [310 kB]
Get:20 http://us.archive.ubuntu.com/ubuntu noble-updates/universe Icons (48x48) [170 kB]
Get:21 http://us.archive.ubuntu.com/ubuntu noble-updates/universe Icons (64x64) [269 kB]
Get:22 http://us.archive.ubuntu.com/ubuntu noble-updates/universe amd64 c-n-f Metadata [19.9 kB]
Get:23 http://us.archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Packages [15.0 kB]
Get:24 http://us.archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Components [940 B]
Get:25 http://us.archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 c-n-f Metadata [552 B]
Get:26 http://us.archive.ubuntu.com/ubuntu noble-backports/main amd64 Components [208 B]
Get:27 http://us.archive.ubuntu.com/ubuntu noble-backports/restricted amd64 Components [212 B]
Get:28 http://u...

tags: added: verification-done verification-done-noble
removed: verification-needed verification-needed-noble
Revision history for this message
Pierre-Olivier Vallès (povalles) wrote :

I have also verified the fix using systemd 255.4-1ubuntu8.5 from noble-proposed.

I was able to launch the transient unit with MemoryKSM=yes (this step used to fail without the fix) and now systemctl reports:

# systemctl show povalles-j | grep -i memoryksm
MemoryKSM=yes

Thank you! Now I can move on and test KSM itself :-)

Revision history for this message
Ubuntu SRU Bot (ubuntu-sru-bot) wrote : Autopkgtest regression report (systemd/255.4-1ubuntu8.5)

All autopkgtests for the newly accepted systemd (255.4-1ubuntu8.5) for noble have finished running.
The following regressions have been reported in tests triggered by the package:

linux-nvidia/6.8.0-1020.22 (arm64)
linux-oem-6.8/unknown (amd64)

Please visit the excuses page listed below and investigate the failures, proceeding afterwards as per the StableReleaseUpdates policy regarding autopkgtest regressions [1].

https://people.canonical.com/~ubuntu-archive/proposed-migration/noble/update_excuses.html#systemd

[1] https://wiki.ubuntu.com/StableReleaseUpdates#Autopkgtest_Regressions

Thank you!

Nick Rosbrook (enr0n)
Changed in systemd (Ubuntu Noble):
milestone: none → ubuntu-24.04.2
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package systemd - 255.4-1ubuntu8.5

---------------
systemd (255.4-1ubuntu8.5) noble; urgency=medium

  [ Chengen Du ]
  * udev: Handle PTP device symlink properly on udev action 'change'
    (LP: #2077779)

  [ Nick Rosbrook ]
  * core/exec-invoke: Fix missing arguments for PR_SET_MEMORY_MERGE call
    (LP: #2081192)

 -- Nick Rosbrook <email address hidden> Thu, 17 Oct 2024 13:15:16 -0400

Changed in systemd (Ubuntu Noble):
status: Fix Committed → Fix Released
Revision history for this message
Andreas Hasenack (ahasenack) wrote : Update Released

The verification of the Stable Release Update for systemd 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.

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.