56 #include <linux/slab.h>
66 #define SOFT_LEBS_LIMIT 4
67 #define HARD_LEBS_LIMIT 32
87 dbg_gc(
"switch GC head from LEB %d:%d to LEB %d (waste %d bytes)",
143 inuma = key_inum(c, &sa->
key);
144 inumb = key_inum(c, &sb->
key);
146 if (inuma == inumb) {
147 unsigned int blka = key_block(c, &sa->
key);
148 unsigned int blkb = key_block(c, &sb->
key);
152 }
else if (inuma <= inumb)
168 static int nondata_nodes_cmp(
void *priv,
struct list_head *a,
205 inuma = key_inum(c, &sa->
key);
206 inumb = key_inum(c, &sb->
key);
208 if (inuma == inumb) {
214 }
else if (inuma <= inumb)
290 if (snod->
len < *min)
294 list_move_tail(&snod->
list, nondata);
299 list_sort(c, nondata, &nondata_nodes_cmp);
332 snod->
offs, new_lnum, new_offs,
355 if (wbuf->
lnum == -1) {
360 err = switch_gc_head(c);
365 err = sort_nodes(c, sleb, &nondata, &min);
377 if (snod->
len > avail)
384 err = move_node(c, sleb, snod, wbuf);
395 if (snod->
len > avail) {
409 err = move_node(c, sleb, snod, wbuf);
414 if (list_empty(&sleb->
nodes) && list_empty(&nondata))
421 err = switch_gc_head(c);
429 list_splice_tail(&nondata, &sleb->
nodes);
446 static int gc_sync_wbufs(
struct ubifs_info *c)
453 err = ubifs_wbuf_sync(&c->
jheads[i].wbuf);
483 dbg_gc(
"LEB %d is free, return it", lp->
lnum);
492 err = gc_sync_wbufs(c);
518 return PTR_ERR(sleb);
526 dbg_gc(
"indexing LEB %d (free %d, dirty %d)",
533 key_read(c, ubifs_idx_key(c, idx), &snod->
key);
562 dbg_gc(
"data LEB %d (free %d, dirty %d)",
565 err = move_nodes(c, sleb);
569 err = gc_sync_wbufs(c);
687 dbg_gc(
"soft limit, some index LEBs GC'ed, -EAGAIN");
698 dbg_gc(
"hard limit, -ENOSPC");
713 dbg_gc(
"no more dirty LEBs");
717 dbg_gc(
"found LEB %d: free %d, dirty %d, sum %d (min. space %d)",
722 if (wbuf->
lnum == -1)
734 err = ubifs_return_leb(c, lp.
lnum);
756 dbg_gc(
"indexing LEB %d freed, continue", lp.
lnum);
762 dbg_gc(
"LEB %d retained, freed %d bytes", lp.
lnum,
763 space_after - space_before);
765 if (space_after > space_before) {
768 if (min_space < c->dead_wm)
773 dbg_gc(
"did not make progress");
799 dbg_gc(
"set min. space to %d", min_space);
803 dbg_gc(
"no space, some index LEBs GC'ed, -EAGAIN");
825 ubifs_return_leb(c, lp.
lnum);
909 ubifs_release_lprops(c);
955 while (!list_empty(&c->
idx_gc)) {
977 if (list_empty(&c->
idx_gc))