Lines Matching full:c
5 * Copyright (C) 2006-2008 Nokia Corporation.
41 * @c: UBIFS file-system description object
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()
60 * @c: UBIFS file-system description object
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 return ubifs_return_leb(c, lnum); in run_gc()
84 * @c: UBIFS file-system description object
89 static long long get_liability(struct ubifs_info *c) in get_liability() argument
93 spin_lock(&c->space_lock); in get_liability()
94 liab = c->bi.idx_growth + c->bi.data_growth + c->bi.dd_growth; in get_liability()
95 spin_unlock(&c->space_lock); in get_liability()
101 * @c: UBIFS file-system description object
117 static int make_free_space(struct ubifs_info *c) in make_free_space() argument
123 liab1 = get_liability(c); in make_free_space()
129 shrink_liability(c, NR_TO_WRITE); in make_free_space()
131 liab2 = get_liability(c); in make_free_space()
139 err = run_gc(c); in make_free_space()
148 err = ubifs_run_commit(c); in make_free_space()
158 * @c: UBIFS file-system description object
163 int ubifs_calc_min_idx_lebs(struct ubifs_info *c) in ubifs_calc_min_idx_lebs() argument
168 idx_size = c->bi.old_idx_sz + c->bi.idx_growth + c->bi.uncommitted_idx; in ubifs_calc_min_idx_lebs()
176 idx_lebs = div_u64(idx_size + c->idx_leb_size - 1, c->idx_leb_size); in ubifs_calc_min_idx_lebs()
189 * @c: UBIFS file-system description object
194 long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs) in ubifs_calc_available() argument
199 available = c->main_bytes - c->lst.total_used; in ubifs_calc_available()
216 subtract_lebs += c->jhead_cnt - 1; in ubifs_calc_available()
221 available -= (long long)subtract_lebs * c->leb_size; in ubifs_calc_available()
224 available -= c->lst.total_dead; in ubifs_calc_available()
232 available -= c->lst.total_dark; in ubifs_calc_available()
240 if (c->lst.idx_lebs > min_idx_lebs) { in ubifs_calc_available()
241 subtract_lebs = c->lst.idx_lebs - min_idx_lebs; in ubifs_calc_available()
242 available -= subtract_lebs * c->dark_wm; in ubifs_calc_available()
251 * @c: UBIFS file-system description object
258 static int can_use_rp(struct ubifs_info *c) in can_use_rp() argument
260 if (uid_eq(current_fsuid(), c->rp_uid) || capable(CAP_SYS_RESOURCE) || in can_use_rp()
261 (!gid_eq(c->rp_gid, GLOBAL_ROOT_GID) && in_group_p(c->rp_gid))) in can_use_rp()
268 * @c: UBIFS file-system description object
280 * Notes about @c->bi.min_idx_lebs and @c->lst.idx_lebs variables:
281 * o @c->lst.idx_lebs is the number of LEBs the index currently uses. It might
285 * o @c->bi.min_idx_lebs is the number of LEBS the index presumably takes. IOW,
286 * the index may be consolidated to take up to @c->bi.min_idx_lebs LEBs.
291 static int do_budget_space(struct ubifs_info *c) in do_budget_space() argument
297 min_idx_lebs = ubifs_calc_min_idx_lebs(c); in do_budget_space()
300 if (min_idx_lebs > c->lst.idx_lebs) in do_budget_space()
301 rsvd_idx_lebs = min_idx_lebs - c->lst.idx_lebs; in do_budget_space()
308 * @c->lst.empty_lebs + @c->freeable_cnt + @c->idx_gc_cnt - in do_budget_space()
309 * @c->lst.taken_empty_lebs in do_budget_space()
311 * @c->lst.empty_lebs are available because they are empty. in do_budget_space()
312 * @c->freeable_cnt are available because they contain only free and in do_budget_space()
313 * dirty space, @c->idx_gc_cnt are available because they are index in do_budget_space()
316 * if it needs them. @c->lst.taken_empty_lebs are empty LEBs that have in do_budget_space()
319 * Note, @c->idx_gc_cnt is included to both @c->lst.empty_lebs (because in do_budget_space()
320 * these LEBs are empty) and to @c->lst.taken_empty_lebs (because they in do_budget_space()
323 * Note, @c->lst.taken_empty_lebs may temporarily be higher by one in do_budget_space()
327 lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt - in do_budget_space()
328 c->lst.taken_empty_lebs; in do_budget_space()
331 min_idx_lebs, c->bi.min_idx_lebs, rsvd_idx_lebs); in do_budget_space()
335 available = ubifs_calc_available(c, min_idx_lebs); in do_budget_space()
336 outstanding = c->bi.data_growth + c->bi.dd_growth; in do_budget_space()
344 if (available - outstanding <= c->rp_size && !can_use_rp(c)) in do_budget_space()
347 c->bi.min_idx_lebs = min_idx_lebs; in do_budget_space()
353 * @c: UBIFS file-system description object
359 static int calc_idx_growth(const struct ubifs_info *c, in calc_idx_growth() argument
366 return znodes * c->max_idx_node_sz; in calc_idx_growth()
372 * @c: UBIFS file-system description object
375 static int calc_data_growth(const struct ubifs_info *c, in calc_data_growth() argument
380 data_growth = req->new_ino ? c->bi.inode_budget : 0; in calc_data_growth()
382 data_growth += c->bi.page_budget; in calc_data_growth()
384 data_growth += c->bi.dent_budget; in calc_data_growth()
392 * @c: UBIFS file-system description object
395 static int calc_dd_growth(const struct ubifs_info *c, in calc_dd_growth() argument
400 dd_growth = req->dirtied_page ? c->bi.page_budget : 0; in calc_dd_growth()
403 dd_growth += c->bi.inode_budget << (req->dirtied_ino - 1); in calc_dd_growth()
405 dd_growth += c->bi.dent_budget; in calc_dd_growth()
412 * @c: UBIFS file-system description object
423 int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req) in ubifs_budget_space() argument
427 ubifs_assert(c, req->new_page <= 1); in ubifs_budget_space()
428 ubifs_assert(c, req->dirtied_page <= 1); in ubifs_budget_space()
429 ubifs_assert(c, req->new_dent <= 1); in ubifs_budget_space()
430 ubifs_assert(c, req->mod_dent <= 1); in ubifs_budget_space()
431 ubifs_assert(c, req->new_ino <= 1); in ubifs_budget_space()
432 ubifs_assert(c, req->new_ino_d <= UBIFS_MAX_INO_DATA); in ubifs_budget_space()
433 ubifs_assert(c, req->dirtied_ino <= 4); in ubifs_budget_space()
434 ubifs_assert(c, req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4); in ubifs_budget_space()
435 ubifs_assert(c, !(req->new_ino_d & 7)); in ubifs_budget_space()
436 ubifs_assert(c, !(req->dirtied_ino_d & 7)); in ubifs_budget_space()
438 data_growth = calc_data_growth(c, req); in ubifs_budget_space()
439 dd_growth = calc_dd_growth(c, req); in ubifs_budget_space()
442 idx_growth = calc_idx_growth(c, req); in ubifs_budget_space()
445 spin_lock(&c->space_lock); in ubifs_budget_space()
446 ubifs_assert(c, c->bi.idx_growth >= 0); in ubifs_budget_space()
447 ubifs_assert(c, c->bi.data_growth >= 0); in ubifs_budget_space()
448 ubifs_assert(c, c->bi.dd_growth >= 0); in ubifs_budget_space()
450 if (unlikely(c->bi.nospace) && (c->bi.nospace_rp || !can_use_rp(c))) { in ubifs_budget_space()
452 spin_unlock(&c->space_lock); in ubifs_budget_space()
456 c->bi.idx_growth += idx_growth; in ubifs_budget_space()
457 c->bi.data_growth += data_growth; in ubifs_budget_space()
458 c->bi.dd_growth += dd_growth; in ubifs_budget_space()
460 err = do_budget_space(c); in ubifs_budget_space()
465 spin_unlock(&c->space_lock); in ubifs_budget_space()
470 c->bi.idx_growth -= idx_growth; in ubifs_budget_space()
471 c->bi.data_growth -= data_growth; in ubifs_budget_space()
472 c->bi.dd_growth -= dd_growth; in ubifs_budget_space()
473 spin_unlock(&c->space_lock); in ubifs_budget_space()
480 err = make_free_space(c); in ubifs_budget_space()
492 c->bi.nospace = 1; in ubifs_budget_space()
493 if (can_use_rp(c) || c->rp_size == 0) in ubifs_budget_space()
494 c->bi.nospace_rp = 1; in ubifs_budget_space()
497 ubifs_err(c, "cannot budget space, error %d", err); in ubifs_budget_space()
503 * @c: UBIFS file-system description object
509 * from @c->bi.idx_growth to @c->bi.uncommitted_idx. The latter will be zeroed
512 void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req) in ubifs_release_budget() argument
514 ubifs_assert(c, req->new_page <= 1); in ubifs_release_budget()
515 ubifs_assert(c, req->dirtied_page <= 1); in ubifs_release_budget()
516 ubifs_assert(c, req->new_dent <= 1); in ubifs_release_budget()
517 ubifs_assert(c, req->mod_dent <= 1); in ubifs_release_budget()
518 ubifs_assert(c, req->new_ino <= 1); in ubifs_release_budget()
519 ubifs_assert(c, req->new_ino_d <= UBIFS_MAX_INO_DATA); in ubifs_release_budget()
520 ubifs_assert(c, req->dirtied_ino <= 4); in ubifs_release_budget()
521 ubifs_assert(c, req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4); in ubifs_release_budget()
522 ubifs_assert(c, !(req->new_ino_d & 7)); in ubifs_release_budget()
523 ubifs_assert(c, !(req->dirtied_ino_d & 7)); in ubifs_release_budget()
525 ubifs_assert(c, req->idx_growth >= 0); in ubifs_release_budget()
526 ubifs_assert(c, req->data_growth >= 0); in ubifs_release_budget()
527 ubifs_assert(c, req->dd_growth >= 0); in ubifs_release_budget()
531 req->data_growth = calc_data_growth(c, req); in ubifs_release_budget()
532 req->dd_growth = calc_dd_growth(c, req); in ubifs_release_budget()
533 req->idx_growth = calc_idx_growth(c, req); in ubifs_release_budget()
539 c->bi.nospace = c->bi.nospace_rp = 0; in ubifs_release_budget()
542 spin_lock(&c->space_lock); in ubifs_release_budget()
543 c->bi.idx_growth -= req->idx_growth; in ubifs_release_budget()
544 c->bi.uncommitted_idx += req->idx_growth; in ubifs_release_budget()
545 c->bi.data_growth -= req->data_growth; in ubifs_release_budget()
546 c->bi.dd_growth -= req->dd_growth; in ubifs_release_budget()
547 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); in ubifs_release_budget()
549 ubifs_assert(c, c->bi.idx_growth >= 0); in ubifs_release_budget()
550 ubifs_assert(c, c->bi.data_growth >= 0); in ubifs_release_budget()
551 ubifs_assert(c, c->bi.dd_growth >= 0); in ubifs_release_budget()
552 ubifs_assert(c, c->bi.min_idx_lebs < c->main_lebs); in ubifs_release_budget()
553 ubifs_assert(c, !(c->bi.idx_growth & 7)); in ubifs_release_budget()
554 ubifs_assert(c, !(c->bi.data_growth & 7)); in ubifs_release_budget()
555 ubifs_assert(c, !(c->bi.dd_growth & 7)); in ubifs_release_budget()
556 spin_unlock(&c->space_lock); in ubifs_release_budget()
561 * @c: UBIFS file-system description object
568 void ubifs_convert_page_budget(struct ubifs_info *c) in ubifs_convert_page_budget() argument
570 spin_lock(&c->space_lock); in ubifs_convert_page_budget()
572 c->bi.idx_growth -= c->max_idx_node_sz << UBIFS_BLOCKS_PER_PAGE_SHIFT; in ubifs_convert_page_budget()
574 c->bi.data_growth -= c->bi.page_budget; in ubifs_convert_page_budget()
576 c->bi.dd_growth += c->bi.page_budget; in ubifs_convert_page_budget()
578 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); in ubifs_convert_page_budget()
579 spin_unlock(&c->space_lock); in ubifs_convert_page_budget()
584 * @c: UBIFS file-system description object
591 void ubifs_release_dirty_inode_budget(struct ubifs_info *c, in ubifs_release_dirty_inode_budget() argument
598 req.dd_growth = c->bi.inode_budget + ALIGN(ui->data_len, 8); in ubifs_release_dirty_inode_budget()
599 ubifs_release_budget(c, &req); in ubifs_release_dirty_inode_budget()
604 * @c: the UBIFS file-system description object
622 long long ubifs_reported_space(const struct ubifs_info *c, long long free) in ubifs_reported_space() argument
635 * introduces 3 * @c->max_idx_node_sz / (@c->fanout/2 - 1) bytes. in ubifs_reported_space()
639 f = c->fanout > 3 ? c->fanout >> 1 : 2; in ubifs_reported_space()
642 divisor += (c->max_idx_node_sz * 3) / (f - 1); in ubifs_reported_space()
649 * @c: UBIFS file-system description object
663 long long ubifs_get_free_space_nolock(struct ubifs_info *c) in ubifs_get_free_space_nolock() argument
668 ubifs_assert(c, c->bi.min_idx_lebs == ubifs_calc_min_idx_lebs(c)); in ubifs_get_free_space_nolock()
669 outstanding = c->bi.data_growth + c->bi.dd_growth; in ubifs_get_free_space_nolock()
670 available = ubifs_calc_available(c, c->bi.min_idx_lebs); in ubifs_get_free_space_nolock()
677 * LEBs we would waste only @c->leb_overhead bytes, not @c->dark_wm. in ubifs_get_free_space_nolock()
683 if (c->bi.min_idx_lebs > c->lst.idx_lebs) in ubifs_get_free_space_nolock()
684 rsvd_idx_lebs = c->bi.min_idx_lebs - c->lst.idx_lebs; in ubifs_get_free_space_nolock()
687 lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt - in ubifs_get_free_space_nolock()
688 c->lst.taken_empty_lebs; in ubifs_get_free_space_nolock()
690 available += lebs * (c->dark_wm - c->leb_overhead); in ubifs_get_free_space_nolock()
693 free = ubifs_reported_space(c, available - outstanding); in ubifs_get_free_space_nolock()
701 * @c: UBIFS file-system description object
706 long long ubifs_get_free_space(struct ubifs_info *c) in ubifs_get_free_space() argument
710 spin_lock(&c->space_lock); in ubifs_get_free_space()
711 free = ubifs_get_free_space_nolock(c); in ubifs_get_free_space()
712 spin_unlock(&c->space_lock); in ubifs_get_free_space()