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)
#define RESERVED_REGION_OFFSET (1 * 1024 * 1024 * 1024)
static int __init memdrv_init(void)
{
struct timeval t1, t2;
printk(KERN_INFO "[memdriver] init\n");
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 ) );
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 ) );
...
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 - ( ), , , , . , , .
.