Skip to content

Commit fb1cd01

Browse files
Artem BityutskiyArtem Bityutskiy
authored andcommitted
UBIFS: introduce a helpful variable
This patch introduces a helpful @c->idx_leb_size variable. The patch also fixes some spelling issues and makes comments use "LEB" instead of "eraseblock", which is more correct. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent c9927c3 commit fb1cd01

4 files changed

Lines changed: 23 additions & 21 deletions

File tree

‎fs/ubifs/budget.c‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,29 +194,26 @@ static int make_free_space(struct ubifs_info *c)
194194
}
195195

196196
/**
197-
* ubifs_calc_min_idx_lebs - calculate amount of eraseblocks for the index.
197+
* ubifs_calc_min_idx_lebs - calculate amount of LEBs for the index.
198198
* @c: UBIFS file-system description object
199199
*
200-
* This function calculates and returns the number of eraseblocks which should
201-
* be kept for index usage.
200+
* This function calculates and returns the number of LEBs which should be kept
201+
* for index usage.
202202
*/
203203
int ubifs_calc_min_idx_lebs(struct ubifs_info *c)
204204
{
205-
int idx_lebs, eff_leb_size = c->leb_size - c->max_idx_node_sz;
205+
int idx_lebs;
206206
long long idx_size;
207207

208208
idx_size = c->old_idx_sz + c->budg_idx_growth + c->budg_uncommitted_idx;
209-
210209
/* And make sure we have thrice the index size of space reserved */
211-
idx_size = idx_size + (idx_size << 1);
212-
210+
idx_size += idx_size << 1;
213211
/*
214212
* We do not maintain 'old_idx_size' as 'old_idx_lebs'/'old_idx_bytes'
215213
* pair, nor similarly the two variables for the new index size, so we
216214
* have to do this costly 64-bit division on fast-path.
217215
*/
218-
idx_size += eff_leb_size - 1;
219-
idx_lebs = div_u64(idx_size, eff_leb_size);
216+
idx_lebs = div_u64(idx_size + c->idx_leb_size - 1, c->idx_leb_size);
220217
/*
221218
* The index head is not available for the in-the-gaps method, so add an
222219
* extra LEB to compensate.
@@ -310,15 +307,15 @@ static int can_use_rp(struct ubifs_info *c)
310307
* do_budget_space - reserve flash space for index and data growth.
311308
* @c: UBIFS file-system description object
312309
*
313-
* This function makes sure UBIFS has enough free eraseblocks for index growth
314-
* and data.
310+
* This function makes sure UBIFS has enough free LEBs for index growth and
311+
* data.
315312
*
316313
* When budgeting index space, UBIFS reserves thrice as many LEBs as the index
317314
* would take if it was consolidated and written to the flash. This guarantees
318315
* that the "in-the-gaps" commit method always succeeds and UBIFS will always
319316
* be able to commit dirty index. So this function basically adds amount of
320317
* budgeted index space to the size of the current index, multiplies this by 3,
321-
* and makes sure this does not exceed the amount of free eraseblocks.
318+
* and makes sure this does not exceed the amount of free LEBs.
322319
*
323320
* Notes about @c->min_idx_lebs and @c->lst.idx_lebs variables:
324321
* o @c->lst.idx_lebs is the number of LEBs the index currently uses. It might
@@ -695,12 +692,12 @@ long long ubifs_reported_space(const struct ubifs_info *c, long long free)
695692
* This function calculates amount of free space to report to user-space.
696693
*
697694
* Because UBIFS may introduce substantial overhead (the index, node headers,
698-
* alignment, wastage at the end of eraseblocks, etc), it cannot report real
699-
* amount of free flash space it has (well, because not all dirty space is
700-
* reclaimable, UBIFS does not actually know the real amount). If UBIFS did so,
701-
* it would bread user expectations about what free space is. Users seem to
702-
* accustomed to assume that if the file-system reports N bytes of free space,
703-
* they would be able to fit a file of N bytes to the FS. This almost works for
695+
* alignment, wastage at the end of LEBs, etc), it cannot report real amount of
696+
* free flash space it has (well, because not all dirty space is reclaimable,
697+
* UBIFS does not actually know the real amount). If UBIFS did so, it would
698+
* bread user expectations about what free space is. Users seem to accustomed
699+
* to assume that if the file-system reports N bytes of free space, they would
700+
* be able to fit a file of N bytes to the FS. This almost works for
704701
* traditional file-systems, because they have way less overhead than UBIFS.
705702
* So, to keep users happy, UBIFS tries to take the overhead into account.
706703
*/

‎fs/ubifs/sb.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ int ubifs_read_superblock(struct ubifs_info *c)
623623
c->main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS;
624624
c->main_lebs -= c->log_lebs + c->lpt_lebs + c->orph_lebs;
625625
c->main_first = c->leb_cnt - c->main_lebs;
626-
c->report_rp_size = ubifs_reported_space(c, c->rp_size);
627626

628627
err = validate_sb(c, sup);
629628
out:

‎fs/ubifs/super.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ static int init_constants_sb(struct ubifs_info *c)
700700
if (err)
701701
return err;
702702

703+
/* Initialize effective LEB size used in budgeting calculations */
704+
c->idx_leb_size = c->leb_size - c->max_idx_node_sz;
703705
return 0;
704706
}
705707

@@ -716,6 +718,7 @@ static void init_constants_master(struct ubifs_info *c)
716718
long long tmp64;
717719

718720
c->min_idx_lebs = ubifs_calc_min_idx_lebs(c);
721+
c->report_rp_size = ubifs_reported_space(c, c->rp_size);
719722

720723
/*
721724
* Calculate total amount of FS blocks. This number is not used

‎fs/ubifs/ubifs.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ struct ubifs_debug_info;
10151015
* @min_io_shift: number of bits in @min_io_size minus one
10161016
* @leb_size: logical eraseblock size in bytes
10171017
* @half_leb_size: half LEB size
1018+
* @idx_leb_size: how many bytes of an LEB are effectively available when it is
1019+
* used to store indexing nodes (@leb_size - @max_idx_node_sz)
10181020
* @leb_cnt: count of logical eraseblocks
10191021
* @max_leb_cnt: maximum count of logical eraseblocks
10201022
* @old_leb_cnt: count of logical eraseblocks before re-size
@@ -1132,8 +1134,8 @@ struct ubifs_debug_info;
11321134
* previous commit start
11331135
* @uncat_list: list of un-categorized LEBs
11341136
* @empty_list: list of empty LEBs
1135-
* @freeable_list: list of freeable non-index LEBs (free + dirty == leb_size)
1136-
* @frdi_idx_list: list of freeable index LEBs (free + dirty == leb_size)
1137+
* @freeable_list: list of freeable non-index LEBs (free + dirty == @leb_size)
1138+
* @frdi_idx_list: list of freeable index LEBs (free + dirty == @leb_size)
11371139
* @freeable_cnt: number of freeable LEBs in @freeable_list
11381140
*
11391141
* @ltab_lnum: LEB number of LPT's own lprops table
@@ -1253,6 +1255,7 @@ struct ubifs_info {
12531255
int min_io_shift;
12541256
int leb_size;
12551257
int half_leb_size;
1258+
int idx_leb_size;
12561259
int leb_cnt;
12571260
int max_leb_cnt;
12581261
int old_leb_cnt;

0 commit comments

Comments
 (0)