mmap

memory mapped files and pointers to volatile objects

依然范特西╮ 提交于 2019-12-22 04:01:46
问题 My understanding of the semantics of volatile in C and C++ is that it turns memory access into (observable) side effects. Whenever reading or writing to a memory mapped file (or shared memory) I would expect the the pointer to be volatile qualified, to indicate that this is in fact I/O. (John Regehr wrote a very good article on the semantics of volatile ). Furthermore, I would expect using functions like memcpy() to access shared memory to be incorrect, since the signature suggests the

Java mmap fails on Android with “mmap failed: ENOMEM (Out of memory)”

ぃ、小莉子 提交于 2019-12-22 03:52:02
问题 Memory mapping a large file on Android in Java works good. But when mapping more than ~1.5GB in total even with multiple mapping calls it fails with: mmap failed: ENOMEM (Out of memory) See the full discussion here. Note: It does not fail on a server Linux. The android:largeHeap="true" is enabled for the application. The following Java code is called a few hundred times requesting ~1MB per call: ByteBuffer buf = raFile.getChannel().map(allowWrites ? FileChannel.MapMode.READ_WRITE :

Why does munmap needs a length as parameter?

北战南征 提交于 2019-12-22 03:19:27
问题 I was wondering, why should the size of mapped memory being one parameter passed in, since there couldn't more more than one mapping starting from same address (could they ?), why won't linux kernel record both start address, length together, but let userspace program remember them. I mean, why wouldn't it be, just use the start address as primary key to store the information tree. 回答1: One can map , say, 5 pages and later unmap one of them. And information about what pages to unmap is passed

Python mmap 'Permission denied' on Linux

时间秒杀一切 提交于 2019-12-22 02:32:38
问题 I have a really large file I'm trying to open with mmap and its giving me permission denied. I've tried different flags and modes to the os.open but its just not working for me. What am I doing wrong? >>> import os,mmap >>> mfd = os.open('BigFile', 0) >>> mfile = mmap.mmap(mfd, 0) Traceback (most recent call last): File "<stdin>", line 1, in <module> mmap.error: [Errno 13] Permission denied >>> (using the built in open() works via the python docs example, but it seems to open more than one

Is there really no mremap in Darwin?

白昼怎懂夜的黑 提交于 2019-12-22 01:43:52
问题 I'm trying to find out how to remap memory-mapped files on a Mac (when I want to expand the available space). I see our friends in the Linux world have mremap but I can find no such function in the headers on my Mac. /Developer/SDKs/MacOSX10.6.sdk/usr/include/sys/mman.h has the following: mmap mprotect msync munlock munmap but no mremap man mremap confirms my fears. I'm currently having to munmap and mmmap if I want to resize the size of the mapped file, which involves invalidating all the

Linux: how to check the largest contiguous address range available to a process

自作多情 提交于 2019-12-21 20:58:02
问题 I want to enter the pid at the command line and get back the largest contiguous address space that has not been reserved. Any ideas? Our 32 bit app, running on 64 bit RHEL 5.4, craps out after running for a while, say 24 hours. At that time it is only up to 2.5 gb of memory use, but we get out of memory errors. We think it failing to mmap large files because the app's memory space is fragmented. I wanted to go out to the production servers and just test that theory. 回答1: Slighly nicer version

python多进程共享内存的读写访问控制

怎甘沉沦 提交于 2019-12-21 19:58:50
问题背景 基于SharedArray库,可以实现python多进程共享内存机制。问题在于,当内存初始化完成之后,我们希望这片内存的属性是只读的,而不希望看到意外的修改发生。 解决方案 解决方案是修改SharedArray库,库函数API attach成员提供的参数原先只有一个,即共享内存的文件名。通过修改attach的输入参数,可以允许用户将映射的内存指定为只读属性。这里面最关键的是mmap函数,attach函数内部调用mmap函数,原先的实现是将读写属性固定为允许读写。我们只需要略加修改,允许根据用户指定的参数来配置mmap,就可以达到内存区只读的目的。 测试结果 实测的结果是,将共享内存设置为read only之后,程序对于该内存的写操作会触发segment fault。 来源: CSDN 作者: hicode666 链接: https://blog.csdn.net/hicode666/article/details/103646590

Diff/compare two files by file descriptor (fd) instead of file name

China☆狼群 提交于 2019-12-21 18:07:30
问题 Is there any way in Linux, using c, to generate a diff/patch of two files stored in memory, using a common format (ie: unified diff, like with the command-line diff utility)? I'm working on a system where I generate two text files in memory, and no external storage is available, or desired. I need to create a line-by-line diff of the two files, and since they are mmap 'ed, they don't have file names, preventing me from simply calling system("diff file1.txt file2.txt") . I have file

Diff/compare two files by file descriptor (fd) instead of file name

…衆ロ難τιáo~ 提交于 2019-12-21 18:07:05
问题 Is there any way in Linux, using c, to generate a diff/patch of two files stored in memory, using a common format (ie: unified diff, like with the command-line diff utility)? I'm working on a system where I generate two text files in memory, and no external storage is available, or desired. I need to create a line-by-line diff of the two files, and since they are mmap 'ed, they don't have file names, preventing me from simply calling system("diff file1.txt file2.txt") . I have file

Memory Mapped files and atomic writes of single blocks

半腔热情 提交于 2019-12-21 03:52:31
问题 If I read and write a single file using normal IO APIs, writes are guaranteed to be atomic on a per-block basis. That is, if my write only modifies a single block, the operating system guarantees that either the whole block is written, or nothing at all. How do I achieve the same effect on a memory mapped file? Memory mapped files are simply byte arrays, so if I modify the byte array, the operating system has no way of knowing when I consider a write "done", so it might (even if that is