mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-16 23:47:39 +07:00
5c1aab1dd5
Add zstd compression and decompression support to BtrFS. zstd at its fastest level compresses almost as well as zlib, while offering much faster compression and decompression, approaching lzo speeds. I benchmarked btrfs with zstd compression against no compression, lzo compression, and zlib compression. I benchmarked two scenarios. Copying a set of files to btrfs, and then reading the files. Copying a tarball to btrfs, extracting it to btrfs, and then reading the extracted files. After every operation, I call `sync` and include the sync time. Between every pair of operations I unmount and remount the filesystem to avoid caching. The benchmark files can be found in the upstream zstd source repository under `contrib/linux-kernel/{btrfs-benchmark.sh,btrfs-extract-benchmark.sh}` [1] [2]. I ran the benchmarks on a Ubuntu 14.04 VM with 2 cores and 4 GiB of RAM. The VM is running on a MacBook Pro with a 3.1 GHz Intel Core i7 processor, 16 GB of RAM, and a SSD. The first compression benchmark is copying 10 copies of the unzipped Silesia corpus [3] into a BtrFS filesystem mounted with `-o compress-force=Method`. The decompression benchmark times how long it takes to `tar` all 10 copies into `/dev/null`. The compression ratio is measured by comparing the output of `df` and `du`. See the benchmark file [1] for details. I benchmarked multiple zstd compression levels, although the patch uses zstd level 1. | Method | Ratio | Compression MB/s | Decompression speed | |---------|-------|------------------|---------------------| | None | 0.99 | 504 | 686 | | lzo | 1.66 | 398 | 442 | | zlib | 2.58 | 65 | 241 | | zstd 1 | 2.57 | 260 | 383 | | zstd 3 | 2.71 | 174 | 408 | | zstd 6 | 2.87 | 70 | 398 | | zstd 9 | 2.92 | 43 | 406 | | zstd 12 | 2.93 | 21 | 408 | | zstd 15 | 3.01 | 11 | 354 | The next benchmark first copies `linux-4.11.6.tar` [4] to btrfs. Then it measures the compression ratio, extracts the tar, and deletes the tar. Then it measures the compression ratio again, and `tar`s the extracted files into `/dev/null`. See the benchmark file [2] for details. | Method | Tar Ratio | Extract Ratio | Copy (s) | Extract (s)| Read (s) | |--------|-----------|---------------|----------|------------|----------| | None | 0.97 | 0.78 | 0.981 | 5.501 | 8.807 | | lzo | 2.06 | 1.38 | 1.631 | 8.458 | 8.585 | | zlib | 3.40 | 1.86 | 7.750 | 21.544 | 11.744 | | zstd 1 | 3.57 | 1.85 | 2.579 | 11.479 | 9.389 | [1] https://github.com/facebook/zstd/blob/dev/contrib/linux-kernel/btrfs-benchmark.sh [2] https://github.com/facebook/zstd/blob/dev/contrib/linux-kernel/btrfs-extract-benchmark.sh [3] http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia [4] https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.11.6.tar.xz zstd source repository: https://github.com/facebook/zstd Signed-off-by: Nick Terrell <terrelln@fb.com> Signed-off-by: Chris Mason <clm@fb.com>
135 lines
4.0 KiB
C
135 lines
4.0 KiB
C
/*
|
|
* 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_
|
|
|
|
/*
|
|
* 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)
|
|
|
|
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;
|
|
};
|
|
|
|
void btrfs_init_compress(void);
|
|
void btrfs_exit_compress(void);
|
|
|
|
int btrfs_compress_pages(int type, struct address_space *mapping,
|
|
u64 start, struct page **pages,
|
|
unsigned long *out_pages,
|
|
unsigned long *total_in,
|
|
unsigned long *total_out);
|
|
int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
|
|
unsigned long start_byte, size_t srclen, size_t destlen);
|
|
int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start,
|
|
unsigned long total_out, u64 disk_start,
|
|
struct bio *bio);
|
|
|
|
blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
|
|
unsigned long len, u64 disk_start,
|
|
unsigned long compressed_len,
|
|
struct page **compressed_pages,
|
|
unsigned long nr_pages);
|
|
blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
|
|
int mirror_num, unsigned long bio_flags);
|
|
|
|
enum btrfs_compression_type {
|
|
BTRFS_COMPRESS_NONE = 0,
|
|
BTRFS_COMPRESS_ZLIB = 1,
|
|
BTRFS_COMPRESS_LZO = 2,
|
|
BTRFS_COMPRESS_ZSTD = 3,
|
|
BTRFS_COMPRESS_TYPES = 3,
|
|
BTRFS_COMPRESS_LAST = 4,
|
|
};
|
|
|
|
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,
|
|
u64 start,
|
|
struct page **pages,
|
|
unsigned long *out_pages,
|
|
unsigned long *total_in,
|
|
unsigned long *total_out);
|
|
|
|
int (*decompress_bio)(struct list_head *workspace,
|
|
struct compressed_bio *cb);
|
|
|
|
int (*decompress)(struct list_head *workspace,
|
|
unsigned char *data_in,
|
|
struct page *dest_page,
|
|
unsigned long start_byte,
|
|
size_t srclen, size_t destlen);
|
|
};
|
|
|
|
extern const struct btrfs_compress_op btrfs_zlib_compress;
|
|
extern const struct btrfs_compress_op btrfs_lzo_compress;
|
|
extern const struct btrfs_compress_op btrfs_zstd_compress;
|
|
|
|
#endif
|