diff options
author | Gao Xiang <gaoxiang25@huawei.com> | 2018-07-26 08:21:59 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-07-27 11:24:08 -0400 |
commit | b29e64d8798018c3e82a426ec34b39b825ac68dc (patch) | |
tree | 3dfecc4d2b2bb5a72bbe31659b4ea65f2385ddab | |
parent | 02827e1796b33f1794966f5c3101f8da2dfa9c1d (diff) |
staging: erofs: add erofs_allocpage
This patch introduces an temporary _on-stack_ page
pool to reuse the freed page directly as much as
it can for better performance and release all pages
at a time, it also slightly reduces the possibility of
the potential memory allocation failure.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/erofs/Makefile | 2 | ||||
-rw-r--r-- | drivers/staging/erofs/internal.h | 7 | ||||
-rw-r--r-- | drivers/staging/erofs/utils.c | 31 |
3 files changed, 39 insertions, 1 deletions
diff --git a/drivers/staging/erofs/Makefile b/drivers/staging/erofs/Makefile index 8558c761a74b..490fa6cced08 100644 --- a/drivers/staging/erofs/Makefile +++ b/drivers/staging/erofs/Makefile | |||
@@ -7,7 +7,7 @@ ccflags-y += -Wall -DEROFS_VERSION=\"$(EROFS_VERSION)\" | |||
7 | obj-$(CONFIG_EROFS_FS) += erofs.o | 7 | obj-$(CONFIG_EROFS_FS) += erofs.o |
8 | # staging requirement: to be self-contained in its own directory | 8 | # staging requirement: to be self-contained in its own directory |
9 | ccflags-y += -I$(src)/include | 9 | ccflags-y += -I$(src)/include |
10 | erofs-objs := super.o inode.o data.o namei.o dir.o | 10 | erofs-objs := super.o inode.o data.o namei.o dir.o utils.o |
11 | erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o | 11 | erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o |
12 | erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o | 12 | erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o |
13 | 13 | ||
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h index bea5ec458707..210ab6c64df8 100644 --- a/drivers/staging/erofs/internal.h +++ b/drivers/staging/erofs/internal.h | |||
@@ -369,5 +369,12 @@ static inline void erofs_vunmap(const void *mem, unsigned int count) | |||
369 | #endif | 369 | #endif |
370 | } | 370 | } |
371 | 371 | ||
372 | /* utils.c */ | ||
373 | extern struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp); | ||
374 | |||
375 | #ifndef lru_to_page | ||
376 | #define lru_to_page(head) (list_entry((head)->prev, struct page, lru)) | ||
377 | #endif | ||
378 | |||
372 | #endif | 379 | #endif |
373 | 380 | ||
diff --git a/drivers/staging/erofs/utils.c b/drivers/staging/erofs/utils.c new file mode 100644 index 000000000000..3dec4f80ed99 --- /dev/null +++ b/drivers/staging/erofs/utils.c | |||
@@ -0,0 +1,31 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | /* | ||
3 | * linux/drivers/staging/erofs/utils.c | ||
4 | * | ||
5 | * Copyright (C) 2018 HUAWEI, Inc. | ||
6 | * http://www.huawei.com/ | ||
7 | * Created by Gao Xiang <gaoxiang25@huawei.com> | ||
8 | * | ||
9 | * This file is subject to the terms and conditions of the GNU General Public | ||
10 | * License. See the file COPYING in the main directory of the Linux | ||
11 | * distribution for more details. | ||
12 | */ | ||
13 | |||
14 | #include "internal.h" | ||
15 | |||
16 | struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp) | ||
17 | { | ||
18 | struct page *page; | ||
19 | |||
20 | if (!list_empty(pool)) { | ||
21 | page = lru_to_page(pool); | ||
22 | list_del(&page->lru); | ||
23 | } else { | ||
24 | page = alloc_pages(gfp | __GFP_NOFAIL, 0); | ||
25 | |||
26 | BUG_ON(page == NULL); | ||
27 | BUG_ON(page->mapping != NULL); | ||
28 | } | ||
29 | return page; | ||
30 | } | ||
31 | |||