From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: "Adrián Larumbe" <adrian.larumbe@collabora.com>
Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@gmail.com, daniel@ffwll.ch,
robdclark@gmail.com, quic_abhinavk@quicinc.com,
dmitry.baryshkov@linaro.org, sean@poorly.run,
marijn.suijten@somainline.org, robh@kernel.org,
steven.price@arm.com, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
healych@amazon.com,
Boris Brezillon <boris.brezillon@collabora.com>,
kernel@collabora.com, freedreno@lists.freedesktop.org
Subject: Re: [PATCH v6 4/6] drm/drm_file: Add DRM obj's RSS reporting function for fdinfo
Date: Wed, 27 Sep 2023 15:36:55 +0100 [thread overview]
Message-ID: <eeff4966-8a93-c2c9-5ec3-5b1f71cd1ad9@linux.intel.com> (raw)
In-Reply-To: <fs3u3b62vhixqpuoa5c4dwckew3l4etvps4zhlgeuwle6o2as2@tsgwsil4s35k>
On 22/09/2023 11:58, Adrián Larumbe wrote:
> On 20.09.2023 16:53, Tvrtko Ursulin wrote:
>>
>> On 20/09/2023 00:34, Adrián Larumbe wrote:
>>> Some BO's might be mapped onto physical memory chunkwise and on demand,
>>> like Panfrost's tiler heap. In this case, even though the
>>> drm_gem_shmem_object page array might already be allocated, only a very
>>> small fraction of the BO is currently backed by system memory, but
>>> drm_show_memory_stats will then proceed to add its entire virtual size to
>>> the file's total resident size regardless.
>>>
>>> This led to very unrealistic RSS sizes being reckoned for Panfrost, where
>>> said tiler heap buffer is initially allocated with a virtual size of 128
>>> MiB, but only a small part of it will eventually be backed by system memory
>>> after successive GPU page faults.
>>>
>>> Provide a new DRM object generic function that would allow drivers to
>>> return a more accurate RSS size for their BOs.
>>>
>>> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
>>> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
>>> Reviewed-by: Steven Price <steven.price@arm.com>
>>> ---
>>> drivers/gpu/drm/drm_file.c | 5 ++++-
>>> include/drm/drm_gem.h | 9 +++++++++
>>> 2 files changed, 13 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
>>> index 883d83bc0e3d..762965e3d503 100644
>>> --- a/drivers/gpu/drm/drm_file.c
>>> +++ b/drivers/gpu/drm/drm_file.c
>>> @@ -944,7 +944,10 @@ void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file)
>>> }
>>> if (s & DRM_GEM_OBJECT_RESIDENT) {
>>> - status.resident += obj->size;
>>> + if (obj->funcs && obj->funcs->rss)
>>> + status.resident += obj->funcs->rss(obj);
>>> + else
>>> + status.resident += obj->size;
>>
>> Presumably you'd want the same smaller size in both active and purgeable? Or
>> you can end up with more in those two than in rss which would look odd.
>
> I didn't think of this. I guess when an object is both resident and purgeable,
> then its RSS and purgeable sizes should be the same.
>
>> Also, alternative to adding a new callback could be adding multiple output
>> parameters to the existing obj->func->status() which maybe ends up simpler due
>> fewer callbacks?
>>
>> Like:
>>
>> s = obj->funcs->status(obj, &supported_status, &rss)
>>
>> And adjust the code flow to pick up the rss if driver signaled it supports
>> reporting it.
>
> I personally find having a separate object callback more readable in this case.
> There's also the question of what output parameter value would be used as a token
> that the relevant BO doesn't have an RSS different from its virtual
> size. I guess '0' would be alright, but this is on the assumption that this
> could never be a legitimate BO virtual size across all DRM drivers. I guess
> most of them round the size up to the nearest page multiple at BO creation
> time.
Okay. See how it will look once you need to apply it to resident and
purgeable. I wonder if "driver knows better" will end up a dominant case
and we do end up considering reversing the scheme (like ask the driver
to fill in the meminfo record). TBH I do not remember all the flavours
both Rob and I proposed at this point.
Regards,
Tvrtko
>
>>
>> Regards,
>>
>> Tvrtko
>>
>>> } else {
>>> /* If already purged or not yet backed by pages, don't
>>> * count it as purgeable:
>>> diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
>>> index bc9f6aa2f3fe..16364487fde9 100644
>>> --- a/include/drm/drm_gem.h
>>> +++ b/include/drm/drm_gem.h
>>> @@ -208,6 +208,15 @@ struct drm_gem_object_funcs {
>>> */
>>> enum drm_gem_object_status (*status)(struct drm_gem_object *obj);
>>> + /**
>>> + * @rss:
>>> + *
>>> + * Return resident size of the object in physical memory.
>>> + *
>>> + * Called by drm_show_memory_stats().
>>> + */
>>> + size_t (*rss)(struct drm_gem_object *obj);
>>> +
>>> /**
>>> * @vm_ops:
>>> *
next prev parent reply other threads:[~2023-09-27 14:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-19 23:34 [PATCH v6 0/6] Add fdinfo support to Panfrost Adrián Larumbe
2023-09-19 23:34 ` [PATCH v6 1/6] drm/panfrost: Add cycle count GPU register definitions Adrián Larumbe
2023-09-19 23:34 ` [PATCH v6 2/6] drm/panfrost: Add fdinfo support GPU load metrics Adrián Larumbe
2023-09-20 15:40 ` Tvrtko Ursulin
2023-09-22 10:57 ` Adrián Larumbe
2023-09-22 13:53 ` Tvrtko Ursulin
2023-09-22 15:23 ` Steven Price
2023-09-25 8:57 ` Tvrtko Ursulin
2023-09-19 23:34 ` [PATCH v6 3/6] drm/panfrost: Add fdinfo support for memory stats Adrián Larumbe
2023-09-19 23:34 ` [PATCH v6 4/6] drm/drm_file: Add DRM obj's RSS reporting function for fdinfo Adrián Larumbe
2023-09-20 15:53 ` Tvrtko Ursulin
2023-09-22 10:58 ` Adrián Larumbe
2023-09-27 14:36 ` Tvrtko Ursulin [this message]
2023-09-19 23:34 ` [PATCH v6 5/6] drm/panfrost: Implement generic DRM object RSS reporting function Adrián Larumbe
2023-09-19 23:34 ` [PATCH v6 6/6] drm/drm-file: Show finer-grained BO sizes in drm_show_memory_stats Adrián Larumbe
2023-09-20 15:32 ` Tvrtko Ursulin
2023-09-21 10:14 ` Tvrtko Ursulin
2023-09-22 11:03 ` Adrián Larumbe
2023-09-22 14:02 ` Tvrtko Ursulin
2023-09-22 11:01 ` Adrián Larumbe
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=eeff4966-8a93-c2c9-5ec3-5b1f71cd1ad9@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=adrian.larumbe@collabora.com \
--cc=airlied@gmail.com \
--cc=boris.brezillon@collabora.com \
--cc=daniel@ffwll.ch \
--cc=dmitry.baryshkov@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=healych@amazon.com \
--cc=kernel@collabora.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=marijn.suijten@somainline.org \
--cc=mripard@kernel.org \
--cc=quic_abhinavk@quicinc.com \
--cc=robdclark@gmail.com \
--cc=robh@kernel.org \
--cc=sean@poorly.run \
--cc=steven.price@arm.com \
--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