ext4: Replace ext4_kvfree_array_rcu() by kvfree_rcu_mightsleep()
Subsystems (2)
Uladzislau Rezki (Sony)
maintainerPATCH 1/1 ext4: Replace ext4_kvfree_array_rcu() by kvfree_rcu_mightsleep()
The ext4_kvfree_array_rcu() function was introduced in order to release some memory after a grace period during resizing of a partition. An object that is freed does not contain any rcu_head filed.
To do so, it requires to allocate some extra memory for a special structure that has an rcu_head filed and pointer one where a freed memory is attached. Finally call_rcu() API is invoked.
Since we have a single argument of kvfree_rcu() API, we can easily replace all that tricky code by one single call that does the same but in more efficient way.
--- fs/ext4/ext4.h | 1 - fs/ext4/mballoc.c | 2 +- fs/ext4/resize.c | 31 ++----------------------------- fs/ext4/super.c | 2 +- 4 files changed, 4 insertions(+), 32 deletions(-)
fs/ext4/ext4.h +0 -1
@@ -3057,7 +3057,6 @@ extern int ext4_generic_delete_entry(struct inode *dir,extern bool ext4_empty_dir (struct inode *inode);/* resize.c */ -extern void ext4_kvfree_array_rcu (void *to_free);extern int ext4_group_add (struct super_block *sb,struct ext4_new_group_data *input); extern int ext4_group_extend(struct super_block *sb,
fs/ext4/mballoc.c +1 -1
@@ -3055,7 +3055,7 @@ int ext4_mb_alloc_groupinfo(struct super_block *sb, ext4_group_t ngroups)rcu_assign_pointer (sbi->s_group_info, new_groupinfo); sbi->s_group_info_size = size /sizeof (*sbi->s_group_info);if (old_groupinfo) -ext4_kvfree_array_rcu (old_groupinfo); +kvfree_rcu_mightsleep (old_groupinfo);ext4_debug ("allocated s_groupinfo array for %d meta_bg's\n" , sbi->s_group_info_size);return 0 ;
fs/ext4/resize.c +2 -29
@@ -18,33 +18,6 @@#include "ext4_jbd2.h" -struct ext4_rcu_ptr { -struct rcu_head rcu; -void *ptr; -}; - -static void ext4_rcu_ptr_callback (struct rcu_head *head) -{ -struct ext4_rcu_ptr *ptr; - - ptr = container_of(head, struct ext4_rcu_ptr, rcu); -kvfree (ptr->ptr); -kfree (ptr); -} - -void ext4_kvfree_array_rcu (void *to_free) -{ -struct ext4_rcu_ptr *ptr =kzalloc (sizeof (*ptr),GFP_KERNEL ); - -if (ptr) { - ptr->ptr = to_free; -call_rcu (&ptr->rcu, ext4_rcu_ptr_callback); -return ; - } -synchronize_rcu (); -kvfree (to_free); -} -int ext4_resize_begin (struct super_block *sb) {struct ext4_sb_info *sbi =EXT4_SB (sb);
@@ -931,7 +904,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, n_group_desc[gdb_num] = gdb_bh;rcu_assign_pointer (EXT4_SB (sb)->s_group_desc, n_group_desc);EXT4_SB (sb)->s_gdb_count++; -ext4_kvfree_array_rcu (o_group_desc); +kvfree_rcu_mightsleep (o_group_desc);lock_buffer (EXT4_SB (sb)->s_sbh);le16_add_cpu (&es->s_reserved_gdt_blocks,-1 );
@@ -994,7 +967,7 @@ static int add_new_gdb_meta_bg(struct super_block *sb,rcu_assign_pointer (EXT4_SB (sb)->s_group_desc, n_group_desc);EXT4_SB (sb)->s_gdb_count++; -ext4_kvfree_array_rcu (o_group_desc); +kvfree_rcu_mightsleep (o_group_desc);return err; }
fs/ext4/super.c +1 -1
@@ -3108,7 +3108,7 @@ int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)rcu_assign_pointer (sbi->s_flex_groups, new_groups); sbi->s_flex_groups_allocated = size;if (old_groups) -ext4_kvfree_array_rcu (old_groups); +kvfree_rcu_mightsleep (old_groups);return 0 ; }
Signature · 1 line
2.30.2
Quoted 9 lines · Uladzislau Rezki (Sony)
The
ext4_kvfree_array_rcu()function was introduced in order to release some memory after a grace period during resizing of a partition. An object that is freed does not contain anyrcu_headfiled.To do so, it requires to allocate some extra memory for a special structure that has an
rcu_headfiled and pointer one where a freed memory is attached. Finallycall_rcu()API is invoked.
Quoted 8 lines
Since we have a single argument of
kvfree_rcu()API, we can easily replace all that tricky code by one single call that does the same but in more efficient way.Cc Lukas Czerner <[email protected]>Cc Andreas Dilger <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>
From an RCU perspective:
Quoted 104 lines
--- fs/ext4/ext4.h | 1 - fs/ext4/mballoc.c | 2 +- fs/ext4/resize.c | 31 ++----------------------------- fs/ext4/super.c | 2 +- 4 files changed, 4 insertions(+), 32 deletions(-)fs/ext4/ext4.h +0
-1@@ -3057,7 +3057,6 @@ extern int ext4_generic_delete_entry(struct inode *dir,extern bool ext4_empty_dir (struct inode *inode);/* resize.c */ -extern void ext4_kvfree_array_rcu (void *to_free);extern int ext4_group_add (struct super_block *sb,struct ext4_new_group_data *input); extern int ext4_group_extend(struct super_block *sb,fs/ext4/mballoc.c +1
-1@@ -3055,7 +3055,7 @@ int ext4_mb_alloc_groupinfo(struct super_block *sb, ext4_group_t ngroups)rcu_assign_pointer (sbi->s_group_info, new_groupinfo); sbi->s_group_info_size = size /sizeof (*sbi->s_group_info);if (old_groupinfo) -ext4_kvfree_array_rcu (old_groupinfo); +kvfree_rcu_mightsleep (old_groupinfo);ext4_debug ("allocated s_groupinfo array for %d meta_bg's\n" , sbi->s_group_info_size);return 0 ;fs/ext4/resize.c +2
-29@@ -18,33 +18,6 @@#include "ext4_jbd2.h" -struct ext4_rcu_ptr { -struct rcu_head rcu; -void *ptr; -}; - -static void ext4_rcu_ptr_callback (struct rcu_head *head) -{ -struct ext4_rcu_ptr *ptr; - - ptr = container_of(head, struct ext4_rcu_ptr, rcu); -kvfree (ptr->ptr); -kfree (ptr); -} - -void ext4_kvfree_array_rcu (void *to_free) -{ -struct ext4_rcu_ptr *ptr =kzalloc (sizeof (*ptr),GFP_KERNEL ); - -if (ptr) { - ptr->ptr = to_free; -call_rcu (&ptr->rcu, ext4_rcu_ptr_callback); -return ; - } -synchronize_rcu (); -kvfree (to_free); -} -int ext4_resize_begin (struct super_block *sb) {struct ext4_sb_info *sbi =EXT4_SB (sb);@@ -931,7 +904,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, n_group_desc[gdb_num] = gdb_bh;rcu_assign_pointer (EXT4_SB (sb)->s_group_desc, n_group_desc);EXT4_SB (sb)->s_gdb_count++; -ext4_kvfree_array_rcu (o_group_desc); +kvfree_rcu_mightsleep (o_group_desc);lock_buffer (EXT4_SB (sb)->s_sbh);le16_add_cpu (&es->s_reserved_gdt_blocks,-1 );@@ -994,7 +967,7 @@ static int add_new_gdb_meta_bg(struct super_block *sb,rcu_assign_pointer (EXT4_SB (sb)->s_group_desc, n_group_desc);EXT4_SB (sb)->s_gdb_count++; -ext4_kvfree_array_rcu (o_group_desc); +kvfree_rcu_mightsleep (o_group_desc);return err; }fs/ext4/super.c +1
-1@@ -3108,7 +3108,7 @@ int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)rcu_assign_pointer (sbi->s_flex_groups, new_groups); sbi->s_flex_groups_allocated = size;if (old_groups) -ext4_kvfree_array_rcu (old_groups); +kvfree_rcu_mightsleep (old_groups);return 0 ; }Signature · 1 line
2.30.2
Uladzislau Rezki
maintainerQuoted 14 lines · Paul E. McKenney
Quoted 13 lines · Uladzislau Rezki (Sony)
The
ext4_kvfree_array_rcu()function was introduced in order to release some memory after a grace period during resizing of a partition. An object that is freed does not contain anyrcu_headfiled.To do so, it requires to allocate some extra memory for a special structure that has an
rcu_headfiled and pointer one where a freed memory is attached. Finallycall_rcu()API is invoked.Since we have a single argument of
kvfree_rcu()API, we can easily replace all that tricky code by one single call that does the same but in more efficient way.
Quoted 9 lines
Quoted 4 lines
Cc Lukas Czerner <[email protected]>Cc Andreas Dilger <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>From an RCU perspective:
Reviewed-by Paul E. McKenney <[email protected]>
Thank you!
--
Uladzislau Rezki