2019-07-31 08:57:31 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2018-07-26 05:21:58 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 HUAWEI, Inc.
|
2020-07-13 06:09:44 -07:00
|
|
|
* https://www.huawei.com/
|
2022-07-15 08:41:51 -07:00
|
|
|
* Copyright (C) 2022 Alibaba Cloud
|
2018-07-26 05:21:58 -07:00
|
|
|
*/
|
2019-06-24 00:22:54 -07:00
|
|
|
#include "compress.h"
|
2022-09-15 02:41:59 -07:00
|
|
|
#include <linux/psi.h>
|
2023-02-08 02:33:22 -07:00
|
|
|
#include <linux/cpuhotplug.h>
|
2018-09-18 07:27:27 -07:00
|
|
|
#include <trace/events/erofs.h>
|
|
|
|
|
2023-02-04 02:30:38 -07:00
|
|
|
#define Z_EROFS_PCLUSTER_MAX_PAGES (Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE)
|
|
|
|
#define Z_EROFS_INLINE_BVECS 2
|
|
|
|
|
|
|
|
/*
|
|
|
|
* let's leave a type here in case of introducing
|
|
|
|
* another tagged pointer later.
|
|
|
|
*/
|
|
|
|
typedef void *z_erofs_next_pcluster_t;
|
|
|
|
|
|
|
|
struct z_erofs_bvec {
|
2024-07-03 05:00:51 -07:00
|
|
|
struct page *page;
|
2023-02-04 02:30:38 -07:00
|
|
|
int offset;
|
|
|
|
unsigned int end;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define __Z_EROFS_BVSET(name, total) \
|
|
|
|
struct name { \
|
|
|
|
/* point to the next page which contains the following bvecs */ \
|
|
|
|
struct page *nextpage; \
|
|
|
|
struct z_erofs_bvec bvec[total]; \
|
|
|
|
}
|
|
|
|
__Z_EROFS_BVSET(z_erofs_bvset,);
|
|
|
|
__Z_EROFS_BVSET(z_erofs_bvset_inline, Z_EROFS_INLINE_BVECS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure fields follow one of the following exclusion rules.
|
|
|
|
*
|
|
|
|
* I: Modifiable by initialization/destruction paths and read-only
|
|
|
|
* for everyone else;
|
|
|
|
*
|
|
|
|
* L: Field should be protected by the pcluster lock;
|
|
|
|
*
|
|
|
|
* A: Field should be accessed / updated in atomic for parallelized code.
|
|
|
|
*/
|
|
|
|
struct z_erofs_pcluster {
|
|
|
|
struct erofs_workgroup obj;
|
|
|
|
struct mutex lock;
|
|
|
|
|
|
|
|
/* A: point to next chained pcluster or TAILs */
|
|
|
|
z_erofs_next_pcluster_t next;
|
|
|
|
|
|
|
|
/* L: the maximum decompression size of this round */
|
|
|
|
unsigned int length;
|
|
|
|
|
|
|
|
/* L: total number of bvecs */
|
|
|
|
unsigned int vcnt;
|
|
|
|
|
2023-12-06 02:10:54 -07:00
|
|
|
/* I: pcluster size (compressed size) in bytes */
|
|
|
|
unsigned int pclustersize;
|
|
|
|
|
2023-02-04 02:30:38 -07:00
|
|
|
/* I: page offset of start position of decompression */
|
|
|
|
unsigned short pageofs_out;
|
|
|
|
|
|
|
|
/* I: page offset of inline compressed data */
|
|
|
|
unsigned short pageofs_in;
|
|
|
|
|
|
|
|
union {
|
|
|
|
/* L: inline a certain number of bvec for bootstrap */
|
|
|
|
struct z_erofs_bvset_inline bvset;
|
|
|
|
|
|
|
|
/* I: can be used to free the pcluster by RCU. */
|
|
|
|
struct rcu_head rcu;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* I: compression algorithm format */
|
|
|
|
unsigned char algorithmformat;
|
|
|
|
|
|
|
|
/* L: whether partial decompression or not */
|
|
|
|
bool partial;
|
|
|
|
|
|
|
|
/* L: indicate several pageofs_outs or not */
|
|
|
|
bool multibases;
|
|
|
|
|
2024-01-26 07:01:42 -07:00
|
|
|
/* L: whether extra buffer allocations are best-effort */
|
|
|
|
bool besteffort;
|
|
|
|
|
2023-02-04 02:30:38 -07:00
|
|
|
/* A: compressed bvecs (can be cached or inplaced pages) */
|
|
|
|
struct z_erofs_bvec compressed_bvecs[];
|
|
|
|
};
|
|
|
|
|
2023-05-26 13:14:56 -07:00
|
|
|
/* the end of a chain of pclusters */
|
2023-05-26 13:14:59 -07:00
|
|
|
#define Z_EROFS_PCLUSTER_TAIL ((void *) 0x700 + POISON_POINTER_DELTA)
|
2023-02-04 02:30:38 -07:00
|
|
|
#define Z_EROFS_PCLUSTER_NIL (NULL)
|
|
|
|
|
|
|
|
struct z_erofs_decompressqueue {
|
|
|
|
struct super_block *sb;
|
|
|
|
atomic_t pending_bios;
|
|
|
|
z_erofs_next_pcluster_t head;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct completion done;
|
|
|
|
struct work_struct work;
|
2023-02-08 02:33:22 -07:00
|
|
|
struct kthread_work kthread_work;
|
2023-02-04 02:30:38 -07:00
|
|
|
} u;
|
|
|
|
bool eio, sync;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool z_erofs_is_inline_pcluster(struct z_erofs_pcluster *pcl)
|
|
|
|
{
|
|
|
|
return !pcl->obj.index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int z_erofs_pclusterpages(struct z_erofs_pcluster *pcl)
|
|
|
|
{
|
2023-12-06 02:10:54 -07:00
|
|
|
return PAGE_ALIGN(pcl->pclustersize) >> PAGE_SHIFT;
|
2023-02-04 02:30:38 -07:00
|
|
|
}
|
|
|
|
|
2024-03-05 02:14:48 -07:00
|
|
|
#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping)
|
|
|
|
static bool erofs_folio_is_managed(struct erofs_sb_info *sbi, struct folio *fo)
|
|
|
|
{
|
|
|
|
return fo->mapping == MNGD_MAPPING(sbi);
|
|
|
|
}
|
|
|
|
|
2023-02-04 02:30:38 -07:00
|
|
|
#define Z_EROFS_ONSTACK_PAGES 32
|
|
|
|
|
2021-04-06 21:39:20 -07:00
|
|
|
/*
|
|
|
|
* since pclustersize is variable for big pcluster feature, introduce slab
|
|
|
|
* pools implementation for different pcluster sizes.
|
|
|
|
*/
|
|
|
|
struct z_erofs_pcluster_slab {
|
|
|
|
struct kmem_cache *slab;
|
|
|
|
unsigned int maxpages;
|
|
|
|
char name[48];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define _PCLP(n) { .maxpages = n }
|
|
|
|
|
|
|
|
static struct z_erofs_pcluster_slab pcluster_pool[] __read_mostly = {
|
|
|
|
_PCLP(1), _PCLP(4), _PCLP(16), _PCLP(64), _PCLP(128),
|
|
|
|
_PCLP(Z_EROFS_PCLUSTER_MAX_PAGES)
|
|
|
|
};
|
|
|
|
|
2022-07-15 08:41:51 -07:00
|
|
|
struct z_erofs_bvec_iter {
|
|
|
|
struct page *bvpage;
|
|
|
|
struct z_erofs_bvset *bvset;
|
|
|
|
unsigned int nr, cur;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct page *z_erofs_bvec_iter_end(struct z_erofs_bvec_iter *iter)
|
|
|
|
{
|
|
|
|
if (iter->bvpage)
|
|
|
|
kunmap_local(iter->bvset);
|
|
|
|
return iter->bvpage;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct page *z_erofs_bvset_flip(struct z_erofs_bvec_iter *iter)
|
|
|
|
{
|
|
|
|
unsigned long base = (unsigned long)((struct z_erofs_bvset *)0)->bvec;
|
|
|
|
/* have to access nextpage in advance, otherwise it will be unmapped */
|
|
|
|
struct page *nextpage = iter->bvset->nextpage;
|
|
|
|
struct page *oldpage;
|
|
|
|
|
|
|
|
DBG_BUGON(!nextpage);
|
|
|
|
oldpage = z_erofs_bvec_iter_end(iter);
|
|
|
|
iter->bvpage = nextpage;
|
|
|
|
iter->bvset = kmap_local_page(nextpage);
|
|
|
|
iter->nr = (PAGE_SIZE - base) / sizeof(struct z_erofs_bvec);
|
|
|
|
iter->cur = 0;
|
|
|
|
return oldpage;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void z_erofs_bvec_iter_begin(struct z_erofs_bvec_iter *iter,
|
|
|
|
struct z_erofs_bvset_inline *bvset,
|
|
|
|
unsigned int bootstrap_nr,
|
|
|
|
unsigned int cur)
|
|
|
|
{
|
|
|
|
*iter = (struct z_erofs_bvec_iter) {
|
|
|
|
.nr = bootstrap_nr,
|
|
|
|
.bvset = (struct z_erofs_bvset *)bvset,
|
|
|
|
};
|
|
|
|
|
|
|
|
while (cur > iter->nr) {
|
|
|
|
cur -= iter->nr;
|
|
|
|
z_erofs_bvset_flip(iter);
|
|
|
|
}
|
|
|
|
iter->cur = cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int z_erofs_bvec_enqueue(struct z_erofs_bvec_iter *iter,
|
|
|
|
struct z_erofs_bvec *bvec,
|
2023-05-26 13:14:55 -07:00
|
|
|
struct page **candidate_bvpage,
|
|
|
|
struct page **pagepool)
|
2022-07-15 08:41:51 -07:00
|
|
|
{
|
2023-05-26 13:14:54 -07:00
|
|
|
if (iter->cur >= iter->nr) {
|
|
|
|
struct page *nextpage = *candidate_bvpage;
|
|
|
|
|
|
|
|
if (!nextpage) {
|
erofs: allocate more short-lived pages from reserved pool first
This patch aims to allocate bvpages and short-lived compressed pages
from the reserved pool first.
After applying this patch, there are three benefits.
1. It reduces the page allocation time.
The bvpages and short-lived compressed pages account for about 4% of
the pages allocated from the system in the multi-app launch benchmarks
[1]. It reduces the page allocation time accordingly and lowers the
likelihood of blockage by page allocation in low memory scenarios.
2. The pages in the reserved pool will be allocated on demand.
Currently, bvpages and short-lived compressed pages are short-lived
pages allocated from the system, and the pages in the reserved pool all
originate from short-lived pages. Consequently, the number of reserved
pool pages will increase to z_erofs_rsv_nrpages over time.
With this patch, all short-lived pages are allocated from the reserved
pool first, so the number of reserved pool pages will only increase when
there are not enough pages. Thus, even if z_erofs_rsv_nrpages is set to
a large number for specific reasons, the actual number of reserved pool
pages may remain low as per demand. In the multi-app launch benchmarks
[1], z_erofs_rsv_nrpages is set at 256, while the number of reserved
pool pages remains below 64.
3. When erofs cache decompression is disabled
(EROFS_ZIP_CACHE_DISABLED), all pages will *only* be allocated from
the reserved pool for erofs. This will significantly reduce the memory
pressure from erofs.
[1] For additional details on the multi-app launch benchmarks, please
refer to commit 0f6273ab4637 ("erofs: add a reserved buffer pool for lz4
decompression").
Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Link: https://lore.kernel.org/r/20240906121110.3701889-1-guochunhai@vivo.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2024-09-06 05:11:10 -07:00
|
|
|
nextpage = __erofs_allocpage(pagepool, GFP_KERNEL,
|
|
|
|
true);
|
2023-05-26 13:14:54 -07:00
|
|
|
if (!nextpage)
|
|
|
|
return -ENOMEM;
|
|
|
|
set_page_private(nextpage, Z_EROFS_SHORTLIVED_PAGE);
|
|
|
|
}
|
2022-07-15 08:41:51 -07:00
|
|
|
DBG_BUGON(iter->bvset->nextpage);
|
2023-05-26 13:14:54 -07:00
|
|
|
iter->bvset->nextpage = nextpage;
|
2022-07-15 08:41:51 -07:00
|
|
|
z_erofs_bvset_flip(iter);
|
|
|
|
|
|
|
|
iter->bvset->nextpage = NULL;
|
|
|
|
*candidate_bvpage = NULL;
|
|
|
|
}
|
|
|
|
iter->bvset->bvec[iter->cur++] = *bvec;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void z_erofs_bvec_dequeue(struct z_erofs_bvec_iter *iter,
|
|
|
|
struct z_erofs_bvec *bvec,
|
|
|
|
struct page **old_bvpage)
|
|
|
|
{
|
|
|
|
if (iter->cur == iter->nr)
|
|
|
|
*old_bvpage = z_erofs_bvset_flip(iter);
|
|
|
|
else
|
|
|
|
*old_bvpage = NULL;
|
|
|
|
*bvec = iter->bvset->bvec[iter->cur++];
|
|
|
|
}
|
|
|
|
|
2021-04-06 21:39:20 -07:00
|
|
|
static void z_erofs_destroy_pcluster_pool(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pcluster_pool); ++i) {
|
|
|
|
if (!pcluster_pool[i].slab)
|
|
|
|
continue;
|
|
|
|
kmem_cache_destroy(pcluster_pool[i].slab);
|
|
|
|
pcluster_pool[i].slab = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int z_erofs_create_pcluster_pool(void)
|
|
|
|
{
|
|
|
|
struct z_erofs_pcluster_slab *pcs;
|
|
|
|
struct z_erofs_pcluster *a;
|
|
|
|
unsigned int size;
|
|
|
|
|
|
|
|
for (pcs = pcluster_pool;
|
|
|
|
pcs < pcluster_pool + ARRAY_SIZE(pcluster_pool); ++pcs) {
|
2022-07-15 08:41:54 -07:00
|
|
|
size = struct_size(a, compressed_bvecs, pcs->maxpages);
|
2021-04-06 21:39:20 -07:00
|
|
|
|
|
|
|
sprintf(pcs->name, "erofs_pcluster-%u", pcs->maxpages);
|
|
|
|
pcs->slab = kmem_cache_create(pcs->name, size, 0,
|
|
|
|
SLAB_RECLAIM_ACCOUNT, NULL);
|
|
|
|
if (pcs->slab)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
z_erofs_destroy_pcluster_pool();
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-12-06 02:10:54 -07:00
|
|
|
static struct z_erofs_pcluster *z_erofs_alloc_pcluster(unsigned int size)
|
2021-04-06 21:39:20 -07:00
|
|
|
{
|
2023-12-06 02:10:54 -07:00
|
|
|
unsigned int nrpages = PAGE_ALIGN(size) >> PAGE_SHIFT;
|
|
|
|
struct z_erofs_pcluster_slab *pcs = pcluster_pool;
|
2021-04-06 21:39:20 -07:00
|
|
|
|
2023-12-06 02:10:54 -07:00
|
|
|
for (; pcs < pcluster_pool + ARRAY_SIZE(pcluster_pool); ++pcs) {
|
2021-04-06 21:39:20 -07:00
|
|
|
struct z_erofs_pcluster *pcl;
|
|
|
|
|
|
|
|
if (nrpages > pcs->maxpages)
|
|
|
|
continue;
|
|
|
|
|
2024-01-23 20:19:45 -07:00
|
|
|
pcl = kmem_cache_zalloc(pcs->slab, GFP_KERNEL);
|
2021-04-06 21:39:20 -07:00
|
|
|
if (!pcl)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2023-12-06 02:10:54 -07:00
|
|
|
pcl->pclustersize = size;
|
2021-04-06 21:39:20 -07:00
|
|
|
return pcl;
|
|
|
|
}
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void z_erofs_free_pcluster(struct z_erofs_pcluster *pcl)
|
|
|
|
{
|
2021-12-28 16:29:19 -07:00
|
|
|
unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
|
2021-04-06 21:39:20 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pcluster_pool); ++i) {
|
|
|
|
struct z_erofs_pcluster_slab *pcs = pcluster_pool + i;
|
|
|
|
|
2021-12-28 16:29:19 -07:00
|
|
|
if (pclusterpages > pcs->maxpages)
|
2021-04-06 21:39:20 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
kmem_cache_free(pcs->slab, pcl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DBG_BUGON(1);
|
|
|
|
}
|
|
|
|
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
static struct workqueue_struct *z_erofs_workqueue __read_mostly;
|
|
|
|
|
2023-02-08 02:33:22 -07:00
|
|
|
#ifdef CONFIG_EROFS_FS_PCPU_KTHREAD
|
|
|
|
static struct kthread_worker __rcu **z_erofs_pcpu_workers;
|
|
|
|
|
|
|
|
static void erofs_destroy_percpu_workers(void)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2023-02-08 02:33:22 -07:00
|
|
|
struct kthread_worker *worker;
|
|
|
|
unsigned int cpu;
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
worker = rcu_dereference_protected(
|
|
|
|
z_erofs_pcpu_workers[cpu], 1);
|
|
|
|
rcu_assign_pointer(z_erofs_pcpu_workers[cpu], NULL);
|
|
|
|
if (worker)
|
|
|
|
kthread_destroy_worker(worker);
|
|
|
|
}
|
|
|
|
kfree(z_erofs_pcpu_workers);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2023-02-08 02:33:22 -07:00
|
|
|
static struct kthread_worker *erofs_init_percpu_worker(int cpu)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2023-02-08 02:33:22 -07:00
|
|
|
struct kthread_worker *worker =
|
|
|
|
kthread_create_worker_on_cpu(cpu, 0, "erofs_worker/%u", cpu);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2023-02-08 02:33:22 -07:00
|
|
|
if (IS_ERR(worker))
|
|
|
|
return worker;
|
|
|
|
if (IS_ENABLED(CONFIG_EROFS_FS_PCPU_KTHREAD_HIPRI))
|
|
|
|
sched_set_fifo_low(worker->task);
|
|
|
|
return worker;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int erofs_init_percpu_workers(void)
|
|
|
|
{
|
|
|
|
struct kthread_worker *worker;
|
|
|
|
unsigned int cpu;
|
|
|
|
|
|
|
|
z_erofs_pcpu_workers = kcalloc(num_possible_cpus(),
|
|
|
|
sizeof(struct kthread_worker *), GFP_ATOMIC);
|
|
|
|
if (!z_erofs_pcpu_workers)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for_each_online_cpu(cpu) { /* could miss cpu{off,on}line? */
|
|
|
|
worker = erofs_init_percpu_worker(cpu);
|
|
|
|
if (!IS_ERR(worker))
|
|
|
|
rcu_assign_pointer(z_erofs_pcpu_workers[cpu], worker);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void erofs_destroy_percpu_workers(void) {}
|
|
|
|
static inline int erofs_init_percpu_workers(void) { return 0; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_EROFS_FS_PCPU_KTHREAD)
|
|
|
|
static DEFINE_SPINLOCK(z_erofs_pcpu_worker_lock);
|
|
|
|
static enum cpuhp_state erofs_cpuhp_state;
|
|
|
|
|
|
|
|
static int erofs_cpu_online(unsigned int cpu)
|
|
|
|
{
|
|
|
|
struct kthread_worker *worker, *old;
|
|
|
|
|
|
|
|
worker = erofs_init_percpu_worker(cpu);
|
|
|
|
if (IS_ERR(worker))
|
|
|
|
return PTR_ERR(worker);
|
|
|
|
|
|
|
|
spin_lock(&z_erofs_pcpu_worker_lock);
|
|
|
|
old = rcu_dereference_protected(z_erofs_pcpu_workers[cpu],
|
|
|
|
lockdep_is_held(&z_erofs_pcpu_worker_lock));
|
|
|
|
if (!old)
|
|
|
|
rcu_assign_pointer(z_erofs_pcpu_workers[cpu], worker);
|
|
|
|
spin_unlock(&z_erofs_pcpu_worker_lock);
|
|
|
|
if (old)
|
|
|
|
kthread_destroy_worker(worker);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int erofs_cpu_offline(unsigned int cpu)
|
|
|
|
{
|
|
|
|
struct kthread_worker *worker;
|
|
|
|
|
|
|
|
spin_lock(&z_erofs_pcpu_worker_lock);
|
|
|
|
worker = rcu_dereference_protected(z_erofs_pcpu_workers[cpu],
|
|
|
|
lockdep_is_held(&z_erofs_pcpu_worker_lock));
|
|
|
|
rcu_assign_pointer(z_erofs_pcpu_workers[cpu], NULL);
|
|
|
|
spin_unlock(&z_erofs_pcpu_worker_lock);
|
|
|
|
|
|
|
|
synchronize_rcu();
|
|
|
|
if (worker)
|
|
|
|
kthread_destroy_worker(worker);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int erofs_cpu_hotplug_init(void)
|
|
|
|
{
|
|
|
|
int state;
|
|
|
|
|
|
|
|
state = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
|
|
|
|
"fs/erofs:online", erofs_cpu_online, erofs_cpu_offline);
|
|
|
|
if (state < 0)
|
|
|
|
return state;
|
|
|
|
|
|
|
|
erofs_cpuhp_state = state;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void erofs_cpu_hotplug_destroy(void)
|
|
|
|
{
|
|
|
|
if (erofs_cpuhp_state)
|
|
|
|
cpuhp_remove_state_nocalls(erofs_cpuhp_state);
|
|
|
|
}
|
|
|
|
#else /* !CONFIG_HOTPLUG_CPU || !CONFIG_EROFS_FS_PCPU_KTHREAD */
|
|
|
|
static inline int erofs_cpu_hotplug_init(void) { return 0; }
|
|
|
|
static inline void erofs_cpu_hotplug_destroy(void) {}
|
|
|
|
#endif
|
|
|
|
|
2024-07-09 02:41:05 -07:00
|
|
|
void z_erofs_exit_subsystem(void)
|
2023-02-08 02:33:22 -07:00
|
|
|
{
|
|
|
|
erofs_cpu_hotplug_destroy();
|
|
|
|
erofs_destroy_percpu_workers();
|
|
|
|
destroy_workqueue(z_erofs_workqueue);
|
|
|
|
z_erofs_destroy_pcluster_pool();
|
2024-07-09 02:41:05 -07:00
|
|
|
z_erofs_exit_decompressor();
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2024-07-09 02:41:05 -07:00
|
|
|
int __init z_erofs_init_subsystem(void)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2024-07-09 02:41:05 -07:00
|
|
|
int err = z_erofs_init_decompressor();
|
2021-04-06 21:39:20 -07:00
|
|
|
|
|
|
|
if (err)
|
2024-07-09 02:41:05 -07:00
|
|
|
goto err_decompressor;
|
|
|
|
|
|
|
|
err = z_erofs_create_pcluster_pool();
|
|
|
|
if (err)
|
|
|
|
goto err_pcluster_pool;
|
2023-02-08 02:33:22 -07:00
|
|
|
|
|
|
|
z_erofs_workqueue = alloc_workqueue("erofs_worker",
|
|
|
|
WQ_UNBOUND | WQ_HIGHPRI, num_possible_cpus());
|
2023-02-16 05:13:04 -07:00
|
|
|
if (!z_erofs_workqueue) {
|
|
|
|
err = -ENOMEM;
|
2024-07-09 02:41:05 -07:00
|
|
|
goto err_workqueue_init;
|
2023-02-16 05:13:04 -07:00
|
|
|
}
|
2023-02-08 02:33:22 -07:00
|
|
|
|
|
|
|
err = erofs_init_percpu_workers();
|
2021-04-06 21:39:20 -07:00
|
|
|
if (err)
|
2024-07-09 02:41:05 -07:00
|
|
|
goto err_pcpu_worker;
|
2023-02-08 02:33:22 -07:00
|
|
|
|
|
|
|
err = erofs_cpu_hotplug_init();
|
|
|
|
if (err < 0)
|
2024-07-09 02:41:05 -07:00
|
|
|
goto err_cpuhp_init;
|
2023-02-08 02:33:22 -07:00
|
|
|
return err;
|
|
|
|
|
2024-07-09 02:41:05 -07:00
|
|
|
err_cpuhp_init:
|
2023-02-08 02:33:22 -07:00
|
|
|
erofs_destroy_percpu_workers();
|
2024-07-09 02:41:05 -07:00
|
|
|
err_pcpu_worker:
|
2023-02-08 02:33:22 -07:00
|
|
|
destroy_workqueue(z_erofs_workqueue);
|
2024-07-09 02:41:05 -07:00
|
|
|
err_workqueue_init:
|
2023-02-08 02:33:22 -07:00
|
|
|
z_erofs_destroy_pcluster_pool();
|
2024-07-09 02:41:05 -07:00
|
|
|
err_pcluster_pool:
|
|
|
|
z_erofs_exit_decompressor();
|
|
|
|
err_decompressor:
|
2021-04-06 21:39:20 -07:00
|
|
|
return err;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2022-07-15 08:41:57 -07:00
|
|
|
enum z_erofs_pclustermode {
|
|
|
|
Z_EROFS_PCLUSTER_INFLIGHT,
|
erofs: complete a missing case for inplace I/O
Add a missing case which could cause unnecessary page allocation but
not directly use inplace I/O instead, which increases runtime extra
memory footprint.
The detail is, considering an online file-backed page, the right half
of the page is chosen to be cached (e.g. the end page of a readahead
request) and some of its data doesn't exist in managed cache, so the
pcluster will be definitely kept in the submission chain. (IOWs, it
cannot be decompressed without I/O, e.g., due to the bypass queue).
Currently, DELAYEDALLOC/TRYALLOC cases can be downgraded as NOINPLACE,
and stop online pages from inplace I/O. After this patch, unneeded page
allocations won't be observed in pickup_page_for_submission() then.
Link: https://lore.kernel.org/r/20210321183227.5182-1-hsiangkao@aol.com
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
2021-03-21 11:32:27 -07:00
|
|
|
/*
|
2022-07-15 08:41:57 -07:00
|
|
|
* a weak form of Z_EROFS_PCLUSTER_FOLLOWED, the difference is that it
|
erofs: complete a missing case for inplace I/O
Add a missing case which could cause unnecessary page allocation but
not directly use inplace I/O instead, which increases runtime extra
memory footprint.
The detail is, considering an online file-backed page, the right half
of the page is chosen to be cached (e.g. the end page of a readahead
request) and some of its data doesn't exist in managed cache, so the
pcluster will be definitely kept in the submission chain. (IOWs, it
cannot be decompressed without I/O, e.g., due to the bypass queue).
Currently, DELAYEDALLOC/TRYALLOC cases can be downgraded as NOINPLACE,
and stop online pages from inplace I/O. After this patch, unneeded page
allocations won't be observed in pickup_page_for_submission() then.
Link: https://lore.kernel.org/r/20210321183227.5182-1-hsiangkao@aol.com
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
2021-03-21 11:32:27 -07:00
|
|
|
* could be dispatched into bypass queue later due to uptodated managed
|
|
|
|
* pages. All related online pages cannot be reused for inplace I/O (or
|
2022-07-15 08:41:52 -07:00
|
|
|
* bvpage) since it can be directly decoded without I/O submission.
|
erofs: complete a missing case for inplace I/O
Add a missing case which could cause unnecessary page allocation but
not directly use inplace I/O instead, which increases runtime extra
memory footprint.
The detail is, considering an online file-backed page, the right half
of the page is chosen to be cached (e.g. the end page of a readahead
request) and some of its data doesn't exist in managed cache, so the
pcluster will be definitely kept in the submission chain. (IOWs, it
cannot be decompressed without I/O, e.g., due to the bypass queue).
Currently, DELAYEDALLOC/TRYALLOC cases can be downgraded as NOINPLACE,
and stop online pages from inplace I/O. After this patch, unneeded page
allocations won't be observed in pickup_page_for_submission() then.
Link: https://lore.kernel.org/r/20210321183227.5182-1-hsiangkao@aol.com
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
2021-03-21 11:32:27 -07:00
|
|
|
*/
|
2022-07-15 08:41:57 -07:00
|
|
|
Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE,
|
2019-02-26 22:33:32 -07:00
|
|
|
/*
|
2023-08-17 01:28:07 -07:00
|
|
|
* The pcluster was just linked to a decompression chain by us. It can
|
|
|
|
* also be linked with the remaining pclusters, which means if the
|
|
|
|
* processing page is the tail page of a pcluster, this pcluster can
|
|
|
|
* safely use the whole page (since the previous pcluster is within the
|
|
|
|
* same chain) for in-place I/O, as illustrated below:
|
|
|
|
* ___________________________________________________
|
|
|
|
* | tail (partial) page | head (partial) page |
|
|
|
|
* | (of the current pcl) | (of the previous pcl) |
|
|
|
|
* |___PCLUSTER_FOLLOWED___|_____PCLUSTER_FOLLOWED_____|
|
2019-02-26 22:33:32 -07:00
|
|
|
*
|
2023-08-17 01:28:07 -07:00
|
|
|
* [ (*) the page above can be used as inplace I/O. ]
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
*/
|
2022-07-15 08:41:57 -07:00
|
|
|
Z_EROFS_PCLUSTER_FOLLOWED,
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
};
|
|
|
|
|
2022-03-01 12:49:50 -07:00
|
|
|
struct z_erofs_decompress_frontend {
|
|
|
|
struct inode *const inode;
|
|
|
|
struct erofs_map_blocks map;
|
2022-07-15 08:41:51 -07:00
|
|
|
struct z_erofs_bvec_iter biter;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2023-05-26 13:14:55 -07:00
|
|
|
struct page *pagepool;
|
2022-07-15 08:41:51 -07:00
|
|
|
struct page *candidate_bvpage;
|
2023-05-26 13:14:56 -07:00
|
|
|
struct z_erofs_pcluster *pcl;
|
2019-07-31 08:57:47 -07:00
|
|
|
z_erofs_next_pcluster_t owned_head;
|
2022-07-15 08:41:57 -07:00
|
|
|
enum z_erofs_pclustermode mode;
|
2019-07-31 08:57:47 -07:00
|
|
|
|
|
|
|
erofs_off_t headoffset;
|
2022-07-15 08:41:54 -07:00
|
|
|
|
|
|
|
/* a pointer used to pick up inplace I/O pages */
|
|
|
|
unsigned int icur;
|
2019-07-31 08:57:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DECOMPRESS_FRONTEND_INIT(__i) { \
|
2022-03-01 12:49:50 -07:00
|
|
|
.inode = __i, .owned_head = Z_EROFS_PCLUSTER_TAIL, \
|
2023-08-17 01:28:11 -07:00
|
|
|
.mode = Z_EROFS_PCLUSTER_FOLLOWED }
|
2019-07-31 08:57:47 -07:00
|
|
|
|
2022-12-05 23:03:52 -07:00
|
|
|
static bool z_erofs_should_alloc_cache(struct z_erofs_decompress_frontend *fe)
|
|
|
|
{
|
|
|
|
unsigned int cachestrategy = EROFS_I_SB(fe->inode)->opt.cache_strategy;
|
|
|
|
|
|
|
|
if (cachestrategy <= EROFS_ZIP_CACHE_DISABLED)
|
|
|
|
return false;
|
|
|
|
|
2023-08-17 01:28:11 -07:00
|
|
|
if (!(fe->map.m_flags & EROFS_MAP_FULL_MAPPED))
|
2022-12-05 23:03:52 -07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (cachestrategy >= EROFS_ZIP_CACHE_READAROUND &&
|
|
|
|
fe->map.m_la < fe->headoffset)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-26 13:14:55 -07:00
|
|
|
static void z_erofs_bind_cache(struct z_erofs_decompress_frontend *fe)
|
2018-07-26 05:22:07 -07:00
|
|
|
{
|
2022-03-01 12:49:51 -07:00
|
|
|
struct address_space *mc = MNGD_MAPPING(EROFS_I_SB(fe->inode));
|
2022-03-01 12:49:50 -07:00
|
|
|
struct z_erofs_pcluster *pcl = fe->pcl;
|
2023-12-06 02:10:54 -07:00
|
|
|
unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
|
2022-12-05 23:03:52 -07:00
|
|
|
bool shouldalloc = z_erofs_should_alloc_cache(fe);
|
2018-12-07 09:19:16 -07:00
|
|
|
bool standalone = true;
|
2022-03-01 12:49:51 -07:00
|
|
|
/*
|
|
|
|
* optimistic allocation without direct reclaim since inplace I/O
|
|
|
|
* can be used if low memory otherwise.
|
|
|
|
*/
|
2020-12-09 05:37:17 -07:00
|
|
|
gfp_t gfp = (mapping_gfp_mask(mc) & ~__GFP_DIRECT_RECLAIM) |
|
|
|
|
__GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
|
2022-07-15 08:41:54 -07:00
|
|
|
unsigned int i;
|
2018-12-07 09:19:16 -07:00
|
|
|
|
2024-01-25 05:00:39 -07:00
|
|
|
if (i_blocksize(fe->inode) != PAGE_SIZE ||
|
|
|
|
fe->mode < Z_EROFS_PCLUSTER_FOLLOWED)
|
2018-12-07 09:19:16 -07:00
|
|
|
return;
|
|
|
|
|
2023-12-06 02:10:54 -07:00
|
|
|
for (i = 0; i < pclusterpages; ++i) {
|
|
|
|
struct page *page, *newpage;
|
2018-12-07 09:19:16 -07:00
|
|
|
|
2024-01-25 05:00:39 -07:00
|
|
|
/* Inaccurate check w/o locking to avoid unneeded lookups */
|
2022-07-15 08:41:54 -07:00
|
|
|
if (READ_ONCE(pcl->compressed_bvecs[i].page))
|
2018-07-26 05:22:07 -07:00
|
|
|
continue;
|
|
|
|
|
2022-07-15 08:41:54 -07:00
|
|
|
page = find_get_page(mc, pcl->obj.index + i);
|
2024-03-05 02:14:45 -07:00
|
|
|
if (!page) {
|
erofs: complete a missing case for inplace I/O
Add a missing case which could cause unnecessary page allocation but
not directly use inplace I/O instead, which increases runtime extra
memory footprint.
The detail is, considering an online file-backed page, the right half
of the page is chosen to be cached (e.g. the end page of a readahead
request) and some of its data doesn't exist in managed cache, so the
pcluster will be definitely kept in the submission chain. (IOWs, it
cannot be decompressed without I/O, e.g., due to the bypass queue).
Currently, DELAYEDALLOC/TRYALLOC cases can be downgraded as NOINPLACE,
and stop online pages from inplace I/O. After this patch, unneeded page
allocations won't be observed in pickup_page_for_submission() then.
Link: https://lore.kernel.org/r/20210321183227.5182-1-hsiangkao@aol.com
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
2021-03-21 11:32:27 -07:00
|
|
|
/* I/O is needed, no possible to decompress directly */
|
2018-12-07 09:19:16 -07:00
|
|
|
standalone = false;
|
2022-12-05 23:03:52 -07:00
|
|
|
if (!shouldalloc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2023-12-06 02:10:54 -07:00
|
|
|
* Try cached I/O if allocation succeeds or fallback to
|
|
|
|
* in-place I/O instead to avoid any direct reclaim.
|
2022-12-05 23:03:52 -07:00
|
|
|
*/
|
2023-05-26 13:14:55 -07:00
|
|
|
newpage = erofs_allocpage(&fe->pagepool, gfp);
|
2022-12-05 23:03:52 -07:00
|
|
|
if (!newpage)
|
erofs: complete a missing case for inplace I/O
Add a missing case which could cause unnecessary page allocation but
not directly use inplace I/O instead, which increases runtime extra
memory footprint.
The detail is, considering an online file-backed page, the right half
of the page is chosen to be cached (e.g. the end page of a readahead
request) and some of its data doesn't exist in managed cache, so the
pcluster will be definitely kept in the submission chain. (IOWs, it
cannot be decompressed without I/O, e.g., due to the bypass queue).
Currently, DELAYEDALLOC/TRYALLOC cases can be downgraded as NOINPLACE,
and stop online pages from inplace I/O. After this patch, unneeded page
allocations won't be observed in pickup_page_for_submission() then.
Link: https://lore.kernel.org/r/20210321183227.5182-1-hsiangkao@aol.com
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
2021-03-21 11:32:27 -07:00
|
|
|
continue;
|
2022-12-05 23:03:52 -07:00
|
|
|
set_page_private(newpage, Z_EROFS_PREALLOCATED_PAGE);
|
2018-07-26 05:22:07 -07:00
|
|
|
}
|
2024-01-25 05:00:39 -07:00
|
|
|
spin_lock(&pcl->obj.lockref.lock);
|
|
|
|
if (!pcl->compressed_bvecs[i].page) {
|
2024-03-05 02:14:45 -07:00
|
|
|
pcl->compressed_bvecs[i].page = page ? page : newpage;
|
2024-01-25 05:00:39 -07:00
|
|
|
spin_unlock(&pcl->obj.lockref.lock);
|
2018-07-26 05:22:07 -07:00
|
|
|
continue;
|
2024-01-25 05:00:39 -07:00
|
|
|
}
|
|
|
|
spin_unlock(&pcl->obj.lockref.lock);
|
2018-07-26 05:22:07 -07:00
|
|
|
|
2021-10-22 02:01:20 -07:00
|
|
|
if (page)
|
2018-12-07 09:19:16 -07:00
|
|
|
put_page(page);
|
2021-10-22 02:01:20 -07:00
|
|
|
else if (newpage)
|
2023-05-26 13:14:55 -07:00
|
|
|
erofs_pagepool_add(&fe->pagepool, newpage);
|
2018-07-26 05:22:07 -07:00
|
|
|
}
|
2018-12-07 09:19:16 -07:00
|
|
|
|
erofs: complete a missing case for inplace I/O
Add a missing case which could cause unnecessary page allocation but
not directly use inplace I/O instead, which increases runtime extra
memory footprint.
The detail is, considering an online file-backed page, the right half
of the page is chosen to be cached (e.g. the end page of a readahead
request) and some of its data doesn't exist in managed cache, so the
pcluster will be definitely kept in the submission chain. (IOWs, it
cannot be decompressed without I/O, e.g., due to the bypass queue).
Currently, DELAYEDALLOC/TRYALLOC cases can be downgraded as NOINPLACE,
and stop online pages from inplace I/O. After this patch, unneeded page
allocations won't be observed in pickup_page_for_submission() then.
Link: https://lore.kernel.org/r/20210321183227.5182-1-hsiangkao@aol.com
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
2021-03-21 11:32:27 -07:00
|
|
|
/*
|
|
|
|
* don't do inplace I/O if all compressed pages are available in
|
|
|
|
* managed cache since it can be moved to the bypass queue instead.
|
|
|
|
*/
|
|
|
|
if (standalone)
|
2022-07-15 08:41:57 -07:00
|
|
|
fe->mode = Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE;
|
2018-07-26 05:22:07 -07:00
|
|
|
}
|
|
|
|
|
2024-07-03 05:00:51 -07:00
|
|
|
/* (erofs_shrinker) disconnect cached encoded data with pclusters */
|
2024-03-05 02:14:48 -07:00
|
|
|
int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi,
|
|
|
|
struct erofs_workgroup *grp)
|
2018-07-26 05:22:07 -07:00
|
|
|
{
|
2019-07-31 08:57:47 -07:00
|
|
|
struct z_erofs_pcluster *const pcl =
|
|
|
|
container_of(grp, struct z_erofs_pcluster, obj);
|
2023-12-06 02:10:54 -07:00
|
|
|
unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
|
2024-07-03 05:00:51 -07:00
|
|
|
struct folio *folio;
|
2018-07-26 05:22:07 -07:00
|
|
|
int i;
|
|
|
|
|
2021-12-28 16:29:19 -07:00
|
|
|
DBG_BUGON(z_erofs_is_inline_pcluster(pcl));
|
2024-07-03 05:00:51 -07:00
|
|
|
/* Each cached folio contains one page unless bs > ps is supported */
|
2023-12-06 02:10:54 -07:00
|
|
|
for (i = 0; i < pclusterpages; ++i) {
|
2024-07-03 05:00:51 -07:00
|
|
|
if (pcl->compressed_bvecs[i].page) {
|
|
|
|
folio = page_folio(pcl->compressed_bvecs[i].page);
|
|
|
|
/* Avoid reclaiming or migrating this folio */
|
|
|
|
if (!folio_trylock(folio))
|
|
|
|
return -EBUSY;
|
2018-07-26 05:22:07 -07:00
|
|
|
|
2024-07-03 05:00:51 -07:00
|
|
|
if (!erofs_folio_is_managed(sbi, folio))
|
|
|
|
continue;
|
|
|
|
pcl->compressed_bvecs[i].page = NULL;
|
|
|
|
folio_detach_private(folio);
|
|
|
|
folio_unlock(folio);
|
|
|
|
}
|
2018-07-26 05:22:07 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-26 13:14:57 -07:00
|
|
|
static bool z_erofs_cache_release_folio(struct folio *folio, gfp_t gfp)
|
2018-07-26 05:22:07 -07:00
|
|
|
{
|
2023-05-26 13:14:57 -07:00
|
|
|
struct z_erofs_pcluster *pcl = folio_get_private(folio);
|
2024-07-03 05:00:51 -07:00
|
|
|
struct z_erofs_bvec *bvec = pcl->compressed_bvecs;
|
|
|
|
struct z_erofs_bvec *end = bvec + z_erofs_pclusterpages(pcl);
|
2023-05-26 13:14:57 -07:00
|
|
|
bool ret;
|
|
|
|
|
|
|
|
if (!folio_test_private(folio))
|
|
|
|
return true;
|
2018-07-26 05:22:07 -07:00
|
|
|
|
2023-05-26 13:14:57 -07:00
|
|
|
ret = false;
|
2023-05-29 05:37:27 -07:00
|
|
|
spin_lock(&pcl->obj.lockref.lock);
|
2024-03-05 02:14:48 -07:00
|
|
|
if (pcl->obj.lockref.count <= 0) {
|
|
|
|
DBG_BUGON(z_erofs_is_inline_pcluster(pcl));
|
2024-07-03 05:00:51 -07:00
|
|
|
for (; bvec < end; ++bvec) {
|
|
|
|
if (bvec->page && page_folio(bvec->page) == folio) {
|
|
|
|
bvec->page = NULL;
|
2024-03-05 02:14:48 -07:00
|
|
|
folio_detach_private(folio);
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
}
|
2018-07-26 05:22:07 -07:00
|
|
|
}
|
|
|
|
}
|
2023-05-29 05:37:27 -07:00
|
|
|
spin_unlock(&pcl->obj.lockref.lock);
|
2018-07-26 05:22:07 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-05-26 13:14:57 -07:00
|
|
|
/*
|
|
|
|
* It will be called only on inode eviction. In case that there are still some
|
|
|
|
* decompression requests in progress, wait with rescheduling for a bit here.
|
|
|
|
* An extra lock could be introduced instead but it seems unnecessary.
|
|
|
|
*/
|
|
|
|
static void z_erofs_cache_invalidate_folio(struct folio *folio,
|
|
|
|
size_t offset, size_t length)
|
|
|
|
{
|
|
|
|
const size_t stop = length + offset;
|
|
|
|
|
|
|
|
/* Check for potential overflow in debug mode */
|
|
|
|
DBG_BUGON(stop > folio_size(folio) || stop < length);
|
|
|
|
|
|
|
|
if (offset == 0 && stop == folio_size(folio))
|
2024-01-23 20:19:45 -07:00
|
|
|
while (!z_erofs_cache_release_folio(folio, 0))
|
2023-05-26 13:14:57 -07:00
|
|
|
cond_resched();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct address_space_operations z_erofs_cache_aops = {
|
|
|
|
.release_folio = z_erofs_cache_release_folio,
|
|
|
|
.invalidate_folio = z_erofs_cache_invalidate_folio,
|
|
|
|
};
|
|
|
|
|
|
|
|
int erofs_init_managed_cache(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct inode *const inode = new_inode(sb);
|
|
|
|
|
|
|
|
if (!inode)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
set_nlink(inode, 1);
|
|
|
|
inode->i_size = OFFSET_MAX;
|
|
|
|
inode->i_mapping->a_ops = &z_erofs_cache_aops;
|
2024-01-23 20:19:45 -07:00
|
|
|
mapping_set_gfp_mask(inode->i_mapping, GFP_KERNEL);
|
2023-05-26 13:14:57 -07:00
|
|
|
EROFS_SB(sb)->managed_cache = inode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-05-28 22:54:23 -07:00
|
|
|
/* callers must be with pcluster lock held */
|
2022-03-01 12:49:50 -07:00
|
|
|
static int z_erofs_attach_page(struct z_erofs_decompress_frontend *fe,
|
2022-07-15 08:41:56 -07:00
|
|
|
struct z_erofs_bvec *bvec, bool exclusive)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2024-01-25 05:00:39 -07:00
|
|
|
struct z_erofs_pcluster *pcl = fe->pcl;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
int ret;
|
|
|
|
|
2022-07-15 08:41:57 -07:00
|
|
|
if (exclusive) {
|
2022-07-15 08:41:51 -07:00
|
|
|
/* give priority for inplaceio to use file pages first */
|
2024-01-25 05:00:39 -07:00
|
|
|
spin_lock(&pcl->obj.lockref.lock);
|
|
|
|
while (fe->icur > 0) {
|
|
|
|
if (pcl->compressed_bvecs[--fe->icur].page)
|
|
|
|
continue;
|
|
|
|
pcl->compressed_bvecs[fe->icur] = *bvec;
|
|
|
|
spin_unlock(&pcl->obj.lockref.lock);
|
2022-07-15 08:41:51 -07:00
|
|
|
return 0;
|
2024-01-25 05:00:39 -07:00
|
|
|
}
|
|
|
|
spin_unlock(&pcl->obj.lockref.lock);
|
|
|
|
|
2022-07-15 08:41:51 -07:00
|
|
|
/* otherwise, check if it can be used as a bvpage */
|
2022-07-15 08:41:57 -07:00
|
|
|
if (fe->mode >= Z_EROFS_PCLUSTER_FOLLOWED &&
|
2022-07-15 08:41:51 -07:00
|
|
|
!fe->candidate_bvpage)
|
|
|
|
fe->candidate_bvpage = bvec->page;
|
|
|
|
}
|
2023-05-26 13:14:55 -07:00
|
|
|
ret = z_erofs_bvec_enqueue(&fe->biter, bvec, &fe->candidate_bvpage,
|
|
|
|
&fe->pagepool);
|
2022-07-15 08:41:51 -07:00
|
|
|
fe->pcl->vcnt += (ret >= 0);
|
|
|
|
return ret;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2022-07-15 08:41:48 -07:00
|
|
|
static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2022-07-15 08:41:48 -07:00
|
|
|
struct erofs_map_blocks *map = &fe->map;
|
2023-12-06 02:10:54 -07:00
|
|
|
struct super_block *sb = fe->inode->i_sb;
|
2021-12-28 16:29:19 -07:00
|
|
|
bool ztailpacking = map->m_flags & EROFS_MAP_META;
|
2019-07-31 08:57:47 -07:00
|
|
|
struct z_erofs_pcluster *pcl;
|
2020-02-19 19:46:42 -07:00
|
|
|
struct erofs_workgroup *grp;
|
2019-07-31 08:57:47 -07:00
|
|
|
int err;
|
2018-09-18 22:49:07 -07:00
|
|
|
|
2022-12-04 20:49:57 -07:00
|
|
|
if (!(map->m_flags & EROFS_MAP_ENCODED) ||
|
2023-12-06 02:10:54 -07:00
|
|
|
(!ztailpacking && !erofs_blknr(sb, map->m_pa))) {
|
2021-10-08 13:08:37 -07:00
|
|
|
DBG_BUGON(1);
|
|
|
|
return -EFSCORRUPTED;
|
|
|
|
}
|
|
|
|
|
2021-04-06 21:39:20 -07:00
|
|
|
/* no available pcluster, let's allocate one */
|
2023-12-06 02:10:54 -07:00
|
|
|
pcl = z_erofs_alloc_pcluster(map->m_plen);
|
2021-04-06 21:39:20 -07:00
|
|
|
if (IS_ERR(pcl))
|
|
|
|
return PTR_ERR(pcl);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2023-05-29 05:37:27 -07:00
|
|
|
spin_lock_init(&pcl->obj.lockref.lock);
|
2023-10-30 23:05:24 -07:00
|
|
|
pcl->obj.lockref.count = 1; /* one ref for this request */
|
2021-10-08 13:08:37 -07:00
|
|
|
pcl->algorithmformat = map->m_algorithmformat;
|
2022-07-15 08:42:02 -07:00
|
|
|
pcl->length = 0;
|
|
|
|
pcl->partial = true;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2019-07-31 08:57:47 -07:00
|
|
|
/* new pclusters should be claimed as type 1, primary and followed */
|
2022-03-01 12:49:50 -07:00
|
|
|
pcl->next = fe->owned_head;
|
2022-05-28 22:54:23 -07:00
|
|
|
pcl->pageofs_out = map->m_la & ~PAGE_MASK;
|
2022-07-15 08:41:57 -07:00
|
|
|
fe->mode = Z_EROFS_PCLUSTER_FOLLOWED;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2018-11-22 10:21:47 -07:00
|
|
|
/*
|
|
|
|
* lock all primary followed works before visible to others
|
2019-07-31 08:57:47 -07:00
|
|
|
* and mutex_trylock *never* fails for a new pcluster.
|
2018-11-22 10:21:47 -07:00
|
|
|
*/
|
2022-05-28 22:54:23 -07:00
|
|
|
mutex_init(&pcl->lock);
|
|
|
|
DBG_BUGON(!mutex_trylock(&pcl->lock));
|
2020-02-19 19:46:42 -07:00
|
|
|
|
2021-12-28 16:29:19 -07:00
|
|
|
if (ztailpacking) {
|
|
|
|
pcl->obj.index = 0; /* which indicates ztailpacking */
|
|
|
|
} else {
|
2023-12-06 02:10:54 -07:00
|
|
|
pcl->obj.index = erofs_blknr(sb, map->m_pa);
|
2018-11-22 10:21:47 -07:00
|
|
|
|
2022-07-15 08:41:48 -07:00
|
|
|
grp = erofs_insert_workgroup(fe->inode->i_sb, &pcl->obj);
|
2021-12-28 16:29:19 -07:00
|
|
|
if (IS_ERR(grp)) {
|
|
|
|
err = PTR_ERR(grp);
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (grp != &pcl->obj) {
|
2022-03-01 12:49:50 -07:00
|
|
|
fe->pcl = container_of(grp,
|
2021-12-28 16:29:19 -07:00
|
|
|
struct z_erofs_pcluster, obj);
|
|
|
|
err = -EEXIST;
|
|
|
|
goto err_out;
|
|
|
|
}
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
2022-03-01 12:49:50 -07:00
|
|
|
fe->owned_head = &pcl->next;
|
|
|
|
fe->pcl = pcl;
|
2019-10-08 05:56:12 -07:00
|
|
|
return 0;
|
2020-02-19 19:46:42 -07:00
|
|
|
|
|
|
|
err_out:
|
2022-05-28 22:54:23 -07:00
|
|
|
mutex_unlock(&pcl->lock);
|
2021-04-06 21:39:20 -07:00
|
|
|
z_erofs_free_pcluster(pcl);
|
2020-02-19 19:46:42 -07:00
|
|
|
return err;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2023-08-17 01:28:07 -07:00
|
|
|
static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
|
2019-07-31 08:57:47 -07:00
|
|
|
{
|
2022-07-15 08:41:48 -07:00
|
|
|
struct erofs_map_blocks *map = &fe->map;
|
2023-08-17 01:28:08 -07:00
|
|
|
struct super_block *sb = fe->inode->i_sb;
|
|
|
|
erofs_blk_t blknr = erofs_blknr(sb, map->m_pa);
|
2022-07-15 08:41:49 -07:00
|
|
|
struct erofs_workgroup *grp = NULL;
|
2019-10-08 05:56:12 -07:00
|
|
|
int ret;
|
2019-02-26 22:33:32 -07:00
|
|
|
|
2022-05-28 22:54:23 -07:00
|
|
|
DBG_BUGON(fe->pcl);
|
|
|
|
/* must be Z_EROFS_PCLUSTER_TAIL or pointed to previous pcluster */
|
2022-03-01 12:49:50 -07:00
|
|
|
DBG_BUGON(fe->owned_head == Z_EROFS_PCLUSTER_NIL);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-07-15 08:41:49 -07:00
|
|
|
if (!(map->m_flags & EROFS_MAP_META)) {
|
2023-08-17 01:28:08 -07:00
|
|
|
grp = erofs_find_workgroup(sb, blknr);
|
2022-07-15 08:41:49 -07:00
|
|
|
} else if ((map->m_pa & ~PAGE_MASK) + map->m_plen > PAGE_SIZE) {
|
|
|
|
DBG_BUGON(1);
|
|
|
|
return -EFSCORRUPTED;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2020-02-19 19:46:42 -07:00
|
|
|
if (grp) {
|
2022-03-01 12:49:50 -07:00
|
|
|
fe->pcl = container_of(grp, struct z_erofs_pcluster, obj);
|
2022-07-15 08:41:49 -07:00
|
|
|
ret = -EEXIST;
|
2020-02-19 19:46:42 -07:00
|
|
|
} else {
|
2022-07-15 08:41:48 -07:00
|
|
|
ret = z_erofs_register_pcluster(fe);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2022-07-15 08:41:49 -07:00
|
|
|
if (ret == -EEXIST) {
|
2022-07-15 08:42:03 -07:00
|
|
|
mutex_lock(&fe->pcl->lock);
|
2024-10-10 02:04:19 -07:00
|
|
|
/* check if this pcluster hasn't been linked into any chain. */
|
|
|
|
if (cmpxchg(&fe->pcl->next, Z_EROFS_PCLUSTER_NIL,
|
|
|
|
fe->owned_head) == Z_EROFS_PCLUSTER_NIL) {
|
|
|
|
/* .. so it can be attached to our submission chain */
|
|
|
|
fe->owned_head = &fe->pcl->next;
|
|
|
|
fe->mode = Z_EROFS_PCLUSTER_FOLLOWED;
|
|
|
|
} else { /* otherwise, it belongs to an inflight chain */
|
|
|
|
fe->mode = Z_EROFS_PCLUSTER_INFLIGHT;
|
|
|
|
}
|
2022-07-15 08:41:49 -07:00
|
|
|
} else if (ret) {
|
2019-10-08 05:56:12 -07:00
|
|
|
return ret;
|
2020-02-19 19:46:42 -07:00
|
|
|
}
|
2023-08-17 01:28:08 -07:00
|
|
|
|
2022-07-15 08:41:51 -07:00
|
|
|
z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset,
|
2022-07-15 08:41:52 -07:00
|
|
|
Z_EROFS_INLINE_BVECS, fe->pcl->vcnt);
|
2023-08-17 01:28:08 -07:00
|
|
|
if (!z_erofs_is_inline_pcluster(fe->pcl)) {
|
|
|
|
/* bind cache first when cached decompression is preferred */
|
|
|
|
z_erofs_bind_cache(fe);
|
|
|
|
} else {
|
|
|
|
void *mptr;
|
|
|
|
|
2024-04-25 13:00:17 -07:00
|
|
|
mptr = erofs_read_metabuf(&map->buf, sb, map->m_pa, EROFS_NO_KMAP);
|
2023-08-17 01:28:08 -07:00
|
|
|
if (IS_ERR(mptr)) {
|
|
|
|
ret = PTR_ERR(mptr);
|
|
|
|
erofs_err(sb, "failed to get inline data %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
get_page(map->buf.page);
|
|
|
|
WRITE_ONCE(fe->pcl->compressed_bvecs[0].page, map->buf.page);
|
2023-12-14 09:13:37 -07:00
|
|
|
fe->pcl->pageofs_in = map->m_pa & ~PAGE_MASK;
|
2023-08-17 01:28:08 -07:00
|
|
|
fe->mode = Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE;
|
|
|
|
}
|
|
|
|
/* file-backed inplace I/O pages are traversed in reverse order */
|
2022-07-15 08:41:54 -07:00
|
|
|
fe->icur = z_erofs_pclusterpages(fe->pcl);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-07-31 08:57:47 -07:00
|
|
|
* keep in mind that no referenced pclusters will be freed
|
|
|
|
* only after a RCU grace period.
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
*/
|
|
|
|
static void z_erofs_rcu_callback(struct rcu_head *head)
|
|
|
|
{
|
2022-05-28 22:54:23 -07:00
|
|
|
z_erofs_free_pcluster(container_of(head,
|
|
|
|
struct z_erofs_pcluster, rcu));
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void erofs_workgroup_free_rcu(struct erofs_workgroup *grp)
|
|
|
|
{
|
2019-07-31 08:57:47 -07:00
|
|
|
struct z_erofs_pcluster *const pcl =
|
|
|
|
container_of(grp, struct z_erofs_pcluster, obj);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-05-28 22:54:23 -07:00
|
|
|
call_rcu(&pcl->rcu, z_erofs_rcu_callback);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2023-08-17 01:28:07 -07:00
|
|
|
static void z_erofs_pcluster_end(struct z_erofs_decompress_frontend *fe)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2022-05-28 22:54:23 -07:00
|
|
|
struct z_erofs_pcluster *pcl = fe->pcl;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-05-28 22:54:23 -07:00
|
|
|
if (!pcl)
|
2023-08-17 01:28:07 -07:00
|
|
|
return;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-07-15 08:41:51 -07:00
|
|
|
z_erofs_bvec_iter_end(&fe->biter);
|
2022-05-28 22:54:23 -07:00
|
|
|
mutex_unlock(&pcl->lock);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2023-05-26 13:14:54 -07:00
|
|
|
if (fe->candidate_bvpage)
|
2022-07-15 08:41:51 -07:00
|
|
|
fe->candidate_bvpage = NULL;
|
|
|
|
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
/*
|
2019-07-31 08:57:47 -07:00
|
|
|
* if all pending pages are added, don't hold its reference
|
|
|
|
* any longer if the pcluster isn't hosted by ourselves.
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
*/
|
2022-07-15 08:41:57 -07:00
|
|
|
if (fe->mode < Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE)
|
2022-05-28 22:54:23 -07:00
|
|
|
erofs_workgroup_put(&pcl->obj);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-05-28 22:54:23 -07:00
|
|
|
fe->pcl = NULL;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2024-07-03 05:00:49 -07:00
|
|
|
static int z_erofs_read_fragment(struct super_block *sb, struct folio *folio,
|
2023-08-17 01:28:06 -07:00
|
|
|
unsigned int cur, unsigned int end, erofs_off_t pos)
|
2022-09-22 19:11:22 -07:00
|
|
|
{
|
2023-08-17 01:28:06 -07:00
|
|
|
struct inode *packed_inode = EROFS_SB(sb)->packed_inode;
|
2022-09-22 19:11:22 -07:00
|
|
|
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
|
2023-08-17 01:28:06 -07:00
|
|
|
unsigned int cnt;
|
|
|
|
u8 *src;
|
2022-09-22 19:11:22 -07:00
|
|
|
|
2022-10-21 01:53:25 -07:00
|
|
|
if (!packed_inode)
|
|
|
|
return -EFSCORRUPTED;
|
|
|
|
|
2024-04-24 21:15:46 -07:00
|
|
|
buf.mapping = packed_inode->i_mapping;
|
2023-08-17 01:28:06 -07:00
|
|
|
for (; cur < end; cur += cnt, pos += cnt) {
|
2024-07-03 05:00:49 -07:00
|
|
|
cnt = min(end - cur, sb->s_blocksize - erofs_blkoff(sb, pos));
|
2024-04-07 00:04:50 -07:00
|
|
|
src = erofs_bread(&buf, pos, EROFS_KMAP);
|
2022-09-22 19:11:22 -07:00
|
|
|
if (IS_ERR(src)) {
|
|
|
|
erofs_put_metabuf(&buf);
|
|
|
|
return PTR_ERR(src);
|
|
|
|
}
|
2024-07-03 05:00:49 -07:00
|
|
|
memcpy_to_folio(folio, cur, src, cnt);
|
2022-09-22 19:11:22 -07:00
|
|
|
}
|
|
|
|
erofs_put_metabuf(&buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-07-03 05:00:50 -07:00
|
|
|
static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,
|
2024-03-05 02:14:44 -07:00
|
|
|
struct folio *folio, bool ra)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2024-07-03 05:00:50 -07:00
|
|
|
struct inode *const inode = f->inode;
|
|
|
|
struct erofs_map_blocks *const map = &f->map;
|
2024-03-05 02:14:44 -07:00
|
|
|
const loff_t offset = folio_pos(folio);
|
2024-07-03 05:00:50 -07:00
|
|
|
const unsigned int bs = i_blocksize(inode);
|
|
|
|
unsigned int end = folio_size(folio), split = 0, cur, pgs;
|
|
|
|
bool tight, excl;
|
2024-07-12 18:04:16 -07:00
|
|
|
int err = 0;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2024-07-03 05:00:50 -07:00
|
|
|
tight = (bs == PAGE_SIZE);
|
2024-09-05 02:30:31 -07:00
|
|
|
erofs_onlinefolio_init(folio);
|
2024-07-03 05:00:50 -07:00
|
|
|
do {
|
|
|
|
if (offset + end - 1 < map->m_la ||
|
|
|
|
offset + end - 1 >= map->m_la + map->m_llen) {
|
|
|
|
z_erofs_pcluster_end(f);
|
|
|
|
map->m_la = offset + end - 1;
|
|
|
|
map->m_llen = 0;
|
|
|
|
err = z_erofs_map_blocks_iter(inode, map, 0);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
2023-08-17 01:28:09 -07:00
|
|
|
|
2024-07-03 05:00:50 -07:00
|
|
|
cur = offset > map->m_la ? 0 : map->m_la - offset;
|
|
|
|
pgs = round_down(cur, PAGE_SIZE);
|
|
|
|
/* bump split parts first to avoid several separate cases */
|
|
|
|
++split;
|
|
|
|
|
|
|
|
if (!(map->m_flags & EROFS_MAP_MAPPED)) {
|
|
|
|
folio_zero_segment(folio, cur, end);
|
|
|
|
tight = false;
|
|
|
|
} else if (map->m_flags & EROFS_MAP_FRAGMENT) {
|
|
|
|
erofs_off_t fpos = offset + cur - map->m_la;
|
|
|
|
|
|
|
|
err = z_erofs_read_fragment(inode->i_sb, folio, cur,
|
|
|
|
cur + min(map->m_llen - fpos, end - cur),
|
|
|
|
EROFS_I(inode)->z_fragmentoff + fpos);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
tight = false;
|
|
|
|
} else {
|
|
|
|
if (!f->pcl) {
|
|
|
|
err = z_erofs_pcluster_begin(f);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
f->pcl->besteffort |= !ra;
|
|
|
|
}
|
2022-09-22 19:11:22 -07:00
|
|
|
|
2024-07-03 05:00:50 -07:00
|
|
|
pgs = round_down(end - 1, PAGE_SIZE);
|
|
|
|
/*
|
|
|
|
* Ensure this partial page belongs to this submit chain
|
|
|
|
* rather than other concurrent submit chains or
|
|
|
|
* noio(bypass) chains since those chains are handled
|
|
|
|
* asynchronously thus it cannot be used for inplace I/O
|
|
|
|
* or bvpage (should be processed in the strict order.)
|
|
|
|
*/
|
|
|
|
tight &= (f->mode >= Z_EROFS_PCLUSTER_FOLLOWED);
|
|
|
|
excl = false;
|
|
|
|
if (cur <= pgs) {
|
|
|
|
excl = (split <= 1) || tight;
|
|
|
|
cur = pgs;
|
|
|
|
}
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2024-07-03 05:00:50 -07:00
|
|
|
err = z_erofs_attach_page(f, &((struct z_erofs_bvec) {
|
|
|
|
.page = folio_page(folio, pgs >> PAGE_SHIFT),
|
|
|
|
.offset = offset + pgs - map->m_la,
|
|
|
|
.end = end - pgs, }), excl);
|
|
|
|
if (err)
|
|
|
|
break;
|
2023-08-17 01:28:09 -07:00
|
|
|
|
2024-09-05 02:30:31 -07:00
|
|
|
erofs_onlinefolio_split(folio);
|
2024-07-03 05:00:50 -07:00
|
|
|
if (f->pcl->pageofs_out != (map->m_la & ~PAGE_MASK))
|
|
|
|
f->pcl->multibases = true;
|
|
|
|
if (f->pcl->length < offset + end - map->m_la) {
|
|
|
|
f->pcl->length = offset + end - map->m_la;
|
|
|
|
f->pcl->pageofs_out = map->m_la & ~PAGE_MASK;
|
|
|
|
}
|
|
|
|
if ((map->m_flags & EROFS_MAP_FULL_MAPPED) &&
|
|
|
|
!(map->m_flags & EROFS_MAP_PARTIAL_REF) &&
|
|
|
|
f->pcl->length == map->m_llen)
|
|
|
|
f->pcl->partial = false;
|
|
|
|
}
|
|
|
|
/* shorten the remaining extent to update progress */
|
|
|
|
map->m_llen = offset + cur - map->m_la;
|
|
|
|
map->m_flags &= ~EROFS_MAP_FULL_MAPPED;
|
|
|
|
if (cur <= pgs) {
|
|
|
|
split = cur < pgs;
|
|
|
|
tight = (bs == PAGE_SIZE);
|
|
|
|
}
|
|
|
|
} while ((end = cur) > 0);
|
2024-09-05 02:30:31 -07:00
|
|
|
erofs_onlinefolio_end(folio, err);
|
2018-09-18 07:27:25 -07:00
|
|
|
return err;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2023-05-23 23:39:44 -07:00
|
|
|
static bool z_erofs_is_sync_decompress(struct erofs_sb_info *sbi,
|
2021-12-06 07:35:52 -07:00
|
|
|
unsigned int readahead_pages)
|
|
|
|
{
|
2022-04-29 08:12:16 -07:00
|
|
|
/* auto: enable for read_folio, disable for readahead */
|
2021-12-06 07:35:52 -07:00
|
|
|
if ((sbi->opt.sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO) &&
|
|
|
|
!readahead_pages)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ((sbi->opt.sync_decompress == EROFS_SYNC_DECOMPRESS_FORCE_ON) &&
|
|
|
|
(readahead_pages <= sbi->opt.max_sync_decompress_pages))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-08 02:58:32 -07:00
|
|
|
static bool z_erofs_page_is_invalidated(struct page *page)
|
|
|
|
{
|
2024-07-03 05:00:51 -07:00
|
|
|
return !page_folio(page)->mapping && !z_erofs_is_shortlived_page(page);
|
2020-12-08 02:58:32 -07:00
|
|
|
}
|
|
|
|
|
2022-07-15 08:41:59 -07:00
|
|
|
struct z_erofs_decompress_backend {
|
|
|
|
struct page *onstack_pages[Z_EROFS_ONSTACK_PAGES];
|
|
|
|
struct super_block *sb;
|
|
|
|
struct z_erofs_pcluster *pcl;
|
|
|
|
|
|
|
|
/* pages with the longest decompressed length for deduplication */
|
|
|
|
struct page **decompressed_pages;
|
|
|
|
/* pages to keep the compressed data */
|
|
|
|
struct page **compressed_pages;
|
|
|
|
|
2022-07-15 08:42:03 -07:00
|
|
|
struct list_head decompressed_secondary_bvecs;
|
2022-07-15 08:41:59 -07:00
|
|
|
struct page **pagepool;
|
2022-07-15 08:42:02 -07:00
|
|
|
unsigned int onstack_used, nr_pages;
|
2022-07-15 08:41:59 -07:00
|
|
|
};
|
|
|
|
|
2022-07-15 08:42:03 -07:00
|
|
|
struct z_erofs_bvec_item {
|
|
|
|
struct z_erofs_bvec bvec;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend *be,
|
|
|
|
struct z_erofs_bvec *bvec)
|
2022-07-15 08:42:01 -07:00
|
|
|
{
|
2022-07-15 08:42:03 -07:00
|
|
|
struct z_erofs_bvec_item *item;
|
2023-07-18 23:54:59 -07:00
|
|
|
unsigned int pgnr;
|
2022-07-15 08:42:01 -07:00
|
|
|
|
2023-07-18 23:54:59 -07:00
|
|
|
if (!((bvec->offset + be->pcl->pageofs_out) & ~PAGE_MASK) &&
|
|
|
|
(bvec->end == PAGE_SIZE ||
|
|
|
|
bvec->offset + bvec->end == be->pcl->length)) {
|
2022-07-15 08:42:03 -07:00
|
|
|
pgnr = (bvec->offset + be->pcl->pageofs_out) >> PAGE_SHIFT;
|
|
|
|
DBG_BUGON(pgnr >= be->nr_pages);
|
2022-10-11 21:50:56 -07:00
|
|
|
if (!be->decompressed_pages[pgnr]) {
|
|
|
|
be->decompressed_pages[pgnr] = bvec->page;
|
2022-07-15 08:42:03 -07:00
|
|
|
return;
|
2022-10-11 21:50:56 -07:00
|
|
|
}
|
2022-07-15 08:42:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (cold path) one pcluster is requested multiple times */
|
|
|
|
item = kmalloc(sizeof(*item), GFP_KERNEL | __GFP_NOFAIL);
|
|
|
|
item->bvec = *bvec;
|
|
|
|
list_add(&item->list, &be->decompressed_secondary_bvecs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void z_erofs_fill_other_copies(struct z_erofs_decompress_backend *be,
|
|
|
|
int err)
|
|
|
|
{
|
|
|
|
unsigned int off0 = be->pcl->pageofs_out;
|
|
|
|
struct list_head *p, *n;
|
|
|
|
|
|
|
|
list_for_each_safe(p, n, &be->decompressed_secondary_bvecs) {
|
|
|
|
struct z_erofs_bvec_item *bvi;
|
|
|
|
unsigned int end, cur;
|
|
|
|
void *dst, *src;
|
|
|
|
|
|
|
|
bvi = container_of(p, struct z_erofs_bvec_item, list);
|
|
|
|
cur = bvi->bvec.offset < 0 ? -bvi->bvec.offset : 0;
|
|
|
|
end = min_t(unsigned int, be->pcl->length - bvi->bvec.offset,
|
|
|
|
bvi->bvec.end);
|
|
|
|
dst = kmap_local_page(bvi->bvec.page);
|
|
|
|
while (cur < end) {
|
|
|
|
unsigned int pgnr, scur, len;
|
|
|
|
|
|
|
|
pgnr = (bvi->bvec.offset + cur + off0) >> PAGE_SHIFT;
|
|
|
|
DBG_BUGON(pgnr >= be->nr_pages);
|
|
|
|
|
|
|
|
scur = bvi->bvec.offset + cur -
|
|
|
|
((pgnr << PAGE_SHIFT) - off0);
|
|
|
|
len = min_t(unsigned int, end - cur, PAGE_SIZE - scur);
|
|
|
|
if (!be->decompressed_pages[pgnr]) {
|
|
|
|
err = -EFSCORRUPTED;
|
|
|
|
cur += len;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
src = kmap_local_page(be->decompressed_pages[pgnr]);
|
|
|
|
memcpy(dst + cur, src + scur, len);
|
|
|
|
kunmap_local(src);
|
|
|
|
cur += len;
|
|
|
|
}
|
|
|
|
kunmap_local(dst);
|
2024-09-05 02:30:31 -07:00
|
|
|
erofs_onlinefolio_end(page_folio(bvi->bvec.page), err);
|
2022-07-15 08:42:03 -07:00
|
|
|
list_del(p);
|
|
|
|
kfree(bvi);
|
2022-07-15 08:42:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 08:42:03 -07:00
|
|
|
static void z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be)
|
2022-07-15 08:41:50 -07:00
|
|
|
{
|
2022-07-15 08:41:59 -07:00
|
|
|
struct z_erofs_pcluster *pcl = be->pcl;
|
2022-07-15 08:41:51 -07:00
|
|
|
struct z_erofs_bvec_iter biter;
|
|
|
|
struct page *old_bvpage;
|
2022-07-15 08:42:03 -07:00
|
|
|
int i;
|
2022-07-15 08:41:50 -07:00
|
|
|
|
2022-07-15 08:41:52 -07:00
|
|
|
z_erofs_bvec_iter_begin(&biter, &pcl->bvset, Z_EROFS_INLINE_BVECS, 0);
|
2022-07-15 08:41:50 -07:00
|
|
|
for (i = 0; i < pcl->vcnt; ++i) {
|
2022-07-15 08:41:51 -07:00
|
|
|
struct z_erofs_bvec bvec;
|
2022-07-15 08:41:50 -07:00
|
|
|
|
2022-07-15 08:41:51 -07:00
|
|
|
z_erofs_bvec_dequeue(&biter, &bvec, &old_bvpage);
|
2022-07-15 08:41:50 -07:00
|
|
|
|
2022-07-15 08:41:51 -07:00
|
|
|
if (old_bvpage)
|
2022-07-15 08:41:59 -07:00
|
|
|
z_erofs_put_shortlivedpage(be->pagepool, old_bvpage);
|
2022-07-15 08:41:50 -07:00
|
|
|
|
2022-07-15 08:41:51 -07:00
|
|
|
DBG_BUGON(z_erofs_page_is_invalidated(bvec.page));
|
2022-07-15 08:42:03 -07:00
|
|
|
z_erofs_do_decompressed_bvec(be, &bvec);
|
2022-07-15 08:41:50 -07:00
|
|
|
}
|
2022-07-15 08:41:51 -07:00
|
|
|
|
|
|
|
old_bvpage = z_erofs_bvec_iter_end(&biter);
|
|
|
|
if (old_bvpage)
|
2022-07-15 08:41:59 -07:00
|
|
|
z_erofs_put_shortlivedpage(be->pagepool, old_bvpage);
|
2022-07-15 08:41:50 -07:00
|
|
|
}
|
|
|
|
|
2022-07-15 08:41:59 -07:00
|
|
|
static int z_erofs_parse_in_bvecs(struct z_erofs_decompress_backend *be,
|
|
|
|
bool *overlapped)
|
2022-07-15 08:41:53 -07:00
|
|
|
{
|
2022-07-15 08:41:59 -07:00
|
|
|
struct z_erofs_pcluster *pcl = be->pcl;
|
2022-07-15 08:41:53 -07:00
|
|
|
unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
*overlapped = false;
|
|
|
|
for (i = 0; i < pclusterpages; ++i) {
|
2022-07-15 08:41:54 -07:00
|
|
|
struct z_erofs_bvec *bvec = &pcl->compressed_bvecs[i];
|
|
|
|
struct page *page = bvec->page;
|
2022-07-15 08:41:53 -07:00
|
|
|
|
2024-09-05 01:47:32 -07:00
|
|
|
/* compressed data ought to be valid when decompressing */
|
|
|
|
if (IS_ERR(page) || !page) {
|
|
|
|
bvec->page = NULL; /* clear the failure reason */
|
|
|
|
err = page ? PTR_ERR(page) : -EIO;
|
2022-07-15 08:41:53 -07:00
|
|
|
continue;
|
|
|
|
}
|
2022-07-15 08:42:00 -07:00
|
|
|
be->compressed_pages[i] = page;
|
2022-07-15 08:41:53 -07:00
|
|
|
|
2023-12-20 23:23:41 -07:00
|
|
|
if (z_erofs_is_inline_pcluster(pcl) ||
|
2024-03-05 02:14:48 -07:00
|
|
|
erofs_folio_is_managed(EROFS_SB(be->sb), page_folio(page))) {
|
2022-07-15 08:41:53 -07:00
|
|
|
if (!PageUptodate(page))
|
|
|
|
err = -EIO;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG_BUGON(z_erofs_page_is_invalidated(page));
|
2023-12-20 23:23:41 -07:00
|
|
|
if (z_erofs_is_shortlived_page(page))
|
|
|
|
continue;
|
|
|
|
z_erofs_do_decompressed_bvec(be, bvec);
|
|
|
|
*overlapped = true;
|
2022-07-15 08:41:53 -07:00
|
|
|
}
|
2023-12-20 23:23:41 -07:00
|
|
|
return err;
|
2022-07-15 08:41:53 -07:00
|
|
|
}
|
|
|
|
|
2022-07-15 08:41:59 -07:00
|
|
|
static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
|
|
|
|
int err)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2022-07-15 08:41:59 -07:00
|
|
|
struct erofs_sb_info *const sbi = EROFS_SB(be->sb);
|
|
|
|
struct z_erofs_pcluster *pcl = be->pcl;
|
2021-12-28 16:29:19 -07:00
|
|
|
unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
|
2023-12-20 23:23:41 -07:00
|
|
|
const struct z_erofs_decompressor *decomp =
|
2024-07-09 02:41:04 -07:00
|
|
|
z_erofs_decomp[pcl->algorithmformat];
|
2024-07-10 22:36:59 -07:00
|
|
|
int i, j, jtop, err2;
|
2022-07-15 08:42:02 -07:00
|
|
|
struct page *page;
|
|
|
|
bool overlapped;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-05-28 22:54:23 -07:00
|
|
|
mutex_lock(&pcl->lock);
|
2022-07-15 08:42:02 -07:00
|
|
|
be->nr_pages = PAGE_ALIGN(pcl->length + pcl->pageofs_out) >> PAGE_SHIFT;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-07-15 08:42:00 -07:00
|
|
|
/* allocate (de)compressed page arrays if cannot be kept on stack */
|
|
|
|
be->decompressed_pages = NULL;
|
|
|
|
be->compressed_pages = NULL;
|
|
|
|
be->onstack_used = 0;
|
2022-07-15 08:42:02 -07:00
|
|
|
if (be->nr_pages <= Z_EROFS_ONSTACK_PAGES) {
|
2022-07-15 08:41:59 -07:00
|
|
|
be->decompressed_pages = be->onstack_pages;
|
2022-07-15 08:42:02 -07:00
|
|
|
be->onstack_used = be->nr_pages;
|
2022-07-15 08:41:59 -07:00
|
|
|
memset(be->decompressed_pages, 0,
|
2022-07-15 08:42:02 -07:00
|
|
|
sizeof(struct page *) * be->nr_pages);
|
2022-07-15 08:42:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pclusterpages + be->onstack_used <= Z_EROFS_ONSTACK_PAGES)
|
|
|
|
be->compressed_pages = be->onstack_pages + be->onstack_used;
|
|
|
|
|
|
|
|
if (!be->decompressed_pages)
|
2022-07-15 08:41:59 -07:00
|
|
|
be->decompressed_pages =
|
2023-03-08 22:31:47 -07:00
|
|
|
kvcalloc(be->nr_pages, sizeof(struct page *),
|
|
|
|
GFP_KERNEL | __GFP_NOFAIL);
|
2022-07-15 08:42:00 -07:00
|
|
|
if (!be->compressed_pages)
|
|
|
|
be->compressed_pages =
|
2023-03-08 22:31:47 -07:00
|
|
|
kvcalloc(pclusterpages, sizeof(struct page *),
|
|
|
|
GFP_KERNEL | __GFP_NOFAIL);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-07-15 08:42:03 -07:00
|
|
|
z_erofs_parse_out_bvecs(be);
|
2022-07-15 08:41:59 -07:00
|
|
|
err2 = z_erofs_parse_in_bvecs(be, &overlapped);
|
2022-07-15 08:41:55 -07:00
|
|
|
if (err2)
|
|
|
|
err = err2;
|
2023-12-20 23:23:41 -07:00
|
|
|
if (!err)
|
|
|
|
err = decomp->decompress(&(struct z_erofs_decompress_req) {
|
2022-07-15 08:41:59 -07:00
|
|
|
.sb = be->sb,
|
|
|
|
.in = be->compressed_pages,
|
|
|
|
.out = be->decompressed_pages,
|
2021-12-28 16:29:19 -07:00
|
|
|
.pageofs_in = pcl->pageofs_in,
|
2022-05-28 22:54:23 -07:00
|
|
|
.pageofs_out = pcl->pageofs_out,
|
2023-12-06 02:10:54 -07:00
|
|
|
.inputsize = pcl->pclustersize,
|
2022-07-15 08:42:02 -07:00
|
|
|
.outputsize = pcl->length,
|
2019-07-31 08:57:47 -07:00
|
|
|
.alg = pcl->algorithmformat,
|
2019-06-24 00:22:57 -07:00
|
|
|
.inplace_io = overlapped,
|
2022-07-15 08:42:02 -07:00
|
|
|
.partial_decoding = pcl->partial,
|
2022-07-15 08:42:03 -07:00
|
|
|
.fillgaps = pcl->multibases,
|
2024-09-05 01:47:32 -07:00
|
|
|
.gfp = pcl->besteffort ? GFP_KERNEL :
|
2024-01-26 07:01:42 -07:00
|
|
|
GFP_NOWAIT | __GFP_NORETRY
|
2022-07-15 08:41:59 -07:00
|
|
|
}, be->pagepool);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2021-12-28 16:29:19 -07:00
|
|
|
/* must handle all compressed pages before actual file pages */
|
|
|
|
if (z_erofs_is_inline_pcluster(pcl)) {
|
2022-07-15 08:41:54 -07:00
|
|
|
page = pcl->compressed_bvecs[0].page;
|
|
|
|
WRITE_ONCE(pcl->compressed_bvecs[0].page, NULL);
|
2021-12-28 16:29:19 -07:00
|
|
|
put_page(page);
|
|
|
|
} else {
|
2024-07-10 22:36:59 -07:00
|
|
|
/* managed folios are still left in compressed_bvecs[] */
|
2021-12-28 16:29:19 -07:00
|
|
|
for (i = 0; i < pclusterpages; ++i) {
|
2023-11-28 11:04:31 -07:00
|
|
|
page = be->compressed_pages[i];
|
2024-03-05 02:14:48 -07:00
|
|
|
if (!page ||
|
|
|
|
erofs_folio_is_managed(sbi, page_folio(page)))
|
2021-12-28 16:29:19 -07:00
|
|
|
continue;
|
2022-07-15 08:41:59 -07:00
|
|
|
(void)z_erofs_put_shortlivedpage(be->pagepool, page);
|
2022-07-15 08:41:54 -07:00
|
|
|
WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
|
2021-12-28 16:29:19 -07:00
|
|
|
}
|
2019-02-26 22:33:30 -07:00
|
|
|
}
|
2022-07-15 08:42:00 -07:00
|
|
|
if (be->compressed_pages < be->onstack_pages ||
|
|
|
|
be->compressed_pages >= be->onstack_pages + Z_EROFS_ONSTACK_PAGES)
|
2023-03-08 22:31:47 -07:00
|
|
|
kvfree(be->compressed_pages);
|
2019-02-26 22:33:30 -07:00
|
|
|
|
2024-07-10 22:36:59 -07:00
|
|
|
jtop = 0;
|
|
|
|
z_erofs_fill_other_copies(be, err);
|
2022-07-15 08:42:02 -07:00
|
|
|
for (i = 0; i < be->nr_pages; ++i) {
|
2022-07-15 08:41:59 -07:00
|
|
|
page = be->decompressed_pages[i];
|
2019-02-26 22:33:30 -07:00
|
|
|
if (!page)
|
|
|
|
continue;
|
|
|
|
|
2020-12-08 02:58:32 -07:00
|
|
|
DBG_BUGON(z_erofs_page_is_invalidated(page));
|
2024-07-10 22:36:59 -07:00
|
|
|
if (!z_erofs_is_shortlived_page(page)) {
|
2024-09-05 02:30:31 -07:00
|
|
|
erofs_onlinefolio_end(page_folio(page), err);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
continue;
|
2024-07-10 22:36:59 -07:00
|
|
|
}
|
|
|
|
if (pcl->algorithmformat != Z_EROFS_COMPRESSION_LZ4) {
|
|
|
|
erofs_pagepool_add(be->pagepool, page);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (j = 0; j < jtop && be->decompressed_pages[j] != page; ++j)
|
|
|
|
;
|
|
|
|
if (j >= jtop) /* this bounce page is newly detected */
|
|
|
|
be->decompressed_pages[jtop++] = page;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
2024-07-10 22:36:59 -07:00
|
|
|
while (jtop)
|
|
|
|
erofs_pagepool_add(be->pagepool,
|
|
|
|
be->decompressed_pages[--jtop]);
|
2022-07-15 08:41:59 -07:00
|
|
|
if (be->decompressed_pages != be->onstack_pages)
|
2023-03-08 22:31:47 -07:00
|
|
|
kvfree(be->decompressed_pages);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-07-15 08:42:02 -07:00
|
|
|
pcl->length = 0;
|
|
|
|
pcl->partial = true;
|
2022-07-15 08:42:03 -07:00
|
|
|
pcl->multibases = false;
|
2024-01-26 07:01:42 -07:00
|
|
|
pcl->besteffort = false;
|
2022-07-15 08:41:51 -07:00
|
|
|
pcl->bvset.nextpage = NULL;
|
2022-05-28 22:54:23 -07:00
|
|
|
pcl->vcnt = 0;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-05-28 22:54:23 -07:00
|
|
|
/* pcluster lock MUST be taken before the following line */
|
2019-07-31 08:57:47 -07:00
|
|
|
WRITE_ONCE(pcl->next, Z_EROFS_PCLUSTER_NIL);
|
2022-05-28 22:54:23 -07:00
|
|
|
mutex_unlock(&pcl->lock);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2024-09-05 01:47:32 -07:00
|
|
|
static int z_erofs_decompress_queue(const struct z_erofs_decompressqueue *io,
|
|
|
|
struct page **pagepool)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2022-07-15 08:41:59 -07:00
|
|
|
struct z_erofs_decompress_backend be = {
|
|
|
|
.sb = io->sb,
|
|
|
|
.pagepool = pagepool,
|
2022-07-15 08:42:03 -07:00
|
|
|
.decompressed_secondary_bvecs =
|
|
|
|
LIST_HEAD_INIT(be.decompressed_secondary_bvecs),
|
2022-07-15 08:41:59 -07:00
|
|
|
};
|
2019-07-31 08:57:47 -07:00
|
|
|
z_erofs_next_pcluster_t owned = io->head;
|
2024-09-05 01:47:32 -07:00
|
|
|
int err = io->eio ? -EIO : 0;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2023-05-26 13:14:56 -07:00
|
|
|
while (owned != Z_EROFS_PCLUSTER_TAIL) {
|
2019-07-31 08:57:47 -07:00
|
|
|
DBG_BUGON(owned == Z_EROFS_PCLUSTER_NIL);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-07-15 08:41:59 -07:00
|
|
|
be.pcl = container_of(owned, struct z_erofs_pcluster, next);
|
|
|
|
owned = READ_ONCE(be.pcl->next);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2024-09-05 01:47:32 -07:00
|
|
|
err = z_erofs_decompress_pcluster(&be, err) ?: err;
|
2023-08-22 04:05:30 -07:00
|
|
|
if (z_erofs_is_inline_pcluster(be.pcl))
|
|
|
|
z_erofs_free_pcluster(be.pcl);
|
|
|
|
else
|
|
|
|
erofs_workgroup_put(&be.pcl->obj);
|
2018-08-05 20:27:53 -07:00
|
|
|
}
|
2024-09-05 01:47:32 -07:00
|
|
|
return err;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2019-11-07 20:37:33 -07:00
|
|
|
static void z_erofs_decompressqueue_work(struct work_struct *work)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2019-10-08 05:56:15 -07:00
|
|
|
struct z_erofs_decompressqueue *bgq =
|
|
|
|
container_of(work, struct z_erofs_decompressqueue, u.work);
|
2021-10-22 02:01:20 -07:00
|
|
|
struct page *pagepool = NULL;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2023-05-26 13:14:56 -07:00
|
|
|
DBG_BUGON(bgq->head == Z_EROFS_PCLUSTER_TAIL);
|
2019-11-07 20:37:33 -07:00
|
|
|
z_erofs_decompress_queue(bgq, &pagepool);
|
2021-10-22 02:01:20 -07:00
|
|
|
erofs_release_pages(&pagepool);
|
2019-10-08 05:56:15 -07:00
|
|
|
kvfree(bgq);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2023-02-08 02:33:22 -07:00
|
|
|
#ifdef CONFIG_EROFS_FS_PCPU_KTHREAD
|
|
|
|
static void z_erofs_decompressqueue_kthread_work(struct kthread_work *work)
|
|
|
|
{
|
|
|
|
z_erofs_decompressqueue_work((struct work_struct *)work);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-21 02:14:12 -07:00
|
|
|
static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,
|
2023-02-04 02:30:36 -07:00
|
|
|
int bios)
|
2022-01-21 02:14:12 -07:00
|
|
|
{
|
|
|
|
struct erofs_sb_info *const sbi = EROFS_SB(io->sb);
|
|
|
|
|
|
|
|
/* wake up the caller thread for sync decompression */
|
2023-02-04 02:30:36 -07:00
|
|
|
if (io->sync) {
|
2022-01-21 02:14:12 -07:00
|
|
|
if (!atomic_add_return(bios, &io->pending_bios))
|
2022-04-01 04:55:27 -07:00
|
|
|
complete(&io->u.done);
|
2022-01-21 02:14:12 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atomic_add_return(bios, &io->pending_bios))
|
|
|
|
return;
|
2023-02-08 02:33:22 -07:00
|
|
|
/* Use (kthread_)work and sync decompression for atomic contexts only */
|
2023-06-21 15:08:47 -07:00
|
|
|
if (!in_task() || irqs_disabled() || rcu_read_lock_any_held()) {
|
2023-02-08 02:33:22 -07:00
|
|
|
#ifdef CONFIG_EROFS_FS_PCPU_KTHREAD
|
|
|
|
struct kthread_worker *worker;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
worker = rcu_dereference(
|
|
|
|
z_erofs_pcpu_workers[raw_smp_processor_id()]);
|
|
|
|
if (!worker) {
|
|
|
|
INIT_WORK(&io->u.work, z_erofs_decompressqueue_work);
|
|
|
|
queue_work(z_erofs_workqueue, &io->u.work);
|
|
|
|
} else {
|
|
|
|
kthread_queue_work(worker, &io->u.kthread_work);
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
#else
|
2022-01-21 02:14:12 -07:00
|
|
|
queue_work(z_erofs_workqueue, &io->u.work);
|
2023-02-08 02:33:22 -07:00
|
|
|
#endif
|
2022-01-21 02:14:12 -07:00
|
|
|
/* enable sync decompression for readahead */
|
|
|
|
if (sbi->opt.sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO)
|
|
|
|
sbi->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_ON;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
z_erofs_decompressqueue_work(&io->u.work);
|
|
|
|
}
|
|
|
|
|
2023-12-06 02:10:53 -07:00
|
|
|
static void z_erofs_fill_bio_vec(struct bio_vec *bvec,
|
|
|
|
struct z_erofs_decompress_frontend *f,
|
|
|
|
struct z_erofs_pcluster *pcl,
|
|
|
|
unsigned int nr,
|
|
|
|
struct address_space *mc)
|
2018-12-07 09:19:15 -07:00
|
|
|
{
|
2022-03-10 11:27:43 -07:00
|
|
|
gfp_t gfp = mapping_gfp_mask(mc);
|
2018-12-07 09:19:15 -07:00
|
|
|
bool tocache = false;
|
2024-01-25 05:00:39 -07:00
|
|
|
struct z_erofs_bvec zbv;
|
2018-12-07 09:19:15 -07:00
|
|
|
struct address_space *mapping;
|
2024-07-03 05:00:51 -07:00
|
|
|
struct folio *folio;
|
2024-09-10 00:08:47 -07:00
|
|
|
struct page *page;
|
2024-03-05 02:14:45 -07:00
|
|
|
int bs = i_blocksize(f->inode);
|
2018-12-07 09:19:16 -07:00
|
|
|
|
2024-03-05 02:14:46 -07:00
|
|
|
/* Except for inplace folios, the entire folio can be used for I/Os */
|
2023-12-06 02:10:53 -07:00
|
|
|
bvec->bv_offset = 0;
|
|
|
|
bvec->bv_len = PAGE_SIZE;
|
2018-12-07 09:19:15 -07:00
|
|
|
repeat:
|
2024-01-25 05:00:39 -07:00
|
|
|
spin_lock(&pcl->obj.lockref.lock);
|
|
|
|
zbv = pcl->compressed_bvecs[nr];
|
|
|
|
spin_unlock(&pcl->obj.lockref.lock);
|
2024-07-03 05:00:51 -07:00
|
|
|
if (!zbv.page)
|
2024-03-05 02:14:46 -07:00
|
|
|
goto out_allocfolio;
|
2018-12-07 09:19:15 -07:00
|
|
|
|
2024-07-03 05:00:51 -07:00
|
|
|
bvec->bv_page = zbv.page;
|
2024-03-05 02:14:46 -07:00
|
|
|
DBG_BUGON(z_erofs_is_shortlived_page(bvec->bv_page));
|
2024-07-03 05:00:51 -07:00
|
|
|
|
|
|
|
folio = page_folio(zbv.page);
|
2020-12-09 05:37:17 -07:00
|
|
|
/*
|
2024-03-05 02:14:46 -07:00
|
|
|
* Handle preallocated cached folios. We tried to allocate such folios
|
2023-12-06 02:10:53 -07:00
|
|
|
* without triggering direct reclaim. If allocation failed, inplace
|
2024-03-05 02:14:46 -07:00
|
|
|
* file-backed folios will be used instead.
|
2020-12-09 05:37:17 -07:00
|
|
|
*/
|
2024-07-03 05:00:51 -07:00
|
|
|
if (folio->private == (void *)Z_EROFS_PREALLOCATED_PAGE) {
|
2020-12-09 05:37:17 -07:00
|
|
|
tocache = true;
|
|
|
|
goto out_tocache;
|
|
|
|
}
|
2018-12-07 09:19:15 -07:00
|
|
|
|
2024-07-03 05:00:51 -07:00
|
|
|
mapping = READ_ONCE(folio->mapping);
|
2018-12-07 09:19:15 -07:00
|
|
|
/*
|
2024-03-05 02:14:46 -07:00
|
|
|
* File-backed folios for inplace I/Os are all locked steady,
|
2023-12-06 02:10:53 -07:00
|
|
|
* therefore it is impossible for `mapping` to be NULL.
|
2018-12-07 09:19:15 -07:00
|
|
|
*/
|
2023-12-06 02:10:53 -07:00
|
|
|
if (mapping && mapping != mc) {
|
2024-01-25 05:00:39 -07:00
|
|
|
if (zbv.offset < 0)
|
|
|
|
bvec->bv_offset = round_up(-zbv.offset, bs);
|
|
|
|
bvec->bv_len = round_up(zbv.end, bs) - bvec->bv_offset;
|
2023-12-06 02:10:53 -07:00
|
|
|
return;
|
|
|
|
}
|
2020-12-08 02:58:32 -07:00
|
|
|
|
2024-07-03 05:00:51 -07:00
|
|
|
folio_lock(folio);
|
2024-09-10 00:08:47 -07:00
|
|
|
if (likely(folio->mapping == mc)) {
|
2023-12-06 02:10:53 -07:00
|
|
|
/*
|
2024-03-05 02:14:46 -07:00
|
|
|
* The cached folio is still in managed cache but without
|
|
|
|
* a valid `->private` pcluster hint. Let's reconnect them.
|
2023-12-06 02:10:53 -07:00
|
|
|
*/
|
2024-07-03 05:00:51 -07:00
|
|
|
if (!folio_test_private(folio)) {
|
|
|
|
folio_attach_private(folio, pcl);
|
2024-03-05 02:14:46 -07:00
|
|
|
/* compressed_bvecs[] already takes a ref before */
|
2024-07-03 05:00:51 -07:00
|
|
|
folio_put(folio);
|
2018-12-07 09:19:15 -07:00
|
|
|
}
|
2024-09-10 00:08:47 -07:00
|
|
|
if (likely(folio->private == pcl)) {
|
|
|
|
/* don't submit cache I/Os again if already uptodate */
|
|
|
|
if (folio_test_uptodate(folio)) {
|
|
|
|
folio_unlock(folio);
|
|
|
|
bvec->bv_page = NULL;
|
|
|
|
}
|
|
|
|
return;
|
2018-12-07 09:19:15 -07:00
|
|
|
}
|
2024-09-10 00:08:47 -07:00
|
|
|
/*
|
|
|
|
* Already linked with another pcluster, which only appears in
|
|
|
|
* crafted images by fuzzers for now. But handle this anyway.
|
|
|
|
*/
|
|
|
|
tocache = false; /* use temporary short-lived pages */
|
|
|
|
} else {
|
|
|
|
DBG_BUGON(1); /* referenced managed folios can't be truncated */
|
|
|
|
tocache = true;
|
2018-12-07 09:19:15 -07:00
|
|
|
}
|
2024-07-03 05:00:51 -07:00
|
|
|
folio_unlock(folio);
|
|
|
|
folio_put(folio);
|
2024-03-05 02:14:46 -07:00
|
|
|
out_allocfolio:
|
erofs: allocate more short-lived pages from reserved pool first
This patch aims to allocate bvpages and short-lived compressed pages
from the reserved pool first.
After applying this patch, there are three benefits.
1. It reduces the page allocation time.
The bvpages and short-lived compressed pages account for about 4% of
the pages allocated from the system in the multi-app launch benchmarks
[1]. It reduces the page allocation time accordingly and lowers the
likelihood of blockage by page allocation in low memory scenarios.
2. The pages in the reserved pool will be allocated on demand.
Currently, bvpages and short-lived compressed pages are short-lived
pages allocated from the system, and the pages in the reserved pool all
originate from short-lived pages. Consequently, the number of reserved
pool pages will increase to z_erofs_rsv_nrpages over time.
With this patch, all short-lived pages are allocated from the reserved
pool first, so the number of reserved pool pages will only increase when
there are not enough pages. Thus, even if z_erofs_rsv_nrpages is set to
a large number for specific reasons, the actual number of reserved pool
pages may remain low as per demand. In the multi-app launch benchmarks
[1], z_erofs_rsv_nrpages is set at 256, while the number of reserved
pool pages remains below 64.
3. When erofs cache decompression is disabled
(EROFS_ZIP_CACHE_DISABLED), all pages will *only* be allocated from
the reserved pool for erofs. This will significantly reduce the memory
pressure from erofs.
[1] For additional details on the multi-app launch benchmarks, please
refer to commit 0f6273ab4637 ("erofs: add a reserved buffer pool for lz4
decompression").
Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Link: https://lore.kernel.org/r/20240906121110.3701889-1-guochunhai@vivo.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2024-09-06 05:11:10 -07:00
|
|
|
page = __erofs_allocpage(&f->pagepool, gfp, true);
|
2024-01-25 05:00:39 -07:00
|
|
|
spin_lock(&pcl->obj.lockref.lock);
|
2024-09-10 00:08:47 -07:00
|
|
|
if (unlikely(pcl->compressed_bvecs[nr].page != zbv.page)) {
|
2024-09-05 01:47:32 -07:00
|
|
|
if (page)
|
|
|
|
erofs_pagepool_add(&f->pagepool, page);
|
2024-01-25 05:00:39 -07:00
|
|
|
spin_unlock(&pcl->obj.lockref.lock);
|
2019-11-21 06:59:54 -07:00
|
|
|
cond_resched();
|
|
|
|
goto repeat;
|
|
|
|
}
|
2024-09-05 01:47:32 -07:00
|
|
|
pcl->compressed_bvecs[nr].page = page ? page : ERR_PTR(-ENOMEM);
|
2024-01-25 05:00:39 -07:00
|
|
|
spin_unlock(&pcl->obj.lockref.lock);
|
2024-09-05 01:47:32 -07:00
|
|
|
bvec->bv_page = page;
|
|
|
|
if (!page)
|
|
|
|
return;
|
|
|
|
folio = page_folio(page);
|
2020-12-09 05:37:17 -07:00
|
|
|
out_tocache:
|
2023-12-06 02:10:53 -07:00
|
|
|
if (!tocache || bs != PAGE_SIZE ||
|
2024-09-10 00:08:47 -07:00
|
|
|
filemap_add_folio(mc, folio, pcl->obj.index + nr, gfp)) {
|
|
|
|
/* turn into a temporary shortlived folio (1 ref) */
|
|
|
|
folio->private = (void *)Z_EROFS_SHORTLIVED_PAGE;
|
2023-12-06 02:10:53 -07:00
|
|
|
return;
|
2024-09-10 00:08:47 -07:00
|
|
|
}
|
2024-07-03 05:00:51 -07:00
|
|
|
folio_attach_private(folio, pcl);
|
2023-12-06 02:10:53 -07:00
|
|
|
/* drop a refcount added by allocpage (then 2 refs in total here) */
|
2024-07-03 05:00:51 -07:00
|
|
|
folio_put(folio);
|
2018-12-07 09:19:15 -07:00
|
|
|
}
|
|
|
|
|
2023-02-04 02:30:36 -07:00
|
|
|
static struct z_erofs_decompressqueue *jobqueue_init(struct super_block *sb,
|
|
|
|
struct z_erofs_decompressqueue *fgq, bool *fg)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2019-10-08 05:56:15 -07:00
|
|
|
struct z_erofs_decompressqueue *q;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2019-10-08 05:56:15 -07:00
|
|
|
if (fg && !*fg) {
|
|
|
|
q = kvzalloc(sizeof(*q), GFP_KERNEL | __GFP_NOWARN);
|
|
|
|
if (!q) {
|
|
|
|
*fg = true;
|
|
|
|
goto fg_out;
|
|
|
|
}
|
2023-02-08 02:33:22 -07:00
|
|
|
#ifdef CONFIG_EROFS_FS_PCPU_KTHREAD
|
|
|
|
kthread_init_work(&q->u.kthread_work,
|
|
|
|
z_erofs_decompressqueue_kthread_work);
|
|
|
|
#else
|
2019-11-07 20:37:33 -07:00
|
|
|
INIT_WORK(&q->u.work, z_erofs_decompressqueue_work);
|
2023-02-08 02:33:22 -07:00
|
|
|
#endif
|
2019-10-08 05:56:15 -07:00
|
|
|
} else {
|
|
|
|
fg_out:
|
|
|
|
q = fgq;
|
2022-04-01 04:55:27 -07:00
|
|
|
init_completion(&fgq->u.done);
|
2019-10-08 05:56:15 -07:00
|
|
|
atomic_set(&fgq->pending_bios, 0);
|
2022-07-15 08:41:55 -07:00
|
|
|
q->eio = false;
|
2023-02-04 02:30:36 -07:00
|
|
|
q->sync = true;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
2019-10-08 05:56:15 -07:00
|
|
|
q->sb = sb;
|
2023-05-26 13:14:56 -07:00
|
|
|
q->head = Z_EROFS_PCLUSTER_TAIL;
|
2019-10-08 05:56:15 -07:00
|
|
|
return q;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2019-07-31 08:57:47 -07:00
|
|
|
/* define decompression jobqueue types */
|
2018-12-07 09:19:18 -07:00
|
|
|
enum {
|
|
|
|
JQ_BYPASS,
|
|
|
|
JQ_SUBMIT,
|
|
|
|
NR_JOBQUEUES,
|
|
|
|
};
|
|
|
|
|
2019-07-31 08:57:47 -07:00
|
|
|
static void move_to_bypass_jobqueue(struct z_erofs_pcluster *pcl,
|
|
|
|
z_erofs_next_pcluster_t qtail[],
|
|
|
|
z_erofs_next_pcluster_t owned_head)
|
2018-12-07 09:19:18 -07:00
|
|
|
{
|
2019-07-31 08:57:47 -07:00
|
|
|
z_erofs_next_pcluster_t *const submit_qtail = qtail[JQ_SUBMIT];
|
|
|
|
z_erofs_next_pcluster_t *const bypass_qtail = qtail[JQ_BYPASS];
|
2018-12-07 09:19:18 -07:00
|
|
|
|
2023-05-26 13:14:56 -07:00
|
|
|
WRITE_ONCE(pcl->next, Z_EROFS_PCLUSTER_TAIL);
|
2018-12-07 09:19:18 -07:00
|
|
|
|
|
|
|
WRITE_ONCE(*submit_qtail, owned_head);
|
2019-07-31 08:57:47 -07:00
|
|
|
WRITE_ONCE(*bypass_qtail, &pcl->next);
|
2018-12-07 09:19:18 -07:00
|
|
|
|
2019-07-31 08:57:47 -07:00
|
|
|
qtail[JQ_BYPASS] = &pcl->next;
|
2018-12-07 09:19:18 -07:00
|
|
|
}
|
|
|
|
|
2024-03-08 02:41:59 -07:00
|
|
|
static void z_erofs_endio(struct bio *bio)
|
2022-01-21 02:14:12 -07:00
|
|
|
{
|
2023-02-04 02:30:36 -07:00
|
|
|
struct z_erofs_decompressqueue *q = bio->bi_private;
|
2022-01-21 02:14:12 -07:00
|
|
|
blk_status_t err = bio->bi_status;
|
2024-03-05 02:14:47 -07:00
|
|
|
struct folio_iter fi;
|
2022-01-21 02:14:12 -07:00
|
|
|
|
2024-03-05 02:14:47 -07:00
|
|
|
bio_for_each_folio_all(fi, bio) {
|
|
|
|
struct folio *folio = fi.folio;
|
2022-01-21 02:14:12 -07:00
|
|
|
|
2024-03-05 02:14:47 -07:00
|
|
|
DBG_BUGON(folio_test_uptodate(folio));
|
|
|
|
DBG_BUGON(z_erofs_page_is_invalidated(&folio->page));
|
2024-03-05 02:14:48 -07:00
|
|
|
if (!erofs_folio_is_managed(EROFS_SB(q->sb), folio))
|
2024-03-05 02:14:47 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!err)
|
|
|
|
folio_mark_uptodate(folio);
|
|
|
|
folio_unlock(folio);
|
2022-01-21 02:14:12 -07:00
|
|
|
}
|
2022-07-15 08:41:55 -07:00
|
|
|
if (err)
|
|
|
|
q->eio = true;
|
2023-02-04 02:30:36 -07:00
|
|
|
z_erofs_decompress_kickoff(q, -1);
|
2024-03-08 02:41:59 -07:00
|
|
|
if (bio->bi_bdev)
|
|
|
|
bio_put(bio);
|
2022-01-21 02:14:12 -07:00
|
|
|
}
|
|
|
|
|
2022-07-15 08:41:48 -07:00
|
|
|
static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,
|
2019-11-07 20:37:33 -07:00
|
|
|
struct z_erofs_decompressqueue *fgq,
|
2023-05-23 23:39:44 -07:00
|
|
|
bool *force_fg, bool readahead)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2022-07-15 08:41:48 -07:00
|
|
|
struct super_block *sb = f->inode->i_sb;
|
|
|
|
struct address_space *mc = MNGD_MAPPING(EROFS_SB(sb));
|
2019-07-31 08:57:47 -07:00
|
|
|
z_erofs_next_pcluster_t qtail[NR_JOBQUEUES];
|
2019-10-08 05:56:15 -07:00
|
|
|
struct z_erofs_decompressqueue *q[NR_JOBQUEUES];
|
2022-03-01 12:49:50 -07:00
|
|
|
z_erofs_next_pcluster_t owned_head = f->owned_head;
|
2021-10-14 01:10:10 -07:00
|
|
|
/* bio is NULL initially, so no need to initialize last_{index,bdev} */
|
2023-12-06 02:10:53 -07:00
|
|
|
erofs_off_t last_pa;
|
2020-01-20 23:48:19 -07:00
|
|
|
unsigned int nr_bios = 0;
|
|
|
|
struct bio *bio = NULL;
|
fs: fix leaked psi pressure state
When psi annotations were added to to btrfs compression reads, the psi
state tracking over add_ra_bio_pages and btrfs_submit_compressed_read was
faulty. A pressure state, once entered, is never left. This results in
incorrectly elevated pressure, which triggers OOM kills.
pflags record the *previous* memstall state when we enter a new one. The
code tried to initialize pflags to 1, and then optimize the leave call
when we either didn't enter a memstall, or were already inside a nested
stall. However, there can be multiple PageWorkingset pages in the bio, at
which point it's that path itself that enters repeatedly and overwrites
pflags. This causes us to miss the exit.
Enter the stall only once if needed, then unwind correctly.
erofs has the same problem, fix that up too. And move the memstall exit
past submit_bio() to restore submit accounting originally added by
b8e24a9300b0 ("block: annotate refault stalls from IO submission").
Link: https://lkml.kernel.org/r/Y2UHRqthNUwuIQGS@cmpxchg.org
Fixes: 4088a47e78f9 ("btrfs: add manual PSI accounting for compressed reads")
Fixes: 99486c511f68 ("erofs: add manual PSI accounting for the compressed address space")
Fixes: 118f3663fbc6 ("block: remove PSI accounting from the bio layer")
Link: https://lore.kernel.org/r/d20a0a85-e415-cf78-27f9-77dd7a94bc8d@leemhuis.info/
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reported-by: Thorsten Leemhuis <linux@leemhuis.info>
Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
Cc: Chao Yu <chao@kernel.org>
Cc: Chris Mason <clm@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: David Sterba <dsterba@suse.com>
Cc: Gao Xiang <xiang@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-11-03 14:34:31 -07:00
|
|
|
unsigned long pflags;
|
|
|
|
int memstall = 0;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2023-12-06 02:10:53 -07:00
|
|
|
/* No need to read from device for pclusters in the bypass queue. */
|
2023-02-04 02:30:36 -07:00
|
|
|
q[JQ_BYPASS] = jobqueue_init(sb, fgq + JQ_BYPASS, NULL);
|
|
|
|
q[JQ_SUBMIT] = jobqueue_init(sb, fgq + JQ_SUBMIT, force_fg);
|
|
|
|
|
2019-10-08 05:56:15 -07:00
|
|
|
qtail[JQ_BYPASS] = &q[JQ_BYPASS]->head;
|
|
|
|
qtail[JQ_SUBMIT] = &q[JQ_SUBMIT]->head;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
|
|
|
/* by default, all need io submission */
|
2018-12-07 09:19:18 -07:00
|
|
|
q[JQ_SUBMIT]->head = owned_head;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
|
|
|
do {
|
2021-10-14 01:10:10 -07:00
|
|
|
struct erofs_map_dev mdev;
|
2019-07-31 08:57:47 -07:00
|
|
|
struct z_erofs_pcluster *pcl;
|
2023-12-06 02:10:53 -07:00
|
|
|
erofs_off_t cur, end;
|
|
|
|
struct bio_vec bvec;
|
2020-01-20 23:48:19 -07:00
|
|
|
unsigned int i = 0;
|
|
|
|
bool bypass = true;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2019-07-31 08:57:47 -07:00
|
|
|
DBG_BUGON(owned_head == Z_EROFS_PCLUSTER_NIL);
|
|
|
|
pcl = container_of(owned_head, struct z_erofs_pcluster, next);
|
2023-05-26 13:14:56 -07:00
|
|
|
owned_head = READ_ONCE(pcl->next);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2021-12-28 16:29:19 -07:00
|
|
|
if (z_erofs_is_inline_pcluster(pcl)) {
|
|
|
|
move_to_bypass_jobqueue(pcl, qtail, owned_head);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-10-14 01:10:10 -07:00
|
|
|
/* no device id here, thus it will always succeed */
|
|
|
|
mdev = (struct erofs_map_dev) {
|
2023-03-13 06:53:08 -07:00
|
|
|
.m_pa = erofs_pos(sb, pcl->obj.index),
|
2021-10-14 01:10:10 -07:00
|
|
|
};
|
|
|
|
(void)erofs_map_dev(sb, &mdev);
|
|
|
|
|
2023-12-06 02:10:53 -07:00
|
|
|
cur = mdev.m_pa;
|
2023-12-06 02:10:54 -07:00
|
|
|
end = cur + pcl->pclustersize;
|
2020-01-20 23:48:19 -07:00
|
|
|
do {
|
2024-09-10 00:08:47 -07:00
|
|
|
bvec.bv_page = NULL;
|
2023-12-06 02:10:53 -07:00
|
|
|
if (bio && (cur != last_pa ||
|
2024-03-08 02:41:59 -07:00
|
|
|
bio->bi_bdev != mdev.m_bdev)) {
|
2024-09-10 00:08:47 -07:00
|
|
|
drain_io:
|
2024-08-29 20:28:39 -07:00
|
|
|
if (erofs_is_fileio_mode(EROFS_SB(sb)))
|
|
|
|
erofs_fileio_submit_bio(bio);
|
|
|
|
else if (erofs_is_fscache_mode(sb))
|
2024-03-08 02:41:59 -07:00
|
|
|
erofs_fscache_submit_bio(bio);
|
2024-08-29 20:28:39 -07:00
|
|
|
else
|
|
|
|
submit_bio(bio);
|
2024-03-08 02:41:59 -07:00
|
|
|
|
fs: fix leaked psi pressure state
When psi annotations were added to to btrfs compression reads, the psi
state tracking over add_ra_bio_pages and btrfs_submit_compressed_read was
faulty. A pressure state, once entered, is never left. This results in
incorrectly elevated pressure, which triggers OOM kills.
pflags record the *previous* memstall state when we enter a new one. The
code tried to initialize pflags to 1, and then optimize the leave call
when we either didn't enter a memstall, or were already inside a nested
stall. However, there can be multiple PageWorkingset pages in the bio, at
which point it's that path itself that enters repeatedly and overwrites
pflags. This causes us to miss the exit.
Enter the stall only once if needed, then unwind correctly.
erofs has the same problem, fix that up too. And move the memstall exit
past submit_bio() to restore submit accounting originally added by
b8e24a9300b0 ("block: annotate refault stalls from IO submission").
Link: https://lkml.kernel.org/r/Y2UHRqthNUwuIQGS@cmpxchg.org
Fixes: 4088a47e78f9 ("btrfs: add manual PSI accounting for compressed reads")
Fixes: 99486c511f68 ("erofs: add manual PSI accounting for the compressed address space")
Fixes: 118f3663fbc6 ("block: remove PSI accounting from the bio layer")
Link: https://lore.kernel.org/r/d20a0a85-e415-cf78-27f9-77dd7a94bc8d@leemhuis.info/
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reported-by: Thorsten Leemhuis <linux@leemhuis.info>
Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
Cc: Chao Yu <chao@kernel.org>
Cc: Chris Mason <clm@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: David Sterba <dsterba@suse.com>
Cc: Gao Xiang <xiang@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-11-03 14:34:31 -07:00
|
|
|
if (memstall) {
|
|
|
|
psi_memstall_leave(&pflags);
|
|
|
|
memstall = 0;
|
|
|
|
}
|
2020-01-20 23:48:19 -07:00
|
|
|
bio = NULL;
|
|
|
|
}
|
2019-09-03 19:09:02 -07:00
|
|
|
|
2024-09-10 00:08:47 -07:00
|
|
|
if (!bvec.bv_page) {
|
|
|
|
z_erofs_fill_bio_vec(&bvec, f, pcl, i++, mc);
|
|
|
|
if (!bvec.bv_page)
|
|
|
|
continue;
|
|
|
|
if (cur + bvec.bv_len > end)
|
|
|
|
bvec.bv_len = end - cur;
|
|
|
|
DBG_BUGON(bvec.bv_len < sb->s_blocksize);
|
|
|
|
}
|
|
|
|
|
2023-12-06 02:10:53 -07:00
|
|
|
if (unlikely(PageWorkingset(bvec.bv_page)) &&
|
|
|
|
!memstall) {
|
2022-09-15 02:41:59 -07:00
|
|
|
psi_memstall_enter(&pflags);
|
fs: fix leaked psi pressure state
When psi annotations were added to to btrfs compression reads, the psi
state tracking over add_ra_bio_pages and btrfs_submit_compressed_read was
faulty. A pressure state, once entered, is never left. This results in
incorrectly elevated pressure, which triggers OOM kills.
pflags record the *previous* memstall state when we enter a new one. The
code tried to initialize pflags to 1, and then optimize the leave call
when we either didn't enter a memstall, or were already inside a nested
stall. However, there can be multiple PageWorkingset pages in the bio, at
which point it's that path itself that enters repeatedly and overwrites
pflags. This causes us to miss the exit.
Enter the stall only once if needed, then unwind correctly.
erofs has the same problem, fix that up too. And move the memstall exit
past submit_bio() to restore submit accounting originally added by
b8e24a9300b0 ("block: annotate refault stalls from IO submission").
Link: https://lkml.kernel.org/r/Y2UHRqthNUwuIQGS@cmpxchg.org
Fixes: 4088a47e78f9 ("btrfs: add manual PSI accounting for compressed reads")
Fixes: 99486c511f68 ("erofs: add manual PSI accounting for the compressed address space")
Fixes: 118f3663fbc6 ("block: remove PSI accounting from the bio layer")
Link: https://lore.kernel.org/r/d20a0a85-e415-cf78-27f9-77dd7a94bc8d@leemhuis.info/
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reported-by: Thorsten Leemhuis <linux@leemhuis.info>
Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
Cc: Chao Yu <chao@kernel.org>
Cc: Chris Mason <clm@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: David Sterba <dsterba@suse.com>
Cc: Gao Xiang <xiang@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-11-03 14:34:31 -07:00
|
|
|
memstall = 1;
|
|
|
|
}
|
2022-09-15 02:41:59 -07:00
|
|
|
|
2020-01-20 23:48:19 -07:00
|
|
|
if (!bio) {
|
2024-08-29 20:28:39 -07:00
|
|
|
if (erofs_is_fileio_mode(EROFS_SB(sb)))
|
|
|
|
bio = erofs_fileio_bio_alloc(&mdev);
|
|
|
|
else if (erofs_is_fscache_mode(sb))
|
|
|
|
bio = erofs_fscache_bio_alloc(&mdev);
|
|
|
|
else
|
|
|
|
bio = bio_alloc(mdev.m_bdev, BIO_MAX_VECS,
|
|
|
|
REQ_OP_READ, GFP_NOIO);
|
2024-03-08 02:41:59 -07:00
|
|
|
bio->bi_end_io = z_erofs_endio;
|
2023-12-06 02:10:53 -07:00
|
|
|
bio->bi_iter.bi_sector = cur >> 9;
|
2023-02-04 02:30:36 -07:00
|
|
|
bio->bi_private = q[JQ_SUBMIT];
|
2023-05-23 23:39:44 -07:00
|
|
|
if (readahead)
|
2020-09-19 00:27:30 -07:00
|
|
|
bio->bi_opf |= REQ_RAHEAD;
|
2020-01-20 23:48:19 -07:00
|
|
|
++nr_bios;
|
|
|
|
}
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2023-12-06 02:10:53 -07:00
|
|
|
if (!bio_add_page(bio, bvec.bv_page, bvec.bv_len,
|
|
|
|
bvec.bv_offset))
|
2024-09-10 00:08:47 -07:00
|
|
|
goto drain_io;
|
2023-12-06 02:10:53 -07:00
|
|
|
last_pa = cur + bvec.bv_len;
|
2020-01-20 23:48:19 -07:00
|
|
|
bypass = false;
|
2023-12-06 02:10:53 -07:00
|
|
|
} while ((cur += bvec.bv_len) < end);
|
2018-07-26 05:22:07 -07:00
|
|
|
|
2020-01-20 23:48:19 -07:00
|
|
|
if (!bypass)
|
2019-07-31 08:57:47 -07:00
|
|
|
qtail[JQ_SUBMIT] = &pcl->next;
|
2018-12-07 09:19:18 -07:00
|
|
|
else
|
2019-07-31 08:57:47 -07:00
|
|
|
move_to_bypass_jobqueue(pcl, qtail, owned_head);
|
|
|
|
} while (owned_head != Z_EROFS_PCLUSTER_TAIL);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-09-15 02:41:59 -07:00
|
|
|
if (bio) {
|
2024-08-29 20:28:39 -07:00
|
|
|
if (erofs_is_fileio_mode(EROFS_SB(sb)))
|
|
|
|
erofs_fileio_submit_bio(bio);
|
|
|
|
else if (erofs_is_fscache_mode(sb))
|
2024-03-08 02:41:59 -07:00
|
|
|
erofs_fscache_submit_bio(bio);
|
2024-08-29 20:28:39 -07:00
|
|
|
else
|
|
|
|
submit_bio(bio);
|
fs: fix leaked psi pressure state
When psi annotations were added to to btrfs compression reads, the psi
state tracking over add_ra_bio_pages and btrfs_submit_compressed_read was
faulty. A pressure state, once entered, is never left. This results in
incorrectly elevated pressure, which triggers OOM kills.
pflags record the *previous* memstall state when we enter a new one. The
code tried to initialize pflags to 1, and then optimize the leave call
when we either didn't enter a memstall, or were already inside a nested
stall. However, there can be multiple PageWorkingset pages in the bio, at
which point it's that path itself that enters repeatedly and overwrites
pflags. This causes us to miss the exit.
Enter the stall only once if needed, then unwind correctly.
erofs has the same problem, fix that up too. And move the memstall exit
past submit_bio() to restore submit accounting originally added by
b8e24a9300b0 ("block: annotate refault stalls from IO submission").
Link: https://lkml.kernel.org/r/Y2UHRqthNUwuIQGS@cmpxchg.org
Fixes: 4088a47e78f9 ("btrfs: add manual PSI accounting for compressed reads")
Fixes: 99486c511f68 ("erofs: add manual PSI accounting for the compressed address space")
Fixes: 118f3663fbc6 ("block: remove PSI accounting from the bio layer")
Link: https://lore.kernel.org/r/d20a0a85-e415-cf78-27f9-77dd7a94bc8d@leemhuis.info/
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reported-by: Thorsten Leemhuis <linux@leemhuis.info>
Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
Cc: Chao Yu <chao@kernel.org>
Cc: Chris Mason <clm@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: David Sterba <dsterba@suse.com>
Cc: Gao Xiang <xiang@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-11-03 14:34:31 -07:00
|
|
|
if (memstall)
|
|
|
|
psi_memstall_leave(&pflags);
|
2022-09-15 02:41:59 -07:00
|
|
|
}
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2020-01-20 23:47:47 -07:00
|
|
|
/*
|
|
|
|
* although background is preferred, no one is pending for submission.
|
2023-02-08 02:33:22 -07:00
|
|
|
* don't issue decompression but drop it directly instead.
|
2020-01-20 23:47:47 -07:00
|
|
|
*/
|
|
|
|
if (!*force_fg && !nr_bios) {
|
|
|
|
kvfree(q[JQ_SUBMIT]);
|
2020-01-20 23:48:19 -07:00
|
|
|
return;
|
2020-01-20 23:47:47 -07:00
|
|
|
}
|
2023-02-04 02:30:36 -07:00
|
|
|
z_erofs_decompress_kickoff(q[JQ_SUBMIT], nr_bios);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2024-09-05 01:47:32 -07:00
|
|
|
static int z_erofs_runqueue(struct z_erofs_decompress_frontend *f,
|
|
|
|
unsigned int ra_folios)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2019-10-08 05:56:15 -07:00
|
|
|
struct z_erofs_decompressqueue io[NR_JOBQUEUES];
|
2024-09-05 01:47:32 -07:00
|
|
|
struct erofs_sb_info *sbi = EROFS_I_SB(f->inode);
|
|
|
|
bool force_fg = z_erofs_is_sync_decompress(sbi, ra_folios);
|
|
|
|
int err;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-03-01 12:49:50 -07:00
|
|
|
if (f->owned_head == Z_EROFS_PCLUSTER_TAIL)
|
2024-09-05 01:47:32 -07:00
|
|
|
return 0;
|
|
|
|
z_erofs_submit_queue(f, io, &force_fg, !!ra_folios);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2019-11-07 20:37:33 -07:00
|
|
|
/* handle bypass queue (no i/o pclusters) immediately */
|
2024-09-05 01:47:32 -07:00
|
|
|
err = z_erofs_decompress_queue(&io[JQ_BYPASS], &f->pagepool);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
if (!force_fg)
|
2024-09-05 01:47:32 -07:00
|
|
|
return err;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
|
|
|
/* wait until all bios are completed */
|
2022-04-01 04:55:27 -07:00
|
|
|
wait_for_completion_io(&io[JQ_SUBMIT].u.done);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2019-11-07 20:37:33 -07:00
|
|
|
/* handle synchronous decompress queue in the caller context */
|
2024-09-05 01:47:32 -07:00
|
|
|
return z_erofs_decompress_queue(&io[JQ_SUBMIT], &f->pagepool) ?: err;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2021-10-08 13:08:39 -07:00
|
|
|
/*
|
|
|
|
* Since partial uptodate is still unimplemented for now, we have to use
|
|
|
|
* approximate readmore strategies as a start.
|
|
|
|
*/
|
|
|
|
static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,
|
2023-05-26 13:14:55 -07:00
|
|
|
struct readahead_control *rac, bool backmost)
|
2021-10-08 13:08:39 -07:00
|
|
|
{
|
|
|
|
struct inode *inode = f->inode;
|
|
|
|
struct erofs_map_blocks *map = &f->map;
|
2023-05-25 00:26:05 -07:00
|
|
|
erofs_off_t cur, end, headoffset = f->headoffset;
|
2021-10-08 13:08:39 -07:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if (backmost) {
|
2023-05-25 00:26:05 -07:00
|
|
|
if (rac)
|
|
|
|
end = headoffset + readahead_length(rac) - 1;
|
|
|
|
else
|
|
|
|
end = headoffset + PAGE_SIZE - 1;
|
2021-10-08 13:08:39 -07:00
|
|
|
map->m_la = end;
|
2021-10-10 14:31:45 -07:00
|
|
|
err = z_erofs_map_blocks_iter(inode, map,
|
|
|
|
EROFS_GET_BLOCKS_READMORE);
|
2021-10-08 13:08:39 -07:00
|
|
|
if (err)
|
|
|
|
return;
|
|
|
|
|
2023-05-25 00:26:05 -07:00
|
|
|
/* expand ra for the trailing edge if readahead */
|
2021-10-08 13:08:39 -07:00
|
|
|
if (rac) {
|
|
|
|
cur = round_up(map->m_la + map->m_llen, PAGE_SIZE);
|
2023-05-25 00:26:05 -07:00
|
|
|
readahead_expand(rac, headoffset, cur - headoffset);
|
2021-10-08 13:08:39 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
end = round_up(end, PAGE_SIZE);
|
|
|
|
} else {
|
|
|
|
end = round_up(map->m_la, PAGE_SIZE);
|
|
|
|
if (!map->m_llen)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur = map->m_la + map->m_llen - 1;
|
2023-07-09 21:25:31 -07:00
|
|
|
while ((cur >= end) && (cur < i_size_read(inode))) {
|
2021-10-08 13:08:39 -07:00
|
|
|
pgoff_t index = cur >> PAGE_SHIFT;
|
2024-07-03 05:00:48 -07:00
|
|
|
struct folio *folio;
|
2021-10-08 13:08:39 -07:00
|
|
|
|
2024-07-03 05:00:48 -07:00
|
|
|
folio = erofs_grab_folio_nowait(inode->i_mapping, index);
|
|
|
|
if (!IS_ERR_OR_NULL(folio)) {
|
|
|
|
if (folio_test_uptodate(folio))
|
|
|
|
folio_unlock(folio);
|
2023-08-08 23:06:37 -07:00
|
|
|
else
|
2024-07-03 05:00:48 -07:00
|
|
|
z_erofs_scan_folio(f, folio, !!rac);
|
|
|
|
folio_put(folio);
|
2021-10-08 13:08:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cur < PAGE_SIZE)
|
|
|
|
break;
|
|
|
|
cur = (index << PAGE_SHIFT) - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 08:12:16 -07:00
|
|
|
static int z_erofs_read_folio(struct file *file, struct folio *folio)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2023-08-17 01:39:42 -07:00
|
|
|
struct inode *const inode = folio->mapping->host;
|
2019-07-31 08:57:47 -07:00
|
|
|
struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
int err;
|
|
|
|
|
2023-08-17 01:39:42 -07:00
|
|
|
trace_erofs_read_folio(folio, false);
|
|
|
|
f.headoffset = (erofs_off_t)folio->index << PAGE_SHIFT;
|
2018-11-22 10:21:49 -07:00
|
|
|
|
2023-05-26 13:14:55 -07:00
|
|
|
z_erofs_pcluster_readmore(&f, NULL, true);
|
2024-03-05 02:14:44 -07:00
|
|
|
err = z_erofs_scan_folio(&f, folio, false);
|
2023-05-26 13:14:55 -07:00
|
|
|
z_erofs_pcluster_readmore(&f, NULL, false);
|
2023-08-17 01:28:07 -07:00
|
|
|
z_erofs_pcluster_end(&f);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2024-09-05 01:47:32 -07:00
|
|
|
/* if some pclusters are ready, need submit them anyway */
|
|
|
|
err = z_erofs_runqueue(&f, 0) ?: err;
|
2023-08-08 23:06:37 -07:00
|
|
|
if (err && err != -EINTR)
|
|
|
|
erofs_err(inode->i_sb, "read error %d @ %lu of nid %llu",
|
|
|
|
err, folio->index, EROFS_I(inode)->nid);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2022-01-01 21:00:17 -07:00
|
|
|
erofs_put_metabuf(&f.map.buf);
|
2023-05-26 13:14:55 -07:00
|
|
|
erofs_release_pages(&f.pagepool);
|
2019-08-19 03:34:21 -07:00
|
|
|
return err;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2020-06-01 21:47:13 -07:00
|
|
|
static void z_erofs_readahead(struct readahead_control *rac)
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
{
|
2020-06-01 21:47:13 -07:00
|
|
|
struct inode *const inode = rac->mapping->host;
|
2019-07-31 08:57:47 -07:00
|
|
|
struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
|
2023-08-17 01:28:12 -07:00
|
|
|
struct folio *head = NULL, *folio;
|
|
|
|
unsigned int nr_folios;
|
|
|
|
int err;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2020-06-01 21:47:13 -07:00
|
|
|
f.headoffset = readahead_pos(rac);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2023-05-26 13:14:55 -07:00
|
|
|
z_erofs_pcluster_readmore(&f, rac, true);
|
2023-08-17 01:28:12 -07:00
|
|
|
nr_folios = readahead_count(rac);
|
|
|
|
trace_erofs_readpages(inode, readahead_index(rac), nr_folios, false);
|
2018-11-22 10:21:48 -07:00
|
|
|
|
2023-08-17 01:28:12 -07:00
|
|
|
while ((folio = readahead_folio(rac))) {
|
|
|
|
folio->private = head;
|
|
|
|
head = folio;
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2023-08-17 01:28:12 -07:00
|
|
|
/* traverse in reverse order for best metadata I/O performance */
|
2018-11-12 13:43:57 -07:00
|
|
|
while (head) {
|
2023-08-17 01:28:12 -07:00
|
|
|
folio = head;
|
|
|
|
head = folio_get_private(folio);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2024-03-05 02:14:44 -07:00
|
|
|
err = z_erofs_scan_folio(&f, folio, true);
|
2023-08-08 23:06:37 -07:00
|
|
|
if (err && err != -EINTR)
|
2023-08-17 01:28:12 -07:00
|
|
|
erofs_err(inode->i_sb, "readahead error at folio %lu @ nid %llu",
|
|
|
|
folio->index, EROFS_I(inode)->nid);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
2023-05-26 13:14:55 -07:00
|
|
|
z_erofs_pcluster_readmore(&f, rac, false);
|
2023-08-17 01:28:07 -07:00
|
|
|
z_erofs_pcluster_end(&f);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
|
2024-09-05 01:47:32 -07:00
|
|
|
(void)z_erofs_runqueue(&f, nr_folios);
|
2022-01-01 21:00:17 -07:00
|
|
|
erofs_put_metabuf(&f.map.buf);
|
2023-05-26 13:14:55 -07:00
|
|
|
erofs_release_pages(&f.pagepool);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
}
|
|
|
|
|
2019-11-07 20:37:33 -07:00
|
|
|
const struct address_space_operations z_erofs_aops = {
|
2022-04-29 08:12:16 -07:00
|
|
|
.read_folio = z_erofs_read_folio,
|
2020-06-01 21:47:13 -07:00
|
|
|
.readahead = z_erofs_readahead,
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 05:22:06 -07:00
|
|
|
};
|