Skip to contentSkip to conversation

erofs: implement .fadvise for page cache share

PATCH Superseded Hongbo Li 2 participants 2 messages Dec 23, 2025

Subsystems (2)

v10 of 18 Superseded Latest is v18 →

lore
Share & tools
lore

Hongbo Li

author
#0 lore raw

PATCH v10 10/10 erofs: implement .fadvise for page cache share

From: Hongzhen Luo <[email protected]>

This patch implements the .fadvise interface for page cache share. Similar to overlayfs, it drops those clean, unused pages through vfs_fadvise().

---
 fs/erofs/ishare.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
fs/erofs/ishare.c +11 -0
index 269b53b3ed79..d7231953cba2 100644
@@ -187,6 +187,16 @@ static int erofs_ishare_mmap(struct file *file, struct vm_area_struct *vma)
 	return generic_file_readonly_mmap(file, vma);
 }
 
+static int erofs_ishare_fadvise(struct file *file, loff_t offset,
+				      loff_t len, int advice)
+{
+	struct file *realfile = file->private_data;
+
+	if (!realfile)
+		return -EINVAL;
+	return vfs_fadvise(realfile, offset, len, advice);
+}
+
 const struct file_operations erofs_ishare_fops = {
 	.open		= erofs_ishare_file_open,
 	.llseek		= generic_file_llseek,
@@ -195,6 +205,7 @@ const struct file_operations erofs_ishare_fops = {
 	.release	= erofs_ishare_file_release,
 	.get_unmapped_area = thp_get_unmapped_area,
 	.splice_read	= filemap_splice_read,
+	.fadvise	= erofs_ishare_fadvise,
 };
 
 /*
Signature · 1 line
2.22.0
#1 lore raw
Quoted 9 lines · Hongbo Li

From: Hongzhen Luo <[email protected]>

This patch implements the .fadvise interface for page cache share. Similar to overlayfs, it drops those clean, unused pages through vfs_fadvise().

This should be sent out together within the series next time.

Quoted 9 lines
---
  fs/erofs/ishare.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
fs/erofs/ishare.c +0 -0
index 269b53b3ed79..d7231953cba2 100644

fs/erofs/ishare.c static int erofs_ishare_mmap(struct file *file, struct vm_area_struct *vma) · line 196

Quoted 10 lines
fs/erofs/ishare.c +7 -0
@@ -187,6 +187,16 @@ static int erofs_ishare_mmap(struct file *file, struct vm_area_struct *vma)
  	return generic_file_readonly_mmap(file, vma);
  }
 
+static int erofs_ishare_fadvise(struct file *file, loff_t offset,
+				      loff_t len, int advice)
+{
+	struct file *realfile = file->private_data;
+
+	if (!realfile)
+		return -EINVAL;

BTW, when file->private_data == NULL here?

I think it can only happen if buggy, so just:

	return vfs_fadvise((struct file *)file->private_data,
			   offset, len, advice);

Thanks,
Gao Xiang

Quoted 14 lines
fs/erofs/ishare.c +4 -0
+	return vfs_fadvise(realfile, offset, len, advice);
+}
+
  const struct file_operations erofs_ishare_fops = {
  	.open		= erofs_ishare_file_open,
  	.llseek		= generic_file_llseek,
@@ -195,6 +205,7 @@ const struct file_operations erofs_ishare_fops = {
  	.release	= erofs_ishare_file_release,
  	.get_unmapped_area = thp_get_unmapped_area,
  	.splice_read	= filemap_splice_read,
+	.fadvise	= erofs_ishare_fadvise,
  };
 
  /*