2019-07-31 17:57:31 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2018-07-26 14:21:59 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 HUAWEI, Inc.
|
|
|
|
* http://www.huawei.com/
|
|
|
|
* Created by Gao Xiang <gaoxiang25@huawei.com>
|
|
|
|
*/
|
|
|
|
#include "internal.h"
|
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 14:22:06 +02:00
|
|
|
#include <linux/pagevec.h>
|
2018-07-26 14:21:59 +02:00
|
|
|
|
2019-07-31 17:57:43 +02:00
|
|
|
struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail)
|
2018-07-26 14:21:59 +02:00
|
|
|
{
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
if (!list_empty(pool)) {
|
|
|
|
page = lru_to_page(pool);
|
2019-07-31 17:57:43 +02:00
|
|
|
DBG_BUGON(page_ref_count(page) != 1);
|
2018-07-26 14:21:59 +02:00
|
|
|
list_del(&page->lru);
|
|
|
|
} else {
|
2019-07-31 17:57:43 +02:00
|
|
|
page = alloc_pages(gfp | (nofail ? __GFP_NOFAIL : 0), 0);
|
2018-07-26 14:21:59 +02:00
|
|
|
}
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2019-06-24 09:22:53 +02:00
|
|
|
#if (EROFS_PCPUBUF_NR_PAGES > 0)
|
|
|
|
static struct {
|
|
|
|
u8 data[PAGE_SIZE * EROFS_PCPUBUF_NR_PAGES];
|
|
|
|
} ____cacheline_aligned_in_smp erofs_pcpubuf[NR_CPUS];
|
|
|
|
|
|
|
|
void *erofs_get_pcpubuf(unsigned int pagenr)
|
|
|
|
{
|
|
|
|
preempt_disable();
|
|
|
|
return &erofs_pcpubuf[smp_processor_id()].data[pagenr * PAGE_SIZE];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-31 17:57:39 +02:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2018-07-26 14:22:05 +02:00
|
|
|
/* global shrink count (for all mounted EROFS instances) */
|
|
|
|
static atomic_long_t erofs_global_shrink_cnt;
|
|
|
|
|
2019-01-16 09:59:53 +01:00
|
|
|
#define __erofs_workgroup_get(grp) atomic_inc(&(grp)->refcount)
|
|
|
|
#define __erofs_workgroup_put(grp) atomic_dec(&(grp)->refcount)
|
|
|
|
|
2019-01-16 14:10:10 +01:00
|
|
|
static int erofs_workgroup_get(struct erofs_workgroup *grp)
|
2019-01-16 09:59:53 +01:00
|
|
|
{
|
|
|
|
int o;
|
|
|
|
|
|
|
|
repeat:
|
|
|
|
o = erofs_wait_on_workgroup_freezed(grp);
|
2019-08-29 18:38:27 +02:00
|
|
|
if (o <= 0)
|
2019-01-16 09:59:53 +01:00
|
|
|
return -1;
|
|
|
|
|
2019-08-29 18:38:27 +02:00
|
|
|
if (atomic_cmpxchg(&grp->refcount, o, o + 1) != o)
|
2019-01-16 09:59:53 +01:00
|
|
|
goto repeat;
|
|
|
|
|
2019-01-16 14:10:10 +01:00
|
|
|
/* decrease refcount paired by erofs_workgroup_put */
|
2019-08-29 18:38:27 +02:00
|
|
|
if (o == 1)
|
2019-01-16 14:10:10 +01:00
|
|
|
atomic_long_dec(&erofs_global_shrink_cnt);
|
2019-01-16 09:59:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2018-07-26 14:22:05 +02:00
|
|
|
|
2019-01-16 14:10:10 +01:00
|
|
|
struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
|
|
|
|
pgoff_t index, bool *tag)
|
2018-07-26 14:22:05 +02:00
|
|
|
{
|
|
|
|
struct erofs_sb_info *sbi = EROFS_SB(sb);
|
|
|
|
struct erofs_workgroup *grp;
|
|
|
|
|
|
|
|
repeat:
|
|
|
|
rcu_read_lock();
|
|
|
|
grp = radix_tree_lookup(&sbi->workstn_tree, index);
|
2019-03-22 03:38:16 +01:00
|
|
|
if (grp) {
|
2017-11-03 18:30:42 +01:00
|
|
|
*tag = xa_pointer_tag(grp);
|
|
|
|
grp = xa_untag_pointer(grp);
|
2018-07-26 14:22:05 +02:00
|
|
|
|
2019-01-16 14:10:10 +01:00
|
|
|
if (erofs_workgroup_get(grp)) {
|
2018-07-26 14:22:05 +02:00
|
|
|
/* prefer to relax rcu read side */
|
|
|
|
rcu_read_unlock();
|
|
|
|
goto repeat;
|
|
|
|
}
|
|
|
|
|
2018-12-11 08:17:50 +01:00
|
|
|
DBG_BUGON(index != grp->index);
|
2018-07-26 14:22:05 +02:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int erofs_register_workgroup(struct super_block *sb,
|
|
|
|
struct erofs_workgroup *grp,
|
|
|
|
bool tag)
|
|
|
|
{
|
|
|
|
struct erofs_sb_info *sbi;
|
|
|
|
int err;
|
|
|
|
|
2018-12-11 08:17:50 +01:00
|
|
|
/* grp shouldn't be broken or used before */
|
2019-08-29 18:38:27 +02:00
|
|
|
if (atomic_read(&grp->refcount) != 1) {
|
2018-12-11 08:17:50 +01:00
|
|
|
DBG_BUGON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-07-26 14:22:05 +02:00
|
|
|
|
|
|
|
err = radix_tree_preload(GFP_NOFS);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
sbi = EROFS_SB(sb);
|
2019-07-31 17:57:35 +02:00
|
|
|
xa_lock(&sbi->workstn_tree);
|
2018-07-26 14:22:05 +02:00
|
|
|
|
2017-11-03 18:30:42 +01:00
|
|
|
grp = xa_tag_pointer(grp, tag);
|
2018-07-26 14:22:05 +02:00
|
|
|
|
2018-11-22 18:16:00 +01:00
|
|
|
/*
|
|
|
|
* Bump up reference count before making this workgroup
|
|
|
|
* visible to other users in order to avoid potential UAF
|
2019-07-31 17:57:35 +02:00
|
|
|
* without serialized by workstn_lock.
|
2018-11-22 18:16:00 +01:00
|
|
|
*/
|
|
|
|
__erofs_workgroup_get(grp);
|
2018-07-26 14:22:05 +02:00
|
|
|
|
2019-07-31 17:57:50 +02:00
|
|
|
err = radix_tree_insert(&sbi->workstn_tree, grp->index, grp);
|
2019-08-29 18:38:27 +02:00
|
|
|
if (err)
|
2018-11-22 18:16:00 +01:00
|
|
|
/*
|
|
|
|
* it's safe to decrease since the workgroup isn't visible
|
|
|
|
* and refcount >= 2 (cannot be freezed).
|
|
|
|
*/
|
|
|
|
__erofs_workgroup_put(grp);
|
2018-07-26 14:22:05 +02:00
|
|
|
|
2019-07-31 17:57:35 +02:00
|
|
|
xa_unlock(&sbi->workstn_tree);
|
2018-07-26 14:22:05 +02:00
|
|
|
radix_tree_preload_end();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-11-22 18:16:00 +01:00
|
|
|
static void __erofs_workgroup_free(struct erofs_workgroup *grp)
|
|
|
|
{
|
|
|
|
atomic_long_dec(&erofs_global_shrink_cnt);
|
|
|
|
erofs_workgroup_free_rcu(grp);
|
|
|
|
}
|
|
|
|
|
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 14:22:06 +02:00
|
|
|
int erofs_workgroup_put(struct erofs_workgroup *grp)
|
|
|
|
{
|
|
|
|
int count = atomic_dec_return(&grp->refcount);
|
|
|
|
|
|
|
|
if (count == 1)
|
|
|
|
atomic_long_inc(&erofs_global_shrink_cnt);
|
2018-11-22 18:16:00 +01:00
|
|
|
else if (!count)
|
|
|
|
__erofs_workgroup_free(grp);
|
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 14:22:06 +02:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2018-11-22 18:16:00 +01:00
|
|
|
static void erofs_workgroup_unfreeze_final(struct erofs_workgroup *grp)
|
|
|
|
{
|
|
|
|
erofs_workgroup_unfreeze(grp, 0);
|
|
|
|
__erofs_workgroup_free(grp);
|
|
|
|
}
|
|
|
|
|
2019-01-08 12:31:47 +01:00
|
|
|
static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi,
|
|
|
|
struct erofs_workgroup *grp,
|
|
|
|
bool cleanup)
|
2018-11-22 18:16:00 +01:00
|
|
|
{
|
|
|
|
/*
|
2019-07-31 17:57:50 +02:00
|
|
|
* If managed cache is on, refcount of workgroups
|
|
|
|
* themselves could be < 0 (freezed). In other words,
|
|
|
|
* there is no guarantee that all refcounts > 0.
|
2018-11-22 18:16:00 +01:00
|
|
|
*/
|
|
|
|
if (!erofs_workgroup_try_to_freeze(grp, 1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
2019-07-31 17:57:50 +02:00
|
|
|
* Note that all cached pages should be unattached
|
|
|
|
* before deleted from the radix tree. Otherwise some
|
|
|
|
* cached pages could be still attached to the orphan
|
|
|
|
* old workgroup when the new one is available in the tree.
|
2018-11-22 18:16:00 +01:00
|
|
|
*/
|
|
|
|
if (erofs_try_to_free_all_cached_pages(sbi, grp)) {
|
|
|
|
erofs_workgroup_unfreeze(grp, 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-07-31 17:57:50 +02:00
|
|
|
* It's impossible to fail after the workgroup is freezed,
|
2018-11-22 18:16:00 +01:00
|
|
|
* however in order to avoid some race conditions, add a
|
|
|
|
* DBG_BUGON to observe this in advance.
|
|
|
|
*/
|
|
|
|
DBG_BUGON(xa_untag_pointer(radix_tree_delete(&sbi->workstn_tree,
|
|
|
|
grp->index)) != grp);
|
|
|
|
|
|
|
|
/*
|
2019-07-31 17:57:50 +02:00
|
|
|
* If managed cache is on, last refcount should indicate
|
|
|
|
* the related workstation.
|
2018-11-22 18:16:00 +01:00
|
|
|
*/
|
|
|
|
erofs_workgroup_unfreeze_final(grp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-31 17:57:39 +02:00
|
|
|
static unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
|
|
|
|
unsigned long nr_shrink,
|
|
|
|
bool cleanup)
|
2018-07-26 14:22:05 +02: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 14:22:06 +02:00
|
|
|
pgoff_t first_index = 0;
|
|
|
|
void *batch[PAGEVEC_SIZE];
|
2018-09-10 21:41:14 +02:00
|
|
|
unsigned int freed = 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 14:22:06 +02:00
|
|
|
|
|
|
|
int i, found;
|
|
|
|
repeat:
|
2019-07-31 17:57:35 +02:00
|
|
|
xa_lock(&sbi->workstn_tree);
|
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 14:22:06 +02:00
|
|
|
|
|
|
|
found = radix_tree_gang_lookup(&sbi->workstn_tree,
|
2019-03-19 00:58:41 +01:00
|
|
|
batch, first_index, PAGEVEC_SIZE);
|
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 14:22:06 +02:00
|
|
|
|
|
|
|
for (i = 0; i < found; ++i) {
|
2017-11-03 18:30:42 +01:00
|
|
|
struct erofs_workgroup *grp = xa_untag_pointer(batch[i]);
|
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 14:22:06 +02:00
|
|
|
|
|
|
|
first_index = grp->index + 1;
|
|
|
|
|
2018-11-22 18:16:00 +01:00
|
|
|
/* try to shrink each valid workgroup */
|
|
|
|
if (!erofs_try_to_release_workgroup(sbi, grp, cleanup))
|
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 14:22:06 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
++freed;
|
2019-08-29 18:38:27 +02:00
|
|
|
if (!--nr_shrink)
|
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 14:22:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-07-31 17:57:35 +02:00
|
|
|
xa_unlock(&sbi->workstn_tree);
|
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 14:22:06 +02:00
|
|
|
|
|
|
|
if (i && nr_shrink)
|
|
|
|
goto repeat;
|
|
|
|
return freed;
|
2018-07-26 14:22:05 +02:00
|
|
|
}
|
|
|
|
|
2018-07-26 14:22:04 +02:00
|
|
|
/* protected by 'erofs_sb_list_lock' */
|
|
|
|
static unsigned int shrinker_run_no;
|
|
|
|
|
|
|
|
/* protects the mounted 'erofs_sb_list' */
|
|
|
|
static DEFINE_SPINLOCK(erofs_sb_list_lock);
|
2018-07-26 14:22:03 +02:00
|
|
|
static LIST_HEAD(erofs_sb_list);
|
|
|
|
|
2019-07-31 17:57:39 +02:00
|
|
|
void erofs_shrinker_register(struct super_block *sb)
|
2018-07-26 14:22:03 +02:00
|
|
|
{
|
2018-07-26 14:22:04 +02:00
|
|
|
struct erofs_sb_info *sbi = EROFS_SB(sb);
|
|
|
|
|
|
|
|
mutex_init(&sbi->umount_mutex);
|
|
|
|
|
|
|
|
spin_lock(&erofs_sb_list_lock);
|
|
|
|
list_add(&sbi->list, &erofs_sb_list);
|
|
|
|
spin_unlock(&erofs_sb_list_lock);
|
2018-07-26 14:22:03 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 17:57:39 +02:00
|
|
|
void erofs_shrinker_unregister(struct super_block *sb)
|
2018-07-26 14:22:03 +02:00
|
|
|
{
|
2019-07-31 17:57:39 +02:00
|
|
|
struct erofs_sb_info *const sbi = EROFS_SB(sb);
|
|
|
|
|
|
|
|
mutex_lock(&sbi->umount_mutex);
|
|
|
|
erofs_shrink_workstation(sbi, ~0UL, true);
|
|
|
|
|
2018-07-26 14:22:04 +02:00
|
|
|
spin_lock(&erofs_sb_list_lock);
|
2019-07-31 17:57:39 +02:00
|
|
|
list_del(&sbi->list);
|
2018-07-26 14:22:04 +02:00
|
|
|
spin_unlock(&erofs_sb_list_lock);
|
2019-07-31 17:57:39 +02:00
|
|
|
mutex_unlock(&sbi->umount_mutex);
|
2018-07-26 14:22:04 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 09:59:55 +01:00
|
|
|
static unsigned long erofs_shrink_count(struct shrinker *shrink,
|
|
|
|
struct shrink_control *sc)
|
2018-07-26 14:22:04 +02:00
|
|
|
{
|
|
|
|
return atomic_long_read(&erofs_global_shrink_cnt);
|
|
|
|
}
|
|
|
|
|
2019-01-16 09:59:55 +01:00
|
|
|
static unsigned long erofs_shrink_scan(struct shrinker *shrink,
|
|
|
|
struct shrink_control *sc)
|
2018-07-26 14:22:04 +02:00
|
|
|
{
|
|
|
|
struct erofs_sb_info *sbi;
|
|
|
|
struct list_head *p;
|
|
|
|
|
|
|
|
unsigned long nr = sc->nr_to_scan;
|
|
|
|
unsigned int run_no;
|
|
|
|
unsigned long freed = 0;
|
|
|
|
|
|
|
|
spin_lock(&erofs_sb_list_lock);
|
2019-07-31 17:57:50 +02:00
|
|
|
do {
|
2018-07-26 14:22:04 +02:00
|
|
|
run_no = ++shrinker_run_no;
|
2019-07-31 17:57:50 +02:00
|
|
|
} while (run_no == 0);
|
2018-07-26 14:22:04 +02:00
|
|
|
|
|
|
|
/* Iterate over all mounted superblocks and try to shrink them */
|
|
|
|
p = erofs_sb_list.next;
|
|
|
|
while (p != &erofs_sb_list) {
|
|
|
|
sbi = list_entry(p, struct erofs_sb_info, list);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We move the ones we do to the end of the list, so we stop
|
|
|
|
* when we see one we have already done.
|
|
|
|
*/
|
|
|
|
if (sbi->shrinker_run_no == run_no)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!mutex_trylock(&sbi->umount_mutex)) {
|
|
|
|
p = p->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&erofs_sb_list_lock);
|
|
|
|
sbi->shrinker_run_no = run_no;
|
|
|
|
|
2020-02-26 09:10:06 +01:00
|
|
|
freed += erofs_shrink_workstation(sbi, nr - freed, false);
|
2018-07-26 14:22:04 +02:00
|
|
|
|
|
|
|
spin_lock(&erofs_sb_list_lock);
|
|
|
|
/* Get the next list element before we move this one */
|
|
|
|
p = p->next;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move this one to the end of the list to provide some
|
|
|
|
* fairness.
|
|
|
|
*/
|
|
|
|
list_move_tail(&sbi->list, &erofs_sb_list);
|
|
|
|
mutex_unlock(&sbi->umount_mutex);
|
|
|
|
|
|
|
|
if (freed >= nr)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock(&erofs_sb_list_lock);
|
|
|
|
return freed;
|
2018-07-26 14:22:03 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 17:57:39 +02:00
|
|
|
static struct shrinker erofs_shrinker_info = {
|
2019-01-16 09:59:55 +01:00
|
|
|
.scan_objects = erofs_shrink_scan,
|
|
|
|
.count_objects = erofs_shrink_count,
|
|
|
|
.seeks = DEFAULT_SEEKS,
|
|
|
|
};
|
|
|
|
|
2019-07-31 17:57:39 +02:00
|
|
|
int __init erofs_init_shrinker(void)
|
|
|
|
{
|
|
|
|
return register_shrinker(&erofs_shrinker_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void erofs_exit_shrinker(void)
|
|
|
|
{
|
|
|
|
unregister_shrinker(&erofs_shrinker_info);
|
|
|
|
}
|
|
|
|
#endif /* !CONFIG_EROFS_FS_ZIP */
|
|
|
|
|