From: Ming Qian <ming.qian@oss.nxp.com>
Add a new read-only control V4L2_CID_MEMORY_USAGE that allows
applications to query the total amount of memory currently used
by a device instance.
This control reports the memory consumption in bytes, including
internal buffers, intermediate processing data, and other
driver-managed allocations. Applications can use this information
for debugging, resource monitoring, or making informed decisions
about buffer allocation strategies.
Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
---
drivers/media/v4l2-core/v4l2-ctrls-defs.c | 8 ++++++++
include/uapi/linux/v4l2-controls.h | 4 +++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
index 551426c4cd01..053db78ff661 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
@@ -831,6 +831,7 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_ALPHA_COMPONENT: return "Alpha Component";
case V4L2_CID_COLORFX_CBCR: return "Color Effects, CbCr";
case V4L2_CID_COLORFX_RGB: return "Color Effects, RGB";
+ case V4L2_CID_MEMORY_USAGE: return "Memory Usage";
/*
* Codec controls
@@ -1476,6 +1477,13 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
*min = 0;
*max = 0xffff;
break;
+ case V4L2_CID_MEMORY_USAGE:
+ *type = V4L2_CTRL_TYPE_INTEGER64;
+ *flags |= V4L2_CTRL_FLAG_READ_ONLY;
+ *min = 0;
+ *max = S64_MAX;
+ *step = 1;
+ break;
case V4L2_CID_FLASH_FAULT:
case V4L2_CID_JPEG_ACTIVE_MARKER:
case V4L2_CID_3A_LOCK:
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index 68dd0c4e47b2..02c6f960d38e 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -110,8 +110,10 @@ enum v4l2_colorfx {
#define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42)
#define V4L2_CID_COLORFX_RGB (V4L2_CID_BASE+43)
+#define V4L2_CID_MEMORY_USAGE (V4L2_CID_BASE+44)
+
/* last CID + 1 */
-#define V4L2_CID_LASTP1 (V4L2_CID_BASE+44)
+#define V4L2_CID_LASTP1 (V4L2_CID_BASE+45)
/* USER-class private control IDs */
--
2.53.0
On Tue, Mar 31, 2026 at 03:23:11PM +0800, ming.qian@oss.nxp.com wrote:
> From: Ming Qian <ming.qian@oss.nxp.com>
>
> Add a new read-only control V4L2_CID_MEMORY_USAGE that allows
> applications to query the total amount of memory currently used
> by a device instance.
>
> This control reports the memory consumption in bytes, including
> internal buffers, intermediate processing data, and other
> driver-managed allocations. Applications can use this information
> for debugging, resource monitoring, or making informed decisions
> about buffer allocation strategies.
>
> Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
> ---
Not sure why not export these information by debugfs, or any benefit vs
debugfs?
Generanlly document should be first patch, then driver change.
Frank
> drivers/media/v4l2-core/v4l2-ctrls-defs.c | 8 ++++++++
> include/uapi/linux/v4l2-controls.h | 4 +++-
> 2 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
> index 551426c4cd01..053db78ff661 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
> @@ -831,6 +831,7 @@ const char *v4l2_ctrl_get_name(u32 id)
> case V4L2_CID_ALPHA_COMPONENT: return "Alpha Component";
> case V4L2_CID_COLORFX_CBCR: return "Color Effects, CbCr";
> case V4L2_CID_COLORFX_RGB: return "Color Effects, RGB";
> + case V4L2_CID_MEMORY_USAGE: return "Memory Usage";
>
> /*
> * Codec controls
> @@ -1476,6 +1477,13 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
> *min = 0;
> *max = 0xffff;
> break;
> + case V4L2_CID_MEMORY_USAGE:
> + *type = V4L2_CTRL_TYPE_INTEGER64;
> + *flags |= V4L2_CTRL_FLAG_READ_ONLY;
> + *min = 0;
> + *max = S64_MAX;
> + *step = 1;
> + break;
> case V4L2_CID_FLASH_FAULT:
> case V4L2_CID_JPEG_ACTIVE_MARKER:
> case V4L2_CID_3A_LOCK:
> diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
> index 68dd0c4e47b2..02c6f960d38e 100644
> --- a/include/uapi/linux/v4l2-controls.h
> +++ b/include/uapi/linux/v4l2-controls.h
> @@ -110,8 +110,10 @@ enum v4l2_colorfx {
> #define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42)
> #define V4L2_CID_COLORFX_RGB (V4L2_CID_BASE+43)
>
> +#define V4L2_CID_MEMORY_USAGE (V4L2_CID_BASE+44)
> +
> /* last CID + 1 */
> -#define V4L2_CID_LASTP1 (V4L2_CID_BASE+44)
> +#define V4L2_CID_LASTP1 (V4L2_CID_BASE+45)
>
> /* USER-class private control IDs */
>
> --
> 2.53.0
>
Hi Frank,
On 3/31/2026 10:33 PM, Frank Li wrote:
> On Tue, Mar 31, 2026 at 03:23:11PM +0800, ming.qian@oss.nxp.com wrote:
>> From: Ming Qian <ming.qian@oss.nxp.com>
>>
>> Add a new read-only control V4L2_CID_MEMORY_USAGE that allows
>> applications to query the total amount of memory currently used
>> by a device instance.
>>
>> This control reports the memory consumption in bytes, including
>> internal buffers, intermediate processing data, and other
>> driver-managed allocations. Applications can use this information
>> for debugging, resource monitoring, or making informed decisions
>> about buffer allocation strategies.
>>
>> Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
>> ---
>
> Not sure why not export these information by debugfs, or any benefit vs
> debugfs?
>
> Generanlly document should be first patch, then driver change.
>
> Frank
Thanks for the comments.
The key reason for adding a V4L2 ctrl is that the original requirement
(from Android) is to query the memory usage per VPU instance in a simple
and stable way. A ctrl naturally fits this use case, as userspace
already has the instance fd and does not need to locate or map any
external paths. In contrast, relying only on debugfs would require
userspace to figure out the relationship between an instance and a
debugfs node, which is neither stable nor friendly for production
systems where debugfs may not even be available.
Debugfs is added only to expose the full hierarchical memory‑tracking
structure (device → instance → queue) for debugging and analysis. It
complements the ctrl, but cannot replace it for the original functional
requirement.
I will reorder the documentation patch to come first in the next
revision.
Regards,
Ming
>
>> drivers/media/v4l2-core/v4l2-ctrls-defs.c | 8 ++++++++
>> include/uapi/linux/v4l2-controls.h | 4 +++-
>> 2 files changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
>> index 551426c4cd01..053db78ff661 100644
>> --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
>> +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
>> @@ -831,6 +831,7 @@ const char *v4l2_ctrl_get_name(u32 id)
>> case V4L2_CID_ALPHA_COMPONENT: return "Alpha Component";
>> case V4L2_CID_COLORFX_CBCR: return "Color Effects, CbCr";
>> case V4L2_CID_COLORFX_RGB: return "Color Effects, RGB";
>> + case V4L2_CID_MEMORY_USAGE: return "Memory Usage";
>>
>> /*
>> * Codec controls
>> @@ -1476,6 +1477,13 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
>> *min = 0;
>> *max = 0xffff;
>> break;
>> + case V4L2_CID_MEMORY_USAGE:
>> + *type = V4L2_CTRL_TYPE_INTEGER64;
>> + *flags |= V4L2_CTRL_FLAG_READ_ONLY;
>> + *min = 0;
>> + *max = S64_MAX;
>> + *step = 1;
>> + break;
>> case V4L2_CID_FLASH_FAULT:
>> case V4L2_CID_JPEG_ACTIVE_MARKER:
>> case V4L2_CID_3A_LOCK:
>> diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
>> index 68dd0c4e47b2..02c6f960d38e 100644
>> --- a/include/uapi/linux/v4l2-controls.h
>> +++ b/include/uapi/linux/v4l2-controls.h
>> @@ -110,8 +110,10 @@ enum v4l2_colorfx {
>> #define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42)
>> #define V4L2_CID_COLORFX_RGB (V4L2_CID_BASE+43)
>>
>> +#define V4L2_CID_MEMORY_USAGE (V4L2_CID_BASE+44)
>> +
>> /* last CID + 1 */
>> -#define V4L2_CID_LASTP1 (V4L2_CID_BASE+44)
>> +#define V4L2_CID_LASTP1 (V4L2_CID_BASE+45)
>>
>> /* USER-class private control IDs */
>>
>> --
>> 2.53.0
>>
Le mardi 31 mars 2026 à 10:33 -0400, Frank Li a écrit :
> On Tue, Mar 31, 2026 at 03:23:11PM +0800, ming.qian@oss.nxp.com wrote:
> > From: Ming Qian <ming.qian@oss.nxp.com>
> >
> > Add a new read-only control V4L2_CID_MEMORY_USAGE that allows
> > applications to query the total amount of memory currently used
> > by a device instance.
> >
> > This control reports the memory consumption in bytes, including
> > internal buffers, intermediate processing data, and other
> > driver-managed allocations. Applications can use this information
> > for debugging, resource monitoring, or making informed decisions
> > about buffer allocation strategies.
> >
> > Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
> > ---
>
> Not sure why not export these information by debugfs, or any benefit vs
> debugfs?
There is also a on-going proposal that uses fdinfo.
Nicolas
>
> Generanlly document should be first patch, then driver change.
>
> Frank
>
> > drivers/media/v4l2-core/v4l2-ctrls-defs.c | 8 ++++++++
> > include/uapi/linux/v4l2-controls.h | 4 +++-
> > 2 files changed, 11 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
> > index 551426c4cd01..053db78ff661 100644
> > --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
> > +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
> > @@ -831,6 +831,7 @@ const char *v4l2_ctrl_get_name(u32 id)
> > case V4L2_CID_ALPHA_COMPONENT: return "Alpha Component";
> > case V4L2_CID_COLORFX_CBCR: return "Color Effects, CbCr";
> > case V4L2_CID_COLORFX_RGB: return "Color Effects, RGB";
> > + case V4L2_CID_MEMORY_USAGE: return "Memory Usage";
> >
> > /*
> > * Codec controls
> > @@ -1476,6 +1477,13 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
> > *min = 0;
> > *max = 0xffff;
> > break;
> > + case V4L2_CID_MEMORY_USAGE:
> > + *type = V4L2_CTRL_TYPE_INTEGER64;
> > + *flags |= V4L2_CTRL_FLAG_READ_ONLY;
> > + *min = 0;
> > + *max = S64_MAX;
> > + *step = 1;
> > + break;
> > case V4L2_CID_FLASH_FAULT:
> > case V4L2_CID_JPEG_ACTIVE_MARKER:
> > case V4L2_CID_3A_LOCK:
> > diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
> > index 68dd0c4e47b2..02c6f960d38e 100644
> > --- a/include/uapi/linux/v4l2-controls.h
> > +++ b/include/uapi/linux/v4l2-controls.h
> > @@ -110,8 +110,10 @@ enum v4l2_colorfx {
> > #define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42)
> > #define V4L2_CID_COLORFX_RGB (V4L2_CID_BASE+43)
> >
> > +#define V4L2_CID_MEMORY_USAGE (V4L2_CID_BASE+44)
> > +
> > /* last CID + 1 */
> > -#define V4L2_CID_LASTP1 (V4L2_CID_BASE+44)
> > +#define V4L2_CID_LASTP1 (V4L2_CID_BASE+45)
> >
> > /* USER-class private control IDs */
> >
> > --
> > 2.53.0
> >
Hi Nicolas,
On 3/31/2026 10:54 PM, Nicolas Dufresne wrote:
> Le mardi 31 mars 2026 à 10:33 -0400, Frank Li a écrit :
>> On Tue, Mar 31, 2026 at 03:23:11PM +0800, ming.qian@oss.nxp.com wrote:
>>> From: Ming Qian <ming.qian@oss.nxp.com>
>>>
>>> Add a new read-only control V4L2_CID_MEMORY_USAGE that allows
>>> applications to query the total amount of memory currently used
>>> by a device instance.
>>>
>>> This control reports the memory consumption in bytes, including
>>> internal buffers, intermediate processing data, and other
>>> driver-managed allocations. Applications can use this information
>>> for debugging, resource monitoring, or making informed decisions
>>> about buffer allocation strategies.
>>>
>>> Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
>>> ---
>>
>> Not sure why not export these information by debugfs, or any benefit vs
>> debugfs?
>
> There is also a on-going proposal that uses fdinfo.
>
> Nicolas
>
Thanks for the reminder about the ongoing fdinfo proposal.
Just to confirm, you are referring to Detlev’s ongoing fdinfo proposal,
specifically this series:
https://lore.kernel.org/lkml/20260212162328.192217-1-detlev.casanova@collabora.com/
I will align my work with it and switch to using fdinfo.
Once the show_fdinfo support from that series is merged, I will prepare
the next revision of my patch accordingly.
Regards,
Ming
>>
>> Generanlly document should be first patch, then driver change.
>>
>> Frank
>>
>>> drivers/media/v4l2-core/v4l2-ctrls-defs.c | 8 ++++++++
>>> include/uapi/linux/v4l2-controls.h | 4 +++-
>>> 2 files changed, 11 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
>>> index 551426c4cd01..053db78ff661 100644
>>> --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
>>> +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
>>> @@ -831,6 +831,7 @@ const char *v4l2_ctrl_get_name(u32 id)
>>> case V4L2_CID_ALPHA_COMPONENT: return "Alpha Component";
>>> case V4L2_CID_COLORFX_CBCR: return "Color Effects, CbCr";
>>> case V4L2_CID_COLORFX_RGB: return "Color Effects, RGB";
>>> + case V4L2_CID_MEMORY_USAGE: return "Memory Usage";
>>>
>>> /*
>>> * Codec controls
>>> @@ -1476,6 +1477,13 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
>>> *min = 0;
>>> *max = 0xffff;
>>> break;
>>> + case V4L2_CID_MEMORY_USAGE:
>>> + *type = V4L2_CTRL_TYPE_INTEGER64;
>>> + *flags |= V4L2_CTRL_FLAG_READ_ONLY;
>>> + *min = 0;
>>> + *max = S64_MAX;
>>> + *step = 1;
>>> + break;
>>> case V4L2_CID_FLASH_FAULT:
>>> case V4L2_CID_JPEG_ACTIVE_MARKER:
>>> case V4L2_CID_3A_LOCK:
>>> diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
>>> index 68dd0c4e47b2..02c6f960d38e 100644
>>> --- a/include/uapi/linux/v4l2-controls.h
>>> +++ b/include/uapi/linux/v4l2-controls.h
>>> @@ -110,8 +110,10 @@ enum v4l2_colorfx {
>>> #define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42)
>>> #define V4L2_CID_COLORFX_RGB (V4L2_CID_BASE+43)
>>>
>>> +#define V4L2_CID_MEMORY_USAGE (V4L2_CID_BASE+44)
>>> +
>>> /* last CID + 1 */
>>> -#define V4L2_CID_LASTP1 (V4L2_CID_BASE+44)
>>> +#define V4L2_CID_LASTP1 (V4L2_CID_BASE+45)
>>>
>>> /* USER-class private control IDs */
>>>
>>> --
>>> 2.53.0
>>>
© 2016 - 2026 Red Hat, Inc.