Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 1 | /* |
| 2 | * fs/ext4/extents_status.h |
| 3 | * |
| 4 | * Written by Yongqiang Yang <xiaoqiangnk@gmail.com> |
| 5 | * Modified by |
| 6 | * Allison Henderson <achender@linux.vnet.ibm.com> |
| 7 | * Zheng Liu <wenqing.lz@taobao.com> |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #ifndef _EXT4_EXTENTS_STATUS_H |
| 12 | #define _EXT4_EXTENTS_STATUS_H |
| 13 | |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 14 | /* |
| 15 | * Turn on ES_DEBUG__ to get lots of info about extent status operations. |
| 16 | */ |
| 17 | #ifdef ES_DEBUG__ |
| 18 | #define es_debug(fmt, ...) printk(fmt, ##__VA_ARGS__) |
| 19 | #else |
| 20 | #define es_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__) |
| 21 | #endif |
| 22 | |
Theodore Ts'o | 8e919d1 | 2013-02-27 14:54:37 -0500 | [diff] [blame] | 23 | /* |
Dmitry Monakhov | 921f266 | 2013-03-10 21:01:03 -0400 | [diff] [blame] | 24 | * With ES_AGGRESSIVE_TEST defined, the result of es caching will be |
| 25 | * checked with old map_block's result. |
| 26 | */ |
| 27 | #define ES_AGGRESSIVE_TEST__ |
| 28 | |
| 29 | /* |
Theodore Ts'o | 8e919d1 | 2013-02-27 14:54:37 -0500 | [diff] [blame] | 30 | * These flags live in the high bits of extent_status.es_pblk |
| 31 | */ |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 32 | #define ES_SHIFT 60 |
| 33 | |
| 34 | #define EXTENT_STATUS_WRITTEN (1 << 3) |
| 35 | #define EXTENT_STATUS_UNWRITTEN (1 << 2) |
| 36 | #define EXTENT_STATUS_DELAYED (1 << 1) |
| 37 | #define EXTENT_STATUS_HOLE (1 << 0) |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 38 | |
| 39 | #define EXTENT_STATUS_FLAGS (EXTENT_STATUS_WRITTEN | \ |
| 40 | EXTENT_STATUS_UNWRITTEN | \ |
| 41 | EXTENT_STATUS_DELAYED | \ |
| 42 | EXTENT_STATUS_HOLE) |
| 43 | |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 44 | #define ES_WRITTEN (1ULL << 63) |
| 45 | #define ES_UNWRITTEN (1ULL << 62) |
| 46 | #define ES_DELAYED (1ULL << 61) |
| 47 | #define ES_HOLE (1ULL << 60) |
| 48 | |
| 49 | #define ES_MASK (ES_WRITTEN | ES_UNWRITTEN | \ |
| 50 | ES_DELAYED | ES_HOLE) |
| 51 | |
Zheng Liu | d3922a7 | 2013-07-01 08:12:37 -0400 | [diff] [blame] | 52 | struct ext4_sb_info; |
Zheng Liu | adb2355 | 2013-03-10 21:13:05 -0400 | [diff] [blame] | 53 | struct ext4_extent; |
| 54 | |
Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 55 | struct extent_status { |
| 56 | struct rb_node rb_node; |
Zheng Liu | 06b0c88 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 57 | ext4_lblk_t es_lblk; /* first logical block extent covers */ |
| 58 | ext4_lblk_t es_len; /* length of extent in block */ |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 59 | ext4_fsblk_t es_pblk; /* first physical block */ |
Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | struct ext4_es_tree { |
| 63 | struct rb_root root; |
| 64 | struct extent_status *cache_es; /* recently accessed extent */ |
| 65 | }; |
| 66 | |
Zheng Liu | eb68d0e | 2014-09-01 22:26:49 -0400 | [diff] [blame] | 67 | struct ext4_es_stats { |
| 68 | unsigned long es_stats_last_sorted; |
| 69 | unsigned long es_stats_shrunk; |
| 70 | unsigned long es_stats_cache_hits; |
| 71 | unsigned long es_stats_cache_misses; |
| 72 | u64 es_stats_scan_time; |
| 73 | u64 es_stats_max_scan_time; |
| 74 | struct percpu_counter es_stats_all_cnt; |
| 75 | struct percpu_counter es_stats_lru_cnt; |
| 76 | }; |
| 77 | |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 78 | extern int __init ext4_init_es(void); |
| 79 | extern void ext4_exit_es(void); |
| 80 | extern void ext4_es_init_tree(struct ext4_es_tree *tree); |
| 81 | |
Zheng Liu | 06b0c88 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 82 | extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 83 | ext4_lblk_t len, ext4_fsblk_t pblk, |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 84 | unsigned int status); |
Theodore Ts'o | 107a7bd | 2013-08-16 21:23:41 -0400 | [diff] [blame] | 85 | extern void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk, |
| 86 | ext4_lblk_t len, ext4_fsblk_t pblk, |
| 87 | unsigned int status); |
Zheng Liu | 06b0c88 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 88 | extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 89 | ext4_lblk_t len); |
Yan, Zheng | e30b5dc | 2013-05-03 02:15:52 -0400 | [diff] [blame] | 90 | extern void ext4_es_find_delayed_extent_range(struct inode *inode, |
| 91 | ext4_lblk_t lblk, ext4_lblk_t end, |
Zheng Liu | be40136 | 2013-02-18 00:27:26 -0500 | [diff] [blame] | 92 | struct extent_status *es); |
Zheng Liu | d100eef | 2013-02-18 00:29:59 -0500 | [diff] [blame] | 93 | extern int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk, |
| 94 | struct extent_status *es); |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 95 | |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 96 | static inline int ext4_es_is_written(struct extent_status *es) |
| 97 | { |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 98 | return (es->es_pblk & ES_WRITTEN) != 0; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static inline int ext4_es_is_unwritten(struct extent_status *es) |
| 102 | { |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 103 | return (es->es_pblk & ES_UNWRITTEN) != 0; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static inline int ext4_es_is_delayed(struct extent_status *es) |
| 107 | { |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 108 | return (es->es_pblk & ES_DELAYED) != 0; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static inline int ext4_es_is_hole(struct extent_status *es) |
| 112 | { |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 113 | return (es->es_pblk & ES_HOLE) != 0; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 116 | static inline unsigned int ext4_es_status(struct extent_status *es) |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 117 | { |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 118 | return es->es_pblk >> ES_SHIFT; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es) |
| 122 | { |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 123 | return es->es_pblk & ~ES_MASK; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static inline void ext4_es_store_pblock(struct extent_status *es, |
| 127 | ext4_fsblk_t pb) |
| 128 | { |
| 129 | ext4_fsblk_t block; |
| 130 | |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 131 | block = (pb & ~ES_MASK) | (es->es_pblk & ES_MASK); |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 132 | es->es_pblk = block; |
| 133 | } |
| 134 | |
| 135 | static inline void ext4_es_store_status(struct extent_status *es, |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 136 | unsigned int status) |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 137 | { |
Theodore Ts'o | 3be78c7 | 2013-08-16 21:22:41 -0400 | [diff] [blame] | 138 | es->es_pblk = (((ext4_fsblk_t) |
| 139 | (status & EXTENT_STATUS_FLAGS) << ES_SHIFT) | |
| 140 | (es->es_pblk & ~ES_MASK)); |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 141 | } |
| 142 | |
Theodore Ts'o | 9a6633b | 2014-02-19 20:15:15 -0500 | [diff] [blame] | 143 | static inline void ext4_es_store_pblock_status(struct extent_status *es, |
| 144 | ext4_fsblk_t pb, |
| 145 | unsigned int status) |
| 146 | { |
| 147 | es->es_pblk = (((ext4_fsblk_t) |
| 148 | (status & EXTENT_STATUS_FLAGS) << ES_SHIFT) | |
| 149 | (pb & ~ES_MASK)); |
| 150 | } |
| 151 | |
Zheng Liu | eb68d0e | 2014-09-01 22:26:49 -0400 | [diff] [blame] | 152 | extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi); |
Zheng Liu | d3922a7 | 2013-07-01 08:12:37 -0400 | [diff] [blame] | 153 | extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi); |
Zheng Liu | 74cd15c | 2013-02-18 00:32:55 -0500 | [diff] [blame] | 154 | extern void ext4_es_lru_add(struct inode *inode); |
| 155 | extern void ext4_es_lru_del(struct inode *inode); |
| 156 | |
Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 157 | #endif /* _EXT4_EXTENTS_STATUS_H */ |