Bug 513296

Summary: The default value of KWIN_DRM_OVERRIDE_SAFETY_MARGIN is not suitable for high refresh rate screens
Product: [Plasma] kwin Reporter: thesword <thesword53>
Component: performanceAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: nate, xaver.hugl
Priority: NOR Keywords: efficiency-and-performance, wayland-only
Version First Reported In: 6.5.4   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description thesword 2025-12-13 15:43:41 UTC
By default the environment variable KWIN_DRM_OVERRIDE_SAFETY_MARGIN is set to 1500, but with this value on my 360Hz monitor, I have frame drops in graphical applications such as Firefox and games. Lowering it to 500 solves the issue for me.


STEPS TO REPRODUCE
1. Keep KWIN_DRM_OVERRIDE_SAFETY_MARGIN at the default value (1500).
2. Open vkcube on a 240 or 360Hz monitor.
3. Show the FPS with mangohud.

OBSERVED RESULT
Periodic stutters.

EXPECTED RESULT
Frame time should be flat

SOFTWARE/OS VERSIONS
Linux: 6.17.9-arch1-1
KDE Plasma Version: 6.5.4
KDE Frameworks Version: 6.20.0
Qt Version: 6.10.1

ADDITIONAL INFORMATION
The safety margin should depends on the monitor refresh rate.
Comment 1 Zamundaaa 2025-12-15 12:20:19 UTC
We might be able to reduce it *slightly* by default, now that we track how long the atomic commit ioctl + work before it takes.
It's quite tricky though, as we have no information for how close or far from the actual kernel / hardware deadline we really are, and we're still waiting for new kernel API to get that information from the driver...

(In reply to thesword from comment #0)
> ADDITIONAL INFORMATION
> The safety margin should depends on the monitor refresh rate.
It should not, that's not what it's for or how it works. If the safety margin is too low, you get half the refresh rate of your screen, no matter how low or high it is.
Comment 2 Bug Janitor Service 2025-12-15 12:28:19 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/8567
Comment 3 Zamundaaa 2025-12-18 15:21:15 UTC
Git commit adf0d882bf62f477abe9aabd344f29c515c7c32e by Xaver Hugl.
Committed on 18/12/2025 at 14:55.
Pushed by zamundaaa into branch 'master'.

backends/drm: reduce safety margin to 1ms

As we track how long the atomic commit processing + ioctl(s) take, it should be
relatively safe to do. In order to reduce it further, we still need new kernel
API with accurate information about the real deadline for each frame though.

M  +1    -1    src/backends/drm/drm_commit_thread.cpp

https://invent.kde.org/plasma/kwin/-/commit/adf0d882bf62f477abe9aabd344f29c515c7c32e