Linux MIPS Architecture development
 help / color / mirror / Atom feed
* Why is mmap()ed reserved memory so slow?
@ 2005-07-15 22:21 David Chau
  2005-07-15 22:35 ` Dan Malek
  2005-07-18 10:51 ` Ralf Baechle
  0 siblings, 2 replies; 4+ messages in thread
From: David Chau @ 2005-07-15 22:21 UTC (permalink / raw)
  To: linux-mips

Hi all,

I'm working on a driver for the Broadcom 1250, and I am using reserved 
memory for some data buffers. The board comes with 256 MB of RAM, so I 
boot Linux with "mem=253M" to reserve some RAM at the top of memory, and 
then mmap() /dev/mem starting at 253 MB.

The problem is that accessing this memory is ridiculously slow. A simple 
benchmark revealed that it takes about 200 cycles to read a 64-bit 
number. If I mmap() /dev/zero instead, a read takes under 3 cycles.

For those of you who knows how the Linux VM works, could you tell me why 
the memory access is so slow? It look like it might be invoking the 
page-fault handler on every read. How can I make memory access faster?

Thanks,
David

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why is mmap()ed reserved memory so slow?
  2005-07-15 22:21 Why is mmap()ed reserved memory so slow? David Chau
@ 2005-07-15 22:35 ` Dan Malek
  2005-07-18 14:44   ` David Chau
  2005-07-18 10:51 ` Ralf Baechle
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Malek @ 2005-07-15 22:35 UTC (permalink / raw)
  To: David Chau; +Cc: linux-mips


On Jul 15, 2005, at 6:21 PM, David Chau wrote:

> For those of you who knows how the Linux VM works, could you tell me 
> why the memory access is so slow? It look like it might be invoking 
> the page-fault handler on every read. How can I make memory access 
> faster?

How about a little more info, like what kernel are you using and what 
are
the parameters you are sending to mmap()?

One of the things that happens here is /dev/mem is thinking this memory 
is
not real memory (because you said the system has only 253M of real
memory), so it treats it like IO space.  This causes changes to the 
attributes
of the pages, most notably the CCA type for cache or pipeline behavior,
which isn't what you want in this case.

The better way to approach this is to place an mmap() function in the
associated driver that works in conjunction with the application to gain
shared access as you expect.  This also closes a hole where an errant
application could write into unexpected places through /dev/mem.

Thanks.

	-- Dan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why is mmap()ed reserved memory so slow?
  2005-07-15 22:21 Why is mmap()ed reserved memory so slow? David Chau
  2005-07-15 22:35 ` Dan Malek
@ 2005-07-18 10:51 ` Ralf Baechle
  1 sibling, 0 replies; 4+ messages in thread
From: Ralf Baechle @ 2005-07-18 10:51 UTC (permalink / raw)
  To: David Chau; +Cc: linux-mips

On Fri, Jul 15, 2005 at 06:21:44PM -0400, David Chau wrote:

> I'm working on a driver for the Broadcom 1250, and I am using reserved 
> memory for some data buffers. The board comes with 256 MB of RAM, so I 
> boot Linux with "mem=253M" to reserve some RAM at the top of memory, and 
> then mmap() /dev/mem starting at 253 MB.
> 
> The problem is that accessing this memory is ridiculously slow. A simple 
> benchmark revealed that it takes about 200 cycles to read a 64-bit 
> number.

mmap will create uncached mappings for anything above the highest RAM
address.

> If I mmap() /dev/zero instead, a read takes under 3 cycles.

Because you have a cache hits.  No RAM is that fast.

Above 200 cycles really is how horribly slow RAM is compared to a moderatly
clocked system.

> For those of you who knows how the Linux VM works, could you tell me why 
> the memory access is so slow? It look like it might be invoking the 
> page-fault handler on every read. How can I make memory access faster?

  Ralf

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why is mmap()ed reserved memory so slow?
  2005-07-15 22:35 ` Dan Malek
@ 2005-07-18 14:44   ` David Chau
  0 siblings, 0 replies; 4+ messages in thread
From: David Chau @ 2005-07-18 14:44 UTC (permalink / raw)
  To: Dan Malek; +Cc: linux-mips

Dan Malek wrote:

> How about a little more info, like what kernel are you using and what are
> the parameters you are sending to mmap()?

Linux (none) 2.4.31 #412 SMP Fri Jul 15 16:26:05 EDT 2005 mips unknown
(unmodified kernel from linux-mips.org).
It's running on the SB1 on a Broadcom 1250 board.

I mmap() with:
int mem_fd = open("/dev/mem", O_RDWR);
void* mem_base =
    mmap(NULL, DRIVER_MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
         mem_fd, DRIVER_MEM_PHYS_BASE);
Where driver_mem_phys_base = 253M, and driver_mem_size=1M.

> The better way to approach this is to place an mmap() function in the
> associated driver that works in conjunction with the application to gain
> shared access as you expect.  This also closes a hole where an errant
> application could write into unexpected places through /dev/mem.


Could you point me to an example of this so I can figure out how to do it?

Thanks,
David

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-07-19 13:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-15 22:21 Why is mmap()ed reserved memory so slow? David Chau
2005-07-15 22:35 ` Dan Malek
2005-07-18 14:44   ` David Chau
2005-07-18 10:51 ` Ralf Baechle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox