Skip to content

Commit aedcd72

Browse files
committed
blk-mq: limit memory consumption if a crash dump is active
It's not uncommon for crash dump kernels to be limited to 128MB or something low in that area. This is normally not a problem for devices as we don't use that much memory, but for some shared SCSI setups with huge queue depths, it can potentially fill most of memory with tons of request allocations. blk-mq does scale back when it fails to allocate memory, but it scales back just enough so that blk-mq succeeds. This could still leave the system with not enough memory to make any real progress. Check if we are in a kdump environment and limit the hardware queues and tag depth. Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 2edd2c7 commit aedcd72

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎block/blk-mq.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/cache.h>
2121
#include <linux/sched/sysctl.h>
2222
#include <linux/delay.h>
23+
#include <linux/crash_dump.h>
2324

2425
#include <trace/events/block.h>
2526

@@ -1742,6 +1743,16 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
17421743
if (!ctx)
17431744
return ERR_PTR(-ENOMEM);
17441745

1746+
/*
1747+
* If a crashdump is active, then we are potentially in a very
1748+
* memory constrained environment. Limit us to 1 queue and
1749+
* 64 tags to prevent using too much memory.
1750+
*/
1751+
if (is_kdump_kernel()) {
1752+
set->nr_hw_queues = 1;
1753+
set->queue_depth = min(64U, set->queue_depth);
1754+
}
1755+
17451756
hctxs = kmalloc_node(set->nr_hw_queues * sizeof(*hctxs), GFP_KERNEL,
17461757
set->numa_node);
17471758

0 commit comments

Comments
 (0)