nvidia-modeset: free the semaphore surface callback record when the waiter is already signalled - #1368
Open
jdd-canada wants to merge 1 commit into
Open
nvidia-modeset: free the semaphore surface callback record when the waiter is already signalled#1368jdd-canada wants to merge 1 commit into
jdd-canada wants to merge 1 commit into
Conversation
…aiter is already signalled nvKmsKapiRegisterSemaphoreSurfaceCallback() allocates a struct NvKmsKapiSemaphoreSurfaceCallback before asking RM to register a waiter. When RM answers NVOS_STATUS_ERROR_ALREADY_SIGNALLED the function returns without freeing the record and without handing it to the caller, so neither of the two documented release paths (the callback running, or unregisterSemaphoreSurfaceCallback()) can ever reach it. nvidia-drm takes this path for every semaphore surface fence whose GPU work completes before the waiter is registered, which on a Wayland compositor is nearly every composited frame. The result is a 40-byte kmalloc-64 object leaked per frame: 11.6 million objects and 2.2 GB of unreclaimable slab over 4.5 days of desktop use on 595.71.05, attributed with slub_debug=U to this call site through __nv_drm_semsurf_ctx_reg_callbacks(). Applies to every tag from 545.29.06 through 610.57.04 and to main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nvKmsKapiRegisterSemaphoreSurfaceCallback()allocates astruct NvKmsKapiSemaphoreSurfaceCallbackbefore asking RM to register a waiter. When RM returnsNVOS_STATUS_ERROR_ALREADY_SIGNALLED, the function returns without freeing the record and without handing it back to the caller, so neither of the two documented release paths (the callback firing, orunregisterSemaphoreSurfaceCallback()) can ever reach it. This change frees the record on that return.nvKmsKapiFree(NULL)is already relied on by the function's ownfail:path, so the call is safe when no callback was requested.Impact
nvidia-drm takes this path through
__nv_drm_semsurf_ctx_reg_callbacks()for every semaphore surface fence whose GPU work completes before the waiter is registered. On a Wayland compositor that waits its own render fence before each KMS commit, that is most composited frames: the leak rate follows the compositor's frame rate, near zero on a static screen and tens of MiB per hour while anything animates.Observed on a laptop (RTX, Void Linux, kernel 6.18.50) over 4.5 days of desktop use on 595.71.05: 11.6 million live kmalloc-64 objects, 2.2 GB of unreclaimable slab, 97 percent of the cache, attributed with
slub_debug=U,kmalloc-64to this one call site:The same lines are present in every tag from 545.29.06 through 610.57.04 and on
mainat 615.71.09.Verification
Stock open module 595.91.07 versus the same source with this patch, same kernel and same day, with slab owner tracking enabled and the site's live count read from
/sys/kernel/debug/slab/kmalloc-64/alloc_traces. Reproduction that isolates the compositor's own fences (a CPU-rendered client, no client-side GPU fences):Patched build afterwards: 20 hours of normal use with kmalloc-64 flat at 7.4 MiB in every hourly slab sample, and about 36 hours further with no growth.