From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE8EE105F79D for ; Fri, 13 Mar 2026 11:41:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5346110EBAD; Fri, 13 Mar 2026 11:41:02 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=natalie.vock@gmx.de header.b="jCi59vlK"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id EC29710EBAD for ; Fri, 13 Mar 2026 11:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1773402037; x=1774006837; i=natalie.vock@gmx.de; bh=V5jXNwTzO8SwdIW86kQH9un7ZTFbFBnER2KXe6QJn+0=; h=X-UI-Sender-Class:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:To:Cc:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=jCi59vlKcxNplrmcHABxTy5EWctYWlSjRhIXs2uRRCjwGYS9fLdcl13lYSRq/rYA GoJKNPwWlhUIk4S6rbAOPOQKGGFuJ9vYuEJGCSw6bxOGkYn92Nl3YWKwP+Te6jJ+N wGXbRNc9ZCVCeYGl1rB3xC6vE60MOupG2DG5KkB9DFLesGi3AtazCDct/VkU/ycuT kuuC4U8YCXUYUNDNRr3egtZ6kmPc25bjCUPlY9rvRyBBP35lg2hrlkfO3HyvAoMsl B8NpMZQ/V8EKdxv9PZJls1RTU/oRfybHfGW2jFsIEw6BRCR0OQEw852085Y/h1SeI iKdrKc61rUVKdScIUA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from client.hidden.invalid by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MS3ir-1wB5dm37gx-00SdnZ; Fri, 13 Mar 2026 12:40:37 +0100 From: Natalie Vock Subject: [PATCH v6 0/6] cgroup/dmem,drm/ttm: Improve protection in contended cases Date: Fri, 13 Mar 2026 12:39:59 +0100 Message-Id: <20260313-dmemcg-aggressive-protect-v6-0-7c71cc1492db@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-B4-Tracking: v=1; b=H4sIAAAAAAAC/43OwYrDIBAG4FcpnmtRR5Omp32PZQ9GZ6yHNEWDd Cl59zWFbcgl9PgPzPf/T5YxRczscniyhCXmON5qaI4H5q72FpBHXzNTQhnRScP9gIML3IaQMOd YkN/TOKGbuHEELbWydb5n9f+ekOLjZX//1HyNeRrT76uqyOX6iVokF1wRgIGenLfuKwyPk0e2k EW9GSn2GVUZaBqtqddYd24YWBkpxR4DyxrZETlyRmO3YfQ/0wildtfoyng869b2YORZbxizMiD UHmMqQ+TBLo0g1jXzPP8BKJsKFtsBAAA= X-Change-ID: 20250915-dmemcg-aggressive-protect-5cf37f717cdb To: Maarten Lankhorst , Maxime Ripard , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Christian Koenig , Huang Rui , Matthew Auld , Matthew Brost , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Tvrtko Ursulin Cc: cgroups@vger.kernel.org, dri-devel@lists.freedesktop.org, Natalie Vock , Tvrtko Ursulin X-Mailer: b4 0.14.3 X-Provags-ID: V03:K1:27zh/WjwvHpNmgS6dRdTuin58lB4RNc7DsxrkFRDMg9Q6VSo6Oy fibPumEEmc22nsETZyqz7/ZWHtkgd8y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P0LbvO0pD8IRfwH4Lpac21i slFfEQEbkvJ5NOLwfe1s/pgnh23dZi//8ahayosTzeTt+g4zxmbvNwjj2JwZhfa0zaPxMiCNt FtpGLRmM9uqai2qM5/zsPWpQsiG00PkS7albwd7ycrRaL98FOG9zRuZ2ZDcKQkYQ762c1A3U5 mM7OkHssBOJXAtTbyhU2 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi all, I've been looking into some cases where dmem protection fails to prevent allocations from ending up in GTT when VRAM gets scarce and apps start competing hard. In short, this is because other (unprotected) applications end up filling VRAM before protected applications do. This causes TTM to back off and try allocating in GTT before anything else, and that is where the allocation is placed in the end. The existing eviction protection cannot prevent this, because no attempt at evicting is ever made (although you could consider the backing-off as an immediate eviction to GTT). This series tries to alleviate this by adding a special case when the allocation is protected by cgroups: Instead of backing off immediately, TTM will try evicting unprotected buffers from the domain to make space for the protected one. This ensures that applications can actually use all the memory protection awarded to them by the system, without being prone to ping-ponging (only protected allocations can evict unprotected ones, never the other way around). The first two patches just add a few small utilities needed to implement this to the dmem controller. The other patches are the TTM implementation: "drm/ttm: Be more aggressive..." decouples cgroup charging from resource allocation to allow us to hold on to the charge even if allocation fails on first try, and adds a path to call ttm_bo_evict_alloc when the charged allocation falls within min/low protection limits. "drm/ttm: Use common ancestor..." is a more general improvement in correctly implementing cgroup protection semantics. With recursive protection rules, unused memory protection afforded to a parent node is transferred to children recursively, which helps protect entire subtrees from stealing each others' memory without needing to protect each cgroup individually. This doesn't apply when considering direct siblings inside the same subtree, so in order to not break prioritization between these siblings, we need to consider the relationship of evictor and evictee when calculating protection. In practice, this fixes cases where a protected cgroup cannot steal memory from unprotected siblings (which, in turn, leads to eviction failures and new allocations being placed in GTT). Thanks, Natalie Signed-off-by: Natalie Vock =2D-- Changes in v6: - Rename dmem_cgroup_common_ancestor to dmem_cgroup_get_common_ancestor (Maarten) - Use ttm_bo_alloc_at_place in eviction cb as well (Tvrtko) - Clean up the more aggressive eviction logic (Tvrtko) - Link to v5: https://lore.kernel.org/r/20260302-dmemcg-aggressive-protect= -v5-0-ffd3a2602309@gmx.de Changes in v5: - Added cgroup_common_ancestor helper to use with dmem_cgroup_common_ancestor (Tejun) - Note: "drm/ttm: Use common ancestor..." needed minor changes since dmem_cgroup_common_ancestor now grabs a reference to the ancestor pool which needs to be dropped after use - Removed extraneous whitespaces in "drm/ttm: Split cgroup charge..." and unnecessary changes done in "drm/ttm: Extract code..." (Tvrtko) - Applied a comment from v3 about below_low not needing to be initialized in "drm/ttm: Be more aggressive..." (Tvrtko) - Fixed uncharging the cgroup on allocation failure (Tvrtko) - Fixed a typo in the message of "drm/ttm: Split cgroup charge..." (Tvrtko) - Added case in ttm_bo_evict_cb for when charging fails, since we need to retry the charge (found myself) - Link to v4: https://lore.kernel.org/r/20260225-dmemcg-aggressive-protect= -v4-0-de847ab35184@gmx.de Changes in v4: - Split cgroup charge decoupling and eviction logic changes into separate commits (Tvrtko) - Fix two cases of errno handling in ttm_bo_alloc_place and its caller (Tvrtko) - Improve commit message/description of "drm/ttm: Make a helper..." (now "drm/ttm: Extract code...") (Tvrtko) - Documentation improvements for new TTM eviction logic (Tvrtko) - Formatting fixes (Tvrtko) - Link to v3: https://lore.kernel.org/r/20251110-dmemcg-aggressive-protect= -v3-0-219ffcfc54e9@gmx.de Changes in v3: - Improved documentation around cgroup queries and TTM eviction helpers (Maarten) - Fixed up ttm_alloc_at_place charge failure logic to return either -EBUSY or -ENOSPC, not -EAGAIN (found this myself) - Link to v2: https://lore.kernel.org/r/20251015-dmemcg-aggressive-protect= -v2-0-36644fb4e37f@gmx.de Changes in v2: - Factored out the ttm logic for charging/allocating/evicting into a separate helper to keep things simpler - Link to v1: https://lore.kernel.org/r/20250915-dmemcg-aggressive-protect= -v1-0-2f3353bfcdac@gmx.de =2D-- Natalie Vock (6): cgroup/dmem: Add queries for protection values cgroup,cgroup/dmem: Add (dmem_)cgroup_common_ancestor helper drm/ttm: Extract code for attempting allocation in a place drm/ttm: Split cgroup charge and resource allocation drm/ttm: Be more aggressive when allocating below protection limit drm/ttm: Use common ancestor of evictor and evictee as limit pool drivers/gpu/drm/ttm/ttm_bo.c | 221 ++++++++++++++++++++++++++++++++= =2D---- drivers/gpu/drm/ttm/ttm_resource.c | 48 +++++--- include/drm/ttm/ttm_resource.h | 6 +- include/linux/cgroup.h | 21 ++++ include/linux/cgroup_dmem.h | 25 +++++ kernel/cgroup/dmem.c | 90 +++++++++++++++ 6 files changed, 368 insertions(+), 43 deletions(-) =2D-- base-commit: 61c0f69a2ff79c8f388a9e973abb4853be467127 change-id: 20250915-dmemcg-aggressive-protect-5cf37f717cdb Best regards, =2D-=20 Natalie Vock