Skip to content

Commit 5ddcee1

Browse files
author
Gao Xiang
committed
erofs: get rid of __stagingpage_alloc helper
Now open code is much cleaner due to iterative development. Link: https://lore.kernel.org/r/20191124025217.12345-1-hsiangkao@aol.com Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
1 parent bda17a4 commit 5ddcee1

4 files changed

Lines changed: 21 additions & 24 deletions

File tree

‎fs/erofs/decompressor.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq,
7373
victim = availables[--top];
7474
get_page(victim);
7575
} else {
76-
victim = erofs_allocpage(pagepool, GFP_KERNEL, false);
76+
victim = erofs_allocpage(pagepool, GFP_KERNEL);
7777
if (!victim)
7878
return -ENOMEM;
7979
victim->mapping = Z_EROFS_MAPPING_STAGING;

‎fs/erofs/internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ int erofs_namei(struct inode *dir, struct qstr *name,
382382
extern const struct file_operations erofs_dir_fops;
383383

384384
/* utils.c / zdata.c */
385-
struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail);
385+
struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
386386

387387
#if (EROFS_PCPUBUF_NR_PAGES > 0)
388388
void *erofs_get_pcpubuf(unsigned int pagenr);

‎fs/erofs/utils.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "internal.h"
88
#include <linux/pagevec.h>
99

10-
struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail)
10+
struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp)
1111
{
1212
struct page *page;
1313

@@ -16,7 +16,7 @@ struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail)
1616
DBG_BUGON(page_ref_count(page) != 1);
1717
list_del(&page->lru);
1818
} else {
19-
page = alloc_pages(gfp | (nofail ? __GFP_NOFAIL : 0), 0);
19+
page = alloc_page(gfp);
2020
}
2121
return page;
2222
}

‎fs/erofs/zdata.c‎

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -546,15 +546,6 @@ static bool z_erofs_collector_end(struct z_erofs_collector *clt)
546546
return true;
547547
}
548548

549-
static inline struct page *__stagingpage_alloc(struct list_head *pagepool,
550-
gfp_t gfp)
551-
{
552-
struct page *page = erofs_allocpage(pagepool, gfp, true);
553-
554-
page->mapping = Z_EROFS_MAPPING_STAGING;
555-
return page;
556-
}
557-
558549
static bool should_alloc_managed_pages(struct z_erofs_decompress_frontend *fe,
559550
unsigned int cachestrategy,
560551
erofs_off_t la)
@@ -661,8 +652,9 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
661652
/* should allocate an additional staging page for pagevec */
662653
if (err == -EAGAIN) {
663654
struct page *const newpage =
664-
__stagingpage_alloc(pagepool, GFP_NOFS);
655+
erofs_allocpage(pagepool, GFP_NOFS | __GFP_NOFAIL);
665656

657+
newpage->mapping = Z_EROFS_MAPPING_STAGING;
666658
err = z_erofs_attach_page(clt, newpage,
667659
Z_EROFS_PAGE_TYPE_EXCLUSIVE);
668660
if (!err)
@@ -1079,19 +1071,24 @@ static struct page *pickup_page_for_submission(struct z_erofs_pcluster *pcl,
10791071
unlock_page(page);
10801072
put_page(page);
10811073
out_allocpage:
1082-
page = __stagingpage_alloc(pagepool, gfp);
1083-
if (oldpage != cmpxchg(&pcl->compressed_pages[nr], oldpage, page)) {
1084-
list_add(&page->lru, pagepool);
1085-
cpu_relax();
1086-
goto repeat;
1087-
}
1088-
if (!tocache)
1089-
goto out;
1090-
if (add_to_page_cache_lru(page, mc, index + nr, gfp)) {
1074+
page = erofs_allocpage(pagepool, gfp | __GFP_NOFAIL);
1075+
if (!tocache || add_to_page_cache_lru(page, mc, index + nr, gfp)) {
1076+
/* non-LRU / non-movable temporary page is needed */
10911077
page->mapping = Z_EROFS_MAPPING_STAGING;
1092-
goto out;
1078+
tocache = false;
10931079
}
10941080

1081+
if (oldpage != cmpxchg(&pcl->compressed_pages[nr], oldpage, page)) {
1082+
if (tocache) {
1083+
/* since it added to managed cache successfully */
1084+
unlock_page(page);
1085+
put_page(page);
1086+
} else {
1087+
list_add(&page->lru, pagepool);
1088+
}
1089+
cond_resched();
1090+
goto repeat;
1091+
}
10951092
set_page_private(page, (unsigned long)pcl);
10961093
SetPagePrivate(page);
10971094
out: /* the only exit (for tracing and debugging) */

0 commit comments

Comments
 (0)