-->

pci_alloc_consistent uncached memory

2019-06-06 07:30发布

问题:

Is it fair to say that pci_alloc_consistent allocates a contiguous non-cached, non-paged kernel memory chunk. The reason I'm asking is that I saw this comment in some kernel/driver code (not in vanilla kernel sources), and I think I understand that the memory is presented as contiguous, however not sure that it's allocated non-cached, because the idea of cache coherency is to maintain data in the cache and DMA memory consistent.

Also, not sure why they call it non-paged.

E.g. https://www.kernel.org/doc/Documentation/DMA-API.txt in section Part Ia says:

Consistent memory is memory for which a write by either the device or the processor can immediately be read by the processor or device without having to worry about caching effects.

So one can't infer that the memory is non-cached, so I tend to think that comments I saw are somewhat misleading.

I would appreciate to get useful comments. Thanks!

回答1:

On x86, the caches are DMA-coherent (which requires that the cache controller snoops all DMA traffic), so consistent memory is just normal (cached) memory.

On most other architectures, caches are not DMA-coherent, so pci_alloc_consistent() must allocate non-cached memory.

"Non-paged" means that the memory cannot be swapped to disk. However, this is something that a Windows driver writer would care about; none of the normal Linux kernel allocation function returns swappable memory.