From patchwork Wed Oct 23 07:52:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13846616 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 CEFE4D2E022 for ; Wed, 23 Oct 2024 07:53:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 461F56B007B; Wed, 23 Oct 2024 03:53:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C3A56B0082; Wed, 23 Oct 2024 03:53:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2169A6B0083; Wed, 23 Oct 2024 03:53:06 -0400 (EDT) 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 F40866B007B for ; Wed, 23 Oct 2024 03:53:05 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 12EF71C4C30 for ; Wed, 23 Oct 2024 07:52:46 +0000 (UTC) X-FDA: 82704100962.28.5413FC2 Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 9DC2E1C0006 for ; Wed, 23 Oct 2024 07:52:56 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=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; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729669907; 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=Uhmn+s8k8jhQaCngLxBILWP+whnm+AxkhSDRJbAnIH0=; b=rMZvMdrVGZmpj3YnCjSuft7TH/VmsqFC1Czi7QeqmAd85pO77AjmCfWcckv3hk2RHmABOW FbuwIsASPjRe/F8ZzT2ouFDuw3bYOwt599SqrcL8Xjggnfvrgipd+4kRsFJKV5xF/gUH8g /j8SVt0QTWzcM9SyTYeyM9c032bVggw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=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; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729669907; a=rsa-sha256; cv=none; b=OOmuymSxFZWqSSLY9EwO90Fc3/f9AVNVmejXV/Ke3HEOT5RbHc6lpGgV+7kPZtXrF5tWlN CWR7i36xt7+gHdgS5Nzqnq6NlCdj6nG3XOT1L9fjpETf/dQoJis51um4bTu47IzGuf2fRG /Jq9QqTkXdnSgrKZ3zmttg8b4ppLatQ= From: Maarten Lankhorst To: intel-xe@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Tejun Heo , Zefan Li , Johannes Weiner , Andrew Morton Cc: Friedrich Vock , cgroups@vger.kernel.org, linux-mm@kvack.org, Maxime Ripard , Maarten Lankhorst Subject: [PATCH 0/7] kernel/cgroups: Add "dev" memory accounting cgroup. Date: Wed, 23 Oct 2024 09:52:53 +0200 Message-ID: <20241023075302.27194-1-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 9DC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asUR4nEVRB6B5OMQLiCnw/y8+U+jQUkDUJ2TT5MNMs1B/Es0d1vkdU4kMqkJsP/AVCqvwW8fCszovA0N4EJQKHwFgq3VYYzyzXzI7FaAI0U4fisXueivuE328AZ11FwXtt4tNpNnJWnN4pX7ISTzk42YbfEmKaFf2SOCaTnZWB9vahMfjvNYv4iLhF4h+IiRvelkOZzaaFxlrCDKwdqKNELJG4/A0+Vqao1jtE65BirH83UXmlQnYKNq+lvJG/Jcy/TcO5lHWPs6WleA== 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 submission! I've added documentation for each call, and integrated the renaming from drm cgroup to dev cgroup, based on maxime ripard's work. Maxime has been testing this with dma-buf heaps and v4l2 too, and it seems to work. In the initial submission, I've decided to only add the smallest enablement possible, to have less chance of breaking things. The API has been changed slightly, from "$name region.$regionname=$limit" in a file called dev.min/low/max to "$subsystem/$name $regionname=$limit" in a file called dev.region.min/low/max. This hopefully allows us to perhaps extend the API later on with the possibility to set scheduler weights on the device, like in https://blogs.igalia.com/tursulin/drm-scheduling-cgroup-controller/ Maarten Lankhorst (5): kernel/cgroup: Add "dev" memory accounting cgroup drm/ttm: Handle cgroup based eviction in TTM drm/xe: Implement cgroup for vram drm/amdgpu: Add cgroups implementation [HACK] drm/xe: Hack to test with mapped pages instead of vram. Maxime Ripard (2): drm/drv: Add drmm cgroup registration for dev cgroups. [DISCUSSION] drm/gem: Add cgroup memory accounting Documentation/admin-guide/cgroup-v2.rst | 51 + Documentation/core-api/cgroup.rst | 9 + Documentation/core-api/index.rst | 1 + Documentation/gpu/drm-compute.rst | 54 ++ drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 6 + drivers/gpu/drm/drm_drv.c | 32 +- drivers/gpu/drm/drm_gem.c | 4 + drivers/gpu/drm/drm_gem_dma_helper.c | 4 + 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 | 57 +- drivers/gpu/drm/ttm/ttm_resource.c | 24 +- drivers/gpu/drm/xe/xe_device.c | 4 + drivers/gpu/drm/xe/xe_device_types.h | 4 + drivers/gpu/drm/xe/xe_ttm_sys_mgr.c | 14 + drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 10 + include/drm/drm_device.h | 4 + include/drm/drm_drv.h | 4 + include/drm/drm_gem.h | 2 + include/drm/ttm/ttm_resource.h | 16 +- include/linux/cgroup_dev.h | 91 ++ include/linux/cgroup_subsys.h | 4 + include/linux/page_counter.h | 2 +- init/Kconfig | 7 + kernel/cgroup/Makefile | 1 + kernel/cgroup/dev.c | 893 ++++++++++++++++++ mm/page_counter.c | 4 +- 30 files changed, 1307 insertions(+), 27 deletions(-) create mode 100644 Documentation/core-api/cgroup.rst create mode 100644 Documentation/gpu/drm-compute.rst create mode 100644 include/linux/cgroup_dev.h create mode 100644 kernel/cgroup/dev.c