CN100449492C - Testing method of physical RAM in Linux system - Google Patents

Testing method of physical RAM in Linux system Download PDF

Info

Publication number
CN100449492C
CN100449492C CN 200510023063 CN200510023063A CN100449492C CN 100449492 C CN100449492 C CN 100449492C CN 200510023063 CN200510023063 CN 200510023063 CN 200510023063 A CN200510023063 A CN 200510023063A CN 100449492 C CN100449492 C CN 100449492C
Authority
CN
China
Prior art keywords
page
memory
physical
physical memory
algorithm
Prior art date
Application number
CN 200510023063
Other languages
Chinese (zh)
Other versions
CN1991770A (en
Inventor
刘文涵
怡 陈
陈玄同
Original Assignee
英业达股份有限公司
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 英业达股份有限公司 filed Critical 英业达股份有限公司
Priority to CN 200510023063 priority Critical patent/CN100449492C/en
Publication of CN1991770A publication Critical patent/CN1991770A/en
Application granted granted Critical
Publication of CN100449492C publication Critical patent/CN100449492C/en

Links

Abstract

本发明公开一种Linux系统下物理内存的测试方法,是利用一个Linux操作系统下的字符设备驱动程序激活一个字符设备,用户只需通过Linux提供的档案作业函数,就可以实现在用户层对指定的物理内存进行读写操作。 The present invention discloses method of physical memory in one kind of Linux systems, using character device driver under a Linux operating system activates a character device, the user simply archive a job function provided by Linux, it can be implemented in a user specified layer physical memory read and write operations. 该方法对于内存分配的最小单位为页,页的大小视Linux系统核心(Kernel)的配置而定。 The method for the minimum unit of memory allocated for the page, depending on the size of the Linux system core (Kernel) depending on the configuration page. 除去系统自身保留的内存以及其它应用程序(包含测试程序本身)所占用的内存空间,利用本发明的测试方法可以直接访问到所有剩余的物理内存并进行读写测试,因此大大提高了内存测试的涵盖率和准确性。 Removal system memory and reserved for itself other applications (containing test program itself) of memory space occupied by the test method of the present invention can be direct access to all the remaining physical memory and read and write tests, thus greatly improving the memory test coverage and accuracy.

Description

Linux系统下物理内存的測试方法 The method of physical memory of the Linux system

技术领域 FIELD

本发明涉及一种物理内存的测试方法,尤其涉及一种应用于Linux操作系统下的物理内存的测试方法。 The present invention relates to a method for testing physical memory, and particularly to a method of physical memory in Linux operating system.

背聚技术 Back poly technology

在Linux系统(一种可免费使用的多用户的计算机操作系统)核心(Kernel)中,内存的最小单位是页,这有利于系统对内存的管理,用户所使用的内存地址是线性地址,它同物理地址之间的转换是通过两级或是三级页表的映像来实现的,这种多级页表的映像可以大大降低页表本身所占用的内存的大小。 In the Linux system (multi-user free use of a computer operating system) kernel (Kernel), the smallest unit of memory is a page, which is conducive to the management of the system memory, memory addresses used by the user is linear address it with conversion between a physical address image is achieved by two or three page tables, this multi-level page table image can greatly reduce the size of memory occupied by the page table itself. 在Linux系统中,用户通常的使用内存的方法是调用系统提供的标准接口函数来分配和释放内存,但是通过这种方式返回的内存地址都是线性地址(或称为虚拟地址),并不是实际的物理地址,这种设计是同处理器本身的特性密不可分的。 In the Linux system, users typically use a standard memory interface function calls a method provided by the system to allocate and free memory, but in this way the return memory address is a linear address (or virtual address), not the actual physical address, this design is characteristic with the processor itself inseparable. 虽然每一个线性地址都对应着一个实际的物理地址,我们也可以通过线性地址转化为物理地址,而且对于此线性地址的读写就是对相应的物理内存的读写,但是这无法满足用户指定对某个物理地址进行读写操作的需求,因为Linux系统提供的内存分配函数只能满足用户在内存空间上的需求, 而无法满足在内存位置上的需求。 While each linear address corresponds to a real physical address, we can also be converted by the linear address to a physical address, and to read and write this linear address is read the corresponding physical memory, but it can not meet the user-specified for a physical address needs read and write operations, because the memory allocation function Linux system provides only meet the needs of users in memory space and can not meet the needs of the memory location. 这就需要我们提供一种对指定物理内存进行读写操作的方法。 This requires us to provide a method to specify the physical memory read and write operations.

目前,我们所使用的计算机的物理内存通常只有几百兆字节(MB)的物理空间,例如256MB或512MB的物理内存空间,而在实际开发Linux系统应用程序时,每个开发进程都可以拥有自己的4GB的内存空间,这是为什么呢? At present, the computer's physical memory that we use usually only a few hundred megabytes (MB) of physical space, such as 256MB or 512MB of physical memory space, and Linux systems applications in the actual development, each development process can have own 4GB memory space, which is why? 这首先要从Lirmx系统核心(Kernel)所工作的内存模式说起,因为Linux系统核心(Kernel)工作于虚拟内存模式,g卩:每一个虚拟页对应一个相应的系统内存的物理页,虚拟页和物理页之间的地址转换由硬件的页表来完成,对于一个特定的虚拟页,根据一条页表记录可以找到对应的物理页,或者是此页无法找到的提示(说明存在一个页错误)。 This is the first from the memory pattern Lirmx system core (Kernel) the work to start, because Linux system core (Kernel) work in virtual memory mode, g Jie: each virtual page corresponds to a corresponding system of physical memory pages, the virtual page and between the physical page address conversion is done in hardware page table, for a particular virtual page, the page table entry in accordance with a corresponding physical page can be found, or the page could not be found tips (specify the presence of a page fault) .

正是基于上述的"虚拟到物理"的页映像原理,Linux系统核心通过内存管 Page image is based on the principle of the above "virtual-to-physical" of, Linux system kernel memory via pipe

理单元,将其虚拟内存映像到物理内存,并当系统所需的物理内存不足时,通过将暂时不用的物理内存中的数据资料交换到计算机硬盘上,当系统再次用到这些数据资料时再从计算机硬盘中交换回来,从而实现了扩展物理内存空间的n的。 Processing unit, the image of its virtual memory to physical memory, and when there is insufficient physical memory required by the system, by temporarily unused physical memory to exchange data on a computer's hard drive, and then when the system uses these data again switching back from the hard disk in the computer, thereby realizing the expansion of n in physical memory space.

但是t.述这种"虚拟到物理"的页映像不总是一一对应的:多个虚拟页(被不同的进程共享的页)有可能同时指向同--个物理页。 But t above this "virtual-to-physical" page image is not always one to one: a plurality of virtual pages (to be shared by different processes pages) it is possible to point to the same - physical pages. 在这种情况下,每个共享进程的页表记录将具有指向对应物理页的映像。 In this case, each shared page table recording process will have an image point corresponding to the physical page. 如果有类似这样的情况,当系统核心想要释放特定的物理页时,事情会变得非常复杂,因为它必须遍历(遍 If this is the case is similar to the core when the system wants to release specific physical page, things will become very complicated, because it must traverse (pass

历,英文名称:Traversal,是指沿着某条搜索路线,依次对树中每个结点均做一次且仅做一次访问。 Calendar, the English name: Traversal, refers to a strip search along the route followed by each node of the tree were done only once and do a visit. 访问结点所做的操作依赖于具体的应用问题。 Access node operation done depends on the specific application problems. 遍历是二义树上最重要的运算之--,是二义树上进行其它运算的基础)所有的进程页表记录来査找指向这个物理页的引用,系统核心只能在引用数达到0 (count =0)时才能释放这个物理页,因为它没有别的办法可以知道是不是还存在实际指向这个页的引用。 Ambiguous tree traversal is the most important operation of the - is the basis of ambiguous tree and perform other operations) All recorded process page table to find a reference point to the physical page, in the heart of the system can only reach 0 reference number ( to release the physical page when the count = 0), because it has no way of knowing there is not a reference to the actual point to this page. 这样当系统负载较高时会让虚拟内存变得非常慢。 So that when high system load will become very slow virtual memory.

当前,我们在生产线上使用内存测试工具测试内存的现有方法是在虚拟内 Currently existing methods, we used memory test tools to test memory on the production line is in the virtual

存中分配尽可能多的虚空间,对其进行各种内存算法的测试,然而虚拟内存具体映像到的是真正的物理内存还是硬盘的交换分区,检测人员都不能清楚地知悉。 Memory allocated as much virtual space, to test various memory algorithms, however, virtual memory is the specific image to the real physical memory or hard disk swap partition, inspectors can not be clearly aware of.

因此,现有的用于Linux系统平台下的物理内存的测试方法,虽然其测试程序实现起来非常简便,但是其测试方法的缺点在于:由于使用系统提供的函数来分配内存,这些函数受到自身保护机制的限制,无法将系统中的空闲内存全部分配出来,因此其测试涵盖率低,根本无法对操作系统和测试程序本身所占用的系统物理内存进行检测;此外,也无法保障分配出来的内存在物理上是连续的;而且,经生产线使用发现,目前现有的内存测试方法很难测出物理内存的实际问题,即使发现问题,由于分配返回的内存地址是线性地址,检测人员也不知道内存真正出错或发生问题的实际物理位置。 Thus, the conventional methods for testing the physical memory of the Linux platform, while the test program is very simple to implement, but the drawback is that the test method: Since the functions provided by the system to allocate memory, these functions themselves be protected limiting mechanism, the system can not be fully allocated out of free memory, so the tests cover is low, the operating system and can not test the program itself occupied by the physical memory system for testing; in addition, it can not guarantee allocation of memory It is physically contiguous; Further, the production line was found, the currently available memory test methods are difficult to measure the actual physical memory problems, even if the problem was found, due to the return memory address is the linear address allocation, memory testers do not know genuine error or actual physical location of the problems.

发明内容 SUMMARY

为了解决上述现有技术中的问题与缺陷,本发明的目的在于提供一种Linux系统下物理内存的测试方法,利用一个Linux操作系统下的字符设备驱 In order to solve the above problems and defects of the prior art, an object of the present invention is the method of physical memory to provide a Linux system, the device driver using the character in a Linux operating system

动程序激活一个字符设备,用户只需通过Linux提供的对档案的作业函数,就 Action program to activate a character device, the user simply by job function files provided by Linux, it is

可以实现在用户层对指定物理内存的读写操作。 Read and write operations may be implemented in a user specified physical memory layer. 该种方法对于内存分配的最小 The method for memory allocation minimum

单位为页,页的大小视Linux系统核心(Kernel)的配置所定。 In pages, depending on the size of the Linux system core (Kernel) page of the configuration set. 除去系统自身保留的内存以及其它应用程序(包含测试程序本身)所占用的内存,可以直接访问到所有剩余的物理内存并进行测试,因此可以大大提高测试的涵盖率及准确性。 Removal system memory and reserved for itself other applications (containing test program itself) occupied by the memory, direct access to physical memory, and all the remaining tests, it can greatly improve coverage and accuracy of the test.

本发明所提供的一种Linux系统下物理内存的测试方法,应用于Limix 操作系统下的物理内存的检测过程中,此方法包含以下步骤:激活一个字符设备驱动程序,以驱动一个字符设备对一个物理内存的物理页进行分配与释放; 当字符设备成功激活后,以页为单位,按照物理内存的物理地址遍历整个物理内存;判断遍历是否完成,如果完成,则关闭字符设备,否则,通过Linux 系统提供的ioctl函数设定所要访问的物理内存的物理地址;当成功设定所要访问的物理内存的物理地址后,通过Linux系统提供的mmap函数将物理内存映像至用户空间;当物理内存被成功映像至用户空间后,通过内存检测算法对物理内存进行测试;通过Linux系统提供的munmap函数解除物理内存与用户空间的映像关系;以及,通过Linux系统提供的ioctl函数释放字符设备中所储存的讯息,并继续以 The method of physical memory in the present invention, one kind of the Linux system is provided, the detection process applied to the physical memory in Limix operating system, the method comprising the steps of: activating a character device driver to a driving device for a character physical memory physical page allocation and release; when a character device is successfully activated, the unit of page, traverse the entire physical memory in accordance with the physical address of the physical memory; determining traversal is completed, if completed, close the character device, otherwise, by Linux physical memory a physical address of the ioctl function to set the system provided to be accessed; when the physical address of the physical memory to be accessed successfully set, mmap functions provided by the Linux system physical memory image to the user space; when the physical memory is successfully after mapped to user space, by the memory test algorithm physical memory test; munmap functions provided by the Linux system releasing mapping relationship physical memory and user space; and, provided by the Linux system ioctl function to release the character device stored message and continue to 为单位,按照物理内存的物理地址遍历整个物理内存, 直至遍历完成。 As a unit, in accordance with the physical address of the physical memory to traverse the entire physical memory until a complete traversal.

综上所述,本发明的优点在于: In summary, the advantages of the present invention:

本发明提供了一种在Linux系统平台下,通过直接访问物理内存进行内存测试的方法。 The present invention provides a process for the Linux platform, memory test performed by direct access to physical memory. 该方法借助于Linux系统核心(Kernel)的源代码对外开放的特性,并通过一个Linux操作系统下的字符设备驱动程序以及Linux系统提供的对档案的作业函数,便可深入到系统核心(Kernel)内部直接访问物理内存, 并执行各种内存检测算法的测试。 The method by means of the features of the Linux system core (Kernel) opening the source code, and a character is provided by the device driver in the operating system, a Linux operating system, Linux, and function file, can be deep into the core of the system (Kernel) internal direct access to physical memory and perform various test memory test algorithms.

因此,本发明的一种Linux系统下物理内存的测试方法与现有技术相比, 其优点在于:本发明的内存测试方法的测试涵盖率高,除了系统核心及应用程序所占用的少量系统物理内存无法检测以外,本方法可对系统中其余的物理内存直接进行访问和检测,并可使测试人员清楚地知道所检测内存的确切物理位置,且按照此内存的物理地址进行测试,从而可方便准确地找到内存真正出错或发生问题的实际物理位置。 Thus, the method of physical memory according to the present invention is one kind of Linux system compared to the prior art, which is advantageous in that: the memory test covering rate test method according to the present invention, in addition to the core system and application system occupied by a small amount of physical other than the memory can not detect, the present method may be remaining in the system physical memory and accessed directly detected, and allows the tester to clearly know the exact physical location of the memory is detected, and tested according to the physical address of this memory, which can easily accurately find the actual physical location of the real memory error or problem occurred. 此外,本发明的方法是在32/64位(bit)保护 Further, in the method of the present invention is a 32/64 bit (bit) Protection

模式F实现的,因此检测效率较高。 F implementation mode, a higher detection efficiency. 附图说明 BRIEF DESCRIPTION

图1为本发明的种Lirmx系统下物理内存的测试方法的方法流程图; 图2为本发明的测试方法中的字符设备对物理内存的物理页进行分配的方法流程图; Methods Test methods of physical memory in the system of Figure 1 Lirmx species present invention flowchart; Test method 2 of the present invention a character device physical memory physical page allocation flowchart;

图3为本发明的测试方法中的字符设备对物理内存的物理页进行释放的方法流程图; Test Method The method of the present invention. FIG. 3 characters device to physical pages of physical memory is released flowchart;

图4为本发明的测试方法中所测试的物理内存的页结构示意图;以及 FIG 4 is a schematic diagram of the physical memory page structure of the test method of the invention tested; and

图5为本发明的测试方法中每个页区中的未被占用页依照伙伴算法链接 Figure 5 shows the test method of the invention for each page in the unoccupied zone in accordance with the buddy system links page

而成的结构示意图。 A schematic view of a structure obtained.

其中,附图标记: Wherein, reference numerals:

步骤IOO激活字符设备驱动程序 IOO step of activating the character device driver

步骤101判断字符设备是否成功激活 Step 101 determines whether the device is successfully activated character

步骤102以页为单位按照物理内存的物理地址遍历整个物理内存步骤103判断遍历是否完成 Step 102 in units of pages in accordance with the physical address of the physical memory to traverse the entire physical memory is determined in step 103 traversal is complete

步骤104通过ioctl函数设定所要访问的物理内存的物理地址步骤105判断设定是否成功 A step 104 of physical memory by the ioctl function to set the physical address to be accessed is set in step 105 determines whether or not successful

步骤106通过mmap函数将物理内存映像至用户空间步骤107判断映像是否成功步骤108通过内存检测算法对物理内存进行测试步骤109通过munmap函数解除此映像关系步骤IIO通过ioctl函数释放字符设备中储存的讯息步骤lll关闭字符设备 Step 106 physical memory image to the user space step by mmap function 107 determines the image is successful in step 108 to test step physical memory through the memory detection algorithm 109 this image relationship step IIO release character device via ioctl function stored in the message released by munmap function step lll closed character device

步骤200获得所要分配的物理内存的物理地址步骤201将此物理地址转换为其所存在的页结构步骤202判断此页是否被占用步骤203获取此页所在的页区结构 Step physical address of the physical memory 201 in step 200 to obtain this physical address to be dispensed into a page structure present in step 202 it is determined whether the page is occupied in step 203 acquires the page where the page region structure

步骤204判断此页是否存在于其页区的伙伴算法结构中步骤205对此页区的伙伴算法结构的访问加锁 This step 204 determines whether the partner page algorithm structure of its partnership structure of the algorithm in step 205 pages zone area existed on this page access lock

步骤206从此页区的伙伴算法链表中移出此页所存在的成员歩骤207对此页区的伙伴算法结构的访问开锁步骤208将此页映像到用户空间步骤209返回出错讯息 Access lock step buddy algorithm step 206 the list is removed from the page regions ho members present in the page area of ​​this step 207 of the algorithm 208 this page structures in the partner image to the user in step 209 to return an error message space

步骤300获得所要释放的物理内存的物理地址 The physical address of the physical memory in step 300 to obtain the desired release

步骤301将此物理地址转换为其所存在的页结构 This step 301 is converted into the physical address page structure in which it is

步骤302判断所要释放的页是否已经被分配 Step 302 determines whether the page to be released has been assigned

步骤303获取此页所在的页区结构 Step 303 acquires page area where the structure of this page

歩骤304对此页区的伙伴算法结构的访问加锁 Access to this area step 304 of the algorithm structure of partner ho lock

步骤305向此页区的伙伴算法链表中加入此页所存在的成员 Step 305 members to join the existence of this page to list on this page buddy algorithm zone

步骤306对此页区的伙伴算法结构的访问开锁 Access unlock algorithm structure of the partner regions to this page 306

步骤307返回释放已成功的讯息 Step 307 returns the message has been successfully released

步骤3Q8返回出错讯息 Step 3Q8 returns an error message

具体实施方式 Detailed ways

以下,将结合附图对本发明的较佳实施方式作详细说明。 Hereinafter, the preferred embodiments in conjunction with the accompanying drawings of embodiment of the present invention will be described in detail.

请参考图1,图1为本发明的一种Linux系统下物理内存的测试方法的方 Please refer to FIG square test method of the physical memory of the present invention, one kind of a Linux system, FIG. 1

法流程图。 Method flowchart. 如图所示,本发明的一种Limix系统下物理内存的测试方法整体包 As shown, the method of physical memory in the system according to the present invention, one kind Limix overall package

含以下步骤: Comprising the following steps:

激活一个字符设备驱动程序,以驱动一个字符设备对一个物理内存的物理页进行分配与释放(步骤100), Linux系统的设备分为字符设备(char device), 块设备(block device)和网络设备(network device)三种,字符设备是指存取时没有高速缓存的设备,典型的字符设备包含鼠标,键盘,串行口等; Activating a character device driver to drive a character device for a physical memory allocation and deallocation of physical pages (step 100), the device is divided into a Linux system character device (char device), a block device (block device) and network equipment (network device) are three characters refer to the device when no cache access device, the typical character device comprises a mouse, keyboard, serial ports and the like;

判断字符设备是否成功激活(步骤101),如果否,则终止本测试进程, 如果字符设备成功激活,则以页为单位,按照物理内存的物理地址遍历整个物理内存(歩骤102); Determining whether the device is successful activation character (step 101), if not, the process terminates this test, if the character device successfully activated, places a page unit, through the entire physical memory in accordance with the physical address of the physical memory (step 102 ho);

判断遍历是否完成(步骤103),如果完成,则关闭字符设备(步骤lll), 否则,通过Linux系统提供的档案作业函数(即ioctl函数)设定所要访问的物理内存的物理地址(步骤104),其中ioctl函数非常庞杂,它可以控制各种档案的属性,它用于控制特殊档案的底层设备参数,这些特殊档案通常是指终端、套接字和接口, ioctl函数是设备驱动程序中对设备的1/0信道进行管理的函数,所谓对I/0信道进行管理,就是对设备的--些特性进行控制,例如串口的传输波特率、马达的转速等等,ioctl函数是档案结构中的一个属性分量,就是说如果你的驱动程序提供了对ioctl的支持,用户就可以在用户程序 Analyzing traversal is completed (step 103), if completed, is closed character device (step LLL), otherwise, the file operation function provided by the Linux system (i.e. ioctl function) the physical address of the physical memory is set to be accessed (step 104) wherein the ioctl function is very complex, it is possible to control various properties of the file, which is used to control specific parameters of the underlying device files, these files usually refers to a special terminal, and an interface socket, ioctl function is a device driver for the device 1/0 of the channel management functions, of the so-called I / 0 channel management, that is, equipment - some of the control characteristics, e.g. baud rate, the motor speed serial port, etc., the ioctl function is a file structure component of a property, that is, if your driver provides support for ioctl, the user can program the user

中使用i0Ctl函数控制设备的1/0信道; 1/0 channel used i0Ctl function control apparatus;

判断设定所要访问的物理内存的物理地址是否成功(步骤105),如果否, 则返回步骤102,继续以页为单位,按照物理内存的物理地址遍历整个物理内存,如果成功设定所要访问的物理内存的物理地址,则通过Linux系统提供的档案作业函数(即咖ap函数)将物理内存映像至用户空间(步骤106) , Linux 系统提供了对进程内存管理进行支持的函数,主要包含了咖ap函数和nmnmap 函数等对进程的虚拟块堆(avl)数进行管理的函数,mmap函数,或者称为"内存映像函数",首先,它可以映像任何位置的内存,而不单单只局限于进程, 其次,它不仅可以将虚拟地址映像到物理的随机存取内存(RAM)或者交换分区(sw即),还可以将它们映像到档案和档案位置,这样,读写内存将对档案中的资料进行读写,不过在这里,我们只需关心mmap函数向进程添加被映像的物理内存的能 Analyzing the physical memory of a physical address setting to be accessed is successful (step 105), if not, returns to step 102 to continue in page units, through the entire physical memory in accordance with the physical address of the physical memory, if successfully set up to be accessed physical memory physical address, file operations function (ie coffee ap function) physical memory image to the user space (step 106) Linux system provided through, Linux system provides a function of process memory management support, mainly containing coffee ap functions and functions, and so on nmnmap process's virtual block stack (avl) carried out a number of management functions, mmap function, or known as the "memory mapping function," first, it can map memory in any location, not just confined to the process Secondly, it can not only images the virtual address to a physical random access memory (RAM) or swap (sw i.e.), they can also be image files and the location of the file, so that the reader will archive the data in the memory read and write, but here, we only care about mmap function to add physical memory to be able to process image ,immm即函数所做的事情恰好与mmap函数相反,其用以解除内存的映像,即:用以释放落在从某一地址开始,长度为一定空间内的物理内存所对应的虚空间; , I.e. things immm mmap function does exactly the opposite function, which is used to lift the image memory, namely: to release fall from a certain address, a length of a space within the physical memory corresponding to the virtual space;

判断物理内存是否被成功映像至用户空间(步骤107),如果否,则返回步骤102,如果是,则通过内存检测算法对物理内存进行测试(步骤108), 其中内存检测算法是指通过向内存中写入特定的数值,然后再读出此数值进行比对从而实现内存测试的各种内存检测算法,内存检测算法是通过Limix系统提供的insraod命令将执行此算法的驱动程序模块动态加载到系统核心上实现的,这些均为现有技术,在此不再赘述; Determining whether the physical memory is successfully mapped to the user space (step 107), if not, returns to step 102, if it is, a test is made (step 108) the physical memory by the memory detection algorithm, wherein the memory test algorithm refers to memory writes to a particular value, and this value is read out to compare insraod command detection algorithms to achieve various memory test the memory, the memory detection algorithm is provided by the system will perform algorithm Limix driver module dynamically loaded into the system realization of the core, these are prior art, are not repeated here;

通过Linux系统提供的档案作业函数(即munmap函数)解除此物理内存与用户空间的映像关系(步骤109);以及 Provided by the Linux operating system files function (i.e., function munmap) releasing this mapping relationship of the physical memory space of the user (step 109); and

通过Linux系统提供的档案作业函数(即ioctl函数)释放字符设备中所储存的讯息(步骤110),然后返回步骤102,继续以页为单位,按照物理内存的物理地址遍历整个物理内存,直至遍历完成。 Provided by the Linux system files job function (i.e. ioctl function) release message (step 110) character device stored, and then returns to step 102 to continue in page units, through the entire physical memory in accordance with the physical address of the physical memory until traversal carry out.

现在请参考图2,此图为本发明的测试方法中的字符设备对物理内存的物 Referring now to Figure 2, the test method of the present invention, this photo shows the character of physical memory devices was

理页进行分配的方法流程图,如图所示,其分配进程还包含如下歩骤: The method for allocating physical page of a flowchart shown in FIG its allocation process further comprising the step ho:

获得所要分配的物理内存的物理地址(步骤200); Obtaining a physical address of physical memory to be allocated (step 200);

将此物理地址转换为其所存在的页结构(步骤201); This physical address translation for the page configuration (step 201) which it is present;

判断此页是否被系统核心或其它硬件及应用程序所占用(步骤202),如果被占用则返回出错讯息(步骤209)后终止分配进程,如果未被占用则获取此页所在的页区(zone)结构(步骤203); To determine whether this page is occupied (step 202), or other core system hardware and applications, if occupied an error message (step 209) returns after the termination of the distribution process, if it is not occupied this page get page area where (zone ) structure (step 203);

判断此页是否存在于其K区(zone)的伙伴(buddy)算法结构屮(歩骤204),如果此页不存在于其页区(zone)的伙伴(buddy)算法结构屮,则返问出错讯息(步骤209)后终止分配进程,否则,对此贞区的伙伴(buddy) 算法结构的访问加锁(步骤205); This page exists to determine whether its partner K zone (zone) of (buddy) algorithm structural Che (ho step 204), this page if their partner page zone (zone) does not exist (buddy) algorithm structural Cao, then returned to ask after the error message (step 209) to terminate the distribution process, otherwise, this partner Chen area (buddy) access algorithm structure lock (step 205);

从此页区的伙伴(buddy)算法链表中移出此页所存在的成员(歩骤206); From this algorithm partner list page region (Buddy) removed a member of this page is present (step 206 ho);

对此页区的伙伴(buddy)算法结构的访问开锁(步骤207);以及 This partner page area (buddy) to unlock access (step 207) algorithm structure; and

将此页映像到用户空间(步骤208),然后终止分配进程。 Add this page mapped to user space (step 208), and terminates the allocation process.

现在请参考图3,此图为本发明的测试方法中的字符设备对物理内存的物理页进行释放的方法流程图,如图所示,其释放进程还包含如下步骤: Referring now to Figure 3, the test method of the present invention, this picture shows the character device in physical memory pages of the physical release flowchart of a method, as shown in FIG release process further comprises the steps of:

获得所要释放的物理内存的物理地址(步骤300); To obtain the physical address of the physical memory is released (step 300);

将此物理地址转换为其所存在的页结构(步骤301); This physical address conversion page configuration (step 301) which it is present;

判断所要释放的页是否已经被分配(步骤302),如果未被分配则返回出错讯息(步骤308)后终止释放进程,如果已被分配则获取此页所在的页区(zone)结构(步骤303); To determine whether you want to release the page has been allocated (step 302), if not assigned an error message (step 308) returns after termination of the release process, if has been assigned the acquired page area (zone) to the page's structure (step 303 );

对此页区的伙伴(buddy)算法结构的访问加锁(步骤304); Partners to this page area (buddy) access algorithm structure lock (step 304);

向此页区的伙伴(buddy)算法链表中加入此页所存在的成员(步骤305); Join members of this page exists to partner this page area (buddy) list algorithms (step 305);

对此页区的伙伴(buddy)算法结构的访问开锁(步骤306);以及 This partner page area (buddy) to unlock access (step 306) algorithm structure; and

返回释放已成功的讯息(步骤307),然后终止释放进程。 Release has been successfully returned messages (step 307), and terminates the release process.

在Linux系统中,核心(Kernel)包含了内存管理机制,内存是以页的形式在系统中存在的,每一个页代表了唯一的一块物理内存,系统通过一个数据结构来描述这个页的信息,并以链表的形式按照页在物理内存的位置将每个页结构链接在一起,并通过一个全局的页结构指针指向链表的头,因此说获得了链表头,就可以得到内存中的任何一个页结构。 In the Linux system, the core (Kernel) includes memory management mechanism, in the form of a memory page is present in the system, each page represents a unique piece of physical memory, the system to describe the information of this page via a data structure, and in the form of a linked list of pages according to the location in physical memory page structure of each linked together by a global pointer to the page head of the list structure, thus he said list head is obtained, it can be any of the pages in memory structure. 当然我们并不能任意的操作内存中的每一个页,既然Limix系统有它自己的内存管理机制,我们就要在不损 Of course, we can not operate any memory of each page, since Limix system has its own memory management mechanism, we will not harm

害系统规则的基础上来实现本发明的目标。 Rules based system damage up to achieve the object of the present invention. F面就进一步说明本发明是如何实现的。 F surface to further illustrate how the present invention is achieved.

在Linux系统启动以后,核心(Kernel)会把物理内存分成多个页,并将每个贞标为已被占用(reserved)和未被占用(unreserved)两种状态,被标为已被占用(reserved)的页是被系统核心或是其它硬件及应用程序所占用的, 用户是不允许使用的,因为对它的操作可能会导致整个系统的崩溃,因此我们的测试程序也不允许测试这一部分的内存,通常这一部分只占整个内存的一小部分,大约有几十兆,如果这一部分的内存有问题,通常系统都无法启动,更不用说要运行本发明的测试程序了,请详见图4,此图为本发明的测试方法中所测试的物理内存的页结构示意图,如图所示,本发明能够测试的就是那些被标为未被占用(unreserved)的页。 After boot Linux, the core (Kernel) will be divided into a plurality of physical memory pages, and each has been marked as occupied Chen (Reserved) and unoccupied (unreserved) two states are marked as occupied ( reserved) page is occupied by the system kernel or other hardware and applications, users are not allowed to use, because its operation may lead to the collapse of the entire system, so our test procedures are not allowed to test this section memory, usually only a small part of this part of the entire memory, about tens of megabytes, if only this memory problem, the system can not start normally, let alone run the test program of the invention, please refer to 4, a schematic structural diagram of physical memory pages test method this picture shows the present invention tested, as shown, the present invention is able to test those marked as unoccupied (unreserved) page. 如下表所示,在Linux系统中,物理内存被划分为三个页区(zone): As shown below, in the Linux system, the physical memory page is divided into three regions (zone):

类型 Types of

直接内S¥i页区 S ¥ i directly within the page area

(ZONE DMA) (ZONE DMA)

普通(ZONE—NORMAL) Normal (ZONE-NORMAL)

高端(ZONE HIGHMEM) High-end (ZONE HIGHMEM)

page

页区 Page area

地址范围0MB - 16MB Address Range 0MB - 16MB

16MB - 896MB 16MB - 896MB

896 MB以上 More than 896 MB

页区(zone)是用stmct一zone—t描述的,它跟踪页框使用、空闲区域和锁等讯息,具体描述如下: Page zone (Zone) is a zone-t stmct described, which use page frame track, a free area, and lock posts, described as follows:

每个结点的内存被分为多个块,称为页区(zone),它表示内存中的一段区域。 Each node memory is divided into a plurality of blocks, called pages zone (Zone), which represents a section of an area of ​​memory. 一个页区(zone)用struct—zone一t结构描述,页区(zone)的类型主要有:直接内存存取(DMA)页区(ZONE—DMA)、普通页区(ZONE—NORMAL)和高端页区(ZONE—HIGHMEM)三种,页区(zone)可以使页面分配更有目的性, 有利于减少内存碎片。 A page zone (Zone) with a t struct-zone structure description, p type regions (Zone) are: direct memory access (DMA) page zone (ZONE-DMA), common page zone (ZONE-NORMAL) and high page zone (zONE-HIGHMEM) are three pages zone (zone) can make the page more purposeful allocation, it helps to reduce memory fragmentation. 直接内存存取(DMA)页区(ZONE—DMA)位于低端的内存空间,用于某些旧的工业标准结构(ISA)设备。 Direct memory access (DMA) page zone (ZONE-DMA) at the lower end of the memory space, used in some older Industry Standard Architecture (ISA) devices. 普通页区(ZONE—NORMAL) 的内存直接映像到Linux系统核心(Kernel)线性地址空间的高端部分,许多核心(Kernel)操作只能在普通页区(ZONE—NORMAL)中进行。 Ordinary page memory zone (ZONE-NORMAL) images directly to the Linux system core (Kernel) high-end part of the linear address space, many of the core (Kernel) can only operate in the general area of ​​the page (ZONE-NORMAL) in.

每个页区(zone)中的未被占用(unreserved)页,依照伙伴(buddy) 算法[每个页区(zone)的页分配使用一种伙伴(buddy)算法,此伙伴(buddy) Each page zone (zone) in unoccupied (unreserved) page, using a partnership (buddy) algorithm in accordance with the partner (buddy) page allocation algorithm [each page area (zone), and this partner (buddy)

算法核心的页分配器引入了页区(zone)结构, 一个页区(zone)就是一大块连续的物理页面,伙伴(buddy)算法将整个页区(zone)划分为以2为幂次的各级页块的集合,相邻的同次页块称为伙伴(buddy), 一对伙伴(buddy) 可以合并到更高次的页面集合中去],链接成图5所示的结构: The core of the algorithm introduces a page page allocator zone (zone) structure, a page area (zone) is a continuous chunk of physical pages, partner (buddy) algorithm to the entire page area (zone) is divided into a power of 2 times levels set page blocks, the adjacent blocks called pages same partners (Buddy), one pair partners (Buddy) may be incorporated into a set of higher-order page to], as shown in FIG. 5 of the link structure:

如图5所示,图中左侧部分中的每一个长方形代表这一个链表,此链表中的每一个成员代表了固定大小的在物理上连续的内存页,这个固定大小就是图中标出的以2为幂次的数字。 As shown, the left portion in FIG Each rectangle represents five this list, this list each represents a member of a fixed size in contiguous physical memory pages, the fixed size is marked in FIG. 2 for the power of numbers. 右侧部分所示的灰色长/j形是此链表的屏蔽,屏蔽的每一位对应着链表中的每一个成员,如果此成员被分配,则屏蔽置l,否则置0。 Long gray / j-shape is shown in the right part of the list of this shield, the shield of each bit corresponds to each member of the list, if this member is assigned, the shield L is set, 0 otherwise.

至此,本领域的技术人员便可依照图1、图2及图3所示的本发明的内存测试方法的流程,通过用户层测试接口及一个字符设备来完成和实现在Limix 操作系统下以较高的测试涵盖率和准确性对未被占用的物理内存直接进行访问和测试。 Thus, those skilled in the art can in accordance with FIG. 1, the process of the present invention the memory testing method shown in FIG. 2 and FIG. 3, is accomplished by the user interface, and a character layer test device and implemented in the operating system at a relatively Limix high test coverage and accuracy of unoccupied physical memory access and test directly.

虽然本发明以前述的较佳实施方式公开如上,然而其并非用以限定本发明。 While the present invention as disclosed in the aforementioned preferred embodiment, however, the present invention is not limited thereto. 本领域的技术人员应当意识到在不脱离本发明所附的权利要求所揭示的本发明的范围和精神的情况下,所作出的变化与修改,均属本发明的专利保护范围之内。 Those skilled in the art will appreciate that variations and modifications without departing from the scope and spirit of the present invention, the invention disclosed in the appended claims is, made, it is within the scope of patent protection of the present invention. 关于本发明所界定的保护范围请参考所附的权利要求。 On the scope of the present invention as defined in claim please refer to the appended claims.

Claims (5)

1、一种Linux系统下物理内存的测试方法,应用于Linux操作系统下的物理内存的检测过程中,该方法包含以下步骤: (a)、激活一字符设备驱动程序,以驱动一字符设备对一物理内存的物理页进行分配与释放; (b)、当所述字符设备成功激活后,以页为单位,按照所述物理内存的物理地址遍历整个物理内存; (c)、判断遍历是否完成,如果完成,则关闭所述字符设备,否则,通过Linux系统提供的ioctl函数设定所要访问的所述物理内存的物理地址; (d)、当成功设定所要访问的物理内存的物理地址后,通过Linux系统提供的mmap函数将所述物理内存映像至用户空间; (e)、当所述物理内存被成功映像至用户空间后,通过内存检测算法对所述物理内存进行测试; (f)、通过Linux系统提供的munmap函数解除该物理内存与用户空间的映像关系;以及(g)、通过所述Linux系统提供的 1, the method of physical memory, one kind of the Linux system, the detection process applied to the physical memory in Linux operating system, the method comprising the steps of: (a), activating a character device drivers for character devices for driving a a physical page of physical memory allocation and release; (B), when the character device successfully activated, in page units, through the entire physical address of the physical memory according to the physical memory; (C), determines whether the traversal completion If completed, the closing device of the character, otherwise, the ioctl function set provided by the Linux system to access physical memory physical addresses; (D), when the physical address of the physical memory to be accessed successfully set up , the mmap functions provided by the Linux system image to the user of the physical memory space; (E), when the physical memory is successfully mapped to user space, the physical memory is tested by the memory test algorithm; (f) , munmap functions provided by the Linux system mapping relationship releasing the physical memory space of the user; and (g), the Linux system is provided by ioctl函数释放该字符设备中所储存的讯息,并继续以页为单位,按照该物理内存的物理地址遍历该整个物理内存,直至遍历完成。 ioctl function to release the stored character message device, and continues in page units, traverses the entire physical address of the physical memory in accordance with the physical memory until a complete traversal.
2、 如权利要求1所述的Linux系统下物理内存的测试方法,其特征在于, 所述字符设备对所述物理内存的物理页进行分配还包含如下步骤:获得所要分配的物理内存的物理地址; 将所述物理地址转换为其所存在的页结构;判断该页是否被系统核心或其它硬件及应用程序占用,如果被占用则返回出错讯息并终止分配进程,如果未被占用则获取该页所在的页区结构;判断该页是否存在于该页区的伙伴算法结构中,如果该页不存在于该页区的伙伴算法结构中,则返回出错讯息并终止分配进程,否则,对该页区的伙伴算法结构的访问加锁;从该页区的伙伴算法链表中移出该页所存在的成员;对该页区的伙伴算法结构的访问开锁;以及将该页映像到用户空间,并终止分配进程。 2, the test method as claimed in physical memory Linux system according to claim 1, wherein said dispensing device of the character of the physical pages of physical memory further comprises the steps of: obtaining a physical address of the physical memory to be allocated ; converting the physical address is present in its page structure; determining whether the page is occupied by a core or other hardware systems and applications, if occupied returns an error message and terminates the allocation process, if the acquisition of the page is not occupied page area where the structure; determine whether the page exists in the partner region algorithm structure of the page, if that page does not exist in the buddy system structure of the page area, it returns an error message and terminates the allocation process, otherwise, the page access algorithm structure partner lock region; member page is present is removed from the buddy algorithm list page zone; unlocked access algorithm structure of the page area partners; and the page image to the user space, and terminate allocation process.
3、 如权利要求1所述的Linux系统下物理内存的测试方法,其特征在于, 所述字符设备对所述物理内存的物理页进行释放还包含如下步骤:获得所要释放的物理内存的物理地址;将该物理地址转换为其所存在的页结构;判断所要释放的页是否已经被分配,如果未被分配则返回出错讯息并终止释放进程,如果已被分配则获取该页所在的页区结构; 对该页区的伙伴算法结构的访问加锁; 向该页区的伙伴算法链表中加入该页所存在的成员; 对该页区的伙伴算法结构的访问开锁;以及返回释放已成功的讯息,并终止释放进程。 3, the test method as claimed in physical memory Linux system according to claim 1, characterized in that said apparatus to said character physical page of physical memory to be released further comprising the steps of: obtaining a physical address of the physical memory to be released ; converting the physical address of the page structure in which it is; to be released to determine whether the page has already been allocated, if not assigned return an error message and terminates the release process, if it has been assigned to obtain the structure of the page where the page area ; access to the area of ​​the page algorithm structure partner locked; adding the page to the presence of members of the buddy algorithm list page zone; unlock access algorithm structure of the page area partners; and the release has been successfully returned messages and terminates the release process.
4、 如权利要求l所述的Linux系统下物理内存测试方法,其特征在于, 所述内存检测算法是通过向内存中写入特定的数值,然后再读出该数值进行比对从而实现内存测试的各种内存检测算法。 4. Test Method physical memory of the Linux system as claimed in claim l, wherein said detection algorithm memory by writing to specific numerical values ​​in memory, and then read out to compare the value in order to achieve a memory test a variety of memory test algorithms.
5、 如权利要求4所述的Linux系统下物理内存的测试方法,其特征在于, 所述内存检测算法是通过Linux系统提供的insmod命令将执行该算法的驱动程序模块动态加载到系统核心上实现的。 5, the test method as claimed in physical memory Linux system according to claim 4, wherein said memory test algorithm insmod command is provided by the execution of the algorithm Linux system driver module dynamically loaded into the core of the system to achieve of.
CN 200510023063 2005-12-28 2005-12-28 Testing method of physical RAM in Linux system CN100449492C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 200510023063 CN100449492C (en) 2005-12-28 2005-12-28 Testing method of physical RAM in Linux system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 200510023063 CN100449492C (en) 2005-12-28 2005-12-28 Testing method of physical RAM in Linux system

Publications (2)

Publication Number Publication Date
CN1991770A CN1991770A (en) 2007-07-04
CN100449492C true CN100449492C (en) 2009-01-07

Family

ID=38214041

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 200510023063 CN100449492C (en) 2005-12-28 2005-12-28 Testing method of physical RAM in Linux system

Country Status (1)

Country Link
CN (1) CN100449492C (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102542200A (en) * 2011-12-21 2012-07-04 北京握奇数据系统有限公司 Method and device for processing digital authentication terminal
CN103412807A (en) * 2013-08-12 2013-11-27 浪潮电子信息产业股份有限公司 Memory inspection testing system
CN104809039B (en) * 2015-04-24 2019-01-01 英业达科技有限公司 Internal-memory detection method based on physical memory allocation map
CN104951276B (en) * 2015-06-24 2017-05-31 福州瑞芯微电子股份有限公司 A kind of detection method and system of the failure of chip instruction cache

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5835704A (en) 1996-11-06 1998-11-10 Intel Corporation Method of testing system memory
US5881221A (en) 1996-12-31 1999-03-09 Compaq Computer Corporation Driver level diagnostics
CN1326152A (en) 2000-05-25 2001-12-12 英业达股份有限公司 Method for automatically and quickly testing memory of palm computer in windows environment
US6742148B1 (en) 2000-03-06 2004-05-25 Pc-Doctor Inc. System and method for testing memory while an operating system is active
GB2408118A (en) 2003-11-14 2005-05-18 Hewlett Packard Development Co System and method for testing a memory using DMA

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5835704A (en) 1996-11-06 1998-11-10 Intel Corporation Method of testing system memory
US5881221A (en) 1996-12-31 1999-03-09 Compaq Computer Corporation Driver level diagnostics
US6742148B1 (en) 2000-03-06 2004-05-25 Pc-Doctor Inc. System and method for testing memory while an operating system is active
CN1326152A (en) 2000-05-25 2001-12-12 英业达股份有限公司 Method for automatically and quickly testing memory of palm computer in windows environment
GB2408118A (en) 2003-11-14 2005-05-18 Hewlett Packard Development Co System and method for testing a memory using DMA

Also Published As

Publication number Publication date
CN1991770A (en) 2007-07-04

Similar Documents

Publication Publication Date Title
US7539828B2 (en) Method and system for automatically preserving persistent storage
US7831977B2 (en) Shared file system cache in a virtual machine or LPAR environment
US7457880B1 (en) System using a single host to receive and redirect all file access commands for shared data storage device from other hosts on a network
US6950107B1 (en) System and method for reserving and managing memory spaces in a memory resource
KR100817087B1 (en) Method for operating buffer cache of storage device including flash memory
JP2582487B2 (en) External storage system and its control method using the semiconductor memory
US7136973B2 (en) Dual media storage device
US9727452B2 (en) Distributing metadata across multiple different disruption regions within an asymmetric memory system
AU2010234648B2 (en) Method and apparatus for storing data in a flash memory data storage device
US8166233B2 (en) Garbage collection for solid state disks
US6728836B1 (en) Segmenting cache to provide varying service levels
US8626986B2 (en) Pre-emptive garbage collection of memory blocks
EP1399826B1 (en) Virtual pci device apparatus and method
US20110264880A1 (en) Object copying with re-copying concurrently written objects
US9064330B2 (en) Shared virtual memory between a host and discrete graphics device in a computing system
US20050177698A1 (en) Method for partitioning memory mass storage device
US20080098195A1 (en) Memory system including flash memory and mapping table management method
US9043513B2 (en) Methods and systems for mapping a peripheral function onto a legacy memory interface
US20170315832A1 (en) Virtualization support for storage devices
US6848034B2 (en) Dense server environment that shares an IDE drive
US8209692B2 (en) Deallocation of computer data in a multithreaded computer
KR100439675B1 (en) An efficient snapshot technique for shated large storage
US20060085626A1 (en) Updating system configuration information
US8166258B2 (en) Skip operations for solid state disks
US6738875B1 (en) Efficient write-watch mechanism useful for garbage collection in a computer system

Legal Events

Date Code Title Description
C06 Publication
C10 Entry into substantive examination
C14 Grant of patent or utility model