Memory access after ioremap is very slow

I am working on a Linux kernel driver that makes a piece of physical memory available to user space. I have a working version of the driver, but it is currently very slow. So, I went back a few steps and tried to create a small simple driver to recreate the problem.

I reserve memory at boot time using the kernel option memmap=2G$1G. Then, in the driver function, __initI ioremappart of this memory and initialize it to a known value. I also added code for measuring time:

#define RESERVED_REGION_SIZE    (1 * 1024 * 1024 * 1024)   // 1GB
#define RESERVED_REGION_OFFSET  (1 * 1024 * 1024 * 1024)   // 1GB

static int __init memdrv_init(void)
{
    struct timeval t1, t2;
    printk(KERN_INFO "[memdriver] init\n");

    // Remap reserved physical memory (that we grabbed at boot time)
    do_gettimeofday( &t1 );
    reservedBlock = ioremap( RESERVED_REGION_OFFSET, RESERVED_REGION_SIZE );
    do_gettimeofday( &t2 );
    printk( KERN_ERR "[memdriver] ioremap() took %d usec\n", usec_diff( &t2, &t1 ) );

    // Set the memory to a known value
    do_gettimeofday( &t1 );
    memset( reservedBlock, 0xAB, RESERVED_REGION_SIZE );
    do_gettimeofday( &t2 );
    printk( KERN_ERR "[memdriver] memset() took %d usec\n", usec_diff( &t2, &t1 ) );

    // Register the character device
    ...

    return 0;
}

I load the driver and check dmesg. He reports:

[memdriver] init
[memdriver] ioremap() took 76268 usec
[memdriver] memset() took 12622779 usec

This is 12.6 seconds for memset. This means that memset is running at 81 MB / s . Why is it so slow?

​​2.6.34 Fedora 13 x86_64.

EDIT:

, PCI ( / ), ( mmap, ). PCI , . ioremap - ( ), , , , . , , .


.

+3
4

ioremap , . .

, kmalloc vmalloc. .

+4

, ioremap() , . (, reservedBlock) readb, readl, writeb, memcpy_toio .. , ( , -, ). , ( -), .

+2

- , , ioremap.

, , , , , . , ( ), ( , 256 ). , , .

+1

memmap

ioremap , tera.

128 , 64 . /proc/vmallocinfo

0xffffc9001f3a8000-0xffffc9201f3a9000 137438957568 0xffffffffa00831c9 phys=1000000000 ioremap

, 0xffffc9001f3a8000 ( ).

-, . memset_io ( ), .

, , , .

+1

Source: https://habr.com/ru/post/1780476/


All Articles