Skip to content

Commit

Permalink
Merge tag 'erofs-for-5.11-rc1' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/xiang/erofs

Pull erofs updates from Gao Xiang:
 "This cycle we got rid of magical page->mapping type marks for
  temporary pages which had some concern before, now such usage is
  replaced with specific page->private.

  Also switch to inplace I/O instead of allocating extra cached pages to
  avoid direct reclaim under low memory scenario.

  There are some bmap bugfix and minor cleanups as well"

* tag 'erofs-for-5.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs:
  erofs: avoid using generic_block_bmap
  erofs: force inplace I/O under low memory scenario
  erofs: simplify try_to_claim_pcluster()
  erofs: insert to managed cache after adding to pcl
  erofs: get rid of magical Z_EROFS_MAPPING_STAGING
  erofs: remove a void EROFS_VERSION macro set in Makefile
  • Loading branch information
Linus Torvalds committed Dec 16, 2020
2 parents 1a50ede + d8b3df8 commit e88bd82
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 111 deletions.
5 changes: 0 additions & 5 deletions fs/erofs/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only

EROFS_VERSION = "1.0"

ccflags-y += -DEROFS_VERSION=\"$(EROFS_VERSION)\"

obj-$(CONFIG_EROFS_FS) += erofs.o
erofs-objs := super.o inode.o data.o namei.o dir.o utils.o
erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o

54 changes: 41 additions & 13 deletions fs/erofs/compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,58 @@ struct z_erofs_decompress_req {
bool inplace_io, partial_decoding;
};

/* some special page->private (unsigned long, see below) */
#define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2)
#define Z_EROFS_PREALLOCATED_PAGE (-2UL << 2)

/*
* - 0x5A110C8D ('sallocated', Z_EROFS_MAPPING_STAGING) -
* used to mark temporary allocated pages from other
* file/cached pages and NULL mapping pages.
* For all pages in a pcluster, page->private should be one of
* Type Last 2bits page->private
* short-lived page 00 Z_EROFS_SHORTLIVED_PAGE
* preallocated page (tryalloc) 00 Z_EROFS_PREALLOCATED_PAGE
* cached/managed page 00 pointer to z_erofs_pcluster
* online page (file-backed, 01/10/11 sub-index << 2 | count
* some pages can be used for inplace I/O)
*
* page->mapping should be one of
* Type page->mapping
* short-lived page NULL
* preallocated page NULL
* cached/managed page non-NULL or NULL (invalidated/truncated page)
* online page non-NULL
*
* For all managed pages, PG_private should be set with 1 extra refcount,
* which is used for page reclaim / migration.
*/
#define Z_EROFS_MAPPING_STAGING ((void *)0x5A110C8D)

/* check if a page is marked as staging */
static inline bool z_erofs_page_is_staging(struct page *page)
/*
* short-lived pages are pages directly from buddy system with specific
* page->private (no need to set PagePrivate since these are non-LRU /
* non-movable pages and bypass reclaim / migration code).
*/
static inline bool z_erofs_is_shortlived_page(struct page *page)
{
return page->mapping == Z_EROFS_MAPPING_STAGING;
if (page->private != Z_EROFS_SHORTLIVED_PAGE)
return false;

DBG_BUGON(page->mapping);
return true;
}

static inline bool z_erofs_put_stagingpage(struct list_head *pagepool,
struct page *page)
static inline bool z_erofs_put_shortlivedpage(struct list_head *pagepool,
struct page *page)
{
if (!z_erofs_page_is_staging(page))
if (!z_erofs_is_shortlived_page(page))
return false;

/* staging pages should not be used by others at the same time */
if (page_ref_count(page) > 1)
/* short-lived pages should not be used by others at the same time */
if (page_ref_count(page) > 1) {
put_page(page);
else
} else {
/* follow the pcluster rule above. */
set_page_private(page, 0);
list_add(&page->lru, pagepool);
}
return true;
}

Expand Down
26 changes: 7 additions & 19 deletions fs/erofs/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,27 +312,12 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
submit_bio(bio);
}

static int erofs_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *bh, int create)
{
struct erofs_map_blocks map = {
.m_la = iblock << 9,
};
int err;

err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
if (err)
return err;

if (map.m_flags & EROFS_MAP_MAPPED)
bh->b_blocknr = erofs_blknr(map.m_pa);

return err;
}

static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
{
struct inode *inode = mapping->host;
struct erofs_map_blocks map = {
.m_la = blknr_to_addr(block),
};

if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
Expand All @@ -341,7 +326,10 @@ static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
return 0;
}

return generic_block_bmap(mapping, block, erofs_get_block);
if (!erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW))
return erofs_blknr(map.m_pa);

return 0;
}

/* for uncompressed (aligned) files and raw access for other files */
Expand Down
2 changes: 1 addition & 1 deletion fs/erofs/decompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq,
victim = erofs_allocpage(pagepool, GFP_KERNEL);
if (!victim)
return -ENOMEM;
victim->mapping = Z_EROFS_MAPPING_STAGING;
set_page_private(victim, Z_EROFS_SHORTLIVED_PAGE);
}
rq->out[i] = victim;
}
Expand Down
Loading

0 comments on commit e88bd82

Please sign in to comment.