linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gao Xiang <gaoxiang25@huawei.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Chao Yu <yuchao0@huawei.com>, <devel@driverdev.osuosl.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	<linux-erofs@lists.ozlabs.org>, "Chao Yu" <chao@kernel.org>,
	Miao Xie <miaoxie@huawei.com>, <weidu.du@huawei.com>,
	Fang Wei <fangwei1@huawei.com>, Gao Xiang <gaoxiang25@huawei.com>
Subject: [PATCH v2 13/22] staging: erofs: refine erofs_allocpage()
Date: Wed, 31 Jul 2019 23:57:43 +0800	[thread overview]
Message-ID: <20190731155752.210602-14-gaoxiang25@huawei.com> (raw)
In-Reply-To: <20190731155752.210602-1-gaoxiang25@huawei.com>

remove duplicated code in decompressor by introducing
failable erofs_allocpage().

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
 drivers/staging/erofs/decompressor.c | 12 +++---------
 drivers/staging/erofs/internal.h     |  2 +-
 drivers/staging/erofs/utils.c        |  5 +++--
 drivers/staging/erofs/zdata.c        |  5 +----
 4 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/erofs/decompressor.c b/drivers/staging/erofs/decompressor.c
index ee5762351f80..744c43a456e9 100644
--- a/drivers/staging/erofs/decompressor.c
+++ b/drivers/staging/erofs/decompressor.c
@@ -74,15 +74,9 @@ static int lz4_prepare_destpages(struct z_erofs_decompress_req *rq,
 			victim = availables[--top];
 			get_page(victim);
 		} else {
-			if (!list_empty(pagepool)) {
-				victim = lru_to_page(pagepool);
-				list_del(&victim->lru);
-				DBG_BUGON(page_ref_count(victim) != 1);
-			} else {
-				victim = alloc_pages(GFP_KERNEL, 0);
-				if (!victim)
-					return -ENOMEM;
-			}
+			victim = erofs_allocpage(pagepool, GFP_KERNEL, false);
+			if (unlikely(!victim))
+				return -ENOMEM;
 			victim->mapping = Z_EROFS_MAPPING_STAGING;
 		}
 		rq->out[i] = victim;
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 5e1ef2b5a458..a631acd0dc62 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -516,7 +516,7 @@ int erofs_namei(struct inode *dir, struct qstr *name,
 extern const struct file_operations erofs_dir_fops;
 
 /* 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)
 void *erofs_get_pcpubuf(unsigned int pagenr);
diff --git a/drivers/staging/erofs/utils.c b/drivers/staging/erofs/utils.c
index 0e86e44d60d0..260ea2970b4b 100644
--- a/drivers/staging/erofs/utils.c
+++ b/drivers/staging/erofs/utils.c
@@ -9,15 +9,16 @@
 #include "internal.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;
 
 	if (!list_empty(pool)) {
 		page = lru_to_page(pool);
+		DBG_BUGON(page_ref_count(page) != 1);
 		list_del(&page->lru);
 	} else {
-		page = alloc_pages(gfp | __GFP_NOFAIL, 0);
+		page = alloc_pages(gfp | (nofail ? __GFP_NOFAIL : 0), 0);
 	}
 	return page;
 }
diff --git a/drivers/staging/erofs/zdata.c b/drivers/staging/erofs/zdata.c
index bc478eebf509..3078510e350d 100644
--- a/drivers/staging/erofs/zdata.c
+++ b/drivers/staging/erofs/zdata.c
@@ -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,
 					       gfp_t gfp)
 {
-	struct page *page = erofs_allocpage(pagepool, gfp);
-
-	if (unlikely(!page))
-		return NULL;
+	struct page *page = erofs_allocpage(pagepool, gfp, true);
 
 	page->mapping = Z_EROFS_MAPPING_STAGING;
 	return page;
-- 
2.17.1


  parent reply	other threads:[~2019-07-31 15:58 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-31 15:57 [PATCH v2 00/22] staging: erofs: updates according to erofs-outofstaging v4 Gao Xiang
2019-07-31 15:57 ` [PATCH v2 01/22] staging: erofs: update source file headers Gao Xiang
2019-07-31 15:57 ` [PATCH v2 02/22] staging: erofs: rename source files for better understanding Gao Xiang
2019-07-31 15:57 ` [PATCH v2 03/22] staging: erofs: fix dummy functions erofs_{get,list}xattr Gao Xiang
2019-07-31 15:57 ` [PATCH v2 04/22] staging: erofs: keep up erofs_fs.h with erofs-outofstaging patchset Gao Xiang
2019-07-31 15:57 ` [PATCH v2 05/22] staging: erofs: sunset erofs_workstn_{lock,unlock} Gao Xiang
2019-07-31 15:57 ` [PATCH v2 06/22] staging: erofs: clean up internal.h Gao Xiang
2019-07-31 15:57 ` [PATCH v2 07/22] staging: erofs: remove redundant #include "internal.h" Gao Xiang
2019-08-01  1:32   ` Chao Yu
2019-07-31 15:57 ` [PATCH v2 08/22] staging: erofs: kill CONFIG_EROFS_FS_IO_MAX_RETRIES Gao Xiang
2019-08-01  1:33   ` Chao Yu
2019-07-31 15:57 ` [PATCH v2 09/22] staging: erofs: clean up shrinker stuffs Gao Xiang
2019-07-31 15:57 ` [PATCH v2 10/22] staging: erofs: kill sbi->dev_name Gao Xiang
2019-07-31 15:57 ` [PATCH v2 11/22] staging: erofs: kill all failure handling in fill_super() Gao Xiang
2019-07-31 15:57 ` [PATCH v2 12/22] staging: erofs: drop __GFP_NOFAIL for managed inode Gao Xiang
2019-08-01  1:39   ` Chao Yu
2019-07-31 15:57 ` Gao Xiang [this message]
2019-07-31 15:57 ` [PATCH v2 14/22] staging: erofs: kill CONFIG_EROFS_FS_USE_VM_MAP_RAM Gao Xiang
2019-07-31 15:57 ` [PATCH v2 15/22] staging: erofs: tidy up zpvec.h Gao Xiang
2019-07-31 15:57 ` [PATCH v2 16/22] staging: erofs: remove redundant braces in inode.c Gao Xiang
2019-07-31 15:57 ` [PATCH v2 17/22] staging: erofs: tidy up decompression frontend Gao Xiang
2019-07-31 15:57 ` [PATCH v2 18/22] staging: erofs: remove clusterbits in sbi Gao Xiang
2019-07-31 15:57 ` [PATCH v2 19/22] staging: erofs: turn cache strategies into mount options Gao Xiang
2019-07-31 15:57 ` [PATCH v2 20/22] staging: erofs: tidy up utils.c Gao Xiang
2019-07-31 15:57 ` [PATCH v2 21/22] staging: erofs: update super.c Gao Xiang
2019-07-31 15:57 ` [PATCH v2 22/22] staging: erofs: update Kconfig Gao Xiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190731155752.210602-14-gaoxiang25@huawei.com \
    --to=gaoxiang25@huawei.com \
    --cc=chao@kernel.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=fangwei1@huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miaoxie@huawei.com \
    --cc=weidu.du@huawei.com \
    --cc=yuchao0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).