Skip to content

Commit 3dc2f20

Browse files
ZhangPengChristoph Hellwig
authored andcommitted
swiotlb: check alloc_size before the allocation of a new memory pool
The allocation request for swiotlb contiguous memory greater than 128*2KB cannot be fulfilled because it exceeds the maximum contiguous memory limit. If the swiotlb memory we allocate is larger than 128*2KB, swiotlb_find_slots() will still schedule the allocation of a new memory pool, which will increase memory overhead. Fix it by adding a check with alloc_size no more than 128*2KB before scheduling the allocation of a new memory pool in swiotlb_find_slots(). Signed-off-by: ZhangPeng <zhangpeng362@huawei.com> Reviewed-by: Petr Tesarik <petr.tesarik1@huawei-partners.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent b07bc23 commit 3dc2f20

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

kernel/dma/swiotlb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,9 @@ static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr,
11361136
int cpu, i;
11371137
int index;
11381138

1139+
if (alloc_size > IO_TLB_SEGSIZE * IO_TLB_SIZE)
1140+
return -1;
1141+
11391142
cpu = raw_smp_processor_id();
11401143
for (i = 0; i < default_nareas; ++i) {
11411144
index = swiotlb_search_area(dev, cpu, i, orig_addr, alloc_size,

0 commit comments

Comments
 (0)