2007-08-28 04:49:44 +08:00
|
|
|
#ifndef __EXTENTMAP__
|
|
|
|
#define __EXTENTMAP__
|
|
|
|
|
|
|
|
#include <linux/rbtree.h>
|
|
|
|
|
2008-01-25 05:13:08 +08:00
|
|
|
#define EXTENT_MAP_LAST_BYTE (u64)-4
|
2007-10-16 04:14:19 +08:00
|
|
|
#define EXTENT_MAP_HOLE (u64)-3
|
2007-08-28 04:49:44 +08:00
|
|
|
#define EXTENT_MAP_INLINE (u64)-2
|
|
|
|
#define EXTENT_MAP_DELALLOC (u64)-1
|
|
|
|
|
2008-07-19 00:01:11 +08:00
|
|
|
/* bits for the flags field */
|
|
|
|
#define EXTENT_FLAG_PINNED 0 /* this entry not yet on disk, don't free it */
|
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
|
|
|
#define EXTENT_FLAG_COMPRESSED 1
|
2008-10-31 02:19:41 +08:00
|
|
|
#define EXTENT_FLAG_VACANCY 2 /* no file extent item found */
|
2008-10-31 02:25:28 +08:00
|
|
|
#define EXTENT_FLAG_PREALLOC 3 /* pre-allocated extent */
|
2008-07-19 00:01:11 +08:00
|
|
|
|
2007-08-28 04:49:44 +08:00
|
|
|
struct extent_map {
|
|
|
|
struct rb_node rb_node;
|
2008-01-25 05:13:08 +08:00
|
|
|
|
|
|
|
/* all of these are in bytes */
|
|
|
|
u64 start;
|
|
|
|
u64 len;
|
2008-11-10 20:34:43 +08:00
|
|
|
u64 orig_start;
|
2007-08-28 04:49:44 +08:00
|
|
|
u64 block_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
|
|
|
u64 block_len;
|
2008-01-25 05:13:08 +08:00
|
|
|
unsigned long flags;
|
2007-08-28 04:49:44 +08:00
|
|
|
struct block_device *bdev;
|
|
|
|
atomic_t refs;
|
2012-01-27 04:01:12 +08:00
|
|
|
unsigned int in_tree;
|
|
|
|
unsigned int compress_type;
|
2007-08-28 04:49:44 +08:00
|
|
|
};
|
|
|
|
|
2008-01-25 05:13:08 +08:00
|
|
|
struct extent_map_tree {
|
|
|
|
struct rb_root map;
|
2009-09-03 04:24:52 +08:00
|
|
|
rwlock_t lock;
|
2007-08-28 04:49:44 +08:00
|
|
|
};
|
|
|
|
|
2008-01-25 05:13:08 +08:00
|
|
|
static inline u64 extent_map_end(struct extent_map *em)
|
|
|
|
{
|
|
|
|
if (em->start + em->len < em->start)
|
|
|
|
return (u64)-1;
|
|
|
|
return em->start + em->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 extent_map_block_end(struct extent_map *em)
|
|
|
|
{
|
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
|
|
|
if (em->block_start + em->block_len < em->block_start)
|
2008-01-25 05:13:08 +08:00
|
|
|
return (u64)-1;
|
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
|
|
|
return em->block_start + em->block_len;
|
2008-01-25 05:13:08 +08:00
|
|
|
}
|
2007-08-28 04:49:44 +08:00
|
|
|
|
2011-04-21 06:34:43 +08:00
|
|
|
void extent_map_tree_init(struct extent_map_tree *tree);
|
2007-08-28 04:49:44 +08:00
|
|
|
struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
|
2008-01-25 05:13:08 +08:00
|
|
|
u64 start, u64 len);
|
2007-08-28 04:49:44 +08:00
|
|
|
int add_extent_mapping(struct extent_map_tree *tree,
|
|
|
|
struct extent_map *em);
|
|
|
|
int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
|
2008-01-25 05:13:08 +08:00
|
|
|
|
2011-04-21 06:48:27 +08:00
|
|
|
struct extent_map *alloc_extent_map(void);
|
2007-08-28 04:49:44 +08:00
|
|
|
void free_extent_map(struct extent_map *em);
|
2007-11-19 23:22:33 +08:00
|
|
|
int __init extent_map_init(void);
|
2007-12-11 22:25:06 +08:00
|
|
|
void extent_map_exit(void);
|
2009-09-12 00:27:37 +08:00
|
|
|
int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len);
|
2009-09-19 04:07:03 +08:00
|
|
|
struct extent_map *search_extent_mapping(struct extent_map_tree *tree,
|
|
|
|
u64 start, u64 len);
|
2007-08-28 04:49:44 +08:00
|
|
|
#endif
|