linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 2/4] squashfs: use percpu for lzo decompression
Date: Fri, 22 Apr 2011 14:17:26 -0700	[thread overview]
Message-ID: <20110422212037.721804532@vyatta.com> (raw)
In-Reply-To: 20110422211724.400984699@vyatta.com

[-- Attachment #1: squashfs-lz-percpu.patch --]
[-- Type: text/plain, Size: 3047 bytes --]

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>


--- a/fs/squashfs/lzo_wrapper.c	2011-04-22 13:15:28.349003198 -0700
+++ b/fs/squashfs/lzo_wrapper.c	2011-04-22 13:21:03.320648456 -0700
@@ -22,6 +22,7 @@
  */
 
 #include <linux/mutex.h>
+#include <linux/percpu.h>
 #include <linux/buffer_head.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
@@ -40,51 +41,71 @@ struct squashfs_lzo {
 static void *lzo_init(struct squashfs_sb_info *msblk, void *buff, int len)
 {
 	int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
+	struct squashfs_lzo __percpu *percpu;
+	struct squashfs_lzo *stream;
+	int cpu, cpu0;
+
+	percpu = alloc_percpu(struct squashfs_lzo);
+	if (!percpu) {
+		ERROR("Failed to allocate per cpu stream\n");
+		return ERR_PTR(-ENOMEM);
+	}
 
-	struct squashfs_lzo *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
-	if (stream == NULL)
-		goto failed;
-	stream->input = vmalloc(block_size);
-	if (stream->input == NULL)
-		goto failed;
-	stream->output = vmalloc(block_size);
-	if (stream->output == NULL)
-		goto failed2;
+	for_each_possible_cpu(cpu) {
+		stream = per_cpu_ptr(percpu, cpu);
+
+		stream->input = vmalloc(block_size);
+		if (stream->input == NULL)
+			goto failed;
+
+		stream->output = vmalloc(block_size);
+		if (stream->output == NULL)
+			goto failed2;
+	}
 
-	return stream;
+	return (__force void *) percpu;
 
 failed2:
 	vfree(stream->input);
 failed:
+	for_each_possible_cpu(cpu0) {
+		if (cpu0 == cpu)
+			break;
+		stream = per_cpu_ptr(percpu, cpu);
+		vfree(stream->output);
+		vfree(stream->input);
+	}
 	ERROR("Failed to allocate lzo workspace\n");
-	kfree(stream);
+	free_percpu(percpu);
 	return ERR_PTR(-ENOMEM);
 }
 
 
 static void lzo_free(void *strm)
 {
-	struct squashfs_lzo *stream = strm;
+	struct squashfs_lzo __percpu *percpu
+		= (struct squashfs_lzo __percpu *) strm;
+	int cpu;
 
-	if (stream) {
+	for_each_possible_cpu(cpu) {
+		struct squashfs_lzo *stream = per_cpu_ptr(percpu, cpu);
 		vfree(stream->input);
 		vfree(stream->output);
 	}
-	kfree(stream);
+	free_percpu(percpu);
 }
 
-
 static int lzo_uncompress(struct squashfs_sb_info *msblk, void **buffer,
 	struct buffer_head **bh, int b, int offset, int length, int srclength,
 	int pages)
 {
-	struct squashfs_lzo *stream = msblk->stream;
+	struct squashfs_lzo __percpu *percpu
+		= (struct squashfs_lzo __percpu *)msblk->stream;
+	struct squashfs_lzo *stream = get_cpu_ptr(percpu);
 	void *buff = stream->input;
 	int avail, i, bytes = length, res;
 	size_t out_len = srclength;
 
-	mutex_lock(&msblk->read_data_mutex);
-
 	for (i = 0; i < b; i++) {
 		wait_on_buffer(bh[i]);
 		if (!buffer_uptodate(bh[i]))
@@ -111,7 +132,7 @@ static int lzo_uncompress(struct squashf
 		bytes -= avail;
 	}
 
-	mutex_unlock(&msblk->read_data_mutex);
+	put_cpu_ptr(stream);
 	return res;
 
 block_release:
@@ -119,7 +140,7 @@ block_release:
 		put_bh(bh[i]);
 
 failed:
-	mutex_unlock(&msblk->read_data_mutex);
+	put_cpu_ptr(stream);
 
 	ERROR("lzo decompression failed, data probably corrupt\n");
 	return -EIO;



  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 ` Stephen Hemminger [this message]
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.721804532@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).