From: Stephen Hemminger <shemminger@vyatta.com>
To: Phillip Lougher <phillip@lougher.demon.co.uk>,
kirk w <kirkpuppy@yahoo.com>
Cc: linux-fsdevel@vger.kernel.org, squashfs-devel@lists.sourceforge.net
Subject: [RFC 1/4] squashfs: use percpu for zlib decompression
Date: Fri, 22 Apr 2011 14:17:25 -0700 [thread overview]
Message-ID: <20110422212037.646381436@vyatta.com> (raw)
In-Reply-To: 20110422211724.400984699@vyatta.com
[-- Attachment #1: squashfs-gzip-percpu.patch --]
[-- Type: text/plain, Size: 3520 bytes --]
Make zlib decompression multi-threaded.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
--- a/fs/squashfs/zlib_wrapper.c 2011-04-22 10:57:09.450024619 -0700
+++ b/fs/squashfs/zlib_wrapper.c 2011-04-22 13:15:52.509266395 -0700
@@ -26,6 +26,7 @@
#include <linux/buffer_head.h>
#include <linux/slab.h>
#include <linux/zlib.h>
+#include <linux/percpu.h>
#include <linux/vmalloc.h>
#include "squashfs_fs.h"
@@ -33,31 +34,53 @@
#include "squashfs.h"
#include "decompressor.h"
+/* don't use per superblock stream anymore. */
static void *zlib_init(struct squashfs_sb_info *dummy, void *buff, int len)
{
- z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL);
- if (stream == NULL)
- goto failed;
- stream->workspace = vmalloc(zlib_inflate_workspacesize());
- if (stream->workspace == NULL)
- goto failed;
+ z_stream __percpu *percpu;
+ z_stream *stream;
+ int cpu, cpu0;
+
+ percpu = alloc_percpu(z_stream);
+ if (!percpu) {
+ ERROR("Failed to allocate per cpu stream\n");
+ return ERR_PTR(-ENOMEM);
+ }
+
+ for_each_possible_cpu(cpu) {
+ stream = per_cpu_ptr(percpu, cpu);
+
+ stream->workspace = vmalloc(zlib_inflate_workspacesize());
+ if (stream->workspace == NULL)
+ goto failed;
+ }
- return stream;
+ return (__force void *) percpu;
failed:
- ERROR("Failed to allocate zlib workspace\n");
- kfree(stream);
+ for_each_possible_cpu(cpu0) {
+ if (cpu0 == cpu)
+ break;
+ stream = per_cpu_ptr(percpu, cpu);
+ vfree(stream->workspace);
+ }
+ free_percpu(percpu);
+
+ ERROR("Failed to allocate zlib workspaces\n");
return ERR_PTR(-ENOMEM);
}
-
static void zlib_free(void *strm)
{
- z_stream *stream = strm;
+ z_stream __percpu *percpu = (z_stream __percpu *) strm;
+ int cpu;
- if (stream)
+ for_each_possible_cpu(cpu) {
+ z_stream *stream = per_cpu_ptr(percpu, cpu);
vfree(stream->workspace);
- kfree(stream);
+
+ }
+ free_percpu(percpu);
}
@@ -67,9 +90,8 @@ static int zlib_uncompress(struct squash
{
int zlib_err, zlib_init = 0;
int k = 0, page = 0;
- z_stream *stream = msblk->stream;
-
- mutex_lock(&msblk->read_data_mutex);
+ z_stream __percpu *percpu = (z_stream __percpu *)msblk->stream;
+ z_stream *stream = get_cpu_ptr(percpu);
stream->avail_out = 0;
stream->avail_in = 0;
@@ -80,7 +102,7 @@ static int zlib_uncompress(struct squash
length -= avail;
wait_on_buffer(bh[k]);
if (!buffer_uptodate(bh[k]))
- goto release_mutex;
+ goto put_per_cpu;
stream->next_in = bh[k]->b_data + offset;
stream->avail_in = avail;
@@ -98,7 +120,7 @@ static int zlib_uncompress(struct squash
ERROR("zlib_inflateInit returned unexpected "
"result 0x%x, srclength %d\n",
zlib_err, srclength);
- goto release_mutex;
+ goto put_per_cpu;
}
zlib_init = 1;
}
@@ -111,26 +133,26 @@ static int zlib_uncompress(struct squash
if (zlib_err != Z_STREAM_END) {
ERROR("zlib_inflate error, data probably corrupt\n");
- goto release_mutex;
+ goto put_per_cpu;
}
zlib_err = zlib_inflateEnd(stream);
if (zlib_err != Z_OK) {
ERROR("zlib_inflate error, data probably corrupt\n");
- goto release_mutex;
+ goto put_per_cpu;
}
if (k < b) {
ERROR("zlib_uncompress error, data remaining\n");
- goto release_mutex;
+ goto put_per_cpu;
}
length = stream->total_out;
- mutex_unlock(&msblk->read_data_mutex);
+ put_cpu_ptr(stream);
return length;
-release_mutex:
- mutex_unlock(&msblk->read_data_mutex);
+put_per_cpu:
+ put_cpu_ptr(stream);
for (; k < b; k++)
put_bh(bh[k]);
next prev parent reply other threads:[~2011-04-22 22:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-22 21:17 [RFC 0/4] Squashfs decompresssion per-cpu Stephen Hemminger
2011-04-22 21:17 ` Stephen Hemminger [this message]
2011-04-22 21:17 ` [RFC 2/4] squashfs: use percpu for lzo decompression Stephen Hemminger
2011-04-22 21:17 ` [RFC 3/4] squashfs: use percpu for xz decompression Stephen Hemminger
2011-04-22 21:17 ` [RFC 4/4] squashfs: eliminate read_data_mutex Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110422212037.646381436@vyatta.com \
--to=shemminger@vyatta.com \
--cc=kirkpuppy@yahoo.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=phillip@lougher.demon.co.uk \
--cc=squashfs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.