Commit b25a1519 authored by Gao Xiang's avatar Gao Xiang Committed by Greg Kroah-Hartman

staging: erofs: refine erofs_allocpage()

remove duplicated code in decompressor by introducing
failable erofs_allocpage().
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarGao Xiang <gaoxiang25@huawei.com>
Link: https://lore.kernel.org/r/20190731155752.210602-14-gaoxiang25@huawei.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8494c29f
...@@ -74,15 +74,9 @@ static int lz4_prepare_destpages(struct z_erofs_decompress_req *rq, ...@@ -74,15 +74,9 @@ static int lz4_prepare_destpages(struct z_erofs_decompress_req *rq,
victim = availables[--top]; victim = availables[--top];
get_page(victim); get_page(victim);
} else { } else {
if (!list_empty(pagepool)) { victim = erofs_allocpage(pagepool, GFP_KERNEL, false);
victim = lru_to_page(pagepool); if (unlikely(!victim))
list_del(&victim->lru); return -ENOMEM;
DBG_BUGON(page_ref_count(victim) != 1);
} else {
victim = alloc_pages(GFP_KERNEL, 0);
if (!victim)
return -ENOMEM;
}
victim->mapping = Z_EROFS_MAPPING_STAGING; victim->mapping = Z_EROFS_MAPPING_STAGING;
} }
rq->out[i] = victim; rq->out[i] = victim;
......
...@@ -516,7 +516,7 @@ int erofs_namei(struct inode *dir, struct qstr *name, ...@@ -516,7 +516,7 @@ int erofs_namei(struct inode *dir, struct qstr *name,
extern const struct file_operations erofs_dir_fops; extern const struct file_operations erofs_dir_fops;
/* utils.c / zdata.c */ /* utils.c / zdata.c */
struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp); struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail);
#if (EROFS_PCPUBUF_NR_PAGES > 0) #if (EROFS_PCPUBUF_NR_PAGES > 0)
void *erofs_get_pcpubuf(unsigned int pagenr); void *erofs_get_pcpubuf(unsigned int pagenr);
......
...@@ -9,15 +9,16 @@ ...@@ -9,15 +9,16 @@
#include "internal.h" #include "internal.h"
#include <linux/pagevec.h> #include <linux/pagevec.h>
struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp) struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail)
{ {
struct page *page; struct page *page;
if (!list_empty(pool)) { if (!list_empty(pool)) {
page = lru_to_page(pool); page = lru_to_page(pool);
DBG_BUGON(page_ref_count(page) != 1);
list_del(&page->lru); list_del(&page->lru);
} else { } else {
page = alloc_pages(gfp | __GFP_NOFAIL, 0); page = alloc_pages(gfp | (nofail ? __GFP_NOFAIL : 0), 0);
} }
return page; return page;
} }
......
...@@ -634,10 +634,7 @@ z_erofs_vle_work_iter_end(struct z_erofs_vle_work_builder *builder) ...@@ -634,10 +634,7 @@ z_erofs_vle_work_iter_end(struct z_erofs_vle_work_builder *builder)
static inline struct page *__stagingpage_alloc(struct list_head *pagepool, static inline struct page *__stagingpage_alloc(struct list_head *pagepool,
gfp_t gfp) gfp_t gfp)
{ {
struct page *page = erofs_allocpage(pagepool, gfp); struct page *page = erofs_allocpage(pagepool, gfp, true);
if (unlikely(!page))
return NULL;
page->mapping = Z_EROFS_MAPPING_STAGING; page->mapping = Z_EROFS_MAPPING_STAGING;
return page; return page;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment