Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 109721
b: refs/heads/master
c: 7dad181
h: refs/heads/master
i:
  109719: daf533a
v: v3
  • Loading branch information
Artem Bityutskiy authored and Artem Bityutskiy committed Aug 31, 2008
1 parent 72ab53e commit 3ec5b4e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9bbb5726efb64e2cfed42f6eec07db80cd87e63b
refs/heads/master: 7dad181bbe58b8fe9e170da28bcd5f6ec9addd6d
38 changes: 34 additions & 4 deletions trunk/fs/ubifs/budget.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,14 +747,24 @@ long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free)
}

/**
* ubifs_budg_get_free_space - return amount of free space.
* ubifs_get_free_space - return amount of free space.
* @c: UBIFS file-system description object
*
* This function returns amount of free space on the file-system.
* This function calculates amount of free space to report to user-space.
*
* Because UBIFS may introduce substantial overhead (the index, node headers,
* alighment, wastage at the end of eraseblocks, etc), it cannot report real
* amount of free flash space it has (well, because not all dirty space is
* reclamable, UBIFS does not actually know the real amount). If UBIFS did so,
* it would bread user expectetion about what free space is. Users seem to
* accustomed to assume that if the file-system reports N bytes of free space,
* they would be able to fit a file of N bytes to the FS. This almost works for
* traditional file-systems, because they have way less overhead than UBIFS.
* So, to keep users happy, UBIFS tries to take the overhead into account.
*/
long long ubifs_budg_get_free_space(struct ubifs_info *c)
long long ubifs_get_free_space(struct ubifs_info *c)
{
int min_idx_lebs;
int min_idx_lebs, rsvd_idx_lebs, lebs;
long long available, outstanding, free;

spin_lock(&c->space_lock);
Expand All @@ -771,6 +781,26 @@ long long ubifs_budg_get_free_space(struct ubifs_info *c)
}

available = ubifs_calc_available(c, min_idx_lebs);

/*
* When reporting free space to user-space, UBIFS guarantees that it is
* possible to write a file of free space size. This means that for
* empty LEBs we may use more precise calculations than
* 'ubifs_calc_available()' is using. Namely, we know that in empty
* LEBs we would waste only @c->leb_overhead bytes, not @c->dark_wm.
* Thus, amend the available space.
*
* Note, the calculations below are similar to what we have in
* 'do_budget_space()', so refer there for comments.
*/
if (min_idx_lebs > c->lst.idx_lebs)
rsvd_idx_lebs = min_idx_lebs - c->lst.idx_lebs;
else
rsvd_idx_lebs = 0;
lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt -
c->lst.taken_empty_lebs;
lebs -= rsvd_idx_lebs;
available += lebs * (c->dark_wm - c->leb_overhead);
spin_unlock(&c->space_lock);

if (available > outstanding)
Expand Down
10 changes: 5 additions & 5 deletions trunk/fs/ubifs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static int ubifs_statfs(struct dentry *dentry, struct kstatfs *buf)
struct ubifs_info *c = dentry->d_sb->s_fs_info;
unsigned long long free;

free = ubifs_budg_get_free_space(c);
free = ubifs_get_free_space(c);
dbg_gen("free space %lld bytes (%lld blocks)",
free, free >> UBIFS_BLOCK_SHIFT);

Expand Down Expand Up @@ -653,11 +653,11 @@ static int init_constants_late(struct ubifs_info *c)
* internally because it does not make much sense for UBIFS, but it is
* necessary to report something for the 'statfs()' call.
*
* Subtract the LEB reserved for GC and the LEB which is reserved for
* deletions.
* Subtract the LEB reserved for GC, the LEB which is reserved for
* deletions, and assume only one journal head is available.
*/
tmp64 = c->main_lebs - 2;
tmp64 *= (uint64_t)c->leb_size - c->dark_wm;
tmp64 = c->main_lebs - 2 - c->jhead_cnt + 1;
tmp64 *= (uint64_t)c->leb_size - c->leb_overhead;
tmp64 = ubifs_reported_space(c, tmp64);
c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT;

Expand Down
2 changes: 1 addition & 1 deletion trunk/fs/ubifs/ubifs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode,
struct ubifs_budget_req *req);
void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
struct ubifs_budget_req *req);
long long ubifs_budg_get_free_space(struct ubifs_info *c);
long long ubifs_get_free_space(struct ubifs_info *c);
int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
void ubifs_convert_page_budget(struct ubifs_info *c);
long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free);
Expand Down

0 comments on commit 3ec5b4e

Please sign in to comment.