public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Changli Gao <xiaosuo@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Jiri Slaby <jslaby@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Changli Gao <xiaosuo@gmail.com>
Subject: [PATCH] fs: use kmalloc() to allocate fdmem if possible
Date: Mon,  3 May 2010 00:46:16 +0800	[thread overview]
Message-ID: <1272818776-7729-1-git-send-email-xiaosuo@gmail.com> (raw)
In-Reply-To: <Alexander Viro <viro@zeniv.linux.org.uk>

use kmalloc() to allocate fdmem if possible.

vmalloc() is used as a fallback solution for fdmem allocation. Two members are
added into the hole of the structure fdtable to indicate if vmalloc() is used
or not.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
 fs/file.c               |   33 ++++++++++++++++++++-------------
 include/linux/fdtable.h |    2 ++
 2 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/fs/file.c b/fs/file.c
index 34bb7f7..f71dd85 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -39,28 +39,34 @@ int sysctl_nr_open_max = 1024 * 1024; /* raised later */
  */
 static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list);
 
-static inline void * alloc_fdmem(unsigned int size)
+static inline void *alloc_fdmem(unsigned int size, unsigned short *use_vmalloc)
 {
-	if (size <= PAGE_SIZE)
-		return kmalloc(size, GFP_KERNEL);
-	else
-		return vmalloc(size);
+	void *data;
+
+	data = kmalloc(size, GFP_KERNEL);
+	if (data != NULL) {
+		*use_vmalloc = 0;
+		return data;
+	}
+	*use_vmalloc = 1;
+
+	return vmalloc(size);
 }
 
 static inline void free_fdarr(struct fdtable *fdt)
 {
-	if (fdt->max_fds <= (PAGE_SIZE / sizeof(struct file *)))
-		kfree(fdt->fd);
-	else
+	if (fdt->fdarr_vmalloc)
 		vfree(fdt->fd);
+	else
+		kfree(fdt->fd);
 }
 
 static inline void free_fdset(struct fdtable *fdt)
 {
-	if (fdt->max_fds <= (PAGE_SIZE * BITS_PER_BYTE / 2))
-		kfree(fdt->open_fds);
-	else
+	if (fdt->fdset_vmalloc)
 		vfree(fdt->open_fds);
+	else
+		kfree(fdt->open_fds);
 }
 
 static void free_fdtable_work(struct work_struct *work)
@@ -167,12 +173,13 @@ static struct fdtable * alloc_fdtable(unsigned int nr)
 	if (!fdt)
 		goto out;
 	fdt->max_fds = nr;
-	data = alloc_fdmem(nr * sizeof(struct file *));
+	data = alloc_fdmem(nr * sizeof(struct file *), &fdt->fdarr_vmalloc);
 	if (!data)
 		goto out_fdt;
 	fdt->fd = (struct file **)data;
 	data = alloc_fdmem(max_t(unsigned int,
-				 2 * nr / BITS_PER_BYTE, L1_CACHE_BYTES));
+				 2 * nr / BITS_PER_BYTE, L1_CACHE_BYTES),
+			   &fdt->fdset_vmalloc);
 	if (!data)
 		goto out_arr;
 	fdt->open_fds = (fd_set *)data;
diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
index 013dc52..1e730bc 100644
--- a/include/linux/fdtable.h
+++ b/include/linux/fdtable.h
@@ -30,6 +30,8 @@ struct embedded_fd_set {
 
 struct fdtable {
 	unsigned int max_fds;
+	unsigned short fdarr_vmalloc;
+	unsigned short fdset_vmalloc;
 	struct file ** fd;      /* current fd array */
 	fd_set *close_on_exec;
 	fd_set *open_fds;

       reply	other threads:[~2010-05-02 16:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Alexander Viro <viro@zeniv.linux.org.uk>
2010-05-02 16:46 ` Changli Gao [this message]
2010-05-02 17:31   ` [PATCH] fs: use kmalloc() to allocate fdmem if possible Avi Kivity
2010-05-03  0:15     ` Tetsuo Handa
2010-05-03  6:06       ` Avi Kivity
2010-05-03  7:05         ` Changli Gao
2010-05-03  7:42           ` Avi Kivity
2010-05-03  7:52             ` Changli Gao
2010-05-03  8:49               ` Avi Kivity
2010-05-03  9:03                 ` Jiri Slaby
2010-05-03  9:18                   ` Avi Kivity
2010-05-03  9:22                     ` Jiri Slaby
2010-05-03  9:25                       ` Jiri Slaby
2010-05-03  9:28                       ` Avi Kivity
2010-05-03  9:13                 ` Eric Dumazet
2010-05-03  9:19                   ` Jiri Slaby
2010-05-03  9:29                     ` Eric Dumazet
2010-05-04  4:20                   ` Changli Gao
2010-05-04  5:33                     ` Eric Dumazet

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=1272818776-7729-1-git-send-email-xiaosuo@gmail.com \
    --to=xiaosuo@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jslaby@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    /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