From patchwork Wed Dec 4 13:44:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13893793 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 2E3B4E7716B for ; Wed, 4 Dec 2024 13:44:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89E776B0088; Wed, 4 Dec 2024 08:44:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 84E896B0089; Wed, 4 Dec 2024 08:44:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 715DD6B008A; Wed, 4 Dec 2024 08:44:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 53B826B0088 for ; Wed, 4 Dec 2024 08:44:20 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ABB1EA101B for ; Wed, 4 Dec 2024 13:44:19 +0000 (UTC) X-FDA: 82857395712.14.18254E2 Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 4B4CD100018 for ; Wed, 4 Dec 2024 13:43:50 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=none (imf05.hostedemail.com: domain of mlankhorst@mblankhorst.nl has no SPF policy when checking 141.105.120.124) smtp.mailfrom=mlankhorst@mblankhorst.nl; dmarc=none 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:references; bh=DUI5Bdl8emdHeupH/u9cPI1LWsFbvKzWqkmlZu29ykM=; b=QZEzD2+KuR26D0iEir2UvPgT4h1QB5e8q6jmyo84/ufVeyZDKTt/dno7EcABMHFa+C/37T OW5kxPwUc+SSa/kohH1JKRP4bjEvzu8xc3v3K0fohRanu2bRotc7yFXUZ7p8s75FKNQsQb 1YIh5MpWqYNVWXfvJM8hQ8j5obwtOP4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733319851; a=rsa-sha256; cv=none; b=y5JJCdcR3qpGx3tQcA3G1fP1gjCzRY3NmZ6GLaHWNcJWmHIHYCpsZ1EK0OIKFonduGpv5X oz8MydlfECW/JrG+7OugIi1eJRpmzdCWOV/M25xz6HUgnhqFV973aiE3ABkjWbpFtTGARA /l2ZGLQzVIA8OR+Iw3DzxPTXPr2AtBk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=none (imf05.hostedemail.com: domain of mlankhorst@mblankhorst.nl has no SPF policy when checking 141.105.120.124) smtp.mailfrom=mlankhorst@mblankhorst.nl; dmarc=none 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 0/7] kernel/cgroups: Add "dmem" memory accounting cgroup. Date: Wed, 4 Dec 2024 14:44:00 +0100 Message-ID: <20241204134410.1161769-1-dev@lankhorst.se> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4B4CD100018 X-Stat-Signature: 4j91jtt4mgpm1i6ihu4gg5fewgjbu3hq X-Rspam-User: X-HE-Tag: 1733319830-78979 X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z5ALlnENK5Gwicr4L00+VuHA8Q9MlxPt9MoIUXAfUyK4= 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: New update. Instead of calling it the 'dev' cgroup, it's now the 'dmem' cgroup. Because it only deals with memory regions, the UAPI has been updated to use dmem.min/low/max/current, and to make the API cleaner, the names are changed too. dmem.current could contain a line like: "drm/0000:03:00.0/vram0 1073741824" But I think using "drm/card0/vram0" instead of PCIID would perhaps be good too. I'm open to changing it to that based on feedback. I've created an IGT test for min and max, and found the changes from Friedrich Vock sent as feedback were needed. I've integrated those into the first patch. Maarten Lankhorst (5): kernel/cgroup: Add "dmem" memory accounting cgroup drm/ttm: Handle cgroup based eviction in TTM drm/xe: Implement cgroup for vram drm/amdgpu: Add cgroups implementation drm/xe: Hack to test with mapped pages instead of vram. Maxime Ripard (2): drm/drv: Add drmm managed registration helper for dmem cgroups. drm/gem: Add cgroup memory accounting for VRAM helper. Documentation/admin-guide/cgroup-v2.rst | 58 +- Documentation/core-api/cgroup.rst | 9 + Documentation/core-api/index.rst | 1 + Documentation/gpu/drm-compute.rst | 54 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 4 + drivers/gpu/drm/drm_drv.c | 32 + drivers/gpu/drm/drm_gem_vram_helper.c | 15 +- drivers/gpu/drm/ttm/tests/ttm_bo_test.c | 18 +- .../gpu/drm/ttm/tests/ttm_bo_validate_test.c | 4 +- drivers/gpu/drm/ttm/tests/ttm_resource_test.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 54 +- drivers/gpu/drm/ttm/ttm_resource.c | 23 +- drivers/gpu/drm/xe/xe_ttm_sys_mgr.c | 5 + drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 8 + include/drm/drm_drv.h | 5 + include/drm/ttm/ttm_resource.h | 12 +- include/linux/cgroup_dmem.h | 67 ++ include/linux/cgroup_subsys.h | 4 + include/linux/page_counter.h | 2 +- init/Kconfig | 10 + kernel/cgroup/Makefile | 1 + kernel/cgroup/dmem.c | 861 ++++++++++++++++++ mm/page_counter.c | 4 +- 23 files changed, 1219 insertions(+), 34 deletions(-) create mode 100644 Documentation/core-api/cgroup.rst create mode 100644 Documentation/gpu/drm-compute.rst create mode 100644 include/linux/cgroup_dmem.h create mode 100644 kernel/cgroup/dmem.c