fs/btrfs/compression.h
Source file repositories/reference/linux-study-clean/fs/btrfs/compression.h
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/compression.h- Extension
.h- Size
- 6543 bytes
- Lines
- 184
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sizes.hlinux/mm.hlinux/list.hlinux/workqueue.hlinux/wait.hlinux/pagemap.hbio.hfs.hbtrfs_inode.h
Detected Declarations
struct address_spacestruct inodestruct btrfs_inodestruct btrfs_ordered_extentstruct compressed_biostruct workspace_managerstruct btrfs_compress_levelsfunction btrfs_calc_input_lengthfunction cleanup_compressed_bio
Annotated Snippet
struct compressed_bio {
/* starting offset in the inode for our pages */
u64 start;
/* Number of bytes in the inode we're working on */
unsigned int len;
/* The compression algorithm for this bio */
u8 compress_type;
/* Whether this is a write for writeback. */
bool writeback;
/* For reads, this is the bio we are copying the data into. */
struct btrfs_bio *orig_bbio;
/* Must be last. */
struct btrfs_bio bbio;
};
static inline struct btrfs_fs_info *cb_to_fs_info(const struct compressed_bio *cb)
{
return cb->bbio.inode->root->fs_info;
}
/* @range_end must be exclusive. */
static inline u32 btrfs_calc_input_length(struct folio *folio, u64 range_end, u64 cur)
{
/* @cur must be inside the folio. */
ASSERT(folio_pos(folio) <= cur);
ASSERT(cur < folio_next_pos(folio));
return umin(range_end, folio_next_pos(folio)) - cur;
}
int btrfs_alloc_compress_wsm(struct btrfs_fs_info *fs_info);
void btrfs_free_compress_wsm(struct btrfs_fs_info *fs_info);
int __init btrfs_init_compress(void);
void __cold btrfs_exit_compress(void);
bool btrfs_compress_level_valid(unsigned int type, int level);
int btrfs_decompress(int type, const u8 *data_in, struct folio *dest_folio,
unsigned long dest_pgoff, size_t srclen, size_t destlen);
int btrfs_decompress_buf2page(const char *buf, u32 buf_len,
struct compressed_bio *cb, u32 decompressed);
struct compressed_bio *btrfs_alloc_compressed_write(struct btrfs_inode *inode,
u64 start, u64 len);
void btrfs_submit_compressed_write(struct btrfs_ordered_extent *ordered,
struct compressed_bio *cb);
void btrfs_submit_compressed_read(struct btrfs_bio *bbio);
int btrfs_compress_str2level(unsigned int type, const char *str, int *level_ret);
struct folio *btrfs_alloc_compr_folio(struct btrfs_fs_info *fs_info, gfp_t gfp);
void btrfs_free_compr_folio(struct folio *folio);
struct workspace_manager {
struct list_head idle_ws;
spinlock_t ws_lock;
/* Number of free workspaces */
int free_ws;
/* Total number of allocated workspaces */
atomic_t total_ws;
/* Waiters for a free workspace */
wait_queue_head_t ws_wait;
};
struct list_head *btrfs_get_workspace(struct btrfs_fs_info *fs_info, int type, int level);
void btrfs_put_workspace(struct btrfs_fs_info *fs_info, int type, struct list_head *ws);
struct btrfs_compress_levels {
/* Maximum level supported by the compression algorithm */
int min_level;
int max_level;
int default_level;
};
/* The heuristic workspaces are managed via the 0th workspace manager */
#define BTRFS_NR_WORKSPACE_MANAGERS BTRFS_NR_COMPRESS_TYPES
extern const struct btrfs_compress_levels btrfs_heuristic_compress;
extern const struct btrfs_compress_levels btrfs_zlib_compress;
extern const struct btrfs_compress_levels btrfs_lzo_compress;
extern const struct btrfs_compress_levels btrfs_zstd_compress;
const char* btrfs_compress_type2str(enum btrfs_compression_type type);
bool btrfs_compress_is_valid_type(const char *str, size_t len);
int btrfs_compress_heuristic(struct btrfs_inode *inode, u64 start, u64 end);
Annotation
- Immediate include surface: `linux/sizes.h`, `linux/mm.h`, `linux/list.h`, `linux/workqueue.h`, `linux/wait.h`, `linux/pagemap.h`, `bio.h`, `fs.h`.
- Detected declarations: `struct address_space`, `struct inode`, `struct btrfs_inode`, `struct btrfs_ordered_extent`, `struct compressed_bio`, `struct workspace_manager`, `struct btrfs_compress_levels`, `function btrfs_calc_input_length`, `function cleanup_compressed_bio`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.