Lines Matching refs:c
51 static void shrink_liability(struct ubifs_info *c, int nr_to_write) in shrink_liability() argument
53 down_read(&c->vfs_sb->s_umount); in shrink_liability()
54 writeback_inodes_sb_nr(c->vfs_sb, nr_to_write, WB_REASON_FS_FREE_SPACE); in shrink_liability()
55 up_read(&c->vfs_sb->s_umount); in shrink_liability()
66 static int run_gc(struct ubifs_info *c) in run_gc() argument
71 down_read(&c->commit_sem); in run_gc()
72 lnum = ubifs_garbage_collect(c, 1); in run_gc()
73 up_read(&c->commit_sem); in run_gc()
79 err = ubifs_return_leb(c, lnum); in run_gc()
92 static long long get_liability(struct ubifs_info *c) in get_liability() argument
96 spin_lock(&c->space_lock); in get_liability()
97 liab = c->bi.idx_growth + c->bi.data_growth + c->bi.dd_growth; in get_liability()
98 spin_unlock(&c->space_lock); in get_liability()
120 static int make_free_space(struct ubifs_info *c) in make_free_space() argument
126 liab1 = get_liability(c); in make_free_space()
132 shrink_liability(c, NR_TO_WRITE); in make_free_space()
134 liab2 = get_liability(c); in make_free_space()
142 err = run_gc(c); in make_free_space()
151 err = ubifs_run_commit(c); in make_free_space()
166 int ubifs_calc_min_idx_lebs(struct ubifs_info *c) in ubifs_calc_min_idx_lebs() argument
171 idx_size = c->bi.old_idx_sz + c->bi.idx_growth + c->bi.uncommitted_idx; in ubifs_calc_min_idx_lebs()
179 idx_lebs = div_u64(idx_size + c->idx_leb_size - 1, c->idx_leb_size); in ubifs_calc_min_idx_lebs()
197 long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs) in ubifs_calc_available() argument
202 available = c->main_bytes - c->lst.total_used; in ubifs_calc_available()
219 subtract_lebs += c->jhead_cnt - 1; in ubifs_calc_available()
224 available -= (long long)subtract_lebs * c->leb_size; in ubifs_calc_available()
227 available -= c->lst.total_dead; in ubifs_calc_available()
235 available -= c->lst.total_dark; in ubifs_calc_available()
243 if (c->lst.idx_lebs > min_idx_lebs) { in ubifs_calc_available()
244 subtract_lebs = c->lst.idx_lebs - min_idx_lebs; in ubifs_calc_available()
245 available -= subtract_lebs * c->dark_wm; in ubifs_calc_available()
261 static int can_use_rp(struct ubifs_info *c) in can_use_rp() argument
263 if (uid_eq(current_fsuid(), c->rp_uid) || capable(CAP_SYS_RESOURCE) || in can_use_rp()
264 (!gid_eq(c->rp_gid, GLOBAL_ROOT_GID) && in_group_p(c->rp_gid))) in can_use_rp()
294 static int do_budget_space(struct ubifs_info *c) in do_budget_space() argument
300 min_idx_lebs = ubifs_calc_min_idx_lebs(c); in do_budget_space()
303 if (min_idx_lebs > c->lst.idx_lebs) in do_budget_space()
304 rsvd_idx_lebs = min_idx_lebs - c->lst.idx_lebs; in do_budget_space()
330 lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt - in do_budget_space()
331 c->lst.taken_empty_lebs; in do_budget_space()
334 min_idx_lebs, c->bi.min_idx_lebs, rsvd_idx_lebs); in do_budget_space()
338 available = ubifs_calc_available(c, min_idx_lebs); in do_budget_space()
339 outstanding = c->bi.data_growth + c->bi.dd_growth; in do_budget_space()
347 if (available - outstanding <= c->rp_size && !can_use_rp(c)) in do_budget_space()
350 c->bi.min_idx_lebs = min_idx_lebs; in do_budget_space()
362 static int calc_idx_growth(const struct ubifs_info *c, in calc_idx_growth() argument
369 return znodes * c->max_idx_node_sz; in calc_idx_growth()
378 static int calc_data_growth(const struct ubifs_info *c, in calc_data_growth() argument
383 data_growth = req->new_ino ? c->bi.inode_budget : 0; in calc_data_growth()
385 data_growth += c->bi.page_budget; in calc_data_growth()
387 data_growth += c->bi.dent_budget; in calc_data_growth()
398 static int calc_dd_growth(const struct ubifs_info *c, in calc_dd_growth() argument
403 dd_growth = req->dirtied_page ? c->bi.page_budget : 0; in calc_dd_growth()
406 dd_growth += c->bi.inode_budget << (req->dirtied_ino - 1); in calc_dd_growth()
408 dd_growth += c->bi.dent_budget; in calc_dd_growth()
426 int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req) in ubifs_budget_space() argument
430 ubifs_assert(c, req->new_page <= 1); in ubifs_budget_space()
431 ubifs_assert(c, req->dirtied_page <= 1); in ubifs_budget_space()
432 ubifs_assert(c, req->new_dent <= 1); in ubifs_budget_space()
433 ubifs_assert(c, req->mod_dent <= 1); in ubifs_budget_space()
434 ubifs_assert(c, req->new_ino <= 1); in ubifs_budget_space()
435 ubifs_assert(c, req->new_ino_d <= UBIFS_MAX_INO_DATA); in ubifs_budget_space()
436 ubifs_assert(c, req->dirtied_ino <= 4); in ubifs_budget_space()
437 ubifs_assert(c, req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4); in ubifs_budget_space()
438 ubifs_assert(c, !(req->new_ino_d & 7)); in ubifs_budget_space()
439 ubifs_assert(c, !(req->dirtied_ino_d & 7)); in ubifs_budget_space()
441 data_growth = calc_data_growth(c, req); in ubifs_budget_space()
442 dd_growth = calc_dd_growth(c, req); in ubifs_budget_space()
445 idx_growth = calc_idx_growth(c, req); in ubifs_budget_space()
448 spin_lock(&c->space_lock); in ubifs_budget_space()
449 ubifs_assert(c, c->bi.idx_growth >= 0); in ubifs_budget_space()
450 ubifs_assert(c, c->bi.data_growth >= 0); in ubifs_budget_space()
451 ubifs_assert(c, c->bi.dd_growth >= 0); in ubifs_budget_space()
453 if (unlikely(c->bi.nospace) && (c->bi.nospace_rp || !can_use_rp(c))) { in ubifs_budget_space()
455 spin_unlock(&c->space_lock); in ubifs_budget_space()
459 c->bi.idx_growth += idx_growth; in ubifs_budget_space()
460 c->bi.data_growth += data_growth; in ubifs_budget_space()
461 c->bi.dd_growth += dd_growth; in ubifs_budget_space()
463 err = do_budget_space(c); in ubifs_budget_space()
468 spin_unlock(&c->space_lock); in ubifs_budget_space()
473 c->bi.idx_growth -= idx_growth; in ubifs_budget_space()
474 c->bi.data_growth -= data_growth; in ubifs_budget_space()
475 c->bi.dd_growth -= dd_growth; in ubifs_budget_space()
476 spin_unlock(&c->space_lock); in ubifs_budget_space()
483 err = make_free_space(c); in ubifs_budget_space()
495 c->bi.nospace = 1; in ubifs_budget_space()
496 if (can_use_rp(c) || c->rp_size == 0) in ubifs_budget_space()
497 c->bi.nospace_rp = 1; in ubifs_budget_space()
500 ubifs_err(c, "cannot budget space, error %d", err); in ubifs_budget_space()
515 void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req) in ubifs_release_budget() argument
517 ubifs_assert(c, req->new_page <= 1); in ubifs_release_budget()
518 ubifs_assert(c, req->dirtied_page <= 1); in ubifs_release_budget()
519 ubifs_assert(c, req->new_dent <= 1); in ubifs_release_budget()
520 ubifs_assert(c, req->mod_dent <= 1); in ubifs_release_budget()
521 ubifs_assert(c, req->new_ino <= 1); in ubifs_release_budget()
522 ubifs_assert(c, req->new_ino_d <= UBIFS_MAX_INO_DATA); in ubifs_release_budget()
523 ubifs_assert(c, req->dirtied_ino <= 4); in ubifs_release_budget()
524 ubifs_assert(c, req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4); in ubifs_release_budget()
525 ubifs_assert(c, !(req->new_ino_d & 7)); in ubifs_release_budget()
526 ubifs_assert(c, !(req->dirtied_ino_d & 7)); in ubifs_release_budget()
528 ubifs_assert(c, req->idx_growth >= 0); in ubifs_release_budget()
529 ubifs_assert(c, req->data_growth >= 0); in ubifs_release_budget()
530 ubifs_assert(c, req->dd_growth >= 0); in ubifs_release_budget()
534 req->data_growth = calc_data_growth(c, req); in ubifs_release_budget()
535 req->dd_growth = calc_dd_growth(c, req); in ubifs_release_budget()
536 req->idx_growth = calc_idx_growth(c, req); in ubifs_release_budget()
542 c->bi.nospace = c->bi.nospace_rp = 0; in ubifs_release_budget()
545 spin_lock(&c->space_lock); in ubifs_release_budget()
546 c->bi.idx_growth -= req->idx_growth; in ubifs_release_budget()
547 c->bi.uncommitted_idx += req->idx_growth; in ubifs_release_budget()
548 c->bi.data_growth -= req->data_growth; in ubifs_release_budget()
549 c->bi.dd_growth -= req->dd_growth; in ubifs_release_budget()
550 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); in ubifs_release_budget()
552 ubifs_assert(c, c->bi.idx_growth >= 0); in ubifs_release_budget()
553 ubifs_assert(c, c->bi.data_growth >= 0); in ubifs_release_budget()
554 ubifs_assert(c, c->bi.dd_growth >= 0); in ubifs_release_budget()
555 ubifs_assert(c, c->bi.min_idx_lebs < c->main_lebs); in ubifs_release_budget()
556 ubifs_assert(c, !(c->bi.idx_growth & 7)); in ubifs_release_budget()
557 ubifs_assert(c, !(c->bi.data_growth & 7)); in ubifs_release_budget()
558 ubifs_assert(c, !(c->bi.dd_growth & 7)); in ubifs_release_budget()
559 spin_unlock(&c->space_lock); in ubifs_release_budget()
571 void ubifs_convert_page_budget(struct ubifs_info *c) in ubifs_convert_page_budget() argument
573 spin_lock(&c->space_lock); in ubifs_convert_page_budget()
575 c->bi.idx_growth -= c->max_idx_node_sz << UBIFS_BLOCKS_PER_PAGE_SHIFT; in ubifs_convert_page_budget()
577 c->bi.data_growth -= c->bi.page_budget; in ubifs_convert_page_budget()
579 c->bi.dd_growth += c->bi.page_budget; in ubifs_convert_page_budget()
581 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); in ubifs_convert_page_budget()
582 spin_unlock(&c->space_lock); in ubifs_convert_page_budget()
594 void ubifs_release_dirty_inode_budget(struct ubifs_info *c, in ubifs_release_dirty_inode_budget() argument
601 req.dd_growth = c->bi.inode_budget + ALIGN(ui->data_len, 8); in ubifs_release_dirty_inode_budget()
602 ubifs_release_budget(c, &req); in ubifs_release_dirty_inode_budget()
625 long long ubifs_reported_space(const struct ubifs_info *c, long long free) in ubifs_reported_space() argument
642 f = c->fanout > 3 ? c->fanout >> 1 : 2; in ubifs_reported_space()
645 divisor += (c->max_idx_node_sz * 3) / (f - 1); in ubifs_reported_space()
666 long long ubifs_get_free_space_nolock(struct ubifs_info *c) in ubifs_get_free_space_nolock() argument
671 ubifs_assert(c, c->bi.min_idx_lebs == ubifs_calc_min_idx_lebs(c)); in ubifs_get_free_space_nolock()
672 outstanding = c->bi.data_growth + c->bi.dd_growth; in ubifs_get_free_space_nolock()
673 available = ubifs_calc_available(c, c->bi.min_idx_lebs); in ubifs_get_free_space_nolock()
686 if (c->bi.min_idx_lebs > c->lst.idx_lebs) in ubifs_get_free_space_nolock()
687 rsvd_idx_lebs = c->bi.min_idx_lebs - c->lst.idx_lebs; in ubifs_get_free_space_nolock()
690 lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt - in ubifs_get_free_space_nolock()
691 c->lst.taken_empty_lebs; in ubifs_get_free_space_nolock()
693 available += lebs * (c->dark_wm - c->leb_overhead); in ubifs_get_free_space_nolock()
696 free = ubifs_reported_space(c, available - outstanding); in ubifs_get_free_space_nolock()
709 long long ubifs_get_free_space(struct ubifs_info *c) in ubifs_get_free_space() argument
713 spin_lock(&c->space_lock); in ubifs_get_free_space()
714 free = ubifs_get_free_space_nolock(c); in ubifs_get_free_space()
715 spin_unlock(&c->space_lock); in ubifs_get_free_space()