Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between mapped region and unmapped region in memory space?

Tags:

c

heap-memory

I came across the following paragraph in an article about malloc.

The heap is a continuous (in term of virtual addresses) space of memory with three bounds:a starting point, a maximum limit (managed through sys/ressource.h’s functions getrlimit(2) and setrlimit(2)) and an end point called the break. The break marks the end of the mapped memory space, that is, the part of the virtual address space that has correspondence into real memory.

enter image description here

I would like to better understand the concept of mapped region and unmapped region.

like image 528
Hells Guardian Avatar asked May 18 '16 06:05

Hells Guardian


People also ask

What is a memory mapping?

What Is Memory-Mapping? Memory-mapping is a mechanism that maps a portion of a file, or an entire file, on disk to a range of addresses within an application's address space. The application can then access files on disk in the same way it accesses dynamic memory.

What is memory mapped files and how in use?

A memory-mapped file contains the contents of a file in virtual memory. This mapping between a file and memory space enables an application, including multiple processes, to modify the file by reading and writing directly to the memory.

What is memory mapping in Linux?

Memory mapping of files is a very powerful abstraction that many operating systems support out of the box. Linux does this via the mmap system call. In most cases where an application reads (or writes) to a file at arbitrary positions, using mmap is a solid alternative to the more traditional read / write system calls.

Why is memory mapping needed?

You can map file data into the process address space. You can also map processes to anonymous memory regions that may be shared by cooperating processes. Memory mapped files provide a mechanism for a process to access files by directly incorporating file data into the process address space.

What is a mapped memory region?

Mapped memory regions, also called shared memory areas, can serve as a large pool for exchanging data among processes. The available subroutines do not provide locks or access control among the processes.

What are the advantages of memory mapped I/O?

Memory Mapped I/O Memory and I/O have separate address space Both have same address space All address can be used by the memory Due to addition of I/O addressable memory become less for memory Separate instruction control read and write operation in I/O and Memory Same instructions can control both I/O and Memory

What is isolated I/O memory mapped memory?

Isolated I/O Memory Mapped I/O Memory and I/O have separate address space Both have same address space All address can be used by the memory Due to addition of I/O addressable memory become less for memory Separate instruction control read and write operation in I/O and Memory

What is the difference between memory mapped I/O and periphral mapped I/O?

Difference b/w Memory Mapped I/O and Periphral Mapped I/O are given below. - Data transfer between any general-purpose register and I/O port. - The memory map (64K) is shared between I/O device and system memory.


2 Answers

The mapped region in the heap means the virtual memory area that can be mapped together with physical memory. And the unmapped region indicates the unused virtual memory space which does not point to any physical memory.

The boundary between mapped region for the heap and unmapped region is the system break point. As the malloc() is used to request some memory, the system break point would be moved to enlarge the mapped region. Linux system offeres brk() and sbrk() methods to increase and decrease the virtual memory address of the system break point.

like image 24
CWLiu Avatar answered Sep 28 '22 14:09

CWLiu


If memory addresses are 64 bits long, as in many modern computers, you have 18446744073709551616 possible memory addresses. (It depends on the processor architecture how many bits can actually be used, but addresses are stored using 64 bits.) That is more than 17 billion gigabytes, which is probably more memory than your computer actually has. So only some of those 17 billion gigabytes correspond to actual memory. For the rest of the addresses, the memory simply doesn't exist. There is no correspondence between the memory address and a memory location. Those addresses are, therefore, unmapped.

That is the simple explanation. In reality, it's a bit more complicated. The memory addresses of your program are not the actual memory addresses of the memory chips, the physical memory, in your computer. Instead, it is virtual memory. Each process has its own memory space, that is, its own 18446744073709551616 addresses, and the memory addresses that a process uses are translated to physical memory addresses by the computer hardware. So one process may have stored some data at memory address 4711, which is actually stored in a real physical memory chip over here, and another process may have also stored some data at memory address 4711, but that is a completely different place, stored in a real physical memory chip over there. The process-internal virtual memory addresses are translated, or mapped, to actual physical memory, but not all of them. The rest, again, are unmapped.

That is, of course, also a simplified explanation. You can use more virtual memory than the amount of physical memory in your computer. This is done by paging, that is, taking some chunks (called pages) of memory not being used right now, and storing them on disk until they are needed again. (This is also called "swapping", even if that term originally meant writing all the memory of a process to disk, not just parts of it.)

And to complicate it even further, some modern operating systems such as Linux and MacOS X (but, I am told, not Windows) overcommit when they allocate memory. This means that they allocate more memory addresses than can be stored on the computer, even using the disk. For example, my computer here with 32 gigabytes of physical memory, and just 4 gigabytes available for paging out data to disk, can't possibly allow for more than 36 gigabyes of actual, usable, virtual memory. But malloc happily allocates more than one hundred thousand gigabytes. It is not until I actually try to store things in all that memory that it is connected to physical memory or disk. But it was part of my virtual memory space, so I would call that too mapped memory, even though it wasn't mapped to anything.

like image 123
Thomas Padron-McCarthy Avatar answered Sep 28 '22 14:09

Thomas Padron-McCarthy