mirror of
https://github.com/torvalds/linux.git
synced 2026-06-06 21:45:45 +02:00
ANDROID: dmabuf: Add mmap_count to struct dmabuf
mmap_count can be used to efficiently calculate the PSS for any DMA buffer that the process has mapped. Bug: 167141117 Change-Id: I8296981f0135a5532969aca3a8baa5da61dfe39f Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This commit is contained in:
parent
7493fb28b3
commit
9132fbe545
|
|
@ -50,3 +50,10 @@ KernelVersion: v5.12
|
||||||
Contact: Hridya Valsaraju <hridya@google.com>
|
Contact: Hridya Valsaraju <hridya@google.com>
|
||||||
Description: This file is read-only and contains a map_counter indicating the
|
Description: This file is read-only and contains a map_counter indicating the
|
||||||
number of distinct device mappings of the attachment.
|
number of distinct device mappings of the attachment.
|
||||||
|
|
||||||
|
What: /sys/kernel/dmabuf/buffers/<inode_number>/mmap_count
|
||||||
|
Date: January 2021
|
||||||
|
KernelVersion: v5.10
|
||||||
|
Contact: Kalesh Singh <kaleshsingh@google.com>
|
||||||
|
Description: This file is read-only and contains a counter indicating the
|
||||||
|
number of times the buffer has been mmap().
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,13 @@ static ssize_t exporter_name_show(struct dma_buf *dmabuf,
|
||||||
return sysfs_emit(buf, "%s\n", dmabuf->exp_name);
|
return sysfs_emit(buf, "%s\n", dmabuf->exp_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ssize_t mmap_count_show(struct dma_buf *dmabuf,
|
||||||
|
struct dma_buf_stats_attribute *attr,
|
||||||
|
char *buf)
|
||||||
|
{
|
||||||
|
return sysfs_emit(buf, "%d\n", dmabuf->mmap_count);
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t size_show(struct dma_buf *dmabuf,
|
static ssize_t size_show(struct dma_buf *dmabuf,
|
||||||
struct dma_buf_stats_attribute *attr,
|
struct dma_buf_stats_attribute *attr,
|
||||||
char *buf)
|
char *buf)
|
||||||
|
|
@ -62,10 +69,13 @@ static ssize_t size_show(struct dma_buf *dmabuf,
|
||||||
static struct dma_buf_stats_attribute exporter_name_attribute =
|
static struct dma_buf_stats_attribute exporter_name_attribute =
|
||||||
__ATTR_RO(exporter_name);
|
__ATTR_RO(exporter_name);
|
||||||
static struct dma_buf_stats_attribute size_attribute = __ATTR_RO(size);
|
static struct dma_buf_stats_attribute size_attribute = __ATTR_RO(size);
|
||||||
|
static struct dma_buf_stats_attribute mmap_count_attribute =
|
||||||
|
__ATTR_RO(mmap_count);
|
||||||
|
|
||||||
static struct attribute *dma_buf_stats_default_attrs[] = {
|
static struct attribute *dma_buf_stats_default_attrs[] = {
|
||||||
&exporter_name_attribute.attr,
|
&exporter_name_attribute.attr,
|
||||||
&size_attribute.attr,
|
&size_attribute.attr,
|
||||||
|
&mmap_count_attribute.attr,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
ATTRIBUTE_GROUPS(dma_buf_stats_default);
|
ATTRIBUTE_GROUPS(dma_buf_stats_default);
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,54 @@ static struct file_system_type dma_buf_fs_type = {
|
||||||
.kill_sb = kill_anon_super,
|
.kill_sb = kill_anon_super,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_DMABUF_SYSFS_STATS
|
||||||
|
static void dma_buf_vma_open(struct vm_area_struct *vma)
|
||||||
|
{
|
||||||
|
struct dma_buf *dmabuf = vma->vm_file->private_data;
|
||||||
|
|
||||||
|
dmabuf->mmap_count++;
|
||||||
|
/* call the heap provided vma open() op */
|
||||||
|
if (dmabuf->exp_vm_ops->open)
|
||||||
|
dmabuf->exp_vm_ops->open(vma);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dma_buf_vma_close(struct vm_area_struct *vma)
|
||||||
|
{
|
||||||
|
struct dma_buf *dmabuf = vma->vm_file->private_data;
|
||||||
|
|
||||||
|
if (dmabuf->mmap_count)
|
||||||
|
dmabuf->mmap_count--;
|
||||||
|
/* call the heap provided vma close() op */
|
||||||
|
if (dmabuf->exp_vm_ops->close)
|
||||||
|
dmabuf->exp_vm_ops->close(vma);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dma_buf_do_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
|
||||||
|
{
|
||||||
|
/* call this first because the exporter might override vma->vm_ops */
|
||||||
|
int ret = dmabuf->ops->mmap(dmabuf, vma);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* save the exporter provided vm_ops */
|
||||||
|
dmabuf->exp_vm_ops = vma->vm_ops;
|
||||||
|
dmabuf->vm_ops = *(dmabuf->exp_vm_ops);
|
||||||
|
/* override open() and close() to provide buffer mmap count */
|
||||||
|
dmabuf->vm_ops.open = dma_buf_vma_open;
|
||||||
|
dmabuf->vm_ops.close = dma_buf_vma_close;
|
||||||
|
vma->vm_ops = &dmabuf->vm_ops;
|
||||||
|
dmabuf->mmap_count++;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#else /* CONFIG_DMABUF_SYSFS_STATS */
|
||||||
|
static int dma_buf_do_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
|
||||||
|
{
|
||||||
|
return dmabuf->ops->mmap(dmabuf, vma);
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_DMABUF_SYSFS_STATS */
|
||||||
|
|
||||||
static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
|
static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
|
||||||
{
|
{
|
||||||
struct dma_buf *dmabuf;
|
struct dma_buf *dmabuf;
|
||||||
|
|
@ -145,7 +193,7 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
|
||||||
dmabuf->size >> PAGE_SHIFT)
|
dmabuf->size >> PAGE_SHIFT)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
return dmabuf->ops->mmap(dmabuf, vma);
|
return dma_buf_do_mmap(dmabuf, vma);
|
||||||
}
|
}
|
||||||
|
|
||||||
static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence)
|
static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence)
|
||||||
|
|
|
||||||
|
|
@ -381,6 +381,9 @@ struct dma_buf_ops {
|
||||||
* @sysfs_entry: for exposing information about this buffer in sysfs.
|
* @sysfs_entry: for exposing information about this buffer in sysfs.
|
||||||
* The attachment_uid member of @sysfs_entry is protected by dma_resv lock
|
* The attachment_uid member of @sysfs_entry is protected by dma_resv lock
|
||||||
* and is incremented on each attach.
|
* and is incremented on each attach.
|
||||||
|
* @mmap_count: number of times buffer has been mmapped.
|
||||||
|
* @exp_vm_ops: the vm ops provided by the buffer exporter.
|
||||||
|
* @vm_ops: the overridden vm_ops used to track mmap_count of the buffer.
|
||||||
*
|
*
|
||||||
* This represents a shared buffer, created by calling dma_buf_export(). The
|
* This represents a shared buffer, created by calling dma_buf_export(). The
|
||||||
* userspace representation is a normal file descriptor, which can be created by
|
* userspace representation is a normal file descriptor, which can be created by
|
||||||
|
|
@ -424,6 +427,9 @@ struct dma_buf {
|
||||||
unsigned int attachment_uid;
|
unsigned int attachment_uid;
|
||||||
struct kset *attach_stats_kset;
|
struct kset *attach_stats_kset;
|
||||||
} *sysfs_entry;
|
} *sysfs_entry;
|
||||||
|
int mmap_count;
|
||||||
|
const struct vm_operations_struct *exp_vm_ops;
|
||||||
|
struct vm_operations_struct vm_ops;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user