diff options
| -rw-r--r-- | fs/squashfs/Kconfig | 13 | ||||
| -rw-r--r-- | fs/squashfs/Makefile | 9 | ||||
| -rw-r--r-- | fs/squashfs/decompressor_multi.c | 200 |
3 files changed, 221 insertions, 1 deletions
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig index c70111ebefd4..1c6d340fc61f 100644 --- a/fs/squashfs/Kconfig +++ b/fs/squashfs/Kconfig | |||
| @@ -63,6 +63,19 @@ config SQUASHFS_LZO | |||
| 63 | 63 | ||
| 64 | If unsure, say N. | 64 | If unsure, say N. |
| 65 | 65 | ||
| 66 | config SQUASHFS_MULTI_DECOMPRESSOR | ||
| 67 | bool "Use multiple decompressors for handling parallel I/O" | ||
| 68 | depends on SQUASHFS | ||
| 69 | help | ||
| 70 | By default Squashfs uses a single decompressor but it gives | ||
| 71 | poor performance on parallel I/O workloads when using multiple CPU | ||
| 72 | machines due to waiting on decompressor availability. | ||
| 73 | |||
| 74 | If you have a parallel I/O workload and your system has enough memory, | ||
| 75 | using this option may improve overall I/O performance. | ||
| 76 | |||
| 77 | If unsure, say N. | ||
| 78 | |||
| 66 | config SQUASHFS_XZ | 79 | config SQUASHFS_XZ |
| 67 | bool "Include support for XZ compressed file systems" | 80 | bool "Include support for XZ compressed file systems" |
| 68 | depends on SQUASHFS | 81 | depends on SQUASHFS |
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile index c223c8439c21..dfebc3b12d61 100644 --- a/fs/squashfs/Makefile +++ b/fs/squashfs/Makefile | |||
| @@ -4,8 +4,15 @@ | |||
| 4 | 4 | ||
| 5 | obj-$(CONFIG_SQUASHFS) += squashfs.o | 5 | obj-$(CONFIG_SQUASHFS) += squashfs.o |
| 6 | squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o | 6 | squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o |
| 7 | squashfs-y += namei.o super.o symlink.o decompressor.o decompressor_single.o | 7 | squashfs-y += namei.o super.o symlink.o decompressor.o |
| 8 | |||
| 8 | squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o | 9 | squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o |
| 9 | squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o | 10 | squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o |
| 10 | squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o | 11 | squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o |
| 11 | squashfs-$(CONFIG_SQUASHFS_ZLIB) += zlib_wrapper.o | 12 | squashfs-$(CONFIG_SQUASHFS_ZLIB) += zlib_wrapper.o |
| 13 | |||
| 14 | ifdef CONFIG_SQUASHFS_MULTI_DECOMPRESSOR | ||
| 15 | squashfs-y += decompressor_multi.o | ||
| 16 | else | ||
| 17 | squashfs-y += decompressor_single.o | ||
| 18 | endif | ||
diff --git a/fs/squashfs/decompressor_multi.c b/fs/squashfs/decompressor_multi.c new file mode 100644 index 000000000000..462731db5130 --- /dev/null +++ b/fs/squashfs/decompressor_multi.c | |||
| @@ -0,0 +1,200 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2013 | ||
| 3 | * Minchan Kim <minchan@kernel.org> | ||
| 4 | * | ||
| 5 | * This work is licensed under the terms of the GNU GPL, version 2. See | ||
| 6 | * the COPYING file in the top-level directory. | ||
| 7 | */ | ||
| 8 | #include <linux/types.h> | ||
| 9 | #include <linux/mutex.h> | ||
| 10 | #include <linux/slab.h> | ||
| 11 | #include <linux/buffer_head.h> | ||
| 12 | #include <linux/sched.h> | ||
| 13 | #include <linux/wait.h> | ||
| 14 | #include <linux/cpumask.h> | ||
| 15 | |||
| 16 | #include "squashfs_fs.h" | ||
| 17 | #include "squashfs_fs_sb.h" | ||
| 18 | #include "decompressor.h" | ||
| 19 | #include "squashfs.h" | ||
| 20 | |||
| 21 | /* | ||
| 22 | * This file implements multi-threaded decompression in the | ||
| 23 | * decompressor framework | ||
| 24 | */ | ||
| 25 | |||
| 26 | |||
| 27 | /* | ||
| 28 | * The reason that multiply two is that a CPU can request new I/O | ||
| 29 | * while it is waiting previous request. | ||
| 30 | */ | ||
| 31 | #define MAX_DECOMPRESSOR (num_online_cpus() * 2) | ||
| 32 | |||
| 33 | |||
| 34 | int squashfs_max_decompressors(void) | ||
| 35 | { | ||
| 36 | return MAX_DECOMPRESSOR; | ||
| 37 | } | ||
| 38 | |||
| 39 | |||
| 40 | struct squashfs_stream { | ||
| 41 | void *comp_opts; | ||
| 42 | struct list_head strm_list; | ||
| 43 | struct mutex mutex; | ||
| 44 | int avail_decomp; | ||
| 45 | wait_queue_head_t wait; | ||
| 46 | }; | ||
| 47 | |||
| 48 | |||
| 49 | struct decomp_stream { | ||
| 50 | void *stream; | ||
| 51 | struct list_head list; | ||
| 52 | }; | ||
| 53 | |||
| 54 | |||
| 55 | static void put_decomp_stream(struct decomp_stream *decomp_strm, | ||
| 56 | struct squashfs_stream *stream) | ||
| 57 | { | ||
| 58 | mutex_lock(&stream->mutex); | ||
| 59 | list_add(&decomp_strm->list, &stream->strm_list); | ||
| 60 | mutex_unlock(&stream->mutex); | ||
| 61 | wake_up(&stream->wait); | ||
| 62 | } | ||
| 63 | |||
| 64 | void *squashfs_decompressor_create(struct squashfs_sb_info *msblk, | ||
| 65 | void *comp_opts) | ||
| 66 | { | ||
| 67 | struct squashfs_stream *stream; | ||
| 68 | struct decomp_stream *decomp_strm = NULL; | ||
| 69 | int err = -ENOMEM; | ||
| 70 | |||
| 71 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); | ||
| 72 | if (!stream) | ||
| 73 | goto out; | ||
| 74 | |||
| 75 | stream->comp_opts = comp_opts; | ||
| 76 | mutex_init(&stream->mutex); | ||
| 77 | INIT_LIST_HEAD(&stream->strm_list); | ||
| 78 | init_waitqueue_head(&stream->wait); | ||
| 79 | |||
| 80 | /* | ||
| 81 | * We should have a decompressor at least as default | ||
| 82 | * so if we fail to allocate new decompressor dynamically, | ||
| 83 | * we could always fall back to default decompressor and | ||
| 84 | * file system works. | ||
| 85 | */ | ||
| 86 | decomp_strm = kmalloc(sizeof(*decomp_strm), GFP_KERNEL); | ||
| 87 | if (!decomp_strm) | ||
| 88 | goto out; | ||
| 89 | |||
| 90 | decomp_strm->stream = msblk->decompressor->init(msblk, | ||
| 91 | stream->comp_opts); | ||
| 92 | if (IS_ERR(decomp_strm->stream)) { | ||
| 93 | err = PTR_ERR(decomp_strm->stream); | ||
| 94 | goto out; | ||
| 95 | } | ||
| 96 | |||
| 97 | list_add(&decomp_strm->list, &stream->strm_list); | ||
| 98 | stream->avail_decomp = 1; | ||
| 99 | return stream; | ||
| 100 | |||
| 101 | out: | ||
| 102 | kfree(decomp_strm); | ||
| 103 | kfree(stream); | ||
| 104 | return ERR_PTR(err); | ||
| 105 | } | ||
| 106 | |||
| 107 | |||
| 108 | void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk) | ||
| 109 | { | ||
| 110 | struct squashfs_stream *stream = msblk->stream; | ||
| 111 | if (stream) { | ||
| 112 | struct decomp_stream *decomp_strm; | ||
| 113 | |||
| 114 | while (!list_empty(&stream->strm_list)) { | ||
| 115 | decomp_strm = list_entry(stream->strm_list.prev, | ||
| 116 | struct decomp_stream, list); | ||
| 117 | list_del(&decomp_strm->list); | ||
| 118 | msblk->decompressor->free(decomp_strm->stream); | ||
| 119 | kfree(decomp_strm); | ||
| 120 | stream->avail_decomp--; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | WARN_ON(stream->avail_decomp); | ||
| 125 | kfree(stream->comp_opts); | ||
| 126 | kfree(stream); | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | static struct decomp_stream *get_decomp_stream(struct squashfs_sb_info *msblk, | ||
| 131 | struct squashfs_stream *stream) | ||
| 132 | { | ||
| 133 | struct decomp_stream *decomp_strm; | ||
| 134 | |||
| 135 | while (1) { | ||
| 136 | mutex_lock(&stream->mutex); | ||
| 137 | |||
| 138 | /* There is available decomp_stream */ | ||
| 139 | if (!list_empty(&stream->strm_list)) { | ||
| 140 | decomp_strm = list_entry(stream->strm_list.prev, | ||
| 141 | struct decomp_stream, list); | ||
| 142 | list_del(&decomp_strm->list); | ||
| 143 | mutex_unlock(&stream->mutex); | ||
| 144 | break; | ||
| 145 | } | ||
| 146 | |||
| 147 | /* | ||
| 148 | * If there is no available decomp and already full, | ||
| 149 | * let's wait for releasing decomp from other users. | ||
| 150 | */ | ||
| 151 | if (stream->avail_decomp >= MAX_DECOMPRESSOR) | ||
| 152 | goto wait; | ||
| 153 | |||
| 154 | /* Let's allocate new decomp */ | ||
| 155 | decomp_strm = kmalloc(sizeof(*decomp_strm), GFP_KERNEL); | ||
| 156 | if (!decomp_strm) | ||
| 157 | goto wait; | ||
| 158 | |||
| 159 | decomp_strm->stream = msblk->decompressor->init(msblk, | ||
| 160 | stream->comp_opts); | ||
| 161 | if (IS_ERR(decomp_strm->stream)) { | ||
| 162 | kfree(decomp_strm); | ||
| 163 | goto wait; | ||
| 164 | } | ||
| 165 | |||
| 166 | stream->avail_decomp++; | ||
| 167 | WARN_ON(stream->avail_decomp > MAX_DECOMPRESSOR); | ||
| 168 | |||
| 169 | mutex_unlock(&stream->mutex); | ||
| 170 | break; | ||
| 171 | wait: | ||
| 172 | /* | ||
| 173 | * If system memory is tough, let's for other's | ||
| 174 | * releasing instead of hurting VM because it could | ||
| 175 | * make page cache thrashing. | ||
| 176 | */ | ||
| 177 | mutex_unlock(&stream->mutex); | ||
| 178 | wait_event(stream->wait, | ||
| 179 | !list_empty(&stream->strm_list)); | ||
| 180 | } | ||
| 181 | |||
| 182 | return decomp_strm; | ||
| 183 | } | ||
| 184 | |||
| 185 | |||
| 186 | int squashfs_decompress(struct squashfs_sb_info *msblk, | ||
| 187 | void **buffer, struct buffer_head **bh, int b, int offset, int length, | ||
| 188 | int srclength, int pages) | ||
| 189 | { | ||
| 190 | int res; | ||
| 191 | struct squashfs_stream *stream = msblk->stream; | ||
| 192 | struct decomp_stream *decomp_stream = get_decomp_stream(msblk, stream); | ||
| 193 | res = msblk->decompressor->decompress(msblk, decomp_stream->stream, | ||
| 194 | buffer, bh, b, offset, length, srclength, pages); | ||
| 195 | put_decomp_stream(decomp_stream, stream); | ||
| 196 | if (res < 0) | ||
| 197 | ERROR("%s decompression failed, data probably corrupt\n", | ||
| 198 | msblk->decompressor->name); | ||
| 199 | return res; | ||
| 200 | } | ||
