vfs: block_read_full_page allocates array depending on environment
RFC PATCH 1/1 vfs: block_read_full_page allocates array depending on environment
Hi,
In block_read_full_page(), buffer_head pointer array is allocated more than the necessity.
For example, the system's page cache size = 16k and filesystem's block size = 4k, the necessary number of pointer array is 4, but it is allocated as 32.
This patch allocates the buffer_head pointer array depending on the system's page cache size and filesystem's block size.
--- fs/buffer.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
fs/buffer.c +2 -3
@@ -2146,13 +2146,12 @@ int block_read_full_page(struct page *page, get_block_t *get_block) {struct inode *inode = page->mapping->host;sector_t iblock, lblock; -struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE ]; -unsigned int blocksize; +unsigned int blocksize =1 << inode->i_blkbits; +struct buffer_head *bh, *head, *arr[PAGE_CACHE_SIZE / blocksize];int nr, i;int fully_mapped =1 ;BUG_ON (!PageLocked (page)); - blocksize =1 << inode->i_blkbits;if (!page_has_buffers (page))create_empty_buffers (page, blocksize,0 ); head =page_buffers (page);
--
1.6.2.5
Thanks,
Masayoshi
fs/buffer.c int block_read_full_page(struct page *page, get_block_t *get_block) · line 2150
Quoted 8 lines · Masayoshi MIZUMA
fs/buffer.c +2
-2@@ -2146,13 +2146,12 @@ int block_read_full_page(struct page *page, get_block_t *get_block) {struct inode *inode = page->mapping->host;sector_t iblock, lblock; -struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE ]; -unsigned int blocksize; +unsigned int blocksize =1 << inode->i_blkbits; +struct buffer_head *bh, *head, *arr[PAGE_CACHE_SIZE / blocksize];
In practice, we avoid to use the variable-length array on the kernel stack. Although I'm not sure how important it is, there are some reasons to avoid. Also sparse will warn it, IIRC.
Thanks.
Quoted 8 lines
fs/buffer.c +0
-1int nr, i;int fully_mapped =1 ;BUG_ON (!PageLocked (page)); - blocksize =1 << inode->i_blkbits;if (!page_has_buffers (page))create_empty_buffers (page, blocksize,0 ); head =page_buffers (page);
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Quoted 14 lines · OGAWA Hirofumi
fs/buffer.c int block_read_full_page(struct page *page, get_block_t *get_block) · line 2150
Quoted 8 lines · Masayoshi MIZUMA
fs/buffer.c +2
-2@@ -2146,13 +2146,12 @@ int block_read_full_page(struct page *page, get_block_t *get_block) {struct inode *inode = page->mapping->host;sector_t iblock, lblock; -struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE ]; -unsigned int blocksize; +unsigned int blocksize =1 << inode->i_blkbits; +struct buffer_head *bh, *head, *arr[PAGE_CACHE_SIZE / blocksize];In practice, we avoid to use the variable-length array on the kernel stack. Although I'm not sure how important it is, there are some reasons to avoid. Also sparse will warn it, IIRC.
Umm... I understand the practice itself, but is there specific reason for the practice ? If there isn't, we don't need to avoid use it, I think.
Thanks,
Masayoshi
Quoted 17 lines · Masayoshi MIZUMA
Quoted 14 lines · OGAWA Hirofumi
fs/buffer.c int block_read_full_page(struct page *page, get_block_t *get_block) · line 2150
Quoted 8 lines · Masayoshi MIZUMA
fs/buffer.c +2
-2@@ -2146,13 +2146,12 @@ int block_read_full_page(struct page *page, get_block_t *get_block) {struct inode *inode = page->mapping->host;sector_t iblock, lblock; -struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE ]; -unsigned int blocksize; +unsigned int blocksize =1 << inode->i_blkbits; +struct buffer_head *bh, *head, *arr[PAGE_CACHE_SIZE / blocksize];In practice, we avoid to use the variable-length array on the kernel stack. Although I'm not sure how important it is, there are some reasons to avoid. Also sparse will warn it, IIRC.
Quoted 2 lines
Umm... I understand the practice itself, but is there specific reason for the practice ? If there isn't, we don't need to avoid use it, I think.
For example, from quick google
http://lkml.org/lkml/2003/9/2/202
I guess you can find more reasons if needed.
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Quoted 19 lines · OGAWA Hirofumi
Quoted 17 lines · Masayoshi MIZUMA
Quoted 14 lines · OGAWA Hirofumi
fs/buffer.c int block_read_full_page(struct page *page, get_block_t *get_block) · line 2150
Quoted 8 lines · Masayoshi MIZUMA
fs/buffer.c +2
-2@@ -2146,13 +2146,12 @@ int block_read_full_page(struct page *page, get_block_t *get_block) {struct inode *inode = page->mapping->host;sector_t iblock, lblock; -struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE ]; -unsigned int blocksize; +unsigned int blocksize =1 << inode->i_blkbits; +struct buffer_head *bh, *head, *arr[PAGE_CACHE_SIZE / blocksize];In practice, we avoid to use the variable-length array on the kernel stack. Although I'm not sure how important it is, there are some reasons to avoid. Also sparse will warn it, IIRC.
Quoted 8 lines
Quoted 2 lines
Umm... I understand the practice itself, but is there specific reason for the practice ? If there isn't, we don't need to avoid use it, I think.
For example, from quick google
http://lkml.org/lkml/2003/9/2/202I guess you can find more reasons if needed.
I understand it. Thanks a lot !
Thanks,
Masayoshi