blob: 0e6a33e81e5fd8aa299f53528a939585d9aa680b [file] [log] [blame]
Zheng Liuc0677e62012-11-08 15:18:54 -05001/*
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 Liu654598b2012-11-08 21:57:20 -050014/*
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'o8e919d12013-02-27 14:54:37 -050023/*
Dmitry Monakhov921f2662013-03-10 21:01:03 -040024 * 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'o8e919d12013-02-27 14:54:37 -050030 * These flags live in the high bits of extent_status.es_pblk
31 */
Theodore Ts'o3be78c72013-08-16 21:22:41 -040032#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 Liufdc02122013-02-18 00:26:51 -050038
39#define EXTENT_STATUS_FLAGS (EXTENT_STATUS_WRITTEN | \
40 EXTENT_STATUS_UNWRITTEN | \
41 EXTENT_STATUS_DELAYED | \
42 EXTENT_STATUS_HOLE)
43
Theodore Ts'o3be78c72013-08-16 21:22:41 -040044#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 Liud3922a72013-07-01 08:12:37 -040052struct ext4_sb_info;
Zheng Liuadb23552013-03-10 21:13:05 -040053struct ext4_extent;
54
Zheng Liuc0677e62012-11-08 15:18:54 -050055struct extent_status {
56 struct rb_node rb_node;
Zheng Liu06b0c882013-02-18 00:26:51 -050057 ext4_lblk_t es_lblk; /* first logical block extent covers */
58 ext4_lblk_t es_len; /* length of extent in block */
Zheng Liufdc02122013-02-18 00:26:51 -050059 ext4_fsblk_t es_pblk; /* first physical block */
Zheng Liuc0677e62012-11-08 15:18:54 -050060};
61
62struct ext4_es_tree {
63 struct rb_root root;
64 struct extent_status *cache_es; /* recently accessed extent */
65};
66
Zheng Liueb68d0e2014-09-01 22:26:49 -040067struct ext4_es_stats {
Zheng Liueb68d0e2014-09-01 22:26:49 -040068 unsigned long es_stats_shrunk;
69 unsigned long es_stats_cache_hits;
70 unsigned long es_stats_cache_misses;
71 u64 es_stats_scan_time;
72 u64 es_stats_max_scan_time;
73 struct percpu_counter es_stats_all_cnt;
Zheng Liuedaa53c2014-11-25 11:45:37 -050074 struct percpu_counter es_stats_shk_cnt;
Zheng Liueb68d0e2014-09-01 22:26:49 -040075};
76
Zheng Liu654598b2012-11-08 21:57:20 -050077extern int __init ext4_init_es(void);
78extern void ext4_exit_es(void);
79extern void ext4_es_init_tree(struct ext4_es_tree *tree);
80
Zheng Liu06b0c882013-02-18 00:26:51 -050081extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
Zheng Liufdc02122013-02-18 00:26:51 -050082 ext4_lblk_t len, ext4_fsblk_t pblk,
Theodore Ts'o3be78c72013-08-16 21:22:41 -040083 unsigned int status);
Theodore Ts'o107a7bd2013-08-16 21:23:41 -040084extern void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk,
85 ext4_lblk_t len, ext4_fsblk_t pblk,
86 unsigned int status);
Zheng Liu06b0c882013-02-18 00:26:51 -050087extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
Zheng Liu654598b2012-11-08 21:57:20 -050088 ext4_lblk_t len);
Yan, Zhenge30b5dc2013-05-03 02:15:52 -040089extern void ext4_es_find_delayed_extent_range(struct inode *inode,
90 ext4_lblk_t lblk, ext4_lblk_t end,
Zheng Liube401362013-02-18 00:27:26 -050091 struct extent_status *es);
Zheng Liud100eef2013-02-18 00:29:59 -050092extern int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk,
93 struct extent_status *es);
Zheng Liu654598b2012-11-08 21:57:20 -050094
Zheng Liufdc02122013-02-18 00:26:51 -050095static inline int ext4_es_is_written(struct extent_status *es)
96{
Theodore Ts'o3be78c72013-08-16 21:22:41 -040097 return (es->es_pblk & ES_WRITTEN) != 0;
Zheng Liufdc02122013-02-18 00:26:51 -050098}
99
100static inline int ext4_es_is_unwritten(struct extent_status *es)
101{
Theodore Ts'o3be78c72013-08-16 21:22:41 -0400102 return (es->es_pblk & ES_UNWRITTEN) != 0;
Zheng Liufdc02122013-02-18 00:26:51 -0500103}
104
105static inline int ext4_es_is_delayed(struct extent_status *es)
106{
Theodore Ts'o3be78c72013-08-16 21:22:41 -0400107 return (es->es_pblk & ES_DELAYED) != 0;
Zheng Liufdc02122013-02-18 00:26:51 -0500108}
109
110static inline int ext4_es_is_hole(struct extent_status *es)
111{
Theodore Ts'o3be78c72013-08-16 21:22:41 -0400112 return (es->es_pblk & ES_HOLE) != 0;
Zheng Liufdc02122013-02-18 00:26:51 -0500113}
114
Theodore Ts'o3be78c72013-08-16 21:22:41 -0400115static inline unsigned int ext4_es_status(struct extent_status *es)
Zheng Liufdc02122013-02-18 00:26:51 -0500116{
Theodore Ts'o3be78c72013-08-16 21:22:41 -0400117 return es->es_pblk >> ES_SHIFT;
Zheng Liufdc02122013-02-18 00:26:51 -0500118}
119
120static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es)
121{
Theodore Ts'o3be78c72013-08-16 21:22:41 -0400122 return es->es_pblk & ~ES_MASK;
Zheng Liufdc02122013-02-18 00:26:51 -0500123}
124
125static inline void ext4_es_store_pblock(struct extent_status *es,
126 ext4_fsblk_t pb)
127{
128 ext4_fsblk_t block;
129
Theodore Ts'o3be78c72013-08-16 21:22:41 -0400130 block = (pb & ~ES_MASK) | (es->es_pblk & ES_MASK);
Zheng Liufdc02122013-02-18 00:26:51 -0500131 es->es_pblk = block;
132}
133
134static inline void ext4_es_store_status(struct extent_status *es,
Theodore Ts'o3be78c72013-08-16 21:22:41 -0400135 unsigned int status)
Zheng Liufdc02122013-02-18 00:26:51 -0500136{
Theodore Ts'o3be78c72013-08-16 21:22:41 -0400137 es->es_pblk = (((ext4_fsblk_t)
138 (status & EXTENT_STATUS_FLAGS) << ES_SHIFT) |
139 (es->es_pblk & ~ES_MASK));
Zheng Liufdc02122013-02-18 00:26:51 -0500140}
141
Theodore Ts'o9a6633b2014-02-19 20:15:15 -0500142static inline void ext4_es_store_pblock_status(struct extent_status *es,
143 ext4_fsblk_t pb,
144 unsigned int status)
145{
146 es->es_pblk = (((ext4_fsblk_t)
147 (status & EXTENT_STATUS_FLAGS) << ES_SHIFT) |
148 (pb & ~ES_MASK));
149}
150
Zheng Liueb68d0e2014-09-01 22:26:49 -0400151extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi);
Zheng Liud3922a72013-07-01 08:12:37 -0400152extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi);
Zheng Liuedaa53c2014-11-25 11:45:37 -0500153extern void ext4_es_list_add(struct inode *inode);
154extern void ext4_es_list_del(struct inode *inode);
Zheng Liu74cd15c2013-02-18 00:32:55 -0500155
Zheng Liuc0677e62012-11-08 15:18:54 -0500156#endif /* _EXT4_EXTENTS_STATUS_H */