Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp962902pxb; Thu, 4 Feb 2021 01:18:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlAn1qlvX4g6BV7U71ye3npK3iV7QiecO3YmoP3wuWEIu4gPl+gfBPTH9J+nKsAEF0vf5H X-Received: by 2002:a17:906:fca1:: with SMTP id qw1mr6662086ejb.130.1612430323884; Thu, 04 Feb 2021 01:18:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612430323; cv=none; d=google.com; s=arc-20160816; b=WsaLO6tEI/cOFgfL950/WYAGBLu95zPaaVdLBpFS66QVbpk3vZKXQ4eVX8nZHV6jJ4 hAHO4qNASwwHFxSCE8rT2GIbB8703qpoIFMzOxp5k27Oy6ZV8gxeHnGLmscBt+v36UPR bOwM047yh7/gomj2tgtycULZDwKgKtouPL3nmA53VOu8zag6sn0m4r5QhLpo6PzQOKs0 mGs6ZTEIh7M+iTywEJQZ1orfF5cYmqzg3FsdAWgd2vr87jp2I3RY+r/plCEDCQULN7It NRZlNxYIvk6jOSAJvQaWQB8ifOMuxiyIIPkaY7ikZ6ie5Hfl648KcV7uUg6JJPhM2gth 71hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=RTzUaR2l9Y+wonn/5AaTUIe22c6Cvk8bS3lsdUKi7C4=; b=adzVn0d5b7zqIjjoDWdz4weeuPy9BKlb2YsEA93M+efp5aKMSjUk1S2/Z11ScvTOv2 7y1Bu6+DbA/7FbpEbURRKk2KlP59624zYRA26Lezr9x112//59GOSPoZO9HwryjlMAqD P7t7M3x46XpBJoW+YWyUt2xsaExaJcXGrKtU9ITEP904xtE5ovQkCRX2fZD7zXCFmObd KlVk/khQzbfywpDD7EOIZ2dFfacxM8t6Y0/kfxnmkH4mPtz1V/4LzcyXPWYTscoyxB5o 6uOgC7QnAlbS0+U/g+irOlCfYU686QfUcIOpu3X/yoI74rJ7EON0DDD9LwOrfhxHWBTs ptNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=PlBUd4Py; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id di1si2846468edb.489.2021.02.04.01.18.18; Thu, 04 Feb 2021 01:18:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=PlBUd4Py; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235124AbhBDJPN (ORCPT + 99 others); Thu, 4 Feb 2021 04:15:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235178AbhBDJOk (ORCPT ); Thu, 4 Feb 2021 04:14:40 -0500 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4F01C0613ED for ; Thu, 4 Feb 2021 01:13:59 -0800 (PST) Received: by mail-oi1-x232.google.com with SMTP id m13so2999436oig.8 for ; Thu, 04 Feb 2021 01:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=RTzUaR2l9Y+wonn/5AaTUIe22c6Cvk8bS3lsdUKi7C4=; b=PlBUd4Py28pehHqU06+ihr1l7h0vSS4JISmS5j2ah1UZ+e8VoB9doYac74bcQDZl7B jYXUClMz2yJNHpgQL2WASwpxpv0GTKchb2om/0uCvplSJ3hklaRcTKDvfuqxPTTlmgMy eGRc6uggEdgrHWuaNQN61koxVhscZ/zAGFRnY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=RTzUaR2l9Y+wonn/5AaTUIe22c6Cvk8bS3lsdUKi7C4=; b=Mllsyc2CvO6Q0g1NcCfnrtaDNzXunNstVCibdnyIBUdALasR1F6/O2hiqN2cV9JszE +jJNn5dGeFpBNN0sPjZuC0ni1xfJVdRwkudGPP8BkQm91Cf7h1gtA2b50l30kBlOaNLY 2OJGoQ6tveGh+3dX7c30nsyLygzXmv23pupo+YYS4NZAWQSHcC2u9xDXKvvU6K0Zah1q xB3lQ9bagiUK8myj+cz3eV0aXolz7gq67R4oaqILg81FR+uRX5XZ40cTXNYpPV6GyNZY Io+yLexolWmT9ZBnodjdIXBnwDtYiVT5ZzLAda9HtQqPJE/EIo4timYb2l8UYoI0wsL7 2qjg== X-Gm-Message-State: AOAM531iriLJK6rdKi9YUaUpifPA2Ldsxr7tvzG2nWj5u2TX4T/KBc61 3c5Q/2fe5dRwWHSwEnUHdcbztaMi49s/5j6WPQQrpB8tu+/rKw== X-Received: by 2002:aca:1906:: with SMTP id l6mr4613717oii.101.1612430038909; Thu, 04 Feb 2021 01:13:58 -0800 (PST) MIME-Version: 1.0 References: <20210126204240.418297-1-hridya@google.com> <3a5e5164-e6d5-c487-71d8-910f943aee1a@amd.com> In-Reply-To: <3a5e5164-e6d5-c487-71d8-910f943aee1a@amd.com> From: Daniel Vetter Date: Thu, 4 Feb 2021 10:13:47 +0100 Message-ID: Subject: Re: [Linaro-mm-sig] [PATCH v3] dmabuf: Add the capability to expose DMA-BUF stats in sysfs To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Hridya Valsaraju , Sumit Semwal , Android Kernel Team , kernel test robot , Greg KH , LKML , DRI mailing list , Linaro MM SIG , Hyesoo Yu , Suren Baghdasaryan , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 4, 2021 at 9:13 AM Christian K=C3=B6nig wrote: > > Am 03.02.21 um 21:14 schrieb Hridya Valsaraju: > > On Wed, Feb 3, 2021 at 2:25 AM Daniel Vetter wrote: > >> On Mon, Feb 01, 2021 at 01:02:30PM -0800, Hridya Valsaraju wrote: > >>> On Mon, Feb 1, 2021 at 10:37 AM Daniel Vetter wrote= : > >>>> On Thu, Jan 28, 2021 at 1:03 PM Sumit Semwal wrote: > >>>>> On Thu, 28 Jan 2021 at 17:23, Christian K=C3=B6nig > >>>>> wrote: > >>>>>> Am 28.01.21 um 12:00 schrieb Sumit Semwal: > >>>>>>> Hi Hridya, > >>>>>>> > >>>>>>> On Wed, 27 Jan 2021 at 17:36, Greg KH wrote: > >>>>>>>> On Tue, Jan 26, 2021 at 12:42:36PM -0800, Hridya Valsaraju wrote= : > >>>>>>>>> This patch allows statistics to be enabled for each DMA-BUF in > >>>>>>>>> sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS. > >>>>>>>>> > >>>>>>>>> The following stats will be exposed by the interface: > >>>>>>>>> > >>>>>>>>> /sys/kernel/dmabuf/buffers//exporter_name > >>>>>>>>> /sys/kernel/dmabuf/buffers//size > >>>>>>>>> /sys/kernel/dmabuf/buffers//attachments//device > >>>>>>>>> /sys/kernel/dmabuf/buffers//attachments//map_counter > >>>>>>>>> > >>>>>>>>> The inode_number is unique for each DMA-BUF and was added earli= er [1] > >>>>>>>>> in order to allow userspace to track DMA-BUF usage across diffe= rent > >>>>>>>>> processes. > >>>>>>>>> > >>>>>>>>> Currently, this information is exposed in > >>>>>>>>> /sys/kernel/debug/dma_buf/bufinfo. > >>>>>>>>> However, since debugfs is considered unsafe to be mounted in pr= oduction, > >>>>>>>>> it is being duplicated in sysfs. > >>>>>>>>> > >>>>>>>>> This information will be used to derive DMA-BUF > >>>>>>>>> per-exporter stats and per-device usage stats for Android Bug r= eports. > >>>>>>>>> The corresponding userspace changes can be found at [2]. > >>>>>>>>> Telemetry tools will also capture this information(along with o= ther > >>>>>>>>> memory metrics) periodically as well as on important events lik= e a > >>>>>>>>> foreground app kill (which might have been triggered by Low Mem= ory > >>>>>>>>> Killer). It will also contribute to provide a snapshot of the s= ystem > >>>>>>>>> memory usage on other events such as OOM kills and Application = Not > >>>>>>>>> Responding events. > >>>>>>>>> > >>>>>>>>> A shell script that can be run on a classic Linux environment t= o read > >>>>>>>>> out the DMA-BUF statistics can be found at [3](suggested by Joh= n > >>>>>>>>> Stultz). > >>>>>>>>> > >>>>>>>>> The patch contains the following improvements over the previous= version: > >>>>>>>>> 1) Each attachment is represented by its own directory to allow= creating > >>>>>>>>> a symlink to the importing device and to also provide room for = future > >>>>>>>>> expansion. > >>>>>>>>> 2) The number of distinct mappings of each attachment is expose= d in a > >>>>>>>>> separate file. > >>>>>>>>> 3) The per-buffer statistics are now in /sys/kernel/dmabuf/buff= ers > >>>>>>>>> inorder to make the interface expandable in future. > >>>>>>>>> > >>>>>>>>> All of the improvements above are based on suggestions/feedback= from > >>>>>>>>> Daniel Vetter and Christian K=C3=B6nig. > >>>>>>>>> > >>>>>>>>> [1]: https://nam11.safelinks.protection.outlook.com/?url=3Dhttp= s%3A%2F%2Flore.kernel.org%2Fpatchwork%2Fpatch%2F1088791%2F&data=3D04%7C= 01%7Cchristian.koenig%40amd.com%7C32ff828b838e44b1de6f08d8c8805913%7C3dd896= 1fe4884e608e11a82d994e183d%7C0%7C0%7C637479800886768855%7CUnknown%7CTWFpbGZ= sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1= 000&sdata=3DimVoJbadV221%2F6u32diSyEICLk7WUNakz8G742RPSaA%3D&reserv= ed=3D0 > >>>>>>>>> [2]: https://nam11.safelinks.protection.outlook.com/?url=3Dhttp= s%3A%2F%2Fandroid-review.googlesource.com%2Fq%2Ftopic%3A%2522dmabuf-sysfs%2= 522&data=3D04%7C01%7Cchristian.koenig%40amd.com%7C32ff828b838e44b1de6f0= 8d8c8805913%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637479800886778838= %7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haW= wiLCJXVCI6Mn0%3D%7C1000&sdata=3DX78MH6IvdcE1mGMngrVdBYooi93vpjvfLU9kQHj= ZyKo%3D&reserved=3D0+(status:open%20OR%20status:merged) > >>>>>>>>> [3]: https://nam11.safelinks.protection.outlook.com/?url=3Dhttp= s%3A%2F%2Fandroid-review.googlesource.com%2Fc%2Fplatform%2Fsystem%2Fmemory%= 2Flibmeminfo%2F%2B%2F1549734&data=3D04%7C01%7Cchristian.koenig%40amd.co= m%7C32ff828b838e44b1de6f08d8c8805913%7C3dd8961fe4884e608e11a82d994e183d%7C0= %7C0%7C637479800886778838%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQI= joiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=3DJH7m5yspXKDqVX= 5DB380cnU4kWNSyh6ctDaphJvOyw8%3D&reserved=3D0 > >>>>>>>>> > >>>>>>>>> Signed-off-by: Hridya Valsaraju > >>>>>>>>> Reported-by: kernel test robot > >>>>>>> Thanks for the patch! > >>>>>>> > >>>>>>> Christian: If you're satisfied with the explanation around not > >>>>>>> directly embedding kobjects into the dma_buf and dma_buf_attachme= nt > >>>>>>> structs, then with Greg's r-b from sysfs PoV, I think we can merg= e it. > >>>>>>> Please let me know if you feel otherwise! > >>>>>> From the technical side it looks clean to me, feel free to add m= y > >>>>>> acked-by while pushing. > >>>>>> > >>>>>> But I would at least try to convince Daniel on the design. At leas= t some > >>>>>> of his concerns seems to be valid and keep in mind that we need to > >>>>>> support this interface forever. > >>>>> Naturally. > >>>>> > >>>>> Since he didn't comment over Hridya's last clarification about the > >>>>> tracepoints to track total GPU memory allocations being orthogonal = to > >>>>> this series, I assumed he agreed with it. > >>>> The tracepoint being orthogonal didn't really look convincing to me, > >>>> since I do expect we'll need that at a much more generic level, at > >>>> allocators. Whether that's dma-buf heaps or in drm or wherever. And = we > >>>> probably also need that to somehow align with cgroups accounting. > >>>> > >>>> But I guess for this it should be easy to extend however we see fit, > >>>> so retrofitting allocator sources and anything else we want/need for > >>>> the overall gpu memory account shouldn't be a problem. Also, it's > >>>> first, so the proof for showing it all works together is more on the > >>>> tracepoints :-) > >>>> > >>>>> Daniel, do you still have objections around adding this patch in? > >>>> Needs docs (especially the uapi I think would be useful to document)= , > >>>> igt tests, that kind of stuff still I think? It's meant to be generi= c > >>>> uapi across drivers, generally we're a pile stricter for that (and y= es > >>>> dma-buf heaps I think didn't do all that, so maybe there's an argume= nt > >>>> for doing this a bit more sloppy or at least "the testsuite is > >>>> somewhere else"). > >>> Thank you for taking another look Daniel! > >>> > >>> I will try adding an IGT test for the sysfs files. Other than the > >>> documentation in > >>> Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers(included in the > >>> patch), is there another place you would like to see the documentatio= n > >>> copied to? > >> So just read the other thread, and sounds like Christian K=C3=B6nig br= ought up > >> a solid concern with dma-buf fds generally not staying around for much= . > > Thank you for the reply Daniel! Could you please elaborate on the > > connection with the other thread you mentioned? I am a little confused > > since this patch does not deal with tracking DMA-BUF fds. > > In general DMA-buf fd are meant to be a temporary transport vehicle to > interchange the data between processes. > > This here sounds like Android is using them as a long term reference. > That is not necessary a good idea and causes multiple issues. > > On of those issues you try to address here, but Daniel is question now > why do you have this problem in the first place? Afaik it's how Android works, lots more fd passing than we do (that's also why Android has sync_file, i.e. pass a sync fd around every frame, whereas we have drm_syncobj, i.e. pass the sync container object fd once around at startup and be done). I more meant that now I'm leaning more towards "we really need a unified *pu buffer reporting scheme" before signing up to something that only works for very limited use cases. The other thing that popped up is that between this patch, the virtio tracepoint there's now a 3rd patch from google Android to account xpu buffer memory in some cases (but only some, only partially). So really this gap-fillers here don't work, and we need something that really looks at the entire problem and figures out how to account that memory. Which is probably cgroups, but we'll see. I asked John to set up some meeting at least with the Android side so we can start to figure this out for real. -Daniel > > Regards, > Christian. > > > > > Regards, > > Hridya > > > >> So I'm leaning more towards "this sounds like it's going to be useful = for > >> Android only, nothing else" concern. > >> -Daniel > >> > --=20 Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch