aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-10-29 14:49:59 -0400
committerChris Mason <chris.mason@oracle.com>2008-10-29 14:49:59 -0400
commitc8b978188c9a0fd3d535c13debd19d522b726f1f (patch)
tree873628723fb82fe2a7c77adc65fa93eca1d61c0c /fs/btrfs/disk-io.c
parent26ce34a9c47334ff7984769e4661b2f1883594ff (diff)
Btrfs: Add zlib compression support
This is a large change for adding compression on reading and writing, both for inline and regular extents. It does some fairly large surgery to the writeback paths. Compression is off by default and enabled by mount -o compress. Even when the -o compress mount option is not used, it is possible to read compressed extents off the disk. If compression for a given set of pages fails to make them smaller, the file is flagged to avoid future compression attempts later. * While finding delalloc extents, the pages are locked before being sent down to the delalloc handler. This allows the delalloc handler to do complex things such as cleaning the pages, marking them writeback and starting IO on their behalf. * Inline extents are inserted at delalloc time now. This allows us to compress the data before inserting the inline extent, and it allows us to insert an inline extent that spans multiple pages. * All of the in-memory extent representations (extent_map.c, ordered-data.c etc) are changed to record both an in-memory size and an on disk size, as well as a flag for compression. From a disk format point of view, the extent pointers in the file are changed to record the on disk size of a given extent and some encoding flags. Space in the disk format is allocated for compression encoding, as well as encryption and a generic 'other' field. Neither the encryption or the 'other' field are currently used. In order to limit the amount of data read for a single random read in the file, the size of a compressed extent is limited to 128k. This is a software only limit, the disk format supports u64 sized compressed extents. In order to limit the ram consumed while processing extents, the uncompressed size of a compressed extent is limited to 256k. This is a software only limit and will be subject to tuning later. Checksumming is still done on compressed extents, and it is done on the uncompressed version of the data. This way additional encodings can be layered on without having to figure out which encoding to checksum. Compression happens at delalloc time, which is basically singled threaded because it is usually done by a single pdflush thread. This makes it tricky to spread the compression load across all the cpus on the box. We'll have to look at parallel pdflush walks of dirty inodes at a later time. Decompression is hooked into readpages and it does spread across CPUs nicely. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 0be044bb6194..dc95f636a11b 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -83,6 +83,7 @@ struct async_submit_bio {
83 extent_submit_bio_hook_t *submit_bio_hook; 83 extent_submit_bio_hook_t *submit_bio_hook;
84 int rw; 84 int rw;
85 int mirror_num; 85 int mirror_num;
86 unsigned long bio_flags;
86 struct btrfs_work work; 87 struct btrfs_work work;
87}; 88};
88 89
@@ -115,6 +116,7 @@ struct extent_map *btree_get_extent(struct inode *inode, struct page *page,
115 } 116 }
116 em->start = 0; 117 em->start = 0;
117 em->len = (u64)-1; 118 em->len = (u64)-1;
119 em->block_len = (u64)-1;
118 em->block_start = 0; 120 em->block_start = 0;
119 em->bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; 121 em->bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev;
120 122
@@ -469,12 +471,13 @@ static void run_one_async_submit(struct btrfs_work *work)
469 wake_up(&fs_info->async_submit_wait); 471 wake_up(&fs_info->async_submit_wait);
470 472
471 async->submit_bio_hook(async->inode, async->rw, async->bio, 473 async->submit_bio_hook(async->inode, async->rw, async->bio,
472 async->mirror_num); 474 async->mirror_num, async->bio_flags);
473 kfree(async); 475 kfree(async);
474} 476}
475 477
476int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, 478int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
477 int rw, struct bio *bio, int mirror_num, 479 int rw, struct bio *bio, int mirror_num,
480 unsigned long bio_flags,
478 extent_submit_bio_hook_t *submit_bio_hook) 481 extent_submit_bio_hook_t *submit_bio_hook)
479{ 482{
480 struct async_submit_bio *async; 483 struct async_submit_bio *async;
@@ -491,6 +494,7 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
491 async->submit_bio_hook = submit_bio_hook; 494 async->submit_bio_hook = submit_bio_hook;
492 async->work.func = run_one_async_submit; 495 async->work.func = run_one_async_submit;
493 async->work.flags = 0; 496 async->work.flags = 0;
497 async->bio_flags = bio_flags;
494 498
495 while(atomic_read(&fs_info->async_submit_draining) && 499 while(atomic_read(&fs_info->async_submit_draining) &&
496 atomic_read(&fs_info->nr_async_submits)) { 500 atomic_read(&fs_info->nr_async_submits)) {
@@ -530,7 +534,7 @@ static int btree_csum_one_bio(struct bio *bio)
530} 534}
531 535
532static int __btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, 536static int __btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
533 int mirror_num) 537 int mirror_num, unsigned long bio_flags)
534{ 538{
535 struct btrfs_root *root = BTRFS_I(inode)->root; 539 struct btrfs_root *root = BTRFS_I(inode)->root;
536 int ret; 540 int ret;
@@ -556,17 +560,17 @@ static int __btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
556} 560}
557 561
558static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, 562static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
559 int mirror_num) 563 int mirror_num, unsigned long bio_flags)
560{ 564{
561 /* 565 /*
562 * kthread helpers are used to submit writes so that checksumming 566 * kthread helpers are used to submit writes so that checksumming
563 * can happen in parallel across all CPUs 567 * can happen in parallel across all CPUs
564 */ 568 */
565 if (!(rw & (1 << BIO_RW))) { 569 if (!(rw & (1 << BIO_RW))) {
566 return __btree_submit_bio_hook(inode, rw, bio, mirror_num); 570 return __btree_submit_bio_hook(inode, rw, bio, mirror_num, 0);
567 } 571 }
568 return btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, 572 return btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info,
569 inode, rw, bio, mirror_num, 573 inode, rw, bio, mirror_num, 0,
570 __btree_submit_bio_hook); 574 __btree_submit_bio_hook);
571} 575}
572 576
@@ -1407,6 +1411,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1407 fs_info->btree_inode = new_inode(sb); 1411 fs_info->btree_inode = new_inode(sb);
1408 fs_info->btree_inode->i_ino = 1; 1412 fs_info->btree_inode->i_ino = 1;
1409 fs_info->btree_inode->i_nlink = 1; 1413 fs_info->btree_inode->i_nlink = 1;
1414
1410 fs_info->thread_pool_size = min(num_online_cpus() + 2, 8); 1415 fs_info->thread_pool_size = min(num_online_cpus() + 2, 8);
1411 1416
1412 INIT_LIST_HEAD(&fs_info->ordered_extents); 1417 INIT_LIST_HEAD(&fs_info->ordered_extents);
@@ -1508,6 +1513,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1508 */ 1513 */
1509 btrfs_init_workers(&fs_info->workers, "worker", 1514 btrfs_init_workers(&fs_info->workers, "worker",
1510 fs_info->thread_pool_size); 1515 fs_info->thread_pool_size);
1516
1511 btrfs_init_workers(&fs_info->submit_workers, "submit", 1517 btrfs_init_workers(&fs_info->submit_workers, "submit",
1512 min_t(u64, fs_devices->num_devices, 1518 min_t(u64, fs_devices->num_devices,
1513 fs_info->thread_pool_size)); 1519 fs_info->thread_pool_size));
@@ -1559,6 +1565,8 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1559 } 1565 }
1560 1566
1561 fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); 1567 fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super);
1568 fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages,
1569 4 * 1024 * 1024 / PAGE_CACHE_SIZE);
1562 1570
1563 nodesize = btrfs_super_nodesize(disk_super); 1571 nodesize = btrfs_super_nodesize(disk_super);
1564 leafsize = btrfs_super_leafsize(disk_super); 1572 leafsize = btrfs_super_leafsize(disk_super);