CN106874119A - Merging method and device based on the scanning of homogeneity internal memory - Google Patents
Merging method and device based on the scanning of homogeneity internal memory Download PDFInfo
- Publication number
- CN106874119A CN106874119A CN201710105084.9A CN201710105084A CN106874119A CN 106874119 A CN106874119 A CN 106874119A CN 201710105084 A CN201710105084 A CN 201710105084A CN 106874119 A CN106874119 A CN 106874119A
- Authority
- CN
- China
- Prior art keywords
- memory
- page
- pool
- homogeneous
- pages
- 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.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5061—Partitioning or combining of resources
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45533—Hypervisors; Virtual machine monitors
- G06F9/45558—Hypervisor-specific management and integration aspects
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45533—Hypervisors; Virtual machine monitors
- G06F9/45558—Hypervisor-specific management and integration aspects
- G06F2009/45583—Memory management, e.g. access or allocation
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5011—Pool
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明涉及虚拟化集群系统的内存优化技术领域,特别是一种基于同质内存扫描的合并方法及装置,针对虚拟化集群系统的内存优化需要,构建一种利用虚拟化技术来无缝聚合同质内存资源的方法及装置,对系统中的空闲内存资源进行统一管理,为在全局内搜寻同质内存提供基础。包括:将内存页面存入动态内存池;查找动态内存池中的内存页面是否在稳定树中存在同质内存页面,若是,则将动态内存池中的内存页面添加到稳定树中;若否,则进行下一步;查找动态内存池中的内存页面是否在非稳定树中存在同质内存页面,若是,则将动态内存池中的内存页面添加到稳定树中;若否,则将动态内存池中的内存页面添加到非稳定树中。
The present invention relates to the technical field of memory optimization of a virtualized cluster system, in particular to a homogeneous memory scanning-based merging method and device. Aiming at the memory optimization needs of a virtualized cluster system, a virtualization technology is used to seamlessly aggregate homogeneous The invention provides a method and device for quality memory resources, and uniformly manages free memory resources in the system, providing a basis for searching for homogeneous memory globally. Including: storing the memory page in the dynamic memory pool; finding whether the memory page in the dynamic memory pool has a homogeneous memory page in the stable tree, if so, adding the memory page in the dynamic memory pool to the stable tree; if not, Then proceed to the next step; find out whether the memory pages in the dynamic memory pool have homogeneous memory pages in the unstable tree, if so, add the memory pages in the dynamic memory pool to the stable tree; The memory pages in are added to the unstable tree.
Description
技术领域technical field
本发明涉及虚拟化集群系统的内存优化技术领域,特别是一种基于同质内存扫描的合并方法及装置。The invention relates to the technical field of memory optimization of a virtualized cluster system, in particular to a method and device for merging based on homogeneous memory scanning.
背景技术Background technique
每个虚拟机上的内存会完整的映射到物理内存上,由于一台服务器上的多个虚拟机运行同一操作系统,因此物理内存中存在大量相同的内存页面,在这里称之为同质内存。现代操作系统设计中,共享内存己经成为一个普遍采用的技术,正是通过这一特点,我们可以将这些同质内存让多个虚拟机共享,通过扫描内存中的页,找到不同虚拟机之间的相同的内存页,然后将相同的内存页进行合并,当某个虚拟机需要修改内存页时,重新申请一个内存页,拷贝原来页数据到此内存页,将此内存页给需要改变内存页的虚拟机,从而达到降低总体内存需求,通过资源复用提高单台服务器内的资源优化,我们将这种方法称之为“节流”。The memory on each virtual machine will be completely mapped to the physical memory. Since multiple virtual machines on a server run the same operating system, there are a large number of identical memory pages in the physical memory, which is called homogeneous memory here. . In the design of modern operating systems, shared memory has become a commonly used technology. It is through this feature that we can share these homogeneous memories with multiple virtual machines. By scanning the pages in the memory, we can find the difference between different virtual machines and then merge the same memory pages. When a virtual machine needs to modify a memory page, re-apply for a memory page, copy the original page data to this memory page, and give this memory page to the memory page that needs to be changed. Page virtual machine, so as to reduce the overall memory demand, and improve resource optimization in a single server through resource reuse. We call this method "throttling".
虽然同质内存共享技术大大节省了内存的使用量,但是为了充分利用服务器的各资源,管理员通常将不同类型的服务器应用,如计算密集型,通信密集型,密集型等,放在同一台服务器上以提高单台服务器的利用率,由于单台服务器上的同构虚拟机数量的减少,又会影响的使用效果。同时虚拟机中数据可分为读频繁和写频繁,因此对于某些内存页并且对内存也数据进行不加区分的进行共享,这就导致了对于写频繁的内存页频繁的被分离出去,而由于分页造成的开销远远大于实用同质内存复用带来的性能提升。Although the homogeneous memory sharing technology greatly saves the memory usage, in order to make full use of the resources of the server, the administrator usually puts different types of server applications, such as computing-intensive, communication-intensive, and intensive, etc., on the same server. In order to improve the utilization rate of a single server, due to the reduction of the number of homogeneous virtual machines on a single server, it will affect the use effect. At the same time, the data in the virtual machine can be divided into frequent reads and frequent writes. Therefore, some memory pages and memory data are shared indiscriminately, which leads to the frequent separation of frequently written memory pages. The overhead caused by paging is far greater than the performance improvement brought by practical homogeneous memory reuse.
发明内容Contents of the invention
鉴于此,本发明提供一种基于同质内存扫描的合并方法及装置,针对虚拟化集群系统的内存优化需要,构建一种利用虚拟化技术来无缝聚合同质内存资源的方法及装置,对系统中的空闲内存资源进行统一管理,为在全局内搜寻同质内存提供基础。In view of this, the present invention provides a method and device for merging based on homogeneous memory scanning. Aiming at the memory optimization needs of a virtualized cluster system, a method and device for seamlessly aggregating homogeneous memory resources using virtualization technology are constructed. Unified management of free memory resources in the system provides a basis for searching for homogeneous memory globally.
为了达到上述目的,本发明是通过以下技术方案实现的:In order to achieve the above object, the present invention is achieved through the following technical solutions:
本发明提供一种基于同质内存扫描的合并方法,包括: 将内存页面存入动态内存池;查找动态内存池中的内存页面是否在稳定树中存在同质内存页面,若是,则将动态内存池中的内存页面添加到稳定树中;若否,则进行下一步; 查找动态内存池中的内存页面是否在非稳定树中存在同质内存页面,若是,则将动态内存池中的内存页面添加到稳定树中;若否,则将动态内存池中的内存页面添加到非稳定树中。The present invention provides a method for merging based on homogeneous memory scanning, including: storing memory pages into a dynamic memory pool; finding whether the memory pages in the dynamic memory pool have homogeneous memory pages in the stable tree, and if so, storing the memory pages in the dynamic memory pool Add the memory pages in the pool to the stable tree; if not, go to the next step; find out whether the memory pages in the dynamic memory pool have homogeneous memory pages in the unstable tree, and if so, add the memory pages in the dynamic memory pool Add to the stable tree; if not, add the memory page in the dynamic memory pool to the unstable tree.
进一步地,将内存页面存入动态内存池之前,还包括: 创建动态内存池。Further, before storing the memory page into the dynamic memory pool, it also includes: creating the dynamic memory pool.
进一步地,将内存页面存入动态内存池,包括: 为发生读写操作的内存页面添加去重标识; 将添加了去重标识的内存页面存入动态内存池。Further, storing the memory pages into the dynamic memory pool includes: adding deduplication marks to the memory pages where read and write operations occur; and storing the memory pages with deduplication marks added into the dynamic memory pool.
进一步地,将添加了去重标识的内存页面存入动态内存池,包括: 将添加了去重标识的内存页面存入有限环形栈,有限环形栈最上层放置最新存入的内存页面。Further, storing the memory page with the deduplication mark added into the dynamic memory pool includes: storing the memory page with the deduplication mark into the limited ring stack, and placing the latest stored memory page at the top of the limited ring stack.
进一步地,将动态内存池中的内存页面添加到非稳定树中,包括: 计算动态内存池中的内存页面的哈希值; 将动态内存池中的内存页面添加到非稳定树。Further, adding the memory pages in the dynamic memory pool to the unstable tree includes: calculating a hash value of the memory pages in the dynamic memory pool; adding the memory pages in the dynamic memory pool to the unstable tree.
进一步地,将动态内存池中的内存页面添加到非稳定树中之后,还包括: 将添加到非稳定树中的内存页面标记为只读。Further, after adding the memory pages in the dynamic memory pool to the unstable tree, the method further includes: marking the memory pages added to the unstable tree as read-only.
本发明还提供一种基于同质内存扫描的合并装置,包括: 内存页面存入模块,用于将内存页面存入动态内存池; 第一查找模块,用于查找动态内存池中的内存页面是否在稳定树中存在同质内存页面; 第二查找模块,用于查找动态内存池中的内存页面是否在非稳定树中存在同质内存页面; 第一添加模块,用于将动态内存池中的内存页面添加到稳定树中; 第二添加模块,用于将动态内存池中的内存页面添加到非稳定树中。The present invention also provides a merging device based on homogeneous memory scanning, including: a memory page storage module, used to store the memory page into the dynamic memory pool; a first search module, used to check whether the memory page in the dynamic memory pool is There are homogeneous memory pages in the stable tree; the second search module is used to find whether the memory pages in the dynamic memory pool have homogeneous memory pages in the unstable tree; the first adding module is used to use the memory pages in the dynamic memory pool The memory page is added to the stable tree; the second adding module is used to add the memory page in the dynamic memory pool to the non-stable tree.
进一步地,还包括: 动态内存池创建模块,用于创建动态内存池。Further, it also includes: a dynamic memory pool creating module, configured to create a dynamic memory pool.
进一步地,还包括: 去重标识添加模块,用于为发生读写操作的内存页面添加去重标识。Further, it also includes: a de-duplication identification adding module, configured to add de-duplication identifications to the memory pages where read and write operations occur.
进一步地,还包括: 哈希计算模块,用于计算动态内存池中的内存页面的哈希值;Further, it also includes: a hash calculation module, configured to calculate the hash value of the memory page in the dynamic memory pool;
进一步地,还包括: 内存页面属性更改模块,用于将添加到非稳定树中的内存页面标记为只读。Further, it also includes: a memory page attribute change module, which is used to mark the memory pages added to the unstable tree as read-only.
本发明提供一种基于同质内存扫描的合并方法,具有如下有益效果:根据读写顺序对内存页面进行无序的扫描以查找同质内存页面,并将其合并到稳定树中,把内存服务器对虚拟文件系统的读操作的对象以及虚拟文件系统写操作的目标做为扫描的主要内存页面,在动态内存池中捕获所有内存读写的提示,然后在动态内存池中全局查找同质内存页面,可以大大提高单个页面的共享度,从而节省更多的内存页面。The invention provides a method for merging based on homogeneous memory scanning, which has the following beneficial effects: scan memory pages out of sequence according to the reading and writing sequence to find homogeneous memory pages, and merge them into a stable tree, The object of the read operation of the virtual file system and the target of the write operation of the virtual file system are used as the main memory page of the scan, and all memory read and write prompts are captured in the dynamic memory pool, and then homogeneous memory pages are globally searched in the dynamic memory pool , can greatly increase the sharing degree of a single page, thus saving more memory pages.
基于同质内存扫描的合并装置的有益效果与基于同质内存扫描的合并方法类似,不再赘述。The beneficial effect of the merging device based on homogeneous memory scanning is similar to that of the merging method based on homogeneous memory scanning, and will not be repeated here.
附图说明Description of drawings
图1为本发明实施例所提供的基于同质内存扫描的合并方法的流程示意图;FIG. 1 is a schematic flowchart of a homogeneous memory scan-based merging method provided by an embodiment of the present invention;
图2为本发明实施例所提供的基于同质内存扫描的合并方法的流程示意图的另一种实施方式;FIG. 2 is another implementation manner of a schematic flowchart of a homogeneous memory scanning-based merging method provided by an embodiment of the present invention;
图3为本发明实施例所提供的基于同质内存扫描的合并装置的结构示意图。FIG. 3 is a schematic structural diagram of a merging device based on homogeneous memory scanning provided by an embodiment of the present invention.
具体实施方式detailed description
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments It is a part of embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.
以下结合具体情况说明本发明的示例性实施例:Exemplary embodiments of the present invention are described below in conjunction with specific circumstances:
请参考图1,图1为本发明实施例所提供的基于同质内存扫描的合并方法的流程示意图;本发明提供一种基于同质内存扫描的合并方法,包括:Please refer to FIG. 1. FIG. 1 is a schematic flow diagram of a merging method based on homogeneous memory scanning provided by an embodiment of the present invention; the present invention provides a merging method based on homogeneous memory scanning, including:
步骤S101、将内存页面存入动态内存池;Step S101, storing memory pages into a dynamic memory pool;
步骤S102、查找动态内存池中的内存页面是否在稳定树中存在同质内存页面,若是,则进行步骤S103;Step S102, check whether the memory pages in the dynamic memory pool have homogeneous memory pages in the stable tree, if so, proceed to step S103;
步骤S103、将动态内存池中的内存页面添加到稳定树中;若否,则进行步骤S104;Step S103, adding memory pages in the dynamic memory pool to the stable tree; if not, proceed to step S104;
步骤S104、查找动态内存池中的内存页面是否在非稳定树中存在同质内存页面,若是,则进行步骤S103;若否,则进行步骤S105;Step S104, check whether the memory pages in the dynamic memory pool have homogeneous memory pages in the unstable tree, if so, proceed to step S103; if not, proceed to step S105;
步骤S105、将动态内存池中的内存页面添加到非稳定树中。Step S105, adding memory pages in the dynamic memory pool to the unstable tree.
请参考图2,图2为本发明实施例所提供的基于同质内存扫描的合并方法的流程示意图的另一种实施方式;本实施例提供一种基于同质内存扫描的合并方法,包括:Please refer to FIG. 2. FIG. 2 is another implementation manner of a schematic flowchart of a homogeneous memory scanning-based merging method provided by an embodiment of the present invention; this embodiment provides a homogeneous memory scanning-based merging method, including:
步骤S201、创建动态内存池;Step S201, creating a dynamic memory pool;
步骤S202、为发生读写操作的内存页面添加去重标识;Step S202, adding a deduplication flag for the memory page where the read/write operation occurs;
步骤S203、将添加了去重标识的内存页面存入动态内存池;Step S203, storing the memory page with the deduplication flag added into the dynamic memory pool;
在本实施例中,将添加了去重标识的内存页面存入有限环形栈,有限环形栈最上层放置最新存入的内存页面。In this embodiment, the memory page with the deduplication mark added is stored in the limited ring stack, and the latest stored memory page is placed on the uppermost layer of the limited ring stack.
步骤S204、查找动态内存池中的内存页面是否在稳定树中存在同质内存页面,若是,则进行步骤S205;Step S204, check whether the memory pages in the dynamic memory pool have homogeneous memory pages in the stable tree, if so, proceed to step S205;
步骤S205、将动态内存池中的内存页面添加到稳定树中;若否,则进行步骤S206;Step S205, adding memory pages in the dynamic memory pool to the stable tree; if not, proceed to step S206;
步骤S206、查找动态内存池中的内存页面是否在非稳定树中存在同质内存页面,若是,则进行步骤S205;若否,则进行步骤S207;Step S206, find out whether the memory pages in the dynamic memory pool have homogeneous memory pages in the unstable tree, if so, proceed to step S205; if not, proceed to step S207;
步骤S207、计算动态内存池中的内存页面的哈希值;Step S207, calculating the hash value of the memory page in the dynamic memory pool;
步骤S208、将动态内存池中的内存页面添加到非稳定树;Step S208, adding memory pages in the dynamic memory pool to the unstable tree;
步骤S209、将添加到非稳定树中的内存页面标记为只读;Step S209, marking the memory pages added to the unstable tree as read-only;
值得说明的是,原生的KSM处理流程可以从以下KSM的原理中得到解释:KSM即KernelSamePage Merging,同时也被称为是一个内核模块,KSM作为内核中的守护进程定期执行页面扫描,识别副本页面并合并副本,释放这些页面以供它用。执行上述操作的过程对用户透明。例如,副本页面被合并(然后被标记为只读),但是,如果这个页面的其中一个用户由于某种原因更改该页面,该用户将收到自己的副本。It is worth noting that the original KSM processing flow can be explained from the following KSM principle: KSM is KernelSamePage Merging, also known as a kernel module, KSM as a daemon process in the kernel regularly performs page scanning to identify duplicate pages And merge the copy, freeing these pages for other use. The process of performing the above operations is transparent to the user. For example, duplicate pages are merged (and then marked read-only), but if one of the users of this page changes the page for some reason, that user will receive their own duplicate.
KSM使用的方法与内存去親合中使用的方法不同。在传统的去稱合中,对象被散列化,然后使用散列值进行初始相似性检查。当散列值一致时,下一步是进行一个实际对象比较,以便正式确定这些对象是否一致。KSM在它的第一个实现中采用这种方法,但后来开发了一种更直观的方法来简化它。需要指出的是,KSM依赖上层应用接口提供扫描的内存区域,虽然KSM可以扫描系统中的所有内存页面,但是由于内存容量比较大,因此对内存区域完全扫描需要大量的时间并且耗费大量的计算资源。因此,Linux为应用程序提供了一个注册函数,让应用程序将自己希望杯合并的内存空间通过该接口向操作系统注册,这个接口函数是:KSM uses a different approach than that used in memory de-affinity. In traditional deweighting, objects are hashed, and the hash value is then used for an initial similarity check. When the hash values agree, the next step is to do an actual object comparison to formally determine whether the objects agree. KSM took this approach in its first implementation, but later developed a more intuitive approach to simplify it. It should be pointed out that KSM relies on the upper-layer application interface to provide the scanned memory area. Although KSM can scan all memory pages in the system, due to the relatively large memory capacity, it takes a lot of time and consumes a lot of computing resources to completely scan the memory area. . Therefore, Linux provides a registration function for the application program, allowing the application program to register the memory space that it wants to merge with the operating system through this interface. This interface function is:
#include<sys/mman.h>#include <sys/mman.h>
int madvise(void * start,size_t length,int advise)int madvise(void * start, size_t length, int advise)
在当前的KSM中,页面通过两个“红黑”树管理,其中一个“红-黑”树是临时的。第一个树称为非稳定树,用于存储还不能理解为稳定的新页面。换句话说,作为合并候选对象的页面存储在这个非稳定树中。非稳定树中的页面不是写保护的。第二个树称为稳定树,存储那些已经发现是稳定的且通过KSM合并的页面。为确定一个页面是否是稳定页面,KSM使用了一个简单的32位校验和。当一个页面被扫描时,它的校验和被计算且与该页面存储在一起。在一次后续扫描中,如果新计算的校验和不等于此前计算的校验和,则该页面正在更改,因此不是一个合格的合并候选对象。由于这两棵树的数据结构为红黑树,因此向这个树中插入和删除的时间复杂度均为O(logn)。In the current KSM, pages are managed through two "red-black" trees, one of which is temporary. The first tree is called the unstable tree and is used to store new pages that are not yet understood to be stable. In other words, pages that are merge candidates are stored in this unstable tree. Pages in an unstable tree are not write-protected. The second tree, called the stable tree, stores pages that have been found to be stable and merged by KSM. To determine whether a page is stable, KSM uses a simple 32-bit checksum. When a page is scanned, its checksum is calculated and stored with the page. On a subsequent scan, if the newly calculated checksum is not equal to the previously calculated checksum, the page is changing and therefore is not a good candidate for a merge. Since the data structure of these two trees is a red-black tree, the time complexity of inserting and deleting into this tree is O(logn).
KSM使用进程处理一个单一的页面时,第一步是检查是否能够在稳定树中发现该页面。一个memcmp(内存比较)操作将在该页面和相关节点的页面上执行。如果memcmp返回0,则页面相同,发现一个匹配值。反之,如果返回-1,则表示候选页面小于当前节点的页面如果返回1,则表示候选页面大于当前节点的页面。尽管比较4K的页面似乎是相当重量级的比较,但是在多数情况下,一旦发现差异,memcmp将提前结束。When KSM processes a single page, the first step is to check whether the page can be found in the stable tree. A memcmp (memory compare) operation will be performed on this page and the page of the associated node. If memcmp returns 0, the pages are the same and a match was found. Conversely, if it returns -1, it means that the candidate page is smaller than the page of the current node. If it returns 1, it means that the candidate page is larger than the page of the current node. Although comparing 4K pages may seem like a pretty heavyweight comparison, in most cases memcmp will end early once differences are found.
本实施例所述的方法是基于原生KSM同质内存合并处理流程的扩展,结合原生KSM处理流程具体的操作方法可以从以下三个方面说明:The method described in this embodiment is based on the extension of the native KSM homogeneous memory merge processing flow, and the specific operation method combined with the native KSM processing flow can be explained from the following three aspects:
在本实施例所述的方法中添加了去重提示的内存页面插入到非稳定树中。此后每次对内存页面有读写操作时都会将操作对象页面在非稳定树中搜索。同时,为了防止在非稳定树中的页面被修改,必须将其中的所有的页面标示为只读模式,当需要写入时,将该页面从非稳定树中摘除,然后写过之后再次插入到非稳定树。In the method described in this embodiment, the memory pages added with deduplication hints are inserted into the unstable tree. After that, every time there is a read and write operation on the memory page, the operation target page will be searched in the unstable tree. At the same time, in order to prevent the pages in the unstable tree from being modified, all the pages in it must be marked as read-only mode. When writing is required, the page is removed from the unstable tree, and then reinserted into the unstable tree.
一、去重标识的获取:根据对KSM的介绍,扫面的范围是由系统调用madvise指定的,在这里为了实现我们的功能,必须扩展这个系统调用。由于被共享的内存页面大多来自于虚拟磁盘镜像,所以还需要修改虚拟文件系统的读命令(read,readv)和写(write,writev)命令,让这些函数在调用的时候顺便在这些页面上加上相应的读写标记,这个标记就做为去重提示。不过,这里的添加读写标记的内存页面必须在系统调用madvise中定义的。1. Acquisition of the de-duplication logo: According to the introduction to KSM, the scanning range is specified by the system call madvise. In order to realize our function, this system call must be extended. Since most of the shared memory pages come from the virtual disk image, it is also necessary to modify the read commands (read, readv) and write (write, writev) commands of the virtual file system, so that these functions can be added to these pages by the way when they are called. On the corresponding read-write mark, this mark is used as a reminder for deduplication. However, the memory pages for adding read-write marks here must be defined in the system call madvise.
二、去重标识的存储:由于计算机中的I/O往往具有促发性,因此基于I/O的去重标识也具有促发性。当I/O的速度大于KSM扫描的速率时,系统可能无法保存大量的去重标识。根据大部分系统中处理这种有序的信息往往采取一个无限的缓冲队列来保存,但是该方法在本系统中不太实用,因为我们无法预测I/O的数量,同时,由于记录这些页面的标识是有一定时效性的,随着我们的处理过程,队列尾部的标识可能会因为老化(当一个内存页面被标识之后没有及时被处理,而此时该内存页面又被读或者写过,这该称该标识老化)而不在具有实际意义,此时在去处理这些标识不仅浪费时间,同时还可能延迟该标识之后标识的处理时间,进一步增加这些标识失效的可能性。这样做的直接后果就是可能使得最终不能找到任何的候选合并页面。2. Storage of deduplication marks: Since I/O in computers is often provocative, deduplication marks based on I/O are also provocative. When the I/O speed is greater than the scanning rate of KSM, the system may not be able to save a large number of deduplication marks. According to the processing of such ordered information in most systems, an infinite buffer queue is often used to save, but this method is not practical in this system, because we cannot predict the number of I/O, and at the same time, due to the recording of these pages The identification has a certain timeliness. With our processing, the identification at the end of the queue may be aging (when a memory page is not processed in time after being identified, and the memory page is read or written at this time, this It should be said that the identification is aging) and has no practical significance. At this time, it is not only a waste of time to process these identifications, but it may also delay the processing time of subsequent identifications after this identification, further increasing the possibility of these identifications becoming invalid. The direct consequence of doing this is that it may make it impossible to find any candidate merge pages in the end.
由于在系统中,并不需要在一次扫描中找出所有可共享的同质内存页面,因此我们提出了一种新的标识存储方式:有限环形栈。这种方式需要很少的额外开销,并且基本上不需要维护。Since in the system, it is not necessary to find all shareable homogeneous memory pages in one scan, we propose a new identity storage method: limited ring stack. This approach requires very little overhead and is basically maintenance-free.
在有限环形栈中,系统处理这些标识时总是从top处取出,这就意味着每次处理的都是最近最新的去重标识内存页面,根据我们上述分析的,最近最新被压入栈中的内存页面往往是最可能被共享的,而对于那些栈底的标识的内存页面,由于时效性可能己经没有任何意义,所以处理到这些页面的时候,意味着系统中没有新标识的内存页面,即时此时处理这些无用的标识也不会给系统带来额外的压力。如果标识的内存页面数量过多,则只会将栈底那些无用的标识删除,根据我们前面的分析,系统不需要再一次处理过程中找到所有的共享内存页面,同时这些标识可能已经没有意义了,通过这种方式可以有效且简单的达到我们的目的。由于这只是一个普通的有限环形栈,不需要额外的维护。In the finite circular stack, the system always fetches these identifiers from top when processing them, which means that each time it processes the latest deduplication identifier memory page, according to our above analysis, the latest is pushed into the stack The memory pages are often the most likely to be shared, and for those memory pages identified at the bottom of the stack, the timeliness may not have any meaning, so when these pages are processed, it means that there are no newly identified memory pages in the system , Even if these useless flags are processed at this time, it will not bring additional pressure to the system. If there are too many marked memory pages, only those useless marks at the bottom of the stack will be deleted. According to our previous analysis, the system does not need to find all the shared memory pages in the process of processing again, and these marks may no longer be meaningful , in this way we can achieve our goal effectively and simply. Since this is just a normal finite ring stack, no additional maintenance is required.
三、去重标识的处理:在这里需要特别的指出,虽然我们提出了基于I/0标识的去重机制,但是并不意味着我们不需要原来的去重机制。基于I/0访问标识的去重机制主要面向那些共享时间比较短且发生过I/0行为的那些内存页面,而对于那些基本上没有I/0行为的内存页面,这种方式就不能发现其共享机会。根据向内存页面中添加去重标识的机制,系统需要对原有的KSM处理方式加以扩充,新的处理流程和原生的KSM处理流程类似。3. Processing of deduplication identification: It needs to be specially pointed out here that although we have proposed a deduplication mechanism based on I/0 identification, it does not mean that we do not need the original deduplication mechanism. The deduplication mechanism based on the I/0 access identifier is mainly for those memory pages that have a relatively short sharing time and have I/0 behaviors, and for those memory pages that basically have no I/0 behaviors, this method cannot find other memory pages. share opportunities. According to the mechanism of adding deduplication identifiers to memory pages, the system needs to expand the original KSM processing method, and the new processing flow is similar to the original KSM processing flow.
将本机制与原生的KSM混合使用,当有限环形栈中有数据时,优先使用基于I/O去重标识的KSM去重方法,否则考虑原生KSM的方式。同时,该混合机制同样是周期性的扫描madvise注册的内存空间。Mix this mechanism with the original KSM. When there is data in the limited ring stack, use the KSM deduplication method based on the I/O deduplication flag first, otherwise consider the native KSM method. At the same time, the hybrid mechanism also periodically scans the memory space registered by madvise.
在该方法中我们首先检查被标示的内存页面是否已经包含在稳定树中,如果存在,将内存池中页表中的物理地址改成稳定树中的页面地址,然后释放原有的内存页面;如果不在稳定树中,首先计算这个内存页面的大小,并且在非稳定树中检查,如果存在于非稳定树中,将这两个页面合并,并将其中的一个插入到稳定树中,如果在非稳定树中也找不到,则将该内存页面插入到非稳定树中。In this method, we first check whether the marked memory page is already included in the stable tree, and if so, change the physical address in the page table in the memory pool to the page address in the stable tree, and then release the original memory page; If it is not in the stable tree, first calculate the size of the memory page, and check it in the unstable tree, if it exists in the unstable tree, merge the two pages, and insert one of them into the stable tree, if in the unstable tree If it is not found in the unstable tree, the memory page is inserted into the unstable tree.
非稳定树的退化:在原生的KSM实现中,把那些频繁写入的内存页面排除在非稳定树中,这样做的好处是避免重复搜索这些页面,因为每次计算的哈希值不同,同样也不会被合并,只有那些在两次扫描过程中哈希值保持不变的页面才会被插入到非稳定树中。但是在我们的实现过程中,当一个内存页面有去重标识时,就将该页面插入到非稳定树中。Degeneration of unstable tree: In the native KSM implementation, those memory pages that are frequently written are excluded from the unstable tree. The advantage of this is to avoid repeated searches for these pages, because the hash value calculated each time is different, and the same They are also not merged, and only those pages whose hashes remain the same between scans are inserted into the unstable tree. However, in our implementation, when a memory page has a deduplication flag, the page is inserted into the unstable tree.
那些与虚拟DMA读写操作相关的内存页面通常被认为是客户操作系统中高速缓存的一部分。对于运行在Guest os 中的应用程序而言,如果虚拟机内部的缓冲被填满,那么Host os中的非稳定树势必会退化。这是因为在这种情况下,即便没有得到Host os清空高速缓存的情况下,Guest os也会将这些源于虚拟磁盘镜像中的整个缓冲都删除,以重新构建新的缓冲空间。此时,非稳定树中的所有被标示的内存页面都会被修改,对于外界而言,该非稳定树将变得不可达。此外,当非稳定树树内部节点改变时,与之同一层的所有兄弟节点也不可达。这也是当Guest os将这些已经被修改过的页面写会虚拟磁盘之后,Host os唯一所能了解到的东西。KSM的非稳定树自动修复程序修复速度会因为每次完整扫描的内存页面数量增加而降低。如果扫描的频率保持稳定,那么一个页面会因为之前的释放而被多重标记。因此,为了应付非稳定树这种退化的问题,一种有效的解决方法就是将插入到非稳定树中的页面标记为只读。这种情况下,当对非稳定树上的内存页面进行写操作的时候,该内存页面会因为发生写错误而从非稳定树中删除。Those memory pages associated with virtual DMA read and write operations are usually considered part of the cache in the guest operating system. For the application program running in the Guest os, if the internal buffer of the virtual machine is filled, the unstable tree in the Host os is bound to degenerate. This is because in this case, even if the cache is not cleared by the Host os, the Guest os will delete the entire buffers originating from the virtual disk image to rebuild a new buffer space. At this time, all marked memory pages in the unstable tree will be modified, and the unstable tree will become unreachable to the outside world. In addition, when an internal node of an unstable tree changes, all sibling nodes at the same level are also unreachable. This is also the only thing the Host os can know after the Guest os writes these modified pages to the virtual disk. KSM's Unstable Tree autohealer repair speed is reduced due to the increased number of memory pages per full scan. If the frequency of scanning remains constant, then a page can be multi-marked due to previous releases. Therefore, in order to cope with the degradation of unstable trees, an effective solution is to mark pages inserted into unstable trees as read-only. In this case, when a memory page on the unstable tree is written, the memory page will be deleted from the unstable tree due to a write error.
本发明还提供一种基于同质内存扫描的合并装置,包括:The present invention also provides a merging device based on homogeneous memory scanning, including:
内存页面存入模块,用于将内存页面存入动态内存池;The memory page is stored in the module, which is used to store the memory page into the dynamic memory pool;
第一查找模块,用于查找动态内存池中的内存页面是否在稳定树中存在同质内存页面;The first search module is used to find whether the memory pages in the dynamic memory pool have homogeneous memory pages in the stable tree;
第二查找模块,用于查找动态内存池中的内存页面是否在非稳定树中存在同质内存页面;The second search module is used to find whether the memory pages in the dynamic memory pool have homogeneous memory pages in the unstable tree;
第一添加模块,用于将动态内存池中的内存页面添加到稳定树中;The first adding module is used to add memory pages in the dynamic memory pool to the stable tree;
第二添加模块,用于将动态内存池中的内存页面添加到非稳定树中。The second adding module is used to add memory pages in the dynamic memory pool to the unstable tree.
请参考图3,图3为本发明实施例所提供的基于同质内存扫描的合并装置的结构示意图;本实施例中,基于同质内存扫描的合并装置,包括:Please refer to FIG. 3. FIG. 3 is a schematic structural diagram of a merging device based on homogeneous memory scanning provided by an embodiment of the present invention; in this embodiment, a merging device based on homogeneous memory scanning includes:
内存页面存入模块301,用于将内存页面存入动态内存池;The memory page is stored in the module 301, which is used to store the memory page into the dynamic memory pool;
第一查找模块302,用于查找动态内存池中的内存页面是否在稳定树中存在同质内存页面;The first search module 302 is used to find whether the memory pages in the dynamic memory pool have homogeneous memory pages in the stable tree;
第二查找模块303,用于查找动态内存池中的内存页面是否在非稳定树中存在同质内存页面;The second search module 303 is used to find whether the memory pages in the dynamic memory pool have homogeneous memory pages in the unstable tree;
第一添加模块304,用于将动态内存池中的内存页面添加到稳定树中;A first adding module 304, configured to add memory pages in the dynamic memory pool to the stable tree;
第二添加模块305,用于将动态内存池中的内存页面添加到非稳定树中;The second adding module 305 is used to add memory pages in the dynamic memory pool to the unstable tree;
动态内存池创建模块306,用于创建动态内存池。A dynamic memory pool creation module 306, configured to create a dynamic memory pool.
去重标识添加模块307,用于为发生读写操作的内存页面添加去重标识。The de-duplication identification adding module 307 is configured to add de-duplication identifications to memory pages where read and write operations occur.
哈希计算模块308,用于计算动态内存池中的内存页面的哈希值;Hash calculation module 308, for calculating the hash value of the memory page in the dynamic memory pool;
内存页面属性更改模块309,用于将添加到非稳定树中的内存页面标记为只读。A memory page attribute changing module 309, configured to mark the memory pages added to the unstable tree as read-only.
最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。Finally, it should also be noted that in this text, relational terms such as first and second etc. are only used to distinguish one entity or operation from another, and do not necessarily require or imply that these entities or operations, any such actual relationship or order exists. Furthermore, the term "comprises", "comprises" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article, or apparatus comprising a set of elements includes not only those elements, but also includes elements not expressly listed. other elements of or also include elements inherent in such a process, method, article, or device. Without further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article or apparatus comprising said element.
以上对本发明所提供的一种高密服务器硬盘背板进行了详细介绍,本文中应用了具体个例对本发明的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本发明的方法及其核心思想;同时,对于本领域的一般技术人员,依据本发明的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本发明的限制。The above is a detailed introduction to a high-density server hard disk backplane provided by the present invention. In this paper, specific examples are used to illustrate the principle and implementation of the present invention. The description of the above embodiments is only used to help understand the method of the present invention. and its core idea; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation and scope of application. limits.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710105084.9A CN106874119A (en) | 2017-02-25 | 2017-02-25 | Merging method and device based on the scanning of homogeneity internal memory |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710105084.9A CN106874119A (en) | 2017-02-25 | 2017-02-25 | Merging method and device based on the scanning of homogeneity internal memory |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN106874119A true CN106874119A (en) | 2017-06-20 |
Family
ID=59167727
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201710105084.9A Pending CN106874119A (en) | 2017-02-25 | 2017-02-25 | Merging method and device based on the scanning of homogeneity internal memory |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN106874119A (en) |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113176958A (en) * | 2021-04-29 | 2021-07-27 | 深信服科技股份有限公司 | Memory sharing method, device, equipment and storage medium |
| CN114756382A (en) * | 2022-06-14 | 2022-07-15 | 中孚安全技术有限公司 | Optimization method, system and server for memory page merging |
| WO2022247821A1 (en) * | 2021-05-26 | 2022-12-01 | 华为技术有限公司 | Memory page processing method and related device thereof |
| WO2025055385A1 (en) * | 2023-09-11 | 2025-03-20 | 京东科技信息技术有限公司 | Image storage method and apparatus for page, and device and storage medium |
Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20120246436A1 (en) * | 2011-03-21 | 2012-09-27 | Microsoft Corporation | Combining memory pages having identical content |
| CN103019884A (en) * | 2012-11-21 | 2013-04-03 | 北京航空航天大学 | Memory page de-weight method and memory page de-weight device based on virtual machine snapshot |
-
2017
- 2017-02-25 CN CN201710105084.9A patent/CN106874119A/en active Pending
Patent Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20120246436A1 (en) * | 2011-03-21 | 2012-09-27 | Microsoft Corporation | Combining memory pages having identical content |
| CN103019884A (en) * | 2012-11-21 | 2013-04-03 | 北京航空航天大学 | Memory page de-weight method and memory page de-weight device based on virtual machine snapshot |
Non-Patent Citations (1)
| Title |
|---|
| 邓文洋: ""虚拟化环境下的多机内存优化技术研究与实现"", 《中国优秀硕士学位论文全文数据库信息科技辑》 * |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113176958A (en) * | 2021-04-29 | 2021-07-27 | 深信服科技股份有限公司 | Memory sharing method, device, equipment and storage medium |
| CN113176958B (en) * | 2021-04-29 | 2024-02-23 | 深信服科技股份有限公司 | Memory sharing method, device, equipment and storage medium |
| WO2022247821A1 (en) * | 2021-05-26 | 2022-12-01 | 华为技术有限公司 | Memory page processing method and related device thereof |
| CN114756382A (en) * | 2022-06-14 | 2022-07-15 | 中孚安全技术有限公司 | Optimization method, system and server for memory page merging |
| WO2025055385A1 (en) * | 2023-09-11 | 2025-03-20 | 京东科技信息技术有限公司 | Image storage method and apparatus for page, and device and storage medium |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| TWI549060B (en) | Access methods and devices for virtual machine data | |
| US8190827B2 (en) | Memory sharing among computer programs | |
| KR101441188B1 (en) | Techniques for memory de-duplication in a virtual system | |
| US10719479B2 (en) | Data unit cloning in memory-based file systems | |
| JP5091655B2 (en) | Computer virtualization apparatus, program thereof, and method thereof | |
| CN103064797B (en) | Data processing method and virtual machine management platform | |
| US20150234669A1 (en) | Memory resource sharing among multiple compute nodes | |
| US20150067283A1 (en) | Image Deduplication of Guest Virtual Machines | |
| WO2017107414A1 (en) | File operation method and device | |
| CN102239478B (en) | Data access processing method and device | |
| CN103049392B (en) | The implementation method of CACHE DIRECTORY and device | |
| WO2015043376A1 (en) | Page access method and page access device, and server | |
| CN107102900B (en) | Management method of shared memory space | |
| CN106874119A (en) | Merging method and device based on the scanning of homogeneity internal memory | |
| WO2024099448A1 (en) | Memory release method and apparatus, memory recovery method and apparatus, and computer device and storage medium | |
| CN103150395A (en) | Directory path analysis method of solid state drive (SSD)-based file system | |
| US20190294590A1 (en) | Region-integrated data deduplication implementing a multi-lifetime duplicate finder | |
| CN113835639B (en) | I/O request processing method, device, equipment and readable storage medium | |
| US11586353B2 (en) | Optimized access to high-speed storage device | |
| CN105068941A (en) | Cache page replacing method and cache page replacing device | |
| CN104035822A (en) | Low-cost efficient internal storage redundancy removing method and system | |
| JP2017033375A (en) | Parallel calculation system, migration method, and migration program | |
| CN108459970A (en) | A kind of method and device of query caching information | |
| CN102722506A (en) | Data storage method and equipment | |
| CN110352410A (en) | Track the access module and preextraction index node of index node |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20170620 |