summaryrefslogtreecommitdiffstats
path: root/fs/erofs/zpvec.h
diff options
context:
space:
mode:
authorGao Xiang <hsiangkao@aol.com>2019-08-22 17:36:59 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-08-24 08:20:10 -0400
commit47e4937a4a7ca4184fd282791dfee76c6799966a (patch)
treefc68338c13a00ac74ac9f1a838491bd3f7649c28 /fs/erofs/zpvec.h
parentf401441deda68326852560bf70d59e95f585bbb3 (diff)
erofs: move erofs out of staging
EROFS filesystem has been merged into linux-staging for a year. EROFS is designed to be a better solution of saving extra storage space with guaranteed end-to-end performance for read-only files with the help of reduced metadata, fixed-sized output compression and decompression inplace technologies. In the past year, EROFS was greatly improved by many people as a staging driver, self-tested, betaed by a large number of our internal users, successfully applied to almost all in-service HUAWEI smartphones as the part of EMUI 9.1 and proven to be stable enough to be moved out of staging. EROFS is a self-contained filesystem driver. Although there are still some TODOs to be more generic, we have a dedicated team actively keeping on working on EROFS in order to make it better with the evolution of Linux kernel as the other in-kernel filesystems. As Pavel suggested, it's better to do as one commit since git can do moves and all histories will be saved in this way. Let's promote it from staging and enhance it more actively as a "real" part of kernel for more wider scenarios! Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Theodore Ts'o <tytso@mit.edu> Cc: Pavel Machek <pavel@denx.de> Cc: David Sterba <dsterba@suse.cz> Cc: Amir Goldstein <amir73il@gmail.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: Darrick J . Wong <darrick.wong@oracle.com> Cc: Dave Chinner <david@fromorbit.com> Cc: Jaegeuk Kim <jaegeuk@kernel.org> Cc: Jan Kara <jack@suse.cz> Cc: Richard Weinberger <richard@nod.at> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Chao Yu <yuchao0@huawei.com> Cc: Miao Xie <miaoxie@huawei.com> Cc: Li Guifu <bluce.liguifu@huawei.com> Cc: Fang Wei <fangwei1@huawei.com> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com> Link: https://lore.kernel.org/r/20190822213659.5501-1-hsiangkao@aol.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/erofs/zpvec.h')
-rw-r--r--fs/erofs/zpvec.h157
1 files changed, 157 insertions, 0 deletions
diff --git a/fs/erofs/zpvec.h b/fs/erofs/zpvec.h
new file mode 100644
index 000000000000..bd3cee16491c
--- /dev/null
+++ b/fs/erofs/zpvec.h
@@ -0,0 +1,157 @@
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2018 HUAWEI, Inc.
4 * http://www.huawei.com/
5 * Created by Gao Xiang <gaoxiang25@huawei.com>
6 */
7#ifndef __EROFS_FS_ZPVEC_H
8#define __EROFS_FS_ZPVEC_H
9
10#include "tagptr.h"
11
12/* page type in pagevec for decompress subsystem */
13enum z_erofs_page_type {
14 /* including Z_EROFS_VLE_PAGE_TAIL_EXCLUSIVE */
15 Z_EROFS_PAGE_TYPE_EXCLUSIVE,
16
17 Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED,
18
19 Z_EROFS_VLE_PAGE_TYPE_HEAD,
20 Z_EROFS_VLE_PAGE_TYPE_MAX
21};
22
23extern void __compiletime_error("Z_EROFS_PAGE_TYPE_EXCLUSIVE != 0")
24 __bad_page_type_exclusive(void);
25
26/* pagevec tagged pointer */
27typedef tagptr2_t erofs_vtptr_t;
28
29/* pagevec collector */
30struct z_erofs_pagevec_ctor {
31 struct page *curr, *next;
32 erofs_vtptr_t *pages;
33
34 unsigned int nr, index;
35};
36
37static inline void z_erofs_pagevec_ctor_exit(struct z_erofs_pagevec_ctor *ctor,
38 bool atomic)
39{
40 if (!ctor->curr)
41 return;
42
43 if (atomic)
44 kunmap_atomic(ctor->pages);
45 else
46 kunmap(ctor->curr);
47}
48
49static inline struct page *
50z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor,
51 unsigned int nr)
52{
53 unsigned int index;
54
55 /* keep away from occupied pages */
56 if (ctor->next)
57 return ctor->next;
58
59 for (index = 0; index < nr; ++index) {
60 const erofs_vtptr_t t = ctor->pages[index];
61 const unsigned int tags = tagptr_unfold_tags(t);
62
63 if (tags == Z_EROFS_PAGE_TYPE_EXCLUSIVE)
64 return tagptr_unfold_ptr(t);
65 }
66 DBG_BUGON(nr >= ctor->nr);
67 return NULL;
68}
69
70static inline void
71z_erofs_pagevec_ctor_pagedown(struct z_erofs_pagevec_ctor *ctor,
72 bool atomic)
73{
74 struct page *next = z_erofs_pagevec_ctor_next_page(ctor, ctor->nr);
75
76 z_erofs_pagevec_ctor_exit(ctor, atomic);
77
78 ctor->curr = next;
79 ctor->next = NULL;
80 ctor->pages = atomic ?
81 kmap_atomic(ctor->curr) : kmap(ctor->curr);
82
83 ctor->nr = PAGE_SIZE / sizeof(struct page *);
84 ctor->index = 0;
85}
86
87static inline void z_erofs_pagevec_ctor_init(struct z_erofs_pagevec_ctor *ctor,
88 unsigned int nr,
89 erofs_vtptr_t *pages,
90 unsigned int i)
91{
92 ctor->nr = nr;
93 ctor->curr = ctor->next = NULL;
94 ctor->pages = pages;
95
96 if (i >= nr) {
97 i -= nr;
98 z_erofs_pagevec_ctor_pagedown(ctor, false);
99 while (i > ctor->nr) {
100 i -= ctor->nr;
101 z_erofs_pagevec_ctor_pagedown(ctor, false);
102 }
103 }
104 ctor->next = z_erofs_pagevec_ctor_next_page(ctor, i);
105 ctor->index = i;
106}
107
108static inline bool z_erofs_pagevec_enqueue(struct z_erofs_pagevec_ctor *ctor,
109 struct page *page,
110 enum z_erofs_page_type type,
111 bool *occupied)
112{
113 *occupied = false;
114 if (unlikely(!ctor->next && type))
115 if (ctor->index + 1 == ctor->nr)
116 return false;
117
118 if (unlikely(ctor->index >= ctor->nr))
119 z_erofs_pagevec_ctor_pagedown(ctor, false);
120
121 /* exclusive page type must be 0 */
122 if (Z_EROFS_PAGE_TYPE_EXCLUSIVE != (uintptr_t)NULL)
123 __bad_page_type_exclusive();
124
125 /* should remind that collector->next never equal to 1, 2 */
126 if (type == (uintptr_t)ctor->next) {
127 ctor->next = page;
128 *occupied = true;
129 }
130 ctor->pages[ctor->index++] = tagptr_fold(erofs_vtptr_t, page, type);
131 return true;
132}
133
134static inline struct page *
135z_erofs_pagevec_dequeue(struct z_erofs_pagevec_ctor *ctor,
136 enum z_erofs_page_type *type)
137{
138 erofs_vtptr_t t;
139
140 if (unlikely(ctor->index >= ctor->nr)) {
141 DBG_BUGON(!ctor->next);
142 z_erofs_pagevec_ctor_pagedown(ctor, true);
143 }
144
145 t = ctor->pages[ctor->index];
146
147 *type = tagptr_unfold_tags(t);
148
149 /* should remind that collector->next never equal to 1, 2 */
150 if (*type == (uintptr_t)ctor->next)
151 ctor->next = tagptr_unfold_ptr(t);
152
153 ctor->pages[ctor->index++] = tagptr_fold(erofs_vtptr_t, NULL, 0);
154 return tagptr_unfold_ptr(t);
155}
156#endif
157