Memory fragmentation (memory fragmentation) (1)

Source: Internet
Author: User

When reading the OSE documentation (OSE architecture User's Guide), I noticed a Summary of the memory fragmentation, which is very incisive. The excerpt is as follows:

The original text is as follows (see the link after the original text. A man has already translated it into Chinese, but he does not know where the original text comes from)

Why is memory fragmentation important

In embedded systems development, memory fragmentation knowledge is crucial

Ultimately, memory fragmentation leads to out-of-memory conditions, even when there might be plenty of free memory left in the system.

In the end, memory fragments will lead to no memory to apply for. Although the total remaining memory seems to be sufficient (but I feel this statement is not rigorous. When the physical memory is insufficient, the system will use virtual memory, hard Disk replacement, so the system should be able to run for a long time, but may eventually run out of memory)

What is memory fragmentation

Fragmented memory is the term used to describe all of a system's unusable free memory. These resources

Remain unused, because the memory allocator that you are using is-for one reason or another-unable

To make this memory available to you. memory fragmentation refers to idle memory that is not available in the system. Because the memory distributor cannot allocate and use these memories

Compile time vs. Run Time

Memory is allocated in unsupported different contexts. The programmer can (by way of the compiler and linker)

Allocate memory for data in structures, unions, arrays, and scalars as local, static, or global variables.

Programmer can also allocate memory dynamically in Run Time Using callsuch as malloc (). When

Compiler and linker perform the memory allocation function, memory fragmentation does not arise, because

The compiler understands the lifetime of the data. The data lifetime offers the nice advantage of being

Stackable (last in, first out). This makes it possible for the memory allocator to work in a very efficient and

Non-fragmenting manner. Generally, memory allocations issued during run time are not stackable. Memory

Allocations are independent in time, which makes the problem extremely difficult to resolve.

Internal/external fragmentation and overhead

Memory allocators waste memory in three basic ways:

• Overhead

• Internal fragmentation

• External fragmentation

The Memory Allocator needs to store some data describing the state of its allocations. That space is generally

Called overhead. This is information about the location, size, and ownership of any free blocks and about

Other internal states. A run-time Allocator typically has no better place to store this overhead information

Than in the memory it manages.

A memory allocator needs to adhere to some basic memory allocation rules. For example, all memory allocations

Must start at an address that is divisible by 4, 8, or 16, depending on the processor architecture.

There may also be other reasons for the memory allocator to only assign blocks of certain predefined sizes

To its clients (Cache-line size perhaps). When a client requests a block of 43 bytes, it may well get 44 or

48, or an even larger number. This extra space that results from rounding the requested size upwards is

Called internal fragmentation.

External fragmentation is created when the Memory Allocator allocates blocks with unused gaps in

Them. This can occur, for example, when an application allocates three blocks in succession and then frees

The one in the middle. The Memory Allocator might reuse the middle block for future allocations, but it is

No longer possible to allocate a block as large as all free memory.

External fragmentation is created when the Memory Allocator allocates blocks with unused gaps in
Them. This can occur, for example, when an application allocates three blocks in succession and then frees
The one in the middle. The Memory Allocator might reuse the middle block for future allocations, but it is
No longer possible to allocate a block as large as all free memory.
Provided the Memory Allocator doesn't change its implementation or Rounding policy in Run Time,
Overhead and internal fragmentation remains constant throughout an application's life time. While overhead
And internal fragmentation may be undesired (because they waste memory), external fragmentation is
Real enemy of embedded systems. External fragmentation is the allocation problem that kills systems.
Whenever the word fragmentation is used throughout the rest of this discussion, think external fragmentation

Definition

Now we are ready for a definition of (external) memory fragmentation. Other definitions are possible,

This is the one most commonly used. It applies to external fragmentation, but can be modified to include

Internal fragmentation (by including internal fragmentation in the denominator ).

Figure 5.1 Definition of memory fragmentation


Fragmentation is a fraction between 0 and 1. A system in which fragmentation = 1 (100%) is completely

Out of memory. With all free memory in a single block (the largest), fragmentation is 0%. With one quarter

Of all free memory in the largest block, fragmentation is 75%. For example, fragmentation is 99% in

System with 5 MB of free memory, when the largest block available for allocation is 50 kb.

A friend has already translated it. If you like Chinese, see:

Http://blog.201314.info/2010/04/25/%E8%BD%AC%EF%BC%9A%E5%86%85%E5%AD%98%E7%A2%8E%E7%89%87%E4%BA%A7%E7%94%9F%E5%8E%9F%E5%9B%A0%E5%8F%8A%E5%A4%84%E7%90%86%E6%8A%80%E6%9C%AF.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.