Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp283601pxu; Fri, 11 Dec 2020 02:12:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNB9BceptVbFxcRJO3S8rDU9T0RpEShFQ+vwWmpnzCQLHQ9naTl8xHAbsbuIsS2qqHb5Bz X-Received: by 2002:a17:906:5c43:: with SMTP id c3mr10455698ejr.390.1607681551929; Fri, 11 Dec 2020 02:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607681551; cv=none; d=google.com; s=arc-20160816; b=nMXRTEWbQZxc+UHpw7qAPIyUUYF61thyxx26ASvRm8w3gR/pieNPrlqQ6ftw8UpRCN /3nzIsKAjx1PLTzrgaxS+1m6aP2fa5Hvpy5vmZOIJXl0ewETD0L7L0kGIL6PLh3wcEmd evpkH4HHj7j9wkLG/HUgnluDlhxKS27XdhlVgIvevTb3GHlGVg/UY0G4JRZWC//kbccE ND22tY94Cogr8M3sxoe2hCd25cpzs9kcL4ObRNdzZ/iHHPeDi1us6PGG4cYW21Uf1kVZ 38JR9JwYRJH5h44ZoAu5vo4ek7PNGS8K5YNfmVwCM5/UPNKnMpJvURJ8ZCKnWbMxul3R q93A== 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=BI42y0NL4g9pgxSiCUPEnrdmXwNVwllMLibIxfqxMAE=; b=ZWokw81eLlS49sxeVYFfaA1tOSCncqg6ojGESLw86vEGpbwkH8fdkgJzjw13OPQUxK JIPW9oV/TNeF/geKPOLdmypER+gdvpi0C5zntwMaZfD0Q2xznDOifdEtsa93CR3Lp6Vv /x8mgKdRLWBqvgY9Y3zKVrUQVzliTcSNKZkNC3R+8fNSEKCq8AJxeLMzpMc7Q9vaZvdC T4a0GrnfWoAdvnGDeVssjIciKipO2YUTDJqJdWzHkhMMuZK06UWcs3SbgzsflphYKKZG aIWn8giZsz7YZuMF6P5T1MNPBKPGJ1/4y+8G15Gi7s52LRMU6NGrLfrD08BNhGlEhUCt xL8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hWMsNOC7; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt17si591024ejb.333.2020.12.11.02.12.07; Fri, 11 Dec 2020 02:12:31 -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=@google.com header.s=20161025 header.b=hWMsNOC7; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391524AbgLJW6y (ORCPT + 99 others); Thu, 10 Dec 2020 17:58:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728309AbgLJWzN (ORCPT ); Thu, 10 Dec 2020 17:55:13 -0500 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2463C0619D8 for ; Thu, 10 Dec 2020 14:42:33 -0800 (PST) Received: by mail-qk1-x742.google.com with SMTP id z188so6676770qke.9 for ; Thu, 10 Dec 2020 14:42:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=BI42y0NL4g9pgxSiCUPEnrdmXwNVwllMLibIxfqxMAE=; b=hWMsNOC78oPCR/5SbuVMdo29OQDG3LMI1Knmo1sKFCQLyigIG4vSOWQB5xY6tp8cU+ 77Z8uG/aPnl2cGAEAmpDq76vp2e71hOkDQQAkwfJgpJYru1alEkjWhfQ6bHjPtzIyCS9 b+Hs8TTIVwUxiv7jNe3RMNaOlKh2oyjH1g4P4BoUKdwVR7/UQI7veEed1ZexzU24kbw8 UpV5cQ2SJ0IRPENlPCcfFgCEUQi3mbkX/YJMbCNFTg4oMKCRK1Xd1S3xGkVeiFbfTIvc kq0UJFcKGNMB3ngzzV9qSQBRsz5C7c9UcOilExHurYt7II0zPp1kOdr07XcXXgaWio9z GU0A== 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=BI42y0NL4g9pgxSiCUPEnrdmXwNVwllMLibIxfqxMAE=; b=fH1dpbIQxQLKBIYSmMk1FyIfDOwTZYo2887wp8KF4YRaZggZSvk4gvb1RqlK3Bl13K FUM7BWHFXS9rGORuW2DunVNFZIXfT1QN72zlZv47VL11MSK8VJWTL2XYTcKT3p8QS39P plPrUx/LeMcylbJzkeLa+aw1VOzdFqU4iah3+8xVRi1EXgxlLgjBBQRHMvgyXbwk3xZF ahMCEdtpsdQ2bMyuNu4x1VIcSUXc0bqpR7LjGIhucsspfQzm8IPHaqKJUgGQ0g6Dc+BU UA4hp/UV2NQL5fizMFH+OUbO7xBSLZK3nsVOQ3bJ658ZCO3XxIk5azFMXr4wko9I04Z8 VnCA== X-Gm-Message-State: AOAM532ZRg4kxCEaD9AKqGD/KTmywbW14Wzix0KGhEFsUCN3/419bRLq xfGrGFEdviQGJ3BmgJA3l93h6lSwWK9UdiLS9/41IQ== X-Received: by 2002:a37:a80a:: with SMTP id r10mr11644017qke.467.1607640152596; Thu, 10 Dec 2020 14:42:32 -0800 (PST) MIME-Version: 1.0 References: <20201210044400.1080308-1-hridya@google.com> <20201210102727.GE401619@phenom.ffwll.local> In-Reply-To: From: Hridya Valsaraju Date: Thu, 10 Dec 2020 14:41:56 -0800 Message-ID: Subject: Re: [PATCH] dmabuf: Add the capability to expose DMA-BUF stats in sysfs To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Greg KH , Suren Baghdasaryan , LKML , dri-devel , linaro-mm-sig@lists.linaro.org, Android Kernel Team , linux-media@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks again for the reviews! On Thu, Dec 10, 2020 at 3:03 AM Christian K=C3=B6nig wrote: > > Am 10.12.20 um 11:56 schrieb Greg KH: > > On Thu, Dec 10, 2020 at 11:27:27AM +0100, Daniel Vetter wrote: > >> On Thu, Dec 10, 2020 at 11:10:45AM +0100, Greg KH wrote: > >>> On Thu, Dec 10, 2020 at 10:58:50AM +0100, Christian K=C3=B6nig wrote: > >>>> In general a good idea, but I have a few concern/comments here. > >>>> > >>>> Am 10.12.20 um 05:43 schrieb Hridya Valsaraju: > >>>>> 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//exporter_name > >>>>> /sys/kernel/dmabuf//size > >>>>> /sys/kernel/dmabuf//dev_map_info > >>>>> > >>>>> The inode_number is unique for each DMA-BUF and was added earlier [= 1] > >>>>> in order to allow userspace to track DMA-BUF usage across different > >>>>> processes. > >>>>> > >>>>> Currently, this information is exposed in > >>>>> /sys/kernel/debug/dma_buf/bufinfo. > >>>>> However, since debugfs is considered unsafe to be mounted in produc= tion, > >>>>> it is being duplicated in sysfs. > >>>> Mhm, this makes it part of the UAPI. What is the justification for t= his? > >>>> > >>>> In other words do we really need those debug information in a produc= tion > >>>> environment? > >>> Production environments seem to want to know who is using up memory := ) > >> This only shows shared memory, so it does smell a lot like $specific_i= ssue > >> and we're designing a narrow solution for that and then have to carry = it > >> forever. > > I think the "issue" is that this was a feature from ion that people > > "missed" in the dmabuf move. Taking away the ability to see what kind > > of allocations were being made didn't make a lot of debugging tools > > happy :( > > Yeah, that is certainly a very valid concern. > > > But Hridya knows more, she's been dealing with the transition for a lon= g > > time now. Currently, telemetry tools capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by an LMK). We would also like to get a snapshot of the system memory usage on other events such as OOM kills and ANRs. > > > >> E.g. why is the list of attachments not a sysfs link? That's how we > >> usually expose struct device * pointers in sysfs to userspace, not as = a > >> list of things. > > These aren't struct devices, so I don't understand the objection here. > > Where else could these go in sysfs? > > Sure they are! Just take a look at an attachment: > > struct dma_buf_attachment { > struct dma_buf *dmabuf; > struct device *dev; > > This is the struct device which is importing the buffer and the patch in > discussion is just printing the name of this device into sysfs. I actually did not know that this is not ok to do. I will change it in the next version of the patch to be sysfs links instead. > > >> Furthermore we don't have the exporter device covered anywhere, how is > >> that tracked? Yes Android just uses ion for all shared buffers, but th= at's > >> not how all of linux userspace works. > > Do we have the exporter device link in the dmabuf interface? If so, > > great, let's use that, but for some reason I didn't think it was there. > > Correct, since we don't really need a device as an exporter (it can just > be a system heap as well) we only have a const char* as name for the > exporter. Yes, the file exporter_name prints out this information. > > >> Then I guess there's the mmaps, you can fish them out of procfs. A too= l > >> which collects all that information might be useful, just as demonstra= tion > >> of how this is all supposed to be used. > > There's a script somewhere that does this today, again, Hridya knows > > more. That is correct, we do have a tool in AOSP that gathers the per-process DMA-BUF map stats from procfs. https://android.googlesource.com/platform/system/memory/libmeminfo/+/refs/h= eads/master/libdmabufinfo/tools/dmabuf_dump.cpp When I send the next revision of the patch, I will also include links to AOSP CLs that show the usage for the sysfs files. > > > >> There's also some things to make sure we're at least having thought ab= out > >> how other things fit in here. E.d. dma_resv attached to the dma-buf > >> matters in general a lot. It doesn't matter on Android because > >> everything's pinned all the time anyway. I see your point Daniel! I will make the interface extendable in the next version of the patch. > >> > >> Also I thought sysfs was one value one file, dumping an entire list in= to > >> dev_info_map with properties we'll need to extend (once you care about > >> dma_resv you also want to know which attachments are dynamic) does not > >> smell like sysfs design at all. > > sysfs is one value per file, what is being exported that is larger than > > that here? Did I miss something on review? > > See this chunk here: > > + > + list_for_each_entry(attachment, &dmabuf->attachments, node) { > + if (attachment->map_counter) { > + ret +=3D sysfs_emit_at(buf, ret, "%s ", > + dev_name(attachment->dev)); > + } > + } > > And yes now that Daniel mentioned that it looks like a sysfs rules > violation to me as well. Sysfs rules do seem to allow an array of similar values in one file https://elixir.bootlin.com/linux/v5.10-rc7/source/Documentation/filesystems= /sysfs.rst#L63 However, I agree that we should change it so that it can be expanded easily in the future. I will fix it in the next version. Thank you all for pointing it out! Regards, Hridya > > Regards, > Christian. > > > > > > thanks, > > > > greg k-h >