aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.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/extent-tree.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/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 280ac1aa9b6d..bbf04e80a1a3 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3278,6 +3278,7 @@ static int noinline relocate_data_extent(struct inode *reloc_inode,
3278 3278
3279 em->start = extent_key->objectid - offset; 3279 em->start = extent_key->objectid - offset;
3280 em->len = extent_key->offset; 3280 em->len = extent_key->offset;
3281 em->block_len = extent_key->offset;
3281 em->block_start = extent_key->objectid; 3282 em->block_start = extent_key->objectid;
3282 em->bdev = root->fs_info->fs_devices->latest_bdev; 3283 em->bdev = root->fs_info->fs_devices->latest_bdev;
3283 set_bit(EXTENT_FLAG_PINNED, &em->flags); 3284 set_bit(EXTENT_FLAG_PINNED, &em->flags);
@@ -3314,10 +3315,14 @@ struct btrfs_ref_path {
3314}; 3315};
3315 3316
3316struct disk_extent { 3317struct disk_extent {
3318 u64 ram_bytes;
3317 u64 disk_bytenr; 3319 u64 disk_bytenr;
3318 u64 disk_num_bytes; 3320 u64 disk_num_bytes;
3319 u64 offset; 3321 u64 offset;
3320 u64 num_bytes; 3322 u64 num_bytes;
3323 u8 compression;
3324 u8 encryption;
3325 u16 other_encoding;
3321}; 3326};
3322 3327
3323static int is_cowonly_root(u64 root_objectid) 3328static int is_cowonly_root(u64 root_objectid)
@@ -3631,6 +3636,11 @@ static int noinline get_new_locations(struct inode *reloc_inode,
3631 btrfs_file_extent_disk_num_bytes(leaf, fi); 3636 btrfs_file_extent_disk_num_bytes(leaf, fi);
3632 exts[nr].offset = btrfs_file_extent_offset(leaf, fi); 3637 exts[nr].offset = btrfs_file_extent_offset(leaf, fi);
3633 exts[nr].num_bytes = btrfs_file_extent_num_bytes(leaf, fi); 3638 exts[nr].num_bytes = btrfs_file_extent_num_bytes(leaf, fi);
3639 exts[nr].ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi);
3640 exts[nr].compression = btrfs_file_extent_compression(leaf, fi);
3641 exts[nr].encryption = btrfs_file_extent_encryption(leaf, fi);
3642 exts[nr].other_encoding = btrfs_file_extent_other_encoding(leaf,
3643 fi);
3634 WARN_ON(exts[nr].offset > 0); 3644 WARN_ON(exts[nr].offset > 0);
3635 WARN_ON(exts[nr].num_bytes != exts[nr].disk_num_bytes); 3645 WARN_ON(exts[nr].num_bytes != exts[nr].disk_num_bytes);
3636 3646
@@ -3846,6 +3856,8 @@ next:
3846 new_extents[0].disk_bytenr); 3856 new_extents[0].disk_bytenr);
3847 btrfs_set_file_extent_disk_num_bytes(leaf, fi, 3857 btrfs_set_file_extent_disk_num_bytes(leaf, fi,
3848 new_extents[0].disk_num_bytes); 3858 new_extents[0].disk_num_bytes);
3859 btrfs_set_file_extent_ram_bytes(leaf, fi,
3860 new_extents[0].ram_bytes);
3849 ext_offset += new_extents[0].offset; 3861 ext_offset += new_extents[0].offset;
3850 btrfs_set_file_extent_offset(leaf, fi, ext_offset); 3862 btrfs_set_file_extent_offset(leaf, fi, ext_offset);
3851 btrfs_mark_buffer_dirty(leaf); 3863 btrfs_mark_buffer_dirty(leaf);
@@ -3911,6 +3923,16 @@ next:
3911 new_extents[i].disk_bytenr); 3923 new_extents[i].disk_bytenr);
3912 btrfs_set_file_extent_disk_num_bytes(leaf, fi, 3924 btrfs_set_file_extent_disk_num_bytes(leaf, fi,
3913 new_extents[i].disk_num_bytes); 3925 new_extents[i].disk_num_bytes);
3926 btrfs_set_file_extent_ram_bytes(leaf, fi,
3927 new_extents[i].ram_bytes);
3928
3929 btrfs_set_file_extent_compression(leaf, fi,
3930 new_extents[i].compression);
3931 btrfs_set_file_extent_encryption(leaf, fi,
3932 new_extents[i].encryption);
3933 btrfs_set_file_extent_other_encoding(leaf, fi,
3934 new_extents[i].other_encoding);
3935
3914 btrfs_set_file_extent_num_bytes(leaf, fi, 3936 btrfs_set_file_extent_num_bytes(leaf, fi,
3915 extent_len); 3937 extent_len);
3916 ext_offset += new_extents[i].offset; 3938 ext_offset += new_extents[i].offset;
@@ -4169,6 +4191,8 @@ static int noinline replace_extents_in_leaf(struct btrfs_trans_handle *trans,
4169 ref->extents[ext_index].num_bytes = new_extent->disk_num_bytes; 4191 ref->extents[ext_index].num_bytes = new_extent->disk_num_bytes;
4170 4192
4171 btrfs_set_file_extent_generation(leaf, fi, trans->transid); 4193 btrfs_set_file_extent_generation(leaf, fi, trans->transid);
4194 btrfs_set_file_extent_ram_bytes(leaf, fi,
4195 new_extent->ram_bytes);
4172 btrfs_set_file_extent_disk_bytenr(leaf, fi, 4196 btrfs_set_file_extent_disk_bytenr(leaf, fi,
4173 new_extent->disk_bytenr); 4197 new_extent->disk_bytenr);
4174 btrfs_set_file_extent_disk_num_bytes(leaf, fi, 4198 btrfs_set_file_extent_disk_num_bytes(leaf, fi,
@@ -4847,7 +4871,8 @@ static struct inode noinline *create_reloc_inode(struct btrfs_fs_info *fs_info,
4847 BUG_ON(err); 4871 BUG_ON(err);
4848 4872
4849 err = btrfs_insert_file_extent(trans, root, objectid, 0, 0, 0, 4873 err = btrfs_insert_file_extent(trans, root, objectid, 0, 0, 0,
4850 group->key.offset, 0); 4874 group->key.offset, 0, group->key.offset,
4875 0, 0, 0);
4851 BUG_ON(err); 4876 BUG_ON(err);
4852 4877
4853 inode = btrfs_iget_locked(root->fs_info->sb, objectid, root); 4878 inode = btrfs_iget_locked(root->fs_info->sb, objectid, root);