swiotlb: checking whether swiotlb buffer is full with io_tlb_used
authorDongli Zhang <dongli.zhang@oracle.com>
Fri, 18 Jan 2019 07:10:28 +0000 (15:10 +0800)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tue, 12 Feb 2019 17:53:01 +0000 (12:53 -0500)
This patch uses io_tlb_used to help check whether swiotlb buffer is full.
io_tlb_used is no longer used for only debugfs. It is also used to help
optimize swiotlb_tbl_map_single().

Suggested-by: Joe Jin <joe.jin@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
kernel/dma/swiotlb.c

index bedc9f9..a01b83e 100644 (file)
@@ -483,6 +483,10 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
         * request and allocate a buffer from that IO TLB pool.
         */
        spin_lock_irqsave(&io_tlb_lock, flags);
+
+       if (unlikely(nslots > io_tlb_nslabs - io_tlb_used))
+               goto not_found;
+
        index = ALIGN(io_tlb_index, stride);
        if (index >= io_tlb_nslabs)
                index = 0;