linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"T.J. Mercier" <tjmercier@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>,
	Kalesh Singh <kaleshsingh@google.com>,
	Minchan Kim <minchan@google.com>,
	Greg Kroah-Hartman <gregkh@google.com>,
	John Stultz <jstultz@google.com>,
	Sumit Semwal <sumit.semwal@linaro.org>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Hridya Valsaraju <hridya@google.com>,
	kernel-team@android.com, linux-media@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] dma-buf: Move sysfs work out of DMA-BUF export path
Date: Tue, 17 May 2022 08:59:44 +0200	[thread overview]
Message-ID: <d820893c-fa2e-3bac-88be-f39c06d89c01@amd.com> (raw)
In-Reply-To: <YoM9BAwybcjG7K/H@kroah.com>

Am 17.05.22 um 08:13 schrieb Greg Kroah-Hartman:
> On Mon, May 16, 2022 at 05:08:05PM -0700, T.J. Mercier wrote:
>> [SNIP]
>>>>>> Fixes: bdb8d06dfefd ("dmabuf: Add the capability to expose DMA-BUF stats in sysfs")
>>>>>> Originally-by: Hridya Valsaraju <hridya@google.com>
>>>>>> Signed-off-by: T.J. Mercier <tjmercier@google.com>
>>>>>>
>>>>>> ---
>>>>>> See the originally submitted patch by Hridya Valsaraju here:
>>>>>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml.org%2Flkml%2F2022%2F1%2F4%2F1066&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7C61d7d3acbe5f47c7d0e608da37cc5ed7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637883648212878440%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=HdSHA2vbBkBgdKxPXIp57EHW49yoMjgmigkVOKeTasI%3D&amp;reserved=0
>>>>>>
>>>>>> v2 changes:
>>>>>> - Defer only sysfs creation instead of creation and teardown per
>>>>>> Christian König
>>>>>>
>>>>>> - Use a work queue instead of a kthread for deferred work per
>>>>>> Christian König
>>>>>> ---
>>>>>>     drivers/dma-buf/dma-buf-sysfs-stats.c | 56 ++++++++++++++++++++-------
>>>>>>     include/linux/dma-buf.h               | 14 ++++++-
>>>>>>     2 files changed, 54 insertions(+), 16 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/dma-buf/dma-buf-sysfs-stats.c b/drivers/dma-buf/dma-buf-sysfs-stats.c
>>>>>> index 2bba0babcb62..67b0a298291c 100644
>>>>>> --- a/drivers/dma-buf/dma-buf-sysfs-stats.c
>>>>>> +++ b/drivers/dma-buf/dma-buf-sysfs-stats.c
>>>>>> @@ -11,6 +11,7 @@
>>>>>>     #include <linux/printk.h>
>>>>>>     #include <linux/slab.h>
>>>>>>     #include <linux/sysfs.h>
>>>>>> +#include <linux/workqueue.h>
>>>>>>
>>>>>>     #include "dma-buf-sysfs-stats.h"
>>>>>>
>>>>>> @@ -168,10 +169,46 @@ void dma_buf_uninit_sysfs_statistics(void)
>>>>>>         kset_unregister(dma_buf_stats_kset);
>>>>>>     }
>>>>>>
>>>>>> +static void sysfs_add_workfn(struct work_struct *work)
>>>>>> +{
>>>>>> +     struct dma_buf_sysfs_entry *sysfs_entry =
>>>>>> +             container_of(work, struct dma_buf_sysfs_entry, sysfs_add_work);
>>>>>> +     struct dma_buf *dmabuf = sysfs_entry->dmabuf;
>>>>>> +
>>>>>> +     /*
>>>>>> +      * A dmabuf is ref-counted via its file member. If this handler holds the only
>>>>>> +      * reference to the dmabuf, there is no need for sysfs kobject creation. This is an
>>>>>> +      * optimization and a race; when the reference count drops to 1 immediately after
>>>>>> +      * this check it is not harmful as the sysfs entry will still get cleaned up in
>>>>>> +      * dma_buf_stats_teardown, which won't get called until the final dmabuf reference
>>>>>> +      * is released, and that can't happen until the end of this function.
>>>>>> +      */
>>>>>> +     if (file_count(dmabuf->file) > 1) {
>>>>> Please completely drop that. I see absolutely no justification for this
>>>>> additional complexity.
>>>>>
>>>> This case gets hit around 5% of the time in my testing so the else is
>>>> not a completely unused branch.
>>> Well I can only repeat myself: This means that your userspace is
>>> severely broken!
>>>
>>> DMA-buf are meant to be long living objects
>> This patch addresses export *latency* regardless of how long-lived the
>> object is. Even a single, long-lived export will benefit from this
>> change if it would otherwise be blocked on adding an object to sysfs.
>> I think attempting to improve this latency still has merit.
> Fixing the latency is nice, but as it's just pushing the needed work off
> to another code path, it will take longer overall for the sysfs stuff to
> be ready for userspace to see.
>
> Perhaps we need to step back and understand what this code is supposed
> to be doing.  As I recall, it was created because some systems do not
> allow debugfs anymore, and they wanted the debugging information that
> the dmabuf code was exposing to debugfs on a "normal" system.  Moving
> that logic to sysfs made sense, but now I am wondering why we didn't see
> these issues in the debugfs code previously?

Well, I think that some key information is that adding the sysfs support 
was justified with the argument that this is not only used for debugging.

If it would be used only for debugging then debugfs would the right 
choice for this. If debugfs is then not available in your environment 
then you should *not* ask the kernel to work around that. Instead we 
should discuss why you want to disable some debugging access, but not 
all of that.

So for now let's assume that this is also used for accounting, e.g. when 
userspace wants to know how many DMA-bufs of which size are flying 
around to make decisions like which process to put into background or 
which to swap out based on that information.

> Perhaps we should go just one step further and make a misc device node
> for dmabug debugging information to be in and just have userspace
> poll/read on the device node and we spit the info that used to be in
> debugfs out through that?  That way this only affects systems when they
> want to read the information and not normal code paths?  Yeah that's a
> hack, but this whole thing feels overly complex now.

Yeah, totally agree on the complexity note. I'm just absolutely not keen 
to add hack over hack over hack to make something work which from my 
point of view has some serious issues with it's design.

For example trying to do accounting based on DMA-bufs is extremely 
questionable to begin with. See a modern game for example can have 
between 10k and 100k of different buffers, reserving one file descriptor 
for each of those objects is absolutely not going to work.

So my request is to please describe your full use case and not just why 
you think this patch is justified.

Regards,
Christian.

>
> thanks,
>
> greg k-h


  reply	other threads:[~2022-05-17  7:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 17:13 [PATCH v2] dma-buf: Move sysfs work out of DMA-BUF export path T.J. Mercier
2022-05-16 17:20 ` Christian König
2022-05-16 18:08   ` T.J. Mercier
2022-05-16 19:21     ` Christian König
2022-05-17  0:08       ` T.J. Mercier
2022-05-17  6:13         ` Greg Kroah-Hartman
2022-05-17  6:59           ` Christian König [this message]
2022-05-17 23:09             ` T.J. Mercier
2022-05-18 12:03               ` Christian König
2022-05-19 22:58                 ` T.J. Mercier
2022-05-20  7:03                   ` Christian König
2022-05-20 21:12                     ` T.J. Mercier
2022-05-17 23:09           ` T.J. Mercier
2022-05-18 12:06             ` Greg Kroah-Hartman
2022-05-25 14:38           ` Daniel Vetter
2022-05-25 21:05             ` T.J. Mercier
2022-05-25 21:39               ` T.J. Mercier
2022-05-30  6:12               ` Christian König
2022-05-31 23:31                 ` T.J. Mercier
2022-06-01 12:40                 ` Daniel Vetter
2022-06-15 17:43                   ` T.J. Mercier
2022-06-15 18:32                     ` Daniel Vetter
2022-06-17  6:11                       ` Christian König

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=d820893c-fa2e-3bac-88be-f39c06d89c01@amd.com \
    --to=christian.koenig@amd.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hridya@google.com \
    --cc=jstultz@google.com \
    --cc=kaleshsingh@google.com \
    --cc=kernel-team@android.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=minchan@google.com \
    --cc=sumit.semwal@linaro.org \
    --cc=surenb@google.com \
    --cc=tjmercier@google.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;
as well as URLs for NNTP newsgroup(s).