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 |
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 --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,