Mmap() an entire large file

MAP_PRIVATE mappings require a memory reservation, as writing to these pages may result in copy-on-write allocations. This means that you can’t map something too much larger than your physical ram + swap. Try using a MAP_SHARED mapping instead. This means that writes to the mapping will be reflected on disk – as such, the kernel … Read more

Setting up Laravel on a Mac php artisan migrate error: No such file or directory [duplicate]

If you are using MAMP be sure to add the unix_socket key with a value of the path that the mysql.sock resides in MAMP. ‘mysql’ => array( ‘driver’ => ‘mysql’, ‘host’ => ‘localhost’, ‘unix_socket’ => ‘/Applications/MAMP/tmp/mysql/mysql.sock’, ‘database’ => ‘database’, ‘username’ => ‘root’, ‘password’ => ‘root’, ‘charset’ => ‘utf8’, ‘collation’ => ‘utf8_unicode_ci’, ‘prefix’ => ”, ),

How to access mmaped /dev/mem without crashing the Linux kernel?

I think I’ve found the issue — it’s to do with /dev/mem memory mapping protection on the x86. Pl refer to this LWN article: “x86: introduce /dev/mem restrictions with a config option” http://lwn.net/Articles/267427/ CONFIG_NONPROMISC_DEVMEM Now (i tested this on a recent 3.2.21 kernel), the config option seems to be called CONFIG_STRICT_DEVMEM. I changed my kernel … Read more

How big can a memory-mapped file be?

You’re being too conservative: A memory-mapped file can be larger than the address space. The view of the memory-mapped file is limited by OS memory constraints, but that’s only the part of the file you’re looking at at one time. (And I guess technically you could map multiple views of discontinuous parts of the file … Read more

Unexpected exec permission from mmap when assembly files included in the project

Linux has an execution domain called READ_IMPLIES_EXEC, which causes all pages allocated with PROT_READ to also be given PROT_EXEC. Older Linux kernels used to use this for executables that used the equivalent of gcc -z execstack. This program will show you whether that’s enabled for itself: #include <stdio.h> #include <sys/personality.h> int main(void) { printf(“Read-implies-exec is … Read more

When should I use mmap for file access?

mmap is great if you have multiple processes accessing data in a read only fashion from the same file, which is common in the kind of server systems I write. mmap allows all those processes to share the same physical memory pages, saving a lot of memory. mmap also allows the operating system to optimize … Read more

Will malloc implementations return free-ed memory back to the system?

The following analysis applies only to glibc (based on the ptmalloc2 algorithm). There are certain options that seem helpful to return the freed memory back to the system: mallopt() (defined in malloc.h) does provide an option to set the trim threshold value using one of the parameter option M_TRIM_THRESHOLD, this indicates the minimum amount of … Read more

tech