Skip to content

Commit bfe2b01

Browse files
Mikulas PatockaMike Snitzer
authored andcommitted
dm stats: add cond_resched when looping over entries
dm-stats can be used with a very large number of entries (it is only limited by 1/4 of total system memory), so add rescheduling points to the loops that iterate over the entries. Cc: stable@vger.kernel.org Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent 4edadf6 commit bfe2b01

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/md/dm-stats.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ void dm_stats_cleanup(struct dm_stats *stats)
225225
atomic_read(&shared->in_flight[READ]),
226226
atomic_read(&shared->in_flight[WRITE]));
227227
}
228+
cond_resched();
228229
}
229230
dm_stat_free(&s->rcu_head);
230231
}
@@ -330,6 +331,7 @@ static int dm_stats_create(struct dm_stats *stats, sector_t start, sector_t end,
330331
for (ni = 0; ni < n_entries; ni++) {
331332
atomic_set(&s->stat_shared[ni].in_flight[READ], 0);
332333
atomic_set(&s->stat_shared[ni].in_flight[WRITE], 0);
334+
cond_resched();
333335
}
334336

335337
if (s->n_histogram_entries) {
@@ -342,6 +344,7 @@ static int dm_stats_create(struct dm_stats *stats, sector_t start, sector_t end,
342344
for (ni = 0; ni < n_entries; ni++) {
343345
s->stat_shared[ni].tmp.histogram = hi;
344346
hi += s->n_histogram_entries + 1;
347+
cond_resched();
345348
}
346349
}
347350

@@ -362,6 +365,7 @@ static int dm_stats_create(struct dm_stats *stats, sector_t start, sector_t end,
362365
for (ni = 0; ni < n_entries; ni++) {
363366
p[ni].histogram = hi;
364367
hi += s->n_histogram_entries + 1;
368+
cond_resched();
365369
}
366370
}
367371
}
@@ -500,6 +504,7 @@ static int dm_stats_list(struct dm_stats *stats, const char *program,
500504
}
501505
DMEMIT("\n");
502506
}
507+
cond_resched();
503508
}
504509
mutex_unlock(&stats->mutex);
505510

@@ -777,6 +782,7 @@ static void __dm_stat_clear(struct dm_stat *s, size_t idx_start, size_t idx_end,
777782
local_irq_enable();
778783
}
779784
}
785+
cond_resched();
780786
}
781787
}
782788

@@ -892,6 +898,8 @@ static int dm_stats_print(struct dm_stats *stats, int id,
892898

893899
if (unlikely(sz + 1 >= maxlen))
894900
goto buffer_overflow;
901+
902+
cond_resched();
895903
}
896904

897905
if (clear)

0 commit comments

Comments
 (0)