0

In Linux we know that we can map physical memory to the user virtual address space using mmap call in user-space app and implementing mmap function pointer in our device driver(using remap_pfn_range). But is there any other way to map the physical memory to user virtual address space without the mmap call. May be we can use malloc call and make an "IOCTL" call passing user virtual start address and then using kmalloc and remap_pfn_range we can map.

I tried once but failed. Is it the correct way or any other way exists.

-Sumeet

Sumeet_Jain
  • 467
  • 4
  • 12
  • 3
    Why don't you want to use "mmap", what are you trying to achieve? – Elliott Frisch Jan 06 '14 at 06:39
  • I am implementing an "usb" driver. I need to send 8000packets/sec for audio streaming. If the memories are mapped then it would be a lot easier. And I am alien to the implementation of mmap call in usb driver. So I thought I could do this using IOCTL call. – Sumeet_Jain Jan 06 '14 at 07:02
  • Well the problem has been solved.Thanks :D – Sumeet_Jain Jan 06 '14 at 10:53

1 Answers1

0

Physical memory is mapped to virtual address space automatically, without any mmap call, by the Operating System. It is called memory management or memory paging. This means that with any new memory your process needs, e.g. by malloc, or in the stack segment, the process asks for new pages and OS creates mapping from virtual to physical memory automatically. But, you need not to know all this - the operating system will hide everything from you. Just be happy in the virtual address space and that's enough :-)

mmap, on the other hand is mapping files to virtual memory. It is special case of mapping. You can also use IPC shared memory (shmget) to share memory between processes. You can also do this using mmap only without actually writing to file.

Depends what you want to do.

Tomas
  • 57,621
  • 49
  • 238
  • 373
  • I want contiguous physical memory at the user-space which cant be achieved using malloc call. – Sumeet_Jain Jan 06 '14 at 06:54
  • this can be only possible in the kernel. See http://lwn.net/Articles/396702/ or http://stackoverflow.com/questions/7200644/allocate-large-32mb-contiguous-region But according to your question I suppose you are not a kernel programmer? – Tomas Jan 06 '14 at 07:03
  • 1
    I have already done this before. I could map physically contiguous memory to the user-space using mmap. Yes I am an "Kernel Programmer" but an amateur one. – Sumeet_Jain Jan 06 '14 at 07:11