Skip to content

Commit 20347fc

Browse files
Tianyu LanChristoph Hellwig
authored andcommitted
swiotlb: split up the global swiotlb lock
Traditionally swiotlb was not performance critical because it was only used for slow devices. But in some setups, like TDX/SEV confidential guests, all IO has to go through swiotlb. Currently swiotlb only has a single lock. Under high IO load with multiple CPUs this can lead to significat lock contention on the swiotlb lock. This patch splits the swiotlb bounce buffer pool into individual areas which have their own lock. Each CPU tries to allocate in its own area first. Only if that fails does it search other areas. On freeing the allocation is freed into the area where the memory was originally allocated from. Area number can be set via swiotlb kernel parameter and is default to be possible cpu number. If possible cpu number is not power of 2, area number will be round up to the next power of 2. This idea from Andi Kleen patch(https://github.com/intel/tdx/commit/ 4529b5784c141782c72ec9bd9a92df2b68cb7d45). Based-on-idea-by: Andi Kleen <[email protected]> Signed-off-by: Tianyu Lan <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent c51ba24 commit 20347fc

File tree

3 files changed

+197
-41
lines changed

3 files changed

+197
-41
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5904,8 +5904,10 @@
59045904
it if 0 is given (See Documentation/admin-guide/cgroup-v1/memory.rst)
59055905

59065906
swiotlb= [ARM,IA-64,PPC,MIPS,X86]
5907-
Format: { <int> | force | noforce }
5907+
Format: { <int> [,<int>] | force | noforce }
59085908
<int> -- Number of I/O TLB slabs
5909+
<int> -- Second integer after comma. Number of swiotlb
5910+
areas with their own lock. Must be power of 2.
59095911
force -- force using of bounce buffers even if they
59105912
wouldn't be automatically used by the kernel
59115913
noforce -- Never use bounce buffers (for debugging)

include/linux/swiotlb.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t phys,
8888
* @late_alloc: %true if allocated using the page allocator
8989
* @force_bounce: %true if swiotlb bouncing is forced
9090
* @for_alloc: %true if the pool is used for memory allocation
91+
* @nareas: The area number in the pool.
92+
* @area_nslabs: The slot number in the area.
9193
*/
9294
struct io_tlb_mem {
9395
phys_addr_t start;
@@ -101,6 +103,9 @@ struct io_tlb_mem {
101103
bool late_alloc;
102104
bool force_bounce;
103105
bool for_alloc;
106+
unsigned int nareas;
107+
unsigned int area_nslabs;
108+
struct io_tlb_area *areas;
104109
struct io_tlb_slot {
105110
phys_addr_t orig_addr;
106111
size_t alloc_size;

0 commit comments

Comments
 (0)