2008-01-25 05:13:08 +08:00
|
|
|
#ifndef __EXTENTIO__
|
|
|
|
#define __EXTENTIO__
|
|
|
|
|
|
|
|
#include <linux/rbtree.h>
|
|
|
|
|
|
|
|
/* bits for the extent state */
|
|
|
|
#define EXTENT_DIRTY 1
|
|
|
|
#define EXTENT_WRITEBACK (1 << 1)
|
|
|
|
#define EXTENT_UPTODATE (1 << 2)
|
|
|
|
#define EXTENT_LOCKED (1 << 3)
|
|
|
|
#define EXTENT_NEW (1 << 4)
|
|
|
|
#define EXTENT_DELALLOC (1 << 5)
|
|
|
|
#define EXTENT_DEFRAG (1 << 6)
|
|
|
|
#define EXTENT_DEFRAG_DONE (1 << 7)
|
|
|
|
#define EXTENT_BUFFER_FILLED (1 << 8)
|
2009-09-03 04:53:46 +08:00
|
|
|
#define EXTENT_BOUNDARY (1 << 9)
|
|
|
|
#define EXTENT_NODATASUM (1 << 10)
|
2009-10-09 01:34:05 +08:00
|
|
|
#define EXTENT_DO_ACCOUNTING (1 << 11)
|
2010-05-16 22:48:47 +08:00
|
|
|
#define EXTENT_FIRST_DELALLOC (1 << 12)
|
2011-09-27 01:58:47 +08:00
|
|
|
#define EXTENT_NEED_WAIT (1 << 13)
|
2011-11-06 16:07:10 +08:00
|
|
|
#define EXTENT_DAMAGED (1 << 14)
|
2008-01-25 05:13:08 +08:00
|
|
|
#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
|
2010-05-16 22:48:47 +08:00
|
|
|
#define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)
|
2008-01-25 05:13:08 +08:00
|
|
|
|
2010-12-17 14:21:50 +08:00
|
|
|
/*
|
|
|
|
* flags for bio submission. The high bits indicate the compression
|
|
|
|
* type for this 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
|
|
|
#define EXTENT_BIO_COMPRESSED 1
|
2012-09-26 02:25:58 +08:00
|
|
|
#define EXTENT_BIO_TREE_LOG 2
|
2010-12-17 14:21:50 +08:00
|
|
|
#define EXTENT_BIO_FLAG_SHIFT 16
|
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
|
|
|
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 22:25:08 +08:00
|
|
|
/* these are bit numbers for test/set bit */
|
|
|
|
#define EXTENT_BUFFER_UPTODATE 0
|
|
|
|
#define EXTENT_BUFFER_BLOCKING 1
|
2009-03-13 23:00:37 +08:00
|
|
|
#define EXTENT_BUFFER_DIRTY 2
|
2011-03-17 01:42:43 +08:00
|
|
|
#define EXTENT_BUFFER_CORRUPT 3
|
2011-05-23 20:25:41 +08:00
|
|
|
#define EXTENT_BUFFER_READAHEAD 4 /* this got triggered by readahead */
|
2012-03-10 05:01:49 +08:00
|
|
|
#define EXTENT_BUFFER_TREE_REF 5
|
|
|
|
#define EXTENT_BUFFER_STALE 6
|
2012-03-13 21:38:00 +08:00
|
|
|
#define EXTENT_BUFFER_WRITEBACK 7
|
|
|
|
#define EXTENT_BUFFER_IOERR 8
|
2012-05-16 23:00:02 +08:00
|
|
|
#define EXTENT_BUFFER_DUMMY 9
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 22:25:08 +08:00
|
|
|
|
2009-10-08 23:27:10 +08:00
|
|
|
/* these are flags for extent_clear_unlock_delalloc */
|
|
|
|
#define EXTENT_CLEAR_UNLOCK_PAGE 0x1
|
|
|
|
#define EXTENT_CLEAR_UNLOCK 0x2
|
|
|
|
#define EXTENT_CLEAR_DELALLOC 0x4
|
|
|
|
#define EXTENT_CLEAR_DIRTY 0x8
|
|
|
|
#define EXTENT_SET_WRITEBACK 0x10
|
|
|
|
#define EXTENT_END_WRITEBACK 0x20
|
|
|
|
#define EXTENT_SET_PRIVATE2 0x40
|
2009-10-09 01:34:05 +08:00
|
|
|
#define EXTENT_CLEAR_ACCOUNTING 0x80
|
2009-10-08 23:27:10 +08:00
|
|
|
|
2008-01-25 05:13:08 +08:00
|
|
|
/*
|
|
|
|
* page->private values. Every page that is controlled by the extent
|
|
|
|
* map has page->private set to one.
|
|
|
|
*/
|
|
|
|
#define EXTENT_PAGE_PRIVATE 1
|
|
|
|
#define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
|
|
|
|
|
2008-01-29 22:59:12 +08:00
|
|
|
struct extent_state;
|
2012-03-27 09:57:36 +08:00
|
|
|
struct btrfs_root;
|
2008-01-29 22:59:12 +08:00
|
|
|
|
2008-04-16 23:14:51 +08:00
|
|
|
typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
|
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
|
|
|
struct bio *bio, int mirror_num,
|
2010-05-25 21:48:28 +08:00
|
|
|
unsigned long bio_flags, u64 bio_offset);
|
2008-01-25 05:13:08 +08:00
|
|
|
struct extent_io_ops {
|
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 (*fill_delalloc)(struct inode *inode, struct page *locked_page,
|
2008-11-07 11:02:51 +08:00
|
|
|
u64 start, u64 end, int *page_started,
|
|
|
|
unsigned long *nr_written);
|
2008-07-18 00:53:51 +08:00
|
|
|
int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
|
2008-01-25 05:13:08 +08:00
|
|
|
int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
|
2008-04-16 23:14:51 +08:00
|
|
|
extent_submit_bio_hook_t *submit_bio_hook;
|
2008-03-25 03:02:07 +08:00
|
|
|
int (*merge_bio_hook)(struct page *page, unsigned long offset,
|
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
|
|
|
size_t size, struct bio *bio,
|
|
|
|
unsigned long bio_flags);
|
2008-01-25 05:13:08 +08:00
|
|
|
int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
|
2012-03-27 09:57:36 +08:00
|
|
|
int (*readpage_io_failed_hook)(struct page *page, int failed_mirror);
|
2008-01-29 22:59:12 +08:00
|
|
|
int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
|
2012-04-16 21:42:26 +08:00
|
|
|
struct extent_state *state, int mirror);
|
2008-05-13 01:39:03 +08:00
|
|
|
int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
|
2008-07-18 00:53:50 +08:00
|
|
|
struct extent_state *state, int uptodate);
|
2011-07-22 00:56:09 +08:00
|
|
|
void (*set_bit_hook)(struct inode *inode, struct extent_state *state,
|
|
|
|
int *bits);
|
|
|
|
void (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
|
|
|
|
int *bits);
|
|
|
|
void (*merge_extent_hook)(struct inode *inode,
|
|
|
|
struct extent_state *new,
|
|
|
|
struct extent_state *other);
|
|
|
|
void (*split_extent_hook)(struct inode *inode,
|
|
|
|
struct extent_state *orig, u64 split);
|
2011-11-01 22:08:06 +08:00
|
|
|
int (*write_cache_pages_lock_hook)(struct page *page, void *data,
|
|
|
|
void (*flush_fn)(void *));
|
2008-01-25 05:13:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct extent_io_tree {
|
|
|
|
struct rb_root state;
|
2010-10-27 08:57:29 +08:00
|
|
|
struct radix_tree_root buffer;
|
2008-01-25 05:13:08 +08:00
|
|
|
struct address_space *mapping;
|
|
|
|
u64 dirty_bytes;
|
2012-03-13 21:38:00 +08:00
|
|
|
int track_uptodate;
|
2008-01-29 22:59:12 +08:00
|
|
|
spinlock_t lock;
|
2008-07-22 23:18:07 +08:00
|
|
|
spinlock_t buffer_lock;
|
2008-01-25 05:13:08 +08:00
|
|
|
struct extent_io_ops *ops;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct extent_state {
|
|
|
|
u64 start;
|
|
|
|
u64 end; /* inclusive */
|
|
|
|
struct rb_node rb_node;
|
2009-09-12 04:12:44 +08:00
|
|
|
|
|
|
|
/* ADD NEW ELEMENTS AFTER THIS */
|
2008-01-29 22:59:12 +08:00
|
|
|
struct extent_io_tree *tree;
|
2008-01-25 05:13:08 +08:00
|
|
|
wait_queue_head_t wq;
|
|
|
|
atomic_t refs;
|
|
|
|
unsigned long state;
|
|
|
|
|
|
|
|
/* for use by the FS */
|
|
|
|
u64 private;
|
|
|
|
|
2008-03-27 04:24:23 +08:00
|
|
|
struct list_head leak_list;
|
2008-01-25 05:13:08 +08:00
|
|
|
};
|
|
|
|
|
2010-08-07 01:21:20 +08:00
|
|
|
#define INLINE_EXTENT_BUFFER_PAGES 16
|
|
|
|
#define MAX_INLINE_EXTENT_BUFFER_SIZE (INLINE_EXTENT_BUFFER_PAGES * PAGE_CACHE_SIZE)
|
2008-01-25 05:13:08 +08:00
|
|
|
struct extent_buffer {
|
|
|
|
u64 start;
|
|
|
|
unsigned long len;
|
|
|
|
unsigned long map_start;
|
|
|
|
unsigned long map_len;
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 22:25:08 +08:00
|
|
|
unsigned long bflags;
|
2012-03-08 05:20:05 +08:00
|
|
|
struct extent_io_tree *tree;
|
2012-03-10 05:01:49 +08:00
|
|
|
spinlock_t refs_lock;
|
2010-08-07 01:21:20 +08:00
|
|
|
atomic_t refs;
|
2012-03-13 21:38:00 +08:00
|
|
|
atomic_t io_pages;
|
2012-04-16 21:42:26 +08:00
|
|
|
int read_mirror;
|
2008-03-27 04:24:23 +08:00
|
|
|
struct list_head leak_list;
|
2010-10-27 08:57:29 +08:00
|
|
|
struct rcu_head rcu_head;
|
2011-09-13 16:55:48 +08:00
|
|
|
pid_t lock_owner;
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 22:25:08 +08:00
|
|
|
|
2011-07-17 03:23:14 +08:00
|
|
|
/* count of read lock holders on the extent buffer */
|
|
|
|
atomic_t write_locks;
|
|
|
|
atomic_t read_locks;
|
|
|
|
atomic_t blocking_writers;
|
|
|
|
atomic_t blocking_readers;
|
|
|
|
atomic_t spinning_readers;
|
|
|
|
atomic_t spinning_writers;
|
2011-09-13 16:55:48 +08:00
|
|
|
int lock_nested;
|
2011-07-17 03:23:14 +08:00
|
|
|
|
|
|
|
/* protects write locks */
|
|
|
|
rwlock_t lock;
|
|
|
|
|
|
|
|
/* readers use lock_wq while they wait for the write
|
|
|
|
* lock holders to unlock
|
|
|
|
*/
|
|
|
|
wait_queue_head_t write_lock_wq;
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 22:25:08 +08:00
|
|
|
|
2011-07-17 03:23:14 +08:00
|
|
|
/* writers use read_lock_wq while they wait for readers
|
|
|
|
* to unlock
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 22:25:08 +08:00
|
|
|
*/
|
2011-07-17 03:23:14 +08:00
|
|
|
wait_queue_head_t read_lock_wq;
|
2010-08-07 01:21:20 +08:00
|
|
|
wait_queue_head_t lock_wq;
|
|
|
|
struct page *inline_pages[INLINE_EXTENT_BUFFER_PAGES];
|
|
|
|
struct page **pages;
|
2008-01-25 05:13:08 +08:00
|
|
|
};
|
|
|
|
|
2010-12-17 14:21:50 +08:00
|
|
|
static inline void extent_set_compress_type(unsigned long *bio_flags,
|
|
|
|
int compress_type)
|
|
|
|
{
|
|
|
|
*bio_flags |= compress_type << EXTENT_BIO_FLAG_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int extent_compress_type(unsigned long bio_flags)
|
|
|
|
{
|
|
|
|
return bio_flags >> EXTENT_BIO_FLAG_SHIFT;
|
|
|
|
}
|
|
|
|
|
2008-01-25 05:13:08 +08:00
|
|
|
struct extent_map_tree;
|
|
|
|
|
|
|
|
typedef struct extent_map *(get_extent_t)(struct inode *inode,
|
|
|
|
struct page *page,
|
2011-04-19 20:29:38 +08:00
|
|
|
size_t pg_offset,
|
2008-01-25 05:13:08 +08:00
|
|
|
u64 start, u64 len,
|
|
|
|
int create);
|
|
|
|
|
|
|
|
void extent_io_tree_init(struct extent_io_tree *tree,
|
2011-04-21 05:35:57 +08:00
|
|
|
struct address_space *mapping);
|
2008-01-25 05:13:08 +08:00
|
|
|
int try_release_extent_mapping(struct extent_map_tree *map,
|
2008-01-29 22:59:12 +08:00
|
|
|
struct extent_io_tree *tree, struct page *page,
|
|
|
|
gfp_t mask);
|
2012-03-10 05:01:49 +08:00
|
|
|
int try_release_extent_buffer(struct page *page, gfp_t mask);
|
2008-04-18 22:29:50 +08:00
|
|
|
int try_release_extent_state(struct extent_map_tree *map,
|
|
|
|
struct extent_io_tree *tree, struct page *page,
|
|
|
|
gfp_t mask);
|
2012-03-01 21:57:19 +08:00
|
|
|
int lock_extent(struct extent_io_tree *tree, u64 start, u64 end);
|
2009-09-03 01:24:36 +08:00
|
|
|
int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
2012-03-01 21:57:19 +08:00
|
|
|
int bits, struct extent_state **cached);
|
|
|
|
int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end);
|
2010-02-04 03:33:23 +08:00
|
|
|
int unlock_extent_cached(struct extent_io_tree *tree, u64 start, u64 end,
|
|
|
|
struct extent_state **cached, gfp_t mask);
|
2012-03-01 21:57:19 +08:00
|
|
|
int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end);
|
2008-01-25 05:13:08 +08:00
|
|
|
int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
|
2011-06-14 02:02:58 +08:00
|
|
|
get_extent_t *get_extent, int mirror_num);
|
2008-01-25 05:13:08 +08:00
|
|
|
int __init extent_io_init(void);
|
|
|
|
void extent_io_exit(void);
|
|
|
|
|
|
|
|
u64 count_range_bits(struct extent_io_tree *tree,
|
|
|
|
u64 *start, u64 search_end,
|
2011-02-24 05:23:20 +08:00
|
|
|
u64 max_bytes, unsigned long bits, int contig);
|
2008-01-25 05:13:08 +08:00
|
|
|
|
2010-05-26 08:56:50 +08:00
|
|
|
void free_extent_state(struct extent_state *state);
|
2008-01-25 05:13:08 +08:00
|
|
|
int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
2009-09-03 03:22:30 +08:00
|
|
|
int bits, int filled, struct extent_state *cached_state);
|
2008-01-25 05:13:08 +08:00
|
|
|
int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
|
|
|
int bits, gfp_t mask);
|
2008-07-18 00:53:50 +08:00
|
|
|
int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
2009-09-03 03:04:12 +08:00
|
|
|
int bits, int wake, int delete, struct extent_state **cached,
|
|
|
|
gfp_t mask);
|
2008-01-25 05:13:08 +08:00
|
|
|
int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
|
|
|
int bits, gfp_t mask);
|
2010-05-26 08:56:50 +08:00
|
|
|
int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
2012-03-01 21:57:19 +08:00
|
|
|
int bits, u64 *failed_start,
|
2010-05-26 08:56:50 +08:00
|
|
|
struct extent_state **cached_state, gfp_t mask);
|
2008-01-25 05:13:08 +08:00
|
|
|
int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
|
2011-04-06 18:02:20 +08:00
|
|
|
struct extent_state **cached_state, gfp_t mask);
|
2012-05-03 02:00:54 +08:00
|
|
|
int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
|
|
|
|
struct extent_state **cached_state, gfp_t mask);
|
2008-01-25 05:13:08 +08:00
|
|
|
int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
|
|
|
|
gfp_t mask);
|
|
|
|
int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
|
|
|
|
gfp_t mask);
|
|
|
|
int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
|
|
|
|
gfp_t mask);
|
2011-09-27 01:56:12 +08:00
|
|
|
int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
2012-09-28 05:07:30 +08:00
|
|
|
int bits, int clear_bits,
|
|
|
|
struct extent_state **cached_state, gfp_t mask);
|
2008-01-25 05:13:08 +08:00
|
|
|
int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
|
2010-02-04 03:33:23 +08:00
|
|
|
struct extent_state **cached_state, gfp_t mask);
|
2012-09-06 09:10:51 +08:00
|
|
|
int set_extent_defrag(struct extent_io_tree *tree, u64 start, u64 end,
|
|
|
|
struct extent_state **cached_state, gfp_t mask);
|
2008-01-25 05:13:08 +08:00
|
|
|
int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
|
2012-09-28 05:07:30 +08:00
|
|
|
u64 *start_ret, u64 *end_ret, int bits,
|
|
|
|
struct extent_state **cached_state);
|
2008-02-19 01:12:38 +08:00
|
|
|
struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
|
|
|
|
u64 start, int bits);
|
2008-01-25 05:13:08 +08:00
|
|
|
int extent_invalidatepage(struct extent_io_tree *tree,
|
|
|
|
struct page *page, unsigned long offset);
|
|
|
|
int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
|
|
|
|
get_extent_t *get_extent,
|
|
|
|
struct writeback_control *wbc);
|
2008-11-07 11:02:51 +08:00
|
|
|
int extent_write_locked_range(struct extent_io_tree *tree, struct inode *inode,
|
|
|
|
u64 start, u64 end, get_extent_t *get_extent,
|
|
|
|
int mode);
|
2008-01-25 05:13:08 +08:00
|
|
|
int extent_writepages(struct extent_io_tree *tree,
|
|
|
|
struct address_space *mapping,
|
|
|
|
get_extent_t *get_extent,
|
|
|
|
struct writeback_control *wbc);
|
2012-03-13 21:38:00 +08:00
|
|
|
int btree_write_cache_pages(struct address_space *mapping,
|
|
|
|
struct writeback_control *wbc);
|
2008-01-25 05:13:08 +08:00
|
|
|
int extent_readpages(struct extent_io_tree *tree,
|
|
|
|
struct address_space *mapping,
|
|
|
|
struct list_head *pages, unsigned nr_pages,
|
|
|
|
get_extent_t get_extent);
|
2009-01-22 03:39:14 +08:00
|
|
|
int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
|
|
|
__u64 start, __u64 len, get_extent_t *get_extent);
|
2008-01-25 05:13:08 +08:00
|
|
|
int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
|
|
|
|
int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
|
|
|
|
void set_page_extent_mapped(struct page *page);
|
|
|
|
|
|
|
|
struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
|
2010-08-07 01:21:20 +08:00
|
|
|
u64 start, unsigned long len);
|
2012-05-16 23:00:02 +08:00
|
|
|
struct extent_buffer *alloc_dummy_extent_buffer(u64 start, unsigned long len);
|
|
|
|
struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
|
2008-01-25 05:13:08 +08:00
|
|
|
struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
|
2011-04-21 07:08:01 +08:00
|
|
|
u64 start, unsigned long len);
|
2008-01-25 05:13:08 +08:00
|
|
|
void free_extent_buffer(struct extent_buffer *eb);
|
2012-03-10 05:01:49 +08:00
|
|
|
void free_extent_buffer_stale(struct extent_buffer *eb);
|
2011-06-10 20:06:53 +08:00
|
|
|
#define WAIT_NONE 0
|
|
|
|
#define WAIT_COMPLETE 1
|
|
|
|
#define WAIT_PAGE_LOCK 2
|
2008-01-25 05:13:08 +08:00
|
|
|
int read_extent_buffer_pages(struct extent_io_tree *tree,
|
2008-02-07 23:50:54 +08:00
|
|
|
struct extent_buffer *eb, u64 start, int wait,
|
2008-04-10 04:28:12 +08:00
|
|
|
get_extent_t *get_extent, int mirror_num);
|
2011-07-22 21:41:52 +08:00
|
|
|
unsigned long num_extent_pages(u64 start, u64 len);
|
|
|
|
struct page *extent_buffer_page(struct extent_buffer *eb, unsigned long i);
|
2008-01-25 05:13:08 +08:00
|
|
|
|
|
|
|
static inline void extent_buffer_get(struct extent_buffer *eb)
|
|
|
|
{
|
|
|
|
atomic_inc(&eb->refs);
|
|
|
|
}
|
|
|
|
|
|
|
|
int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
|
|
|
|
unsigned long start,
|
|
|
|
unsigned long len);
|
|
|
|
void read_extent_buffer(struct extent_buffer *eb, void *dst,
|
|
|
|
unsigned long start,
|
|
|
|
unsigned long len);
|
|
|
|
void write_extent_buffer(struct extent_buffer *eb, const void *src,
|
|
|
|
unsigned long start, unsigned long len);
|
|
|
|
void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
|
|
|
|
unsigned long dst_offset, unsigned long src_offset,
|
|
|
|
unsigned long len);
|
|
|
|
void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
|
|
|
|
unsigned long src_offset, unsigned long len);
|
|
|
|
void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
|
|
|
|
unsigned long src_offset, unsigned long len);
|
|
|
|
void memset_extent_buffer(struct extent_buffer *eb, char c,
|
|
|
|
unsigned long start, unsigned long len);
|
2012-03-01 21:56:26 +08:00
|
|
|
void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits);
|
2012-03-29 08:31:37 +08:00
|
|
|
void clear_extent_buffer_dirty(struct extent_buffer *eb);
|
2012-03-13 21:38:00 +08:00
|
|
|
int set_extent_buffer_dirty(struct extent_buffer *eb);
|
|
|
|
int set_extent_buffer_uptodate(struct extent_buffer *eb);
|
|
|
|
int clear_extent_buffer_uptodate(struct extent_buffer *eb);
|
|
|
|
int extent_buffer_uptodate(struct extent_buffer *eb);
|
2008-01-25 05:13:08 +08:00
|
|
|
int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
|
2011-07-20 00:04:14 +08:00
|
|
|
unsigned long min_len, char **map,
|
2008-01-25 05:13:08 +08:00
|
|
|
unsigned long *map_start,
|
2011-07-20 00:04:14 +08:00
|
|
|
unsigned long *map_len);
|
2008-04-10 04:28:12 +08:00
|
|
|
int extent_range_uptodate(struct extent_io_tree *tree,
|
|
|
|
u64 start, u64 end);
|
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 extent_clear_unlock_delalloc(struct inode *inode,
|
|
|
|
struct extent_io_tree *tree,
|
|
|
|
u64 start, u64 end, struct page *locked_page,
|
2009-10-08 23:27:10 +08:00
|
|
|
unsigned long op);
|
2010-11-22 11:02:55 +08:00
|
|
|
struct bio *
|
|
|
|
btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs,
|
|
|
|
gfp_t gfp_flags);
|
2011-07-22 21:41:52 +08:00
|
|
|
|
|
|
|
struct btrfs_mapping_tree;
|
|
|
|
|
|
|
|
int repair_io_failure(struct btrfs_mapping_tree *map_tree, u64 start,
|
|
|
|
u64 length, u64 logical, struct page *page,
|
|
|
|
int mirror_num);
|
2012-02-15 23:23:57 +08:00
|
|
|
int end_extent_writepage(struct page *page, int err, u64 start, u64 end);
|
2012-03-27 09:57:36 +08:00
|
|
|
int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,
|
|
|
|
int mirror_num);
|
2008-01-25 05:13:08 +08:00
|
|
|
#endif
|