aboutsummaryrefslogtreecommitdiffstats
path: root/fs/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/buffer.c')
-rw-r--r--fs/buffer.c92
1 files changed, 52 insertions, 40 deletions
diff --git a/fs/buffer.c b/fs/buffer.c
index 456c9ab7705b..3ebccf4aa7e3 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -67,14 +67,14 @@ static int sync_buffer(void *word)
67 return 0; 67 return 0;
68} 68}
69 69
70void fastcall __lock_buffer(struct buffer_head *bh) 70void __lock_buffer(struct buffer_head *bh)
71{ 71{
72 wait_on_bit_lock(&bh->b_state, BH_Lock, sync_buffer, 72 wait_on_bit_lock(&bh->b_state, BH_Lock, sync_buffer,
73 TASK_UNINTERRUPTIBLE); 73 TASK_UNINTERRUPTIBLE);
74} 74}
75EXPORT_SYMBOL(__lock_buffer); 75EXPORT_SYMBOL(__lock_buffer);
76 76
77void fastcall unlock_buffer(struct buffer_head *bh) 77void unlock_buffer(struct buffer_head *bh)
78{ 78{
79 smp_mb__before_clear_bit(); 79 smp_mb__before_clear_bit();
80 clear_buffer_locked(bh); 80 clear_buffer_locked(bh);
@@ -678,7 +678,7 @@ void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode)
678 } else { 678 } else {
679 BUG_ON(mapping->assoc_mapping != buffer_mapping); 679 BUG_ON(mapping->assoc_mapping != buffer_mapping);
680 } 680 }
681 if (list_empty(&bh->b_assoc_buffers)) { 681 if (!bh->b_assoc_map) {
682 spin_lock(&buffer_mapping->private_lock); 682 spin_lock(&buffer_mapping->private_lock);
683 list_move_tail(&bh->b_assoc_buffers, 683 list_move_tail(&bh->b_assoc_buffers,
684 &mapping->private_list); 684 &mapping->private_list);
@@ -794,6 +794,7 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list)
794{ 794{
795 struct buffer_head *bh; 795 struct buffer_head *bh;
796 struct list_head tmp; 796 struct list_head tmp;
797 struct address_space *mapping;
797 int err = 0, err2; 798 int err = 0, err2;
798 799
799 INIT_LIST_HEAD(&tmp); 800 INIT_LIST_HEAD(&tmp);
@@ -801,9 +802,14 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list)
801 spin_lock(lock); 802 spin_lock(lock);
802 while (!list_empty(list)) { 803 while (!list_empty(list)) {
803 bh = BH_ENTRY(list->next); 804 bh = BH_ENTRY(list->next);
805 mapping = bh->b_assoc_map;
804 __remove_assoc_queue(bh); 806 __remove_assoc_queue(bh);
807 /* Avoid race with mark_buffer_dirty_inode() which does
808 * a lockless check and we rely on seeing the dirty bit */
809 smp_mb();
805 if (buffer_dirty(bh) || buffer_locked(bh)) { 810 if (buffer_dirty(bh) || buffer_locked(bh)) {
806 list_add(&bh->b_assoc_buffers, &tmp); 811 list_add(&bh->b_assoc_buffers, &tmp);
812 bh->b_assoc_map = mapping;
807 if (buffer_dirty(bh)) { 813 if (buffer_dirty(bh)) {
808 get_bh(bh); 814 get_bh(bh);
809 spin_unlock(lock); 815 spin_unlock(lock);
@@ -822,8 +828,17 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list)
822 828
823 while (!list_empty(&tmp)) { 829 while (!list_empty(&tmp)) {
824 bh = BH_ENTRY(tmp.prev); 830 bh = BH_ENTRY(tmp.prev);
825 list_del_init(&bh->b_assoc_buffers);
826 get_bh(bh); 831 get_bh(bh);
832 mapping = bh->b_assoc_map;
833 __remove_assoc_queue(bh);
834 /* Avoid race with mark_buffer_dirty_inode() which does
835 * a lockless check and we rely on seeing the dirty bit */
836 smp_mb();
837 if (buffer_dirty(bh)) {
838 list_add(&bh->b_assoc_buffers,
839 &bh->b_assoc_map->private_list);
840 bh->b_assoc_map = mapping;
841 }
827 spin_unlock(lock); 842 spin_unlock(lock);
828 wait_on_buffer(bh); 843 wait_on_buffer(bh);
829 if (!buffer_uptodate(bh)) 844 if (!buffer_uptodate(bh))
@@ -1164,7 +1179,7 @@ __getblk_slow(struct block_device *bdev, sector_t block, int size)
1164 * mark_buffer_dirty() is atomic. It takes bh->b_page->mapping->private_lock, 1179 * mark_buffer_dirty() is atomic. It takes bh->b_page->mapping->private_lock,
1165 * mapping->tree_lock and the global inode_lock. 1180 * mapping->tree_lock and the global inode_lock.
1166 */ 1181 */
1167void fastcall mark_buffer_dirty(struct buffer_head *bh) 1182void mark_buffer_dirty(struct buffer_head *bh)
1168{ 1183{
1169 WARN_ON_ONCE(!buffer_uptodate(bh)); 1184 WARN_ON_ONCE(!buffer_uptodate(bh));
1170 if (!buffer_dirty(bh) && !test_set_buffer_dirty(bh)) 1185 if (!buffer_dirty(bh) && !test_set_buffer_dirty(bh))
@@ -1195,7 +1210,7 @@ void __brelse(struct buffer_head * buf)
1195void __bforget(struct buffer_head *bh) 1210void __bforget(struct buffer_head *bh)
1196{ 1211{
1197 clear_buffer_dirty(bh); 1212 clear_buffer_dirty(bh);
1198 if (!list_empty(&bh->b_assoc_buffers)) { 1213 if (bh->b_assoc_map) {
1199 struct address_space *buffer_mapping = bh->b_page->mapping; 1214 struct address_space *buffer_mapping = bh->b_page->mapping;
1200 1215
1201 spin_lock(&buffer_mapping->private_lock); 1216 spin_lock(&buffer_mapping->private_lock);
@@ -1436,6 +1451,7 @@ void invalidate_bh_lrus(void)
1436{ 1451{
1437 on_each_cpu(invalidate_bh_lru, NULL, 1, 1); 1452 on_each_cpu(invalidate_bh_lru, NULL, 1, 1);
1438} 1453}
1454EXPORT_SYMBOL_GPL(invalidate_bh_lrus);
1439 1455
1440void set_bh_page(struct buffer_head *bh, 1456void set_bh_page(struct buffer_head *bh,
1441 struct page *page, unsigned long offset) 1457 struct page *page, unsigned long offset)
@@ -1798,7 +1814,7 @@ void page_zero_new_buffers(struct page *page, unsigned from, unsigned to)
1798 start = max(from, block_start); 1814 start = max(from, block_start);
1799 size = min(to, block_end) - start; 1815 size = min(to, block_end) - start;
1800 1816
1801 zero_user_page(page, start, size, KM_USER0); 1817 zero_user(page, start, size);
1802 set_buffer_uptodate(bh); 1818 set_buffer_uptodate(bh);
1803 } 1819 }
1804 1820
@@ -1861,19 +1877,10 @@ static int __block_prepare_write(struct inode *inode, struct page *page,
1861 mark_buffer_dirty(bh); 1877 mark_buffer_dirty(bh);
1862 continue; 1878 continue;
1863 } 1879 }
1864 if (block_end > to || block_start < from) { 1880 if (block_end > to || block_start < from)
1865 void *kaddr; 1881 zero_user_segments(page,
1866 1882 to, block_end,
1867 kaddr = kmap_atomic(page, KM_USER0); 1883 block_start, from);
1868 if (block_end > to)
1869 memset(kaddr+to, 0,
1870 block_end-to);
1871 if (block_start < from)
1872 memset(kaddr+block_start,
1873 0, from-block_start);
1874 flush_dcache_page(page);
1875 kunmap_atomic(kaddr, KM_USER0);
1876 }
1877 continue; 1884 continue;
1878 } 1885 }
1879 } 1886 }
@@ -2104,8 +2111,7 @@ int block_read_full_page(struct page *page, get_block_t *get_block)
2104 SetPageError(page); 2111 SetPageError(page);
2105 } 2112 }
2106 if (!buffer_mapped(bh)) { 2113 if (!buffer_mapped(bh)) {
2107 zero_user_page(page, i * blocksize, blocksize, 2114 zero_user(page, i * blocksize, blocksize);
2108 KM_USER0);
2109 if (!err) 2115 if (!err)
2110 set_buffer_uptodate(bh); 2116 set_buffer_uptodate(bh);
2111 continue; 2117 continue;
@@ -2218,7 +2224,7 @@ int cont_expand_zero(struct file *file, struct address_space *mapping,
2218 &page, &fsdata); 2224 &page, &fsdata);
2219 if (err) 2225 if (err)
2220 goto out; 2226 goto out;
2221 zero_user_page(page, zerofrom, len, KM_USER0); 2227 zero_user(page, zerofrom, len);
2222 err = pagecache_write_end(file, mapping, curpos, len, len, 2228 err = pagecache_write_end(file, mapping, curpos, len, len,
2223 page, fsdata); 2229 page, fsdata);
2224 if (err < 0) 2230 if (err < 0)
@@ -2245,7 +2251,7 @@ int cont_expand_zero(struct file *file, struct address_space *mapping,
2245 &page, &fsdata); 2251 &page, &fsdata);
2246 if (err) 2252 if (err)
2247 goto out; 2253 goto out;
2248 zero_user_page(page, zerofrom, len, KM_USER0); 2254 zero_user(page, zerofrom, len);
2249 err = pagecache_write_end(file, mapping, curpos, len, len, 2255 err = pagecache_write_end(file, mapping, curpos, len, len,
2250 page, fsdata); 2256 page, fsdata);
2251 if (err < 0) 2257 if (err < 0)
@@ -2422,7 +2428,6 @@ int nobh_write_begin(struct file *file, struct address_space *mapping,
2422 unsigned block_in_page; 2428 unsigned block_in_page;
2423 unsigned block_start, block_end; 2429 unsigned block_start, block_end;
2424 sector_t block_in_file; 2430 sector_t block_in_file;
2425 char *kaddr;
2426 int nr_reads = 0; 2431 int nr_reads = 0;
2427 int ret = 0; 2432 int ret = 0;
2428 int is_mapped_to_disk = 1; 2433 int is_mapped_to_disk = 1;
@@ -2493,13 +2498,8 @@ int nobh_write_begin(struct file *file, struct address_space *mapping,
2493 continue; 2498 continue;
2494 } 2499 }
2495 if (buffer_new(bh) || !buffer_mapped(bh)) { 2500 if (buffer_new(bh) || !buffer_mapped(bh)) {
2496 kaddr = kmap_atomic(page, KM_USER0); 2501 zero_user_segments(page, block_start, from,
2497 if (block_start < from) 2502 to, block_end);
2498 memset(kaddr+block_start, 0, from-block_start);
2499 if (block_end > to)
2500 memset(kaddr + to, 0, block_end - to);
2501 flush_dcache_page(page);
2502 kunmap_atomic(kaddr, KM_USER0);
2503 continue; 2503 continue;
2504 } 2504 }
2505 if (buffer_uptodate(bh)) 2505 if (buffer_uptodate(bh))
@@ -2636,7 +2636,7 @@ int nobh_writepage(struct page *page, get_block_t *get_block,
2636 * the page size, the remaining memory is zeroed when mapped, and 2636 * the page size, the remaining memory is zeroed when mapped, and
2637 * writes to that region are not written out to the file." 2637 * writes to that region are not written out to the file."
2638 */ 2638 */
2639 zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0); 2639 zero_user_segment(page, offset, PAGE_CACHE_SIZE);
2640out: 2640out:
2641 ret = mpage_writepage(page, get_block, wbc); 2641 ret = mpage_writepage(page, get_block, wbc);
2642 if (ret == -EAGAIN) 2642 if (ret == -EAGAIN)
@@ -2709,7 +2709,7 @@ has_buffers:
2709 if (page_has_buffers(page)) 2709 if (page_has_buffers(page))
2710 goto has_buffers; 2710 goto has_buffers;
2711 } 2711 }
2712 zero_user_page(page, offset, length, KM_USER0); 2712 zero_user(page, offset, length);
2713 set_page_dirty(page); 2713 set_page_dirty(page);
2714 err = 0; 2714 err = 0;
2715 2715
@@ -2785,7 +2785,7 @@ int block_truncate_page(struct address_space *mapping,
2785 goto unlock; 2785 goto unlock;
2786 } 2786 }
2787 2787
2788 zero_user_page(page, offset, length, KM_USER0); 2788 zero_user(page, offset, length);
2789 mark_buffer_dirty(bh); 2789 mark_buffer_dirty(bh);
2790 err = 0; 2790 err = 0;
2791 2791
@@ -2831,7 +2831,7 @@ int block_write_full_page(struct page *page, get_block_t *get_block,
2831 * the page size, the remaining memory is zeroed when mapped, and 2831 * the page size, the remaining memory is zeroed when mapped, and
2832 * writes to that region are not written out to the file." 2832 * writes to that region are not written out to the file."
2833 */ 2833 */
2834 zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0); 2834 zero_user_segment(page, offset, PAGE_CACHE_SIZE);
2835 return __block_write_full_page(inode, page, get_block, wbc); 2835 return __block_write_full_page(inode, page, get_block, wbc);
2836} 2836}
2837 2837
@@ -3037,7 +3037,7 @@ drop_buffers(struct page *page, struct buffer_head **buffers_to_free)
3037 do { 3037 do {
3038 struct buffer_head *next = bh->b_this_page; 3038 struct buffer_head *next = bh->b_this_page;
3039 3039
3040 if (!list_empty(&bh->b_assoc_buffers)) 3040 if (bh->b_assoc_map)
3041 __remove_assoc_queue(bh); 3041 __remove_assoc_queue(bh);
3042 bh = next; 3042 bh = next;
3043 } while (bh != head); 3043 } while (bh != head);
@@ -3169,7 +3169,7 @@ static void recalc_bh_state(void)
3169 3169
3170struct buffer_head *alloc_buffer_head(gfp_t gfp_flags) 3170struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
3171{ 3171{
3172 struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, 3172 struct buffer_head *ret = kmem_cache_alloc(bh_cachep,
3173 set_migrateflags(gfp_flags, __GFP_RECLAIMABLE)); 3173 set_migrateflags(gfp_flags, __GFP_RECLAIMABLE));
3174 if (ret) { 3174 if (ret) {
3175 INIT_LIST_HEAD(&ret->b_assoc_buffers); 3175 INIT_LIST_HEAD(&ret->b_assoc_buffers);
@@ -3257,12 +3257,24 @@ int bh_submit_read(struct buffer_head *bh)
3257} 3257}
3258EXPORT_SYMBOL(bh_submit_read); 3258EXPORT_SYMBOL(bh_submit_read);
3259 3259
3260static void
3261init_buffer_head(struct kmem_cache *cachep, void *data)
3262{
3263 struct buffer_head *bh = data;
3264
3265 memset(bh, 0, sizeof(*bh));
3266 INIT_LIST_HEAD(&bh->b_assoc_buffers);
3267}
3268
3260void __init buffer_init(void) 3269void __init buffer_init(void)
3261{ 3270{
3262 int nrpages; 3271 int nrpages;
3263 3272
3264 bh_cachep = KMEM_CACHE(buffer_head, 3273 bh_cachep = kmem_cache_create("buffer_head",
3265 SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD); 3274 sizeof(struct buffer_head), 0,
3275 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
3276 SLAB_MEM_SPREAD),
3277 init_buffer_head);
3266 3278
3267 /* 3279 /*
3268 * Limit the bh occupancy to 10% of ZONE_NORMAL 3280 * Limit the bh occupancy to 10% of ZONE_NORMAL