.. | .. |
---|
56 | 56 | size_t percpu_alloc_size; |
---|
57 | 57 | size_t histogram_alloc_size; |
---|
58 | 58 | struct dm_stat_percpu *stat_percpu[NR_CPUS]; |
---|
59 | | - struct dm_stat_shared stat_shared[0]; |
---|
| 59 | + struct dm_stat_shared stat_shared[]; |
---|
60 | 60 | }; |
---|
61 | 61 | |
---|
62 | 62 | #define STAT_PRECISE_TIMESTAMPS 1 |
---|
.. | .. |
---|
85 | 85 | a = shared_memory_amount + alloc_size; |
---|
86 | 86 | if (a < shared_memory_amount) |
---|
87 | 87 | return false; |
---|
88 | | - if (a >> PAGE_SHIFT > totalram_pages / DM_STATS_MEMORY_FACTOR) |
---|
| 88 | + if (a >> PAGE_SHIFT > totalram_pages() / DM_STATS_MEMORY_FACTOR) |
---|
89 | 89 | return false; |
---|
90 | 90 | #ifdef CONFIG_MMU |
---|
91 | 91 | if (a > (VMALLOC_END - VMALLOC_START) / DM_STATS_VMALLOC_FACTOR) |
---|
.. | .. |
---|
188 | 188 | atomic_read(&shared->in_flight[WRITE]); |
---|
189 | 189 | } |
---|
190 | 190 | |
---|
191 | | -void dm_stats_init(struct dm_stats *stats) |
---|
| 191 | +int dm_stats_init(struct dm_stats *stats) |
---|
192 | 192 | { |
---|
193 | 193 | int cpu; |
---|
194 | 194 | struct dm_stats_last_position *last; |
---|
.. | .. |
---|
196 | 196 | mutex_init(&stats->mutex); |
---|
197 | 197 | INIT_LIST_HEAD(&stats->list); |
---|
198 | 198 | stats->last = alloc_percpu(struct dm_stats_last_position); |
---|
| 199 | + if (!stats->last) |
---|
| 200 | + return -ENOMEM; |
---|
| 201 | + |
---|
199 | 202 | for_each_possible_cpu(cpu) { |
---|
200 | 203 | last = per_cpu_ptr(stats->last, cpu); |
---|
201 | 204 | last->last_sector = (sector_t)ULLONG_MAX; |
---|
202 | 205 | last->last_rw = UINT_MAX; |
---|
203 | 206 | } |
---|
| 207 | + |
---|
| 208 | + return 0; |
---|
204 | 209 | } |
---|
205 | 210 | |
---|
206 | 211 | void dm_stats_cleanup(struct dm_stats *stats) |
---|
.. | .. |
---|
224 | 229 | atomic_read(&shared->in_flight[READ]), |
---|
225 | 230 | atomic_read(&shared->in_flight[WRITE])); |
---|
226 | 231 | } |
---|
| 232 | + cond_resched(); |
---|
227 | 233 | } |
---|
228 | 234 | dm_stat_free(&s->rcu_head); |
---|
229 | 235 | } |
---|
.. | .. |
---|
262 | 268 | if (n_entries != (size_t)n_entries || !(size_t)(n_entries + 1)) |
---|
263 | 269 | return -EOVERFLOW; |
---|
264 | 270 | |
---|
265 | | - shared_alloc_size = sizeof(struct dm_stat) + (size_t)n_entries * sizeof(struct dm_stat_shared); |
---|
| 271 | + shared_alloc_size = struct_size(s, stat_shared, n_entries); |
---|
266 | 272 | if ((shared_alloc_size - sizeof(struct dm_stat)) / sizeof(struct dm_stat_shared) != n_entries) |
---|
267 | 273 | return -EOVERFLOW; |
---|
268 | 274 | |
---|
.. | .. |
---|
313 | 319 | for (ni = 0; ni < n_entries; ni++) { |
---|
314 | 320 | atomic_set(&s->stat_shared[ni].in_flight[READ], 0); |
---|
315 | 321 | atomic_set(&s->stat_shared[ni].in_flight[WRITE], 0); |
---|
| 322 | + cond_resched(); |
---|
316 | 323 | } |
---|
317 | 324 | |
---|
318 | 325 | if (s->n_histogram_entries) { |
---|
.. | .. |
---|
325 | 332 | for (ni = 0; ni < n_entries; ni++) { |
---|
326 | 333 | s->stat_shared[ni].tmp.histogram = hi; |
---|
327 | 334 | hi += s->n_histogram_entries + 1; |
---|
| 335 | + cond_resched(); |
---|
328 | 336 | } |
---|
329 | 337 | } |
---|
330 | 338 | |
---|
.. | .. |
---|
345 | 353 | for (ni = 0; ni < n_entries; ni++) { |
---|
346 | 354 | p[ni].histogram = hi; |
---|
347 | 355 | hi += s->n_histogram_entries + 1; |
---|
| 356 | + cond_resched(); |
---|
348 | 357 | } |
---|
349 | 358 | } |
---|
350 | 359 | } |
---|
.. | .. |
---|
474 | 483 | } |
---|
475 | 484 | DMEMIT("\n"); |
---|
476 | 485 | } |
---|
| 486 | + cond_resched(); |
---|
477 | 487 | } |
---|
478 | 488 | mutex_unlock(&stats->mutex); |
---|
479 | 489 | |
---|
.. | .. |
---|
750 | 760 | local_irq_enable(); |
---|
751 | 761 | } |
---|
752 | 762 | } |
---|
| 763 | + cond_resched(); |
---|
753 | 764 | } |
---|
754 | 765 | } |
---|
755 | 766 | |
---|
.. | .. |
---|
865 | 876 | |
---|
866 | 877 | if (unlikely(sz + 1 >= maxlen)) |
---|
867 | 878 | goto buffer_overflow; |
---|
| 879 | + |
---|
| 880 | + cond_resched(); |
---|
868 | 881 | } |
---|
869 | 882 | |
---|
870 | 883 | if (clear) |
---|