* [PATCH] xfs: Use kmem_zalloc for bp->b_pages. @ 2019-03-09 15:36 Sean Fu 2019-03-09 17:32 ` Darrick J. Wong 0 siblings, 1 reply; 4+ messages in thread From: Sean Fu @ 2019-03-09 15:36 UTC (permalink / raw) To: darrick.wong; +Cc: linux-xfs, linux-kernel, Sean Fu Change the allocation of bp->b_pages to use kmem_zalloc instead of kmem_alloc. Remove unnecessary memset for bp->b_pages. This reduces text size by 42 bytes. Before: text data bss dec hex filename 23335 588 8 23931 5d7b ./fs/xfs/xfs_buf.o After: text data bss dec hex filename 23293 588 8 23889 5d51 ./fs/xfs/xfs_buf.o Signed-off-by: Sean Fu <fxinrong@gmail.com> --- fs/xfs/xfs_buf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 4f5f2ff3f70f..be4f740b97c1 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -289,12 +289,11 @@ _xfs_buf_get_pages( if (page_count <= XB_PAGES) { bp->b_pages = bp->b_page_array; } else { - bp->b_pages = kmem_alloc(sizeof(struct page *) * + bp->b_pages = kmem_zalloc(sizeof(struct page *) * page_count, KM_NOFS); if (bp->b_pages == NULL) return -ENOMEM; } - memset(bp->b_pages, 0, sizeof(struct page *) * page_count); } return 0; } -- 2.16.4 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] xfs: Use kmem_zalloc for bp->b_pages. 2019-03-09 15:36 [PATCH] xfs: Use kmem_zalloc for bp->b_pages Sean Fu @ 2019-03-09 17:32 ` Darrick J. Wong 2019-03-10 5:07 ` Sean Fu 0 siblings, 1 reply; 4+ messages in thread From: Darrick J. Wong @ 2019-03-09 17:32 UTC (permalink / raw) To: Sean Fu; +Cc: linux-xfs, linux-kernel On Sat, Mar 09, 2019 at 11:36:36PM +0800, Sean Fu wrote: > Change the allocation of bp->b_pages to use kmem_zalloc instead of > kmem_alloc. > Remove unnecessary memset for bp->b_pages. > > This reduces text size by 42 bytes. > Before: > text data bss dec hex filename > 23335 588 8 23931 5d7b ./fs/xfs/xfs_buf.o > After: > text data bss dec hex filename > 23293 588 8 23889 5d51 ./fs/xfs/xfs_buf.o > > Signed-off-by: Sean Fu <fxinrong@gmail.com> > --- > fs/xfs/xfs_buf.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c > index 4f5f2ff3f70f..be4f740b97c1 100644 > --- a/fs/xfs/xfs_buf.c > +++ b/fs/xfs/xfs_buf.c > @@ -289,12 +289,11 @@ _xfs_buf_get_pages( > if (page_count <= XB_PAGES) { > bp->b_pages = bp->b_page_array; > } else { > - bp->b_pages = kmem_alloc(sizeof(struct page *) * > + bp->b_pages = kmem_zalloc(sizeof(struct page *) * > page_count, KM_NOFS); > if (bp->b_pages == NULL) > return -ENOMEM; > } > - memset(bp->b_pages, 0, sizeof(struct page *) * page_count); Does this leave b_pages uninitialized in the page_count <= XB_PAGES case? --D > } > return 0; > } > -- > 2.16.4 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xfs: Use kmem_zalloc for bp->b_pages. 2019-03-09 17:32 ` Darrick J. Wong @ 2019-03-10 5:07 ` Sean Fu 2019-03-10 21:53 ` Dave Chinner 0 siblings, 1 reply; 4+ messages in thread From: Sean Fu @ 2019-03-10 5:07 UTC (permalink / raw) To: Darrick J. Wong; +Cc: Sean Fu, linux-xfs, linux-kernel On Sat, Mar 09, 2019 at 09:32:30AM -0800, Darrick J. Wong wrote: > On Sat, Mar 09, 2019 at 11:36:36PM +0800, Sean Fu wrote: > > Change the allocation of bp->b_pages to use kmem_zalloc instead of > > kmem_alloc. > > Remove unnecessary memset for bp->b_pages. > > > > This reduces text size by 42 bytes. > > Before: > > text data bss dec hex filename > > 23335 588 8 23931 5d7b ./fs/xfs/xfs_buf.o > > After: > > text data bss dec hex filename > > 23293 588 8 23889 5d51 ./fs/xfs/xfs_buf.o > > > > Signed-off-by: Sean Fu <fxinrong@gmail.com> > > --- > > fs/xfs/xfs_buf.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c > > index 4f5f2ff3f70f..be4f740b97c1 100644 > > --- a/fs/xfs/xfs_buf.c > > +++ b/fs/xfs/xfs_buf.c > > @@ -289,12 +289,11 @@ _xfs_buf_get_pages( > > if (page_count <= XB_PAGES) { > > bp->b_pages = bp->b_page_array; > > } else { > > - bp->b_pages = kmem_alloc(sizeof(struct page *) * > > + bp->b_pages = kmem_zalloc(sizeof(struct page *) * > > page_count, KM_NOFS); > > if (bp->b_pages == NULL) > > return -ENOMEM; > > } > > - memset(bp->b_pages, 0, sizeof(struct page *) * page_count); > > Does this leave b_pages uninitialized in the page_count <= XB_PAGES > case? bp is allocated by kmem_zone_zalloc, But i will take a deep look at xfs_buf_associate_memory. > > --D > > > } > > return 0; > > } > > -- > > 2.16.4 > > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xfs: Use kmem_zalloc for bp->b_pages. 2019-03-10 5:07 ` Sean Fu @ 2019-03-10 21:53 ` Dave Chinner 0 siblings, 0 replies; 4+ messages in thread From: Dave Chinner @ 2019-03-10 21:53 UTC (permalink / raw) To: Sean Fu; +Cc: Darrick J. Wong, linux-xfs, linux-kernel On Sun, Mar 10, 2019 at 01:07:32PM +0800, Sean Fu wrote: > On Sat, Mar 09, 2019 at 09:32:30AM -0800, Darrick J. Wong wrote: > > On Sat, Mar 09, 2019 at 11:36:36PM +0800, Sean Fu wrote: > > > Change the allocation of bp->b_pages to use kmem_zalloc instead of > > > kmem_alloc. > > > Remove unnecessary memset for bp->b_pages. > > > > > > This reduces text size by 42 bytes. > > > Before: > > > text data bss dec hex filename > > > 23335 588 8 23931 5d7b ./fs/xfs/xfs_buf.o > > > After: > > > text data bss dec hex filename > > > 23293 588 8 23889 5d51 ./fs/xfs/xfs_buf.o > > > > > > Signed-off-by: Sean Fu <fxinrong@gmail.com> > > > --- > > > fs/xfs/xfs_buf.c | 3 +-- > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c > > > index 4f5f2ff3f70f..be4f740b97c1 100644 > > > --- a/fs/xfs/xfs_buf.c > > > +++ b/fs/xfs/xfs_buf.c > > > @@ -289,12 +289,11 @@ _xfs_buf_get_pages( > > > if (page_count <= XB_PAGES) { > > > bp->b_pages = bp->b_page_array; > > > } else { > > > - bp->b_pages = kmem_alloc(sizeof(struct page *) * > > > + bp->b_pages = kmem_zalloc(sizeof(struct page *) * > > > page_count, KM_NOFS); > > > if (bp->b_pages == NULL) > > > return -ENOMEM; > > > } > > > - memset(bp->b_pages, 0, sizeof(struct page *) * page_count); > > > > Does this leave b_pages uninitialized in the page_count <= XB_PAGES > > case? > bp is allocated by kmem_zone_zalloc, But i will take a deep look at xfs_buf_associate_memory. We can (and do) reuse buffers with different memory buffers via xfs_buf_associate_memory() (e.g. see the split log buffer code in xlog_sync()]. I'd prefer that we leave the explicit memset here for this re-use case - leaving the page pointer array with stale page pointers (even though beyond b_page_count) means any page array overrun turns into a memory corruption (via access of a stale page) rather than a NULL pointer dereference and immediate fail. IMO, a small decrease in binary size is not worth changing the failure behaviour from a definite, immediate fail to a random memory corruption failure some time in the future... Cheers, Dave. -- Dave Chinner david@fromorbit.com ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-10 21:54 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-03-09 15:36 [PATCH] xfs: Use kmem_zalloc for bp->b_pages Sean Fu 2019-03-09 17:32 ` Darrick J. Wong 2019-03-10 5:07 ` Sean Fu 2019-03-10 21:53 ` Dave Chinner
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox