compression.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2008 Oracle. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #ifndef __BTRFS_COMPRESSION_
  19. #define __BTRFS_COMPRESSION_
  20. /*
  21. * We want to make sure that amount of RAM required to uncompress an extent is
  22. * reasonable, so we limit the total size in ram of a compressed extent to
  23. * 128k. This is a crucial number because it also controls how easily we can
  24. * spread reads across cpus for decompression.
  25. *
  26. * We also want to make sure the amount of IO required to do a random read is
  27. * reasonably small, so we limit the size of a compressed extent to 128k.
  28. */
  29. /* Maximum length of compressed data stored on disk */
  30. #define BTRFS_MAX_COMPRESSED (SZ_128K)
  31. /* Maximum size of data before compression */
  32. #define BTRFS_MAX_UNCOMPRESSED (SZ_128K)
  33. void btrfs_init_compress(void);
  34. void btrfs_exit_compress(void);
  35. int btrfs_compress_pages(int type, struct address_space *mapping,
  36. u64 start, struct page **pages,
  37. unsigned long *out_pages,
  38. unsigned long *total_in,
  39. unsigned long *total_out);
  40. int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
  41. unsigned long start_byte, size_t srclen, size_t destlen);
  42. int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start,
  43. unsigned long total_out, u64 disk_start,
  44. struct bio *bio);
  45. int btrfs_submit_compressed_write(struct inode *inode, u64 start,
  46. unsigned long len, u64 disk_start,
  47. unsigned long compressed_len,
  48. struct page **compressed_pages,
  49. unsigned long nr_pages);
  50. int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
  51. int mirror_num, unsigned long bio_flags);
  52. enum btrfs_compression_type {
  53. BTRFS_COMPRESS_NONE = 0,
  54. BTRFS_COMPRESS_ZLIB = 1,
  55. BTRFS_COMPRESS_LZO = 2,
  56. BTRFS_COMPRESS_TYPES = 2,
  57. BTRFS_COMPRESS_LAST = 3,
  58. };
  59. struct btrfs_compress_op {
  60. struct list_head *(*alloc_workspace)(void);
  61. void (*free_workspace)(struct list_head *workspace);
  62. int (*compress_pages)(struct list_head *workspace,
  63. struct address_space *mapping,
  64. u64 start,
  65. struct page **pages,
  66. unsigned long *out_pages,
  67. unsigned long *total_in,
  68. unsigned long *total_out);
  69. int (*decompress_bio)(struct list_head *workspace,
  70. struct page **pages_in,
  71. u64 disk_start,
  72. struct bio *orig_bio,
  73. size_t srclen);
  74. int (*decompress)(struct list_head *workspace,
  75. unsigned char *data_in,
  76. struct page *dest_page,
  77. unsigned long start_byte,
  78. size_t srclen, size_t destlen);
  79. };
  80. extern const struct btrfs_compress_op btrfs_zlib_compress;
  81. extern const struct btrfs_compress_op btrfs_lzo_compress;
  82. #endif