# Linux Kernel Module Cheat

##### 27.4.6.1. mmap MAP_ANONYMOUS

Basic `mmap` example, do the same as userland/c/malloc.c, but with `mmap`.

Example: userland/linux/mmap_anonymous.c

In POSIX 7 mmap always maps to a file.

If we add the MAP_ANONYMOUS Linux extension however, this is not required, and mmap can be used to allocate memory like malloc.

Answers: https://stackoverflow.com/questions/4779188/how-to-use-mmap-to-allocate-a-memory-in-heap