From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Lucas Stach <l.stach@pengutronix.de>,
linux-mm@kvack.org, dri-devel@lists.freedesktop.org
Cc: Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@linux.ie>,
Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@suse.com>,
linux-fsdevel@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [RFC PATCH 0/5] GEM buffer memory tracking
Date: Fri, 9 Sep 2022 13:32:57 +0200 [thread overview]
Message-ID: <068ab330-dbf7-8aa8-8bed-156ca01be48b@gmail.com> (raw)
In-Reply-To: <20220909111640.3789791-1-l.stach@pengutronix.de>
Am 09.09.22 um 13:16 schrieb Lucas Stach:
> Hi MM and DRM people,
>
> during the discussions about per-file OOM badness [1] it repeatedly came up
> that it should be possible to simply track the DRM GEM memory usage by some
> new MM counters.
>
> The basic problem statement is as follows: in the DRM subsystem drivers can
> allocate buffer aka. GEM objects on behalf of a userspace process. In many
> cases those buffers behave just like anonymous memory, but they may be used
> only by the devices driven by the DRM drivers. As the buffers can be quite
> large (multi-MB is the norm, rather than the exception) userspace will not
> map/fault them into the process address space when it doesn't need access to
> the content of the buffers. Thus the memory used by those buffers is not
> accounted to any process and evades visibility by the usual userspace tools
> and the OOM handling.
>
> This series tries to remedy this situation by making such memory visible
> by accounting it exclusively to the process that created the GEM object.
> For now it only hooks up the tracking to the CMA helpers and the etnaviv
> drivers, which was enough for me to prove the concept and see it actually
> working, other drivers could follow if the proposal sounds sane.
>
> Known shortcomings of this very simplistic implementation:
>
> 1. GEM objects can be shared between processes by exporting/importing them
> as dma-bufs. When they are shared between multiple processes, killing the
> process that got the memory accounted will not actually free the memory, as
> the object is kept alive by the sharing process.
>
> 2. It currently only accounts the full size of them GEM object, more advanced
> devices/drivers may only sparsely populate the backing storage of the object
> as needed. This could be solved by having more granular accounting.
>
> I would like to invite everyone to poke holes into this proposal to see if
> this might get us on the right trajectory to finally track GEM memory usage
> or if it (again) falls short and doesn't satisfy the requirements we have
> for graphics memory tracking.
Good to see other looking into this problem as well since I didn't had
time for it recently.
I've tried this approach as well, but was quickly shot down by the
forking behavior of the core kernel.
The problem is that the MM counters get copied over to child processes
and because of that become imbalanced when this child process now
terminates.
What you could do is to change the forking behavior for MM_DRIVERPAGES
so that it always stays with the process which has initially allocated
the memory and never leaks to children.
Apart from that I suggest to rename it since the shmemfd and a few other
implementations have pretty much the same problem.
Regards,
Christian.
>
> Regards,
> Lucas
>
> [1] https://lore.kernel.org/linux-mm/20220531100007.174649-1-christian.koenig@amd.com/
>
> Lucas Stach (5):
> mm: add MM_DRIVERPAGES
> drm/gem: track mm struct of allocating process in gem object
> drm/gem: add functions to account GEM object memory usage
> drm/cma-helper: account memory used by CMA GEM objects
> drm/etnaviv: account memory used by GEM buffers
>
> drivers/gpu/drm/drm_gem.c | 42 +++++++++++++++++++++++++++
> drivers/gpu/drm/drm_gem_cma_helper.c | 4 +++
> drivers/gpu/drm/etnaviv/etnaviv_gem.c | 3 ++
> fs/proc/task_mmu.c | 6 ++--
> include/drm/drm_gem.h | 15 ++++++++++
> include/linux/mm.h | 3 +-
> include/linux/mm_types_task.h | 1 +
> kernel/fork.c | 1 +
> 8 files changed, 72 insertions(+), 3 deletions(-)
>
prev parent reply other threads:[~2022-09-09 11:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-09 11:16 Lucas Stach
2022-09-09 11:16 ` [RFC PATCH 1/5] mm: add MM_DRIVERPAGES Lucas Stach
2022-09-09 11:16 ` [RFC PATCH 2/5] drm/gem: track mm struct of allocating process in gem object Lucas Stach
2022-09-09 11:16 ` [RFC PATCH 3/5] drm/gem: add functions to account GEM object memory usage Lucas Stach
2022-09-09 11:16 ` [RFC PATCH 4/5] drm/cma-helper: account memory used by CMA GEM objects Lucas Stach
2022-09-09 11:16 ` [RFC PATCH 5/5] drm/etnaviv: account memory used by GEM buffers Lucas Stach
2022-09-09 11:32 ` Christian König [this message]
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=068ab330-dbf7-8aa8-8bed-156ca01be48b@gmail.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=airlied@linux.ie \
--cc=akpm@linux-foundation.org \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel@pengutronix.de \
--cc=l.stach@pengutronix.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
/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