"Reprint" Memory Fragmentation

Source: Internet
Author: User

Memory FragmentationEditMemory fragmentation is divided into: internal fragments and external fragments Internal FragmentationAn internal fragment is a memory space that has been allocated (which can clearly indicate which process it belongs to) but cannot be exploited; the inner fragment is a block of storage within the region or inside the page. Processes that occupy these areas or pages do not use this storage block. The system cannot take advantage of this block of storage while the process is occupying it. It is not possible for the system to exploit this block until the process releases it, or when the process is finished. The pipettes is continuously allocated with only internal fragments. Multi-channel fixed continuous distribution has both internal and external fragments. external FragmentsExternal fragmentation refers to memory idle areas that are not yet assigned (not part of any process), but are too small to be allocated to new processes that request memory space. An external fragment is an idle block of storage that is outside of any assigned area or page. The sum of these blocks can meet the length requirements of the current request, but the system cannot meet the current request due to their address discontinuity or other reasons. Multi-channel variable continuous distribution only external fragments. 2Reduce Memory FragmentationEdit Memory fragmentation occurs because a block of memory is allocated so that it is idle, but not the free memory is returned to the maximum memory block. This last step is crucial. If the memory allocation program is valid, you cannot prevent the system from allocating memory blocks and making them idle. Even if a memory-allocation program does not guarantee that the returned memory can be connected to the maximum memory block (this method can completely avoid memory fragmentation issues), you can try to control and limit memory fragmentation. All of these practices involve the partitioning of memory blocks. Each time the system reduces the number of partitioned memory blocks and ensures that the chunks of memory are as large as possible, you will improve. The purpose of this is to reuse memory blocks as many times as possible, rather than splitting the blocks of memory every time to exactly match the requested storage. Splitting a block of memory creates a lot of small memory fragmentation, like a heap of sand. It is difficult to combine these scattered sands with the rest of the memory later. It's a good idea to leave some unused bytes in each block of memory. The number of bytes left should be seen to what extent the system avoids memory fragmentation. For small systems, adding a few bytes of internal fragmentation is a step in the right direction. When the system requests 1 bytes of memory, the amount of storage you allocate depends on the operating state of the system. If the primary portion of the memory storage allocated by the system is 1 ~ 16 bytes, it is wise to allocate 16 bytes for small memory. As long as you limit the maximum amount of memory that can be allocated, you can achieve a large savings effect. However, the disadvantage of this approach is that the system is constantly trying to allocate memory blocks that are larger than the limit, which may cause the system to stop working. It is also useful to reduce the amount of memory storage between the maximum and minimum memory block storage. A large amount of fragmentation can be avoided by using log-increased memory block storage. For example, each storage volume might be 20% larger than the previous one. In an embedded system, it may be impractical to use "one storage for all needs" for the memory allocation program in an embedded system. This approach is extremely expensive from the internal fragmentation, but the system can completely avoid external fragmentation and reach the maximum amount of storage supported. Connecting adjacent free memory blocks is a technique that can significantly reduce memory fragmentation. Without this approach, some allocation algorithms, such as the first fit algorithm, will not work at all. However, the effect is limited, and connecting adjacent memory blocks can only alleviate problems caused by the allocation algorithm, but not the underlying problem. Also, adjacent memory block connections can be difficult to implement when memory block storage is limited. Some memory allocators are advanced to collect statistics about the distribution habits of a system at run time, and then classify all memory allocations by storage, such as small, medium, and junior classes. The system assigns each allocation to an area of managed memory, because that area includes the amount of memory block storage. Smaller amounts of storage are allocated based on larger reserves. This scheme is one of the first interesting mixes for the algorithm and a limited set of fixed storage algorithms, but not the realThe time. Effective use of temporary limitations is often difficult, but it is worth mentioning that allocating programs that temporarily extend a place of coexistence in memory are more likely to produce memory fragmentation. While other technologies can mitigate this problem, limiting the number of memory blocks in different storage remains the primary way to reduce memory fragmentation. Modern software environments have implemented various tools to avoid memory fragmentation. For example, the OSE real-time operating system developed specifically for distributed, high-availability fault-tolerant systems provides three runtime memory allocations: Kernel Alloc (), which is allocated according to the system or memory block pool, heap malloc (), allocated according to the program heap, and OSE memory manager Alloc_region, It is allocated according to memory management program memory. In many ways, Alloc is the ultimate memory allocation program. It produces very little memory fragmentation, is fast, and has the ability to determine. You can adjust or even remove memory fragments. An external fragment is generated only when a storage is allocated, which is free, but is no longer allocated. Internal fragments are constantly generated, but they are constant for a given system and eight of storage. Alloc is an implementation method of a fixed storage memory allocation program with eight free tables. System programmers can configure each amount of storage and decide to use less storage to further reduce fragmentation. In addition to the start, allocating memory blocks and making memory blocks idle are constant-time operations. First, the system must round up the amount of storage requested to the next available store. For eight kinds of storage, this goal can be achieved with three if statements. Second, the system always inserts or deletes a block of memory in the table headers of the eight free tables. Initially, allocating unused memory takes a few more cycles, but is still extremely fast and takes time to be constant. The memory overhead of the heap malloc () (8 ~ 16 bytes/allocation) is smaller than alloc, so you can deactivate the exclusive right of the memory. The malloc () allocation program is fairly fast on average. Its internal fragments are less than alloc (), but the external fragments are more than alloc (). It has a maximum amount of allocated storage, but for most systems this limit is large enough. Optional shared ownership and low overhead allow malloc () to apply to C + + applications that have many small objects and shared objects. A heap is a method of implementing a partner system with internal heap data structures. In the OSE, there are 28 different storage available, each of which is the sum of the first two stores, thus forming a Fibonacci (Fibonacci) sequence. The actual memory block storage is multiplied by 16 bytes for the sequence number, which includes the allocation program overhead or 8 bytes/allocation (16 bytes if file and row information is enabled). The OSE Memory management program works best when you rarely need large chunks of memory. A typical system is to allocate storage space to the entire system,Heap or library. In a system with MMU, some implementations use the MMU conversion function to significantly reduce or even eliminate memory fragmentation. In other cases, the OSE memory management program generates very much fragmentation. It has no maximum allocated storage and is an implementation method that is first suitable for memory allocation programs. Memory allocations are rounded to an even number of pages-typically 4 K bytes.

"Reprint" Memory Fragmentation

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.