[go: up one dir, main page]

CN106168926B - Memory allocation method based on linux buddy system - Google Patents

Memory allocation method based on linux buddy system Download PDF

Info

Publication number
CN106168926B
CN106168926B CN201610338920.3A CN201610338920A CN106168926B CN 106168926 B CN106168926 B CN 106168926B CN 201610338920 A CN201610338920 A CN 201610338920A CN 106168926 B CN106168926 B CN 106168926B
Authority
CN
China
Prior art keywords
memory
free
bank
idle
block
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610338920.3A
Other languages
Chinese (zh)
Other versions
CN106168926A (en
Inventor
朱宗卫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Miwei Technology Co ltd
Original Assignee
Individual
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Individual filed Critical Individual
Priority to CN201610338920.3A priority Critical patent/CN106168926B/en
Publication of CN106168926A publication Critical patent/CN106168926A/en
Application granted granted Critical
Publication of CN106168926B publication Critical patent/CN106168926B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F1/00Details not covered by groups G06F3/00 - G06F13/00 and G06F21/00
    • G06F1/26Power supply means, e.g. regulation thereof
    • G06F1/32Means for saving power
    • G06F1/3203Power management, i.e. event-based initiation of a power-saving mode
    • G06F1/3234Power saving characterised by the action undertaken
    • G06F1/329Power saving characterised by the action undertaken by task scheduling
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System (AREA)

Abstract

The invention discloses a memory allocation method based on a linux partner system, which is characterized by comprising the steps of distinguishing and marking idle blocks according to memory banks in advance, and preferentially allocating the idle blocks with the same bank number according to the bank number sequence when an application program applies for a memory. The PASR algorithm based on the Bank-active memory allocation strategy effectively reduces the power consumption in the standby state of the system and improves the battery endurance capacity of the mobile equipment.

Description

基于linux伙伴系统的内存分配方法Memory allocation method based on linux buddy system

技术领域technical field

本发明属于嵌入式设备待机功耗优化技术领域,具体的是一种基于linux伙伴系统的内存分配方法。The invention belongs to the technical field of optimization of standby power consumption of embedded devices, in particular to a memory allocation method based on a linux partner system.

背景技术Background technique

伴随着智能手机的快速发展,长期以来困扰着传统计算机的功耗与性能的矛盾在智能手机上显得更为突出,其主要原因有以下几点:首先,智能手机性能的提升速度远远超过普通计算机的发展速度。归功于在传统计算机方面的技术积累,在过去的几年中,智能手机CPU的速度经历了异常快速的增长速度。其次,电池制造技术的提升速度远落后于电量需求的增长速度。相对于智能手机计算速度的快速提升,手机电池容量的提升却缓慢得很多,这主要是因为手机电池的制造工艺发展缓慢,远远落后于用于CPU制造的集成电路发展速度。另外,由于智能手机作为移动设备的本质特性,手机的体积受到很大的限制。在全球智能手机制造向更轻、更薄的发展趋势下,手机的机身可谓“寸土寸金”,每一块空间都被发挥利用到了极致。依赖手机的结构设计优化或者提升电池的制造工艺来满足快速发展的智能手机电量需求的难度越来越大,寻求新的提升智能手机续航能力的手段刻不容缓。With the rapid development of smart phones, the contradiction between power consumption and performance that has plagued traditional computers for a long time has become more prominent on smart phones. The speed of computer development. Thanks to the accumulation of technology in traditional computers, the speed of smartphone CPUs has experienced an unusually rapid growth rate in the past few years. Second, the improvement rate of battery manufacturing technology lags far behind the growth rate of electricity demand. Compared with the rapid increase in the computing speed of smartphones, the increase in battery capacity of mobile phones is much slower. This is mainly because the manufacturing process of mobile phone batteries has developed slowly, which is far behind the development speed of integrated circuits used in CPU manufacturing. In addition, due to the essential characteristics of smart phones as mobile devices, the volume of mobile phones is greatly limited. Under the trend of global smart phone manufacturing becoming lighter and thinner, the body of the mobile phone can be described as "every inch is precious", and every piece of space has been utilized to the extreme. It is becoming more and more difficult to rely on the optimization of the structural design of the mobile phone or the improvement of the manufacturing process of the battery to meet the power demand of the fast-growing smart phone. It is urgent to find new means to improve the battery life of the smart phone.

作为智能手机的内存,它的能耗占整机能耗的比重相当可观,特别是在待机状态下。不同于SRAM,DRAM需要周期性地进行自刷新以维持它所保存的数据不被丢失。当前DRAM的自刷新策略是全局自刷新,也就是周期性地对整个DRAM进行自刷新。如果某一部分的DRAM没有保存数据,那么显然,对于这一部分DRAM的周期性自刷新是毫无必要的,这就造成了能耗的白白浪费。DRAM的局部阵列自刷新(PASR)策略可以很好地解决这一问题。PASR是指对于整个DRAM,仅对保存有数据的Bank进行周期性地自刷新。As the memory of a smart phone, its energy consumption accounts for a considerable proportion of the energy consumption of the whole machine, especially in the standby state. Unlike SRAM, DRAM needs to perform self-refresh periodically in order to maintain its saved data from being lost. The current self-refresh strategy of the DRAM is global self-refresh, that is, the entire DRAM is periodically self-refreshed. If a certain part of the DRAM does not store data, then obviously, the periodic self-refresh of this part of the DRAM is unnecessary, which causes a waste of energy consumption. DRAM's partial array self-refresh (PASR) strategy can solve this problem well. PASR means that for the entire DRAM, only the Bank with data is periodically self-refreshed.

然而现在Linux的物理内存是较为离散的。对于内核的内存需求,Linux内存管理系统倾向于从低物理地址的内存区分配;而对于用户进程的内存需求,则倾向于从高物理地址的内存区分配。并且随着进程不断创建和消亡的往复循环过程,内存中的碎片问题不可避免,这也加剧了物理内存的离散程度。本发明由此而来。However, the physical memory of Linux is relatively discrete now. For the memory requirements of the kernel, the Linux memory management system tends to allocate from memory areas with low physical addresses; while for the memory requirements of user processes, it tends to allocate from memory areas with high physical addresses. And as the process continues to create and die in a reciprocating cycle, the fragmentation problem in the memory is inevitable, which also aggravates the discreteness of the physical memory. The present invention comes from this.

发明内容Contents of the invention

本发明的目的是提供一种基于linux伙伴系统的内存分配方法,解决了现有技术中现有的linux伙伴系统功耗较高,而采用大量内存数据的硬性迁移聚集可能会带来不小的系统开销,同时还有可能造成内存数据丢失等影响系统稳定安全的诸多问题。The purpose of the present invention is to provide a memory allocation method based on the linux buddy system, which solves the problem that the power consumption of the existing linux buddy system in the prior art is high, and the hard migration and aggregation of a large amount of memory data may cause considerable damage. System overhead, as well as many problems that may affect the stability and security of the system, such as loss of memory data.

为了解决现有技术中的这些问题,本发明提供的技术方案如下:In order to solve these problems in the prior art, the technical scheme provided by the invention is as follows:

一种基于linux伙伴系统的内存分配方法,其特征在于所述方法包括预先将空闲块按照内存bank的不同进行内存bank编号标记,应用程序申请内存时按照bank编号优先分配同一bank编号的空闲块的步骤。A method for allocating memory based on a linux buddy system, characterized in that the method includes pre-marking free blocks with memory bank numbers according to different memory banks, and assigning priority to free blocks of the same bank number according to bank numbers when application programs apply for memory step.

优选的技术方案中,所述方法进行内存bank编号标记后形成同一空闲块位阶(order)不同bank编号的空闲块链表,空闲块位阶依次是0、1、2、3、4、5、6、7、8、9、10,相应空闲块位阶的空闲块依次包含大小为1、2、4、8、16、32、64、128、256、512和1024个连续的空闲页框。In the preferred technical solution, the method forms a free block linked list of different bank numbers of the same free block order after marking the memory bank number, and the order of the free block is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, the free blocks corresponding to the free block ranks sequentially include 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024 consecutive free page frames.

优选的技术方案中,所述方法中空闲块位阶(order)是根据linux伙伴系统的裂分规则进行划分,空闲块位阶依次是0、1、2、3、4、5、6、7、8、9、10,每个空闲块依次包含大小为1、2、4、8、16、32、64、128、256、512和1024个连续的空闲页框。In the preferred technical solution, the order of free blocks in the method is divided according to the splitting rules of the linux partner system, and the order of free blocks is 0, 1, 2, 3, 4, 5, 6, 7 in sequence , 8, 9, 10, each free block sequentially contains 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024 consecutive free page frames.

优选的技术方案中,所述方法中应用程序申请内存时,按照空闲块位阶的优先顺序遍历同一bank编号的空闲块;如找到同一位阶的空闲块,则终止遍历;否则按照bank编号继续遍历下一bank编号的空闲块,如此循环直到找到满足要求的空闲块或者分配失败返回。In the preferred technical solution, when the application program in the method applies for memory, it traverses the free blocks of the same bank number according to the priority order of the free block rank; if a free block of the same rank is found, the traversal is terminated; otherwise, continue according to the bank number Traverse the free blocks of the next bank number, and loop until a free block that meets the requirements is found or the allocation fails and returns.

优选的技术方案中,所述方法中应用程序申请内存时,按照bank编号的优先顺序遍历同一位阶的空闲块;如找到同一位阶的空闲块,则终止遍历;否则继续遍历下一位阶的空闲块,如此循环直到找到满足要求的空闲块或者分配失败返回。In the preferred technical solution, when the application program applies for memory in the method, it traverses the free blocks of the same level according to the priority order of bank numbers; if it finds a free block of the same level, then terminates the traversal; otherwise, it continues to traverse the next level The free block, and so on loop until a free block that meets the requirements is found or the allocation fails and returns.

优选的技术方案中,所述方法中内存初始化时,如果应用程序请求内存找不到同一位阶的空闲块,则linux伙伴系统按照位阶从大到小的顺序进行分裂成伙伴的下一位阶空闲块;如果应用程序请求内存仍然找不到满足要求的空闲块,则继续按照上述方法进行分裂,直到找到同一位阶的空闲块。In the preferred technical solution, when the memory is initialized in the method, if the application program requests the memory and cannot find a free block of the same level, the linux buddy system will split into the next bit of the buddy according to the order from large to small If the application program requests memory and still cannot find a free block that meets the requirements, continue to split according to the above method until a free block of the same level is found.

优选的技术方案中,所述方法中如果应用释放内存时,需判断释放的内存空闲块的伙伴块是否空闲;如果伙伴块为空闲块,则按照linux伙伴系统的合并规则进行合并空闲块;如此循环,直到不能进行合并。In the preferred technical scheme, if the application releases the memory in the method, it is necessary to judge whether the partner block of the released memory free block is free; if the partner block is a free block, then merge the free block according to the merging rules of the linux partner system; Loop until no merging can be done.

本发明的另一目的在于一种linux系统设备的内存刷新方法,其特征在于所述方法包括当整个bank的内存块均为空闲块,且linux系统设备处于深度睡眠状态时,按照内存部分阵列自刷新配置,关闭整个内存bank的刷新。Another object of the present invention is a memory refresh method for linux system equipment, which is characterized in that the method includes when the memory blocks of the entire bank are free blocks, and the linux system equipment is in a deep sleep state, according to the memory part array automatically Refresh the configuration and turn off the refresh of the entire memory bank.

优选的技术方案中,所述方法还包括当linux系统设备从深度睡眠状态唤醒或者进入浅睡眠状态时,关闭内存部分阵列自刷新配置,重新进行整个内存bank的刷新。In a preferred technical solution, the method further includes when the linux system device wakes up from the deep sleep state or enters the light sleep state, closing the self-refresh configuration of the memory part array, and re-refreshing the entire memory bank.

根据linux伙伴系统的划分,将所有的空闲页框分组为11个类型的空闲块链表,每个空闲块链表依次包含大小为1、2、4、8、16、32、64、128、256、512和1024个连续的空闲页框,空闲块链表的order依次是0、1、2、3、4、5、6、7、8、9、10。According to the division of the Linux partner system, all free page frames are grouped into 11 types of free block linked lists, and each free block linked list contains the sizes of 1, 2, 4, 8, 16, 32, 64, 128, 256, There are 512 and 1024 consecutive free page frames, and the order of the free block list is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.

伙伴系统buddy system

伙伴系统是Linux物理内存管理的核心。伙伴系统把所有的空闲页框分组为11个块链表,每个块链表分别包含大小为1,2,4,8,16,32,64,128,256,512和1024个连续的页框。对1024个页框的最大请求对应着4MB大小的连续RAM块。每个块的第一个页框的物理地址是该块大小的整数倍。例如,大小为16个页框的块,其起始地址是16*4096(是一个常规页的大小)的倍数。The buddy system is at the heart of Linux physical memory management. The buddy system groups all free page frames into 11 block lists, and each block list contains 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, and 1024 consecutive page frames. The maximum request for 1024 page frames corresponds to a contiguous RAM block of size 4MB. The physical address of the first page frame of each block is an integer multiple of the block size. For example, a block size of 16 page frames has a starting address that is a multiple of 16*4096 (which is the size of a regular page).

假设要请求一个256个页框的块(即1MB)。算法先在256个页框的链表中检查是否有一个空闲块。如果没有这样的块,算法会查找下一个更大的页块,也就是,在512个页框的链表中找一个空闲块。如果存在这样的块,内核就把512的页框块裂分成两等份,一半用作满足请求,另一半插入到256个页框的链表中。如果在512个页框的块链表中也没找到空闲块,就继续找更大的空闲块——1024个页框的空闲块。如果这样的块存在,内核把1024个页框块分成两等份的512个页框块,把其中一个512个页框块插入到512个页框块的链表中,而把另一个512个页框块继续分成两等份的256个页框块,一个插入256个页框块的链表中,另一个用作满足请求。如果1024个页框的链表还是空的,算法就放弃并发出错信号。Suppose you want to request a block of 256 page frames (ie 1MB). The algorithm first checks for a free block in the linked list of 256 page frames. If there is no such block, the algorithm looks for the next larger page block, that is, finds a free block in the linked list of 512 page frames. If there is such a block, the kernel splits the 512 page frame block into two equal parts, half of which is used to satisfy the request, and the other half is inserted into the linked list of 256 page frames. If no free block is found in the block chain list of 512 page frames, continue to find a larger free block—a free block of 1024 page frames. If such a block exists, the kernel divides the 1024 page frame blocks into two equal parts of 512 page frame blocks, inserts one of the 512 page frame blocks into the linked list of 512 page frame blocks, and inserts the other 512 page frame blocks The frame block is further divided into two equal parts of 256 page frame blocks, one is inserted into the linked list of 256 page frame blocks, and the other is used to satisfy the request. If the linked list of 1024 page frames is still empty, the algorithm gives up and signals an error.

以上过程的逆过程就是页框块的释放过程,也是该算法名字的由来。内核试图把大小为b的一对空闲伙伴块合并为一个大小为2b的单独块。满足以下条件的两个块称为伙伴:a.两个块具有相同的大小,记作b; b.它们的物理地址是连续的; c.第一块的第一个页框的物理地址是2* b*4096的倍数。该算法是迭代的,如果它成功合并所释放的块,它会试图合并2b大小的块,以再次试图形成更大的块。The reverse process of the above process is the release process of the page frame block, which is also the origin of the algorithm name. The kernel tries to merge a pair of free buddy blocks of size b into a single block of size 2b. Two blocks that meet the following conditions are called partners: a. The two blocks have the same size, denoted as b; b. Their physical addresses are consecutive; c. The physical address of the first page frame of the first block is Multiples of 2*b*4096. The algorithm is iterative, and if it successfully merges freed blocks, it tries to merge blocks of size 2b to again attempt to form larger blocks.

把每个内存节点(node)的物理内存划分为3个管理区(zone):ZONE_DMA(0~16M)、ZONE_NORMAL(16M~896M)、ZONE_HIGHMEM(896M~MAX)。通过划分为不同的管理区,内核定义了内存的一个层次结构,有内存请求时首先试图分配“廉价”的内存。如果失败,则根据访问速度和容量,逐渐尝试分配“更昂贵”的内存。Divide the physical memory of each memory node (node) into three management zones (zone): ZONE_DMA (0~16M), ZONE_NORMAL (16M~896M), ZONE_HIGHMEM (896M~MAX). By dividing into different management areas, the kernel defines a hierarchy of memory, and when there is a memory request, it first tries to allocate "cheap" memory. Failing that, incrementally tries to allocate "more expensive" memory, depending on access speed and capacity.

高端内存(ZONE_HIGHMEM)是最廉价的,因为内核没有任何部分依赖于从该内存域分配的内存,如果高端内存域用尽,对内核没有任何副作用,这也是优先分配高端内存的原因。普通内存域(ZONE_NORMAL)的情况有所不同。许多内核数据结构必须保存在该内存域,而不能放置到高端内存域。因此如果普通内存完全用尽,那么内核会面临紧急情况。所以只要高端内存域的内存没有用尽,就不会从普通内存域分配内存。最昂贵的是DMA内存域(ZONE_DMA),因为它用于外设和系统之间的数据传输。因此从该内存域分配内存是最后一招。High memory (ZONE_HIGHMEM) is the cheapest, because no part of the kernel depends on memory allocated from this memory zone. If the high memory zone is exhausted, there will be no side effects on the kernel, which is why high memory is allocated first. The situation is different for the normal memory domain (ZONE_NORMAL). Many kernel data structures must be kept in this memory domain and cannot be placed in the upper memory domain. So if normal memory is completely exhausted, the kernel will panic. So as long as the memory in the upper memory domain is not exhausted, no memory will be allocated from the normal memory domain. The most expensive is the DMA memory zone (ZONE_DMA), since it is used for data transfer between peripherals and the system. So allocating memory from this memory domain is a last resort.

每个管理区根据空闲内存块阶(order)的不同,划分成多个free_area。内存管理区的c语言伪代码如下:Each management area is divided into multiple free_areas according to the order of free memory blocks. The C language pseudocode of the memory management area is as follows:

<include/linux/mmzone.h><include/linux/mmzone.h>

struct zone {struct zone {

……...

/*/*

*不同大小的空闲内存块* Free memory blocks of different sizes

*/*/

struct free_area[MAX_ORDER];struct free_area[MAX_ORDER];

……...

};};

struct free_area {struct free_area {

struct list_head free_list[MIGRATE_TYPES];struct list_head free_list[MIGRATE_TYPES];

unsigned long nr_free;unsigned long nr_free;

};};

可以看出,根据不同的迁移类型(migratetype),每个free_area分成了多个free_list。nr_free表示free_area中所有空闲块的数目。其中不考虑migratetype,这不会对bank造成影响。因此,Linux伙伴系统的组织结构图如图1所示。如果请求一块2个页框的内存域,伙伴算法先在free_area[1]的free_list链表中查找空闲块,若找到了则直接返回;否则,按照算法逻辑去order更大的free_area的free_list链表中去查找、分解、分配,直到满足分配请求或分配失败。It can be seen that each free_area is divided into multiple free_lists according to different migration types (migratetype). nr_free represents the number of all free blocks in free_area. The migratetype is not considered, which will not affect the bank. Therefore, the organizational chart of the Linux buddy system is shown in Figure 1. If a memory domain with 2 page frames is requested, the buddy algorithm first searches for a free block in the free_list linked list of free_area[1], and returns it directly if found; otherwise, go to the free_list linked list of free_area with a larger order according to the algorithm logic Find, break down, allocate until allocation request is satisfied or allocation fails.

聚集(Bank-Intensive)的内存分配策略Aggregation (Bank-Intensive) memory allocation strategy

Linux的伙伴系统简单高效地管理着内存的分配和释放。本发明技术方案中的Bank聚集的内存集中分配策略是通过修改伙伴系统,在分配内存的时候,按照要求分配指定Bank中的内存块,达到Bank聚集的分配效果。Linux's buddy system manages the allocation and release of memory simply and efficiently. The centralized memory allocation strategy of Bank aggregation in the technical solution of the present invention is to allocate the memory blocks in the specified Bank according to requirements when allocating memory by modifying the partner system, so as to achieve the allocation effect of Bank aggregation.

现有的伙伴系统的结构组织中是没有Bank这个概念的,因此它无法感知到Bank的存在,也就无法做到Bank聚集的内存分配。本发明的bank为逻辑bank,即L-bank,SDRAM的内部是一个存储阵列。存储阵列和表格的检索原理一样,先指定一个行(Row),再指定一个列(Column),可以准确地找到所需要的存储单元,这就是内存芯片寻址的基本原理。存储阵列就是逻辑Bank(Logical Bank,简称L-Bank)。There is no concept of Bank in the structure organization of the existing partner system, so it cannot perceive the existence of Bank, and cannot achieve the memory allocation of Bank aggregation. The bank of the present invention is a logic bank, ie L-bank, and the inside of the SDRAM is a storage array. The retrieval principle of the storage array is the same as that of the table. First specify a row (Row) and then specify a column (Column) to accurately find the required storage unit. This is the basic principle of memory chip addressing. The storage array is a logical bank (Logical Bank, L-Bank for short).

本发明技术方案对linux伙伴系统的结构组织进行修改,添加一层Bank结构,对free_list进行细分,重新组织空闲块,根据空闲块的Bank编号把空闲块挂到对应的bank_free_list中。图2是linux伙伴系统修改后的结构组织图。对于order相同的空闲内存块,在原始的伙伴系统中把它们不加区分地挂在了同一free_list链表中;而修改后的伙伴系统则根据这些空闲块的Bank编号的不同,将它们挂在了不同的free_list上。The technical scheme of the present invention modifies the structure organization of the linux partner system, adds a Bank structure, subdivides the free_list, reorganizes the free blocks, and hangs the free blocks into the corresponding bank_free_list according to the Bank numbers of the free blocks. Fig. 2 is the structural organization diagram of the modified linux partner system. For the free memory blocks with the same order, they are hung in the same free_list linked list indiscriminately in the original buddy system; while the modified buddy system hangs them in the same free list according to the different Bank numbers of these free blocks. on a different free_list.

修改后的linux伙伴系统没有删除原始伙伴系统结构组织所涉及到的一些数据结构,只是添加了一些数据结构用来辅助Bank聚集(Bank-Intensive)的内存分配策略的实现。The modified linux buddy system does not delete some data structures involved in the original buddy system structure organization, but only adds some data structures to assist the implementation of the Bank-Intensive memory allocation strategy.

典型的实现如下,在struct free_area中添加成员bank_free_list,如以下的C语言伪代码所示:A typical implementation is as follows, adding member bank_free_list to struct free_area, as shown in the following C language pseudocode:

<include/linux/mmzone.h><include/linux/mmzone.h>

struct free_area {struct free_area {

…… ...

/*/*

*把一个free_list中的空闲块按照Bank号的不同划分到多个bank_free_list中* Divide the free blocks in a free_list into multiple bank_free_lists according to the Bank number

*其中NR_BANKS_PASR表示bank的数目*Where NR_BANKS_PASR indicates the number of banks

*/*/

struct list_head bank_free_list[MIGRATE_TYPES][NR_BANKS_PASR];struct list_head bank_free_list[MIGRATE_TYPES][NR_BANKS_PASR];

……...

};};

在struct page中添加成员bank_list,如以下的C语言伪代码所示:Add the member bank_list to the struct page, as shown in the following C language pseudocode:

<include/linux/mmzone.h><include/linux/mmzone.h>

struct page {struct page {

……...

/*/*

*此bank_list字段存放指向bank_free_list链表中相邻元素的指针,*The bank_list field stores pointers to adjacent elements in the bank_free_list linked list,

*即bank_free_list中的各空闲块通过struct page中的bank_list字段链接起来* That is, the free blocks in bank_free_list are linked through the bank_list field in the struct page

*/*/

struct list_head bank_list;struct list_head bank_list;

……...

};};

通过bank_free_list、bank_list的添加,把一个free_list中的空闲块按照Bank号的不同划分到多个bank_free_list中;而bank_list字段存放指向bank_free_list链表中相邻元素的指针,bank_free_list中的各空闲块通过struct page中的bank_list字段链接起来。这样在伙伴系统的空闲块链表中无缝的插入bank编号,这样可以作为实现bank聚集的基础。Through the addition of bank_free_list and bank_list, the free blocks in a free_list are divided into multiple bank_free_lists according to the different bank numbers; the bank_list field stores pointers to adjacent elements in the bank_free_list linked list, and each free block in the bank_free_list passes through the struct page The bank_list field is linked. In this way, the bank number is seamlessly inserted into the free block list of the partner system, which can be used as the basis for bank aggregation.

内存分配策略memory allocation strategy

从Bank选择的角度,子分配策略可以分为按照Bank编号递增序或递减序分配、指定Bank分配、按照Bank利用率分配等多种分配策略;从Bank聚集程度的角度,子分配策略可以分为Order-Bank策略(保守策略)和Bank-Order策略(激进策略)。从两个角度划分的子分配策略可以分别两两组合成一个完整分配策略。From the perspective of Bank selection, sub-allocation strategies can be divided into various allocation strategies such as allocation in ascending or descending order of Bank numbers, allocation of designated banks, and allocation according to Bank utilization; from the perspective of Bank aggregation degree, sub-allocation strategies can be divided into Order-Bank strategy (conservative strategy) and Bank-Order strategy (radical strategy). The sub-allocation strategies divided from two perspectives can be combined into a complete allocation strategy in two groups.

结合图2解释一下分配策略。假定按照Bank编号递增序分配,分别结合Order-Bank策略和Bank-Order策略。Combined with Figure 2 to explain the allocation strategy. Assuming that the bank numbers are allocated in ascending order, the Order-Bank strategy and the Bank-Order strategy are combined respectively.

策略Strategy

假设要请求一块1个页框的空闲块,先去free_area[0]->bank[0]的bank_free_list中查找,若有满足要求的空闲块,就直接返回。如果没有找到,就去free_area[0]->bank[1]的bank_free_list中查找,依次遍历free_area[0]中bank[2]、bank[3]…的bank_free_list直到找到满足要求的空闲块。如果在free_area[0]中没有找到,再去free_area[1]、free_area[2]……中查找,查找顺序和free_area[0]中一样,直到满足请求或者分配失败返回。Suppose you want to request a free block with 1 page frame, first go to the bank_free_list of free_area[0]->bank[0] to search, if there is a free block that meets the requirements, it will return directly. If not found, go to the bank_free_list of free_area[0]->bank[1] to search, and traverse the bank_free_list of bank[2], bank[3]... in free_area[0] until you find a free block that meets the requirements. If it is not found in free_area[0], then search in free_area[1], free_area[2]..., the search order is the same as in free_area[0], until the request is satisfied or the allocation fails and returns.

策略Strategy

假设要请求一块1个页框的空闲块,先去free_area[0]->bank[0]的bank_free_list中查找,若有满足要求的空闲块,就直接返回。如果没有找到,就去free_area[1]->bank[0]的bank_free_list中查找,依次遍历free_area[2]、free_area[3]……中bank[0]的bank_free_list直到找到满足要求的空闲块。如果在各free_area的bank[0]中没有找到,再去各free_area的bank[1]中查找,查找顺序和bank[1]一样,直到满足请求或者分配失败返回。Suppose you want to request a free block with 1 page frame, first go to the bank_free_list of free_area[0]->bank[0] to search, if there is a free block that meets the requirements, it will return directly. If not found, go to the bank_free_list of free_area[1]->bank[0] to search, and traverse the bank_free_list of bank[0] in free_area[2], free_area[3]... until you find a free block that meets the requirements. If it is not found in the bank[0] of each free_area, then search in the bank[1] of each free_area, the search order is the same as that of bank[1], until the request is satisfied or the allocation fails and returns.

基于bank聚集的内存分配策略在现实的linux智能设备中如何使用。本发明提供了一种实现方式,用于实现linux智能设备的功耗优化,特别是内存功耗的优化。在具体实现中,本发明技术方案以Android智能设备为例进行说明。How to use the memory allocation strategy based on bank aggregation in real linux smart devices. The present invention provides an implementation method for optimizing the power consumption of linux smart devices, especially the optimization of memory power consumption. In a specific implementation, the technical solution of the present invention is described by taking an Android smart device as an example.

待机流程中的PASR配置PASR configuration in standby process

要进行PASR控制,就首先要存在空闲的Bank,而为了达到较好的节能效果,就应该空闲出尽可能多的Bank。根据Linux物理内存布局,只有对离散的内存布局进行调整,对内存数据进行聚集迁移,才能空闲出尽可能多的Bank,才能进行有效的PASR控制已达到较好的节能效果。内存数据聚集迁移,就是将内存中的有效数据聚集到某些Bank上,以空闲出尽可能多的Bank。实现内存数据聚集迁移,最直接的方法就是在系统即将进行PASR控制时,将内存数据硬性的聚集迁移到某些Bank上,而空闲出其余的Bank。然而这种对于大量内存数据的硬性迁移聚集可能会带来不小的系统开销,同时还有可能造成内存数据丢失等影响系统稳定安全的诸多问题。In order to perform PASR control, there must first be idle Banks, and in order to achieve a better energy-saving effect, as many Banks as possible should be idled. According to the physical memory layout of Linux, only by adjusting the discrete memory layout and gathering and migrating memory data, can as many banks as possible be freed, and effective PASR control can be carried out to achieve a better energy-saving effect. In-memory data aggregation and migration is to gather valid data in memory to certain banks to free up as many banks as possible. The most direct way to achieve memory data aggregation and migration is to migrate memory data rigidly to certain banks when the system is about to perform PASR control, and leave the rest of the banks free. However, this kind of hard migration and aggregation of a large amount of memory data may bring a lot of system overhead, and it may also cause memory data loss and many other problems that affect the stability and security of the system.

针对于内存数据硬性聚集迁移的问题,本发明技术方案提出了一种Bank聚集(Bank-Intensive)的内存分配策略。该策略通过修改Linux内存管理系统,使得在内存分配阶段就尽量将内存数据聚集在某些Bank上,大大提升了PASR所带来的功耗收益。Aiming at the problem of hard aggregation and migration of memory data, the technical solution of the present invention proposes a Bank-Intensive memory allocation strategy. By modifying the Linux memory management system, this strategy makes it possible to gather memory data in some Banks during the memory allocation stage, which greatly improves the power consumption benefit brought by PASR.

配置涉及到内存数据的安全性问题,因此,如何选择PASR配置时机显得尤为重要。系统中进程的创建、运行、消亡往往伴随着内存的分配和释放,导致内存一直处在相对活跃状态,不利于进行PASR配置。在Android的Early_Suspend(浅睡眠)状态下,仍然有部分进程在运行,只有进入到标准Linux的Suspend(深度睡眠)状态时,除工作进程外的所有进程都被冻结,此时系统基本不会存在内存的分配、释放操作,内存状态相对平静,可以进行PASR配置,停掉部分空闲Bank的刷新操作以降低待机时的内存功耗。当系统从休眠状态被唤醒时,应当首先进行PASR的复位配置,开启空闲Bank的刷新操作,因为此时系统往往会进行大量的内存分配,若内存分配落入尚未开启刷新操作的空闲Bank中,将造成部分内存数据丢失,甚至带来更为严重的后果。Configuration involves the security of memory data, so how to choose the timing of PASR configuration is particularly important. The creation, running, and death of processes in the system are often accompanied by memory allocation and release, resulting in relatively active memory, which is not conducive to PASR configuration. In the Early_Suspend (light sleep) state of Android, some processes are still running. Only when entering the Suspend (deep sleep) state of standard Linux, all processes except the working process are frozen, and the system will basically not exist at this time. For memory allocation and release operations, the memory state is relatively quiet, and PASR configuration can be performed to stop the refresh operation of some idle banks to reduce memory power consumption during standby. When the system wakes up from the dormant state, the reset configuration of PASR should be performed first, and the refresh operation of the idle bank should be enabled, because the system will often perform a large amount of memory allocation at this time. If the memory allocation falls into the idle bank that has not yet started the refresh operation, Part of the memory data will be lost, and even more serious consequences will be caused.

配置的时机选择Timing of configuration

在标准Linux中,休眠主要分三个主要的步骤:(1)冻结用户态进程和内核态任务;(2)调用注册的设备的suspend的回调函数,其调用顺序是按照驱动加载时的注册顺序。(3)休眠核心设备和使CPU进入休眠态冻结进程是内核把进程列表中所有的进程的状态都设置为停止,并且保存下所有进程的上下文。 当这些进程被解冻的时候,它们是不知道自己被冻结过的,只是简单的继续执行。通过上文的分析可知,PASR的设置时机应该选在核心设备进入休眠态之前,同样地,核心设备被唤醒后应该立即执行PASR的复位操作,打开空闲Bank的刷新操作。通过分析P6s平台kernel源码(版本号为3.0.8),确定了系统进入休眠态的代码位置,如以下的C语言伪代码所示:In standard Linux, hibernation is mainly divided into three main steps: (1) freezing the user mode process and kernel mode tasks; (2) calling the suspend callback function of the registered device, and the calling order is according to the registration order when the driver is loaded . (3) Sleeping the core device and putting the CPU into a sleep state to freeze the process means that the kernel sets the state of all processes in the process list to stop, and saves the context of all processes. When these processes are unfrozen, they do not know that they have been frozen, but simply continue to execute. From the above analysis, it can be seen that the setting time of PASR should be selected before the core device enters the sleep state. Similarly, after the core device is awakened, the reset operation of PASR should be performed immediately, and the refresh operation of the idle bank should be enabled. By analyzing the source code of the P6s platform kernel (version number is 3.0.8), the code location where the system enters the dormant state is determined, as shown in the following C language pseudocode:

/*/*

*File:arch/arm/mach-hi6620/pwrctrl/sleepMgr/pwrctrl_sleep.c*File:arch/arm/mach-hi6620/pwrctrl/sleepMgr/pwrctrl_sleep.c

*/*/

s32_t pwrctrl_deep_sleep(suspend_state_t state)s32_t pwrctrl_deep_sleep(suspend_state_t state)

{{

……...

pwrctrl_asm_deep_sleep_entry(); //休眠入口函数pwrctrl_asm_deep_sleep_entry(); //sleep entry function

……...

}}

pwrctrl_asm_deep_sleep_entry函数由汇编语言编写,是系统完全进入休眠态的入口,应当在执行该函数前,进行PASR设置,关闭空闲Bank的自刷新操作;系统被唤醒时从此函数返回,所以应该紧接在该函数后,进行PASR复位操作,重新开启空闲Bank的自刷新操作。The pwrctrl_asm_deep_sleep_entry function is written in assembly language and is the entry point for the system to enter the dormant state completely. Before executing this function, perform PASR setting and close the self-refresh operation of the idle bank; when the system is awakened, return from this function, so it should be followed by this function After that, the PASR reset operation is performed, and the self-refresh operation of the idle Bank is restarted.

系统休眠前的PASR设置PASR setting before system sleep

在Bank聚集的内存分配策略中,实时统计了各个Bank中的页框使用情况。在进行PASR设置时,首先要根据各个Bank中的页框使用情况识别出空闲Bank,然后通过读写与Bank自刷新相关的寄存器,关闭空闲Bank的自刷新。核心操作步骤如以下的C语言伪代码所示:In the memory allocation strategy of Bank aggregation, the usage of page frames in each Bank is counted in real time. When setting PASR, first identify the idle bank according to the usage of the page frame in each bank, and then close the self-refresh of the idle bank by reading and writing the registers related to the bank's self-refresh. The core operation steps are shown in the following C language pseudocode:

/*/*

*File:arch/arm/mach-hi6620/pwrctrl/sleepMgr/pwrctrl_sleep.c*File:arch/arm/mach-hi6620/pwrctrl/sleepMgr/pwrctrl_sleep.c

*/*/

static void __iomem *REG_BASE_DDRC_DMC0_VIRT = 0;static void __iomem *REG_BASE_DDRC_DMC0_VIRT = 0;

int pasr_set_segment(int rank)int pasr_set_segment(int rank)

{{

…… ...

for(i = 0+rank_tmp*8; i<(rank_tmp+1)*8; i++)for(i = 0+rank_tmp*8; i<(rank_tmp+1)*8; i++)

{{

if(nr_free_pages_per_bank[i]>= 32768) //判断bank[i]是否空闲 if(nr_free_pages_per_bank[i]>= 32768) //Determine whether bank[i] is free

{ {

segment_tmp = i % 8; segment_tmp = i % 8;

segment_tmp = 1<<segment_tmp; segment_tmp = 1<<segment_tmp;

segment |= segment_tmp; segment |= segment_tmp;

} }

}}

……...

value = (segment<<16) | (0x11<<8) | (rank<<4) | 0x2; //空闲bank集合value = (segment<<16) | (0x11<<8) | (rank<<4) | 0x2; // free bank set

……...

//将空闲bank集合写入自刷新控制寄存器关闭其自刷新操作//Write the idle bank set into the self-refresh control register to close its self-refresh operation

writel(value, \ SOC_MDDRC_DMC_DDRC_CFG_SFC_ADDR(REG_BASE_DDRC_DMC0_VIRT));writel(value, \ SOC_MDDRC_DMC_DDRC_CFG_SFC_ADDR(REG_BASE_DDRC_DMC0_VIRT));

……...

return 0;return 0;

}}

当判断出具有空闲bank集合时,将空闲bank集合写入自刷新控制寄存器关闭其自刷新操作。自刷新控制寄存器方便后期系统唤醒后的PASR复位。When it is judged that there is an idle bank set, write the idle bank set into the self-refresh control register to close its self-refresh operation. The self-refresh control register facilitates the PASR reset after the system wakes up later.

系统唤醒后的PASR复位PASR reset after system wake-up

和休眠前的PASR设置相比,系统唤醒后的PASR复位操作要简单一些,因为只需将所有Bank的自刷新操作设为开启状态即可,而不必去详细查询那些自刷新操作被关闭的空闲Bank然后将其开启,操作流程如以下的C语言伪代码所示:Compared with the PASR setting before hibernation, the PASR reset operation after the system wakes up is simpler, because it only needs to set the self-refresh operation of all Banks to the on state, without having to query in detail the idle banks whose self-refresh operation is turned off. Bank then turns it on, and the operation process is shown in the following C language pseudocode:

/*/*

*File:arch/arm/mach-hi6620/pwrctrl/sleepMgr/pwrctrl_sleep.c*File:arch/arm/mach-hi6620/pwrctrl/sleepMgr/pwrctrl_sleep.c

*/*/

int pasr_reset_segment(void)int pasr_reset_segment(void)

{{

……...

value = 0x0 | (0x11<<8) | (0x3<<4) | 0x2; //所有bank的集合value = 0x0 | (0x11<<8) | (0x3<<4) | 0x2; //A collection of all banks

……...

//将所有bank的自刷新设为开启状态//Set self-refresh of all banks to on

writel(value, SOC_MDDRC_DMC_DDRC_CFG_SFC_ADDR(REG_BASE_DDRC_DMC0_VIRT));writel(value, SOC_MDDRC_DMC_DDRC_CFG_SFC_ADDR(REG_BASE_DDRC_DMC0_VIRT));

……...

return 0;return 0;

}}

在休眠-唤醒函数pwrctrl_asm_deep_sleep_entry前后分别调用pasr_set_segment函数和pasr_reset_segment函数,就完成了待机流程中的PASR配置,如以下的C语言伪代码所示:Call the pasr_set_segment function and pasr_reset_segment function before and after the sleep-wake function pwrctrl_asm_deep_sleep_entry to complete the PASR configuration in the standby process, as shown in the following C language pseudo code:

/*/*

*File:arch/arm/mach-hi6620/pwrctrl/sleepMgr/pwrctrl_sleep.c*File:arch/arm/mach-hi6620/pwrctrl/sleepMgr/pwrctrl_sleep.c

*/*/

s32_t pwrctrl_deep_sleep(suspend_state_t state)s32_t pwrctrl_deep_sleep(suspend_state_t state)

{{

……...

pasr_set_segment(0); //关闭rank0中空闲bank的自刷新pasr_set_segment(0); //Close the self-refresh of the idle bank in rank0

pasr_set_segment(1); //关闭rank1中空闲bank的自刷新pasr_set_segment(1); //Close the self-refresh of the idle bank in rank1

pwrctrl_asm_deep_sleep_entry(); pwrctrl_asm_deep_sleep_entry();

pasr_reset_segment(); //开启bank的自刷新pasr_reset_segment(); //Enable bank self-refresh

……...

}}

方法即是将PASR配置信息关闭如清空自刷新控制寄存器的暂存信息,然后将所有bank置为自刷新状态。The method is to close the PASR configuration information, such as clearing the temporary storage information of the self-refresh control register, and then set all banks to the self-refresh state.

相对于现有技术中的方案,本发明的优点是:Compared with the scheme in the prior art, the advantages of the present invention are:

本发明基于bank聚集(Bank-Intensive)的内存分配策略,通过修改Linux伙伴系统的原始内存分配策略,以使内存分配相对于bank能达到较好的聚集效果。通过在多方平台的实验验证,聚集效果相当不错。配合以PASR控制,在P6s平台下的待机功耗优化收益达到了23%,体现了该PASR算法的有效性和实用性。总之,基于Bank-Intensive内存分配策略的PASR算法有效地降低了系统待机状态下的功耗,提升了移动设备的电池续航能力。The present invention is based on a bank-intensive memory allocation strategy, and by modifying the original memory allocation strategy of the Linux partner system, the memory allocation can achieve a better aggregation effect relative to the bank. Through the experimental verification on the multi-party platform, the aggregation effect is quite good. Cooperating with PASR control, the profit of standby power optimization under the P6s platform reaches 23%, which reflects the effectiveness and practicability of the PASR algorithm. In short, the PASR algorithm based on the Bank-Intensive memory allocation strategy effectively reduces the power consumption of the system in standby mode and improves the battery life of mobile devices.

附图说明Description of drawings

下面结合附图及实施例对本发明作进一步描述。The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

图1为原始的Linux伙伴系统组织结构图。Figure 1 is an organizational chart of the original Linux buddy system.

图2为linux伙伴系统修改后的组织结构图。Figure 2 is the modified organization chart of the linux partner system.

图3为原始内存分配策略的内存分配结果。Figure 3 shows the memory allocation result of the original memory allocation strategy.

图4为按照bank利用率进行分配的bank-order分配策略的内存分配图。Figure 4 is a memory allocation diagram of the bank-order allocation strategy allocated according to the bank utilization rate.

图5为系统启动稳定后,各segment的使用情况。Figure 5 shows the usage of each segment after the system is started and stabilized.

图6为启动一个应用,各segment的使用情况。Figure 6 shows the usage of each segment when an application is started.

图7为启动多个应用,各segment的使用情况。Figure 7 shows the usage of each segment when multiple applications are started.

具体实施方式Detailed ways

以下结合具体实施例对上述方案做进一步说明。应理解,这些实施例是用于说明本发明而不限制本发明的范围。实施例中采用的实施条件可以根据具体系统的条件做进一步调整,未注明的实施条件通常为常规实验中的条件。The above solution will be further described below in conjunction with specific embodiments. It should be understood that these examples are used to illustrate the present invention and not to limit the scope of the present invention. The implementation conditions used in the examples can be further adjusted according to the conditions of the specific system, and the unspecified implementation conditions are usually the conditions in routine experiments.

实施例Example

实验目的Purpose

Bank聚集(Bank-Intensive)的内存分配策略通过修改Linux伙伴系统,在原始的结构组织基础上添加一层Bank结构,实现相对于Bank较为集中的内存分配。此实验的目的是测试验证该分配策略的内存聚集效果。The Bank-Intensive memory allocation strategy modifies the Linux partner system and adds a Bank structure on the basis of the original structure organization to achieve a more concentrated memory allocation than the Bank. The purpose of this experiment is to test and verify the memory aggregation effect of this allocation strategy.

实验平台experiment platform

软件平台:Windows XP(宿主机)+VMware(虚拟机)+android-x86;Software platform: Windows XP (host) + VMware (virtual machine) + android-x86;

该实验平台是在windows XP宿主机上安装VMware虚拟机,在虚拟机中运行android-x86系统,已完成对本策略的测试验证。The experimental platform is to install a VMware virtual machine on a Windows XP host machine, and run the android-x86 system in the virtual machine. The test and verification of this strategy has been completed.

下面具体介绍一下实验平台的各部分。The following is a detailed introduction to each part of the experimental platform.

(宿主机)采用CPU型号为Intel Core2 Quad Q8400,4G内存,500G硬盘。(Host) CPU model is Intel Core2 Quad Q8400, 4G memory, 500G hard disk.

(虚拟机)为其在宿主机的硬件环境中配置2个处理器,每个处理器1个核心,2G内存,20G硬盘(Virtual machine) It configures 2 processors in the hardware environment of the host machine, each processor has 1 core, 2G memory, and 20G hard disk

虚拟的内存规格,信息如下:Virtual memory specifications, the information is as follows:

DDR大小2GByte,2个rank,每个rank中有8个bank,数据位宽32位,内部4个DIE,每个DIE数据位宽16位,每个rank由2个DIE组成,即两个16bit拼接成32bit。表1是DRAM地址映射方式,1位rank号和3位bank号共同组成了16个Bank。DDR size is 2GByte, 2 ranks, each rank has 8 banks, data bit width is 32 bits, internal 4 DIEs, each DIE data bit width is 16 bits, each rank is composed of 2 DIEs, namely two 16bits Spliced into 32bit. Table 1 shows the DRAM address mapping method. The 1-bit rank number and the 3-bit bank number together form 16 Banks.

表1 DRAM地址映射方式 rank row bank column DW 比特数 1 14 3 11 2 固定为2'b00 Table 1 DRAM address mapping method rank row bank column DW number of bits 1 14 3 11 2 Fixed to 2'b00

Android-x86选用ics-x86版本,该版本基于Android4.0(Ice Cream Sandwich)。Android-x86 uses the ics-x86 version, which is based on Android4.0 (Ice Cream Sandwich).

实验方法experimental method

测试的内容为系统启动的整个过程中的内存分配,也就是系统本身运行所需的内存分配。当系统启动完成且运行平稳后,插入内存统计的模块,进行内存分配情况的统计。当卸载模块时,内存分配情况的统计结构就会输出在终端上。The content of the test is the memory allocation during the whole process of system startup, that is, the memory allocation required for the system itself to run. After the system starts up and runs smoothly, insert the memory statistics module to make statistics on memory allocation. When a module is unloaded, a statistical structure of the memory allocation is output on the terminal.

实验结果及分析Experimental Results and Analysis

测试了分配策略所提到的多种分配策略,以按照bank利用率进行分配的bank-order分配策略为例,分析一下实验结果。The various allocation strategies mentioned in the allocation strategy were tested, and the bank-order allocation strategy that is allocated according to the bank utilization rate was taken as an example to analyze the experimental results.

图3与图4中的bank_no表示Bank编号,nr_alloc_pages表示该Bank中已分配的页框数目,nr_free_pages表示该Bank中空闲的页框数目。total_nr_free_pages和total_nr_alloc_pages分别表示整个系统中空闲的页框数目和已分配的页框数目。对比图3与图4,可以看到:原始的内存分配策略感知不到Bank的存在,内存分配相对于Bank而言是随机的、离散的;而在按照Bank利用率进行分配的Bank-Order分配策略中,Bank9~Bank15基本上都被空闲了出来,40%的页框都分配在了Bank8上(26203 / 64086),聚集效果十分明显。bank_no in FIG. 3 and FIG. 4 indicates the bank number, nr_alloc_pages indicates the number of allocated page frames in the bank, and nr_free_pages indicates the number of free page frames in the bank. total_nr_free_pages and total_nr_alloc_pages respectively represent the number of free page frames and the number of allocated page frames in the entire system. Comparing Figure 3 and Figure 4, it can be seen that the original memory allocation strategy does not perceive the existence of Bank, and memory allocation is random and discrete compared to Bank; while Bank-Order allocation based on Bank utilization In the strategy, Bank9~Bank15 are basically freed, and 40% of the page frames are allocated to Bank8 (26203 / 64086), and the aggregation effect is very obvious.

平台下的聚集效果及功耗收益验证Aggregation effect and power consumption benefit verification under the platform

由于受平台限制,前期的实验部分是在虚拟环境下进行的。本小节将PASR算法移植到P6s平台下,进行现实环境下的实验测试,包括Bank-Intensive内存分配策略的聚集效果验证以及其所带来的功耗收益验证。Due to the limitation of the platform, the early part of the experiment was carried out in a virtual environment. In this section, the PASR algorithm is transplanted to the P6s platform for experimental testing in a real environment, including the verification of the aggregation effect of the Bank-Intensive memory allocation strategy and the verification of the power consumption benefits it brings.

平台搭载了主频为1.6G HZ的海思Kirin910四核处理器,运行内存RAM容量为2GB。内存DRAM的地址映射模式如表1所示。The platform is equipped with a HiSilicon Kirin910 quad-core processor with a main frequency of 1.6G HZ and a RAM capacity of 2GB. The address mapping mode of memory DRAM is shown in Table 1.

经过查看芯片手册以及讨论分析,P6s平台下DRAM的PASR可控粒度为segment(row中的前3位)或者bank。为了保证可控粒度单位内的连续内存块足够大以尽量能满足内存分配请求,本PASR算法选择segmen作为PASR的基本控制单元。下面分别测试了系统启动后、启动一个应用程序以及启动多个应用程序等3种应用场景下的Bank-Intensive内存分配策略(按照segment利用率分配,优先分配利用率高的segment)的效果。After checking the chip manual and discussion and analysis, the PASR controllable granularity of DRAM under the P6s platform is segment (the first 3 digits in the row) or bank. In order to ensure that the continuous memory block in the controllable granularity unit is large enough to satisfy the memory allocation request as much as possible, this PASR algorithm selects segment as the basic control unit of PASR. The effect of the Bank-Intensive memory allocation strategy (allocated according to the segment utilization rate, and the segment with high utilization rate is allocated first) is tested respectively in the following three application scenarios: after the system is started, when an application is started, and when multiple applications are started.

图5是系统启动稳定后,各segment的使用情况。可以看出segment2,segment7~segment12都是完全空闲的。图6是系统启动稳定后,启动一个应用,各segment的使用情况。可以看出,内存分配集中在了segment7和segment8上,segment2,segment9~segment12依然完全空闲。Figure 5 shows the usage of each segment after the system is started and stabilized. It can be seen that segment2, segment7~segment12 are completely free. Figure 6 shows the usage of each segment when an application is started after the system is stable. It can be seen that the memory allocation is concentrated on segment7 and segment8, and segment2, segment9~segment12 are still completely free.

图7是继续启动应用,各segment的使用情况。可以看出,内存分配继续集中在segment7和segment8上,其中segment7更是被完全分配完,segment2, segment9~segment12依然完全空闲。Figure 7 shows the usage of each segment after continuing to start the application. It can be seen that the memory allocation continues to concentrate on segment7 and segment8, among which segment7 is completely allocated, and segment2, segment9~segment12 are still completely free.

以上实验数据表明,Bank-Intensive内存分配策略在P6s平台下同样表现出了优秀的聚集分配效果,充分使用已被占用的segment,以空闲出更多的segment进行PASR控制。结合Android待机流程中的PASR配置,在系统进入待机状态时关闭空闲segment的自刷新,测试功耗收益,结果:在原始待机状态下,系统的平均电流为2.60mA,开启基于Bank-Intensive内存分配策略的PASR控制后,平均电流降到了2.00mA,收益达到了23%。分析原因不难发现,系统启动平稳后有7个segment是完全空闲的(如图5所示),PASR控制通过配置相关寄存器关掉了这7个空闲segment的自刷新操作,因此带来了上述功耗收益。The above experimental data shows that the Bank-Intensive memory allocation strategy also exhibits excellent aggregation and allocation effects on the P6s platform, making full use of the occupied segments to free up more segments for PASR control. Combined with the PASR configuration in the Android standby process, turn off the self-refresh of the idle segment when the system enters the standby state, and test the power consumption gain. The result: in the original standby state, the average current of the system is 2.60mA, and the memory allocation based on Bank-Intensive is enabled After the PASR control of the strategy, the average current drops to 2.00mA, and the gain reaches 23%. Analyzing the reason, it is not difficult to find that after the system starts smoothly, 7 segments are completely idle (as shown in Figure 5). PASR control disables the self-refresh operation of these 7 idle segments by configuring related registers, thus bringing the above-mentioned power gain.

上述实施例只为说明本发明的技术构思及特点,其目的在于让熟悉此项技术的人是能够了解本发明的内容并据以实施,并不能以此限制本发明的保护范围。凡根据本发明精神实质所做的等效变换或修饰,都应涵盖在本发明的保护范围之内。The above-mentioned embodiments are only to illustrate the technical conception and characteristics of the present invention. The purpose is to enable those familiar with this technology to understand the content of the present invention and implement it accordingly, and not to limit the protection scope of the present invention. All equivalent changes or modifications made according to the spirit of the present invention shall fall within the protection scope of the present invention.

Claims (6)

1. The memory allocation method based on the linux partner system is characterized by comprising the steps of marking the free blocks with memory bank numbers according to different memory banks in advance, and preferentially allocating the free blocks with the same bank number according to the bank numbers when an application program applies for a memory; the method comprises the steps of marking memory bank numbers to form a free block linked list of different bank numbers of the same free block level (order), wherein the free block level is 0, 1,2, 3, 4, 5, 6, 7, 8, 9 and 10 in sequence, and the free blocks of the corresponding free block level sequentially comprise continuous free page frames with the sizes of 1,2,4,8, 16, 32, 64, 128, 256, 512 and 1024.
2. The memory allocation method according to claim 1, wherein the idle block levels (orders) in the method are divided according to a split rule of a linux partner system, the idle block levels are sequentially 0, 1,2, 3, 4, 5, 6, 7, 8, 9, 10, and each idle block sequentially contains 1,2,4,8, 16, 32, 64, 128, 256, 512, and 1024 consecutive idle page frames.
3. The memory allocation method according to claim 1, wherein when an application program applies for memory, the method traverses idle blocks with the same bank number according to the priority order of idle block levels; if the idle blocks with the same level are found, the traversal is terminated; otherwise, traversing the idle block of the next bank number according to the bank number, and circulating until the idle block meeting the requirement is found or the allocation fails to return.
4. The memory allocation method according to claim 1, wherein when an application program applies for memory, the method traverses idle blocks of the same level according to the priority order of bank numbers; if the idle blocks with the same level are found, the traversal is terminated; otherwise, continuing to traverse the idle block of the next level, and circulating until the idle block meeting the requirement is found or the allocation fails to return.
5. The memory allocation method according to claim 1, wherein when the memory is initialized in the method, if the application program requests the memory to find the idle blocks with the same level, the linux partner system splits the idle blocks into the idle blocks with the next level of the partner according to the order from the higher level to the lower level; if the application program requests the memory to still find the idle blocks meeting the requirement, the method continues to split until the idle blocks with the same level are found.
6. The memory allocation method according to claim 1, wherein if the application releases the memory, it is determined whether the partner block of the released memory free block is free; if the partner block is an idle block, the idle block is merged according to the merging rule of the linux partner system; this is looped until no merging can take place.
CN201610338920.3A 2016-05-20 2016-05-20 Memory allocation method based on linux buddy system Active CN106168926B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610338920.3A CN106168926B (en) 2016-05-20 2016-05-20 Memory allocation method based on linux buddy system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610338920.3A CN106168926B (en) 2016-05-20 2016-05-20 Memory allocation method based on linux buddy system

Publications (2)

Publication Number Publication Date
CN106168926A CN106168926A (en) 2016-11-30
CN106168926B true CN106168926B (en) 2023-07-07

Family

ID=57359148

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610338920.3A Active CN106168926B (en) 2016-05-20 2016-05-20 Memory allocation method based on linux buddy system

Country Status (1)

Country Link
CN (1) CN106168926B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107729146A (en) * 2017-10-11 2018-02-23 晶晨半导体(上海)股份有限公司 A kind of memory release method
CN107908475B (en) * 2017-11-09 2021-11-26 深圳市创维软件有限公司 Memory capacity judging method, server and storage medium
CN111858393B (en) * 2020-07-13 2023-06-02 Oppo(重庆)智能科技有限公司 Memory page management method, memory page management device, medium and electronic equipment
CN113849311B (en) * 2021-09-28 2023-11-17 苏州浪潮智能科技有限公司 Memory space management method, device, computer equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102662853A (en) * 2012-03-22 2012-09-12 北京北大众志微系统科技有限责任公司 Memory management method and device capable of realizing memory level parallelism
CN105068940A (en) * 2015-07-28 2015-11-18 北京工业大学 Self-adaptive page strategy determination method based on Bank division

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8094500B2 (en) * 2009-01-05 2012-01-10 Sandisk Technologies Inc. Non-volatile memory and method with write cache partitioning

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102662853A (en) * 2012-03-22 2012-09-12 北京北大众志微系统科技有限责任公司 Memory management method and device capable of realizing memory level parallelism
CN105068940A (en) * 2015-07-28 2015-11-18 北京工业大学 Self-adaptive page strategy determination method based on Bank division

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
面向虚拟共享域划分的自适应迁移与复制机制;黄安文等;《计算机研究与发展》;20130815(第08期);全文 *

Also Published As

Publication number Publication date
CN106168926A (en) 2016-11-30

Similar Documents

Publication Publication Date Title
CN104769520B (en) System and method for dynamic memory power management
US11977484B2 (en) Adapting in-memory database in hybrid memory systems and operating system interface
US9348527B2 (en) Storing data in persistent hybrid memory
US10365842B2 (en) System and method for reducing power consumption of memory
US20160085585A1 (en) Memory System, Method for Processing Memory Access Request and Computer System
US10698732B2 (en) Page ranking in operating system virtual pages in hybrid memory systems
CN103593324B (en) A fast-starting low-power computer system-on-chip with self-learning function
CN103136120B (en) Row buffering operating strategy defining method and device, bank division methods and device
Cui et al. DTail: a flexible approach to DRAM refresh management
TW201812565A (en) Method and system for managing memory power consumption
CN106168926B (en) Memory allocation method based on linux buddy system
CN103019955B (en) The EMS memory management process of PCR-based AM main memory application
WO2016112713A1 (en) Processing method and device for memory page in memory
CN104798058B (en) Method and device for efficiently storing/recovering state information during power state transition
Kim et al. CAUSE: Critical application usage-aware memory system using non-volatile memory for mobile devices
CN104360825A (en) Hybrid internal memory system and management method thereof
JP2018500639A (en) System and method for reducing standby power of volatile memory in portable computing devices
WO2016106738A1 (en) Transaction conflict detection method and apparatus and computer system
WO2021129847A1 (en) Memory setting method and apparatus
CN115794680A (en) A multi-core operating system based on hardware cloning technology and its control method
US11556253B1 (en) Reducing power consumption by selective memory chip hibernation
TW201435586A (en) Flash memory apparatus, and method and device for managing data thereof
US10365997B2 (en) Optimizing DRAM memory based on read-to-write ratio of memory access latency
CN103744791A (en) Memory migration method and device
CN117785931A (en) Data processing method, device, system and related equipment

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20250608

Address after: 215164 Jiangsu Province Suzhou City Suzhou Industrial Park Ren'ai Road 166 Administrative Building 307 309

Patentee after: Suzhou Miwei Technology Co.,Ltd.

Country or region after: China

Address before: Zhongshan East Road, Mudu town of Suzhou city in Jiangsu province 215101 No. 70

Patentee before: Zhu Zongwei

Country or region before: China