Skip to contentSkip to conversation

add dmem_cgroups test

PATCH Superseded Thadeu Lima de Souza Cascardo 4 participants 15 messages Jul 2 – Jul 10

Subsystems (2)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover add dmem_cgroups test

v3 TLDR:
Sending again for fixes when running on top of Xe.

This patchset is based on the work of Thomas Hellström at [1] and a followup I have submitted at [2]. This is now a v3, since I submitted [6].

With this version, I reverted the order in which to apply the patchsets, as this one adds the infrastructure and the drivers mechanisms, and a test for dmem.current and its behavior around dmem.max that is currently supported in the kernel.

As for the new dmem.max eviction behavior, introduced by [3], it has been pushed to a branch at [4]. If preferred, I can submit the two patches independently.

I have run the tests, including the ones that test dmem.max eviction behavior on a system with a 1GiB VRAM amdgpu card. Rodrigo Siqueira helped me run it on a Xe system. We have applied the patchset at [3] on top of current linux origin/master [5], with a fixup for the amdgpu driver.

Now, for the changes since v1 [2]:
- Changed the test name from drv_dmem_cgroups to dmem_cgroups.
- Have system includes before igt ones.
- Documented the current SUBTEST.
- Changed free_vram driver hook to only release a given BO. This allows for the eviction trigger by a new allocation added by write_eviction_nonblock subtest.
- Changed allocate_vram to keep more state necessary for releasing a single BO.
- Added a global free_vram helper to free all allocated VRAM.

Compared to v3 of [1]:
- I have kept wait_for_usage_drop as release can be lazy and we test for it on test_current SUBTEST, but had USAGE_DROP_TIMEOUT_MS be a little longer.
- Changed BO_SIZE and EVICT_STEP to allow for more than two eviction steps on a 1GiB VRAM system.
- Reduced USAGE_SLACK to avoid false positives, but still allow for some page table accounting.

Compared to v2 of this one [6]:

- Ignore -ENOMEM and -ENOSPC when trying to fill VRAM.
- When limiting max memory, allow for some slack, as there might be some overhead.
- On Xe, allocate GEM object with no deferred backing, and skip binding.

[1] https://patchwork.freedesktop.org/series/163935/#rev3
[2] https://patchwork.freedesktop.org/series/166496/
[3] https://lore.kernel.org/dri-devel/[email protected]/
[4] https://gitlab.freedesktop.org/cascardo/igt-gpu-tools/-/commits/dmem_max?ref_type=heads
[5] 502d801f0ab0 ("Merge tag 'erofs-for-7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs")
[6] https://lore.kernel.org/dri-devel/[email protected]/

Thadeu Lima de Souza Cascardo (4):
lib/xe: Introduce dmem driver and implement Xe support lib/amdgpu: add amdgpu_cgroup_region_name lib/amdgpu: add amdgpu support to igt_dmem_driver tests/dmem_cgroups: add test for dmem.current

Thomas Hellström (3):
lib/igt_cgroup: add cgroup v2 and dmem controller helpers tests/cgroup_dmem: add dmem cgroup controller test lib/xe: add xe_cgroup_region_name() helper

 lib/amdgpu/amd_dmem.c   |  99 +++++++
 lib/amdgpu/amd_memory.c |  25 ++
 lib/amdgpu/amd_memory.h |   2 +
 lib/igt.h               |   1 +
 lib/igt_cgroup.c        | 638 ++++++++++++++++++++++++++++++++++++++++
 lib/igt_cgroup.h        |  56 ++++
 lib/igt_dmem_driver.h   |  25 ++
 lib/meson.build         |   3 +
 lib/xe/xe_dmem.c        | 143 +++++++++
 lib/xe/xe_query.c       |  32 ++
 lib/xe/xe_query.h       |   2 +
 tests/cgroup_dmem.c     |  92 ++++++
 tests/dmem_cgroups.c    | 245 +++++++++++++++
 tests/meson.build       |   2 +
 14 files changed, 1365 insertions(+)
 create mode 100644 lib/amdgpu/amd_dmem.c
 create mode 100644 lib/igt_cgroup.c
 create mode 100644 lib/igt_cgroup.h
 create mode 100644 lib/igt_dmem_driver.h
 create mode 100644 lib/xe/xe_dmem.c
 create mode 100644 tests/cgroup_dmem.c
 create mode 100644 tests/dmem_cgroups.c
Signature · 1 line
2.47.3
#1 lore raw

PATCH v2 1/7 lib/igt_cgroup: add cgroup v2 and dmem controller helpers

From: Thomas Hellström <[email protected]>

Add igt_cgroup, a library module providing helpers to create and manage cgroup v2 sub-cgroups from IGT tests, with support for the dmem controller that governs device memory (e.g. GPU VRAM) limits.

The API covers:
- igt_cgroup_new() / igt_cgroup_free(): create and destroy a named sub-cgroup under the unified cgroupv2 hierarchy, enabling the dmem controller automatically.
- igt_cgroup_move_current(): move the calling process into a cgroup.
- igt_cgroup_dmem_set/get_max/min/low(): write and read dmem.max, dmem.min and dmem.low for a named device memory region.
- igt_cgroup_dmem_get_current(): read current per-cgroup device memory usage.
- igt_cgroup_dmem_get_system_current(): read system-wide device memory usage from the root cgroup.
- igt_cgroup_dmem_get_capacity(): read total region capacity from the root cgroup's dmem.capacity file.
- igt_cgroup_dmem_regions() / igt_cgroup_dmem_regions_free(): enumerate all registered device memory regions.

All public API functions that can fail use igt_assert internally rather than returning error codes, following the IGT convention.

Assisted-by GitHub Copilot:claude-sonnet-4.6
---
 lib/igt.h        |   1 +
 lib/igt_cgroup.c | 638 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_cgroup.h |  56 +++++
 lib/meson.build  |   1 +
 4 files changed, 696 insertions(+)
 create mode 100644 lib/igt_cgroup.c
 create mode 100644 lib/igt_cgroup.h
lib/igt.h +1 -0
index 173ca70bff28..d8e5de7dcd2f 100644
@@ -27,6 +27,7 @@
 #include "drmtest.h"
 #include "i915_3d.h"
 #include "igt_aux.h"
+#include "igt_cgroup.h"
 #include "igt_configfs.h"
 #include "igt_core.h"
 #include "igt_debugfs.h"
lib/igt_cgroup.c new file +638 -0

638 lines not on this page · raw message

lib/igt_cgroup.h new file +56 -0

56 lines not on this page · raw message

lib/meson.build +1 -0
index d1289a5e086f..e0d9c2f7475b 100644
@@ -19,6 +19,7 @@ lib_sources = [
 	'i915/i915_dp.c',
 	'igt_collection.c',
 	'igt_color_encoding.c',
+	'igt_cgroup.c',
 	'igt_configfs.c',
 	'igt_facts.c',
 	'igt_crc.c',
Signature · 1 line
2.47.3
#2 lore raw

PATCH v2 2/7 tests/cgroup_dmem: add dmem cgroup controller test

In reply to Thadeu Lima de Souza Cascardo

From: Thomas Hellström <[email protected]>

Add a test that exercises the cgroup v2 dmem controller interface using the new igt_cgroup library.

The test uses igt_simple_main and:
- Skips if no dmem regions are registered (no cgroup v2 or no dmem-capable device).
- Creates a sub-cgroup and moves the test process into it.
- Enumerates all registered device memory regions and prints their capacity, system-wide current usage, per-cgroup current usage, and configured min, low and max limits.
- Destroys the cgroup on completion.

Assisted-by GitHub Copilot:claude-sonnet-4.6
---
 tests/cgroup_dmem.c | 92 +++++++++++++++++++++++++++++++++++++++++++++
 tests/meson.build   |  1 +
 2 files changed, 93 insertions(+)
 create mode 100644 tests/cgroup_dmem.c
tests/cgroup_dmem.c new file +92 -0
new file mode 100644
index 000000000000..442c965f9bbf
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+/**
+ * TEST: cgroup dmem
+ * Description: Exercises the cgroup v2 dmem controller interface.  Creates a
+ *              cgroup, moves the process into it, enumerates all dmem regions,
+ *              prints their capacity, system-wide current usage, per-cgroup
+ *              current usage and configured limits, then destroys the cgroup.
+ * Category: Core
+ * Mega feature: General Core features
+ * Sub-category: uapi
+ * Functionality: cgroup
+ * Feature: dmem
+ * Test category: uapi
+ */
+
+#include <inttypes.h>
+
+#include "igt.h"
+#include "igt_cgroup.h"
+
+IGT_TEST_DESCRIPTION("Exercises the cgroup v2 dmem controller interface.");
+
+static void fmt_bytes(uint64_t v, char *buf, size_t len)
+{
+	if (v == IGT_CGROUP_DMEM_MAX)
+		snprintf(buf, len, "max");
+	else
+		snprintf(buf, len, "%" PRIu64, v);
+}
+
+int igt_simple_main()
+{
+	struct igt_cgroup *cg;
+	const char *region;
+	char **regions;
+	uint64_t capacity, sys_current, cg_current, min, low, max;
+	char cap_s[32], sys_s[32], cg_s[32];
+	char min_s[32], low_s[32], max_s[32];
+	int i;
+
+	igt_require_f(igt_cgroup_dmem_available(),
+		      "No dmem regions found; is cgroup v2 with the "
+		      "dmem controller available?\n");
+
+	cg = igt_cgroup_new("igt-cgroup-dmem-test");
+	igt_assert_f(cg, "Failed to create cgroup\n");
+
+	igt_cgroup_move_current(cg);
+
+	regions = igt_cgroup_dmem_regions();
+	igt_assert_f(regions, "Failed to enumerate dmem regions\n");
+
+	igt_info("%-40s %16s %16s %16s %16s %16s %16s\n",
+		 "region", "capacity", "system-current",
+		 "cgroup-current", "min", "low", "max");
+	igt_info("%-40s %16s %16s %16s %16s %16s %16s\n",
+		 "------", "--------", "--------------",
+		 "--------------", "---", "---", "---");
+
+	for (i = 0; regions[i]; i++) {
+		region = regions[i];
+
+		igt_cgroup_dmem_get_capacity(region, &capacity);
+		fmt_bytes(capacity, cap_s, sizeof(cap_s));
+
+		igt_cgroup_dmem_get_system_current(region, &sys_current);
+		fmt_bytes(sys_current, sys_s, sizeof(sys_s));
+
+		igt_cgroup_dmem_get_current(cg, region, &cg_current);
+		fmt_bytes(cg_current, cg_s, sizeof(cg_s));
+
+		igt_cgroup_dmem_get_min(cg, region, &min);
+		fmt_bytes(min, min_s, sizeof(min_s));
+
+		igt_cgroup_dmem_get_low(cg, region, &low);
+		fmt_bytes(low, low_s, sizeof(low_s));
+
+		igt_cgroup_dmem_get_max(cg, region, &max);
+		fmt_bytes(max, max_s, sizeof(max_s));
+
+		igt_info("%-40s %16s %16s %16s %16s %16s %16s\n",
+			 region, cap_s, sys_s, cg_s,
+			 min_s, low_s, max_s);
+	}
+
+	igt_cgroup_dmem_regions_free(regions);
+	igt_cgroup_free(cg);
+}
tests/meson.build +1 -0
index 96bd6213d192..88a0ce224432 100644
@@ -1,4 +1,5 @@
 test_progs = [
+	'cgroup_dmem',
 	'core_auth',
 	'core_debugfs',
 	'core_getclient',
Signature · 1 line
2.47.3
#3 lore raw

PATCH v2 3/7 lib/xe: add xe_cgroup_region_name() helper

In reply to Thadeu Lima de Souza Cascardo

From: Thomas Hellström <[email protected]>

Add xe_cgroup_region_name(fd, region) which constructs the dmem cgroup region path for a given xe memory region. The returned string has the form "drm/<pci-slot>/<region>" (e.g. "drm/0000:03:00.0/vram0"), matching the name registered by the kernel via drmm_cgroup_register_region().

Only VRAM regions are tracked by the dmem controller; system and stolen memory regions return NULL.

Assisted-by GitHub Copilot:claude-sonnet-4.6
---
 lib/xe/xe_query.c | 32 ++++++++++++++++++++++++++++++++
 lib/xe/xe_query.h |  2 ++
 2 files changed, 34 insertions(+)
lib/xe/xe_query.c +32 -0
index 68e60ddc75a2..e2b25be21140 100644
@@ -7,6 +7,7 @@
  */
 
 #include <fcntl.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <pthread.h>
 
@@ -21,6 +22,7 @@
 
 #include "drmtest.h"
 #include "igt_debugfs.h"
+#include "igt_device.h"
 #include "ioctl_wrappers.h"
 #include "igt_map.h"
 #include "intel_common.h"
@@ -1304,6 +1306,36 @@ int xe_query_eu_thread_count(int fd, int gt)
 		xe_hwconfig_lookup_value_u32(fd, INTEL_HWCONFIG_NUM_THREADS_PER_EU);
 }
 
+/**
+ * xe_cgroup_region_name() - Build the dmem cgroup region name for an xe memory region.
+ * @fd: xe device fd.
+ * @region: Region mask (as used by xe_mem_region(), xe_region_name(), etc.).
+ *
+ * Constructs the full dmem cgroup region path for @region on the device
+ * identified by @fd.  The returned string has the form
+ * ``drm/<pci-slot>/<region>`` (e.g. ``drm/0000:03:00.0/vram0``), matching
+ * the name registered by the kernel driver via drmm_cgroup_register_region().
+ *
+ * Only VRAM regions are registered with the dmem controller; passing a
+ * system-memory region returns %NULL.
+ *
+ * Return: A newly allocated string that the caller must free(), or %NULL if
+ * @region is not tracked by the dmem cgroup controller.
+ */
+char *xe_cgroup_region_name(int fd, uint64_t region)
+{
+	char pci_slot[NAME_MAX];
+	char *name;
+
+	if (xe_region_class(fd, region) != DRM_XE_MEM_REGION_CLASS_VRAM)
+		return NULL;
+
+	igt_device_get_pci_slot_name(fd, pci_slot);
+
+	igt_assert(asprintf(&name, "drm/%s/%s", pci_slot, xe_region_name(region)) > 0);
+	return name;
+}
+
 igt_constructor
 {
 	xe_device_cache_init();
lib/xe/xe_query.h +2 -0
index 59330d80fd1b..a6ef9cab9aa1 100644
@@ -206,4 +206,6 @@ void xe_device_put(int fd);
 int xe_query_eu_count(int fd, int gt);
 int xe_query_eu_thread_count(int fd, int gt);
 
+char *xe_cgroup_region_name(int fd, uint64_t region);
+
 #endif	/* XE_QUERY_H */
Signature · 1 line
2.47.3
#4 lore raw

PATCH v2 4/7 lib/xe: Introduce dmem driver and implement Xe support

In reply to Thadeu Lima de Souza Cascardo

In order to be reuse the same dmem tests with multiple drivers, we need to abstract a few operations. That includes getting the region name, and allocating and releasing VRAM. As there is some initialization also when multiple allocations are done, also provide init and deinit functions.

The Xe implementation was based on the original operations from xe_cgroups.c written by Thomas Hellström. However, instead of doing a deferred backing, followed by a bind, it does a simple non-deferred GEM object creation on the VRAM region.

---
 lib/igt_dmem_driver.h |  24 +++++++
 lib/meson.build       |   1 +
 lib/xe/xe_dmem.c      | 143 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 168 insertions(+)
 create mode 100644 lib/igt_dmem_driver.h
 create mode 100644 lib/xe/xe_dmem.c
lib/igt_dmem_driver.h new file +24 -0
new file mode 100644
index 000000000000..2f4a4673ab16
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2026 Valve Corporation
+ * Authors:
+ *  Thadeu Lima de Souza Cascardo <[email protected]>
+ */
+
+#ifndef __IGT_DMEM_DRIVER_H__
+#define __IGT_DMEM_DRIVER_H__
+
+#include <stdlib.h>
+
+struct igt_dmem_driver {
+	const char *name;
+	char * (*get_region_name)(int fd);
+	int (*init)(void **ctx, int fd, int max_bo);
+	void (*deinit)(void *ctx);
+	int (*allocate_vram)(void *ctx, int n_bo, size_t len);
+	void (*free_vram)(void *ctx, int n_bo);
+};
+
+extern const struct igt_dmem_driver xe_dmem_driver;
+
+#endif
lib/meson.build +1 -0
index e0d9c2f7475b..04fe5755c82c 100644
@@ -126,6 +126,7 @@ lib_sources = [
 	'igt_msm.c',
 	'igt_dsc.c',
 	'igt_hook.c',
+	'xe/xe_dmem.c',
 	'xe/xe_gt.c',
 	'xe/xe_ioctl.c',
 	'xe/xe_legacy.c',
lib/xe/xe_dmem.c new file +143 -0

143 lines not on this page · raw message

Signature · 1 line
2.47.3
#5 lore raw

PATCH v2 5/7 lib/amdgpu: add amdgpu_cgroup_region_name

In reply to Thadeu Lima de Souza Cascardo

The amdgpu dmem region name uses its PCI address, just like the one from Xe, but there is only a single VRAM region.

---
 lib/amdgpu/amd_memory.c | 25 +++++++++++++++++++++++++
 lib/amdgpu/amd_memory.h |  2 ++
 2 files changed, 27 insertions(+)
lib/amdgpu/amd_memory.c +25 -0
index 12fe23c65ab2..2da4a8a4baee 100644
@@ -30,9 +30,11 @@
 #include <amdgpu_drm.h>
 #include <stdio.h>
 #include <string.h>
+#include <limits.h>
 #include <unistd.h>
 #include <sys/mman.h>
 #include <inttypes.h>
+#include "igt_device.h"
 
 /**
  *
@@ -679,6 +681,29 @@ bool virtual_free_memory(void *address, unsigned int size)
 	}
 }
 
+/**
+ * amdgpu_cgroup_region_name() - Build the dmem cgroup region name for an amdgpu.
+ * @fd: amdgpu device fd.
+ *
+ * Constructs the full dmem cgroup region path for VRAM on the device
+ * identified by @fd.  The returned string has the form
+ * ``drm/<pci-slot>/vram`` (e.g. ``drm/0000:03:00.0/vram``), matching
+ * the name registered by the kernel driver via drmm_cgroup_register_region().
+ *
+ * Return: A newly allocated string that the caller must free(), or %NULL if
+ * @region is not tracked by the dmem cgroup controller.
+ */
+char *amdgpu_cgroup_region_name(int fd)
+{
+	char pci_slot[NAME_MAX];
+	char *name;
+
+	igt_device_get_pci_slot_name(fd, pci_slot);
+
+	igt_assert(asprintf(&name, "drm/%s/vram", pci_slot) > 0);
+	return name;
+}
+
 /**
  * Wait for specific value in memory with timeout
  */
lib/amdgpu/amd_memory.h +2 -0
index e26c85bc4b0a..de169e580c1b 100644
@@ -105,6 +105,8 @@ void
 bool
 virtual_free_memory(void *address, unsigned int size);
 
+char *amdgpu_cgroup_region_name(int fd);
+
 bool
 wait_on_value(unsigned int *ptr, unsigned int expected);
 #endif
Signature · 1 line
2.47.3
#6 lore raw

PATCH v2 6/7 lib/amdgpu: add amdgpu support to igt_dmem_driver

In reply to Thadeu Lima de Souza Cascardo

This allows dmem cgroups tests to run on top of amdgpu driver, adding support to allocate and release VRAM memory.

This does this by allocating a BO from VRAM domain, which will try to place BOs on VRAM, but may fallback to GTT.

---
 lib/amdgpu/amd_dmem.c | 99 +++++++++++++++++++++++++++++++++++++++++++
 lib/igt_dmem_driver.h |  1 +
 lib/meson.build       |  1 +
 3 files changed, 101 insertions(+)
 create mode 100644 lib/amdgpu/amd_dmem.c
lib/amdgpu/amd_dmem.c new file +99 -0
new file mode 100644
index 000000000000..5ff6437dc78a
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2026 Valve Corporation
+ * Authors:
+ *  Thadeu Lima de Souza Cascardo <[email protected]>
+ */
+
+#include <errno.h>
+
+#include "igt.h"
+#include "igt_cgroup.h"
+#include "igt_dmem_driver.h"
+#include "lib/amdgpu/amd_memory.h"
+
+struct amdgpu_dmem_ctx {
+	int fd;
+	amdgpu_device_handle device;
+	amdgpu_bo_handle *handles;
+	int max_bo;
+};
+
+static int amdgpu_dmem_init(void **ctx, int fd, int max_bo)
+{
+	struct amdgpu_dmem_ctx *actx;
+	uint32_t major, minor;
+	int err = -ENOMEM;
+
+	actx = malloc(sizeof(*actx));
+	if (!actx)
+		return -ENOMEM;
+
+	actx->handles = calloc(max_bo, sizeof(actx->handles[0]));
+	if (!actx->handles)
+		goto out;
+
+	actx->max_bo = max_bo;
+
+	err = amdgpu_device_initialize(fd, &major, &minor, &actx->device);
+	if (err)
+		goto out;
+
+	*ctx = actx;
+
+	return 0;
+
+out:
+	if (actx->handles)
+		free(actx->handles);
+	free(actx);
+
+	return err;
+}
+
+static void amdgpu_dmem_deinit(void *ctx)
+{
+	struct amdgpu_dmem_ctx *actx = ctx;
+
+	amdgpu_device_deinitialize(actx->device);
+	free(actx->handles);
+	free(actx);
+}
+
+static int amdgpu_dmem_allocate_vram(void *ctx, int n_bo, size_t len)
+{
+	struct amdgpu_dmem_ctx *actx = ctx;
+	amdgpu_bo_handle handle;
+	int err;
+
+	if (n_bo >= actx->max_bo)
+		return -ENOMEM;
+
+	err = amdgpu_bo_alloc_wrap(actx->device, len, 4096,
+				   AMDGPU_GEM_DOMAIN_VRAM, 0, &handle);
+	if (err)
+		return err;
+
+	actx->handles[n_bo] = handle;
+
+	return 0;
+}
+
+static void amdgpu_dmem_free_vram(void *ctx, int n_bo)
+{
+	struct amdgpu_dmem_ctx *actx = ctx;
+	if (n_bo >= actx->max_bo)
+		return;
+	if (actx->handles[n_bo])
+		amdgpu_bo_free(actx->handles[n_bo]);
+	actx->handles[n_bo] = 0;
+}
+
+const struct igt_dmem_driver amdgpu_dmem_driver = {
+	.name = "amdgpu",
+	.get_region_name = amdgpu_cgroup_region_name,
+	.init = amdgpu_dmem_init,
+	.deinit = amdgpu_dmem_deinit,
+	.allocate_vram = amdgpu_dmem_allocate_vram,
+	.free_vram = amdgpu_dmem_free_vram,
+};
lib/igt_dmem_driver.h +1 -0
index 2f4a4673ab16..d34c839740a5 100644
@@ -20,5 +20,6 @@ struct igt_dmem_driver {
 };
 
 extern const struct igt_dmem_driver xe_dmem_driver;
+extern const struct igt_dmem_driver amdgpu_dmem_driver;
 
 #endif
lib/meson.build +1 -0
index 04fe5755c82c..6bf9d0d9cb74 100644
@@ -199,6 +199,7 @@ if libdrm_amdgpu.found()
 		'amdgpu/amd_mmd_shared.c',
 		'amdgpu/amd_jpeg_shared.c',
 		'amdgpu/amd_utils.c',
+		'amdgpu/amd_dmem.c',
 		'amdgpu/amd_vcn_shared.c'
 	]
 	if libdrm_amdgpu.version().version_compare('> 2.4.99')
Signature · 1 line
2.47.3
#7 lore raw

PATCH v2 7/7 tests/dmem_cgroups: add test for dmem.current

In reply to Thadeu Lima de Souza Cascardo

Based on the work of Thomas Hellström to test dmem.max eviction, add a test for dmem.current usage after allocations and setting dmem.max.

Create a dmem cgroup, allocate close to capacity (or at most 4GiB), check current usage is within a small slack of the expected allocation. Then, set max to a small value and check allocations and current usage are limited to the max set. Set max to 0, then check no allocations are allowed and current usage is also within the slack. After each allocation, release memory and check current usage has gone down.

---
 tests/dmem_cgroups.c | 245 +++++++++++++++++++++++++++++++++++++++++++
 tests/meson.build    |   1 +
 2 files changed, 246 insertions(+)
 create mode 100644 tests/dmem_cgroups.c
tests/dmem_cgroups.c new file +245 -0
new file mode 100644
index 000000000000..da2475a14ff9
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+/**
+ * TEST: dmem_cgroups
+ * DESCRIPTION: Tests exercising the dmem cgroup controller on devices.
+ * Category: Core
+ * Mega feature: General Core features
+ * Sub-category: cgroup
+ * FUNCTIONALITY: cgroup dmem controller
+ */
+
+#include <errno.h>
+#include <signal.h>
+#include <stdatomic.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "drmtest.h"
+#include "igt.h"
+#include "igt_aux.h"
+#include "igt_cgroup.h"
+#include "igt_dmem_driver.h"
+
+#define BO_SIZE			SZ_64M
+#define MAX_LIMIT		((uint64_t)4 * SZ_1G)
+#define USAGE_SLACK		SZ_4M		/* tolerance above the set max */
+#define USAGE_POLL_MS		10
+#define USAGE_DROP_TIMEOUT_MS	1000
+
+/**
+ * SUBTEST: current
+ * DESCRIPTION:
+ *  Create a dmem cgroup, allocate close to capacity (or at most 4GiB),
+ *  check current usage is within a small slack of the expected allocation.
+ *  Then, set max to a small value and check allocations and current usage
+ *  are limited to the max set.
+ *  Set max to 0, then check no allocations are allowed and current usage
+ *  is also within the slack.
+ *  After each allocation, release memory and check current usage has gone
+ *  down.
+ * REQUIREMENTS: xe or amdgpu device with at least one VRAM region
+ */
+
+static uint64_t wait_for_usage_drop(struct igt_cgroup *cg, const char *region,
+				    uint64_t limit)
+{
+	uint64_t current;
+	unsigned int elapsed = 0;
+
+	do {
+		igt_cgroup_dmem_get_current(cg, region, &current);
+		if (current <= limit)
+			return current;
+		usleep(USAGE_POLL_MS * 1000);
+		elapsed += USAGE_POLL_MS;
+	} while (elapsed < USAGE_DROP_TIMEOUT_MS);
+
+	return current;
+}
+
+static int allocate_vram(const struct igt_dmem_driver *drv, void *ctx, int fd, int max_bo, size_t len)
+{
+	int n_bo, err = 0;
+	for (n_bo = 0; n_bo < max_bo; n_bo++) {
+		err = drv->allocate_vram(ctx, n_bo, len);
+		if (err)
+			break;
+	}
+	/* These are expected failures we can ignore. */
+	if (err == -ENOMEM || err == -ENOSPC)
+		err = 0;
+	return err ?: n_bo;
+}
+
+static void free_vram(const struct igt_dmem_driver *drv, void *ctx, int max_bo)
+{
+	int i;
+	for (i = 0; i < max_bo; i++)
+		drv->free_vram(ctx, i);
+}
+
+static void test_current(int fd, char *cg_region, unsigned int flags, const struct igt_dmem_driver *drv)
+{
+	struct igt_cgroup *cg;
+	void *ctx;
+	uint64_t current, capacity, cg_max;
+	int n_bo = 0, max_bo;
+	int err;
+
+	igt_cgroup_dmem_get_capacity(cg_region, &capacity);
+	igt_require_f(capacity >= 4 * BO_SIZE,
+		      "VRAM capacity (%"PRIu64" MiB) too small to test\n",
+		      capacity / SZ_1M);
+
+	/*
+	 * Use up to 4 GiB, or the full capacity if the device has less.
+	 * Leave one BO_SIZE worth of headroom so the device isn't completely
+	 * exhausted before the cgroup limit is hit.
+	 */
+	cg_max = min(MAX_LIMIT, capacity - BO_SIZE - USAGE_SLACK);
+	cg_max = ALIGN_DOWN(cg_max, BO_SIZE);
+
+	/* Create cgroup and move into it */
+	cg = igt_cgroup_new("igt_cgroups_test");
+	igt_cgroup_move_current(cg);
+
+	max_bo = cg_max / BO_SIZE;
+
+	err = drv->init(&ctx, fd, max_bo);
+	igt_assert_f(!err, "Failed to initialize driver");
+
+	n_bo = allocate_vram(drv, ctx, fd, max_bo, BO_SIZE);
+	igt_assert_f(n_bo > 0, "failed to allocate VRAM\n");
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After fill: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < cg_max + USAGE_SLACK && current > cg_max - USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin of allocation (%"PRIu64" MiB)\n",
+		     current / SZ_1M, cg_max / SZ_1M);
+
+	free_vram(drv, ctx, n_bo);
+	wait_for_usage_drop(cg, cg_region, USAGE_SLACK);
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After free: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin (%d MiB)\n",
+		     current / SZ_1M, USAGE_SLACK / SZ_1M);
+
+	/* Allow for a slack as there might be some extra pages allocated. */
+	igt_cgroup_dmem_set_max(cg, cg_region, 2 * BO_SIZE + USAGE_SLACK, false);
+
+	n_bo = allocate_vram(drv, ctx, fd, max_bo, BO_SIZE);
+	igt_assert_f(n_bo > 0, "failed to allocate VRAM\n");
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After fill: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < 2 * BO_SIZE + USAGE_SLACK && current > 2 * BO_SIZE - USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin of allocation (%"PRIu64" MiB)\n",
+		     current / SZ_1M, cg_max / SZ_1M);
+
+	free_vram(drv, ctx, n_bo);
+	wait_for_usage_drop(cg, cg_region, USAGE_SLACK);
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After free: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin (%d MiB)\n",
+		     current / SZ_1M, USAGE_SLACK / SZ_1M);
+
+	igt_cgroup_dmem_set_max(cg, cg_region, USAGE_SLACK, false);
+
+	n_bo = allocate_vram(drv, ctx, fd, max_bo, BO_SIZE);
+	igt_assert_f(n_bo != -ENOMEM, "VRAM allocation succeeded despite max set to 0\n");
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After fill: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin\n",
+		     current / SZ_1M);
+
+	if (n_bo > 0)
+		free_vram(drv, ctx, n_bo);
+	wait_for_usage_drop(cg, cg_region, USAGE_SLACK);
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After free: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin (%d MiB)\n",
+		     current / SZ_1M, USAGE_SLACK / SZ_1M);
+
+	drv->deinit(ctx);
+	igt_cgroup_free(cg);
+}
+
+static const struct {
+	const char *name;
+	void (*test_fn)(int fd, char *cg_region, unsigned int flags, const struct igt_dmem_driver *drv);
+	unsigned int flags;
+} subtests[] = {
+	{ "current", test_current, 0 },
+	{ }
+};
+
+static const struct {
+	int driver_flag;
+	const struct igt_dmem_driver *driver;
+} drivers[] = {
+	{ DRIVER_XE, &xe_dmem_driver },
+	{ DRIVER_AMDGPU, &amdgpu_dmem_driver },
+	{ },
+};
+
+int igt_main()
+{
+	igt_fixture() {
+		igt_require_f(getuid() == 0, "Test requires root\n");
+		/* Check dmem cgroup controller is available before doing anything else */
+		igt_require_f(igt_cgroup_dmem_available(),
+			      "dmem cgroup controller not available (no cgroup v2 or no registered regions)\n");
+
+	}
+
+	for (int d = 0; drivers[d].driver; d++) {
+		igt_subtest_group() {
+			int fd = -1;
+			char *cg_region;
+			igt_fixture() {
+				fd = drm_open_driver(drivers[d].driver_flag);
+				igt_require_f(fd >= 0,
+					"No %s device found, skipping\n",
+					drivers[d].driver->name);
+				cg_region = drivers[d].driver->get_region_name(fd);
+				igt_require_f(cg_region, "Region not tracked by dmem cgroup controller\n");
+			}
+
+			for (int i = 0; subtests[i].name; i++)
+				igt_subtest_f("%s-%s", drivers[d].driver->name, subtests[i].name)
+					subtests[i].test_fn(fd, cg_region, subtests[i].flags, drivers[d].driver);
+
+			igt_fixture() {
+				if (fd >= 0)
+					drm_close_driver(fd);
+				free(cg_region);
+			}
+		}
+	}
+}
tests/meson.build +1 -0
index 88a0ce224432..dfdaab41825a 100644
@@ -11,6 +11,7 @@ test_progs = [
 	'core_sysfs',
 	'dmabuf',
 	'dmabuf_sync_file',
+	'dmem_cgroups',
 	'device_reset',
 	'dumb_buffer',
 	'drm_buddy',
Signature · 1 line
2.47.3
#8 lore raw

Re: [PATCH i-g-t v2 7/7] tests/dmem_cgroups: add test for dmem.current

Hi Thadeu,

Quoted 10 lines · Thadeu Lima de Souza Cascardo

Based on the work of Thomas Hellström to test dmem.max eviction, add a test for dmem.current usage after allocations and setting dmem.max.

Create a dmem cgroup, allocate close to capacity (or at most 4GiB), check current usage is within a small slack of the expected allocation. Then, set max to a small value and check allocations and current usage are limited to the max set. Set max to 0, then check no allocations are allowed and current usage is also within the slack. After each allocation, release memory and check current usage has gone down.

Quoted 3 lines
---
 tests/dmem_cgroups.c | 245 +++++++++++++++++++++++++++++++++++++++++++

Why two tests? dmesm_cgropus and cgroups_dmem?
Why not only one? This is confusing.

Regards,
Kamil

Quoted 270 lines
 tests/meson.build    |   1 +
 2 files changed, 246 insertions(+)
 create mode 100644 tests/dmem_cgroups.c
tests/dmem_cgroups.c new file +245 -0
new file mode 100644
index 000000000000..da2475a14ff9
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+/**
+ * TEST: dmem_cgroups
+ * DESCRIPTION: Tests exercising the dmem cgroup controller on devices.
+ * Category: Core
+ * Mega feature: General Core features
+ * Sub-category: cgroup
+ * FUNCTIONALITY: cgroup dmem controller
+ */
+
+#include <errno.h>
+#include <signal.h>
+#include <stdatomic.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "drmtest.h"
+#include "igt.h"
+#include "igt_aux.h"
+#include "igt_cgroup.h"
+#include "igt_dmem_driver.h"
+
+#define BO_SIZE			SZ_64M
+#define MAX_LIMIT		((uint64_t)4 * SZ_1G)
+#define USAGE_SLACK		SZ_4M		/* tolerance above the set max */
+#define USAGE_POLL_MS		10
+#define USAGE_DROP_TIMEOUT_MS	1000
+
+/**
+ * SUBTEST: current
+ * DESCRIPTION:
+ *  Create a dmem cgroup, allocate close to capacity (or at most 4GiB),
+ *  check current usage is within a small slack of the expected allocation.
+ *  Then, set max to a small value and check allocations and current usage
+ *  are limited to the max set.
+ *  Set max to 0, then check no allocations are allowed and current usage
+ *  is also within the slack.
+ *  After each allocation, release memory and check current usage has gone
+ *  down.
+ * REQUIREMENTS: xe or amdgpu device with at least one VRAM region
+ */
+
+static uint64_t wait_for_usage_drop(struct igt_cgroup *cg, const char *region,
+				    uint64_t limit)
+{
+	uint64_t current;
+	unsigned int elapsed = 0;
+
+	do {
+		igt_cgroup_dmem_get_current(cg, region, &current);
+		if (current <= limit)
+			return current;
+		usleep(USAGE_POLL_MS * 1000);
+		elapsed += USAGE_POLL_MS;
+	} while (elapsed < USAGE_DROP_TIMEOUT_MS);
+
+	return current;
+}
+
+static int allocate_vram(const struct igt_dmem_driver *drv, void *ctx, int fd, int max_bo, size_t len)
+{
+	int n_bo, err = 0;
+	for (n_bo = 0; n_bo < max_bo; n_bo++) {
+		err = drv->allocate_vram(ctx, n_bo, len);
+		if (err)
+			break;
+	}
+	/* These are expected failures we can ignore. */
+	if (err == -ENOMEM || err == -ENOSPC)
+		err = 0;
+	return err ?: n_bo;
+}
+
+static void free_vram(const struct igt_dmem_driver *drv, void *ctx, int max_bo)
+{
+	int i;
+	for (i = 0; i < max_bo; i++)
+		drv->free_vram(ctx, i);
+}
+
+static void test_current(int fd, char *cg_region, unsigned int flags, const struct igt_dmem_driver *drv)
+{
+	struct igt_cgroup *cg;
+	void *ctx;
+	uint64_t current, capacity, cg_max;
+	int n_bo = 0, max_bo;
+	int err;
+
+	igt_cgroup_dmem_get_capacity(cg_region, &capacity);
+	igt_require_f(capacity >= 4 * BO_SIZE,
+		      "VRAM capacity (%"PRIu64" MiB) too small to test\n",
+		      capacity / SZ_1M);
+
+	/*
+	 * Use up to 4 GiB, or the full capacity if the device has less.
+	 * Leave one BO_SIZE worth of headroom so the device isn't completely
+	 * exhausted before the cgroup limit is hit.
+	 */
+	cg_max = min(MAX_LIMIT, capacity - BO_SIZE - USAGE_SLACK);
+	cg_max = ALIGN_DOWN(cg_max, BO_SIZE);
+
+	/* Create cgroup and move into it */
+	cg = igt_cgroup_new("igt_cgroups_test");
+	igt_cgroup_move_current(cg);
+
+	max_bo = cg_max / BO_SIZE;
+
+	err = drv->init(&ctx, fd, max_bo);
+	igt_assert_f(!err, "Failed to initialize driver");
+
+	n_bo = allocate_vram(drv, ctx, fd, max_bo, BO_SIZE);
+	igt_assert_f(n_bo > 0, "failed to allocate VRAM\n");
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After fill: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < cg_max + USAGE_SLACK && current > cg_max - USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin of allocation (%"PRIu64" MiB)\n",
+		     current / SZ_1M, cg_max / SZ_1M);
+
+	free_vram(drv, ctx, n_bo);
+	wait_for_usage_drop(cg, cg_region, USAGE_SLACK);
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After free: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin (%d MiB)\n",
+		     current / SZ_1M, USAGE_SLACK / SZ_1M);
+
+	/* Allow for a slack as there might be some extra pages allocated. */
+	igt_cgroup_dmem_set_max(cg, cg_region, 2 * BO_SIZE + USAGE_SLACK, false);
+
+	n_bo = allocate_vram(drv, ctx, fd, max_bo, BO_SIZE);
+	igt_assert_f(n_bo > 0, "failed to allocate VRAM\n");
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After fill: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < 2 * BO_SIZE + USAGE_SLACK && current > 2 * BO_SIZE - USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin of allocation (%"PRIu64" MiB)\n",
+		     current / SZ_1M, cg_max / SZ_1M);
+
+	free_vram(drv, ctx, n_bo);
+	wait_for_usage_drop(cg, cg_region, USAGE_SLACK);
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After free: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin (%d MiB)\n",
+		     current / SZ_1M, USAGE_SLACK / SZ_1M);
+
+	igt_cgroup_dmem_set_max(cg, cg_region, USAGE_SLACK, false);
+
+	n_bo = allocate_vram(drv, ctx, fd, max_bo, BO_SIZE);
+	igt_assert_f(n_bo != -ENOMEM, "VRAM allocation succeeded despite max set to 0\n");
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After fill: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin\n",
+		     current / SZ_1M);
+
+	if (n_bo > 0)
+		free_vram(drv, ctx, n_bo);
+	wait_for_usage_drop(cg, cg_region, USAGE_SLACK);
+
+	igt_cgroup_dmem_get_current(cg, cg_region, &current);
+	igt_debug("After free: cgroup current = %"PRIu64" MiB, "
+		  "max = %"PRIu64" MiB\n",
+		  current / SZ_1M, cg_max / SZ_1M);
+	igt_assert_f(current < USAGE_SLACK,
+		     "current usage (%"PRIu64" MiB) is not within margin (%d MiB)\n",
+		     current / SZ_1M, USAGE_SLACK / SZ_1M);
+
+	drv->deinit(ctx);
+	igt_cgroup_free(cg);
+}
+
+static const struct {
+	const char *name;
+	void (*test_fn)(int fd, char *cg_region, unsigned int flags, const struct igt_dmem_driver *drv);
+	unsigned int flags;
+} subtests[] = {
+	{ "current", test_current, 0 },
+	{ }
+};
+
+static const struct {
+	int driver_flag;
+	const struct igt_dmem_driver *driver;
+} drivers[] = {
+	{ DRIVER_XE, &xe_dmem_driver },
+	{ DRIVER_AMDGPU, &amdgpu_dmem_driver },
+	{ },
+};
+
+int igt_main()
+{
+	igt_fixture() {
+		igt_require_f(getuid() == 0, "Test requires root\n");
+		/* Check dmem cgroup controller is available before doing anything else */
+		igt_require_f(igt_cgroup_dmem_available(),
+			      "dmem cgroup controller not available (no cgroup v2 or no registered regions)\n");
+
+	}
+
+	for (int d = 0; drivers[d].driver; d++) {
+		igt_subtest_group() {
+			int fd = -1;
+			char *cg_region;
+			igt_fixture() {
+				fd = drm_open_driver(drivers[d].driver_flag);
+				igt_require_f(fd >= 0,
+					"No %s device found, skipping\n",
+					drivers[d].driver->name);
+				cg_region = drivers[d].driver->get_region_name(fd);
+				igt_require_f(cg_region, "Region not tracked by dmem cgroup controller\n");
+			}
+
+			for (int i = 0; subtests[i].name; i++)
+				igt_subtest_f("%s-%s", drivers[d].driver->name, subtests[i].name)
+					subtests[i].test_fn(fd, cg_region, subtests[i].flags, drivers[d].driver);
+
+			igt_fixture() {
+				if (fd >= 0)
+					drm_close_driver(fd);
+				free(cg_region);
+			}
+		}
+	}
+}
tests/meson.build +1 -0
index 88a0ce224432..dfdaab41825a 100644
@@ -11,6 +11,7 @@ test_progs = [
 	'core_sysfs',
 	'dmabuf',
 	'dmabuf_sync_file',
+	'dmem_cgroups',
 	'device_reset',
 	'dumb_buffer',
 	'drm_buddy',
Signature · 1 line
2.47.3
#9 lore raw

Re: [PATCH i-g-t v2 7/7] tests/dmem_cgroups: add test for dmem.current

Quoted 16 lines · Kamil Konieczny

Hi Thadeu,

Quoted 10 lines · Thadeu Lima de Souza Cascardo

Based on the work of Thomas Hellström to test dmem.max eviction, add a test for dmem.current usage after allocations and setting dmem.max.

Create a dmem cgroup, allocate close to capacity (or at most 4GiB), check current usage is within a small slack of the expected allocation. Then, set max to a small value and check allocations and current usage are limited to the max set. Set max to 0, then check no allocations are allowed and current usage is also within the slack. After each allocation, release memory and check current usage has gone down.

Quoted 3 lines
---
 tests/dmem_cgroups.c | 245 +++++++++++++++++++++++++++++++++++++++++++
Quoted 5 lines

Why two tests? dmesm_cgropus and cgroups_dmem?
Why not only one? This is confusing.

Regards,
Kamil

Agreed. This is the result of cgroups_dmem being present in the original patchset and the other test being Xe specific. The Xe specific test is now replaced by what I initially called drv_dmem_cgroups, but I ended up renaming dmem_cgroups.

I will merge them all into cgroups_dmem and send a v4.

Thanks.
Cascardo.

#10 lore raw
In reply to Thadeu Lima de Souza Cascardo

I don't know if that's a problem or not, but your patches in patch series are titled as v2 instead of v3, at least that's how I see them.

Jan

Quoted 113 lines

-----Original Message-----
From: igt-dev <[email protected]> On Behalf Of Thadeu Lima de Souza Cascardo
Sent: Thursday, July 2, 2026 3:01 PM
To: [email protected]
Cc: [email protected]; Thadeu Lima de Souza Cascardo <[email protected]>; [email protected]; amd- [email protected]; [email protected]; Christian Koenig <[email protected]>; [email protected]; Thomas Hellström <[email protected]>; Kamil Konieczny <[email protected]>; Janusz Krzysztofik <[email protected]>; Vitaly Prosyak <[email protected]>; Natalie Vock <[email protected]>; Tvrtko Ursulin <[email protected]>; [email protected]
Subject: [PATCH i-g-t v3 0/7] add dmem_cgroups test

v3 TLDR:
Sending again for fixes when running on top of Xe.

This patchset is based on the work of Thomas Hellström at [1] and a followup I have submitted at [2]. This is now a v3, since I submitted [6].

With this version, I reverted the order in which to apply the patchsets, as this one adds the infrastructure and the drivers mechanisms, and a test for dmem.current and its behavior around dmem.max that is currently supported
in the kernel.

As for the new dmem.max eviction behavior, introduced by [3], it has been pushed to a branch at [4]. If preferred, I can submit the two patches independently.

I have run the tests, including the ones that test dmem.max eviction behavior on a system with a 1GiB VRAM amdgpu card. Rodrigo Siqueira helped
me run it on a Xe system. We have applied the patchset at [3] on top of current linux origin/master [5], with a fixup for the amdgpu driver.

Now, for the changes since v1 [2]:
- Changed the test name from drv_dmem_cgroups to dmem_cgroups.
- Have system includes before igt ones.
- Documented the current SUBTEST.
- Changed free_vram driver hook to only release a given BO. This allows for the eviction trigger by a new allocation added by write_eviction_nonblock subtest.
- Changed allocate_vram to keep more state necessary for releasing a single BO.
- Added a global free_vram helper to free all allocated VRAM.

Compared to v3 of [1]:
- I have kept wait_for_usage_drop as release can be lazy and we test for it on test_current SUBTEST, but had USAGE_DROP_TIMEOUT_MS be a little longer.
- Changed BO_SIZE and EVICT_STEP to allow for more than two eviction steps on a 1GiB VRAM system.
- Reduced USAGE_SLACK to avoid false positives, but still allow for some page table accounting.

Compared to v2 of this one [6]:

- Ignore -ENOMEM and -ENOSPC when trying to fill VRAM.
- When limiting max memory, allow for some slack, as there might be some overhead.
- On Xe, allocate GEM object with no deferred backing, and skip binding.

[1] https://patchwork.freedesktop.org/series/163935/#rev3
[2] https://patchwork.freedesktop.org/series/166496/
[3] https://lore.kernel.org/dri-devel/20260611173301.17473-1-
[email protected]/
[4] https://gitlab.freedesktop.org/cascardo/igt-gpu-tools/-
/commits/dmem_max?ref_type=heads
[5] 502d801f0ab0 ("Merge tag 'erofs-for-7.2-rc1' of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs")
[6] https://lore.kernel.org/dri-devel/20260623174319.4138648-1-
[email protected]/

Thadeu Lima de Souza Cascardo (4):
lib/xe: Introduce dmem driver and implement Xe support lib/amdgpu: add amdgpu_cgroup_region_name lib/amdgpu: add amdgpu support to igt_dmem_driver tests/dmem_cgroups: add test for dmem.current

Thomas Hellström (3):
lib/igt_cgroup: add cgroup v2 and dmem controller helpers tests/cgroup_dmem: add dmem cgroup controller test lib/xe: add xe_cgroup_region_name() helper

 lib/amdgpu/amd_dmem.c   |  99 +++++++
 lib/amdgpu/amd_memory.c |  25 ++
 lib/amdgpu/amd_memory.h |   2 +
 lib/igt.h               |   1 +
 lib/igt_cgroup.c        | 638 ++++++++++++++++++++++++++++++++++++++++
 lib/igt_cgroup.h        |  56 ++++
 lib/igt_dmem_driver.h   |  25 ++
 lib/meson.build         |   3 +
 lib/xe/xe_dmem.c        | 143 +++++++++
 lib/xe/xe_query.c       |  32 ++
 lib/xe/xe_query.h       |   2 +
 tests/cgroup_dmem.c     |  92 ++++++
 tests/dmem_cgroups.c    | 245 +++++++++++++++
 tests/meson.build       |   2 +
 14 files changed, 1365 insertions(+)
 create mode 100644 lib/amdgpu/amd_dmem.c
 create mode 100644 lib/igt_cgroup.c
 create mode 100644 lib/igt_cgroup.h
 create mode 100644 lib/igt_dmem_driver.h
 create mode 100644 lib/xe/xe_dmem.c
 create mode 100644 tests/cgroup_dmem.c
 create mode 100644 tests/dmem_cgroups.c

--
2.47.3

#11 lore raw
Quoted 4 lines · Jan

I don't know if that's a problem or not, but your patches in patch series are titled as v2 instead of v3, at least that's how I see them.

Jan

I decided to name this one v3, though I did not call the previous one v2, because I have submitted a patchset earlier that was on top of Thomas Hellström patchset.

I think it tracks the history of the patchset better. I am sorry if this got confusing.

Cascardo.

Quoted 114 lines
Quoted 113 lines

-----Original Message-----
From: igt-dev <[email protected]> On Behalf Of Thadeu Lima de Souza Cascardo
Sent: Thursday, July 2, 2026 3:01 PM
To: [email protected]
Cc: [email protected]; Thadeu Lima de Souza Cascardo <[email protected]>; [email protected]; amd- [email protected]; [email protected]; Christian Koenig <[email protected]>; [email protected]; Thomas Hellström <[email protected]>; Kamil Konieczny <[email protected]>; Janusz Krzysztofik <[email protected]>; Vitaly Prosyak <[email protected]>; Natalie Vock <[email protected]>; Tvrtko Ursulin <[email protected]>; [email protected]
Subject: [PATCH i-g-t v3 0/7] add dmem_cgroups test

v3 TLDR:
Sending again for fixes when running on top of Xe.

This patchset is based on the work of Thomas Hellström at [1] and a followup I have submitted at [2]. This is now a v3, since I submitted [6].

With this version, I reverted the order in which to apply the patchsets, as this one adds the infrastructure and the drivers mechanisms, and a test for dmem.current and its behavior around dmem.max that is currently supported
in the kernel.

As for the new dmem.max eviction behavior, introduced by [3], it has been pushed to a branch at [4]. If preferred, I can submit the two patches independently.

I have run the tests, including the ones that test dmem.max eviction behavior on a system with a 1GiB VRAM amdgpu card. Rodrigo Siqueira helped
me run it on a Xe system. We have applied the patchset at [3] on top of current linux origin/master [5], with a fixup for the amdgpu driver.

Now, for the changes since v1 [2]:
- Changed the test name from drv_dmem_cgroups to dmem_cgroups.
- Have system includes before igt ones.
- Documented the current SUBTEST.
- Changed free_vram driver hook to only release a given BO. This allows for the eviction trigger by a new allocation added by write_eviction_nonblock subtest.
- Changed allocate_vram to keep more state necessary for releasing a single BO.
- Added a global free_vram helper to free all allocated VRAM.

Compared to v3 of [1]:
- I have kept wait_for_usage_drop as release can be lazy and we test for it on test_current SUBTEST, but had USAGE_DROP_TIMEOUT_MS be a little longer.
- Changed BO_SIZE and EVICT_STEP to allow for more than two eviction steps on a 1GiB VRAM system.
- Reduced USAGE_SLACK to avoid false positives, but still allow for some page table accounting.

Compared to v2 of this one [6]:

- Ignore -ENOMEM and -ENOSPC when trying to fill VRAM.
- When limiting max memory, allow for some slack, as there might be some overhead.
- On Xe, allocate GEM object with no deferred backing, and skip binding.

[1] https://patchwork.freedesktop.org/series/163935/#rev3
[2] https://patchwork.freedesktop.org/series/166496/
[3] https://lore.kernel.org/dri-devel/20260611173301.17473-1-
[email protected]/
[4] https://gitlab.freedesktop.org/cascardo/igt-gpu-tools/-
/commits/dmem_max?ref_type=heads
[5] 502d801f0ab0 ("Merge tag 'erofs-for-7.2-rc1' of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs")
[6] https://lore.kernel.org/dri-devel/20260623174319.4138648-1-
[email protected]/

Thadeu Lima de Souza Cascardo (4):
lib/xe: Introduce dmem driver and implement Xe support lib/amdgpu: add amdgpu_cgroup_region_name lib/amdgpu: add amdgpu support to igt_dmem_driver tests/dmem_cgroups: add test for dmem.current

Thomas Hellström (3):
lib/igt_cgroup: add cgroup v2 and dmem controller helpers tests/cgroup_dmem: add dmem cgroup controller test lib/xe: add xe_cgroup_region_name() helper

 lib/amdgpu/amd_dmem.c   |  99 +++++++
 lib/amdgpu/amd_memory.c |  25 ++
 lib/amdgpu/amd_memory.h |   2 +
 lib/igt.h               |   1 +
 lib/igt_cgroup.c        | 638 ++++++++++++++++++++++++++++++++++++++++
 lib/igt_cgroup.h        |  56 ++++
 lib/igt_dmem_driver.h   |  25 ++
 lib/meson.build         |   3 +
 lib/xe/xe_dmem.c        | 143 +++++++++
 lib/xe/xe_query.c       |  32 ++
 lib/xe/xe_query.h       |   2 +
 tests/cgroup_dmem.c     |  92 ++++++
 tests/dmem_cgroups.c    | 245 +++++++++++++++
 tests/meson.build       |   2 +
 14 files changed, 1365 insertions(+)
 create mode 100644 lib/amdgpu/amd_dmem.c
 create mode 100644 lib/igt_cgroup.c
 create mode 100644 lib/igt_cgroup.h
 create mode 100644 lib/igt_dmem_driver.h
 create mode 100644 lib/xe/xe_dmem.c
 create mode 100644 tests/cgroup_dmem.c
 create mode 100644 tests/dmem_cgroups.c

--
2.47.3

#12 lore raw

Hi Thadeu,

Quoted 6 lines · Thadeu Lima de Souza Cascardo
Quoted 4 lines · Jan

I don't know if that's a problem or not, but your patches in patch series are titled as v2 instead of v3, at least that's how I see them.

Jan

Quoted 9 lines

I decided to name this one v3, though I did not call the previous one v2, because I have submitted a patchset earlier that was on top of Thomas Hellström patchset.

I think it tracks the history of the patchset better. I am sorry if this got confusing.

Cascardo.

Please keep versioning the same across series, if your cover letter has v3, all patches in series should also have v3.

Regards,
Kamil

Quoted 114 lines
Quoted 114 lines
Quoted 113 lines

-----Original Message-----
From: igt-dev <[email protected]> On Behalf Of Thadeu Lima de Souza Cascardo
Sent: Thursday, July 2, 2026 3:01 PM
To: [email protected]
Cc: [email protected]; Thadeu Lima de Souza Cascardo <[email protected]>; [email protected]; amd- [email protected]; [email protected]; Christian Koenig <[email protected]>; [email protected]; Thomas Hellström <[email protected]>; Kamil Konieczny <[email protected]>; Janusz Krzysztofik <[email protected]>; Vitaly Prosyak <[email protected]>; Natalie Vock <[email protected]>; Tvrtko Ursulin <[email protected]>; [email protected]
Subject: [PATCH i-g-t v3 0/7] add dmem_cgroups test

v3 TLDR:
Sending again for fixes when running on top of Xe.

This patchset is based on the work of Thomas Hellström at [1] and a followup I have submitted at [2]. This is now a v3, since I submitted [6].

With this version, I reverted the order in which to apply the patchsets, as this one adds the infrastructure and the drivers mechanisms, and a test for dmem.current and its behavior around dmem.max that is currently supported
in the kernel.

As for the new dmem.max eviction behavior, introduced by [3], it has been pushed to a branch at [4]. If preferred, I can submit the two patches independently.

I have run the tests, including the ones that test dmem.max eviction behavior on a system with a 1GiB VRAM amdgpu card. Rodrigo Siqueira helped
me run it on a Xe system. We have applied the patchset at [3] on top of current linux origin/master [5], with a fixup for the amdgpu driver.

Now, for the changes since v1 [2]:
- Changed the test name from drv_dmem_cgroups to dmem_cgroups.
- Have system includes before igt ones.
- Documented the current SUBTEST.
- Changed free_vram driver hook to only release a given BO. This allows for the eviction trigger by a new allocation added by write_eviction_nonblock subtest.
- Changed allocate_vram to keep more state necessary for releasing a single BO.
- Added a global free_vram helper to free all allocated VRAM.

Compared to v3 of [1]:
- I have kept wait_for_usage_drop as release can be lazy and we test for it on test_current SUBTEST, but had USAGE_DROP_TIMEOUT_MS be a little longer.
- Changed BO_SIZE and EVICT_STEP to allow for more than two eviction steps on a 1GiB VRAM system.
- Reduced USAGE_SLACK to avoid false positives, but still allow for some page table accounting.

Compared to v2 of this one [6]:

- Ignore -ENOMEM and -ENOSPC when trying to fill VRAM.
- When limiting max memory, allow for some slack, as there might be some overhead.
- On Xe, allocate GEM object with no deferred backing, and skip binding.

[1] https://patchwork.freedesktop.org/series/163935/#rev3
[2] https://patchwork.freedesktop.org/series/166496/
[3] https://lore.kernel.org/dri-devel/20260611173301.17473-1-
[email protected]/
[4] https://gitlab.freedesktop.org/cascardo/igt-gpu-tools/-
/commits/dmem_max?ref_type=heads
[5] 502d801f0ab0 ("Merge tag 'erofs-for-7.2-rc1' of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs")
[6] https://lore.kernel.org/dri-devel/20260623174319.4138648-1-
[email protected]/

Thadeu Lima de Souza Cascardo (4):
lib/xe: Introduce dmem driver and implement Xe support lib/amdgpu: add amdgpu_cgroup_region_name lib/amdgpu: add amdgpu support to igt_dmem_driver tests/dmem_cgroups: add test for dmem.current

Thomas Hellström (3):
lib/igt_cgroup: add cgroup v2 and dmem controller helpers tests/cgroup_dmem: add dmem cgroup controller test lib/xe: add xe_cgroup_region_name() helper

 lib/amdgpu/amd_dmem.c   |  99 +++++++
 lib/amdgpu/amd_memory.c |  25 ++
 lib/amdgpu/amd_memory.h |   2 +
 lib/igt.h               |   1 +
 lib/igt_cgroup.c        | 638 ++++++++++++++++++++++++++++++++++++++++
 lib/igt_cgroup.h        |  56 ++++
 lib/igt_dmem_driver.h   |  25 ++
 lib/meson.build         |   3 +
 lib/xe/xe_dmem.c        | 143 +++++++++
 lib/xe/xe_query.c       |  32 ++
 lib/xe/xe_query.h       |   2 +
 tests/cgroup_dmem.c     |  92 ++++++
 tests/dmem_cgroups.c    | 245 +++++++++++++++
 tests/meson.build       |   2 +
 14 files changed, 1365 insertions(+)
 create mode 100644 lib/amdgpu/amd_dmem.c
 create mode 100644 lib/igt_cgroup.c
 create mode 100644 lib/igt_cgroup.h
 create mode 100644 lib/igt_dmem_driver.h
 create mode 100644 lib/xe/xe_dmem.c
 create mode 100644 tests/cgroup_dmem.c
 create mode 100644 tests/dmem_cgroups.c

--
2.47.3

#13 lore raw
Quoted 15 lines · Kamil Konieczny

Hi Thadeu,

Quoted 13 lines · Thadeu Lima de Souza Cascardo
Quoted 4 lines · Jan

I don't know if that's a problem or not, but your patches in patch series are titled as v2 instead of v3, at least that's how I see them.

Jan

I decided to name this one v3, though I did not call the previous one v2, because I have submitted a patchset earlier that was on top of Thomas Hellström patchset.

I think it tracks the history of the patchset better. I am sorry if this got confusing.

Quoted 8 lines
Quoted 2 lines

Cascardo.

Please keep versioning the same across series, if your cover letter has v3, all patches in series should also have v3.

Regards,
Kamil

Ah, I missed that and didn't notice when sending. I will make sure everything is v4 when I send the next version.

Cascardo.

Tested-by on the v3 series
#14 lore raw
In reply to Thadeu Lima de Souza Cascardo
Quoted 39 lines · Thadeu Lima de Souza Cascardo

v3 TLDR:
Sending again for fixes when running on top of Xe.

This patchset is based on the work of Thomas Hellström at [1] and a followup I have submitted at [2]. This is now a v3, since I submitted [6].

With this version, I reverted the order in which to apply the patchsets, as this one adds the infrastructure and the drivers mechanisms, and a test for dmem.current and its behavior around dmem.max that is currently supported in the kernel.

As for the new dmem.max eviction behavior, introduced by [3], it has been pushed to a branch at [4]. If preferred, I can submit the two patches independently.

I have run the tests, including the ones that test dmem.max eviction behavior on a system with a 1GiB VRAM amdgpu card. Rodrigo Siqueira helped me run it on a Xe system. We have applied the patchset at [3] on top of current linux origin/master [5], with a fixup for the amdgpu driver.

Now, for the changes since v1 [2]:
- Changed the test name from drv_dmem_cgroups to dmem_cgroups.
- Have system includes before igt ones.
- Documented the current SUBTEST.
- Changed free_vram driver hook to only release a given BO. This allows for the eviction trigger by a new allocation added by write_eviction_nonblock subtest.
- Changed allocate_vram to keep more state necessary for releasing a single BO.
- Added a global free_vram helper to free all allocated VRAM.

Compared to v3 of [1]:
- I have kept wait_for_usage_drop as release can be lazy and we test for it on test_current SUBTEST, but had USAGE_DROP_TIMEOUT_MS be a little longer.
- Changed BO_SIZE and EVICT_STEP to allow for more than two eviction steps on a 1GiB VRAM system.
- Reduced USAGE_SLACK to avoid false positives, but still allow for some page table accounting.

Quoted 6 lines

Compared to v2 of this one [6]:

- Ignore -ENOMEM and -ENOSPC when trying to fill VRAM.
- When limiting max memory, allow for some slack, as there might be some overhead.
- On Xe, allocate GEM object with no deferred backing, and skip binding.

Hi,

I tested this series with the following hardware:
- RX9060XT
- RX570
- Intel ARC B580

Based on that, this series was:

Thanks

Quoted 46 lines

[1] https://patchwork.freedesktop.org/series/163935/#rev3
[2] https://patchwork.freedesktop.org/series/166496/
[3] https://lore.kernel.org/dri-devel/[email protected]/
[4] https://gitlab.freedesktop.org/cascardo/igt-gpu-tools/-/commits/dmem_max?ref_type=heads
[5] 502d801f0ab0 ("Merge tag 'erofs-for-7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs")
[6] https://lore.kernel.org/dri-devel/[email protected]/

Thadeu Lima de Souza Cascardo (4):
lib/xe: Introduce dmem driver and implement Xe support lib/amdgpu: add amdgpu_cgroup_region_name lib/amdgpu: add amdgpu support to igt_dmem_driver tests/dmem_cgroups: add test for dmem.current

Thomas Hellström (3):
lib/igt_cgroup: add cgroup v2 and dmem controller helpers tests/cgroup_dmem: add dmem cgroup controller test lib/xe: add xe_cgroup_region_name() helper

 lib/amdgpu/amd_dmem.c   |  99 +++++++
 lib/amdgpu/amd_memory.c |  25 ++
 lib/amdgpu/amd_memory.h |   2 +
 lib/igt.h               |   1 +
 lib/igt_cgroup.c        | 638 ++++++++++++++++++++++++++++++++++++++++
 lib/igt_cgroup.h        |  56 ++++
 lib/igt_dmem_driver.h   |  25 ++
 lib/meson.build         |   3 +
 lib/xe/xe_dmem.c        | 143 +++++++++
 lib/xe/xe_query.c       |  32 ++
 lib/xe/xe_query.h       |   2 +
 tests/cgroup_dmem.c     |  92 ++++++
 tests/dmem_cgroups.c    | 245 +++++++++++++++
 tests/meson.build       |   2 +
 14 files changed, 1365 insertions(+)
 create mode 100644 lib/amdgpu/amd_dmem.c
 create mode 100644 lib/igt_cgroup.c
 create mode 100644 lib/igt_cgroup.h
 create mode 100644 lib/igt_dmem_driver.h
 create mode 100644 lib/xe/xe_dmem.c
 create mode 100644 tests/cgroup_dmem.c
 create mode 100644 tests/dmem_cgroups.c
Signature · 1 line
2.47.3
Signature · 2 lines
Rodrigo Siqueira
https://siqueira.tech