From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org
Cc: linux-fsdevel@vger.kernel.org, huyue2@coolpad.com,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 4/6] erofs: implement .read_iter for page cache sharing
Date: Fri, 6 Jan 2023 20:53:28 +0800 [thread overview]
Message-ID: <20230106125330.55529-5-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230106125330.55529-1-jefflexu@linux.alibaba.com>
When page cache sharing enabled, page caches are managed in the address
space of blobs rather than erofs inodes. All erofs inodes sharing one
chunk will refer to and share the page cache in the blob's address
space.
Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
fs/erofs/fscache.c | 64 +++++++++++++++++++++++++++++++++++++++++++++
fs/erofs/internal.h | 1 +
2 files changed, 65 insertions(+)
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index ea276884f043..1f2a42dd1590 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -320,6 +320,70 @@ const struct address_space_operations erofs_fscache_access_aops = {
static const struct file_operations erofs_fscache_meta_fops = {};
+static ssize_t erofs_fscache_share_file_read_iter(struct kiocb *iocb,
+ struct iov_iter *to)
+{
+ struct file *filp = iocb->ki_filp;
+ struct inode *inode = file_inode(filp);
+ /* since page cache sharing is enabled only when i_size <= chunk_size */
+ struct erofs_map_blocks map = {}; /* .m_la = 0 */
+ struct erofs_map_dev mdev;
+ struct folio *folio;
+ ssize_t already_read = 0;
+ int ret = 0;
+
+ /* no need taking (shared) inode lock since it's a ro filesystem */
+ if (!iov_iter_count(to))
+ return 0;
+
+ if (IS_DAX(inode) || iocb->ki_flags & IOCB_DIRECT)
+ return -EOPNOTSUPP;
+
+ ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
+ if (ret)
+ return ret;
+
+ mdev = (struct erofs_map_dev) {
+ .m_deviceid = map.m_deviceid,
+ .m_pa = map.m_pa,
+ };
+ ret = erofs_map_dev(inode->i_sb, &mdev);
+ if (ret)
+ return ret;
+
+ do {
+ size_t bytes, copied, offset, fsize;
+ pgoff_t index = (mdev.m_pa >> PAGE_SHIFT) + (iocb->ki_pos >> PAGE_SHIFT);
+
+ folio = read_cache_folio(mdev.m_fscache->inode->i_mapping, index, NULL, NULL);
+ if (IS_ERR(folio)) {
+ ret = PTR_ERR(folio);
+ break;
+ }
+
+ fsize = folio_size(folio);
+ offset = iocb->ki_pos & (fsize - 1);
+ bytes = min_t(size_t, inode->i_size - iocb->ki_pos, iov_iter_count(to));
+ bytes = min_t(size_t, bytes, fsize - offset);
+ copied = copy_folio_to_iter(folio, offset, bytes, to);
+ folio_put(folio);
+ iocb->ki_pos += copied;
+ already_read += copied;
+ if (copied < bytes) {
+ ret = -EFAULT;
+ break;
+ }
+ } while (iov_iter_count(to) && iocb->ki_pos < inode->i_size);
+
+ file_accessed(filp);
+ return already_read ? already_read : ret;
+}
+
+const struct file_operations erofs_fscache_share_file_fops = {
+ .llseek = generic_file_llseek,
+ .read_iter = erofs_fscache_share_file_read_iter,
+};
+
static void erofs_fscache_domain_put(struct erofs_domain *domain)
{
mutex_lock(&erofs_domain_list_lock);
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 24d471fe2fa4..386e2fd4c025 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -617,6 +617,7 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache);
extern const struct address_space_operations erofs_fscache_access_aops;
+extern const struct file_operations erofs_fscache_share_file_fops;
#else
static inline int erofs_fscache_register_fs(struct super_block *sb)
{
--
2.19.1.6.gb485710b
WARNING: multiple messages have this Message-ID (diff)
From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org
Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH 4/6] erofs: implement .read_iter for page cache sharing
Date: Fri, 6 Jan 2023 20:53:28 +0800 [thread overview]
Message-ID: <20230106125330.55529-5-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230106125330.55529-1-jefflexu@linux.alibaba.com>
When page cache sharing enabled, page caches are managed in the address
space of blobs rather than erofs inodes. All erofs inodes sharing one
chunk will refer to and share the page cache in the blob's address
space.
Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
fs/erofs/fscache.c | 64 +++++++++++++++++++++++++++++++++++++++++++++
fs/erofs/internal.h | 1 +
2 files changed, 65 insertions(+)
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index ea276884f043..1f2a42dd1590 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -320,6 +320,70 @@ const struct address_space_operations erofs_fscache_access_aops = {
static const struct file_operations erofs_fscache_meta_fops = {};
+static ssize_t erofs_fscache_share_file_read_iter(struct kiocb *iocb,
+ struct iov_iter *to)
+{
+ struct file *filp = iocb->ki_filp;
+ struct inode *inode = file_inode(filp);
+ /* since page cache sharing is enabled only when i_size <= chunk_size */
+ struct erofs_map_blocks map = {}; /* .m_la = 0 */
+ struct erofs_map_dev mdev;
+ struct folio *folio;
+ ssize_t already_read = 0;
+ int ret = 0;
+
+ /* no need taking (shared) inode lock since it's a ro filesystem */
+ if (!iov_iter_count(to))
+ return 0;
+
+ if (IS_DAX(inode) || iocb->ki_flags & IOCB_DIRECT)
+ return -EOPNOTSUPP;
+
+ ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
+ if (ret)
+ return ret;
+
+ mdev = (struct erofs_map_dev) {
+ .m_deviceid = map.m_deviceid,
+ .m_pa = map.m_pa,
+ };
+ ret = erofs_map_dev(inode->i_sb, &mdev);
+ if (ret)
+ return ret;
+
+ do {
+ size_t bytes, copied, offset, fsize;
+ pgoff_t index = (mdev.m_pa >> PAGE_SHIFT) + (iocb->ki_pos >> PAGE_SHIFT);
+
+ folio = read_cache_folio(mdev.m_fscache->inode->i_mapping, index, NULL, NULL);
+ if (IS_ERR(folio)) {
+ ret = PTR_ERR(folio);
+ break;
+ }
+
+ fsize = folio_size(folio);
+ offset = iocb->ki_pos & (fsize - 1);
+ bytes = min_t(size_t, inode->i_size - iocb->ki_pos, iov_iter_count(to));
+ bytes = min_t(size_t, bytes, fsize - offset);
+ copied = copy_folio_to_iter(folio, offset, bytes, to);
+ folio_put(folio);
+ iocb->ki_pos += copied;
+ already_read += copied;
+ if (copied < bytes) {
+ ret = -EFAULT;
+ break;
+ }
+ } while (iov_iter_count(to) && iocb->ki_pos < inode->i_size);
+
+ file_accessed(filp);
+ return already_read ? already_read : ret;
+}
+
+const struct file_operations erofs_fscache_share_file_fops = {
+ .llseek = generic_file_llseek,
+ .read_iter = erofs_fscache_share_file_read_iter,
+};
+
static void erofs_fscache_domain_put(struct erofs_domain *domain)
{
mutex_lock(&erofs_domain_list_lock);
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 24d471fe2fa4..386e2fd4c025 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -617,6 +617,7 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache);
extern const struct address_space_operations erofs_fscache_access_aops;
+extern const struct file_operations erofs_fscache_share_file_fops;
#else
static inline int erofs_fscache_register_fs(struct super_block *sb)
{
--
2.19.1.6.gb485710b
next prev parent reply other threads:[~2023-01-06 12:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-06 12:53 [RFC PATCH 0/6] erofs: support page cache sharing between EROFS images in fscache mode Jingbo Xu
2023-01-06 12:53 ` Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 1/6] erofs: remove unused device mapping in the meta routine Jingbo Xu
2023-01-06 12:53 ` Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 2/6] erofs: unify anonymous inodes for blob Jingbo Xu
2023-01-06 12:53 ` Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 3/6] erofs: alloc anonymous file for blob in share domain mode Jingbo Xu
2023-01-06 12:53 ` Jingbo Xu
2023-01-06 12:53 ` Jingbo Xu [this message]
2023-01-06 12:53 ` [RFC PATCH 4/6] erofs: implement .read_iter for page cache sharing Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 5/6] erofs: implement .mmap " Jingbo Xu
2023-01-06 12:53 ` Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 6/6] erofs: enable page cache sharing in fscache mode Jingbo Xu
2023-01-06 12:53 ` Jingbo Xu
2023-01-19 8:54 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230106125330.55529-5-jefflexu@linux.alibaba.com \
--to=jefflexu@linux.alibaba.com \
--cc=chao@kernel.org \
--cc=huyue2@coolpad.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.