mmap

Zero a large memory mapping with `madvise`

↘锁芯ラ 提交于 2019-12-03 12:53:27
问题 I have the following problem: I allocate a large chunk of memory (multiple GiB) via mmap with MAP_ANONYMOUS . That chunk holds a large hash map which needs to be zeroed every now and then. Not the entire mapping may be used in each round (not every page is faulted in), so memset is not a good idea - takes too long. What is the best strategy to do this quickly? Will madvise(ptr, length, MADV_DONTNEED); guarantee me that any subsequent accesses provide new empty pages? From the Linux man

In linux , how to create a file descriptor for a memory region

狂风中的少年 提交于 2019-12-03 12:30:28
I have some program handling some data either in a file or in some memory buffer. I want to provide uniform way to handle these cases. I can either 1) mmap the file so we can handle them uniformly as a memory buffer; 2) create FILE* using fopen and fmemopen so access them uniformly as FILE*. However, I can't use either ways above. I need to handle them both as file descriptor, because one of the libraries I use only takes file descriptor, and it does mmap on the file descriptor. So my question is, given a memory buffer (we can assume it is aligned to 4K), can we get a file descriptor that

Platform independent memory mapped [file] IO

妖精的绣舞 提交于 2019-12-03 10:32:11
I've spent some time investigating memory mapped IO for an application I'm working on. I have some very large (TB scale) files, and I want to map segments from them into memory, for both reading and writing, making maximum use of OS-level caching. The software I'm writing needs to work under Unix/Linux and Windows... performance is critical. I've discovered boost::iostreams::mapped_file_source and boost::iostreams::mapped_file_sink , which provide most of the facilities I'm looking for. The facilities I'd like, but haven't found are: Forcing a synchronisation of written data to disk ( msync (2

Mmap and struct in C [closed]

南楼画角 提交于 2019-12-03 10:20:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I would like to read and write structs with mmap in C. I have a function named insert_med which allows the insertion of a new struct med into the mmap and each struct (with a unique key ) has to be written in a different position of the array (when a new struct is added, it has to be added in the last empty

Bad Linux Memory Mapped File Performance with Random Access C++ & Python

泄露秘密 提交于 2019-12-03 10:19:52
问题 While trying to use memory mapped files to create a multi-gigabyte file (around 13gb), I ran into what appears to be a problem with mmap(). The initial implementation was done in c++ on Windows using boost::iostreams::mapped_file_sink and all was well. The code was then run on Linux and what took minutes on Windows became hours on Linux. The two machines are clones of the same hardware: Dell R510 2.4GHz 8M Cache 16GB Ram 1TB Disk PERC H200 Controller. The Linux is Oracle Enterprise Linux 6.5

Trap all accesses to an address range (Linux)

蓝咒 提交于 2019-12-03 09:38:39
问题 Background I'm writing a framework to enable co-simulation of RTL running in a simulator and un-modified host software. The host software is written to control actual hardware and typically works in one of two ways: Read/Write calls through a driver Memory mapped access using mmap The former case is pretty straightforward - write a library that implements the same read / write calls as the driver and link against that when running a simulation. This all works wonderfully and I can run un

Shmem vs tmpfs vs mmap [closed]

喜夏-厌秋 提交于 2019-12-03 09:26:56
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Does someone know how well the following 3 compare in terms of speed: shared memory tmpfs (/dev/shm) mmap (/dev/shm) Thanks! 回答1: Read

Overlapping pages with mmap (MAP_FIXED)

匆匆过客 提交于 2019-12-03 09:10:37
问题 Due to some obscure reasons which are not relevant for this question, I need to resort to use MAP_FIXED in order to obtain a page close to where the text section of libc lives in memory. Before reading mmap(2) (which I should had done in the first place), I was expecting to get an error if I called mmap with MAP_FIXED and a base address overlapping an already-mapped area. However that is not the case. For instance, here is part of /proc/maps for certain process 7ffff7299000-7ffff744c000 r-xp

mremap(2) with HugeTLB to change virtual address?

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is the Linux mremap(2) function able to change the virtual address of a HugeTLB obtained from mmap() to a new fixed virtual address? (Background: I want to remap the virtual address based on the physical address of the memory I get. This is to efficiently perform virtual to physical address translations by inspecting pointer addresses directly. I will use the memory for DMA to hardware from userspace.) This does not seem to work with my simple test program: #define _GNU_SOURCE #include <stdio.h> #include <sys/mman.h> #include <stdint.h>

mmap(): resetting old memory to a zero&#039;d non-resident state

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm writing a memory allocation routine, and it's currently running smoothly. I get my memory from the OS with mmap() in 4096-byte pages. When I start my memory allocator I allocate 1gig of virtual address space with mmap(), and then as allocations are made I divide it up into hunks according to the specifics of my allocation algorithm. I feel safe allocating as much as a 1gig of memory on a whim because I know mmap() doesn't actually put pages into physical memory until I actually write to them. Now, the program using my allocator might