From: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
To: Boris Brezillon <boris.brezillon@collabora.com>,
Steven Price <steven.price@arm.com>,
Liviu Dudau <liviu.dudau@arm.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Sumit Semwal <sumit.semwal@linaro.org>,
Christian König <christian.koenig@amd.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Subject: [PATCH 4/4] drm/panthor: Add explicit memory claim sysfs knob
Date: Wed, 06 May 2026 12:45:59 +0200 [thread overview]
Message-ID: <20260506-panthor-explicit-reclaim-v1-4-44f82ac147ce@collabora.com> (raw)
In-Reply-To: <20260506-panthor-explicit-reclaim-v1-0-44f82ac147ce@collabora.com>
For deployments of systems with very tight memory and a system resource
manager process that can make well-founded decisions on trade-offs, a
way to tell panthor that all of a process' swapped-out GPU memory should
be swapped back in without touching every page manually is of interest.
Make it possible to do this by adding a new sysfs file, called
"mem_claim". Writing a TGID to it will cause panthor to search through
all panthor_files associated with that process, and bring all its
buffers back from swap.
Doing this requires the writer to have the CAP_SYS_RESOURCE capability,
even when operating on themselves.
Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
---
Documentation/ABI/testing/sysfs-driver-panthor-mem | 17 ++++++++++++++
drivers/gpu/drm/panthor/panthor_drv.c | 26 ++++++++++++++++++++++
drivers/gpu/drm/panthor/panthor_mmu.c | 25 +++++++++++++++++++++
drivers/gpu/drm/panthor/panthor_mmu.h | 1 +
4 files changed, 69 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-driver-panthor-mem b/Documentation/ABI/testing/sysfs-driver-panthor-mem
index 6639394abed2..41e2c18f641d 100644
--- a/Documentation/ABI/testing/sysfs-driver-panthor-mem
+++ b/Documentation/ABI/testing/sysfs-driver-panthor-mem
@@ -15,3 +15,20 @@ Description:
* -EPERM: insufficient permissions to run a reclaim on given TGID
* -EINTR: interrupted by signal
* -ESRCH: given TGID is not using panthor, and might not exist at all
+
+What: /sys/bus/platform/drivers/panthor/.../mem_claim
+Date: May 2026
+Contact: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
+Description:
+ (WO) Writing to this file will cause GPU memory for all panthor GPU
+ contexts associated with the TGID that's written to it to be brought
+ back from swap. The write completes when the operation has finished.
+
+ The writing process requires the CAP_SYS_RESOURCE capability.
+
+ Possible error codes:
+ * -ERANGE: given TGID is too large/small for the TGID type.
+ * -EINVAL: given TGID could not be parsed.
+ * -EPERM: insufficient permissions
+ * -EINTR: interrupted by signal
+ * -ESRCH: given TGID is not using panthor, and might not exist at all
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index 7d19b8785ea3..fb2172b0439c 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1924,9 +1924,35 @@ static ssize_t mem_reclaim_store(struct device *dev,
static DEVICE_ATTR_WO(mem_reclaim);
+static ssize_t mem_claim_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct panthor_device *ptdev = dev_get_drvdata(dev);
+ pid_t tgid;
+ int ret;
+
+ ret = kstrtoint(buf, 0, &tgid);
+ if (ret)
+ return ret;
+
+ if (!capable(CAP_SYS_RESOURCE))
+ return -EPERM;
+
+ ret = panthor_run_on_pfiles_of_tgid(ptdev, tgid, panthor_mmu_force_claim);
+ if (ret < 0)
+ return ret;
+ else if (!ret)
+ return -ESRCH;
+
+ return len;
+}
+
+static DEVICE_ATTR_WO(mem_claim);
+
static struct attribute *panthor_attrs[] = {
&dev_attr_profiling.attr,
&dev_attr_mem_reclaim.attr,
+ &dev_attr_mem_claim.attr,
NULL,
};
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index e185787f5657..7130ba4a24da 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -3232,6 +3232,31 @@ void panthor_mmu_force_reclaim(struct panthor_file *pfile)
freed, freed_sz, nr_to_scan, remaining);
}
+/**
+ * panthor_mmu_force_claim - Swap in all VMs associated with a file
+ * @pfile: pointer to the &struct panthor_file whose memory to swap in
+ *
+ * Attempt to get all GPU memory of @pfile swapped back in.
+ */
+void panthor_mmu_force_claim(struct panthor_file *pfile)
+{
+ struct panthor_vm *vm;
+ unsigned long i;
+ int ret;
+
+ xa_for_each(&pfile->vms->xa, i, vm) {
+ struct dma_resv *resv = drm_gpuvm_resv(&vm->base);
+
+ dma_resv_lock(resv, NULL);
+ ret = drm_gpuvm_validate(&vm->base, NULL);
+ if (ret)
+ drm_dbg(&vm->ptdev->base, "drm_gpuvm_validate failed: %pe\n",
+ ERR_PTR(ret));
+
+ dma_resv_unlock(resv);
+ }
+}
+
/**
* panthor_mmu_unplug() - Unplug the MMU logic
* @ptdev: Device.
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.h b/drivers/gpu/drm/panthor/panthor_mmu.h
index 34adca4b4e95..460f83eb22a9 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.h
+++ b/drivers/gpu/drm/panthor/panthor_mmu.h
@@ -25,6 +25,7 @@ void panthor_mmu_post_reset(struct panthor_device *ptdev);
void panthor_mmu_suspend(struct panthor_device *ptdev);
void panthor_mmu_resume(struct panthor_device *ptdev);
void panthor_mmu_force_reclaim(struct panthor_file *pfile);
+void panthor_mmu_force_claim(struct panthor_file *pfile);
int panthor_vm_map_bo_range(struct panthor_vm *vm, struct panthor_gem_object *bo,
u64 offset, u64 size, u64 va, u32 flags);
--
2.54.0
next prev parent reply other threads:[~2026-05-06 10:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 10:45 [PATCH 0/4] Let userspace explicitly trigger memory reclaims Nicolas Frattaroli
2026-05-06 10:45 ` [PATCH 1/4] drm/panthor: Add freed_sz parameter to reclaim_priv_bos Nicolas Frattaroli
2026-05-06 15:06 ` Steven Price
2026-05-06 15:19 ` Nicolas Frattaroli
2026-05-07 3:42 ` Claude review: " Claude Code Review Bot
2026-05-06 10:45 ` [PATCH 2/4] MAINTAINERS: Add sysfs ABI docs to list of panthor files Nicolas Frattaroli
2026-05-07 3:42 ` Claude review: " Claude Code Review Bot
2026-05-06 10:45 ` [PATCH 3/4] drm/panthor: Add explicit memory reclaim sysfs knob Nicolas Frattaroli
2026-05-07 3:42 ` Claude review: " Claude Code Review Bot
2026-05-06 10:45 ` Nicolas Frattaroli [this message]
2026-05-07 3:42 ` Claude review: drm/panthor: Add explicit memory claim " Claude Code Review Bot
2026-05-06 15:06 ` [PATCH 0/4] Let userspace explicitly trigger memory reclaims Steven Price
2026-05-06 15:43 ` Nicolas Frattaroli
2026-05-06 15:55 ` Steven Price
2026-05-07 3:42 ` Claude review: " Claude Code Review Bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260506-panthor-explicit-reclaim-v1-4-44f82ac147ce@collabora.com \
--to=nicolas.frattaroli@collabora.com \
--cc=airlied@gmail.com \
--cc=boris.brezillon@collabora.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=liviu.dudau@arm.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=steven.price@arm.com \
--cc=sumit.semwal@linaro.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox