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>
2008-10-30 02:49:59 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License v2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BTRFS_COMPRESSION_
|
|
|
|
#define __BTRFS_COMPRESSION_
|
|
|
|
|
2017-02-15 02:30:39 +08:00
|
|
|
/*
|
|
|
|
* We want to make sure that amount of RAM required to uncompress an extent is
|
|
|
|
* reasonable, so we limit the total size in ram of a compressed extent to
|
|
|
|
* 128k. This is a crucial number because it also controls how easily we can
|
|
|
|
* spread reads across cpus for decompression.
|
|
|
|
*
|
|
|
|
* We also want to make sure the amount of IO required to do a random read is
|
|
|
|
* reasonably small, so we limit the size of a compressed extent to 128k.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Maximum length of compressed data stored on disk */
|
|
|
|
#define BTRFS_MAX_COMPRESSED (SZ_128K)
|
|
|
|
/* Maximum size of data before compression */
|
|
|
|
#define BTRFS_MAX_UNCOMPRESSED (SZ_128K)
|
|
|
|
|
2017-05-26 15:44:59 +08:00
|
|
|
struct compressed_bio {
|
|
|
|
/* number of bios pending for this compressed extent */
|
|
|
|
refcount_t pending_bios;
|
|
|
|
|
|
|
|
/* the pages with the compressed data on them */
|
|
|
|
struct page **compressed_pages;
|
|
|
|
|
|
|
|
/* inode that owns this data */
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
/* starting offset in the inode for our pages */
|
|
|
|
u64 start;
|
|
|
|
|
|
|
|
/* number of bytes in the inode we're working on */
|
|
|
|
unsigned long len;
|
|
|
|
|
|
|
|
/* number of bytes on disk */
|
|
|
|
unsigned long compressed_len;
|
|
|
|
|
|
|
|
/* the compression algorithm for this bio */
|
|
|
|
int compress_type;
|
|
|
|
|
|
|
|
/* number of compressed pages in the array */
|
|
|
|
unsigned long nr_pages;
|
|
|
|
|
|
|
|
/* IO errors */
|
|
|
|
int errors;
|
|
|
|
int mirror_num;
|
|
|
|
|
|
|
|
/* for reads, this is the bio we are copying the data into */
|
|
|
|
struct bio *orig_bio;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the start of a variable length array of checksums only
|
|
|
|
* used by reads
|
|
|
|
*/
|
|
|
|
u32 sums;
|
|
|
|
};
|
|
|
|
|
2012-03-01 21:56:26 +08:00
|
|
|
void btrfs_init_compress(void);
|
2010-12-17 14:21:50 +08:00
|
|
|
void btrfs_exit_compress(void);
|
|
|
|
|
|
|
|
int btrfs_compress_pages(int type, struct address_space *mapping,
|
2017-02-15 02:04:07 +08:00
|
|
|
u64 start, struct page **pages,
|
2010-12-17 14:21:50 +08:00
|
|
|
unsigned long *out_pages,
|
|
|
|
unsigned long *total_in,
|
2017-02-15 02:45:05 +08:00
|
|
|
unsigned long *total_out);
|
2010-12-17 14:21:50 +08:00
|
|
|
int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
|
|
|
|
unsigned long start_byte, size_t srclen, size_t destlen);
|
2017-02-15 00:58:04 +08:00
|
|
|
int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start,
|
2010-11-08 15:22:19 +08:00
|
|
|
unsigned long total_out, u64 disk_start,
|
2016-11-25 16:07:46 +08:00
|
|
|
struct bio *bio);
|
2010-12-17 14:21:50 +08:00
|
|
|
|
2017-06-03 15:38:06 +08:00
|
|
|
blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
|
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>
2008-10-30 02:49:59 +08:00
|
|
|
unsigned long len, u64 disk_start,
|
|
|
|
unsigned long compressed_len,
|
|
|
|
struct page **compressed_pages,
|
|
|
|
unsigned long nr_pages);
|
2017-06-03 15:38:06 +08:00
|
|
|
blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
|
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>
2008-10-30 02:49:59 +08:00
|
|
|
int mirror_num, unsigned long bio_flags);
|
2016-03-10 17:26:59 +08:00
|
|
|
|
|
|
|
enum btrfs_compression_type {
|
|
|
|
BTRFS_COMPRESS_NONE = 0,
|
|
|
|
BTRFS_COMPRESS_ZLIB = 1,
|
|
|
|
BTRFS_COMPRESS_LZO = 2,
|
|
|
|
BTRFS_COMPRESS_TYPES = 2,
|
|
|
|
BTRFS_COMPRESS_LAST = 3,
|
|
|
|
};
|
|
|
|
|
2010-12-17 14:21:50 +08:00
|
|
|
struct btrfs_compress_op {
|
|
|
|
struct list_head *(*alloc_workspace)(void);
|
|
|
|
|
|
|
|
void (*free_workspace)(struct list_head *workspace);
|
|
|
|
|
|
|
|
int (*compress_pages)(struct list_head *workspace,
|
|
|
|
struct address_space *mapping,
|
2017-02-15 02:04:07 +08:00
|
|
|
u64 start,
|
2010-12-17 14:21:50 +08:00
|
|
|
struct page **pages,
|
|
|
|
unsigned long *out_pages,
|
|
|
|
unsigned long *total_in,
|
2017-02-15 02:45:05 +08:00
|
|
|
unsigned long *total_out);
|
2010-12-17 14:21:50 +08:00
|
|
|
|
2016-11-25 16:07:46 +08:00
|
|
|
int (*decompress_bio)(struct list_head *workspace,
|
2017-05-26 15:44:59 +08:00
|
|
|
struct compressed_bio *cb);
|
2010-12-17 14:21:50 +08:00
|
|
|
|
|
|
|
int (*decompress)(struct list_head *workspace,
|
|
|
|
unsigned char *data_in,
|
|
|
|
struct page *dest_page,
|
|
|
|
unsigned long start_byte,
|
|
|
|
size_t srclen, size_t destlen);
|
|
|
|
};
|
|
|
|
|
2015-01-03 01:23:10 +08:00
|
|
|
extern const struct btrfs_compress_op btrfs_zlib_compress;
|
|
|
|
extern const struct btrfs_compress_op btrfs_lzo_compress;
|
2010-12-17 14:21:50 +08:00
|
|
|
|
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>
2008-10-30 02:49:59 +08:00
|
|
|
#endif
|