Skip to content

Commit 37a098e

Browse files
committed
dm round robin: revert "use percpu 'repeat_count' and 'current_path'"
The sloppy nature of lockless access to percpu pointers (s->current_path) in rr_select_path(), from multiple threads, is causing some paths to used more than others -- which results in less IO performance being observed. Revert these upstream commits to restore truly symmetric round-robin IO submission in DM multipath: b0b477c dm round robin: use percpu 'repeat_count' and 'current_path' 802934b dm round robin: do not use this_cpu_ptr() without having preemption disabled There is no benefit to all this complexity if repeat_count = 1 (which is the recommended default). Cc: stable@vger.kernel.org # 4.6+ Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent 6085831 commit 37a098e

1 file changed

Lines changed: 14 additions & 53 deletions

File tree

‎drivers/md/dm-round-robin.c‎

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include <linux/module.h>
1818

1919
#define DM_MSG_PREFIX "multipath round-robin"
20-
#define RR_MIN_IO 1000
21-
#define RR_VERSION "1.1.0"
20+
#define RR_MIN_IO 1
21+
#define RR_VERSION "1.2.0"
2222

2323
/*-----------------------------------------------------------------
2424
* Path-handling code, paths are held in lists
@@ -47,44 +47,19 @@ struct selector {
4747
struct list_head valid_paths;
4848
struct list_head invalid_paths;
4949
spinlock_t lock;
50-
struct dm_path * __percpu *current_path;
51-
struct percpu_counter repeat_count;
5250
};
5351

54-
static void set_percpu_current_path(struct selector *s, struct dm_path *path)
55-
{
56-
int cpu;
57-
58-
for_each_possible_cpu(cpu)
59-
*per_cpu_ptr(s->current_path, cpu) = path;
60-
}
61-
6252
static struct selector *alloc_selector(void)
6353
{
6454
struct selector *s = kmalloc(sizeof(*s), GFP_KERNEL);
6555

66-
if (!s)
67-
return NULL;
68-
69-
INIT_LIST_HEAD(&s->valid_paths);
70-
INIT_LIST_HEAD(&s->invalid_paths);
71-
spin_lock_init(&s->lock);
72-
73-
s->current_path = alloc_percpu(struct dm_path *);
74-
if (!s->current_path)
75-
goto out_current_path;
76-
set_percpu_current_path(s, NULL);
77-
78-
if (percpu_counter_init(&s->repeat_count, 0, GFP_KERNEL))
79-
goto out_repeat_count;
56+
if (s) {
57+
INIT_LIST_HEAD(&s->valid_paths);
58+
INIT_LIST_HEAD(&s->invalid_paths);
59+
spin_lock_init(&s->lock);
60+
}
8061

8162
return s;
82-
83-
out_repeat_count:
84-
free_percpu(s->current_path);
85-
out_current_path:
86-
kfree(s);
87-
return NULL;;
8863
}
8964

9065
static int rr_create(struct path_selector *ps, unsigned argc, char **argv)
@@ -105,8 +80,6 @@ static void rr_destroy(struct path_selector *ps)
10580

10681
free_paths(&s->valid_paths);
10782
free_paths(&s->invalid_paths);
108-
free_percpu(s->current_path);
109-
percpu_counter_destroy(&s->repeat_count);
11083
kfree(s);
11184
ps->context = NULL;
11285
}
@@ -157,6 +130,11 @@ static int rr_add_path(struct path_selector *ps, struct dm_path *path,
157130
return -EINVAL;
158131
}
159132

133+
if (repeat_count > 1) {
134+
DMWARN_LIMIT("repeat_count > 1 is deprecated, using 1 instead");
135+
repeat_count = 1;
136+
}
137+
160138
/* allocate the path */
161139
pi = kmalloc(sizeof(*pi), GFP_KERNEL);
162140
if (!pi) {
@@ -183,9 +161,6 @@ static void rr_fail_path(struct path_selector *ps, struct dm_path *p)
183161
struct path_info *pi = p->pscontext;
184162

185163
spin_lock_irqsave(&s->lock, flags);
186-
if (p == *this_cpu_ptr(s->current_path))
187-
set_percpu_current_path(s, NULL);
188-
189164
list_move(&pi->list, &s->invalid_paths);
190165
spin_unlock_irqrestore(&s->lock, flags);
191166
}
@@ -208,29 +183,15 @@ static struct dm_path *rr_select_path(struct path_selector *ps, size_t nr_bytes)
208183
unsigned long flags;
209184
struct selector *s = ps->context;
210185
struct path_info *pi = NULL;
211-
struct dm_path *current_path = NULL;
212-
213-
local_irq_save(flags);
214-
current_path = *this_cpu_ptr(s->current_path);
215-
if (current_path) {
216-
percpu_counter_dec(&s->repeat_count);
217-
if (percpu_counter_read_positive(&s->repeat_count) > 0) {
218-
local_irq_restore(flags);
219-
return current_path;
220-
}
221-
}
222186

223-
spin_lock(&s->lock);
187+
spin_lock_irqsave(&s->lock, flags);
224188
if (!list_empty(&s->valid_paths)) {
225189
pi = list_entry(s->valid_paths.next, struct path_info, list);
226190
list_move_tail(&pi->list, &s->valid_paths);
227-
percpu_counter_set(&s->repeat_count, pi->repeat_count);
228-
set_percpu_current_path(s, pi->path);
229-
current_path = pi->path;
230191
}
231192
spin_unlock_irqrestore(&s->lock, flags);
232193

233-
return current_path;
194+
return pi ? pi->path : NULL;
234195
}
235196

236197
static struct path_selector_type rr_ps = {

0 commit comments

Comments
 (0)