9 #include <linux/sched.h>
10 #include <linux/slab.h>
24 #define WL_RATELIMIT 100
25 #define MAX_OBJ_ALIASES 2600
26 #define SCAN_RATIO 512
28 #define SCAN_ROUNDS 128
29 #define SCAN_ROUNDS_HIGH 4
87 static void logfs_mark_segment_bad(
struct super_block *sb,
u32 segno)
109 *gc_level =
GC_LEVEL(ec_level & 0xf);
131 u32 seg_ofs, logical_segno, cleaned = 0;
138 err =
wbuf_read(sb, dev_ofs(sb, segno, 0),
sizeof(sh), &sh);
142 if (sh.crc != logfs_crc32(&sh,
sizeof(sh), 4)) {
143 logfs_mark_segment_bad(sb, segno);
149 seg_ofs +
sizeof(oh) < super->
s_segsize; ) {
150 ofs = dev_ofs(sb, logical_segno, seg_ofs);
151 err =
wbuf_read(sb, dev_ofs(sb, segno, seg_ofs),
sizeof(oh),
158 if (oh.crc != logfs_crc32(&oh,
sizeof(oh) - 4, 4)) {
159 logfs_mark_segment_bad(sb, segno);
169 logfs_cleanse_block(sb, ofs, ino, bix, gc_level);
171 }
else if (valid == 2) {
205 rb_link_node(&cand->
rb_node, parent, p);
242 remove_from_list(cand);
246 free_candidate(sb, cand);
273 if (cand->
valid == 0) {
275 log_gc_noisy(
"add reserve segment %x (ec %x) at %llx\n",
277 dev_ofs(sb, cand->
segno, 0));
282 dev_ofs(sb, cand->
segno, 0));
287 if (cand->
valid < full)
292 cand = add_list(cand, &super->
s_ec_list);
295 free_candidate(sb, cand);
314 __add_candidate(sb, cand);
318 static void remove_segment_from_lists(
struct super_block *sb,
u32 segno)
325 remove_from_list(cand);
326 free_candidate(sb, cand);
336 if (segment_is_reserved(sb, segno))
339 remove_segment_from_lists(sb, segno);
340 valid = logfs_valid_bytes(sb, segno, &ec, &gc_level);
341 if (valid == RESERVED)
344 dist = root_distance(sb, gc_level);
345 add_candidate(sb, segno, valid, ec, dist);
350 if (list->
count == 0)
372 for (i = max_dist; i >= 0; i--) {
378 if (this->valid + LOGFS_MAX_OBJECTSIZE <= cand->valid)
392 log_gc(
"GC attempted, but no candidate found\n");
398 valid = logfs_valid_bytes(sb, segno, &ec, &gc_level);
399 free_candidate(sb, cand);
400 log_gc(
"GC segment #%02x at %llx, %x required, %x free, %x valid, %llx free\n",
402 dist, no_free_segments(sb), valid,
404 cleaned = logfs_gc_segment(sb, segno);
405 log_gc(
"GC segment #%02x complete - now %x valid\n", segno,
415 cand = get_candidate(sb);
417 remove_from_list(cand);
418 return __logfs_gc_once(sb, cand);
441 scan_segment(sb, segno);
460 int round,
progress, last_progress = 0;
470 if (no_free_segments(sb) >= target &&
474 log_gc(
"__logfs_gc_pass(%x)\n", target);
476 if (no_free_segments(sb) >= target)
482 round += logfs_scan_some(sb);
483 if (no_free_segments(sb) >= target)
485 progress = logfs_gc_once(sb);
487 last_progress = round;
488 else if (round - last_progress > 2)
509 log_gc(
"Write back one alias\n");
512 block->
ops->write_block(block);
528 if (*next_event < super->
s_gec) {
543 wl_cand = first_in_list(&super->
s_ec_list);
551 remove_from_list(wl_cand);
552 __logfs_gc_once(sb, wl_cand);
578 static void logfs_journal_wl_pass(
struct super_block *sb)
582 u32 min_journal_ec = -1, max_reserve_ec = 0;
594 if (super->s_journal_seg[i])
595 min_journal_ec =
min(min_journal_ec,
596 super->s_journal_ec[i]);
600 for (i = 0; i < 2; i++) {
607 max_reserve_ec =
max(max_reserve_ec, ec);
610 if (min_journal_ec > max_reserve_ec + 2 *
WL_DELTA) {
628 logfs_journal_wl_pass(sb);
631 static int check_area(
struct super_block *sb,
int i)
643 if (super->
s_devops->can_write_buf(sb, ofs) == 0)
656 valid = logfs_valid_bytes(sb, segno, &ec, &gc_level);
657 cleaned = logfs_gc_segment(sb, segno);
658 if (cleaned != valid)
668 err = check_area(sb, i);
675 static void logfs_init_candlist(
struct candidate_list *list,
int maxcount,
699 static void logfs_cleanup_list(
struct super_block *sb,
704 while (list->
count) {
707 remove_from_list(cand);
708 free_candidate(sb, cand);
730 logfs_cleanup_list(sb, &super->
s_low_list[i]);
731 logfs_cleanup_list(sb, &super->
s_ec_list);