kmalloc and uncached memory

Lin Ming minggr at gmail.com
Wed Apr 16 11:11:39 PDT 2014


Hi Peter,

I have a performance problem(on ARM board) that cpu is very bus at
cache invalidation.
So I'm trying to alloc an uncached memory to eliminate cache invalidation.

But I also have problem with dma_alloc_coherent().
If I don't use dma_alloc_coherent(), is it OK to use below code to
alloc uncached memory?

struct page *page;
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd;
pte_t *pte;
void *cpu_addr;
dma_addr_t dma_addr;
unsigned int vaddr;

cpu_addr = kmalloc(PAGE_SIZE, GFP_KERNEL);
dma_addr = pci_map_single(NULL, cpu_addr, PAGE_SIZE, (int)DMA_FROM_DEVICE);
vaddr = (unsigned int)uncached->cpu_addr;
pgd = pgd_offset_k(vaddr);
pud = pud_offset(pgd, vaddr);
pmd = pmd_offset(pud, vaddr);
pte = pte_offset_kernel(pmd, vaddr);
page = virt_to_page(vaddr);
set_pte_ext(pte, mk_pte(page,  pgprot_dmacoherent(pgprot_kernel)), 0);

/* This kmalloc memory won't be freed  */

Thanks,
Ming



More information about the linux-arm-kernel mailing list