Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp33650ima; Thu, 14 Mar 2019 18:52:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1I2/nb4/QpAmC7oa6xJR/AT+S1NCt0AIFg9EQEjQR0i6T6c8cFx6gFEW3pRhXbyUg6PLd X-Received: by 2002:a17:902:9a95:: with SMTP id w21mr1502399plp.118.1552614765062; Thu, 14 Mar 2019 18:52:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552614765; cv=none; d=google.com; s=arc-20160816; b=S24LsyRo5/gqI2aAWXzytTcMqhPVxiHS4ciiY3vslhzZ47qP7nZOJyHUBfcF+CYupy ddMj5fxNHv/Ez7yCNQnnG0D8s7Jn9wqHW2ZbKNEKiqrJkrkWsP7z77wiQ5+q/MpxiUYg AOobEvbNfS0Wf7OQt/qPvfE24pTJ/Ld5ZlCPVudP/hIoI4D/L/AXtu5CA0C4AKgqLVEf LBNMIujsfnnYAZ0G9YIFeHl9kZnJhQXNSMH8+X/dwT3oSEA+mdBmZZB88bKX6XNT0lOb BcZJO2x1YmDct1bS7T3eIQOe6IkTSB6yTGlQDGWzqQ6hAJNDU/o0mM2sjxIDP1zyVXcO U8YQ== 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=j+EKE+JvaEx6WP8A7cFB62QmIXFykKUTN5Lyz0yPMTs=; b=BFe/RZy0lsFu4AQBLZTW6FUijz9cOhFTAGMnLB6+y5YL3OZPWtrhgIBPmI1QIweNbm OUKQ7ZpvEzMvzNBuLAPSFNd2+5axNT1oYYFJ1z+MFWoXMHM+kt5ZKLf6RgTf2GMqTmXK xNZRdMb6AcS2pd842RwYYEv7s0UclJmfsIyoA6RzuLc1z/tjJKlIpm2JFxpztYNkusuM IqNTLLhuWEFs1qXK+wWH2sGgSc2nSBFEegdDq33v0c5tQ7aXr8gOARMs+O0zob2OotFB lvYYPBgAAZ742fHCzP/wxTW7CKKnurf52iJacl0Kk9biOA7XpCcrZAaUB5LULTBF9RRX 31iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uhgfdHQW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d21si472340pll.437.2019.03.14.18.52.16; Thu, 14 Mar 2019 18:52:45 -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=@google.com header.s=20161025 header.b=uhgfdHQW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727652AbfCOBuy (ORCPT + 99 others); Thu, 14 Mar 2019 21:50:54 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:43194 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726571AbfCOBux (ORCPT ); Thu, 14 Mar 2019 21:50:53 -0400 Received: by mail-lj1-f193.google.com with SMTP id z20so6532249ljj.10 for ; Thu, 14 Mar 2019 18:50:52 -0700 (PDT) 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=j+EKE+JvaEx6WP8A7cFB62QmIXFykKUTN5Lyz0yPMTs=; b=uhgfdHQW/0lCQXPyiXhrb8qnM2uL4GV6kj0k1z+cqrZBmgRmrX+szBD5IGwzzwg0Dj ylCm/zecxSZToVaXVBRW1vS8kho0lc+ezsN+UC1T9eeWz1hm8s4iq4j7/rveOC+anxuZ CvKfGqq1xCOOvqBIEZ51TInasvzAsxT9dEQ59m2MRd0lYioHI88u/e1ZtMLxixCjSJHo HGPdLCkH9vSf2/Ti77TdK10fsL3IEIjOYi5a0HTSeE/XIA8gkvRzRXArVGdiqf1kmy0g JYcNusXEHuderXAfThoiSN8kAjvmsHMqxMq6hYQMnAvcwu8Yje2w3S2IGaNJQq0KbVs7 tsPw== 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=j+EKE+JvaEx6WP8A7cFB62QmIXFykKUTN5Lyz0yPMTs=; b=F7/TaWBmeWl7/wZF6oLahAYncPBDLCwC1NA1k1z4M/DSUjCzZ0cuZZNB+GcYbxcYuQ 6xrYZ2VjTdMJHoUinLVUxlOHjJf61ShcX0HIVak3ANEK93jbrsruwxbZJcneFOV3CqYZ OPK+C2W49rVtredCBgcKUdajPUDht5VhfOWg3bn5/AWx3yERFWw8JjcIV7Q9JlpofZX4 NEF5lYLFlm41OCLO4kvWQeUovEa5FSqXi8s4gnPBFSxEMVvEehS1IZq7ZafD/h+uA9wX Pc8TfYXpcLCqiHXafsouVaNujlASEQxKPupNfXC4QULJLFnxj4cO/yr9Ijnoa+hawNtz P9ZA== X-Gm-Message-State: APjAAAUPQj4bok+CGUYsF98PMKjasjC/hOQmXpxoDnToQLVEkZ/dJvZ0 RvCbuOFROFEejpkdu3Pfk8UC2S45gZ+oNMZEpwl59g== X-Received: by 2002:a2e:1510:: with SMTP id s16mr595740ljd.62.1552614651111; Thu, 14 Mar 2019 18:50:51 -0700 (PDT) MIME-Version: 1.0 References: <20190227035448.117169-1-fengc@google.com> In-Reply-To: From: Chenbo Feng Date: Thu, 14 Mar 2019 18:50:40 -0700 Message-ID: Subject: Re: [RFC dma-buf 0/3] Improve the dma-buf tracking To: Sumit Semwal Cc: LKML , DRI mailing list , linux-media@vger.kernel.org, Erick Reyes 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 On Thu, Mar 14, 2019 at 10:49 AM Sumit Semwal wro= te: > > 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 co= unt > > how many dma-buf fds or mappings a process has, we can't get the size o= f > > the backing buffers or tell if two entries point to the same dma-buf. A= nd > > in debugfs, we can get a per-buffer breakdown of size and reference cou= nt, > > but can't tell which processes are actually holding the references to e= ach > > buffer. > > > > To resolve the issue above and provide better method for userspace to t= rack > > the dma-buf usage across different processes, the following changes are > > proposed in dma-buf kernel side. First of all, replace the singleton in= ode > > inside the dma-buf subsystem with a mini-filesystem, and assign each > > dma-buf a unique inode out of this filesystem. With this change, calli= ng > > 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-buffe= r. > > Secoundly, add the inode information to /sys/kernel/debug/dma_buf/bufin= fo > > so in the case where a buffer is mmap()ed into a process=E2=80=99s addr= ess 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. Th= is > > information can be extremely helpful for tracking and accounting shared > > buffers based on their usage and original purpose. Last but not least, = add > > dma-buf information to /proc/pid/fdinfo by adding a show_fdinfo() handl= er > > to dma_buf_file_operations. The handler will print the file_count and n= ame > > 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? Yes, I agree we need to control the dma-buf naming to make sure it doesn't confuse the user. Ideally the process asked for dma-buf need to make sure they only set the name once when they are using the buffer for the same purpose. But I guess we can add check in kernel side to make sure the name only get initialized once and can never change after it. Or do we have better way to disallow multiple renaming of buffers once they start getting used? Can we find a way to set the name information in dma_buf_export so no one can change it after that? > > > > > 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.