+++ /dev/null
-From 9933fc0ac1ac14b795819cd63d05ea92112f690a Mon Sep 17 00:00:00 2001
-From: Theodore Ts'o <tytso@mit.edu>
-Date: Mon, 1 Aug 2011 08:45:02 -0400
-Subject: ext4: introduce ext4_kvmalloc(), ext4_kzalloc(), and ext4_kvfree()
-Git-commit: 9933fc0a
-Patch-mainline: v3.1-rc1
-
-Introduce new helper functions which try kmalloc, and then fall back
-to vmalloc if necessary, and use them for allocating and deallocating
-s_flex_groups.
-
-Upstream-Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-Signed-off-by: Jeff Mahoney <jeffm@suse.com>
----
- fs/ext4/ext4.h | 3 +++
- fs/ext4/super.c | 54 ++++++++++++++++++++++++++++++++++++------------------
- 2 files changed, 39 insertions(+), 18 deletions(-)
-
---- a/fs/ext4/ext4.h
-+++ b/fs/ext4/ext4.h
-@@ -1686,6 +1686,9 @@ extern int ext4_group_extend(struct supe
- ext4_fsblk_t n_blocks_count);
-
- /* super.c */
-+extern void *ext4_kvmalloc(size_t size, gfp_t flags);
-+extern void *ext4_kvzalloc(size_t size, gfp_t flags);
-+extern void ext4_kvfree(void *ptr);
- extern void __ext4_error(struct super_block *, const char *, const char *, ...)
- __attribute__ ((format (printf, 3, 4)));
- #define ext4_error(sb, message...) __ext4_error(sb, __func__, ## message)
---- a/fs/ext4/super.c
-+++ b/fs/ext4/super.c
-@@ -80,6 +80,35 @@ static void ext4_clear_request_list(void
-
- wait_queue_head_t aio_wq[WQ_HASH_SZ];
-
-+void *ext4_kvmalloc(size_t size, gfp_t flags)
-+{
-+ void *ret;
-+
-+ ret = kmalloc(size, flags | __GFP_NOWARN);
-+ if (!ret)
-+ ret = __vmalloc(size, flags, PAGE_KERNEL);
-+ return ret;
-+}
-+
-+void *ext4_kvzalloc(size_t size, gfp_t flags)
-+{
-+ void *ret;
-+
-+ ret = kzalloc(size, flags | __GFP_NOWARN);
-+ if (!ret)
-+ ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
-+ return ret;
-+}
-+
-+void ext4_kvfree(void *ptr)
-+{
-+ if (is_vmalloc_addr(ptr))
-+ vfree(ptr);
-+ else
-+ kfree(ptr);
-+
-+}
-+
- ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
- struct ext4_group_desc *bg)
- {
-@@ -677,10 +706,7 @@ static void ext4_put_super(struct super_
- for (i = 0; i < sbi->s_gdb_count; i++)
- brelse(sbi->s_group_desc[i]);
- kfree(sbi->s_group_desc);
-- if (is_vmalloc_addr(sbi->s_flex_groups))
-- vfree(sbi->s_flex_groups);
-- else
-- kfree(sbi->s_flex_groups);
-+ ext4_kvfree(sbi->s_flex_groups);
- percpu_counter_destroy(&sbi->s_freeblocks_counter);
- percpu_counter_destroy(&sbi->s_freeinodes_counter);
- percpu_counter_destroy(&sbi->s_dirs_counter);
-@@ -1815,15 +1841,11 @@ static int ext4_fill_flex_info(struct su
- ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
- EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
- size = flex_group_count * sizeof(struct flex_groups);
-- sbi->s_flex_groups = kzalloc(size, GFP_KERNEL);
-+ sbi->s_flex_groups = ext4_kvzalloc(size, GFP_KERNEL);
- if (sbi->s_flex_groups == NULL) {
-- sbi->s_flex_groups = vzalloc(size);
-- if (sbi->s_flex_groups == NULL) {
-- ext4_msg(sb, KERN_ERR,
-- "not enough memory for %u flex groups",
-- flex_group_count);
-- goto failed;
-- }
-+ ext4_msg(sb, KERN_ERR, "not enough memory for %u flex groups",
-+ flex_group_count);
-+ goto failed;
- }
-
- for (i = 0; i < sbi->s_groups_count; i++) {
-@@ -3464,12 +3486,8 @@ failed_mount_wq:
- sbi->s_journal = NULL;
- }
- failed_mount3:
-- if (sbi->s_flex_groups) {
-- if (is_vmalloc_addr(sbi->s_flex_groups))
-- vfree(sbi->s_flex_groups);
-- else
-- kfree(sbi->s_flex_groups);
-- }
-+ if (sbi->s_flex_groups)
-+ ext4_kvfree(sbi->s_flex_groups);
- percpu_counter_destroy(&sbi->s_freeblocks_counter);
- percpu_counter_destroy(&sbi->s_freeinodes_counter);
- percpu_counter_destroy(&sbi->s_dirs_counter);