From: Gao Xiang hsiangkao@linux.alibaba.com
anolis inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT
Reference: https://gitee.com/anolis/cloud-kernel/commit/fc0e0a6efb525928abcad54374c6dbf...
--------------------------------
ANBZ: #1666
commit 09c543798c3cde19aae575a0f76d5fc7c130ff18 upstream.
Get rid of old erofs_get_meta_page() within zmap operations by using on-stack meta buffers in order to prepare subpage and folio features.
Finally, erofs_get_meta_page() is useless. Get rid of it!
Link: https://lore.kernel.org/r/20220102040017.51352-6-hsiangkao@linux.alibaba.com Reviewed-by: Yue Hu huyue2@yulong.com Reviewed-by: Liu Bo bo.liu@linux.alibaba.com Reviewed-by: Chao Yu chao@kernel.org [ Gao Xiang: adapt anolis codebase which is mainly based on 5.10. ] Signed-off-by: Gao Xiang hsiangkao@linux.alibaba.com Signed-off-by: Huang Jianan jnhuang@linux.alibaba.com Reviewed-by: Gao Xiang hsiangkao@linux.alibaba.com Reviewed-by: Jeffle Xu jefflexu@linux.alibaba.com Signed-off-by: Zizhi Wo wozizhi@huawei.com Signed-off-by: Baokun Li libaokun1@huawei.com --- fs/erofs/data.c | 10 ---------- fs/erofs/internal.h | 6 +++--- fs/erofs/zdata.c | 9 ++------- fs/erofs/zmap.c | 46 +++++++++++---------------------------------- 4 files changed, 16 insertions(+), 55 deletions(-)
diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 7b855137be8b..ac331d1c2e2f 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -42,16 +42,6 @@ static struct page *erofs_read_meta_page(struct super_block *sb, pgoff_t index) return page; }
-struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr) -{ - struct page *page = erofs_read_meta_page(sb, blkaddr); - - /* should already be PageUptodate */ - if (!IS_ERR(page)) - lock_page(page); - return page; -} - void erofs_unmap_metabuf(struct erofs_buf *buf) { if (buf->kmap_type == EROFS_KMAP) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 8a495bc4df1e..efaa98a84508 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -348,13 +348,13 @@ enum { #define EROFS_MAP_FULL_MAPPED (1 << BH_FullMapped)
struct erofs_map_blocks { + struct erofs_buf buf; + erofs_off_t m_pa, m_la; u64 m_plen, m_llen;
unsigned short m_deviceid; unsigned int m_flags; - - struct page *mpage; };
/* Flags used by erofs_map_blocks_flatmode() */ @@ -384,7 +384,7 @@ struct erofs_map_dev { };
/* data.c */ -struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr); +void erofs_unmap_metabuf(struct erofs_buf *buf); void erofs_put_metabuf(struct erofs_buf *buf); void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, erofs_blk_t blkaddr, enum erofs_kmap_type type); diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index eeb286935f8e..c93a511e21fb 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -1303,9 +1303,7 @@ static int z_erofs_readpage(struct file *file, struct page *page) if (err) erofs_err(inode->i_sb, "failed to read, err [%d]", err);
- if (f.map.mpage) - put_page(f.map.mpage); - + erofs_put_metabuf(&f.map.buf); /* clean up the remaining free pages */ put_pages_list(&pagepool); return err; @@ -1359,10 +1357,7 @@ static void z_erofs_readahead(struct readahead_control *rac) (void)z_erofs_collector_end(&f.clt);
z_erofs_runqueue(inode->i_sb, &f, &pagepool, sync); - - if (f.map.mpage) - put_page(f.map.mpage); - + erofs_put_metabuf(&f.map.buf); /* clean up the remaining free pages */ put_pages_list(&pagepool); } diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 6b9987205c90..840e795a7c70 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -31,7 +31,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) struct super_block *const sb = inode->i_sb; int err; erofs_off_t pos; - struct page *page; + struct erofs_buf buf = __EROFS_BUF_INITIALIZER; void *kaddr; struct z_erofs_map_header *h;
@@ -55,14 +55,13 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize + vi->xattr_isize, 8); - page = erofs_get_meta_page(sb, erofs_blknr(pos)); - if (IS_ERR(page)) { - err = PTR_ERR(page); + kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), + EROFS_KMAP_ATOMIC); + if (IS_ERR(kaddr)) { + err = PTR_ERR(kaddr); goto out_unlock; }
- kaddr = kmap_atomic(page); - h = kaddr + erofs_blkoff(pos); vi->z_advise = le16_to_cpu(h->h_advise); vi->z_algorithmtype[0] = h->h_algorithmtype & 15; @@ -92,9 +91,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) smp_mb(); set_bit(EROFS_I_Z_INITED_BIT, &vi->flags); unmap_done: - kunmap_atomic(kaddr); - unlock_page(page); - put_page(page); + erofs_put_metabuf(&buf); out_unlock: clear_and_wake_up_bit(EROFS_I_BL_Z_BIT, &vi->flags); return err; @@ -117,31 +114,11 @@ static int z_erofs_reload_indexes(struct z_erofs_maprecorder *m, erofs_blk_t eblk) { struct super_block *const sb = m->inode->i_sb; - struct erofs_map_blocks *const map = m->map; - struct page *mpage = map->mpage; - - if (mpage) { - if (mpage->index == eblk) { - if (!m->kaddr) - m->kaddr = kmap_atomic(mpage); - return 0; - }
- if (m->kaddr) { - kunmap_atomic(m->kaddr); - m->kaddr = NULL; - } - put_page(mpage); - } - - mpage = erofs_get_meta_page(sb, eblk); - if (IS_ERR(mpage)) { - map->mpage = NULL; - return PTR_ERR(mpage); - } - m->kaddr = kmap_atomic(mpage); - unlock_page(mpage); - map->mpage = mpage; + m->kaddr = erofs_read_metabuf(&m->map->buf, sb, eblk, + EROFS_KMAP_ATOMIC); + if (IS_ERR(m->kaddr)) + return PTR_ERR(m->kaddr); return 0; }
@@ -461,8 +438,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, map->m_flags |= EROFS_MAP_MAPPED;
unmap_out: - if (m.kaddr) - kunmap_atomic(m.kaddr); + erofs_unmap_metabuf(&m.map->buf);
out: erofs_dbg("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o",