Rebase to reflect accepted patches and snapshot
[ext4-patch-queue.git] / use-uint-for-es_status
blobb041ccb9ea8318041c5d6e6c4e25184a9d614cd7
1 ext4: use unsigned int for es_status values
3 Don't use an unsigned long long for the es_status flags; this requires
4 that we pass 64-bit values around which is painful on 32-bit systems.
5 Instead pass the extent status flags around using the low 4 bits of an
6 unsigned int, and shift them into place when we are reading or writing
7 es_pblk.
9 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
11 ---
12  fs/ext4/extents_status.c    |  6 +++---
13  fs/ext4/extents_status.h    | 47 ++++++++++++++++++++++++++-------------------
14  fs/ext4/inode.c             |  6 +++---
15  include/trace/events/ext4.h | 14 +++++++-------
16  4 files changed, 40 insertions(+), 33 deletions(-)
18 diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
19 index ee018d5..7358fb3 100644
20 --- a/fs/ext4/extents_status.c
21 +++ b/fs/ext4/extents_status.c
22 @@ -261,7 +261,7 @@ void ext4_es_find_delayed_extent_range(struct inode *inode,
23         if (tree->cache_es) {
24                 es1 = tree->cache_es;
25                 if (in_range(lblk, es1->es_lblk, es1->es_len)) {
26 -                       es_debug("%u cached by [%u/%u) %llu %llx\n",
27 +                       es_debug("%u cached by [%u/%u) %llu %x\n",
28                                  lblk, es1->es_lblk, es1->es_len,
29                                  ext4_es_pblock(es1), ext4_es_status(es1));
30                         goto out;
31 @@ -641,13 +641,13 @@ out:
32   */
33  int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
34                           ext4_lblk_t len, ext4_fsblk_t pblk,
35 -                         unsigned long long status)
36 +                         unsigned int status)
37  {
38         struct extent_status newes;
39         ext4_lblk_t end = lblk + len - 1;
40         int err = 0;
42 -       es_debug("add [%u/%u) %llu %llx to extent status tree of inode %lu\n",
43 +       es_debug("add [%u/%u) %llu %x to extent status tree of inode %lu\n",
44                  lblk, len, pblk, status, inode->i_ino);
46         if (!len)
47 diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h
48 index e936730..ae1be58 100644
49 --- a/fs/ext4/extents_status.h
50 +++ b/fs/ext4/extents_status.h
51 @@ -29,16 +29,26 @@
52  /*
53   * These flags live in the high bits of extent_status.es_pblk
54   */
55 -#define EXTENT_STATUS_WRITTEN  (1ULL << 63)
56 -#define EXTENT_STATUS_UNWRITTEN (1ULL << 62)
57 -#define EXTENT_STATUS_DELAYED  (1ULL << 61)
58 -#define EXTENT_STATUS_HOLE     (1ULL << 60)
59 +#define ES_SHIFT       60
61 +#define EXTENT_STATUS_WRITTEN  (1 << 3)
62 +#define EXTENT_STATUS_UNWRITTEN (1 << 2)
63 +#define EXTENT_STATUS_DELAYED  (1 << 1)
64 +#define EXTENT_STATUS_HOLE     (1 << 0)
66  #define EXTENT_STATUS_FLAGS    (EXTENT_STATUS_WRITTEN | \
67                                  EXTENT_STATUS_UNWRITTEN | \
68                                  EXTENT_STATUS_DELAYED | \
69                                  EXTENT_STATUS_HOLE)
71 +#define ES_WRITTEN             (1ULL << 63)
72 +#define ES_UNWRITTEN           (1ULL << 62)
73 +#define ES_DELAYED             (1ULL << 61)
74 +#define ES_HOLE                        (1ULL << 60)
76 +#define ES_MASK                        (ES_WRITTEN | ES_UNWRITTEN | \
77 +                                ES_DELAYED | ES_HOLE)
79  struct ext4_sb_info;
80  struct ext4_extent;
82 @@ -60,7 +70,7 @@ extern void ext4_es_init_tree(struct ext4_es_tree *tree);
84  extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
85                                  ext4_lblk_t len, ext4_fsblk_t pblk,
86 -                                unsigned long long status);
87 +                                unsigned int status);
88  extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
89                                  ext4_lblk_t len);
90  extern void ext4_es_find_delayed_extent_range(struct inode *inode,
91 @@ -72,32 +82,32 @@ extern int ext4_es_zeroout(struct inode *inode, struct ext4_extent *ex);
93  static inline int ext4_es_is_written(struct extent_status *es)
94  {
95 -       return (es->es_pblk & EXTENT_STATUS_WRITTEN) != 0;
96 +       return (es->es_pblk & ES_WRITTEN) != 0;
97  }
99  static inline int ext4_es_is_unwritten(struct extent_status *es)
101 -       return (es->es_pblk & EXTENT_STATUS_UNWRITTEN) != 0;
102 +       return (es->es_pblk & ES_UNWRITTEN) != 0;
105  static inline int ext4_es_is_delayed(struct extent_status *es)
107 -       return (es->es_pblk & EXTENT_STATUS_DELAYED) != 0;
108 +       return (es->es_pblk & ES_DELAYED) != 0;
111  static inline int ext4_es_is_hole(struct extent_status *es)
113 -       return (es->es_pblk & EXTENT_STATUS_HOLE) != 0;
114 +       return (es->es_pblk & ES_HOLE) != 0;
117 -static inline ext4_fsblk_t ext4_es_status(struct extent_status *es)
118 +static inline unsigned int ext4_es_status(struct extent_status *es)
120 -       return (es->es_pblk & EXTENT_STATUS_FLAGS);
121 +       return es->es_pblk >> ES_SHIFT;
124  static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es)
126 -       return (es->es_pblk & ~EXTENT_STATUS_FLAGS);
127 +       return es->es_pblk & ~ES_MASK;
130  static inline void ext4_es_store_pblock(struct extent_status *es,
131 @@ -105,19 +115,16 @@ static inline void ext4_es_store_pblock(struct extent_status *es,
133         ext4_fsblk_t block;
135 -       block = (pb & ~EXTENT_STATUS_FLAGS) |
136 -               (es->es_pblk & EXTENT_STATUS_FLAGS);
137 +       block = (pb & ~ES_MASK) | (es->es_pblk & ES_MASK);
138         es->es_pblk = block;
141  static inline void ext4_es_store_status(struct extent_status *es,
142 -                                       unsigned long long status)
143 +                                       unsigned int status)
145 -       ext4_fsblk_t block;
147 -       block = (status & EXTENT_STATUS_FLAGS) |
148 -               (es->es_pblk & ~EXTENT_STATUS_FLAGS);
149 -       es->es_pblk = block;
150 +       es->es_pblk = (((ext4_fsblk_t)
151 +                       (status & EXTENT_STATUS_FLAGS) << ES_SHIFT) |
152 +                      (es->es_pblk & ~ES_MASK));
155  extern void ext4_es_register_shrinker(struct ext4_sb_info *sbi);
156 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
157 index 19a1643..3cfbcaa 100644
158 --- a/fs/ext4/inode.c
159 +++ b/fs/ext4/inode.c
160 @@ -554,7 +554,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
161         }
162         if (retval > 0) {
163                 int ret;
164 -               unsigned long long status;
165 +               unsigned int status;
167  #ifdef ES_AGGRESSIVE_TEST
168                 if (retval != map->m_len) {
169 @@ -655,7 +655,7 @@ found:
171         if (retval > 0) {
172                 int ret;
173 -               unsigned long long status;
174 +               unsigned int status;
176  #ifdef ES_AGGRESSIVE_TEST
177                 if (retval != map->m_len) {
178 @@ -1638,7 +1638,7 @@ add_delayed:
179                 set_buffer_delay(bh);
180         } else if (retval > 0) {
181                 int ret;
182 -               unsigned long long status;
183 +               unsigned int status;
185  #ifdef ES_AGGRESSIVE_TEST
186                 if (retval != map->m_len) {
187 diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
188 index 2068db2..47a355b 100644
189 --- a/include/trace/events/ext4.h
190 +++ b/include/trace/events/ext4.h
191 @@ -64,10 +64,10 @@ struct extent_status;
192         { EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER, "LAST_CLUSTER" })
194  #define show_extent_status(status) __print_flags(status, "",   \
195 -       { (1 << 3),     "W" },                                  \
196 -       { (1 << 2),     "U" },                                  \
197 -       { (1 << 1),     "D" },                                  \
198 -       { (1 << 0),     "H" })
199 +       { EXTENT_STATUS_WRITTEN,        "W" },                  \
200 +       { EXTENT_STATUS_UNWRITTEN,      "U" },                  \
201 +       { EXTENT_STATUS_DELAYED,        "D" },                  \
202 +       { EXTENT_STATUS_HOLE,           "H" })
205  TRACE_EVENT(ext4_free_inode,
206 @@ -2212,7 +2212,7 @@ TRACE_EVENT(ext4_es_insert_extent,
207                 __entry->lblk   = es->es_lblk;
208                 __entry->len    = es->es_len;
209                 __entry->pblk   = ext4_es_pblock(es);
210 -               __entry->status = ext4_es_status(es) >> 60;
211 +               __entry->status = ext4_es_status(es);
212         ),
214         TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s",
215 @@ -2289,7 +2289,7 @@ TRACE_EVENT(ext4_es_find_delayed_extent_range_exit,
216                 __entry->lblk   = es->es_lblk;
217                 __entry->len    = es->es_len;
218                 __entry->pblk   = ext4_es_pblock(es);
219 -               __entry->status = ext4_es_status(es) >> 60;
220 +               __entry->status = ext4_es_status(es);
221         ),
223         TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s",
224 @@ -2343,7 +2343,7 @@ TRACE_EVENT(ext4_es_lookup_extent_exit,
225                 __entry->lblk   = es->es_lblk;
226                 __entry->len    = es->es_len;
227                 __entry->pblk   = ext4_es_pblock(es);
228 -               __entry->status = ext4_es_status(es) >> 60;
229 +               __entry->status = ext4_es_status(es);
230                 __entry->found  = found;
231         ),