Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit dcb9f48

Browse files
committed
Merge tag 'erofs-for-6.10-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs
Pull more erofs updates from Gao Xiang: "The main ones are metadata API conversion to byte offsets by Al Viro. Another patch gets rid of unnecessary memory allocation out of DEFLATE decompressor. The remaining one is a trivial cleanup. - Convert metadata APIs to byte offsets - Avoid allocating DEFLATE streams unnecessarily - Some erofs_show_options() cleanup" * tag 'erofs-for-6.10-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs: erofs: avoid allocating DEFLATE streams before mounting z_erofs_pcluster_begin(): don't bother with rounding position down erofs: don't round offset down for erofs_read_metabuf() erofs: don't align offset for erofs_read_metabuf() (simple cases) erofs: mechanically convert erofs_read_metabuf() to offsets erofs: clean up erofs_show_options()
2 parents c40b199 + 80eb4f6 commit dcb9f48

File tree

8 files changed

+65
-88
lines changed

8 files changed

+65
-88
lines changed

fs/erofs/data.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb)
7272
}
7373

7474
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
75-
erofs_blk_t blkaddr, enum erofs_kmap_type type)
75+
erofs_off_t offset, enum erofs_kmap_type type)
7676
{
7777
erofs_init_metabuf(buf, sb);
78-
return erofs_bread(buf, erofs_pos(sb, blkaddr), type);
78+
return erofs_bread(buf, offset, type);
7979
}
8080

8181
static int erofs_map_blocks_flatmode(struct inode *inode,
@@ -152,7 +152,7 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)
152152
pos = ALIGN(erofs_iloc(inode) + vi->inode_isize +
153153
vi->xattr_isize, unit) + unit * chunknr;
154154

155-
kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(sb, pos), EROFS_KMAP);
155+
kaddr = erofs_read_metabuf(&buf, sb, pos, EROFS_KMAP);
156156
if (IS_ERR(kaddr)) {
157157
err = PTR_ERR(kaddr);
158158
goto out;
@@ -163,7 +163,7 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)
163163

164164
/* handle block map */
165165
if (!(vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES)) {
166-
__le32 *blkaddr = kaddr + erofs_blkoff(sb, pos);
166+
__le32 *blkaddr = kaddr;
167167

168168
if (le32_to_cpu(*blkaddr) == EROFS_NULL_ADDR) {
169169
map->m_flags = 0;
@@ -174,7 +174,7 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)
174174
goto out_unlock;
175175
}
176176
/* parse chunk indexes */
177-
idx = kaddr + erofs_blkoff(sb, pos);
177+
idx = kaddr;
178178
switch (le32_to_cpu(idx->blkaddr)) {
179179
case EROFS_NULL_ADDR:
180180
map->m_flags = 0;
@@ -294,11 +294,10 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
294294
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
295295

296296
iomap->type = IOMAP_INLINE;
297-
ptr = erofs_read_metabuf(&buf, sb,
298-
erofs_blknr(sb, mdev.m_pa), EROFS_KMAP);
297+
ptr = erofs_read_metabuf(&buf, sb, mdev.m_pa, EROFS_KMAP);
299298
if (IS_ERR(ptr))
300299
return PTR_ERR(ptr);
301-
iomap->inline_data = ptr + erofs_blkoff(sb, mdev.m_pa);
300+
iomap->inline_data = ptr;
302301
iomap->private = buf.base;
303302
} else {
304303
iomap->type = IOMAP_MAPPED;

fs/erofs/decompressor_deflate.c

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,15 @@ int __init z_erofs_deflate_init(void)
4646
/* by default, use # of possible CPUs instead */
4747
if (!z_erofs_deflate_nstrms)
4848
z_erofs_deflate_nstrms = num_possible_cpus();
49-
50-
for (; z_erofs_deflate_avail_strms < z_erofs_deflate_nstrms;
51-
++z_erofs_deflate_avail_strms) {
52-
struct z_erofs_deflate *strm;
53-
54-
strm = kzalloc(sizeof(*strm), GFP_KERNEL);
55-
if (!strm)
56-
goto out_failed;
57-
58-
/* XXX: in-kernel zlib cannot shrink windowbits currently */
59-
strm->z.workspace = vmalloc(zlib_inflate_workspacesize());
60-
if (!strm->z.workspace) {
61-
kfree(strm);
62-
goto out_failed;
63-
}
64-
65-
spin_lock(&z_erofs_deflate_lock);
66-
strm->next = z_erofs_deflate_head;
67-
z_erofs_deflate_head = strm;
68-
spin_unlock(&z_erofs_deflate_lock);
69-
}
7049
return 0;
71-
72-
out_failed:
73-
erofs_err(NULL, "failed to allocate zlib workspace");
74-
z_erofs_deflate_exit();
75-
return -ENOMEM;
7650
}
7751

7852
int z_erofs_load_deflate_config(struct super_block *sb,
7953
struct erofs_super_block *dsb, void *data, int size)
8054
{
8155
struct z_erofs_deflate_cfgs *dfl = data;
56+
static DEFINE_MUTEX(deflate_resize_mutex);
57+
static bool inited;
8258

8359
if (!dfl || size < sizeof(struct z_erofs_deflate_cfgs)) {
8460
erofs_err(sb, "invalid deflate cfgs, size=%u", size);
@@ -89,9 +65,36 @@ int z_erofs_load_deflate_config(struct super_block *sb,
8965
erofs_err(sb, "unsupported windowbits %u", dfl->windowbits);
9066
return -EOPNOTSUPP;
9167
}
68+
mutex_lock(&deflate_resize_mutex);
69+
if (!inited) {
70+
for (; z_erofs_deflate_avail_strms < z_erofs_deflate_nstrms;
71+
++z_erofs_deflate_avail_strms) {
72+
struct z_erofs_deflate *strm;
73+
74+
strm = kzalloc(sizeof(*strm), GFP_KERNEL);
75+
if (!strm)
76+
goto failed;
77+
/* XXX: in-kernel zlib cannot customize windowbits */
78+
strm->z.workspace = vmalloc(zlib_inflate_workspacesize());
79+
if (!strm->z.workspace) {
80+
kfree(strm);
81+
goto failed;
82+
}
9283

84+
spin_lock(&z_erofs_deflate_lock);
85+
strm->next = z_erofs_deflate_head;
86+
z_erofs_deflate_head = strm;
87+
spin_unlock(&z_erofs_deflate_lock);
88+
}
89+
inited = true;
90+
}
91+
mutex_unlock(&deflate_resize_mutex);
9392
erofs_info(sb, "EXPERIMENTAL DEFLATE feature in use. Use at your own risk!");
9493
return 0;
94+
failed:
95+
mutex_unlock(&deflate_resize_mutex);
96+
z_erofs_deflate_exit();
97+
return -ENOMEM;
9598
}
9699

97100
int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,

fs/erofs/fscache.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,15 @@ static int erofs_fscache_data_read_slice(struct erofs_fscache_rq *req)
273273
if (map.m_flags & EROFS_MAP_META) {
274274
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
275275
struct iov_iter iter;
276-
erofs_blk_t blknr;
277-
size_t offset, size;
276+
size_t size = map.m_llen;
278277
void *src;
279278

280-
/* For tail packing layout, the offset may be non-zero. */
281-
offset = erofs_blkoff(sb, map.m_pa);
282-
blknr = erofs_blknr(sb, map.m_pa);
283-
size = map.m_llen;
284-
285-
src = erofs_read_metabuf(&buf, sb, blknr, EROFS_KMAP);
279+
src = erofs_read_metabuf(&buf, sb, map.m_pa, EROFS_KMAP);
286280
if (IS_ERR(src))
287281
return PTR_ERR(src);
288282

289283
iov_iter_xarray(&iter, ITER_DEST, &mapping->i_pages, pos, PAGE_SIZE);
290-
if (copy_to_iter(src + offset, size, &iter) != size) {
284+
if (copy_to_iter(src, size, &iter) != size) {
291285
erofs_put_metabuf(&buf);
292286
return -EFAULT;
293287
}

fs/erofs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void *erofs_read_inode(struct erofs_buf *buf,
2626
blkaddr = erofs_blknr(sb, inode_loc);
2727
*ofs = erofs_blkoff(sb, inode_loc);
2828

29-
kaddr = erofs_read_metabuf(buf, sb, blkaddr, EROFS_KMAP);
29+
kaddr = erofs_read_metabuf(buf, sb, erofs_pos(sb, blkaddr), EROFS_KMAP);
3030
if (IS_ERR(kaddr)) {
3131
erofs_err(sb, "failed to get inode (nid: %llu) page, err %ld",
3232
vi->nid, PTR_ERR(kaddr));
@@ -66,7 +66,7 @@ static void *erofs_read_inode(struct erofs_buf *buf,
6666
goto err_out;
6767
}
6868
memcpy(copied, dic, gotten);
69-
kaddr = erofs_read_metabuf(buf, sb, blkaddr + 1,
69+
kaddr = erofs_read_metabuf(buf, sb, erofs_pos(sb, blkaddr + 1),
7070
EROFS_KMAP);
7171
if (IS_ERR(kaddr)) {
7272
erofs_err(sb, "failed to get inode payload block (nid: %llu), err %ld",

fs/erofs/internal.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,12 @@ enum {
6464
};
6565

6666
struct erofs_mount_opts {
67-
#ifdef CONFIG_EROFS_FS_ZIP
6867
/* current strategy of how to use managed cache */
6968
unsigned char cache_strategy;
7069
/* strategy of sync decompression (0 - auto, 1 - force on, 2 - force off) */
7170
unsigned int sync_decompress;
72-
7371
/* threshold for decompression synchronously */
7472
unsigned int max_sync_decompress_pages;
75-
#endif
7673
unsigned int mount_opt;
7774
};
7875

@@ -406,7 +403,7 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset,
406403
enum erofs_kmap_type type);
407404
void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb);
408405
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
409-
erofs_blk_t blkaddr, enum erofs_kmap_type type);
406+
erofs_off_t offset, enum erofs_kmap_type type);
410407
int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev);
411408
int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
412409
u64 start, u64 len);

fs/erofs/super.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,10 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
178178
struct erofs_fscache *fscache;
179179
struct erofs_deviceslot *dis;
180180
struct file *bdev_file;
181-
void *ptr;
182181

183-
ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *pos), EROFS_KMAP);
184-
if (IS_ERR(ptr))
185-
return PTR_ERR(ptr);
186-
dis = ptr + erofs_blkoff(sb, *pos);
182+
dis = erofs_read_metabuf(buf, sb, *pos, EROFS_KMAP);
183+
if (IS_ERR(dis))
184+
return PTR_ERR(dis);
187185

188186
if (!sbi->devs->flatdev && !dif->path) {
189187
if (!dis->tag[0]) {
@@ -943,26 +941,14 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)
943941
struct erofs_sb_info *sbi = EROFS_SB(root->d_sb);
944942
struct erofs_mount_opts *opt = &sbi->opt;
945943

946-
#ifdef CONFIG_EROFS_FS_XATTR
947-
if (test_opt(opt, XATTR_USER))
948-
seq_puts(seq, ",user_xattr");
949-
else
950-
seq_puts(seq, ",nouser_xattr");
951-
#endif
952-
#ifdef CONFIG_EROFS_FS_POSIX_ACL
953-
if (test_opt(opt, POSIX_ACL))
954-
seq_puts(seq, ",acl");
955-
else
956-
seq_puts(seq, ",noacl");
957-
#endif
958-
#ifdef CONFIG_EROFS_FS_ZIP
959-
if (opt->cache_strategy == EROFS_ZIP_CACHE_DISABLED)
960-
seq_puts(seq, ",cache_strategy=disabled");
961-
else if (opt->cache_strategy == EROFS_ZIP_CACHE_READAHEAD)
962-
seq_puts(seq, ",cache_strategy=readahead");
963-
else if (opt->cache_strategy == EROFS_ZIP_CACHE_READAROUND)
964-
seq_puts(seq, ",cache_strategy=readaround");
965-
#endif
944+
if (IS_ENABLED(CONFIG_EROFS_FS_XATTR))
945+
seq_puts(seq, test_opt(opt, XATTR_USER) ?
946+
",user_xattr" : ",nouser_xattr");
947+
if (IS_ENABLED(CONFIG_EROFS_FS_POSIX_ACL))
948+
seq_puts(seq, test_opt(opt, POSIX_ACL) ? ",acl" : ",noacl");
949+
if (IS_ENABLED(CONFIG_EROFS_FS_ZIP))
950+
seq_printf(seq, ",cache_strategy=%s",
951+
erofs_param_cache_strategy[opt->cache_strategy].name);
966952
if (test_opt(opt, DAX_ALWAYS))
967953
seq_puts(seq, ",dax=always");
968954
if (test_opt(opt, DAX_NEVER))

fs/erofs/zdata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
868868
} else {
869869
void *mptr;
870870

871-
mptr = erofs_read_metabuf(&map->buf, sb, blknr, EROFS_NO_KMAP);
871+
mptr = erofs_read_metabuf(&map->buf, sb, map->m_pa, EROFS_NO_KMAP);
872872
if (IS_ERR(mptr)) {
873873
ret = PTR_ERR(mptr);
874874
erofs_err(sb, "failed to get inline data %d", ret);

fs/erofs/zmap.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m,
3434
unsigned int advise;
3535

3636
m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
37-
erofs_blknr(inode->i_sb, pos), EROFS_KMAP);
37+
pos, EROFS_KMAP);
3838
if (IS_ERR(m->kaddr))
3939
return PTR_ERR(m->kaddr);
4040

4141
m->nextpackoff = pos + sizeof(struct z_erofs_lcluster_index);
4242
m->lcn = lcn;
43-
di = m->kaddr + erofs_blkoff(inode->i_sb, pos);
43+
di = m->kaddr;
4444

4545
advise = le16_to_cpu(di->di_advise);
4646
m->type = advise & Z_EROFS_LI_LCLUSTER_TYPE_MASK;
@@ -109,7 +109,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
109109
{
110110
struct erofs_inode *const vi = EROFS_I(m->inode);
111111
const unsigned int lclusterbits = vi->z_logical_clusterbits;
112-
unsigned int vcnt, base, lo, lobits, encodebits, nblk, eofs;
112+
unsigned int vcnt, lo, lobits, encodebits, nblk, bytes;
113113
int i;
114114
u8 *in, type;
115115
bool big_pcluster;
@@ -127,11 +127,11 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
127127
big_pcluster = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1;
128128
lobits = max(lclusterbits, ilog2(Z_EROFS_LI_D0_CBLKCNT) + 1U);
129129
encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt;
130-
eofs = erofs_blkoff(m->inode->i_sb, pos);
131-
base = round_down(eofs, vcnt << amortizedshift);
132-
in = m->kaddr + base;
130+
bytes = pos & ((vcnt << amortizedshift) - 1);
133131

134-
i = (eofs - base) >> amortizedshift;
132+
in = m->kaddr - bytes;
133+
134+
i = bytes >> amortizedshift;
135135

136136
lo = decode_compactedbits(lobits, in, encodebits * i, &type);
137137
m->type = type;
@@ -256,7 +256,7 @@ static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m,
256256
out:
257257
pos += lcn * (1 << amortizedshift);
258258
m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
259-
erofs_blknr(inode->i_sb, pos), EROFS_KMAP);
259+
pos, EROFS_KMAP);
260260
if (IS_ERR(m->kaddr))
261261
return PTR_ERR(m->kaddr);
262262
return unpack_compacted_index(m, amortizedshift, pos, lookahead);
@@ -570,7 +570,6 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
570570
int err, headnr;
571571
erofs_off_t pos;
572572
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
573-
void *kaddr;
574573
struct z_erofs_map_header *h;
575574

576575
if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags)) {
@@ -590,13 +589,12 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
590589
goto out_unlock;
591590

592591
pos = ALIGN(erofs_iloc(inode) + vi->inode_isize + vi->xattr_isize, 8);
593-
kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(sb, pos), EROFS_KMAP);
594-
if (IS_ERR(kaddr)) {
595-
err = PTR_ERR(kaddr);
592+
h = erofs_read_metabuf(&buf, sb, pos, EROFS_KMAP);
593+
if (IS_ERR(h)) {
594+
err = PTR_ERR(h);
596595
goto out_unlock;
597596
}
598597

599-
h = kaddr + erofs_blkoff(sb, pos);
600598
/*
601599
* if the highest bit of the 8-byte map header is set, the whole file
602600
* is stored in the packed inode. The rest bits keeps z_fragmentoff.

0 commit comments

Comments
 (0)