mmap

mmap substitute for malloc

浪子不回头ぞ 提交于 2021-02-20 05:00:07
问题 I need to find a way to use mmap instead of malloc. How is this possible? (I am not using libc only syscalls) And yes brk() is possible. I used sbrk() but realized its not sys-call... (x86 inline assembly) I've been looking around and saw this: How to use mmap to allocate a memory in heap? But it didn't help for me, because I had a segfault. Basically, all I want to do a create 3 slabs of memory for storing characters. Say, char * x = malloc(1000); char * y = malloc(2000); char * z = malloc

Why (ftruncate+mmap+memcpy) is faster than (write)?

自闭症网瘾萝莉.ら 提交于 2021-02-19 08:13:13
问题 I found a different way to write data, which is faster than normal unix write function. Firstly, ftruncate the file to the length we need, then mmap this block of file, finally, using memcpy to flush the file content. I will give the example code below. As I known, mmap can load the file into the process address space, accelerating by ignoring the page cache. BUT, I don't have any idea why it can fast up the writing speed. Whether I write a wrong test case or it can be a kind of opti trick?

How should I read Intel PCI uncore performance counters on Linux as non-root?

喜欢而已 提交于 2021-02-19 02:43:06
问题 I'd like to have a library that allows 'self profiling' of critical sections of Linux executables. In the same way that one can time a section using gettimeofday() or RDTSC I'd like to be able to count events such as branch misses and cache hits. There are a number of tools that do similar things (perf, PAPI, likwid) but I haven't found anything that matches what I'm looking for. Likwid comes closest, so I'm mostly looking at ways to modify it's existing Marker API. The per-core counters are

C/C++ - Memory map file using mmap

孤者浪人 提交于 2021-02-08 06:49:59
问题 I'm new to memory mapping files and am a bit confused. Is it possible to map files larger than the total amount of memory because as I understood memory mapping uses demand paging and will hold only the currently relevant pages in memory. Is this right or will my application crash when using more space than the actual memory. Thanks EDIT OS: Ubuntu 14.04 LTS x86_64 App-Bitness: 64bit (I guess: pointers are 8 byte) I'm trying to allocate memory from the mapped file in order to store the tree

Mmap and valgrind, mmap doesnt increase heap size

99封情书 提交于 2021-02-07 20:28:34
问题 I'm attending operating systems course on my university, one of the tasks we were given is to implement simple malloc using mmap. Now that i got it working i tried to use valgrind to detect any bugs left. And regarldess of freeing memory or not, valgrind doesnt see any memory leaks. As an example consider following C code: int main() { int psize = getpagesize(),i; int *ptr = mmap(NULL, psize, PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); for(i = 0; i < psize/4; i++) ptr[i] = i;

Mmap and valgrind, mmap doesnt increase heap size

拟墨画扇 提交于 2021-02-07 20:25:59
问题 I'm attending operating systems course on my university, one of the tasks we were given is to implement simple malloc using mmap. Now that i got it working i tried to use valgrind to detect any bugs left. And regarldess of freeing memory or not, valgrind doesnt see any memory leaks. As an example consider following C code: int main() { int psize = getpagesize(),i; int *ptr = mmap(NULL, psize, PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); for(i = 0; i < psize/4; i++) ptr[i] = i;

Linux mapping virtual memory range to existing virtual memory range?

拜拜、爱过 提交于 2021-02-06 13:47:45
问题 In Linux, is there a way (in user space) to map a virtual address range to the physical pages that back an existing virtual address range? The mmap() function only allows one to map files or "new" physical pages. I need to be able to do something like this: int* addr1 = malloc(SIZE); int* addr2 = 0x60000; // Assume nothing is allocated here fancy_map_function(addr1, addr2, SIZE); assert(*addr1 == *addr2); // Should succeed assert(addr1 != addr2); // Should succeed 回答1: I was curious so I

Linux mapping virtual memory range to existing virtual memory range?

霸气de小男生 提交于 2021-02-06 13:46:16
问题 In Linux, is there a way (in user space) to map a virtual address range to the physical pages that back an existing virtual address range? The mmap() function only allows one to map files or "new" physical pages. I need to be able to do something like this: int* addr1 = malloc(SIZE); int* addr2 = 0x60000; // Assume nothing is allocated here fancy_map_function(addr1, addr2, SIZE); assert(*addr1 == *addr2); // Should succeed assert(addr1 != addr2); // Should succeed 回答1: I was curious so I

Why does mmap fail on iOS?

烈酒焚心 提交于 2021-02-06 10:12:36
问题 I'm trying to use mmap to read and play audio files on iOS. It works fine for files up to about 400MB. But when I try a 500MB file, I get a ENOMEM error. char *path = [[[NSBundle mainBundle] pathForResource: @"test500MB" ofType: @"wav"] cStringUsingEncoding: [NSString defaultCStringEncoding]]; FILE *f = fopen( path, "rb" ); fseek( f, 0, SEEK_END ); int len = (int)ftell( f ); fseek( f, 0, SEEK_SET ); void *raw = mmap( 0, len, PROT_READ, MAP_SHARED, fileno( f ), 0 ); if ( raw == MAP_FAILED ) {

Purging numpy.memmap

ぃ、小莉子 提交于 2021-01-29 08:49:52
问题 Given a numpy.memmap object created with mode='r' (i.e. read-only), is there a way to force it to purge all loaded pages out of physical RAM, without deleting the object itself? In other words, I'd like the reference to the memmap instance to remain valid, but all physical memory that's being used to cache the on-disk data to be uncommitted. Any views onto to the memmap array must also remain valid. I am hoping to use this as a diagnostic tool, to help separate "real" memory requirements of a