• Home
  • Raw
  • Download

Lines Matching refs:dc

21 static void __update_writeback_rate(struct cached_dev *dc)  in __update_writeback_rate()  argument
23 struct cache_set *c = dc->disk.c; in __update_writeback_rate()
27 div_u64(cache_sectors * dc->writeback_percent, 100); in __update_writeback_rate()
29 int64_t target = div64_u64(cache_dirty_target * bdev_sectors(dc->bdev), in __update_writeback_rate()
34 int64_t dirty = bcache_dev_sectors_dirty(&dc->disk); in __update_writeback_rate()
35 int64_t derivative = dirty - dc->disk.sectors_dirty_last; in __update_writeback_rate()
39 dc->disk.sectors_dirty_last = dirty; in __update_writeback_rate()
43 proportional *= dc->writeback_rate_update_seconds; in __update_writeback_rate()
44 proportional = div_s64(proportional, dc->writeback_rate_p_term_inverse); in __update_writeback_rate()
46 derivative = div_s64(derivative, dc->writeback_rate_update_seconds); in __update_writeback_rate()
48 derivative = ewma_add(dc->disk.sectors_dirty_derivative, derivative, in __update_writeback_rate()
49 (dc->writeback_rate_d_term / in __update_writeback_rate()
50 dc->writeback_rate_update_seconds) ?: 1, 0); in __update_writeback_rate()
52 derivative *= dc->writeback_rate_d_term; in __update_writeback_rate()
53 derivative = div_s64(derivative, dc->writeback_rate_p_term_inverse); in __update_writeback_rate()
60 dc->writeback_rate.next + NSEC_PER_MSEC)) in __update_writeback_rate()
63 dc->writeback_rate.rate = in __update_writeback_rate()
64 clamp_t(int64_t, (int64_t) dc->writeback_rate.rate + change, in __update_writeback_rate()
67 dc->writeback_rate_proportional = proportional; in __update_writeback_rate()
68 dc->writeback_rate_derivative = derivative; in __update_writeback_rate()
69 dc->writeback_rate_change = change; in __update_writeback_rate()
70 dc->writeback_rate_target = target; in __update_writeback_rate()
75 struct cached_dev *dc = container_of(to_delayed_work(work), in update_writeback_rate() local
79 down_read(&dc->writeback_lock); in update_writeback_rate()
81 if (atomic_read(&dc->has_dirty) && in update_writeback_rate()
82 dc->writeback_percent) in update_writeback_rate()
83 __update_writeback_rate(dc); in update_writeback_rate()
85 up_read(&dc->writeback_lock); in update_writeback_rate()
87 schedule_delayed_work(&dc->writeback_rate_update, in update_writeback_rate()
88 dc->writeback_rate_update_seconds * HZ); in update_writeback_rate()
91 static unsigned writeback_delay(struct cached_dev *dc, unsigned sectors) in writeback_delay() argument
93 if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags) || in writeback_delay()
94 !dc->writeback_percent) in writeback_delay()
97 return bch_next_delay(&dc->writeback_rate, sectors); in writeback_delay()
102 struct cached_dev *dc; member
112 if (!io->dc->writeback_percent) in dirty_init()
132 struct cached_dev *dc = io->dc; in write_dirty_finish() local
152 atomic_inc(&PTR_BUCKET(dc->disk.c, &w->key, i)->pin); in write_dirty_finish()
154 ret = bch_btree_insert(dc->disk.c, &keys, NULL, &w->key); in write_dirty_finish()
160 ? &dc->disk.c->writeback_keys_failed in write_dirty_finish()
161 : &dc->disk.c->writeback_keys_done); in write_dirty_finish()
164 bch_keybuf_del(&dc->writeback_keys, w); in write_dirty_finish()
165 up(&dc->in_flight); in write_dirty_finish()
189 io->bio.bi_bdev = io->dc->bdev; in write_dirty()
192 closure_bio_submit(&io->bio, cl, &io->dc->disk); in write_dirty()
194 continue_at(cl, write_dirty_finish, io->dc->writeback_write_wq); in write_dirty()
202 bch_count_io_errors(PTR_CACHE(io->dc->disk.c, &w->key, 0), in read_dirty_endio()
212 closure_bio_submit(&io->bio, cl, &io->dc->disk); in read_dirty_submit()
214 continue_at(cl, write_dirty, io->dc->writeback_write_wq); in read_dirty_submit()
217 static void read_dirty(struct cached_dev *dc) in read_dirty() argument
234 w = bch_keybuf_next(&dc->writeback_keys); in read_dirty()
238 BUG_ON(ptr_stale(dc->disk.c, &w->key, 0)); in read_dirty()
240 if (KEY_START(&w->key) != dc->last_read || in read_dirty()
245 dc->last_read = KEY_OFFSET(&w->key); in read_dirty()
254 io->dc = dc; in read_dirty()
258 io->bio.bi_bdev = PTR_CACHE(dc->disk.c, in read_dirty()
268 down(&dc->in_flight); in read_dirty()
271 delay = writeback_delay(dc, KEY_SIZE(&w->key)); in read_dirty()
278 bch_keybuf_del(&dc->writeback_keys, w); in read_dirty()
327 struct cached_dev *dc = container_of(buf, struct cached_dev, writeback_keys); in dirty_pred() local
329 BUG_ON(KEY_INODE(k) != dc->disk.id); in dirty_pred()
334 static void refill_full_stripes(struct cached_dev *dc) in refill_full_stripes() argument
336 struct keybuf *buf = &dc->writeback_keys; in refill_full_stripes()
340 stripe = offset_to_stripe(&dc->disk, KEY_OFFSET(&buf->last_scanned)); in refill_full_stripes()
342 if (stripe >= dc->disk.nr_stripes) in refill_full_stripes()
348 stripe = find_next_bit(dc->disk.full_dirty_stripes, in refill_full_stripes()
349 dc->disk.nr_stripes, stripe); in refill_full_stripes()
351 if (stripe == dc->disk.nr_stripes) in refill_full_stripes()
354 next_stripe = find_next_zero_bit(dc->disk.full_dirty_stripes, in refill_full_stripes()
355 dc->disk.nr_stripes, stripe); in refill_full_stripes()
357 buf->last_scanned = KEY(dc->disk.id, in refill_full_stripes()
358 stripe * dc->disk.stripe_size, 0); in refill_full_stripes()
360 bch_refill_keybuf(dc->disk.c, buf, in refill_full_stripes()
361 &KEY(dc->disk.id, in refill_full_stripes()
362 next_stripe * dc->disk.stripe_size, 0), in refill_full_stripes()
373 if (stripe == dc->disk.nr_stripes) { in refill_full_stripes()
383 static bool refill_dirty(struct cached_dev *dc) in refill_dirty() argument
385 struct keybuf *buf = &dc->writeback_keys; in refill_dirty()
386 struct bkey start = KEY(dc->disk.id, 0, 0); in refill_dirty()
387 struct bkey end = KEY(dc->disk.id, MAX_KEY_OFFSET, 0); in refill_dirty()
399 if (dc->partial_stripes_expensive) { in refill_dirty()
400 refill_full_stripes(dc); in refill_dirty()
406 bch_refill_keybuf(dc->disk.c, buf, &end, dirty_pred); in refill_dirty()
416 bch_refill_keybuf(dc->disk.c, buf, &start_pos, dirty_pred); in refill_dirty()
423 struct cached_dev *dc = arg; in bch_writeback_thread() local
427 down_write(&dc->writeback_lock); in bch_writeback_thread()
428 if (!atomic_read(&dc->has_dirty) || in bch_writeback_thread()
429 (!test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags) && in bch_writeback_thread()
430 !dc->writeback_running)) { in bch_writeback_thread()
431 up_write(&dc->writeback_lock); in bch_writeback_thread()
442 searched_full_index = refill_dirty(dc); in bch_writeback_thread()
445 RB_EMPTY_ROOT(&dc->writeback_keys.keys)) { in bch_writeback_thread()
446 atomic_set(&dc->has_dirty, 0); in bch_writeback_thread()
447 cached_dev_put(dc); in bch_writeback_thread()
448 SET_BDEV_STATE(&dc->sb, BDEV_STATE_CLEAN); in bch_writeback_thread()
449 bch_write_bdev_super(dc, NULL); in bch_writeback_thread()
452 up_write(&dc->writeback_lock); in bch_writeback_thread()
454 bch_ratelimit_reset(&dc->writeback_rate); in bch_writeback_thread()
455 read_dirty(dc); in bch_writeback_thread()
458 unsigned delay = dc->writeback_delay * HZ; in bch_writeback_thread()
462 !test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags)) in bch_writeback_thread()
505 void bch_cached_dev_writeback_init(struct cached_dev *dc) in bch_cached_dev_writeback_init() argument
507 sema_init(&dc->in_flight, 64); in bch_cached_dev_writeback_init()
508 init_rwsem(&dc->writeback_lock); in bch_cached_dev_writeback_init()
509 bch_keybuf_init(&dc->writeback_keys); in bch_cached_dev_writeback_init()
511 dc->writeback_metadata = true; in bch_cached_dev_writeback_init()
512 dc->writeback_running = true; in bch_cached_dev_writeback_init()
513 dc->writeback_percent = 10; in bch_cached_dev_writeback_init()
514 dc->writeback_delay = 30; in bch_cached_dev_writeback_init()
515 dc->writeback_rate.rate = 1024; in bch_cached_dev_writeback_init()
517 dc->writeback_rate_update_seconds = 5; in bch_cached_dev_writeback_init()
518 dc->writeback_rate_d_term = 30; in bch_cached_dev_writeback_init()
519 dc->writeback_rate_p_term_inverse = 6000; in bch_cached_dev_writeback_init()
521 INIT_DELAYED_WORK(&dc->writeback_rate_update, update_writeback_rate); in bch_cached_dev_writeback_init()
524 int bch_cached_dev_writeback_start(struct cached_dev *dc) in bch_cached_dev_writeback_start() argument
526 dc->writeback_write_wq = alloc_workqueue("bcache_writeback_wq", in bch_cached_dev_writeback_start()
528 if (!dc->writeback_write_wq) in bch_cached_dev_writeback_start()
531 dc->writeback_thread = kthread_create(bch_writeback_thread, dc, in bch_cached_dev_writeback_start()
533 if (IS_ERR(dc->writeback_thread)) in bch_cached_dev_writeback_start()
534 return PTR_ERR(dc->writeback_thread); in bch_cached_dev_writeback_start()
536 schedule_delayed_work(&dc->writeback_rate_update, in bch_cached_dev_writeback_start()
537 dc->writeback_rate_update_seconds * HZ); in bch_cached_dev_writeback_start()
539 bch_writeback_queue(dc); in bch_cached_dev_writeback_start()