From patchwork Wed Dec 4 13:44:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13893800 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC5A0E7716B for ; Wed, 4 Dec 2024 13:44:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A85D6B0096; Wed, 4 Dec 2024 08:44:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 40BAB6B0099; Wed, 4 Dec 2024 08:44:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25EC96B009A; Wed, 4 Dec 2024 08:44:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 014036B0096 for ; Wed, 4 Dec 2024 08:44:26 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9F0CE160FF9 for ; Wed, 4 Dec 2024 13:44:26 +0000 (UTC) X-FDA: 82857395544.07.DE749BA Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 881161C001A for ; Wed, 4 Dec 2024 13:44:18 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=none (imf18.hostedemail.com: domain of mlankhorst@mblankhorst.nl has no SPF policy when checking 141.105.120.124) smtp.mailfrom=mlankhorst@mblankhorst.nl ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733319851; a=rsa-sha256; cv=none; b=qbb3qTT2I/2NfVcUwktX439uRlecid2/qsxp+0x/qZR7cmotbW3dxKtToC1Nmp7ig+A21c Q0rUvv81wZTPomyKnj8FuXfKLCGn1KKyMCflJQ9RQuAvV2+kxCTXPwIzMvFXkoJ3rQLzC3 3fg+tDEh2Civ+lLFnE5GlKhqoKBn5DM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=none; spf=none (imf18.hostedemail.com: domain of mlankhorst@mblankhorst.nl has no SPF policy when checking 141.105.120.124) smtp.mailfrom=mlankhorst@mblankhorst.nl ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733319851; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zegV347caA0s8BZ7GEXiSZYIv8SzjPo5UMB3MMj8mc0=; b=ned4OCf6o50G23JberR37T9qW/t3Kuw2TlKcpx3pDxeQUJLD3+he4S64zRQKWPJ/d0baFX ZzeF4z2k7RqeK9tAe/oTTXhWIY7CGb1W3t9cvYSTcdtPBpC+rNbgRIYeyzDNdLgQ1zj4iB w+MwKn1/Wim5nbfsUrufYRIY/I/BMns= From: Maarten Lankhorst To: linux-kernel@vger.kernel.org, intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Tejun Heo , Zefan Li , Johannes Weiner , Andrew Morton , Friedrich Vock , Maxime Ripard Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, Maarten Lankhorst , Maarten Lankhorst Subject: [PATCH v2 7/7] drm/gem: Add cgroup memory accounting for VRAM helper. Date: Wed, 4 Dec 2024 14:44:07 +0100 Message-ID: <20241204134410.1161769-8-dev@lankhorst.se> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204134410.1161769-1-dev@lankhorst.se> References: <20241204134410.1161769-1-dev@lankhorst.se> MIME-Version: 1.0 X-Stat-Signature: 8hrn98agxdmyjmxw6k83juxtbpqumw78 X-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i Amv3cdtXSlftMPjgUtgrk6T13vkDprtvbI/IrWy6ho+p885e9FiAkI/1Wzg8/Y9dE0ZGnkQmtgGJkPeFFy76loX0/Ia6v5W2UUHmCUmFQv8013KK2ObQUf/8wboOp5rHaNapGnihxd8wXyDGtqOZVpbYkUA2SCf+Ty/KI X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Maxime Ripard This allows any driver using the VRAM helper to set limits on VRAM using cgroup. Signed-off-by: Maxime Ripard Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/drm_gem_vram_helper.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c index 22b1fe9c03b81..70979523ee984 100644 --- a/drivers/gpu/drm/drm_gem_vram_helper.c +++ b/drivers/gpu/drm/drm_gem_vram_helper.c @@ -925,6 +925,7 @@ EXPORT_SYMBOL(drm_vram_mm_debugfs_init); static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev, uint64_t vram_base, size_t vram_size) { + struct ttm_resource_manager *man; int ret; vmm->vram_base = vram_base; @@ -939,8 +940,20 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev, ret = ttm_range_man_init(&vmm->bdev, TTM_PL_VRAM, false, vram_size >> PAGE_SHIFT); - if (ret) + if (ret) { + ttm_device_fini(&vmm->bdev); return ret; + } + + man = ttm_manager_type(&vmm->bdev, TTM_PL_VRAM); + man->cg = drmm_register_region(dev, "vram", size); + if (IS_ERR(man->cg)) { + ret = PTR_ERR(man->cg); + + ttm_range_man_fini(&vmm->bdev, TTM_PL_VRAM); + ttm_device_fini(&vmm->bdev); + return ret; + } return 0; }