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/5af84129f73c550f84ce568646603d0...
--------------------------------
ANBZ: #1666
commit fdf80a4793021c2f27953b3075f401a497519ba4 upstream.
In order to support subpage and folio for all uncompressed files, introduce meta buffer descriptors, which can be effectively stored on stack, in place of meta page operations.
This converts the uncompressed data path to meta buffers.
Link: https://lore.kernel.org/r/20220102040017.51352-2-hsiangkao@linux.alibaba.com Reviewed-by: Liu Bo bo.liu@linux.alibaba.com Reviewed-by: Chao Yu chao@kernel.org Signed-off-by: Gao Xiang hsiangkao@linux.alibaba.com [ Huang Jianan: kill the unnecessary kunmap_atomic in erofs_read_raw_page() ] 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 | 95 ++++++++++++++++++++++++++++++++++----------- fs/erofs/internal.h | 13 +++++++ 2 files changed, 86 insertions(+), 22 deletions(-)
diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 125698c6f6e2..7b855137be8b 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -32,19 +32,75 @@ static void erofs_readendio(struct bio *bio) bio_put(bio); }
-struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr) +static struct page *erofs_read_meta_page(struct super_block *sb, pgoff_t index) { struct address_space *const mapping = sb->s_bdev->bd_inode->i_mapping; struct page *page;
- page = read_cache_page_gfp(mapping, blkaddr, + page = read_cache_page_gfp(mapping, index, mapping_gfp_constraint(mapping, ~__GFP_FS)); + 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) + kunmap(buf->page); + else if (buf->kmap_type == EROFS_KMAP_ATOMIC) + kunmap_atomic(buf->base); + buf->base = NULL; + buf->kmap_type = EROFS_NO_KMAP; +} + +void erofs_put_metabuf(struct erofs_buf *buf) +{ + if (!buf->page) + return; + erofs_unmap_metabuf(buf); + put_page(buf->page); + buf->page = NULL; +} + +void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, + erofs_blk_t blkaddr, enum erofs_kmap_type type) +{ + erofs_off_t offset = blknr_to_addr(blkaddr); + pgoff_t index = offset >> PAGE_SHIFT; + struct page *page = buf->page; + + if (!page || page->index != index) { + erofs_put_metabuf(buf); + page = erofs_read_meta_page(sb, index); + if (IS_ERR(page)) + return page; + /* should already be PageUptodate, no need to lock page */ + buf->page = page; + } + if (buf->kmap_type == EROFS_NO_KMAP) { + if (type == EROFS_KMAP) + buf->base = kmap(page); + else if (type == EROFS_KMAP_ATOMIC) + buf->base = kmap_atomic(page); + buf->kmap_type = type; + } else if (buf->kmap_type != type) { + DBG_BUGON(1); + return ERR_PTR(-EFAULT); + } + if (type == EROFS_NO_KMAP) + return NULL; + return buf->base + (offset & ~PAGE_MASK); +} + static int erofs_map_blocks_flatmode(struct inode *inode, struct erofs_map_blocks *map, int flags) @@ -54,7 +110,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode, struct erofs_inode *vi = EROFS_I(inode); bool tailendpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE);
- nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE); + nblocks = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); lastblk = nblocks - tailendpacking;
/* there is no hole in flatmode */ @@ -95,10 +151,11 @@ static int erofs_map_blocks(struct inode *inode, struct super_block *sb = inode->i_sb; struct erofs_inode *vi = EROFS_I(inode); struct erofs_inode_chunk_index *idx; - struct page *page; + struct erofs_buf buf = __EROFS_BUF_INITIALIZER; u64 chunknr; unsigned int unit; erofs_off_t pos; + void *kaddr; int err = 0;
trace_erofs_map_blocks_enter(inode, map, flags); @@ -124,9 +181,9 @@ static int erofs_map_blocks(struct inode *inode, pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize + vi->xattr_isize, unit) + unit * chunknr;
- page = erofs_get_meta_page(inode->i_sb, erofs_blknr(pos)); - if (IS_ERR(page)) { - err = PTR_ERR(page); + kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP); + if (IS_ERR(kaddr)) { + err = PTR_ERR(kaddr); goto out; } map->m_la = chunknr << vi->chunkbits; @@ -135,7 +192,7 @@ static int erofs_map_blocks(struct inode *inode,
/* handle block map */ if (!(vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES)) { - __le32 *blkaddr = page_address(page) + erofs_blkoff(pos); + __le32 *blkaddr = kaddr + erofs_blkoff(pos);
if (le32_to_cpu(*blkaddr) == EROFS_NULL_ADDR) { map->m_flags = 0; @@ -146,7 +203,7 @@ static int erofs_map_blocks(struct inode *inode, goto out_unlock; } /* parse chunk indexes */ - idx = page_address(page) + erofs_blkoff(pos); + idx = kaddr + erofs_blkoff(pos); switch (le32_to_cpu(idx->blkaddr)) { case EROFS_NULL_ADDR: map->m_flags = 0; @@ -159,8 +216,7 @@ static int erofs_map_blocks(struct inode *inode, break; } out_unlock: - unlock_page(page); - put_page(page); + erofs_put_metabuf(&buf); out: if (!err) map->m_llen = map->m_plen; @@ -274,30 +330,25 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, /* deal with inline page */ if (map.m_flags & EROFS_MAP_META) { void *vsrc, *vto; - struct page *ipage; + struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
DBG_BUGON(map.m_plen > PAGE_SIZE);
- ipage = erofs_get_meta_page(sb, blknr); - - if (IS_ERR(ipage)) { - err = PTR_ERR(ipage); + vsrc = erofs_read_metabuf(&buf, inode->i_sb, + blknr, EROFS_KMAP_ATOMIC); + if (IS_ERR(vsrc)) { + err = PTR_ERR(vsrc); goto err_out; } - - vsrc = kmap_atomic(ipage); vto = kmap_atomic(page); memcpy(vto, vsrc + blkoff, map.m_plen); memset(vto + map.m_plen, 0, PAGE_SIZE - map.m_plen); kunmap_atomic(vto); - kunmap_atomic(vsrc); flush_dcache_page(page);
SetPageUptodate(page); - /* TODO: could we unlock the page earlier? */ - unlock_page(ipage); - put_page(ipage);
+ erofs_put_metabuf(&buf); /* imply err = 0, see erofs_map_blocks */ goto has_updated; } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 954a1cfb9509..ca6e127e1096 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -200,6 +200,19 @@ static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp) #error erofs cannot be used in this platform #endif
+enum erofs_kmap_type { + EROFS_NO_KMAP, /* don't map the buffer */ + EROFS_KMAP, /* use kmap() to map the buffer */ + EROFS_KMAP_ATOMIC, /* use kmap_atomic() to map the buffer */ +}; + +struct erofs_buf { + struct page *page; + void *base; + enum erofs_kmap_type kmap_type; +}; +#define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL }) + #define ROOT_NID(sb) ((sb)->root_nid)
#define erofs_blknr(addr) ((addr) / EROFS_BLKSIZ)