mmap

mmap slower than ioremap

柔情痞子 提交于 2019-12-02 20:57:00
I am developing for an ARM device running Linux 2.6.37. I am trying to toggle an IO pin as fast as possible. I made a little kernel module and a user space application. I tried two things : Manipulate the GPIO control registers directly from the kernel space using ioremap . mmap() the GPIO control registers without caching and using them from user space. Both methods work, but the second is about 3 times slower than the first (observed on oscilloscope). I think I disabled all caching mechanisms. Of course I'd like to get the best of the two worlds : flexibility and ease of development from

堆外内存

喜夏-厌秋 提交于 2019-12-02 18:17:18
java 版的 mmap,返回的对象是 DirectByteBuffer,是堆外内存 // java.nio.channels.FileChannel#map public abstract MappedByteBuffer map(MapMode mode, long position, long size) throws IOException; 设置堆外内存的大小 -XX:MaxDirectMemorySize=16G 来源: https://www.cnblogs.com/allenwas3/p/11757237.html

Mapping an array to a file via Mmap in Go

别等时光非礼了梦想. 提交于 2019-12-02 17:10:57
I'm trying to map an array to a file via Mmap, the array could be any type, like float64. In C, I find this one . After reading some texts, I wrote this sample . I don't know if it is correct, and it is not writing the values to the file. If I increase the size of array a lot, e.g from 1000 to 10000, it crashes. If someone know how to do that in the correctly way, please, tell me. Thanks! For example, revising your sample program, package main import ( "fmt" "os" "syscall" "unsafe" ) func main() { const n = 1e3 t := int(unsafe.Sizeof(0)) * n map_file, err := os.Create("/tmp/test.dat") if err !

How to map an empty file using mmap

[亡魂溺海] 提交于 2019-12-02 17:00:53
问题 I am trying to create an empty file if it does not exists. And than map it using mmap() so, that i can pass it to my other program for writing. I am not sure which arguments for mmap are suitable for an empty file. My code works for non empty files but gives error "Invalid argument" if file is empty Code program1 (only creates an empty file if not exists) int i; int fd = open("/home/sungmin/dummy_programs/dummy.txt", O_RDONLY | O_CREAT, 0777); char *pmap; pid_t child; if (fd == -1) { perror(

How to use mmap to allocate a memory in heap?

巧了我就是萌 提交于 2019-12-02 16:51:28
Just the question stated, how can I use mmap() to allocate a memory in heap? This is my only option because malloc() is not a reentrant function. Why do you need reentrancy? The only time it's needed is for calling a function from a signal handler; otherwise, thread-safety is just as good. Both malloc and mmap are thread-safe. Neither is async-signal-safe per POSIX. In practice, mmap probably works fine from a signal handler, but the whole idea of allocating memory from a signal handler is a very bad idea. If you want to use mmap to allocate anonymous memory, you can use (not 100% portable but

Passing a pointer to process spawned with exec()

拥有回忆 提交于 2019-12-02 15:13:53
问题 I would like to pass a pointer (I am putting a file with data in memory with mmap) to processes spawned using fork + exec, but I am stuck on how to pass a pointer to the exec() spawned process? UPDATE1: Thanks for your inputs, I do use shared memory creating it with mmap with MAP_INHERIT flag: Each mapped file and shared memory region created with the mmap() function is unmapped by a successful call to any of the exec functions, except those regions mapped with the MAP_INHERIT option. Regions

Getting segmentation fault SIGSEGV in memcpy after mmap

扶醉桌前 提交于 2019-12-02 08:26:54
问题 I wrote a simple Android native function that get a filename and some more arguments and read the file by mmapping (mmap) it's memory. Because it's mmap, I don't really need to call "read()" so I just memcpy() from the address returned from the mmap(). But, somewhere I'm getting a SIGSEGV probably because I'm trying to access a memory which I not permitted. But I don't understand why, I already asked all file's memory to be mapped! I'm attaching my code and the error I got: EDIT I fixed the

What is the difference between calling mmap() on a disk file before or after a fork?

一笑奈何 提交于 2019-12-01 23:50:14
问题 I've been working on understanding how mmap() works with disk-backed files, and am mostly getting it, but I still have this question. In a situation with a master process that forks a bunch of worker child processes, and a file-backed read-only mmapped db, does it matter if the mmaps happen in the master process before the forks, or in the child processes? My understanding is that if it happens in the master process before the fork, then in the memory page table, all of the mapped pages are

Mmap system call operation that is able to access memory locations

℡╲_俬逩灬. 提交于 2019-12-01 21:30:01
I am writing a program that allocates huge chunks of memory using mmap and then accesses random memory locations to read and write into it. I just tried out the following code: #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> int main() { int fd,len=1024*1024; fd=open("hello",O_READ); char*addr=mmap(0,len,PROT_READ+PROT_WRITE,MAP_SHARED,fd,0); for(fd=0;fd<len;fd++) putchar(addr[fd]); if (addr==MAP_FAILED) {perror("mmap"); exit(1);} printf("mmap returned %p, which seems readable and writable\n",addr); munmap(addr,len); return 0; } But I cannot execute this program, is there anything

GDB can't access mmap()'d kernel allocated memory?

一笑奈何 提交于 2019-12-01 20:26:25
问题 I'm running into an issue with GDB and some buffers allocated in kernel space. The buffers are allocated by a kernel module that is supposed to allocate contiguous blocks of memory, and then memory mapped into userspace via a mmap() call. GDB, however, can't seem to access these blocks at any time. For example, after hitting a breakpoint in GDB: (gdb) x /10xb 0x4567e000 0x4567e000: Cannot access memory at address 0x4567e000 However, looking at the application's currently mapped memory regions