Commit 4d61db4f87b527734ac0cc830dda8fcc4e2add2f
1 parent
af14a1ad79
Exists in
master
and in
4 other branches
UBIFS: use nicer 64-bit math
Instead of using do_div(), use better primitives from linux/math64.h. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Showing 6 changed files with 30 additions and 35 deletions Side-by-side Diff
fs/ubifs/budget.c
... | ... | @@ -32,7 +32,7 @@ |
32 | 32 | |
33 | 33 | #include "ubifs.h" |
34 | 34 | #include <linux/writeback.h> |
35 | -#include <asm/div64.h> | |
35 | +#include <linux/math64.h> | |
36 | 36 | |
37 | 37 | /* |
38 | 38 | * When pessimistic budget calculations say that there is no enough space, |
... | ... | @@ -258,8 +258,8 @@ |
258 | 258 | */ |
259 | 259 | int ubifs_calc_min_idx_lebs(struct ubifs_info *c) |
260 | 260 | { |
261 | - int ret; | |
262 | - uint64_t idx_size; | |
261 | + int idx_lebs, eff_leb_size = c->leb_size - c->max_idx_node_sz; | |
262 | + long long idx_size; | |
263 | 263 | |
264 | 264 | idx_size = c->old_idx_sz + c->budg_idx_growth + c->budg_uncommitted_idx; |
265 | 265 | |
266 | 266 | |
... | ... | @@ -271,18 +271,16 @@ |
271 | 271 | * pair, nor similarly the two variables for the new index size, so we |
272 | 272 | * have to do this costly 64-bit division on fast-path. |
273 | 273 | */ |
274 | - if (do_div(idx_size, c->leb_size - c->max_idx_node_sz)) | |
275 | - ret = idx_size + 1; | |
276 | - else | |
277 | - ret = idx_size; | |
274 | + idx_size += eff_leb_size - 1; | |
275 | + idx_lebs = div_u64(idx_size, eff_leb_size); | |
278 | 276 | /* |
279 | 277 | * The index head is not available for the in-the-gaps method, so add an |
280 | 278 | * extra LEB to compensate. |
281 | 279 | */ |
282 | - ret += 1; | |
283 | - if (ret < MIN_INDEX_LEBS) | |
284 | - ret = MIN_INDEX_LEBS; | |
285 | - return ret; | |
280 | + idx_lebs += 1; | |
281 | + if (idx_lebs < MIN_INDEX_LEBS) | |
282 | + idx_lebs = MIN_INDEX_LEBS; | |
283 | + return idx_lebs; | |
286 | 284 | } |
287 | 285 | |
288 | 286 | /** |
... | ... | @@ -718,7 +716,7 @@ |
718 | 716 | * Note, the calculation is pessimistic, which means that most of the time |
719 | 717 | * UBIFS reports less space than it actually has. |
720 | 718 | */ |
721 | -long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free) | |
719 | +long long ubifs_reported_space(const struct ubifs_info *c, long long free) | |
722 | 720 | { |
723 | 721 | int divisor, factor, f; |
724 | 722 | |
... | ... | @@ -740,8 +738,7 @@ |
740 | 738 | divisor = UBIFS_MAX_DATA_NODE_SZ; |
741 | 739 | divisor += (c->max_idx_node_sz * 3) / (f - 1); |
742 | 740 | free *= factor; |
743 | - do_div(free, divisor); | |
744 | - return free; | |
741 | + return div_u64(free, divisor); | |
745 | 742 | } |
746 | 743 | |
747 | 744 | /** |
fs/ubifs/debug.c
fs/ubifs/lpt.c
... | ... | @@ -43,8 +43,9 @@ |
43 | 43 | * mounted. |
44 | 44 | */ |
45 | 45 | |
46 | -#include <linux/crc16.h> | |
47 | 46 | #include "ubifs.h" |
47 | +#include <linux/crc16.h> | |
48 | +#include <linux/math64.h> | |
48 | 49 | |
49 | 50 | /** |
50 | 51 | * do_calc_lpt_geom - calculate sizes for the LPT area. |
51 | 52 | |
... | ... | @@ -135,15 +136,13 @@ |
135 | 136 | int ubifs_calc_lpt_geom(struct ubifs_info *c) |
136 | 137 | { |
137 | 138 | int lebs_needed; |
138 | - uint64_t sz; | |
139 | + long long sz; | |
139 | 140 | |
140 | 141 | do_calc_lpt_geom(c); |
141 | 142 | |
142 | 143 | /* Verify that lpt_lebs is big enough */ |
143 | 144 | sz = c->lpt_sz * 2; /* Must have at least 2 times the size */ |
144 | - sz += c->leb_size - 1; | |
145 | - do_div(sz, c->leb_size); | |
146 | - lebs_needed = sz; | |
145 | + lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size); | |
147 | 146 | if (lebs_needed > c->lpt_lebs) { |
148 | 147 | ubifs_err("too few LPT LEBs"); |
149 | 148 | return -EINVAL; |
... | ... | @@ -175,7 +174,7 @@ |
175 | 174 | int *big_lpt) |
176 | 175 | { |
177 | 176 | int i, lebs_needed; |
178 | - uint64_t sz; | |
177 | + long long sz; | |
179 | 178 | |
180 | 179 | /* Start by assuming the minimum number of LPT LEBs */ |
181 | 180 | c->lpt_lebs = UBIFS_MIN_LPT_LEBS; |
... | ... | @@ -202,9 +201,7 @@ |
202 | 201 | /* Now check there are enough LPT LEBs */ |
203 | 202 | for (i = 0; i < 64 ; i++) { |
204 | 203 | sz = c->lpt_sz * 4; /* Allow 4 times the size */ |
205 | - sz += c->leb_size - 1; | |
206 | - do_div(sz, c->leb_size); | |
207 | - lebs_needed = sz; | |
204 | + lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size); | |
208 | 205 | if (lebs_needed > c->lpt_lebs) { |
209 | 206 | /* Not enough LPT LEBs so try again with more */ |
210 | 207 | c->lpt_lebs = lebs_needed; |
fs/ubifs/sb.c
... | ... | @@ -28,6 +28,7 @@ |
28 | 28 | |
29 | 29 | #include "ubifs.h" |
30 | 30 | #include <linux/random.h> |
31 | +#include <linux/math64.h> | |
31 | 32 | |
32 | 33 | /* |
33 | 34 | * Default journal size in logical eraseblocks as a percent of total |
... | ... | @@ -80,7 +81,7 @@ |
80 | 81 | int err, tmp, jnl_lebs, log_lebs, max_buds, main_lebs, main_first; |
81 | 82 | int lpt_lebs, lpt_first, orph_lebs, big_lpt, ino_waste, sup_flags = 0; |
82 | 83 | int min_leb_cnt = UBIFS_MIN_LEB_CNT; |
83 | - uint64_t tmp64, main_bytes; | |
84 | + long long tmp64, main_bytes; | |
84 | 85 | __le64 tmp_le64; |
85 | 86 | |
86 | 87 | /* Some functions called from here depend on the @c->key_len filed */ |
... | ... | @@ -160,7 +161,7 @@ |
160 | 161 | if (!sup) |
161 | 162 | return -ENOMEM; |
162 | 163 | |
163 | - tmp64 = (uint64_t)max_buds * c->leb_size; | |
164 | + tmp64 = (long long)max_buds * c->leb_size; | |
164 | 165 | if (big_lpt) |
165 | 166 | sup_flags |= UBIFS_FLG_BIGLPT; |
166 | 167 | |
... | ... | @@ -187,9 +188,8 @@ |
187 | 188 | |
188 | 189 | generate_random_uuid(sup->uuid); |
189 | 190 | |
190 | - main_bytes = (uint64_t)main_lebs * c->leb_size; | |
191 | - tmp64 = main_bytes * DEFAULT_RP_PERCENT; | |
192 | - do_div(tmp64, 100); | |
191 | + main_bytes = (long long)main_lebs * c->leb_size; | |
192 | + tmp64 = div_u64(main_bytes * DEFAULT_RP_PERCENT, 100); | |
193 | 193 | if (tmp64 > DEFAULT_MAX_RP_SIZE) |
194 | 194 | tmp64 = DEFAULT_MAX_RP_SIZE; |
195 | 195 | sup->rp_size = cpu_to_le64(tmp64); |
fs/ubifs/super.c
... | ... | @@ -34,6 +34,7 @@ |
34 | 34 | #include <linux/parser.h> |
35 | 35 | #include <linux/seq_file.h> |
36 | 36 | #include <linux/mount.h> |
37 | +#include <linux/math64.h> | |
37 | 38 | #include "ubifs.h" |
38 | 39 | |
39 | 40 | /* |
... | ... | @@ -612,7 +613,7 @@ |
612 | 613 | static int init_constants_late(struct ubifs_info *c) |
613 | 614 | { |
614 | 615 | int tmp, err; |
615 | - uint64_t tmp64; | |
616 | + long long tmp64; | |
616 | 617 | |
617 | 618 | c->main_bytes = (long long)c->main_lebs * c->leb_size; |
618 | 619 | c->max_znode_sz = sizeof(struct ubifs_znode) + |
... | ... | @@ -639,9 +640,8 @@ |
639 | 640 | * Make sure that the log is large enough to fit reference nodes for |
640 | 641 | * all buds plus one reserved LEB. |
641 | 642 | */ |
642 | - tmp64 = c->max_bud_bytes; | |
643 | - tmp = do_div(tmp64, c->leb_size); | |
644 | - c->max_bud_cnt = tmp64 + !!tmp; | |
643 | + tmp64 = c->max_bud_bytes + c->leb_size - 1; | |
644 | + c->max_bud_cnt = div_u64(tmp64, c->leb_size); | |
645 | 645 | tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1); |
646 | 646 | tmp /= c->leb_size; |
647 | 647 | tmp += 1; |
... | ... | @@ -677,7 +677,7 @@ |
677 | 677 | * Consequently, if the journal is too small, UBIFS will treat it as |
678 | 678 | * always full. |
679 | 679 | */ |
680 | - tmp64 = (uint64_t)(c->jhead_cnt + 1) * c->leb_size + 1; | |
680 | + tmp64 = (long long)(c->jhead_cnt + 1) * c->leb_size + 1; | |
681 | 681 | if (c->bg_bud_bytes < tmp64) |
682 | 682 | c->bg_bud_bytes = tmp64; |
683 | 683 | if (c->max_bud_bytes < tmp64 + c->leb_size) |
... | ... | @@ -699,7 +699,7 @@ |
699 | 699 | * head is available. |
700 | 700 | */ |
701 | 701 | tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt + 1; |
702 | - tmp64 *= (uint64_t)c->leb_size - c->leb_overhead; | |
702 | + tmp64 *= (long long)c->leb_size - c->leb_overhead; | |
703 | 703 | tmp64 = ubifs_reported_space(c, tmp64); |
704 | 704 | c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT; |
705 | 705 |
fs/ubifs/ubifs.h
... | ... | @@ -1498,7 +1498,7 @@ |
1498 | 1498 | long long ubifs_get_free_space(struct ubifs_info *c); |
1499 | 1499 | int ubifs_calc_min_idx_lebs(struct ubifs_info *c); |
1500 | 1500 | void ubifs_convert_page_budget(struct ubifs_info *c); |
1501 | -long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free); | |
1501 | +long long ubifs_reported_space(const struct ubifs_info *c, long long free); | |
1502 | 1502 | long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs); |
1503 | 1503 | |
1504 | 1504 | /* find.c */ |