Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp4040260imc; Thu, 14 Mar 2019 10:50:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrOGVwmZmShQ9WGGdE6c3PlOGvjavx3c2pBi/TALMB/qCOkYQcDD9G21LQ3dE6rRKubu9H X-Received: by 2002:a63:4c0e:: with SMTP id z14mr16622377pga.123.1552585814067; Thu, 14 Mar 2019 10:50:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552585814; cv=none; d=google.com; s=arc-20160816; b=t8M8GrqRY06FtJe9FCjUKrk2FSURwSLu0g+MTJQvF39xCVXDdh4Nl1O9y090MAPxeY 2ms5YxDpqyKpglGmtSuacTXCoQDdy0PllsEYmkQkDhoe+ci3TZ7KiPW2OPnA1tVqVkHY kgShLvCkX1C1+icpe79v1PUxdTDKswyUhg1PjHT+qlfk0+plLdDadOECxpeClKlAZhhI 14Zf4QHFyKf01h2EUP+m7Q1XcxN0EClJC9GojMOyGpiYhLHZdH3AZa3W9hq7rHDiyaNE He1KCFSmM4WibDdAZ+qPQH1YPTuWNpMhch4OGx2/oWnJtfNAoqkHruqOrHE9bj4WsWS1 x0Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7QeesPBLVC4Xvhqsvje2fdOGstxWInZX/y0Xrblk/lI=; b=CRE6pM9MbBFOfQZWlUEADMKXXBGsrIfp2v+PPttyu8oPa90kEyr81xYW5uFmvApQnV pp1VbbHRpHnCMKGiStRQZ/lO61jIW4h7EN2uiK5yV6FrYV7yOPINOZ54pIwwclUeenVx wzEZ2derAxGoLw5FUZPhcB2307XkmURKnEY/EEse8W+eE9zUY7WB6eZTfOnLn5QeCWpx hF7AQeFyvc0JfAdDtFSabY7hAYjW7JPDq437uo5BTccW58HrC9dLS//VW91tgmrq4KxZ 39212JOnJy1SpozCNSzUvUZ7ehI7cq5qOahtx9Y7sxT8g7Xo8anti40LNwdfUfY4ZBnm CJ6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z4Filnma; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si12524061pgq.343.2019.03.14.10.49.58; Thu, 14 Mar 2019 10:50:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z4Filnma; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727649AbfCNRtW (ORCPT + 99 others); Thu, 14 Mar 2019 13:49:22 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:46858 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727544AbfCNRtT (ORCPT ); Thu, 14 Mar 2019 13:49:19 -0400 Received: by mail-ot1-f67.google.com with SMTP id c18so5885675otl.13 for ; Thu, 14 Mar 2019 10:49:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=7QeesPBLVC4Xvhqsvje2fdOGstxWInZX/y0Xrblk/lI=; b=Z4FilnmaoC0PufNfruldxw5igd6C4XDa/FOoEve6mdpYGblElx6ydzZDxg4RqIR9Gf 2E7lZlZ3sVy8YawqgimGeS1LrBPV1NAuigwiAnhUpn8S14ctJc0/WT5lB+++wHch1J00 MIQHLFs94TTzY6LslQO+98zz7Q6O+KCYB3SViKgFYtPu/svYHFtSFcexXqPilMNx5xuj DBa09dd0thbr897DRNt9LJKRljVK36DCcMjJVLYskNB+zszmlxqhmOWCW0bunF6RQ9mg okrCyz2XDQznUBDlEgtSew2vATKJPm0y8axW59QvW5Jm7ElOh11/LyLA37lfE4F3oGB6 BWBw== 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=7QeesPBLVC4Xvhqsvje2fdOGstxWInZX/y0Xrblk/lI=; b=J2D/lrI+yHAy7EO7iIw0lKHMfKKt2Jf2Ap3Z/bxqIEwz6CNR/Upp2/8MJt3yPRje0j dVt3a8OdytpnRW0e18tApNhZLEpSfpKojpStagf7rG2Xi/XnfuxIKorzMsxfR02oEK5v PIlmmHra79ak//2htnXnuCp6jZpK2lrxnC/i0WynLHcKyiUwKDKm/8R8cG3LnSf33Chj ZRZAJQPX0y3HfZgxsmK3w+DKcDCOypcEadOHbTuoGlwsLNNr23EP+yCm8xs9onSwdMW+ +sb1NYif3iVFxSxWH1XMHVpyBMGmf+8wa9p33XOUcrC4q7tsJgQLRRmVAEfQFZLxuu9F FkKg== X-Gm-Message-State: APjAAAV5OlNNmb8qhhacK9Jisi6yBvgeoNHZHY0ROpkXD74ZkpB2Xfzu 38zGhHgV+Ou5NtwqM0IoKLUH01FC57oF/fgNZ8HxXg== X-Received: by 2002:a05:6830:1493:: with SMTP id s19mr32952288otq.117.1552585757971; Thu, 14 Mar 2019 10:49:17 -0700 (PDT) MIME-Version: 1.0 References: <20190227035448.117169-1-fengc@google.com> In-Reply-To: <20190227035448.117169-1-fengc@google.com> From: Sumit Semwal Date: Thu, 14 Mar 2019 23:19:06 +0530 Message-ID: Subject: Re: [RFC dma-buf 0/3] Improve the dma-buf tracking To: Chenbo Feng Cc: LKML , DRI mailing list , linux-media@vger.kernel.org, erickreyes@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Chenbo,Thank you for your RFC series. On Wed, 27 Feb 2019 at 09:24, Chenbo Feng wrote: > > Currently, all dma-bufs share the same anonymous inode. While we can coun= t > how many dma-buf fds or mappings a process has, we can't get the size of > the backing buffers or tell if two entries point to the same dma-buf. And > in debugfs, we can get a per-buffer breakdown of size and reference count= , > but can't tell which processes are actually holding the references to eac= h > buffer. > > To resolve the issue above and provide better method for userspace to tra= ck > the dma-buf usage across different processes, the following changes are > proposed in dma-buf kernel side. First of all, replace the singleton inod= e > inside the dma-buf subsystem with a mini-filesystem, and assign each > dma-buf a unique inode out of this filesystem. With this change, calling > stat(2) on each entry gives the caller a unique ID (st_ino), the buffer's > size (st_size), and even the number of pages assigned to each dma-buffer. > Secoundly, add the inode information to /sys/kernel/debug/dma_buf/bufinfo > so in the case where a buffer is mmap()ed into a process=E2=80=99s addres= s space > but all remaining fds have been closed, we can still get the dma-buf > information and try to accociate it with the process by searching the > proc/pid/maps and looking for the corresponding inode number exposed in > dma-buf debug fs. Thirdly, created an ioctl to assign names to dma-bufs > which lets userspace assign short names (e.g., "CAMERA") to buffers. This > information can be extremely helpful for tracking and accounting shared > buffers based on their usage and original purpose. Last but not least, ad= d > dma-buf information to /proc/pid/fdinfo by adding a show_fdinfo() handler > to dma_buf_file_operations. The handler will print the file_count and nam= e > of each buffer. In general, I think I like the idea as it contributes to a much more relevant usage analysis of dma-buf backed buffers. I will get to doing a more detailed review soon, but immediately, we might want to think a bit about the get/set_name IOCTLS - do we need to think of disallowing multiple renaming of buffers once they start getting used? It could otherwise make the whole metrics a lot confused? > > Greg Hackmann (3): > dma-buf: give each buffer a full-fledged inode > dma-buf: add DMA_BUF_{GET,SET}_NAME ioctls > dma-buf: add show_fdinfo handler > > drivers/dma-buf/dma-buf.c | 121 ++++++++++++++++++++++++++++++++--- > include/linux/dma-buf.h | 5 +- > include/uapi/linux/dma-buf.h | 4 ++ > include/uapi/linux/magic.h | 1 + > 4 files changed, 122 insertions(+), 9 deletions(-) > > -- > 2.21.0.rc2.261.ga7da99ff1b-goog > Best, Sumit.