All of lore.kernel.org
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: Theodore Ts'o <tytso@mit.edu>, linux-ext4@vger.kernel.org
Cc: LKML <linux-kernel@vger.kernel.org>, RCU <rcu@vger.kernel.org>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Michal Hocko <mhocko@suse.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Daniel Axtens <dja@axtens.net>,
	Frederic Weisbecker <frederic@kernel.org>,
	Neeraj Upadhyay <neeraju@codeaurora.org>,
	Joel Fernandes <joel@joelfernandes.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Theodore Y . Ts'o" <tytso@mit.edu>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>
Subject: Re: [PATCH RESEND] ext4: Replace ext4_kvfree_array_rcu() by kvfree_rcu() API
Date: Wed, 15 Dec 2021 20:40:25 +0100	[thread overview]
Message-ID: <YbpEqWAH6r1Dz8HC@pc638.lan> (raw)
In-Reply-To: <20211215111845.2514-2-urezki@gmail.com>

On Wed, Dec 15, 2021 at 12:18:38PM +0100, Uladzislau Rezki (Sony) wrote:
> 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.
> 
> TO: "Theodore Ts'o" <tytso@mit.edu>
> TO: linux-ext4@vger.kernel.org
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> ---
>  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(-)
> 
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 404dd50856e5..7e8ff3ac2beb 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -3089,7 +3089,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,
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 215b7068f548..b0469f7a5c55 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -3109,7 +3109,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(old_groupinfo);
>  	ext4_debug("allocated s_groupinfo array for %d meta_bg's\n",
>  		   sbi->s_group_info_size);
>  	return 0;
> diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
> index b63cb88ccdae..ac6aa037aaab 100644
> --- a/fs/ext4/resize.c
> +++ b/fs/ext4/resize.c
> @@ -17,33 +17,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);
> @@ -906,7 +879,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(o_group_desc);
>  
>  	lock_buffer(EXT4_SB(sb)->s_sbh);
>  	le16_add_cpu(&es->s_reserved_gdt_blocks, -1);
> @@ -969,7 +942,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(o_group_desc);
>  	return err;
>  }
>  
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 111b0498a232..3942cd271a00 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -2759,7 +2759,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(old_groups);
>  	return 0;
>  }
>  
> -- 
> 2.30.2
> 
+ "Theodore Ts'o" <tytso@mit.edu>
+ linux-ext4@vger.kernel.org

--
Vlad Rezki

  reply	other threads:[~2021-12-15 19:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15 11:18 [PATCH] drdb: Switch to kvfree_rcu() API Uladzislau Rezki (Sony)
2021-12-15 11:18 ` [PATCH RESEND] ext4: Replace ext4_kvfree_array_rcu() by " Uladzislau Rezki (Sony)
2021-12-15 19:40   ` Uladzislau Rezki [this message]
2021-12-15 11:18 ` [PATCH RESEND] ext4: Switch to " Uladzislau Rezki (Sony)
2021-12-15 19:41   ` Uladzislau Rezki
2021-12-15 11:18 ` [PATCH] fs: nfs: sysfs: " Uladzislau Rezki (Sony)
2021-12-15 19:42   ` Uladzislau Rezki
2021-12-15 11:18 ` [PATCH] mfd: dln2: " Uladzislau Rezki (Sony)
2021-12-15 19:43   ` Uladzislau Rezki
2021-12-16 17:01     ` Lee Jones
2021-12-17 15:06       ` Uladzislau Rezki
2021-12-15 11:18 ` [PATCH] misc: vmw_vmci: " Uladzislau Rezki (Sony)
2021-12-15 19:45   ` Uladzislau Rezki
2021-12-15 11:18 ` [PATCH] mlxsw: core: " Uladzislau Rezki (Sony)
2021-12-15 19:46   ` Uladzislau Rezki
2021-12-15 23:38     ` Jakub Kicinski
2021-12-15 11:18 ` [PATCH] RDMA/hfi1: " Uladzislau Rezki (Sony)
2021-12-15 19:47   ` Uladzislau Rezki
2021-12-15 19:49     ` Jason Gunthorpe
2021-12-15 20:51       ` Uladzislau Rezki
2021-12-15 11:18 ` [PATCH] scsi: core: " Uladzislau Rezki (Sony)
2021-12-15 19:48   ` Uladzislau Rezki
2021-12-15 19:38 ` [PATCH] drdb: " Uladzislau Rezki
2021-12-15 19:38   ` [Drbd-dev] " Uladzislau Rezki

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=YbpEqWAH6r1Dz8HC@pc638.lan \
    --to=urezki@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=dja@axtens.net \
    --cc=frederic@kernel.org \
    --cc=joel@joelfernandes.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.com \
    --cc=neeraju@codeaurora.org \
    --cc=oleksiy.avramchenko@sonymobile.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rcu@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.