fs: use memclear_highpage_flush to zero page data
Subsystems (13)
PATCH 1/2 fs: use memclear_highpage_flush to zero page data
It's very common for file systems to need to zero part or all of a page, the simplist way is just to use kmap_atomic() and memset(). There's actually a library function in include/linux/highmem.h that does exactly that, but it's confusingly named memclear_highpage_flush(), which is descriptive of *how* it does the work rather than what the *purpose* is. So this patch renames the function to zero_page_data(), and calls it from the various places that currently open code it.
Compile tested in x86_64.
---
drivers/block/loop.c | 6 --- fs/affs/file.c | 6 --- fs/buffer.c | 53 +++++-------------------------- fs/direct-io.c | 8 +--- fs/ecryptfs/mmap.c | 14 +------- fs/ext3/inode.c | 12 +------ fs/ext4/inode.c | 12 +------ fs/ext4/writeback.c | 12 +------ fs/gfs2/bmap.c | 6 --- fs/mpage.c | 11 +----- fs/nfs/read.c | 10 ++--- fs/nfs/write.c | 2 - fs/ntfs/aops.c | 32 +++--------------- fs/ntfs/file.c | 47 +++++---------------------- fs/ocfs2/aops.c | 5 -- fs/reiser4/plugin/file/cryptcompress.c | 19 +---------- fs/reiser4/plugin/file/file.c | 6 --- fs/reiser4/plugin/item/ctail.c | 6 --- fs/reiser4/plugin/item/extent_file_ops.c | 19 +++-------- fs/reiser4/plugin/item/tail.c | 8 +--- fs/reiserfs/file.c | 39 ++++++---------------- fs/reiserfs/inode.c | 13 +------ fs/xfs/linux-2.6/xfs_lrw.c | 2 - include/linux/highmem.h | 2 - mm/filemap_xip.c | 7 ---- mm/truncate.c | 2 - 26 files changed, 78 insertions(+), 281 deletions(-)
---
drivers/block/loop.c +1 -5
@@ -244,17 +244,13 @@ static int do_lo_send_aops(struct loop_d transfer_result =lo_do_transfer (lo,WRITE , page, offset, bvec->bv_page, bv_offs, size,IV );if (unlikely (transfer_result)) { -char *kaddr; -/* * The transfer failed, but we still write the data to * keep prepare/commit calls balanced. */ printk (KERN_ERR "loop: transfer error block %llu\n" , (unsigned long long )index); - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 , size); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, offset, size); }flush_dcache_page (page); ret = aops->commit_write(file, page, offset,
fs/affs/file.c +1 -5
@@ -628,11 +628,7 @@ static int affs_prepare_write_ofs(structreturn err; }if (to <PAGE_CACHE_SIZE ) { -char *kaddr =kmap_atomic (page,KM_USER0 ); - -memset (kaddr + to,0 ,PAGE_CACHE_SIZE - to); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, to,PAGE_CACHE_SIZE - to);if (size > offset + to) {if (size < offset +PAGE_CACHE_SIZE ) tmp = size & ~PAGE_CACHE_MASK ;
fs/buffer.c +9 -44
138 lines not on this page · raw message
fs/direct-io.c +2 -6
@@ -867,7 +867,6 @@ static int do_direct_IO(struct dio *dio) do_holes:/* Handle holes */ if (!buffer_mapped (map_bh)) { -char *kaddr;loff_t i_size_aligned;/* AKPM: eargh, -ENOTBLK is a hack */
@@ -888,11 +887,8 @@ do_holes:page_cache_release (page); goto out; } - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + (block_in_page << blkbits), -0 ,1 << blkbits); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, block_in_page << blkbits, +1 << blkbits); dio->block_in_file++; block_in_page++; goto next_block;
fs/ecryptfs/mmap.c +3 -11
@@ -364,18 +364,14 @@ static int fill_zeros_to_end_of_page(str {struct inode *inode = page->mapping->host;int end_byte_in_page; -char *page_virt;if ((i_size_read (inode) /PAGE_CACHE_SIZE ) != page->index) goto out; end_byte_in_page =i_size_read (inode) %PAGE_CACHE_SIZE ;if (to > end_byte_in_page) end_byte_in_page = to; - page_virt =kmap_atomic (page,KM_USER0 ); -memset ((page_virt + end_byte_in_page),0 , - (PAGE_CACHE_SIZE - end_byte_in_page)); -kunmap_atomic (page_virt,KM_USER0 ); -flush_dcache_page (page); +zero_page_data (page, end_byte_in_page, +PAGE_CACHE_SIZE - end_byte_in_page); out:return 0 ; }
@@ -740,7 +736,6 @@ int write_zeros(struct file *file, pgoff {int rc =0 ;struct page *tmp_page; -char *tmp_page_virt; tmp_page =ecryptfs_get1page (file, index);if (IS_ERR (tmp_page)) {
@@ -757,10 +752,7 @@ int write_zeros(struct file *file, pgoffpage_cache_release (tmp_page); goto out; } - tmp_page_virt =kmap_atomic (tmp_page,KM_USER0 ); -memset (((char *)tmp_page_virt + start),0 , num_zeros); -kunmap_atomic (tmp_page_virt,KM_USER0 ); -flush_dcache_page (tmp_page); +zero_page_data (tmp_page, start, num_zeros); rc =ecryptfs_commit_write (file, tmp_page, start, start + num_zeros);if (rc <0 ) { ecryptfs_printk(KERN_ERR, "Error attempting to write zero's "
fs/ext3/inode.c +2 -10
@@ -1767,7 +1767,6 @@ static int ext3_block_truncate_page(handstruct inode *inode = mapping->host;struct buffer_head *bh;int err =0 ; -void *kaddr; blocksize = inode->i_sb->s_blocksize; length = blocksize - (offset & (blocksize -1 ));
@@ -1779,10 +1778,7 @@ static int ext3_block_truncate_page(hand*/ if (!page_has_buffers (page) &&test_opt (inode->i_sb,NOBH ) &&ext3_should_writeback_data (inode) &&PageUptodate (page)) { - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 , length); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, offset, length);set_page_dirty (page); goto unlock; }
@@ -1835,11 +1831,7 @@ static int ext3_block_truncate_page(hand goto unlock; } - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 , length); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); - +zero_page_data (page, offset, length);BUFFER_TRACE (bh,"zeroed end of block" ); err =0 ;
fs/ext4/inode.c +2 -10
@@ -1791,7 +1791,6 @@ int ext4_block_truncate_page(handle_t *hstruct inode *inode = mapping->host;struct buffer_head *bh;int err =0 ; -void *kaddr; if ((EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) && test_opt(inode->i_sb, EXTENTS) &&
@@ -1808,10 +1807,7 @@ int ext4_block_truncate_page(handle_t *h*/ if (!page_has_buffers (page) &&test_opt (inode->i_sb,NOBH ) &&ext4_should_writeback_data (inode) &&PageUptodate (page)) { - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 , length); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, offset, length);set_page_dirty (page); goto unlock; }
@@ -1864,11 +1860,7 @@ int ext4_block_truncate_page(handle_t *h goto unlock; } - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 , length); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); - +zero_page_data (page, offset, length);BUFFER_TRACE (bh,"zeroed end of block" ); err =0 ;
fs/ext4/writeback.c +2 -10
@@ -976,7 +976,6 @@ int ext4_wb_writepage(struct page *page,loff_t i_size =i_size_read (inode);pgoff_t end_index = i_size >>PAGE_CACHE_SHIFT ;unsigned offset; -void *kaddr;wb_debug ("writepage %lu from inode %lu\n" , page->index, inode->i_ino);
@@ -1026,10 +1025,7 @@ int ext4_wb_writepage(struct page *page,* the page size, the remaining memory is zeroed when mapped, and * writes to that region are not written out to the file." */ - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 ,PAGE_CACHE_SIZE - offset); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, offset,PAGE_CACHE_SIZE - offset);return ext4_wb_write_single_page (page, wbc); }
@@ -1080,7 +1076,6 @@ int ext4_wb_block_truncate_page(handle_tstruct inode *inode = mapping->host;struct buffer_head bh, *bhw = &bh;unsigned blocksize, length; -void *kaddr;int err =0 ; wb_debug("partial truncate from %lu on page %lu from inode %lu\n",
@@ -1119,10 +1114,7 @@ int ext4_wb_block_truncate_page(handle_t } } - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 , length); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, offset, length);SetPageUptodate (page);__set_page_dirty_nobuffers (page);
fs/gfs2/bmap.c +1 -5
@@ -885,7 +885,6 @@ static int gfs2_block_truncate_page(struunsigned blocksize, iblock, length, pos;struct buffer_head *bh;struct page *page; -void *kaddr;int err; page =grab_cache_page (mapping, index);
@@ -933,10 +932,7 @@ static int gfs2_block_truncate_page(struif (sdp->sd_args.ar_data ==GFS2_DATA_ORDERED ||gfs2_is_jdata (ip))gfs2_trans_add_bh (ip->i_gl, bh,0 ); - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 , length); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, offset, length); unlock:unlock_page (page);
fs/mpage.c +2 -9
@@ -284,11 +284,8 @@ do_mpage_readpage(struct bio *bio, struc }if (first_hole != blocks_per_page) { -char *kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + (first_hole << blkbits),0 , +zero_page_data (page, first_hole << blkbits,PAGE_CACHE_SIZE - (first_hole << blkbits)); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 );if (first_hole ==0 ) {SetPageUptodate (page);unlock_page (page);
@@ -586,14 +583,10 @@ page_is_mapped:* written out to the file." */ unsigned offset = i_size & (PAGE_CACHE_SIZE -1 ); -char *kaddr;if (page->index > end_index || !offset) goto confused; - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 ,PAGE_CACHE_SIZE - offset); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, offset,PAGE_CACHE_SIZE - offset); }/*
fs/nfs/read.c +5 -5
@@ -79,7 +79,7 @@ void nfs_readdata_release(void *data)static int nfs_return_empty_page (struct page *page) { -memclear_highpage_flush (page,0 ,PAGE_CACHE_SIZE ); +zero_page_data (page,0 ,PAGE_CACHE_SIZE );SetPageUptodate (page);unlock_page (page);return 0 ;
@@ -103,10 +103,10 @@ static void nfs_readpage_truncate_uninit pglen =PAGE_CACHE_SIZE - base;for (;;) {if (remainder <= pglen) { -memclear_highpage_flush (*pages, base, remainder); +zero_page_data (*pages, base, remainder);break ; } -memclear_highpage_flush (*pages, base, pglen); +zero_page_data (*pages, base, pglen); pages++; remainder -= pglen; pglen =PAGE_CACHE_SIZE ;
@@ -130,7 +130,7 @@ static int nfs_readpage_async(struct nfsreturn PTR_ERR (new); }if (len <PAGE_CACHE_SIZE ) -memclear_highpage_flush (page, len,PAGE_CACHE_SIZE - len); +zero_page_data (page, len,PAGE_CACHE_SIZE - len);nfs_list_add_request (new, &one_request);nfs_pagein_one (&one_request, inode);
@@ -561,7 +561,7 @@ readpage_async_filler(void *data, structreturn PTR_ERR (new); }if (len <PAGE_CACHE_SIZE ) -memclear_highpage_flush (page, len,PAGE_CACHE_SIZE - len); +zero_page_data (page, len,PAGE_CACHE_SIZE - len);nfs_list_add_request (new, desc->head);return 0 ; }
fs/nfs/write.c +1 -1
@@ -169,7 +169,7 @@ static void nfs_mark_uptodate(struct pagif (count !=nfs_page_length (page))return ;if (count !=PAGE_CACHE_SIZE ) -memclear_highpage_flush (page, count,PAGE_CACHE_SIZE - count); +zero_page_data (page, count,PAGE_CACHE_SIZE - count);SetPageUptodate (page); }
fs/ntfs/aops.c +6 -26
@@ -86,19 +86,15 @@ static void ntfs_end_buffer_async_read(s }/* Check for the current buffer head overflowing. */ if (unlikely (file_ofs + bh->b_size > init_size)) { -u8 *kaddr;int ofs; ofs =0 ;if (file_ofs < init_size) ofs = init_size - file_ofs;local_irq_save (flags); - kaddr =kmap_atomic (page,KM_BIO_SRC_IRQ ); -memset (kaddr +bh_offset (bh) + ofs,0 , +zero_page_data (page,bh_offset (bh) + ofs, bh->b_size - ofs); -kunmap_atomic (kaddr,KM_BIO_SRC_IRQ );local_irq_restore (flags); -flush_dcache_page (page); } }else {clear_buffer_uptodate (bh);
@@ -245,8 +241,7 @@ static int ntfs_read_block(struct page * rl =NULL ; nr = i =0 ; do { - u8 *kaddr; - int err; + int err = 0; if (unlikely(buffer_uptodate(bh))) continue;
@@ -254,7 +249,6 @@ static int ntfs_read_block(struct page * arr[nr++] = bh;continue ; } - err =0 ; bh->b_bdev = vol->sb->s_bdev;/* Is the block within the allowed limits? */ if (iblock < lblock) {
@@ -340,10 +334,7 @@ handle_hole: bh->b_blocknr =-1UL ;clear_buffer_mapped (bh); handle_zblock: - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + i * blocksize,0 , blocksize); -kunmap_atomic (kaddr,KM_USER0 ); -flush_dcache_page (page); +zero_page_data (page, i * blocksize, blocksize);if (likely (!err))set_buffer_uptodate (bh); }while (i++, iblock++, (bh = bh->b_this_page) != head);
@@ -460,10 +451,7 @@ retry_readpage:* ok to ignore the compressed flag here. */ if (unlikely (page->index >0 )) { - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr,0 ,PAGE_CACHE_SIZE ); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page,0 ,PAGE_CACHE_SIZE ); goto done; }if (!NInoAttr (ni))
@@ -790,14 +778,9 @@ lock_retry_remap:* uptodate so it can get discarded by the VM. */ if (err == -ENOENT || lcn ==LCN_ENOENT ) { -u8 *kaddr; - bh->b_blocknr =-1 ;clear_buffer_dirty (bh); - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr +bh_offset (bh),0 , blocksize); -kunmap_atomic (kaddr,KM_USER0 ); -flush_dcache_page (page); +zero_page_data (page,bh_offset (bh), blocksize);set_buffer_uptodate (bh); err =0 ;continue ;
@@ -1422,10 +1405,7 @@ retry_writepage:if (page->index >= (i_size >>PAGE_CACHE_SHIFT )) {/* The page straddles i_size. */ unsigned int ofs = i_size & ~PAGE_CACHE_MASK ; - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + ofs,0 ,PAGE_CACHE_SIZE - ofs); -kunmap_atomic (kaddr,KM_USER0 ); -flush_dcache_page (page); +zero_page_data (page, ofs,PAGE_CACHE_SIZE - ofs); }/* Handle mst protected attributes. */ if (NInoMstProtected (ni))
fs/ntfs/file.c +10 -37
110 lines not on this page · raw message
fs/ocfs2/aops.c +1 -4
@@ -234,10 +234,7 @@ static int ocfs2_readpage(struct file *f* XXX sys_readahead() seems to get that wrong? */ if (start >=i_size_read (inode)) { -char *addr =kmap (page); -memset (addr,0 ,PAGE_SIZE ); -flush_dcache_page (page); -kunmap (page); +zero_page_data (page,0 ,PAGE_SIZE );SetPageUptodate (page); ret =0 ; goto out_alloc;
fs/reiser4/plugin/file/cryptcompress.c +3 -16
@@ -1897,7 +1897,6 @@ static int write_hole(struct inode *inode, reiser4_cluster_t * clust, loff_t file_off, loff_t to_file) { - char *data; int result = 0;unsigned cl_off, cl_count =0 ;unsigned to_pg, pg_off;
@@ -1934,10 +1933,7 @@ write_hole(struct inode *inode, reiser4_ to_pg =min_count (PAGE_CACHE_SIZE - pg_off, cl_count);lock_page (page); - data =kmap_atomic (page,KM_USER0 ); -memset (data + pg_off,0 , to_pg); -flush_dcache_page (page); -kunmap_atomic (data,KM_USER0 ); +zero_page_data (page, pg_off, to_pg);SetPageUptodate (page);unlock_page (page);
@@ -2167,7 +2163,6 @@ read_some_cluster_pages(struct inode *inif (clust->nr_pages) {int off; -char *data;struct page * pg;assert ("edward-1419" , clust->pages !=NULL ); pg = clust->pages[clust->nr_pages -1 ];
@@ -2175,10 +2170,7 @@ read_some_cluster_pages(struct inode *in off =off_to_pgoff (win->off+win->count+win->delta);if (off) {lock_page (pg); - data =kmap_atomic (pg,KM_USER0 ); -memset (data + off,0 ,PAGE_CACHE_SIZE - off); -flush_dcache_page (pg); -kunmap_atomic (data,KM_USER0 ); +zero_page_data (pg, off,PAGE_CACHE_SIZE - off);unlock_page (pg); } }
@@ -2217,20 +2209,15 @@ read_some_cluster_pages(struct inode *in (count_to_nrpages(inode->i_size) <= pg->index)) {/* .. and appended, so set zeroes to the rest */ -char *data;int offset;lock_page (pg); - data =kmap_atomic (pg,KM_USER0 ); -assert ("edward-1260" ,count_to_nrpages (win->off + win->count + win->delta) -1 == i); offset =off_to_pgoff (win->off + win->count + win->delta); -memset (data + offset,0 ,PAGE_CACHE_SIZE - offset); -flush_dcache_page (pg); -kunmap_atomic (data,KM_USER0 ); +zero_page_data (pg, offset,PAGE_CACHE_SIZE - offset);unlock_page (pg);/* still not uptodate */ break ;
fs/reiser4/plugin/file/file.c +1 -5
@@ -433,7 +433,6 @@ static int shorten_file(struct inode *instruct page *page;int padd_from;unsigned long index; -char *kaddr;unix_file_info_t *uf_info;/*
@@ -523,10 +522,7 @@ static int shorten_file(struct inode *inlock_page (page);assert ("vs-1066" ,PageLocked (page)); - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + padd_from,0 ,PAGE_CACHE_SIZE - padd_from); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, padd_from,PAGE_CACHE_SIZE - padd_from);unlock_page (page);page_cache_release (page);/* the below does up(sbinfo->delete_mutex). Do not get confused */
fs/reiser4/plugin/item/ctail.c +1 -5
@@ -627,11 +627,7 @@ int do_readpage_ctail(struct inode * ino#endif case FAKE_DISK_CLUSTER :/* fill the page by zeroes */ - data =kmap_atomic (page,KM_USER0 ); - -memset (data,0 ,PAGE_CACHE_SIZE ); -flush_dcache_page (page); -kunmap_atomic (data,KM_USER0 ); +zero_page_data (page,0 ,PAGE_CACHE_SIZE );SetPageUptodate (page);break ;case PREP_DISK_CLUSTER :
fs/reiser4/plugin/item/extent_file_ops.c +6 -13
@@ -1090,17 +1090,6 @@ ssize_t reiser4_write_extent(struct filereturn (count - left) ? (count - left) : -EFAULT ; } -static inline void zero_page (struct page *page) -{ -char *kaddr =kmap_atomic (page,KM_USER0 ); - -memset (kaddr,0 ,PAGE_CACHE_SIZE ); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); -SetPageUptodate (page); -unlock_page (page); -} -int reiser4_do_readpage_extent (reiser4_extent * ext,reiser4_block_nr pos,struct page *page) {
@@ -1122,7 +1111,9 @@ int reiser4_do_readpage_extent(reiser4_e*/ j =jfind (mapping, index);if (j ==NULL ) { -zero_page (page); +zero_page_data (page,0 ,PAGE_CACHE_SIZE ); +SetPageUptodate (page); +unlock_page (page);return 0 ; }spin_lock_jnode (j);
@@ -1135,7 +1126,9 @@ int reiser4_do_readpage_extent(reiser4_e block = *jnode_get_io_block (j);spin_unlock_jnode (j);if (block ==0 ) { -zero_page (page); +zero_page_data (page,0 ,PAGE_CACHE_SIZE ); +SetPageUptodate (page); +unlock_page (page);jput (j);return 0 ; }
fs/reiser4/plugin/item/tail.c +2 -6
@@ -391,12 +391,8 @@ static int do_readpage_tail(uf_coord_t * } done: -if (mapped !=PAGE_CACHE_SIZE ) { - pagedata =kmap_atomic (page,KM_USER0 ); -memset (pagedata + mapped,0 ,PAGE_CACHE_SIZE - mapped); -flush_dcache_page (page); -kunmap_atomic (pagedata,KM_USER0 ); - } +if (mapped !=PAGE_CACHE_SIZE ) +zero_page_data (page, mapped,PAGE_CACHE_SIZE - mapped);SetPageUptodate (page); out_unlock_page:unlock_page (page);
fs/reiserfs/file.c +11 -28
@@ -1059,20 +1059,12 @@ static int reiserfs_prepare_file_region_maping blocks, since there is none, so we just zero out remaining parts of first and last pages in write area (if needed) */ if ((pos & ~((loff_t )PAGE_CACHE_SIZE -1 )) > inode->i_size) { -if (from !=0 ) {/* First page needs to be partially zeroed */ -char *kaddr =kmap_atomic (prepared_pages[0 ],KM_USER0 ); -memset (kaddr,0 , from); -kunmap_atomic (kaddr,KM_USER0 ); -flush_dcache_page (prepared_pages[0 ]); - } -if (to !=PAGE_CACHE_SIZE ) {/* Last page needs to be partially zeroed */ -char *kaddr = -kmap_atomic (prepared_pages[num_pages -1 ], -KM_USER0 ); -memset (kaddr + to,0 ,PAGE_CACHE_SIZE - to); -kunmap_atomic (kaddr,KM_USER0 ); -flush_dcache_page (prepared_pages[num_pages -1 ]); - } +if (from !=0 )/* First page needs to be partially zeroed */ +zero_page_data (prepared_pages[0 ],0 , from); + +if (to !=PAGE_CACHE_SIZE )/* Last page needs to be partially zeroed */ +zero_page_data (prepared_pages[num_pages-1 ], to, +PAGE_CACHE_SIZE - to);/* Since all blocks are new - use already calculated value */ return blocks;
@@ -1199,13 +1191,9 @@ static int reiserfs_prepare_file_region_ll_rw_block (READ ,1 , &bh); *wait_bh++ = bh; }else {/* Not mapped, zero it */ -char *kaddr = -kmap_atomic (prepared_pages[0 ], -KM_USER0 ); -memset (kaddr + block_start,0 , - from - block_start); -kunmap_atomic (kaddr,KM_USER0 ); -flush_dcache_page (prepared_pages[0 ]); +zero_page_data (prepared_pages[0 ], + block_start, + from - block_start);set_buffer_uptodate (bh); } }
@@ -1237,13 +1225,8 @@ static int reiserfs_prepare_file_region_ll_rw_block (READ ,1 , &bh); *wait_bh++ = bh; }else {/* Not mapped, zero it */ -char *kaddr = -kmap_atomic (prepared_pages - [num_pages -1 ], -KM_USER0 ); -memset (kaddr + to,0 , block_end - to); -kunmap_atomic (kaddr,KM_USER0 ); -flush_dcache_page (prepared_pages[num_pages -1 ]); +zero_page_data (prepared_pages[num_pages-1 ], + to, block_end - to);set_buffer_uptodate (bh); } }
fs/reiserfs/inode.c +2 -11
@@ -2148,13 +2148,8 @@ int reiserfs_truncate_file(struct inode length = offset & (blocksize -1 );/* if we are not on a block boundary */ if (length) { -char *kaddr; - length = blocksize - length; - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 , length); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, offset, length);if (buffer_mapped (bh) && bh->b_blocknr !=0 ) {mark_buffer_dirty (bh); }
@@ -2370,7 +2365,6 @@ static int reiserfs_write_full_page(stru** last byte in the file */ if (page->index >= end_index) { -char *kaddr;unsigned last_offset; last_offset = inode->i_size & (PAGE_CACHE_SIZE -1 );
@@ -2379,10 +2373,7 @@ static int reiserfs_write_full_page(struunlock_page (page);return 0 ; } - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + last_offset,0 ,PAGE_CACHE_SIZE - last_offset); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +zero_page_data (page, last_offset,PAGE_CACHE_SIZE - last_offset); } bh = head; block = page->index << (PAGE_CACHE_SHIFT - s->s_blocksize_bits);
fs/xfs/linux-2.6/xfs_lrw.c +1 -1
@@ -159,7 +159,7 @@ xfs_iozero(if (status) goto unlock; -memclear_highpage_flush (page, offset, bytes); +zero_page_data (page, offset, bytes); status = mapping->a_ops->commit_write (NULL , page, offset, offset + bytes);
include/linux/highmem.h +1 -1
@@ -137,7 +137,7 @@ static inline void clear_highpage(struct/* * Same but also flushes aliased cache contents to RAM. */ -static inline void memclear_highpage_flush (struct page *page,unsigned int offset,unsigned int size) +static inline void zero_page_data (struct page *page,unsigned int offset,unsigned int size) {void *kaddr;
mm/filemap_xip.c +1 -6
@@ -440,7 +440,6 @@ xip_truncate_page(struct address_space *unsigned blocksize;unsigned length;struct page *page; -void *kaddr;BUG_ON (!mapping->a_ops->get_xip_page);
@@ -464,11 +463,7 @@ xip_truncate_page(struct address_space *else return PTR_ERR (page); } - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr + offset,0 , length); -kunmap_atomic (kaddr,KM_USER0 ); - -flush_dcache_page (page); +zero_page_data (page, offset, length);return 0 ; }EXPORT_SYMBOL_GPL (xip_truncate_page);
mm/truncate.c +1 -1
@@ -46,7 +46,7 @@ void do_invalidatepage(struct page *pagestatic inline void truncate_partial_page (struct page *page,unsigned partial) { -memclear_highpage_flush (page, partial,PAGE_CACHE_SIZE -partial); +zero_page_data (page, partial,PAGE_CACHE_SIZE -partial);if (PagePrivate (page))do_invalidatepage (page, partial); }
PATCH 2/2 fs: use simple_prepare_write to zero page data
It's common for file systems to need to zero data on either side of a write, if a page is not Uptodate during prepare_write. It just so happens that simple_prepare_write() in libfs.c does exactly that, so we can avoid duplication and just call that function to zero page data.
Compile tested on x86_64.
---
cifs/file.c | 9 +-------- ext4/writeback.c | 17 +---------------- reiser4/plugin/item/extent_file_ops.c | 13 +++---------- 3 files changed, 5 insertions(+), 34 deletions(-)
---
fs/cifs/file.c +1 -8
@@ -1955,14 +1955,7 @@ static int cifs_prepare_write(struct fil* We don't need to read data beyond the end of the file. * zero it, and set the page uptodate */ -void *kaddr =kmap_atomic (page,KM_USER0 ); - -if (from) -memset (kaddr,0 , from); -if (to <PAGE_CACHE_SIZE ) -memset (kaddr + to,0 ,PAGE_CACHE_SIZE - to); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); +simple_prepare_write (file, page, from, to);SetPageUptodate (page); }else if ((file->f_flags &O_ACCMODE ) !=O_WRONLY ) {/* might as well read a page, it is fast enough */
fs/ext4/writeback.c +1 -16
@@ -819,21 +819,6 @@ int ext4_wb_writepages(struct address_spreturn 0 ; } -static void ext4_wb_clear_page (struct page *page,int from,int to) -{ -void *kaddr; - -if (to <PAGE_CACHE_SIZE || from >0 ) { - kaddr =kmap_atomic (page,KM_USER0 ); -if (PAGE_CACHE_SIZE > to) -memset (kaddr + to,0 ,PAGE_CACHE_SIZE - to); -if (0 < from) -memset (kaddr,0 , from); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); - } -} -int ext4_wb_prepare_write (struct file *file,struct page *page,unsigned from,unsigned to) {
@@ -863,7 +848,7 @@ int ext4_wb_prepare_write(struct file *f/* this block isn't allocated yet, reserve space */ wb_debug ("reserve space for new block\n" ); page->private =1 ; -ext4_wb_clear_page (page, from, to); +simple_prepare_write (file, page, from, to);ClearPageMappedToDisk (page); }else {/* block is already mapped, so no need to reserve */
fs/reiser4/plugin/item/extent_file_ops.c +3 -10
@@ -1040,16 +1040,9 @@ ssize_t reiser4_write_extent(struct fileBUG_ON (get_current_context ()->trans->atom !=NULL );lock_page (page); -if (!PageUptodate (page) && to_page !=PAGE_CACHE_SIZE ) { -void *kaddr; - - kaddr =kmap_atomic (page,KM_USER0 ); -memset (kaddr,0 , page_off); -memset (kaddr + page_off + to_page,0 , -PAGE_CACHE_SIZE - (page_off + to_page)); -flush_dcache_page (page); -kunmap_atomic (kaddr,KM_USER0 ); - } +if (!PageUptodate (page) && to_page !=PAGE_CACHE_SIZE ) +simple_prepare_write (file, page, page_off, + page_off + to_page); written =filemap_copy_from_user (page, page_off, buf, to_page);flush_dcache_page (page);
Andrew Morton
maintainerQuoted 33 lines · On Mon, 09 Apr 2007 21:31:37 -0700 Nate Diller <[email protected]> wrote:
It's very common for file systems to need to zero part or all of a page, the simplist way is just to use
kmap_atomic()andmemset(). There's actually a library function ininclude/linux/highmem.hthat does exactly that, but it's confusingly namedmemclear_highpage_flush(), which is descriptive of *how* it does the work rather than what the *purpose* is. So this patch renames the function tozero_page_data(), and calls it from the various places that currently open code it.Compile tested in
x86_64.Signed-off-by Nate Diller <[email protected]>---
drivers/block/loop.c | 6 --- fs/affs/file.c | 6 --- fs/buffer.c | 53 +++++-------------------------- fs/direct-io.c | 8 +--- fs/ecryptfs/mmap.c | 14 +------- fs/ext3/inode.c | 12 +------ fs/ext4/inode.c | 12 +------ fs/ext4/writeback.c | 12 +------ fs/gfs2/bmap.c | 6 --- fs/mpage.c | 11 +----- fs/nfs/read.c | 10 ++--- fs/nfs/write.c | 2 - fs/ntfs/aops.c | 32 +++--------------- fs/ntfs/file.c | 47 +++++---------------------- fs/ocfs2/aops.c | 5 -- fs/reiser4/plugin/file/cryptcompress.c | 19 +---------- fs/reiser4/plugin/file/file.c | 6 --- fs/reiser4/plugin/item/ctail.c | 6 --- fs/reiser4/plugin/item/extent_file_ops.c | 19 +++--------
Quoted 9 lines
fs/reiser4/plugin/item/tail.c | 8 +--- fs/reiserfs/file.c | 39 ++++++---------------- fs/reiserfs/inode.c | 13 +------ fs/xfs/linux-2.6/xfs_lrw.c | 2 - include/linux/highmem.h | 2 - mm/filemap_xip.c | 7 ---- mm/truncate.c | 2 - 26 files changed, 78 insertions(+), 281 deletions(-)
Not sure that I agree with the name zero_page_data(). People might use it to, err, zero a page's data. Whereas it is really only for use against
*user* pages. zero_user_page(), perhaps.
Plus..
This patch as presented causes me surprising amounts of trouble. I need to split it up into
- core plus filesystems which don't have maintainers (for me to merge)
- filesystems which do have maintainers (one patch per), for maintainers to merge.
- another patch for reiser4, to remain in -mm.
And this is actually not possible to do, because my merge and the subsystem maintainers' merges will happen at different times. In the intervening window, the kernel won't compile.
So instead I need to
- split off the reiser4 bit
- get acks from fs maintainers on the rest
- merge the whole thing in one hit (minus reiser4)
And I can do that, but it is the less preferable option.
The better way to do this merge is:
patch #1:
static inline void memclear_highpage_flush(...) __deprecated
{
zero_user_page(...);
}patch #2..n: convert filesystems.
then, when all filesystems are converted, we're ready to remove memclear_highpage_flush(). But we do that six months later - let's not screw out-of-tree fs maintainers (and their users) unnecessarily.
Quoted 88 lines · Andrew Morton
Quoted 36 lines · On Mon, 09 Apr 2007 21:31:37 -0700 Nate Diller <[email protected]> wrote:
It's very common for file systems to need to zero part or all of a page, the simplist way is just to use
kmap_atomic()andmemset(). There's actually a library function ininclude/linux/highmem.hthat does exactly that, but it's confusingly namedmemclear_highpage_flush(), which is descriptive of *how* it does the work rather than what the *purpose* is. So this patch renames the function tozero_page_data(), and calls it from the various places that currently open code it.Compile tested in
x86_64.Signed-off-by Nate Diller <[email protected]>---
drivers/block/loop.c | 6 --- fs/affs/file.c | 6 --- fs/buffer.c | 53 ++++ +-------------------------- fs/direct-io.c | 8 +--- fs/ecryptfs/mmap.c | 14 +------- fs/ext3/inode.c | 12 +------ fs/ext4/inode.c | 12 +------ fs/ext4/writeback.c | 12 +------ fs/gfs2/bmap.c | 6 --- fs/mpage.c | 11 +----- fs/nfs/read.c | 10 ++--- fs/nfs/write.c | 2 - fs/ntfs/aops.c | 32 +++--------------- fs/ntfs/file.c | 47 ++++ +---------------------- fs/ocfs2/aops.c | 5 -- fs/reiser4/plugin/file/cryptcompress.c | 19 +---------- fs/reiser4/plugin/file/file.c | 6 --- fs/reiser4/plugin/item/ctail.c | 6 --- fs/reiser4/plugin/item/extent_file_ops.c | 19 +++-------- fs/reiser4/plugin/item/tail.c | 8 +---Quoted 9 lines
fs/reiserfs/file.c | 39 +++++ +---------------- fs/reiserfs/inode.c | 13 +------ fs/xfs/linux-2.6/xfs_lrw.c | 2 - include/linux/highmem.h | 2 - mm/filemap_xip.c | 7 ---- mm/truncate.c | 2 - 26 files changed, 78 insertions(+), 281 deletions(-)Not sure that I agree with the name
zero_page_data(). People might use it to, err, zero a page's data. Whereas it is really only for use against
*user* pages.zero_user_page(), perhaps.Plus..
This patch as presented causes me surprising amounts of trouble. I need to split it up into
- core plus filesystems which don't have maintainers (for me to
merge)- filesystems which do have maintainers (one patch per), for maintainers to merge.
- another patch for reiser4, to remain in -mm.
And this is actually not possible to do, because my merge and the subsystem maintainers' merges will happen at different times. In the intervening window, the kernel won't compile.
So instead I need to
- split off the reiser4 bit
- get acks from fs maintainers on the rest
- merge the whole thing in one hit (minus reiser4)
And I can do that, but it is the less preferable option.
The better way to do this merge is:
patch #1:
static inline void
memclear_highpage_flush(...)__deprecated{ zero_user_page(...); }
Quoted 6 lines
patch #2..n: convert filesystems.
then, when all filesystems are converted, we're ready to remove
memclear_highpage_flush(). But we do that six months later - let's not screw out-of-tree fs maintainers (and their users) unnecessarily.
Nate, I think you either do not understand what the KM_* constants passed to kmap_atomic() mean or you were overeager in your code replacement... You really, really cannot replace KM_BIO_SRC_IRQ with KM_USER0 in the NTFS i/o completion handler without trashing people's data left right an centre!
Best regards,
Anton
Signature · 3 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer, http://www.linux-ntfs.org/
Quoted 109 lines · Anton Altaparmakov
Quoted 100 lines · Andrew Morton
Quoted 42 lines · On Mon, 09 Apr 2007 21:31:37 -0700 Nate Diller <[email protected]> wrote:
It's very common for file systems to need to zero part or all of a page, the
simplist way is just to usekmap_atomic()andmemset(). There's actually a
library function ininclude/linux/highmem.hthat does exactly that, but it's
confusingly namedmemclear_highpage_flush(), which is descriptive of *how*
it does the work rather than what the *purpose* is. So this patch renames
the function tozero_page_data(), and calls it from the various places that
currently open code it.Compile tested in
x86_64.Signed-off-by Nate Diller <[email protected]>---
drivers/block/loop.c | 6 --- fs/affs/file.c | 6 --- fs/buffer.c | 53 ++++ +-------------------------- fs/direct-io.c | 8 +--- fs/ecryptfs/mmap.c | 14 +------- fs/ext3/inode.c | 12 +------ fs/ext4/inode.c | 12 +------ fs/ext4/writeback.c | 12 +------ fs/gfs2/bmap.c | 6 --- fs/mpage.c | 11 +----- fs/nfs/read.c | 10 ++--- fs/nfs/write.c | 2 - fs/ntfs/aops.c | 32 +++--------------- fs/ntfs/file.c | 47 ++++ +---------------------- fs/ocfs2/aops.c | 5 -- fs/reiser4/plugin/file/cryptcompress.c | 19 +---------- fs/reiser4/plugin/file/file.c | 6 --- fs/reiser4/plugin/item/ctail.c | 6 --- fs/reiser4/plugin/item/extent_file_ops.c | 19 +++-------- fs/reiser4/plugin/item/tail.c | 8 +---Quoted 9 lines
fs/reiserfs/file.c | 39 +++++ +---------------- fs/reiserfs/inode.c | 13 +------ fs/xfs/linux-2.6/xfs_lrw.c | 2 - include/linux/highmem.h | 2 - mm/filemap_xip.c | 7 ---- mm/truncate.c | 2 - 26 files changed, 78 insertions(+), 281 deletions(-)Not sure that I agree with the name
zero_page_data(). People might use it
to, err, zero a page's data. Whereas it is really only for use against
*user* pages.zero_user_page(), perhaps.Plus..
This patch as presented causes me surprising amounts of trouble. I need to
split it up into- core plus filesystems which don't have maintainers (for me to
merge)- filesystems which do have maintainers (one patch per), for maintainers to merge.
- another patch for reiser4, to remain in -mm.
And this is actually not possible to do, because my merge and the subsystem
maintainers' merges will happen at different times. In the intervening
window, the kernel won't compile.So instead I need to
- split off the reiser4 bit
- get acks from fs maintainers on the rest
- merge the whole thing in one hit (minus reiser4)
And I can do that, but it is the less preferable option.
The better way to do this merge is:
patch #1:
static inline void
memclear_highpage_flush(...)__deprecated{ zero_user_page(...); }Quoted 7 lines
patch #2..n: convert filesystems.
then, when all filesystems are converted, we're ready to remove
memclear_highpage_flush(). But we do that six months later - let's not
screw out-of-tree fs maintainers (and their users) unnecessarily.
Quoted 5 lines
Nate, I think you either do not understand what the KM_* constants passed to
kmap_atomic()mean or you were overeager in your code replacement... You really, really cannot replaceKM_BIO_SRC_IRQwithKM_USER0in the NTFS i/o completion handler without trashing people's data left right an centre!
good catch, I was indeed careless on that one. I just double checked all the other changes and that was the only non-KM_USER0 that slipped through. Thanks!
I will submit a new patch later today that fixes this problem and the issues AKPM raised.
NATE