Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp203075pxb; Fri, 16 Apr 2021 03:33:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ3JB+IwSP4iu1Lk7wjH3/DTW86hOMBQvGCYEn9keWMhv3fJL5MjnzCzgphmvCAn/lla1p X-Received: by 2002:aa7:d1ce:: with SMTP id g14mr2664522edp.122.1618569199856; Fri, 16 Apr 2021 03:33:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618569199; cv=none; d=google.com; s=arc-20160816; b=RDWOxudQoO4MAdNQs1jH8GhUZRRxTxbh3CrUDKgoLcOOtVJ0XWrzhsvMzkEfFNI6OI jQrHF9WlQohYeOhD2qPU/Td5j0Mhvv6M2dyG9NizoibzDCp8Y6UdcyA7W6e9rH75wv7N NX7LaZzRX7TUPUPubSvH4095XQhiONA4Q71G4j0HW11bxwVLA625//5d9tc9wR1IG7ln 8MK9tBslI/rXtGzkLKF9qtI9yPlktKGcvEZpK85u5/kZBUA//BPzcau3dbmkblUJp6Hv odpjWXqrWNHdl1BhlhssEKti6c01rKnup67VB9LstbyPpRyreRSmv3NLuNoVbwPNSo8W LqBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=vOdwQquOGwCP3Hl1t+hyvxbAuJZO7DnTkFkKi70KvdI=; b=SoZm/Y0OKE1t389z/s1jrlCH2GEmnNr44lj5QAx7fHF35Um8q3nYfVbDr0HBbsLoJI 17qzGs6X4cNE8bnjzK7JZuxYo/SRGmfjhwC0dT31jtxaaDQO+1gP+KBIw0CAb2Jd6vT5 86RG4almzZ4ZNGovOjyPx58TrSyMj8IiHiT0LdgwZyq3Oe255gMHKiNQOJrG7EC3UH/O UbbhXzigi2le9l3JDPwpGcdubXqBudrkWV5wo5ZqHbyhlqggtFPr2XnAGvgMc9tb3YDZ pTDWsVzqprazQQVLVcNCBqUHbcWZvbC373Y4vnlR+I2N6cTOBrMw79O/QKXHgtOyJWcn n9sw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=sony.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si4729139ejr.444.2021.04.16.03.32.56; Fri, 16 Apr 2021 03:33:19 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=sony.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241974AbhDPJi5 (ORCPT + 99 others); Fri, 16 Apr 2021 05:38:57 -0400 Received: from jptosegrel01.sonyericsson.com ([124.215.201.71]:12904 "EHLO JPTOSEGREL01.sonyericsson.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235027AbhDPJiv (ORCPT ); Fri, 16 Apr 2021 05:38:51 -0400 From: Peter Enderborg To: , , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Alexey Dobriyan , Andrew Morton , Muchun Song , Roman Gushchin , Shakeel Butt , Michal Hocko , NeilBrown , Sami Tolvanen , Mike Rapoport , , , CC: Peter Enderborg Subject: [PATCH] dma-buf: Add DmaBufTotal counter in meminfo Date: Fri, 16 Apr 2021 11:37:19 +0200 Message-ID: <20210416093719.6197-1-peter.enderborg@sony.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-SEG-SpamProfiler-Analysis: v=2.3 cv=crzlbGwi c=1 sm=1 tr=0 a=9drRLWArJOlETflmpfiyCA==:117 a=3YhXtTcJ-WEA:10 a=z6gsHLkEAAAA:8 a=USQXLDy_ZNVIum19Oj8A:9 a=d-OLMTCWyvARjPbQ-enb:22 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 X-SEG-SpamProfiler-Score: 0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds a total used dma-buf memory. Details can be found in debugfs, however it is not for everyone and not always available. Signed-off-by: Peter Enderborg --- drivers/dma-buf/dma-buf.c | 12 ++++++++++++ fs/proc/meminfo.c | 2 ++ include/linux/dma-buf.h | 1 + 3 files changed, 15 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index f264b70c383e..9f88171b394c 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -37,6 +37,7 @@ struct dma_buf_list { }; static struct dma_buf_list db_list; +static atomic_long_t dma_buf_size; static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen) { @@ -79,6 +80,7 @@ static void dma_buf_release(struct dentry *dentry) if (dmabuf->resv == (struct dma_resv *)&dmabuf[1]) dma_resv_fini(dmabuf->resv); + atomic_long_sub(dmabuf->size, &dma_buf_size); module_put(dmabuf->owner); kfree(dmabuf->name); kfree(dmabuf); @@ -586,6 +588,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) mutex_lock(&db_list.lock); list_add(&dmabuf->list_node, &db_list.head); mutex_unlock(&db_list.lock); + atomic_long_add(dmabuf->size, &dma_buf_size); return dmabuf; @@ -1346,6 +1349,15 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) } EXPORT_SYMBOL_GPL(dma_buf_vunmap); +/** + * dma_buf_get_size - Return the used nr pages by dma-buf + */ +long dma_buf_get_size(void) +{ + return atomic_long_read(&dma_buf_size) >> PAGE_SHIFT; +} +EXPORT_SYMBOL_GPL(dma_buf_get_size); + #ifdef CONFIG_DEBUG_FS static int dma_buf_debug_show(struct seq_file *s, void *unused) { diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 6fa761c9cc78..3c1a82b51a6f 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -16,6 +16,7 @@ #ifdef CONFIG_CMA #include #endif +#include #include #include "internal.h" @@ -145,6 +146,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) show_val_kb(m, "CmaFree: ", global_zone_page_state(NR_FREE_CMA_PAGES)); #endif + show_val_kb(m, "DmaBufTotal: ", dma_buf_get_size()); hugetlb_report_meminfo(m); diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index efdc56b9d95f..f6481315a377 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -507,4 +507,5 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, unsigned long); int dma_buf_vmap(struct dma_buf *dmabuf, struct dma_buf_map *map); void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map); +long dma_buf_get_size(void); #endif /* __DMA_BUF_H__ */ -- 2.17.1