|
8 | 8 | #include "dm-bio-prison-v2.h"
|
9 | 9 | #include "dm-bio-record.h"
|
10 | 10 | #include "dm-cache-metadata.h"
|
| 11 | +#include "dm-io-tracker.h" |
11 | 12 |
|
12 | 13 | #include <linux/dm-io.h>
|
13 | 14 | #include <linux/dm-kcopyd.h>
|
@@ -39,77 +40,6 @@ DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(cache_copy_throttle,
|
39 | 40 |
|
40 | 41 | /*----------------------------------------------------------------*/
|
41 | 42 |
|
42 |
| -struct io_tracker { |
43 |
| - spinlock_t lock; |
44 |
| - |
45 |
| - /* |
46 |
| - * Sectors of in-flight IO. |
47 |
| - */ |
48 |
| - sector_t in_flight; |
49 |
| - |
50 |
| - /* |
51 |
| - * The time, in jiffies, when this device became idle (if it is |
52 |
| - * indeed idle). |
53 |
| - */ |
54 |
| - unsigned long idle_time; |
55 |
| - unsigned long last_update_time; |
56 |
| -}; |
57 |
| - |
58 |
| -static void iot_init(struct io_tracker *iot) |
59 |
| -{ |
60 |
| - spin_lock_init(&iot->lock); |
61 |
| - iot->in_flight = 0ul; |
62 |
| - iot->idle_time = 0ul; |
63 |
| - iot->last_update_time = jiffies; |
64 |
| -} |
65 |
| - |
66 |
| -static bool __iot_idle_for(struct io_tracker *iot, unsigned long jifs) |
67 |
| -{ |
68 |
| - if (iot->in_flight) |
69 |
| - return false; |
70 |
| - |
71 |
| - return time_after(jiffies, iot->idle_time + jifs); |
72 |
| -} |
73 |
| - |
74 |
| -static bool iot_idle_for(struct io_tracker *iot, unsigned long jifs) |
75 |
| -{ |
76 |
| - bool r; |
77 |
| - |
78 |
| - spin_lock_irq(&iot->lock); |
79 |
| - r = __iot_idle_for(iot, jifs); |
80 |
| - spin_unlock_irq(&iot->lock); |
81 |
| - |
82 |
| - return r; |
83 |
| -} |
84 |
| - |
85 |
| -static void iot_io_begin(struct io_tracker *iot, sector_t len) |
86 |
| -{ |
87 |
| - spin_lock_irq(&iot->lock); |
88 |
| - iot->in_flight += len; |
89 |
| - spin_unlock_irq(&iot->lock); |
90 |
| -} |
91 |
| - |
92 |
| -static void __iot_io_end(struct io_tracker *iot, sector_t len) |
93 |
| -{ |
94 |
| - if (!len) |
95 |
| - return; |
96 |
| - |
97 |
| - iot->in_flight -= len; |
98 |
| - if (!iot->in_flight) |
99 |
| - iot->idle_time = jiffies; |
100 |
| -} |
101 |
| - |
102 |
| -static void iot_io_end(struct io_tracker *iot, sector_t len) |
103 |
| -{ |
104 |
| - unsigned long flags; |
105 |
| - |
106 |
| - spin_lock_irqsave(&iot->lock, flags); |
107 |
| - __iot_io_end(iot, len); |
108 |
| - spin_unlock_irqrestore(&iot->lock, flags); |
109 |
| -} |
110 |
| - |
111 |
| -/*----------------------------------------------------------------*/ |
112 |
| - |
113 | 43 | /*
|
114 | 44 | * Represents a chunk of future work. 'input' allows continuations to pass
|
115 | 45 | * values between themselves, typically error values.
|
@@ -470,7 +400,7 @@ struct cache {
|
470 | 400 | struct batcher committer;
|
471 | 401 | struct work_struct commit_ws;
|
472 | 402 |
|
473 |
| - struct io_tracker tracker; |
| 403 | + struct dm_io_tracker tracker; |
474 | 404 |
|
475 | 405 | mempool_t migration_pool;
|
476 | 406 |
|
@@ -866,15 +796,15 @@ static void accounted_begin(struct cache *cache, struct bio *bio)
|
866 | 796 | if (accountable_bio(cache, bio)) {
|
867 | 797 | pb = get_per_bio_data(bio);
|
868 | 798 | pb->len = bio_sectors(bio);
|
869 |
| - iot_io_begin(&cache->tracker, pb->len); |
| 799 | + dm_iot_io_begin(&cache->tracker, pb->len); |
870 | 800 | }
|
871 | 801 | }
|
872 | 802 |
|
873 | 803 | static void accounted_complete(struct cache *cache, struct bio *bio)
|
874 | 804 | {
|
875 | 805 | struct per_bio_data *pb = get_per_bio_data(bio);
|
876 | 806 |
|
877 |
| - iot_io_end(&cache->tracker, pb->len); |
| 807 | + dm_iot_io_end(&cache->tracker, pb->len); |
878 | 808 | }
|
879 | 809 |
|
880 | 810 | static void accounted_request(struct cache *cache, struct bio *bio)
|
@@ -1642,7 +1572,7 @@ enum busy {
|
1642 | 1572 |
|
1643 | 1573 | static enum busy spare_migration_bandwidth(struct cache *cache)
|
1644 | 1574 | {
|
1645 |
| - bool idle = iot_idle_for(&cache->tracker, HZ); |
| 1575 | + bool idle = dm_iot_idle_for(&cache->tracker, HZ); |
1646 | 1576 | sector_t current_volume = (atomic_read(&cache->nr_io_migrations) + 1) *
|
1647 | 1577 | cache->sectors_per_block;
|
1648 | 1578 |
|
@@ -2603,7 +2533,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)
|
2603 | 2533 |
|
2604 | 2534 | batcher_init(&cache->committer, commit_op, cache,
|
2605 | 2535 | issue_op, cache, cache->wq);
|
2606 |
| - iot_init(&cache->tracker); |
| 2536 | + dm_iot_init(&cache->tracker); |
2607 | 2537 |
|
2608 | 2538 | init_rwsem(&cache->background_work_lock);
|
2609 | 2539 | prevent_background_work(cache);
|
|
0 commit comments