io.c (6f10f7d1b02b1bbc305f88d7696445dd38b13881) io.c (1fae7cf05293d3a2c9e59c1bc59372322386467c)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Some low level IO code, and hacks for various block layer limitations
4 *
5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
6 * Copyright 2012 Google, Inc.
7 */
8
9#include "bcache.h"
10#include "bset.h"
11#include "debug.h"
12
13#include <linux/blkdev.h>
14
15/* Bios with headers */
16
17void bch_bbio_free(struct bio *bio, struct cache_set *c)
18{
19 struct bbio *b = container_of(bio, struct bbio, bio);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Some low level IO code, and hacks for various block layer limitations
4 *
5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
6 * Copyright 2012 Google, Inc.
7 */
8
9#include "bcache.h"
10#include "bset.h"
11#include "debug.h"
12
13#include <linux/blkdev.h>
14
15/* Bios with headers */
16
17void bch_bbio_free(struct bio *bio, struct cache_set *c)
18{
19 struct bbio *b = container_of(bio, struct bbio, bio);
20
20 mempool_free(b, &c->bio_meta);
21}
22
23struct bio *bch_bbio_alloc(struct cache_set *c)
24{
25 struct bbio *b = mempool_alloc(&c->bio_meta, GFP_NOIO);
26 struct bio *bio = &b->bio;
27

--- 12 unchanged lines hidden (view full) ---

40 b->submit_time_us = local_clock_us();
41 closure_bio_submit(c, bio, bio->bi_private);
42}
43
44void bch_submit_bbio(struct bio *bio, struct cache_set *c,
45 struct bkey *k, unsigned int ptr)
46{
47 struct bbio *b = container_of(bio, struct bbio, bio);
21 mempool_free(b, &c->bio_meta);
22}
23
24struct bio *bch_bbio_alloc(struct cache_set *c)
25{
26 struct bbio *b = mempool_alloc(&c->bio_meta, GFP_NOIO);
27 struct bio *bio = &b->bio;
28

--- 12 unchanged lines hidden (view full) ---

41 b->submit_time_us = local_clock_us();
42 closure_bio_submit(c, bio, bio->bi_private);
43}
44
45void bch_submit_bbio(struct bio *bio, struct cache_set *c,
46 struct bkey *k, unsigned int ptr)
47{
48 struct bbio *b = container_of(bio, struct bbio, bio);
49
48 bch_bkey_copy_single_ptr(&b->key, k, ptr);
49 __bch_submit_bbio(bio, c);
50}
51
52/* IO errors */
53void bch_count_backing_io_errors(struct cached_dev *dc, struct bio *bio)
54{
55 unsigned int errors;

--- 71 unchanged lines hidden (view full) ---

127 int is_read = (bio_data_dir(bio) == READ ? 1 : 0);
128
129 unsigned int threshold = op_is_write(bio_op(bio))
130 ? c->congested_write_threshold_us
131 : c->congested_read_threshold_us;
132
133 if (threshold) {
134 unsigned int t = local_clock_us();
50 bch_bkey_copy_single_ptr(&b->key, k, ptr);
51 __bch_submit_bbio(bio, c);
52}
53
54/* IO errors */
55void bch_count_backing_io_errors(struct cached_dev *dc, struct bio *bio)
56{
57 unsigned int errors;

--- 71 unchanged lines hidden (view full) ---

129 int is_read = (bio_data_dir(bio) == READ ? 1 : 0);
130
131 unsigned int threshold = op_is_write(bio_op(bio))
132 ? c->congested_write_threshold_us
133 : c->congested_read_threshold_us;
134
135 if (threshold) {
136 unsigned int t = local_clock_us();
135
136 int us = t - b->submit_time_us;
137 int congested = atomic_read(&c->congested);
138
139 if (us > (int) threshold) {
140 int ms = us / 1024;
137 int us = t - b->submit_time_us;
138 int congested = atomic_read(&c->congested);
139
140 if (us > (int) threshold) {
141 int ms = us / 1024;
142
141 c->congested_last_us = t;
142
143 ms = min(ms, CONGESTED_MAX + congested);
144 atomic_sub(ms, &c->congested);
145 } else if (congested < 0)
146 atomic_inc(&c->congested);
147 }
148

--- 12 unchanged lines hidden ---
143 c->congested_last_us = t;
144
145 ms = min(ms, CONGESTED_MAX + congested);
146 atomic_sub(ms, &c->congested);
147 } else if (congested < 0)
148 atomic_inc(&c->congested);
149 }
150

--- 12 unchanged lines hidden ---