aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2009-04-06 22:01:43 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-07 11:31:16 -0400
commit3358b4aaa84fd4c1cdd64391875e92cbb8afeb29 (patch)
tree4ae252a8b06715a57a76c8a645f44c3ce0066d9c /fs
parent0c4fb877641c5c72d4a3ce8921a256bfe44055c0 (diff)
nilfs2: fix problems of memory allocation in ioctl
This is another patch for fixing the following problems of a memory copy function in nilfs2 ioctl: (1) It tries to allocate 128KB size of memory even for small objects. (2) Though the function repeatedly tries large memory allocations while reducing the size, GFP_NOWAIT flag is not specified. This increases the possibility of system memory shortage. (3) During the retries of (2), verbose warnings are printed because _GFP_NOWARN flag is not used for the kmalloc calls. The first patch was still doing large allocations by kmalloc which are repeatedly tried while reducing the size. Andi Kleen told me that using copy_from_user for large memory is not good from the viewpoint of preempt latency: On Fri, 12 Dec 2008 21:24:11 +0100, Andi Kleen <andi@firstfloor.org> wrote: > > In the current interface, each data item is copied twice: one is to > > the allocated memory from user space (via copy_from_user), and another > > For such large copies it is better to use multiple smaller (e.g. 4K) > copy user, that gives better real time preempt latencies. Each cfu has a > cond_resched(), but only one, not multiple times in the inner loop. He also advised me that: On Sun, 14 Dec 2008 16:13:27 +0100, Andi Kleen <andi@firstfloor.org> wrote: > Better would be if you could go to PAGE_SIZE. order 0 allocations > are typically the fastest / least likely to stall. > > Also in this case it's a good idea to use __get_free_pages() > directly, kmalloc tends to be become less efficient at larger > sizes. For the function in question, the size of buffer memory can be reduced since the buffer is repeatedly used for a number of small objects. On the other hand, it may incur large preempt latencies for larger buffer because a copy_from_user (and a copy_to_user) was applied only once each cycle. With that, this revision uses the order 0 allocations with __get_free_pages() to fix the original problems. Cc: Andi Kleen <andi@firstfloor.org> Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/nilfs2/ioctl.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index 35ba60ea9617..02e91e167ca2 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -34,9 +34,6 @@
34#include "dat.h" 34#include "dat.h"
35 35
36 36
37#define KMALLOC_SIZE_MIN 4096 /* 4KB */
38#define KMALLOC_SIZE_MAX 131072 /* 128 KB */
39
40static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs, 37static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
41 struct nilfs_argv *argv, int dir, 38 struct nilfs_argv *argv, int dir,
42 ssize_t (*dofunc)(struct the_nilfs *, 39 ssize_t (*dofunc)(struct the_nilfs *,
@@ -44,21 +41,20 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
44 void *, size_t, size_t)) 41 void *, size_t, size_t))
45{ 42{
46 void *buf; 43 void *buf;
47 size_t ksize, maxmembs, total, n; 44 size_t maxmembs, total, n;
48 ssize_t nr; 45 ssize_t nr;
49 int ret, i; 46 int ret, i;
50 47
51 if (argv->v_nmembs == 0) 48 if (argv->v_nmembs == 0)
52 return 0; 49 return 0;
53 50
54 for (ksize = KMALLOC_SIZE_MAX; ksize >= KMALLOC_SIZE_MIN; ksize /= 2) { 51 if (argv->v_size > PAGE_SIZE)
55 buf = kmalloc(ksize, GFP_NOFS); 52 return -EINVAL;
56 if (buf != NULL) 53
57 break; 54 buf = (void *)__get_free_pages(GFP_NOFS, 0);
58 } 55 if (unlikely(!buf))
59 if (ksize < KMALLOC_SIZE_MIN)
60 return -ENOMEM; 56 return -ENOMEM;
61 maxmembs = ksize / argv->v_size; 57 maxmembs = PAGE_SIZE / argv->v_size;
62 58
63 ret = 0; 59 ret = 0;
64 total = 0; 60 total = 0;
@@ -89,7 +85,7 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
89 } 85 }
90 argv->v_nmembs = total; 86 argv->v_nmembs = total;
91 87
92 kfree(buf); 88 free_pages((unsigned long)buf, 0);
93 return ret; 89 return ret;
94} 90}
95 91