Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+30 -35
+11 -14
fs/ubifs/budget.c
··· 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 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 ··· 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 /** ··· 716 718 * Note, the calculation is pessimistic, which means that most of the time 717 719 * UBIFS reports less space than it actually has. 718 720 */ 719 - long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free) 721 + long long ubifs_reported_space(const struct ubifs_info *c, long long free) 720 722 { 721 723 int divisor, factor, f; 722 724 ··· 738 740 divisor = UBIFS_MAX_DATA_NODE_SZ; 739 741 divisor += (c->max_idx_node_sz * 3) / (f - 1); 740 742 free *= factor; 741 - do_div(free, divisor); 742 - return free; 743 + return div_u64(free, divisor); 743 744 } 744 745 745 746 /**
+1
fs/ubifs/debug.c
··· 33 33 #include <linux/module.h> 34 34 #include <linux/moduleparam.h> 35 35 #include <linux/debugfs.h> 36 + #include <linux/math64.h> 36 37 37 38 #ifdef CONFIG_UBIFS_FS_DEBUG 38 39
+6 -9
fs/ubifs/lpt.c
··· 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. ··· 136 135 int ubifs_calc_lpt_geom(struct ubifs_info *c) 137 136 { 138 137 int lebs_needed; 139 - uint64_t sz; 138 + long long sz; 140 139 141 140 do_calc_lpt_geom(c); 142 141 143 142 /* Verify that lpt_lebs is big enough */ 144 143 sz = c->lpt_sz * 2; /* Must have at least 2 times the size */ 145 - sz += c->leb_size - 1; 146 - do_div(sz, c->leb_size); 147 - lebs_needed = sz; 144 + lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size); 148 145 if (lebs_needed > c->lpt_lebs) { 149 146 ubifs_err("too few LPT LEBs"); 150 147 return -EINVAL; ··· 174 175 int *big_lpt) 175 176 { 176 177 int i, lebs_needed; 177 - uint64_t sz; 178 + long long sz; 178 179 179 180 /* Start by assuming the minimum number of LPT LEBs */ 180 181 c->lpt_lebs = UBIFS_MIN_LPT_LEBS; ··· 201 202 /* Now check there are enough LPT LEBs */ 202 203 for (i = 0; i < 64 ; i++) { 203 204 sz = c->lpt_sz * 4; /* Allow 4 times the size */ 204 - sz += c->leb_size - 1; 205 - do_div(sz, c->leb_size); 206 - lebs_needed = sz; 205 + lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size); 207 206 if (lebs_needed > c->lpt_lebs) { 208 207 /* Not enough LPT LEBs so try again with more */ 209 208 c->lpt_lebs = lebs_needed;
+5 -5
fs/ubifs/sb.c
··· 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 ··· 81 80 int err, tmp, jnl_lebs, log_lebs, max_buds, main_lebs, main_first; 82 81 int lpt_lebs, lpt_first, orph_lebs, big_lpt, ino_waste, sup_flags = 0; 83 82 int min_leb_cnt = UBIFS_MIN_LEB_CNT; 84 - uint64_t tmp64, main_bytes; 83 + long long tmp64, main_bytes; 85 84 __le64 tmp_le64; 86 85 87 86 /* Some functions called from here depend on the @c->key_len filed */ ··· 161 160 if (!sup) 162 161 return -ENOMEM; 163 162 164 - tmp64 = (uint64_t)max_buds * c->leb_size; 163 + tmp64 = (long long)max_buds * c->leb_size; 165 164 if (big_lpt) 166 165 sup_flags |= UBIFS_FLG_BIGLPT; 167 166 ··· 188 187 189 188 generate_random_uuid(sup->uuid); 190 189 191 - main_bytes = (uint64_t)main_lebs * c->leb_size; 192 - tmp64 = main_bytes * DEFAULT_RP_PERCENT; 193 - do_div(tmp64, 100); 190 + main_bytes = (long long)main_lebs * c->leb_size; 191 + tmp64 = div_u64(main_bytes * DEFAULT_RP_PERCENT, 100); 194 192 if (tmp64 > DEFAULT_MAX_RP_SIZE) 195 193 tmp64 = DEFAULT_MAX_RP_SIZE; 196 194 sup->rp_size = cpu_to_le64(tmp64);
+6 -6
fs/ubifs/super.c
··· 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 /* ··· 613 612 static int init_constants_late(struct ubifs_info *c) 614 613 { 615 614 int tmp, err; 616 - uint64_t tmp64; 615 + long long tmp64; 617 616 618 617 c->main_bytes = (long long)c->main_lebs * c->leb_size; 619 618 c->max_znode_sz = sizeof(struct ubifs_znode) + ··· 640 639 * Make sure that the log is large enough to fit reference nodes for 641 640 * all buds plus one reserved LEB. 642 641 */ 643 - tmp64 = c->max_bud_bytes; 644 - tmp = do_div(tmp64, c->leb_size); 645 - c->max_bud_cnt = tmp64 + !!tmp; 642 + tmp64 = c->max_bud_bytes + c->leb_size - 1; 643 + c->max_bud_cnt = div_u64(tmp64, c->leb_size); 646 644 tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1); 647 645 tmp /= c->leb_size; 648 646 tmp += 1; ··· 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 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
+1 -1
fs/ubifs/ubifs.h
··· 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 */