linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Colin Cross <ccross@android.com>
To: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Colin Cross <ccross@android.com>
Subject: [PATCH 2/3] sched_stats: use the new seq_reserve function
Date: Thu, 22 Sep 2011 13:57:08 -0700	[thread overview]
Message-ID: <1316725029-22737-3-git-send-email-ccross@android.com> (raw)
In-Reply-To: <1316725029-22737-1-git-send-email-ccross@android.com>

Instead of writing directly to private members of the seq_file struct,
use the new seq_reserve function to specify the predicted size of the
seq buffer.

Signed-off-by: Colin Cross <ccross@android.com>
---
 fs/proc/stat.c       |   23 ++++++++---------------
 kernel/sched_stats.h |   18 +++++++++---------
 2 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 9758b65..1fdf158 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -6,7 +6,6 @@
 #include <linux/proc_fs.h>
 #include <linux/sched.h>
 #include <linux/seq_file.h>
-#include <linux/slab.h>
 #include <linux/time.h>
 #include <linux/irqnr.h>
 #include <asm/cputime.h>
@@ -134,24 +133,18 @@ static int show_stat(struct seq_file *p, void *v)
 static int stat_open(struct inode *inode, struct file *file)
 {
 	unsigned size = 4096 * (1 + num_possible_cpus() / 32);
-	char *buf;
 	struct seq_file *m;
 	int res;
 
-	/* don't ask for more than the kmalloc() max size */
-	if (size > KMALLOC_MAX_SIZE)
-		size = KMALLOC_MAX_SIZE;
-	buf = kmalloc(size, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
 	res = single_open(file, show_stat, NULL);
-	if (!res) {
-		m = file->private_data;
-		m->buf = buf;
-		m->size = size;
-	} else
-		kfree(buf);
+	if (res)
+		return res;
+
+	m = file->private_data;
+	res = seq_reserve(m, size);
+	if (res)
+		single_release(inode, file);
+
 	return res;
 }
 
diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h
index 331e01b..ee05143 100644
--- a/kernel/sched_stats.h
+++ b/kernel/sched_stats.h
@@ -74,19 +74,19 @@ static int show_schedstat(struct seq_file *seq, void *v)
 static int schedstat_open(struct inode *inode, struct file *file)
 {
 	unsigned int size = PAGE_SIZE * (1 + num_online_cpus() / 32);
-	char *buf = kmalloc(size, GFP_KERNEL);
 	struct seq_file *m;
 	int res;
 
-	if (!buf)
-		return -ENOMEM;
 	res = single_open(file, show_schedstat, NULL);
-	if (!res) {
-		m = file->private_data;
-		m->buf = buf;
-		m->size = size;
-	} else
-		kfree(buf);
+	if (res)
+		return res;
+
+
+	m = file->private_data;
+	res = seq_reserve(m, size);
+	if (res)
+		single_release(inode, file);
+
 	return res;
 }
 
-- 
1.7.4.1

  parent reply	other threads:[~2011-09-22 20:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-22 20:57 [PATCH 0/3] Replace kmalloc with vmalloc in seq_files Colin Cross
2011-09-22 20:57 ` [PATCH 1/3] fs: seq_file: add seq_reserve Colin Cross
2011-09-22 22:54   ` Alan Cox
2011-09-22 23:24     ` Colin Cross
2011-09-22 20:57 ` Colin Cross [this message]
2011-09-22 20:57 ` [PATCH 3/3] seq_file: convert seq buffer to vmalloc Colin Cross
2011-09-22 21:07   ` Joe Perches
2011-09-22 21:19     ` Colin Cross
2011-09-22 23:26       ` NamJae Jeon
2011-09-22 21:20     ` Peter Zijlstra
2011-09-22 21:22 ` [PATCH 0/3] Replace kmalloc with vmalloc in seq_files Peter Zijlstra
2011-09-22 21:23 ` Christoph Hellwig
2011-09-23  0:00   ` Colin Cross

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=1316725029-22737-3-git-send-email-ccross@android.com \
    --to=ccross@android.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).