squashfs: migrate from ll_rw_block usage to BIO
ll_rw_block() function has been deprecated in favor of BIO which appears to come with large performance improvements. This patch decreases boot time by close to 40% when using squashfs for the root file-system. This is observed at least in the context of starting an Android VM on Chrome OS using crosvm. The patch was tested on 4.19 as well as master. This patch is largely based on Adrien Schildknecht's patch that was originally sent as https://lkml.org/lkml/2017/9/22/814 though with some significant changes and simplifications while also taking Phillip Lougher's feedback into account, around preserving support for FILE_CACHE in particular. [akpm@linux-foundation.org: fix build error reported by Randy] Link: http://lkml.kernel.org/r/319997c2-5fc8-f889-2ea3-d913308a7c1f@infradead.org Signed-off-by: Philippe Liard <pliard@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Adrien Schildknecht <adrien+dev@schischi.me> Cc: Phillip Lougher <phillip@squashfs.org.uk> Cc: Guenter Roeck <groeck@chromium.org> Cc: Daniel Rosenberg <drosen@google.com> Link: https://chromium.googlesource.com/chromiumos/platform/crosvm Link: http://lkml.kernel.org/r/20191106074238.186023-1-pliard@google.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
9bf9511e3d
commit
93e72b3c61
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/buffer_head.h>
|
||||
#include <linux/bio.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/zstd.h>
|
||||
#include <linux/vmalloc.h>
|
||||
@@ -59,33 +59,44 @@ static void zstd_free(void *strm)
|
||||
|
||||
|
||||
static int zstd_uncompress(struct squashfs_sb_info *msblk, void *strm,
|
||||
struct buffer_head **bh, int b, int offset, int length,
|
||||
struct bio *bio, int offset, int length,
|
||||
struct squashfs_page_actor *output)
|
||||
{
|
||||
struct workspace *wksp = strm;
|
||||
ZSTD_DStream *stream;
|
||||
size_t total_out = 0;
|
||||
size_t zstd_err;
|
||||
int k = 0;
|
||||
int error = 0;
|
||||
ZSTD_inBuffer in_buf = { NULL, 0, 0 };
|
||||
ZSTD_outBuffer out_buf = { NULL, 0, 0 };
|
||||
struct bvec_iter_all iter_all = {};
|
||||
struct bio_vec *bvec = bvec_init_iter_all(&iter_all);
|
||||
|
||||
stream = ZSTD_initDStream(wksp->window_size, wksp->mem, wksp->mem_size);
|
||||
|
||||
if (!stream) {
|
||||
ERROR("Failed to initialize zstd decompressor\n");
|
||||
goto out;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
out_buf.size = PAGE_SIZE;
|
||||
out_buf.dst = squashfs_first_page(output);
|
||||
|
||||
do {
|
||||
if (in_buf.pos == in_buf.size && k < b) {
|
||||
int avail = min(length, msblk->devblksize - offset);
|
||||
for (;;) {
|
||||
size_t zstd_err;
|
||||
|
||||
if (in_buf.pos == in_buf.size) {
|
||||
const void *data;
|
||||
int avail;
|
||||
|
||||
if (!bio_next_segment(bio, &iter_all)) {
|
||||
error = -EIO;
|
||||
break;
|
||||
}
|
||||
|
||||
avail = min(length, ((int)bvec->bv_len) - offset);
|
||||
data = page_address(bvec->bv_page) + bvec->bv_offset;
|
||||
length -= avail;
|
||||
in_buf.src = bh[k]->b_data + offset;
|
||||
in_buf.src = data + offset;
|
||||
in_buf.size = avail;
|
||||
in_buf.pos = 0;
|
||||
offset = 0;
|
||||
@@ -97,8 +108,8 @@ static int zstd_uncompress(struct squashfs_sb_info *msblk, void *strm,
|
||||
/* Shouldn't run out of pages
|
||||
* before stream is done.
|
||||
*/
|
||||
squashfs_finish_page(output);
|
||||
goto out;
|
||||
error = -EIO;
|
||||
break;
|
||||
}
|
||||
out_buf.pos = 0;
|
||||
out_buf.size = PAGE_SIZE;
|
||||
@@ -107,29 +118,20 @@ static int zstd_uncompress(struct squashfs_sb_info *msblk, void *strm,
|
||||
total_out -= out_buf.pos;
|
||||
zstd_err = ZSTD_decompressStream(stream, &out_buf, &in_buf);
|
||||
total_out += out_buf.pos; /* add the additional data produced */
|
||||
if (zstd_err == 0)
|
||||
break;
|
||||
|
||||
if (in_buf.pos == in_buf.size && k < b)
|
||||
put_bh(bh[k++]);
|
||||
} while (zstd_err != 0 && !ZSTD_isError(zstd_err));
|
||||
if (ZSTD_isError(zstd_err)) {
|
||||
ERROR("zstd decompression error: %d\n",
|
||||
(int)ZSTD_getErrorCode(zstd_err));
|
||||
error = -EIO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
squashfs_finish_page(output);
|
||||
|
||||
if (ZSTD_isError(zstd_err)) {
|
||||
ERROR("zstd decompression error: %d\n",
|
||||
(int)ZSTD_getErrorCode(zstd_err));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (k < b)
|
||||
goto out;
|
||||
|
||||
return (int)total_out;
|
||||
|
||||
out:
|
||||
for (; k < b; k++)
|
||||
put_bh(bh[k]);
|
||||
|
||||
return -EIO;
|
||||
return error ? error : total_out;
|
||||
}
|
||||
|
||||
const struct squashfs_decompressor squashfs_zstd_comp_ops = {
|
||||
|
Reference in New Issue
Block a user