erofs: get rid of ->lru usage
PATCH 1/1 erofs: get rid of ->lru usage
Currently, ->lru is a way to arrange non-LRU pages and has some in-kernel users. In order to minimize noticable issues of page reclaim and cache thrashing under high memory presure, limited temporary pages were all chained with ->lru and can be reused during the request. However, it seems that ->lru could be removed when folio is landing.
Let's use page->private to chain temporary pages for now instead and transform EROFS formally after the topic of the folio / file page design is finalized.
--- fs/erofs/compress.h | 11 +++++----- fs/erofs/decompressor.c | 8 +++---- fs/erofs/decompressor_lzma.c | 2 +- fs/erofs/internal.h | 9 +++++++- fs/erofs/pcpubuf.c | 6 +++--- fs/erofs/utils.c | 19 +++++++++++----- fs/erofs/zdata.c | 42 ++++++++++++++++-------------------- 7 files changed, 53 insertions(+), 44 deletions(-)
fs/erofs/compress.h +5 -6
@@ -22,7 +22,7 @@ struct z_erofs_decompress_req {struct z_erofs_decompressor {int (*decompress)(struct z_erofs_decompress_req *rq, -struct list_head *pagepool); +struct page **pagepool);char *name; };
@@ -64,7 +64,7 @@ static inline bool z_erofs_is_shortlived_page(struct page *page)return true; } -static inline bool z_erofs_put_shortlivedpage (struct list_head *pagepool, +static inline bool z_erofs_put_shortlivedpage (struct page **pagepool,struct page *page) {if (!z_erofs_is_shortlived_page (page))
@@ -75,8 +75,7 @@ static inline bool z_erofs_put_shortlivedpage(struct list_head *pagepool,put_page (page); }else {/* follow the pcluster rule above. */ -set_page_private (page,0 ); -list_add (&page->lru, pagepool); +erofs_pagepool_add (pagepool, page); }return true; }
@@ -89,9 +88,9 @@ static inline bool erofs_page_is_managed(const struct erofs_sb_info *sbi, }int z_erofs_decompress (struct z_erofs_decompress_req *rq, -struct list_head *pagepool); +struct page **pagepool);/* prototypes for specific algorithms */ int z_erofs_lzma_decompress (struct z_erofs_decompress_req *rq, -struct list_head *pagepool); +struct page **pagepool);#endif
fs/erofs/decompressor.c +4 -4
@@ -57,7 +57,7 @@ int z_erofs_load_lz4_config(struct super_block *sb,* all physical pages are consecutive, which can be seen for moderate CR. */ static int z_erofs_lz4_prepare_dstpages (struct z_erofs_decompress_req *rq, -struct list_head *pagepool) +struct page **pagepool) {const unsigned int nr =PAGE_ALIGN (rq->pageofs_out + rq->outputsize) >>PAGE_SHIFT ;
@@ -254,7 +254,7 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, }static int z_erofs_lz4_decompress (struct z_erofs_decompress_req *rq, -struct list_head *pagepool) +struct page **pagepool) {const unsigned int nrpages_out =PAGE_ALIGN (rq->pageofs_out + rq->outputsize) >>PAGE_SHIFT ;
@@ -296,7 +296,7 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, }static int z_erofs_shifted_transform (struct z_erofs_decompress_req *rq, -struct list_head *pagepool) +struct page **pagepool) {const unsigned int nrpages_out =PAGE_ALIGN (rq->pageofs_out + rq->outputsize) >>PAGE_SHIFT ;
@@ -352,7 +352,7 @@ static struct z_erofs_decompressor decompressors[] = { };int z_erofs_decompress (struct z_erofs_decompress_req *rq, -struct list_head *pagepool) +struct page **pagepool) {return decompressors[rq->alg].decompress (rq, pagepool); }
fs/erofs/decompressor_lzma.c +1 -1
@@ -150,7 +150,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }int z_erofs_lzma_decompress (struct z_erofs_decompress_req *rq, -struct list_head *pagepool) +struct page **pagepool) {const unsigned int nrpages_out =PAGE_ALIGN (rq->pageofs_out + rq->outputsize) >>PAGE_SHIFT ;
fs/erofs/internal.h +8 -1
@@ -499,7 +499,14 @@ void erofs_pcpubuf_init(void);void erofs_pcpubuf_exit (void );/* utils.c / zdata.c */ -struct page *erofs_allocpage (struct list_head *pool,gfp_t gfp); +struct page *erofs_allocpage (struct page **pagepool,gfp_t gfp); +static inline void erofs_pagepool_add (struct page **pagepool, +struct page *page) +{ +set_page_private (page, (unsigned long )*pagepool); + *pagepool = page; +} +void erofs_release_pages (struct page **pagepool);#ifdef CONFIG_EROFS_FS_ZIP int erofs_workgroup_put (struct erofs_workgroup *grp);
fs/erofs/pcpubuf.c +3 -3
@@ -49,7 +49,7 @@ int erofs_pcpubuf_growsize(unsigned int nrpages) {static DEFINE_MUTEX (pcb_resize_mutex);static unsigned int pcb_nrpages; -LIST_HEAD (pagepool); +struct page *pagepool =NULL ;int delta, cpu, ret, i;mutex_lock (&pcb_resize_mutex);
@@ -102,13 +102,13 @@ int erofs_pcpubuf_growsize(unsigned int nrpages)vunmap (old_ptr); free_pagearray:while (i) -list_add (&oldpages[--i]->lru, &pagepool); +erofs_pagepool_add (&pagepool, oldpages[--i]);kfree (oldpages);if (ret)break ; } pcb_nrpages = nrpages; -put_pages_list (&pagepool); +erofs_release_pages (&pagepool); out:mutex_unlock (&pcb_resize_mutex);return ret;
fs/erofs/utils.c +14 -5
@@ -6,20 +6,29 @@#include "internal.h" #include <linux/pagevec.h> -struct page *erofs_allocpage (struct list_head *pool,gfp_t gfp) +struct page *erofs_allocpage (struct page **pagepool,gfp_t gfp) { -struct page *page; +struct page *page = *pagepool; -if (!list_empty (pool)) { - page =lru_to_page (pool); +if (page) {DBG_BUGON (page_ref_count (page) !=1 ); -list_del (&page->lru); + *pagepool = (struct page *)page_private (page); }else { page =alloc_page (gfp); }return page; } +void erofs_release_pages (struct page **pagepool) +{ +while (*pagepool) { +struct page *page = *pagepool; + + *pagepool = (struct page *)page_private (page); +put_page (page); + } +} +#ifdef CONFIG_EROFS_FS_ZIP /* global shrink count (for all mounted EROFS instances) */ static atomic_long_t erofs_global_shrink_cnt;
fs/erofs/zdata.c +18 -24
138 lines not on this page · raw message
Signature · 1 line
2.24.4
Quoted 7 lines · Gao Xiang
Currently, ->lru is a way to arrange non-LRU pages and has some in-kernel users. In order to minimize noticable issues of page reclaim and cache thrashing under high memory presure, limited temporary pages were all chained with ->lru and can be reused during the request. However, it seems that ->lru could be removed when folio is landing.
Quoted 8 lines
Let's use
page->privateto chain temporary pages for now instead and transform EROFS formally after the topic of the folio / file page design is finalized.Cc Matthew Wilcox <[email protected]>Cc Kent Overstreet <[email protected]>Cc Chao Yu <[email protected]>Signed-off-by Gao Xiang <[email protected]>
Thanks,
Quoted 7 lines · Gao Xiang
Currently, ->lru is a way to arrange non-LRU pages and has some in-kernel users. In order to minimize noticable issues of page reclaim and cache thrashing under high memory presure, limited temporary pages were all chained with ->lru and can be reused during the request. However, it seems that ->lru could be removed when folio is landing.
Quoted 8 lines
Let's use
page->privateto chain temporary pages for now instead and transform EROFS formally after the topic of the folio / file page design is finalized.Cc Matthew Wilcox <[email protected]>Cc Kent Overstreet <[email protected]>Cc Chao Yu <[email protected]>Signed-off-by Gao Xiang <[email protected]>
Would it not be an option to use an array of pointers to pages, instead of a linked list? Arrays are faster than lists, and page->private is another thing we prefer not to use if we don't have to.
That said - this is definitely preferable to using page->lru - thank you.
Quoted 12 lines · Kent Overstreet
Quoted 11 lines · Gao Xiang
Currently, ->lru is a way to arrange non-LRU pages and has some in-kernel users. In order to minimize noticable issues of page reclaim and cache thrashing under high memory presure, limited temporary pages were all chained with ->lru and can be reused during the request. However, it seems that ->lru could be removed when folio is landing.
Let's use
page->privateto chain temporary pages for now instead and transform EROFS formally after the topic of the folio / file page design is finalized.
Quoted 8 lines
Quoted 4 lines
Cc Matthew Wilcox <[email protected]>Cc Kent Overstreet <[email protected]>Cc Chao Yu <[email protected]>Signed-off-by Gao Xiang <[email protected]>Would it not be an option to use an array of pointers to pages, instead of a linked list? Arrays are faster than lists, and
page->privateis another thing we prefer not to use if we don't have to.
Our requirement is to maintain variable-sized temporary pages, that may be short or maybe long during decompression process (according to different algorithms and whether it's inplace I/O or not) rather than before I/O submission:
For LZ4, that maybe 16 pages for lz4 sliding window and other
temporary pages;
For LZMA, since it has a internal dictionary (sliding window) so we
don't have to allocate any temporary pages for cached decompression (outplace I/O), but we still need allocating temporary pages to handle overlapped decompression due to inplace I/O (think about it, if each compressed pcluster is 4pages -- 16KiB, we have to allocate for example another 128KiB compressed pages due to read request for outplace I/O, but instead 0 pages for inplace I/O during I/O process, and only 4 pages for decompression process. It saves much memory in the low memory scenarios by using inplace I/O and important to the performance).
Currently we only add some page to the head or pick some page from head, so a singly-linked list is also fine to us for now.
Quoted 4 lines
That said - this is definitely preferable to using
page->lru- thank you.Reviewed-by Kent Overstreet <[email protected]>
Thank you!
Thanks,
Gao Xiang