diff mbox series

[2/7] btrfs: Allocate file_ra_state on stack

Message ID 2bb91af815d028ed3231910fcc5d8c6779ebf79c.1627418762.git.rgoldwyn@suse.com (mailing list archive)
State New, archived
Headers show
Series Allocate structures on stack instead of kmalloc() | expand

Commit Message

Goldwyn Rodrigues July 27, 2021, 9:17 p.m. UTC
From: Goldwyn Rodrigues <rgoldwyn@suse.com>

Instead of allocating file_ra_state using kmalloc, allocate on stack.
sizeof(struct readahead) = 32 bytes

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/btrfs/free-space-cache.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

Comments

Anand Jain July 28, 2021, 5:29 a.m. UTC | #1
On 28/07/2021 05:17, Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 
> Instead of allocating file_ra_state using kmalloc, allocate on stack.
> sizeof(struct readahead) = 32 bytes
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

Looks good.
  Reviewed-by: Anand Jain <anand.jain@oracle.com>


> ---
>   fs/btrfs/free-space-cache.c | 12 +++---------
>   1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 2131ae5b9ed7..8eeb65278ac0 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -344,19 +344,13 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
>   
>   static void readahead_cache(struct inode *inode)
>   {
> -	struct file_ra_state *ra;
> +	struct file_ra_state ra;
>   	unsigned long last_index;
>   
> -	ra = kzalloc(sizeof(*ra), GFP_NOFS);
> -	if (!ra)
> -		return;
> -
> -	file_ra_state_init(ra, inode->i_mapping);
> +	file_ra_state_init(&ra, inode->i_mapping);
>   	last_index = (i_size_read(inode) - 1) >> PAGE_SHIFT;
>   
> -	page_cache_sync_readahead(inode->i_mapping, ra, NULL, 0, last_index);
> -
> -	kfree(ra);
> +	page_cache_sync_readahead(inode->i_mapping, &ra, NULL, 0, last_index);
>   }
>   
>   static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,
>
diff mbox series

Patch

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 2131ae5b9ed7..8eeb65278ac0 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -344,19 +344,13 @@  int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
 
 static void readahead_cache(struct inode *inode)
 {
-	struct file_ra_state *ra;
+	struct file_ra_state ra;
 	unsigned long last_index;
 
-	ra = kzalloc(sizeof(*ra), GFP_NOFS);
-	if (!ra)
-		return;
-
-	file_ra_state_init(ra, inode->i_mapping);
+	file_ra_state_init(&ra, inode->i_mapping);
 	last_index = (i_size_read(inode) - 1) >> PAGE_SHIFT;
 
-	page_cache_sync_readahead(inode->i_mapping, ra, NULL, 0, last_index);
-
-	kfree(ra);
+	page_cache_sync_readahead(inode->i_mapping, &ra, NULL, 0, last_index);
 }
 
 static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,