Skip to content

Commit

Permalink
swiotlb: use the atomic counter of total used slabs if available
Browse files Browse the repository at this point in the history
If DEBUG_FS is enabled, the cost of keeping an exact number of total
used slabs is already paid. In this case, there is no reason to use an
inexact number for statistics and kernel messages.

Signed-off-by: Petr Tesarik <petr.tesarik.ext@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Petr Tesarik authored and Christoph Hellwig committed Jun 7, 2023
1 parent efa76af commit 693405c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kernel/dma/swiotlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,15 @@ static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr,
return -1;
}

#ifdef CONFIG_DEBUG_FS

static unsigned long mem_used(struct io_tlb_mem *mem)
{
return atomic_long_read(&mem->total_used);
}

#else /* !CONFIG_DEBUG_FS */

static unsigned long mem_used(struct io_tlb_mem *mem)
{
int i;
Expand All @@ -727,6 +736,8 @@ static unsigned long mem_used(struct io_tlb_mem *mem)
return used;
}

#endif /* CONFIG_DEBUG_FS */

phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
size_t mapping_size, size_t alloc_size,
unsigned int alloc_align_mask, enum dma_data_direction dir,
Expand Down

0 comments on commit 693405c

Please sign in to comment.