Skip to content

Commit b137545

Browse files
Artem BityutskiyArtem Bityutskiy
authored andcommitted
UBIFS: introduce a separate structure for budgeting info
This patch separates out all the budgeting-related information from 'struct ubifs_info' to 'struct ubifs_budg_info'. This way the code looks a bit cleaner. However, the main driver for this is that we want to save budgeting information and print it later, so a separate data structure for this is helpful. This patch is a preparation for the further debugging output improvements. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent cc64f77 commit b137545

11 files changed

Lines changed: 135 additions & 130 deletions

File tree

‎fs/ubifs/budget.c‎

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static long long get_liability(struct ubifs_info *c)
106106
long long liab;
107107

108108
spin_lock(&c->space_lock);
109-
liab = c->budg_idx_growth + c->budg_data_growth + c->budg_dd_growth;
109+
liab = c->bi.idx_growth + c->bi.data_growth + c->bi.dd_growth;
110110
spin_unlock(&c->space_lock);
111111
return liab;
112112
}
@@ -180,7 +180,7 @@ int ubifs_calc_min_idx_lebs(struct ubifs_info *c)
180180
int idx_lebs;
181181
long long idx_size;
182182

183-
idx_size = c->old_idx_sz + c->budg_idx_growth + c->budg_uncommitted_idx;
183+
idx_size = c->bi.old_idx_sz + c->bi.idx_growth + c->bi.uncommitted_idx;
184184
/* And make sure we have thrice the index size of space reserved */
185185
idx_size += idx_size << 1;
186186
/*
@@ -292,13 +292,13 @@ static int can_use_rp(struct ubifs_info *c)
292292
* budgeted index space to the size of the current index, multiplies this by 3,
293293
* and makes sure this does not exceed the amount of free LEBs.
294294
*
295-
* Notes about @c->min_idx_lebs and @c->lst.idx_lebs variables:
295+
* Notes about @c->bi.min_idx_lebs and @c->lst.idx_lebs variables:
296296
* o @c->lst.idx_lebs is the number of LEBs the index currently uses. It might
297297
* be large, because UBIFS does not do any index consolidation as long as
298298
* there is free space. IOW, the index may take a lot of LEBs, but the LEBs
299299
* will contain a lot of dirt.
300-
* o @c->min_idx_lebs is the number of LEBS the index presumably takes. IOW,
301-
* the index may be consolidated to take up to @c->min_idx_lebs LEBs.
300+
* o @c->bi.min_idx_lebs is the number of LEBS the index presumably takes. IOW,
301+
* the index may be consolidated to take up to @c->bi.min_idx_lebs LEBs.
302302
*
303303
* This function returns zero in case of success, and %-ENOSPC in case of
304304
* failure.
@@ -343,13 +343,13 @@ static int do_budget_space(struct ubifs_info *c)
343343
c->lst.taken_empty_lebs;
344344
if (unlikely(rsvd_idx_lebs > lebs)) {
345345
dbg_budg("out of indexing space: min_idx_lebs %d (old %d), "
346-
"rsvd_idx_lebs %d", min_idx_lebs, c->min_idx_lebs,
346+
"rsvd_idx_lebs %d", min_idx_lebs, c->bi.min_idx_lebs,
347347
rsvd_idx_lebs);
348348
return -ENOSPC;
349349
}
350350

351351
available = ubifs_calc_available(c, min_idx_lebs);
352-
outstanding = c->budg_data_growth + c->budg_dd_growth;
352+
outstanding = c->bi.data_growth + c->bi.dd_growth;
353353

354354
if (unlikely(available < outstanding)) {
355355
dbg_budg("out of data space: available %lld, outstanding %lld",
@@ -360,7 +360,7 @@ static int do_budget_space(struct ubifs_info *c)
360360
if (available - outstanding <= c->rp_size && !can_use_rp(c))
361361
return -ENOSPC;
362362

363-
c->min_idx_lebs = min_idx_lebs;
363+
c->bi.min_idx_lebs = min_idx_lebs;
364364
return 0;
365365
}
366366

@@ -393,11 +393,11 @@ static int calc_data_growth(const struct ubifs_info *c,
393393
{
394394
int data_growth;
395395

396-
data_growth = req->new_ino ? c->inode_budget : 0;
396+
data_growth = req->new_ino ? c->bi.inode_budget : 0;
397397
if (req->new_page)
398-
data_growth += c->page_budget;
398+
data_growth += c->bi.page_budget;
399399
if (req->new_dent)
400-
data_growth += c->dent_budget;
400+
data_growth += c->bi.dent_budget;
401401
data_growth += req->new_ino_d;
402402
return data_growth;
403403
}
@@ -413,12 +413,12 @@ static int calc_dd_growth(const struct ubifs_info *c,
413413
{
414414
int dd_growth;
415415

416-
dd_growth = req->dirtied_page ? c->page_budget : 0;
416+
dd_growth = req->dirtied_page ? c->bi.page_budget : 0;
417417

418418
if (req->dirtied_ino)
419-
dd_growth += c->inode_budget << (req->dirtied_ino - 1);
419+
dd_growth += c->bi.inode_budget << (req->dirtied_ino - 1);
420420
if (req->mod_dent)
421-
dd_growth += c->dent_budget;
421+
dd_growth += c->bi.dent_budget;
422422
dd_growth += req->dirtied_ino_d;
423423
return dd_growth;
424424
}
@@ -460,19 +460,19 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
460460

461461
again:
462462
spin_lock(&c->space_lock);
463-
ubifs_assert(c->budg_idx_growth >= 0);
464-
ubifs_assert(c->budg_data_growth >= 0);
465-
ubifs_assert(c->budg_dd_growth >= 0);
463+
ubifs_assert(c->bi.idx_growth >= 0);
464+
ubifs_assert(c->bi.data_growth >= 0);
465+
ubifs_assert(c->bi.dd_growth >= 0);
466466

467-
if (unlikely(c->nospace) && (c->nospace_rp || !can_use_rp(c))) {
467+
if (unlikely(c->bi.nospace) && (c->bi.nospace_rp || !can_use_rp(c))) {
468468
dbg_budg("no space");
469469
spin_unlock(&c->space_lock);
470470
return -ENOSPC;
471471
}
472472

473-
c->budg_idx_growth += idx_growth;
474-
c->budg_data_growth += data_growth;
475-
c->budg_dd_growth += dd_growth;
473+
c->bi.idx_growth += idx_growth;
474+
c->bi.data_growth += data_growth;
475+
c->bi.dd_growth += dd_growth;
476476

477477
err = do_budget_space(c);
478478
if (likely(!err)) {
@@ -484,9 +484,9 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
484484
}
485485

486486
/* Restore the old values */
487-
c->budg_idx_growth -= idx_growth;
488-
c->budg_data_growth -= data_growth;
489-
c->budg_dd_growth -= dd_growth;
487+
c->bi.idx_growth -= idx_growth;
488+
c->bi.data_growth -= data_growth;
489+
c->bi.dd_growth -= dd_growth;
490490
spin_unlock(&c->space_lock);
491491

492492
if (req->fast) {
@@ -506,9 +506,9 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
506506
goto again;
507507
}
508508
dbg_budg("FS is full, -ENOSPC");
509-
c->nospace = 1;
509+
c->bi.nospace = 1;
510510
if (can_use_rp(c) || c->rp_size == 0)
511-
c->nospace_rp = 1;
511+
c->bi.nospace_rp = 1;
512512
smp_wmb();
513513
} else
514514
ubifs_err("cannot budget space, error %d", err);
@@ -523,8 +523,8 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
523523
* This function releases the space budgeted by 'ubifs_budget_space()'. Note,
524524
* since the index changes (which were budgeted for in @req->idx_growth) will
525525
* only be written to the media on commit, this function moves the index budget
526-
* from @c->budg_idx_growth to @c->budg_uncommitted_idx. The latter will be
527-
* zeroed by the commit operation.
526+
* from @c->bi.idx_growth to @c->bi.uncommitted_idx. The latter will be zeroed
527+
* by the commit operation.
528528
*/
529529
void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req)
530530
{
@@ -553,23 +553,23 @@ void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req)
553553
if (!req->data_growth && !req->dd_growth)
554554
return;
555555

556-
c->nospace = c->nospace_rp = 0;
556+
c->bi.nospace = c->bi.nospace_rp = 0;
557557
smp_wmb();
558558

559559
spin_lock(&c->space_lock);
560-
c->budg_idx_growth -= req->idx_growth;
561-
c->budg_uncommitted_idx += req->idx_growth;
562-
c->budg_data_growth -= req->data_growth;
563-
c->budg_dd_growth -= req->dd_growth;
564-
c->min_idx_lebs = ubifs_calc_min_idx_lebs(c);
565-
566-
ubifs_assert(c->budg_idx_growth >= 0);
567-
ubifs_assert(c->budg_data_growth >= 0);
568-
ubifs_assert(c->budg_dd_growth >= 0);
569-
ubifs_assert(c->min_idx_lebs < c->main_lebs);
570-
ubifs_assert(!(c->budg_idx_growth & 7));
571-
ubifs_assert(!(c->budg_data_growth & 7));
572-
ubifs_assert(!(c->budg_dd_growth & 7));
560+
c->bi.idx_growth -= req->idx_growth;
561+
c->bi.uncommitted_idx += req->idx_growth;
562+
c->bi.data_growth -= req->data_growth;
563+
c->bi.dd_growth -= req->dd_growth;
564+
c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
565+
566+
ubifs_assert(c->bi.idx_growth >= 0);
567+
ubifs_assert(c->bi.data_growth >= 0);
568+
ubifs_assert(c->bi.dd_growth >= 0);
569+
ubifs_assert(c->bi.min_idx_lebs < c->main_lebs);
570+
ubifs_assert(!(c->bi.idx_growth & 7));
571+
ubifs_assert(!(c->bi.data_growth & 7));
572+
ubifs_assert(!(c->bi.dd_growth & 7));
573573
spin_unlock(&c->space_lock);
574574
}
575575

@@ -586,13 +586,13 @@ void ubifs_convert_page_budget(struct ubifs_info *c)
586586
{
587587
spin_lock(&c->space_lock);
588588
/* Release the index growth reservation */
589-
c->budg_idx_growth -= c->max_idx_node_sz << UBIFS_BLOCKS_PER_PAGE_SHIFT;
589+
c->bi.idx_growth -= c->max_idx_node_sz << UBIFS_BLOCKS_PER_PAGE_SHIFT;
590590
/* Release the data growth reservation */
591-
c->budg_data_growth -= c->page_budget;
591+
c->bi.data_growth -= c->bi.page_budget;
592592
/* Increase the dirty data growth reservation instead */
593-
c->budg_dd_growth += c->page_budget;
593+
c->bi.dd_growth += c->bi.page_budget;
594594
/* And re-calculate the indexing space reservation */
595-
c->min_idx_lebs = ubifs_calc_min_idx_lebs(c);
595+
c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
596596
spin_unlock(&c->space_lock);
597597
}
598598

@@ -612,7 +612,7 @@ void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
612612

613613
memset(&req, 0, sizeof(struct ubifs_budget_req));
614614
/* The "no space" flags will be cleared because dd_growth is > 0 */
615-
req.dd_growth = c->inode_budget + ALIGN(ui->data_len, 8);
615+
req.dd_growth = c->bi.inode_budget + ALIGN(ui->data_len, 8);
616616
ubifs_release_budget(c, &req);
617617
}
618618

@@ -682,9 +682,9 @@ long long ubifs_get_free_space_nolock(struct ubifs_info *c)
682682
int rsvd_idx_lebs, lebs;
683683
long long available, outstanding, free;
684684

685-
ubifs_assert(c->min_idx_lebs == ubifs_calc_min_idx_lebs(c));
686-
outstanding = c->budg_data_growth + c->budg_dd_growth;
687-
available = ubifs_calc_available(c, c->min_idx_lebs);
685+
ubifs_assert(c->bi.min_idx_lebs == ubifs_calc_min_idx_lebs(c));
686+
outstanding = c->bi.data_growth + c->bi.dd_growth;
687+
available = ubifs_calc_available(c, c->bi.min_idx_lebs);
688688

689689
/*
690690
* When reporting free space to user-space, UBIFS guarantees that it is
@@ -697,8 +697,8 @@ long long ubifs_get_free_space_nolock(struct ubifs_info *c)
697697
* Note, the calculations below are similar to what we have in
698698
* 'do_budget_space()', so refer there for comments.
699699
*/
700-
if (c->min_idx_lebs > c->lst.idx_lebs)
701-
rsvd_idx_lebs = c->min_idx_lebs - c->lst.idx_lebs;
700+
if (c->bi.min_idx_lebs > c->lst.idx_lebs)
701+
rsvd_idx_lebs = c->bi.min_idx_lebs - c->lst.idx_lebs;
702702
else
703703
rsvd_idx_lebs = 0;
704704
lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt -

‎fs/ubifs/commit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static int do_commit(struct ubifs_info *c)
182182
c->mst_node->root_len = cpu_to_le32(zroot.len);
183183
c->mst_node->ihead_lnum = cpu_to_le32(c->ihead_lnum);
184184
c->mst_node->ihead_offs = cpu_to_le32(c->ihead_offs);
185-
c->mst_node->index_size = cpu_to_le64(c->old_idx_sz);
185+
c->mst_node->index_size = cpu_to_le64(c->bi.old_idx_sz);
186186
c->mst_node->lpt_lnum = cpu_to_le32(c->lpt_lnum);
187187
c->mst_node->lpt_offs = cpu_to_le32(c->lpt_offs);
188188
c->mst_node->nhead_lnum = cpu_to_le32(c->nhead_lnum);

‎fs/ubifs/debug.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -614,14 +614,14 @@ void dbg_dump_budg(struct ubifs_info *c)
614614
spin_lock(&dbg_lock);
615615
printk(KERN_DEBUG "(pid %d) Budgeting info: budg_data_growth %lld, "
616616
"budg_dd_growth %lld, budg_idx_growth %lld\n", current->pid,
617-
c->budg_data_growth, c->budg_dd_growth, c->budg_idx_growth);
617+
c->bi.data_growth, c->bi.dd_growth, c->bi.idx_growth);
618618
printk(KERN_DEBUG "\tdata budget sum %lld, total budget sum %lld, "
619-
"freeable_cnt %d\n", c->budg_data_growth + c->budg_dd_growth,
620-
c->budg_data_growth + c->budg_dd_growth + c->budg_idx_growth,
619+
"freeable_cnt %d\n", c->bi.data_growth + c->bi.dd_growth,
620+
c->bi.data_growth + c->bi.dd_growth + c->bi.idx_growth,
621621
c->freeable_cnt);
622622
printk(KERN_DEBUG "\tmin_idx_lebs %d, old_idx_sz %lld, "
623-
"calc_idx_sz %lld, idx_gc_cnt %d\n", c->min_idx_lebs,
624-
c->old_idx_sz, c->calc_idx_sz, c->idx_gc_cnt);
623+
"calc_idx_sz %lld, idx_gc_cnt %d\n", c->bi.min_idx_lebs,
624+
c->bi.old_idx_sz, c->calc_idx_sz, c->idx_gc_cnt);
625625
printk(KERN_DEBUG "\tdirty_pg_cnt %ld, dirty_zn_cnt %ld, "
626626
"clean_zn_cnt %ld\n", atomic_long_read(&c->dirty_pg_cnt),
627627
atomic_long_read(&c->dirty_zn_cnt),
@@ -648,8 +648,8 @@ void dbg_dump_budg(struct ubifs_info *c)
648648
printk(KERN_DEBUG "\tcommit state %d\n", c->cmt_state);
649649

650650
/* Print budgeting predictions */
651-
available = ubifs_calc_available(c, c->min_idx_lebs);
652-
outstanding = c->budg_data_growth + c->budg_dd_growth;
651+
available = ubifs_calc_available(c, c->bi.min_idx_lebs);
652+
outstanding = c->bi.data_growth + c->bi.dd_growth;
653653
free = ubifs_get_free_space_nolock(c);
654654
printk(KERN_DEBUG "Budgeting predictions:\n");
655655
printk(KERN_DEBUG "\tavailable: %lld, outstanding %lld, free %lld\n",

‎fs/ubifs/dir.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ static int ubifs_unlink(struct inode *dir, struct dentry *dentry)
603603
ubifs_release_budget(c, &req);
604604
else {
605605
/* We've deleted something - clean the "no space" flags */
606-
c->nospace = c->nospace_rp = 0;
606+
c->bi.nospace = c->bi.nospace_rp = 0;
607607
smp_wmb();
608608
}
609609
return 0;
@@ -693,7 +693,7 @@ static int ubifs_rmdir(struct inode *dir, struct dentry *dentry)
693693
ubifs_release_budget(c, &req);
694694
else {
695695
/* We've deleted something - clean the "no space" flags */
696-
c->nospace = c->nospace_rp = 0;
696+
c->bi.nospace = c->bi.nospace_rp = 0;
697697
smp_wmb();
698698
}
699699
return 0;

‎fs/ubifs/file.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static void release_new_page_budget(struct ubifs_info *c)
212212
*/
213213
static void release_existing_page_budget(struct ubifs_info *c)
214214
{
215-
struct ubifs_budget_req req = { .dd_growth = c->page_budget};
215+
struct ubifs_budget_req req = { .dd_growth = c->bi.page_budget};
216216

217217
ubifs_release_budget(c, &req);
218218
}
@@ -1189,7 +1189,7 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
11891189
if (budgeted)
11901190
ubifs_release_budget(c, &req);
11911191
else {
1192-
c->nospace = c->nospace_rp = 0;
1192+
c->bi.nospace = c->bi.nospace_rp = 0;
11931193
smp_wmb();
11941194
}
11951195
return err;

‎fs/ubifs/find.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
252252
* But if the index takes fewer LEBs than it is reserved for it,
253253
* this function must avoid picking those reserved LEBs.
254254
*/
255-
if (c->min_idx_lebs >= c->lst.idx_lebs) {
256-
rsvd_idx_lebs = c->min_idx_lebs - c->lst.idx_lebs;
255+
if (c->bi.min_idx_lebs >= c->lst.idx_lebs) {
256+
rsvd_idx_lebs = c->bi.min_idx_lebs - c->lst.idx_lebs;
257257
exclude_index = 1;
258258
}
259259
spin_unlock(&c->space_lock);
@@ -276,7 +276,7 @@ int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
276276
pick_free = 0;
277277
} else {
278278
spin_lock(&c->space_lock);
279-
exclude_index = (c->min_idx_lebs >= c->lst.idx_lebs);
279+
exclude_index = (c->bi.min_idx_lebs >= c->lst.idx_lebs);
280280
spin_unlock(&c->space_lock);
281281
}
282282

@@ -501,8 +501,8 @@ int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs,
501501

502502
/* Check if there are enough empty LEBs for commit */
503503
spin_lock(&c->space_lock);
504-
if (c->min_idx_lebs > c->lst.idx_lebs)
505-
rsvd_idx_lebs = c->min_idx_lebs - c->lst.idx_lebs;
504+
if (c->bi.min_idx_lebs > c->lst.idx_lebs)
505+
rsvd_idx_lebs = c->bi.min_idx_lebs - c->lst.idx_lebs;
506506
else
507507
rsvd_idx_lebs = 0;
508508
lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt -

‎fs/ubifs/master.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static int validate_master(const struct ubifs_info *c)
148148
}
149149

150150
main_sz = (long long)c->main_lebs * c->leb_size;
151-
if (c->old_idx_sz & 7 || c->old_idx_sz >= main_sz) {
151+
if (c->bi.old_idx_sz & 7 || c->bi.old_idx_sz >= main_sz) {
152152
err = 9;
153153
goto out;
154154
}
@@ -218,7 +218,7 @@ static int validate_master(const struct ubifs_info *c)
218218
}
219219

220220
if (c->lst.total_dead + c->lst.total_dark +
221-
c->lst.total_used + c->old_idx_sz > main_sz) {
221+
c->lst.total_used + c->bi.old_idx_sz > main_sz) {
222222
err = 21;
223223
goto out;
224224
}
@@ -286,7 +286,7 @@ int ubifs_read_master(struct ubifs_info *c)
286286
c->gc_lnum = le32_to_cpu(c->mst_node->gc_lnum);
287287
c->ihead_lnum = le32_to_cpu(c->mst_node->ihead_lnum);
288288
c->ihead_offs = le32_to_cpu(c->mst_node->ihead_offs);
289-
c->old_idx_sz = le64_to_cpu(c->mst_node->index_size);
289+
c->bi.old_idx_sz = le64_to_cpu(c->mst_node->index_size);
290290
c->lpt_lnum = le32_to_cpu(c->mst_node->lpt_lnum);
291291
c->lpt_offs = le32_to_cpu(c->mst_node->lpt_offs);
292292
c->nhead_lnum = le32_to_cpu(c->mst_node->nhead_lnum);
@@ -305,7 +305,7 @@ int ubifs_read_master(struct ubifs_info *c)
305305
c->lst.total_dead = le64_to_cpu(c->mst_node->total_dead);
306306
c->lst.total_dark = le64_to_cpu(c->mst_node->total_dark);
307307

308-
c->calc_idx_sz = c->old_idx_sz;
308+
c->calc_idx_sz = c->bi.old_idx_sz;
309309

310310
if (c->mst_node->flags & cpu_to_le32(UBIFS_MST_NO_ORPHS))
311311
c->no_orphs = 1;

0 commit comments

Comments
 (0)