Whamcloud - gitweb
LU-2762 ldiskfs: use upstream ext4_kvzalloc
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel6.3 / ext4-introduce-ext4_kvmalloc-ext4_kzalloc-and-ext4_kvfree.patch
1 From 9933fc0ac1ac14b795819cd63d05ea92112f690a Mon Sep 17 00:00:00 2001
2 From: Theodore Ts'o <tytso@mit.edu>
3 Date: Mon, 1 Aug 2011 08:45:02 -0400
4 Subject: ext4: introduce ext4_kvmalloc(), ext4_kzalloc(), and ext4_kvfree()
5 Git-commit: 9933fc0a
6 Patch-mainline: v3.1-rc1
7
8 Introduce new helper functions which try kmalloc, and then fall back
9 to vmalloc if necessary, and use them for allocating and deallocating
10 s_flex_groups.
11
12 Upstream-Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
13 Signed-off-by: Jeff Mahoney <jeffm@suse.com>
14 ---
15  fs/ext4/ext4.h  |    3 +++
16  fs/ext4/super.c |   54 ++++++++++++++++++++++++++++++++++++------------------
17  2 files changed, 39 insertions(+), 18 deletions(-)
18
19 --- a/fs/ext4/ext4.h
20 +++ b/fs/ext4/ext4.h
21 @@ -1686,6 +1686,9 @@ extern int ext4_group_extend(struct supe
22                                 ext4_fsblk_t n_blocks_count);
23
24  /* super.c */
25 +extern void *ext4_kvmalloc(size_t size, gfp_t flags);
26 +extern void *ext4_kvzalloc(size_t size, gfp_t flags);
27 +extern void ext4_kvfree(void *ptr);
28  extern void __ext4_error(struct super_block *, const char *, const char *, ...)
29         __attribute__ ((format (printf, 3, 4)));
30  #define ext4_error(sb, message...)     __ext4_error(sb, __func__, ## message)
31 --- a/fs/ext4/super.c
32 +++ b/fs/ext4/super.c
33 @@ -80,6 +80,35 @@ static void ext4_clear_request_list(void
34
35  wait_queue_head_t aio_wq[WQ_HASH_SZ];
36
37 +void *ext4_kvmalloc(size_t size, gfp_t flags)
38 +{
39 +       void *ret;
40 +
41 +       ret = kmalloc(size, flags);
42 +       if (!ret)
43 +               ret = __vmalloc(size, flags, PAGE_KERNEL);
44 +       return ret;
45 +}
46 +
47 +void *ext4_kvzalloc(size_t size, gfp_t flags)
48 +{
49 +       void *ret;
50 +
51 +       ret = kmalloc(size, flags);
52 +       if (!ret)
53 +               ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
54 +       return ret;
55 +}
56 +
57 +void ext4_kvfree(void *ptr)
58 +{
59 +       if (is_vmalloc_addr(ptr))
60 +               vfree(ptr);
61 +       else
62 +               kfree(ptr);
63 +
64 +}
65 +
66  ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
67                                struct ext4_group_desc *bg)
68  {
69 @@ -677,10 +706,7 @@ static void ext4_put_super(struct super_
70         for (i = 0; i < sbi->s_gdb_count; i++)
71                 brelse(sbi->s_group_desc[i]);
72         kfree(sbi->s_group_desc);
73 -       if (is_vmalloc_addr(sbi->s_flex_groups))
74 -               vfree(sbi->s_flex_groups);
75 -       else
76 -               kfree(sbi->s_flex_groups);
77 +       ext4_kvfree(sbi->s_flex_groups);
78         percpu_counter_destroy(&sbi->s_freeblocks_counter);
79         percpu_counter_destroy(&sbi->s_freeinodes_counter);
80         percpu_counter_destroy(&sbi->s_dirs_counter);
81 @@ -1815,15 +1841,11 @@ static int ext4_fill_flex_info(struct su
82                         ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
83                               EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
84         size = flex_group_count * sizeof(struct flex_groups);
85 -       sbi->s_flex_groups = kzalloc(size, GFP_KERNEL);
86 +       sbi->s_flex_groups = ext4_kvzalloc(size, GFP_KERNEL);
87         if (sbi->s_flex_groups == NULL) {
88 -               sbi->s_flex_groups = vzalloc(size);
89 -               if (sbi->s_flex_groups == NULL) {
90 -                       ext4_msg(sb, KERN_ERR,
91 -                                "not enough memory for %u flex groups",
92 -                                flex_group_count);
93 -                       goto failed;
94 -               }
95 +               ext4_msg(sb, KERN_ERR, "not enough memory for %u flex groups",
96 +                        flex_group_count);
97 +               goto failed;
98         }
99
100         for (i = 0; i < sbi->s_groups_count; i++) {
101 @@ -3464,12 +3486,8 @@ failed_mount_wq:
102                 sbi->s_journal = NULL;
103         }
104  failed_mount3:
105 -       if (sbi->s_flex_groups) {
106 -               if (is_vmalloc_addr(sbi->s_flex_groups))
107 -                       vfree(sbi->s_flex_groups);
108 -               else
109 -                       kfree(sbi->s_flex_groups);
110 -       }
111 +       if (sbi->s_flex_groups)
112 +               ext4_kvfree(sbi->s_flex_groups);
113         percpu_counter_destroy(&sbi->s_freeblocks_counter);
114         percpu_counter_destroy(&sbi->s_freeinodes_counter);
115         percpu_counter_destroy(&sbi->s_dirs_counter);