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 3/4] squashfs: use percpu for xz decompression
Date: Fri, 22 Apr 2011 14:17:27 -0700 [thread overview]
Message-ID: <20110422212037.796772577@vyatta.com> (raw)
In-Reply-To: 20110422211724.400984699@vyatta.com
[-- Attachment #1: squashfs-xz-percpu.patch --]
[-- Type: text/plain, Size: 2689 bytes --]
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
--- a/fs/squashfs/xz_wrapper.c 2011-04-22 13:55:21.251194626 -0700
+++ b/fs/squashfs/xz_wrapper.c 2011-04-22 13:55:35.779665142 -0700
@@ -47,9 +47,11 @@ static void *squashfs_xz_init(struct squ
int len)
{
struct comp_opts *comp_opts = buff;
+ struct squashfs_xz __percpu *percpu;
struct squashfs_xz *stream;
int dict_size = msblk->block_size;
int err, n;
+ int cpu, cpu0;
if (comp_opts) {
/* check compressor options are the expected length */
@@ -71,47 +73,58 @@ static void *squashfs_xz_init(struct squ
dict_size = max_t(int, dict_size, SQUASHFS_METADATA_SIZE);
- stream = kmalloc(sizeof(*stream), GFP_KERNEL);
- if (stream == NULL) {
- err = -ENOMEM;
- goto failed;
- }
+ percpu = alloc_percpu(struct squashfs_xz);
+ if (!percpu)
+ goto nomem;
+
+ for_each_possible_cpu(cpu) {
+ stream = per_cpu_ptr(percpu, cpu);
- stream->state = xz_dec_init(XZ_PREALLOC, dict_size);
- if (stream->state == NULL) {
- kfree(stream);
- err = -ENOMEM;
- goto failed;
+ stream->state = xz_dec_init(XZ_PREALLOC, dict_size);
+ if (stream->state == NULL)
+ goto cleanup_cpu;
}
- return stream;
+ return (__force void *) percpu;
+cleanup_cpu:
+ for_each_possible_cpu(cpu0) {
+ if (cpu0 == cpu)
+ break;
+
+ stream = per_cpu_ptr(percpu, cpu);
+ xz_dec_end(stream->state);
+ }
+ free_percpu(percpu);
+nomem:
+ err = -ENOMEM;
failed:
ERROR("Failed to initialise xz decompressor\n");
return ERR_PTR(err);
}
-
static void squashfs_xz_free(void *strm)
{
- struct squashfs_xz *stream = strm;
+ struct squashfs_xz __percpu *percpu
+ = (struct squashfs_xz __percpu *) strm;
+ int cpu;
- if (stream) {
+ for_each_possible_cpu(cpu) {
+ struct squashfs_xz *stream = per_cpu_ptr(percpu, cpu);
xz_dec_end(stream->state);
- kfree(stream);
}
+ free_percpu(percpu);
}
-
static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void **buffer,
struct buffer_head **bh, int b, int offset, int length, int srclength,
int pages)
{
enum xz_ret xz_err;
int avail, total = 0, k = 0, page = 0;
- struct squashfs_xz *stream = msblk->stream;
-
- mutex_lock(&msblk->read_data_mutex);
+ struct squashfs_xz __percpu *percpu
+ = (struct squashfs_xz __percpu *)msblk->stream;
+ struct squashfs_xz *stream = get_cpu_ptr(percpu);
xz_dec_reset(stream->state);
stream->buf.in_pos = 0;
@@ -158,11 +171,11 @@ static int squashfs_xz_uncompress(struct
}
total += stream->buf.out_pos;
- mutex_unlock(&msblk->read_data_mutex);
+ put_cpu_ptr(stream);
return total;
release_mutex:
- mutex_unlock(&msblk->read_data_mutex);
+ 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 ` [RFC 1/4] squashfs: use percpu for zlib decompression Stephen Hemminger
2011-04-22 21:17 ` [RFC 2/4] squashfs: use percpu for lzo decompression Stephen Hemminger
2011-04-22 21:17 ` Stephen Hemminger [this message]
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.796772577@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.