Skip to content

Commit dc4fa29

Browse files
committed
dm io tracker: factor out IO tracker
Allow other code to use dm_io_tracker. Signed-off-by: Mike Snitzer <[email protected]>
1 parent b6e58b5 commit dc4fa29

File tree

2 files changed

+75
-76
lines changed

2 files changed

+75
-76
lines changed

drivers/md/dm-cache-target.c

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "dm-bio-prison-v2.h"
99
#include "dm-bio-record.h"
1010
#include "dm-cache-metadata.h"
11+
#include "dm-io-tracker.h"
1112

1213
#include <linux/dm-io.h>
1314
#include <linux/dm-kcopyd.h>
@@ -39,77 +40,6 @@ DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(cache_copy_throttle,
3940

4041
/*----------------------------------------------------------------*/
4142

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-
11343
/*
11444
* Represents a chunk of future work. 'input' allows continuations to pass
11545
* values between themselves, typically error values.
@@ -470,7 +400,7 @@ struct cache {
470400
struct batcher committer;
471401
struct work_struct commit_ws;
472402

473-
struct io_tracker tracker;
403+
struct dm_io_tracker tracker;
474404

475405
mempool_t migration_pool;
476406

@@ -866,15 +796,15 @@ static void accounted_begin(struct cache *cache, struct bio *bio)
866796
if (accountable_bio(cache, bio)) {
867797
pb = get_per_bio_data(bio);
868798
pb->len = bio_sectors(bio);
869-
iot_io_begin(&cache->tracker, pb->len);
799+
dm_iot_io_begin(&cache->tracker, pb->len);
870800
}
871801
}
872802

873803
static void accounted_complete(struct cache *cache, struct bio *bio)
874804
{
875805
struct per_bio_data *pb = get_per_bio_data(bio);
876806

877-
iot_io_end(&cache->tracker, pb->len);
807+
dm_iot_io_end(&cache->tracker, pb->len);
878808
}
879809

880810
static void accounted_request(struct cache *cache, struct bio *bio)
@@ -1642,7 +1572,7 @@ enum busy {
16421572

16431573
static enum busy spare_migration_bandwidth(struct cache *cache)
16441574
{
1645-
bool idle = iot_idle_for(&cache->tracker, HZ);
1575+
bool idle = dm_iot_idle_for(&cache->tracker, HZ);
16461576
sector_t current_volume = (atomic_read(&cache->nr_io_migrations) + 1) *
16471577
cache->sectors_per_block;
16481578

@@ -2603,7 +2533,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)
26032533

26042534
batcher_init(&cache->committer, commit_op, cache,
26052535
issue_op, cache, cache->wq);
2606-
iot_init(&cache->tracker);
2536+
dm_iot_init(&cache->tracker);
26072537

26082538
init_rwsem(&cache->background_work_lock);
26092539
prevent_background_work(cache);

drivers/md/dm-io-tracker.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (C) 2021 Red Hat, Inc. All rights reserved.
3+
*
4+
* This file is released under the GPL.
5+
*/
6+
7+
#ifndef DM_IO_TRACKER_H
8+
#define DM_IO_TRACKER_H
9+
10+
#include <linux/jiffies.h>
11+
12+
struct dm_io_tracker {
13+
spinlock_t lock;
14+
15+
/*
16+
* Sectors of in-flight IO.
17+
*/
18+
sector_t in_flight;
19+
20+
/*
21+
* The time, in jiffies, when this device became idle
22+
* (if it is indeed idle).
23+
*/
24+
unsigned long idle_time;
25+
unsigned long last_update_time;
26+
};
27+
28+
static inline void dm_iot_init(struct dm_io_tracker *iot)
29+
{
30+
spin_lock_init(&iot->lock);
31+
iot->in_flight = 0ul;
32+
iot->idle_time = 0ul;
33+
iot->last_update_time = jiffies;
34+
}
35+
36+
static inline bool dm_iot_idle_for(struct dm_io_tracker *iot, unsigned long j)
37+
{
38+
bool r = false;
39+
40+
spin_lock_irq(&iot->lock);
41+
if (!iot->in_flight)
42+
r = time_after(jiffies, iot->idle_time + j);
43+
spin_unlock_irq(&iot->lock);
44+
45+
return r;
46+
}
47+
48+
static inline void dm_iot_io_begin(struct dm_io_tracker *iot, sector_t len)
49+
{
50+
spin_lock_irq(&iot->lock);
51+
iot->in_flight += len;
52+
spin_unlock_irq(&iot->lock);
53+
}
54+
55+
static inline void dm_iot_io_end(struct dm_io_tracker *iot, sector_t len)
56+
{
57+
unsigned long flags;
58+
59+
if (!len)
60+
return;
61+
62+
spin_lock_irqsave(&iot->lock, flags);
63+
iot->in_flight -= len;
64+
if (!iot->in_flight)
65+
iot->idle_time = jiffies;
66+
spin_unlock_irqrestore(&iot->lock, flags);
67+
}
68+
69+
#endif

0 commit comments

Comments
 (0)