WO2016082191A1 - File access method and apparatus - Google Patents

File access method and apparatus Download PDF

Info

Publication number
WO2016082191A1
WO2016082191A1 PCT/CN2014/092513 CN2014092513W WO2016082191A1 WO 2016082191 A1 WO2016082191 A1 WO 2016082191A1 CN 2014092513 W CN2014092513 W CN 2014092513W WO 2016082191 A1 WO2016082191 A1 WO 2016082191A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
address
virtual space
space
memory
Prior art date
Application number
PCT/CN2014/092513
Other languages
French (fr)
Chinese (zh)
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 PCT/CN2014/092513 priority Critical patent/WO2016082191A1/en
Priority to CN201480037874.2A priority patent/CN105830022B/en
Publication of WO2016082191A1 publication Critical patent/WO2016082191A1/en

Links

Images

Definitions

  • the present invention relates to the field of computers and, more particularly, to a method and apparatus for accessing files.
  • the central processing unit reads data and stores data directly from the disk at a slow speed due to the limitation of the disk access capability. Therefore, the CPU needs to access the data in the disk through the memory.
  • BIO Block Input Output
  • the CPU accesses the files on the disk by means of BIO (Block Input Output). Specifically, when a file needs to be read from a disk, the CPU needs to first copy the data of the file to be read from the disk into the memory in units of blocks, and then read the data from the memory. When you need to write data to a file on the disk, the CPU needs to write the received data to the memory first, and then write the data in the memory to the disk in block units.
  • NVM non-volatile memory
  • next-generation NVM such as PCM (Phase Change Memory), ReRAM (Resistive Random Access Memory) or MRAM (Magnetic RAM, magnetic random access memory), etc.
  • PCM Phase Change Memory
  • ReRAM Resistive Random Access Memory
  • MRAM Magnetic RAM, magnetic random access memory
  • the CPU accesses the file system in a traditional BIO manner, and requires memory as a bridge for file access.
  • NVM media When the next generation of NVM media is used as memory, due to the non-volatility of NVM media, files in the file system can be stored in memory for a long time and directly accessed by the CPU. If the file is accessed using the traditional BIO method, it is bound to be Causes file system access to be inefficient.
  • Embodiments of the present invention provide a method and apparatus for accessing a file to improve file access efficiency.
  • a method of accessing a file is provided, the method being applied to a storage device that establishes a file system in a memory, wherein the memory is a non-volatile memory NVM, including: receiving An access request for accessing a file, where the access request carries an identifier of a file to be accessed, data of all files in the file system is stored in a memory, the memory is a non-volatile storage medium, and the file is stored in the memory Obtaining information of the first virtual space from the metadata of the file according to the identifier of the file, where the first virtual space is a virtual consecutive address according to the first physical space of the memory a mapping relationship between the first virtual space and a second virtual space of a process of accessing the file, wherein the second virtual space is a contiguous address space in a virtual space of the process; Linking a file page table of the file into a page table of the process according to the mapping relationship, wherein the file page table is configured to map a virtual address
  • the linking, by the mapping, the file page table of the file into the page table of the process, according to the first virtual space Determining a starting address of the second virtual space; determining a page directory entry corresponding to a starting address of the second virtual space in a page table of the process; The base address of the file page table is recorded in the page directory entry.
  • the establishing the first virtual space and the second virtual space of the process of accessing the file includes: recording a location offset of an address of the first virtual space and an address of the second virtual space.
  • the location offset of the address of the first virtual space and the address of the second virtual space is 0. .
  • the method further includes: virtualizing the first virtual space according to the first physical space of the memory.
  • the access request is a write request, where the access request carries data to be written and the access request a starting address, the accessing the physical address of the file in the memory according to a page table of a process linked to the file page table, comprising: determining a page table according to a process after linking the file page table The physical address corresponding to the start address of the access request cannot be obtained; a new physical address is allocated to the file in the memory; and the to-be-written data is written into the new physical address.
  • the method further comprises: adding a new virtual address to the first virtual space, and establishing a location in the file page table A mapping relationship between the new virtual address and the new physical address.
  • the second aspect provides an apparatus for accessing a file, including: a receiving module, configured to receive an access request for accessing a file, where the access request carries an identifier of a file to be accessed, where the file is an arbitrary file in the file system.
  • the data of all files in the file system is stored in a memory, the memory is a non-volatile storage medium, the file is stored in a first physical space of the memory, and an acquiring module is configured to: according to the identifier of the file Acquiring information of the first virtual space in the metadata of the file, where the first virtual space is a virtual continuous address space according to the first physical space of the memory; and an establishing module, configured to establish the first virtual space And a mapping relationship between the second virtual space of the process of accessing the file, wherein the second virtual space is a contiguous address space in the virtual space of the process; the linking module is configured to Mapping a file page table of the file into a page table of the process, wherein the file page table is used in the first virtual space Mapping a virtual address to a physical address of the first physical space; access module, the physical address for a page table memory in accordance with the process of accessing the file into the document after the page chain table.
  • the linking module is specifically configured to: determine, according to a starting address of the first virtual space, and the mapping relationship, the second virtual space a start address; a page directory entry corresponding to a start address of the second virtual space is determined in a page table of the process; a base address of the file page table is recorded in the page directory entry.
  • the establishing module is specifically configured to record an address of the first virtual space and the second virtual space The position offset of the address.
  • the location offset of the address of the first virtual space and the address of the second virtual space is 0. .
  • the device further includes: a virtual module, configured to virtualize the first physical space according to the memory A virtual space.
  • the access request is a write request, where the access request carries data to be written and the Accessing the start address of the request
  • the access module is specifically configured to: determine that the physical address corresponding to the start address of the access request cannot be obtained according to the page table of the process linked to the file page table; in the memory Assigning a new physical address to the file; writing the data to be written to the new physical address.
  • the method further includes: adding a module, configured to add a new virtual address to the first virtual space;
  • the module is further configured to establish a mapping relationship between the new virtual address and the new physical address in the file page table.
  • a mapping relationship between the first virtual space that is virtualized according to the first physical space of the storage file and the second virtual space in the process is established, and the file is based on the mapping relationship.
  • the file page table is linked into the page table of the process, and the file page table records the mapping relationship between the virtual address in the first virtual space and the physical address in the first physical space, so that the file page table can be linked
  • the page table of the post process implements access to the file by the process. Compared with the traditional way of accessing files by BIO, the process of copying data blocks from disk to memory is reduced, and the file access efficiency is improved.
  • FIG. 1 is a schematic flowchart of a method for accessing a file according to an embodiment of the present invention.
  • FIG. 2 is an exemplary diagram of a mapping relationship between a first virtual space and a second virtual space.
  • FIG. 3 is another exemplary diagram of a mapping relationship between a first virtual space and a second virtual space.
  • FIG. 4 is a schematic block diagram of an apparatus for accessing a file according to an embodiment of the present invention.
  • FIG. 5 is a schematic block diagram of an apparatus for accessing a file according to an embodiment of the present invention.
  • the operating system can choose which 4M content to keep in memory at each moment, and exchange program fragments between memory and disk when needed, so that This 16M program runs on a machine with only 4M of RAM.
  • a virtual address space is a range of virtual addresses that a process can access.
  • the size of the virtual address space is typically determined by the computer's instruction set architecture. For example, a 32-bit Central Processing Unit (CPU) provides a virtual address space of 0 to 0xFFFFFF (4G). One of the addresses in the virtual address space is called a virtual address.
  • CPU Central Processing Unit
  • One of the addresses in the virtual address space is called a virtual address.
  • the physical address space corresponds to the physical address range of the memory.
  • One of the addresses in the physical address space is called a physical address.
  • the physical address space is smaller than the virtual address space, and the physical address space can be mapped into the virtual address space.
  • the virtual address (or linear address) is not directly sent to the memory address bus, but is sent to the MMU (Memory Management Unit), thereby virtualizing The address is mapped to a physical address. That is, the MMU is used to map the virtual address of the program to the physical address of the memory.
  • MMU Memory Management Unit
  • the MMU In order to map the virtual address of the program to the physical address of the memory, the MMU introduces a paging mechanism. Specifically, in paging, for efficiency, the virtual address space is divided in units of pages, and pages in the virtual address space may be referred to as virtual pages, and corresponding physical address spaces are also divided in units of pages.
  • a page of a physical address space can be referred to as a physical page (or a physical page frame), where the virtual page and the physical page are the same size.
  • the MMU Based on the concept of introducing a page, the MMU implements an index of a virtual address to a physical address in the form of a multi-level page table. Specifically, a virtual address, size 4 bytes (32 bits), contains information to find the physical address, divided into three parts:
  • the 10th (up to 10th) from the 22nd to the 31st is the index in the page directory
  • the 12th to the 21st bits are the indexes in the page table
  • the 12th bit to the 11th bit is an in-page offset.
  • the CPU For a virtual address to be converted to a physical address, the CPU first finds the physical page where the page directory is located based on the value in control register CR3. Then, according to the value of the 10th (the highest 10bit) of the 22nd to the 31st of the virtual address as the index, the corresponding PDE (page directory entry) is found, and the PDE has the page table corresponding to the virtual address. Physical address. With the physical address of the page table, according to the values of the 10th to the 21st bits of the virtual address as the index, the corresponding PTE (page table entry) in the page table is found. The physical address of the physical page corresponding to this virtual address is in the page table entry. Finally, the lowest 12 bits of the virtual address, that is, the intra-page offset, plus the physical address of the physical page, the physical address corresponding to the virtual address is obtained.
  • a page directory has 1024 entries, and the highest virtual address of 10 bits can just index 1024 entries (2 to 10 powers equals 1024).
  • a page table also has 1024 entries, 10 bits in the middle of the virtual address, just 1024 entries.
  • the lowest 12-bit virtual address (2 to the 12th power equals 4096), as an intra-page offset, can just index 4KB, which is each byte in a physical page.
  • the calculation process of converting a virtual address into a physical address means that the processor finds the physical page of the current page directory through CR3, takes the upper 10 bits of the virtual address, and then shifts the 10 bit to the left by 2 bits (because each page directory entry is 4 bytes long).
  • shifting 2 bits to the left is equivalent to multiplying 4) to get the address in the page, and taking out the PDE (4 bytes) at the address, and finding the physical page of the page table corresponding to the virtual address, taking the 12th bit of the virtual address to The 21st bit of the 21st bit, then shift the 10 bit to the left by 2 bits (because each page table entry is 4 bytes long, 2 bits left shift is equivalent to multiplying 4) to get the address in the page, and take out the PTE at the address ( 4 bytes), the address of the physical page corresponding to the virtual address is found, and finally the 12-bit in-page offset is obtained to obtain the physical address.
  • a 32-bit pointer that can address a range of 0x00000000-0xFFFFFF, 4GB. This means that a 32-bit pointer can address every byte of the entire 4GB address space.
  • a page directory entry that corresponds to a page table.
  • a process has a page directory. So in page units, page directories and page tables can guarantee the mapping of each page and physical memory in the 4G address space.
  • Each process has its own 4G address space, from 0x00000000-0xFFFFFF. This is achieved by each process's own set of page directories and page tables. Since each process has its own page directory and page table, the physical memory of each process's address space map is different. The values of the same virtual address of both processes (if there is a physical memory map) are generally different because they tend to correspond to different physical pages.
  • mapping process of the MMU from the virtual address of the program to the physical address of the memory is described in detail above.
  • the NVM medium is used as the memory
  • the paging-based MMU is used to implement direct access of the program to the file.
  • a file system is a software structure in the operating system that is responsible for managing and storing file information.
  • a file system is a system that organizes and allocates space for file storage devices, is responsible for file storage, and protects and retrieves stored files.
  • a file system consists of three parts: an interface to a file system, a collection of software for file manipulation and management, file data, and attributes.
  • the central concept of a file system is a superblock, an inode, a data block, a directory block, and an indirection block.
  • the super block includes general information about the file system, such as the size of the file system.
  • the inode includes all the information of a file other than the file name.
  • the file name is stored in the directory block along with the number of inodes.
  • the directory entry includes the file name and the number of inodes of the file.
  • These dynamically allocated blocks are indirect blocks.
  • data and metadata of the file may also be stored in the memory. It should be noted that, in the embodiment of the present invention, the memory is a non-volatile memory NVM.
  • FIG. 1 is a schematic flowchart of a method for accessing a file according to an embodiment of the present invention.
  • the method of Figure 1 includes:
  • the file can be any file in the file system.
  • data of all files in the file system is stored in the memory, and the memory is a non-volatile storage medium, and the data of the file is stored in the first physical space of the memory.
  • the file identifier can be a file name. For example, File_1.doc.
  • the file identifier is a unique identifier for the file system identification file.
  • the memory since the memory cannot store data for a long time, the data of the file in the file system is stored in the disk, and the memory serves as a bridge between the CPU and the disk to implement file access.
  • the memory in the embodiment of the present invention adopts an NVM medium, and the memory is non-volatile and can store data for a long time. Therefore, all files in the file system can be stored in the memory, so that the disk can be omitted.
  • the process of copying stored data into memory, the CPU can directly access the file data stored in the memory.
  • the data of the file is usually stored in the memory in the form of a physical page.
  • the first physical space refers to a physical space composed of all physical pages storing the file data.
  • the physical page storing the file data is usually non-contiguous.
  • the first physical space is virtualized into a continuous address space, that is, the first virtual space, and the first
  • the information of a virtual space is stored in the metadata of the file.
  • the information of the first virtual space may be used to indicate the address range of the first virtual space, and the information of the first virtual space may be presented in multiple manners, for example, the start address of the first virtual space and the first virtual space may be stored.
  • the size, or, can also directly store the address range of the first virtual address space.
  • the first physical space may be virtualized according to the first physical space in the process of establishing the file system, or the first physical space may be virtualized into the first virtual space according to the received request after receiving the request.
  • the time of the virtual first virtual space is not limited, and the virtual mode of the first virtual space is not limited.
  • the second virtual space can be used to represent the address space occupied by the file in the virtual space of the process, that is, the process needs to access the file through the second virtual space.
  • the mapping manner between the first virtual space and the second virtual space may be a parallel mapping or an offset mapping.
  • FIG. 2 is a schematic diagram of the parallel mapping.
  • the data of the file is stored by four physical pages, the four physicals.
  • the page constitutes the first physical space, and the four physical pages are discretely distributed in the physical space of the memory.
  • four consecutive virtual pages are virtualized based on the four physical pages, and the four virtual pages constitute a first virtual space, and then the first page is created by using the file page table of the file.
  • a mapping relationship between a virtual page in a virtual space and a physical page in the first physical space thereby establishing a mapping relationship between the virtual address in the first virtual address space and the physical address in the first physical space.
  • the first virtual space is mapped in parallel to the virtual space of the process to obtain a second virtual address space.
  • the starting address of the first virtual space and the second virtual space are The size is the same.
  • FIG. 3 is a schematic diagram of the offset mapping.
  • the data of the file is stored by four physical pages.
  • the physical pages constitute the first physical space, and the four physical pages are discretely distributed in the physical space of the memory.
  • four consecutive virtual pages are virtualized based on the four physical pages, and the four virtual pages constitute a first virtual space. Then, by using the file page table of the file, establishing a mapping relationship between the virtual page in the first virtual space and the physical page in the first physical space, thereby establishing a virtual address in the first virtual address space and the first physical space Mapping of physical addresses.
  • the first virtual space is mapped to the virtual space of the process according to a certain offset to obtain a second virtual address space.
  • the first virtual space and the second virtual space are The size is the same, but the starting address has a certain offset.
  • Step 130 may include recording a location offset of an address of the first virtual space and an address of the second virtual space. It can be understood that when the parallel mapping is adopted, the address offset of the address of the first virtual space and the address of the second virtual space is 0; when the offset mapping is adopted, the address of the first virtual space and the second virtual space The location offset of the address is greater than zero.
  • the mapping between the size of the first virtual space, the starting address of the first virtual space, and the starting address of the second virtual space may be recorded to determine a mapping relationship between the first virtual space and the second virtual space.
  • the mapping relationship between the first virtual space and the second virtual space may also be determined by recording an offset of the size of the first virtual space, recording an end address of the first virtual space, and an end address of the second virtual space.
  • the mapping relationship between the first virtual space and the second virtual space may also be determined by recording offsets of respective addresses in the first virtual space and respective addresses in the corresponding second virtual space.
  • step 140 may include: determining a starting address of the second virtual space according to a starting address of the first virtual space and a mapping relationship; determining and determining in a page table of the process The page directory entry corresponding to the start address of the second virtual space; the base address of the file page table is recorded in the page directory entry.
  • the virtual memory is based on the MMU mapping mechanism to implement virtual address to memory physical address translation, and the implementation of the MMU mapping mechanism needs to utilize the process's page table.
  • a virtual address in the virtual space of a process corresponds to a page directory entry of the process page table.
  • the starting address of the second virtual space may be obtained according to the starting address of the first virtual space and the mapping relationship. For example, in the mapping mode shown in FIG. 2, since the first virtual space is parallel mapped to the second virtual space, the starting addresses of the first virtual space and the second virtual space are the same, and the first virtual space and the second virtual space are The same size.
  • the start address of the first virtual space is different from the start address of the second virtual space, and the difference between the two is different. Is the position offset. Therefore, in the mapping mode shown in FIG. 3, the starting address of the second virtual space can be obtained according to the starting address of the first virtual space and the position offset.
  • the corresponding page directory entry can be found from the process page table based on the starting address of the second virtual space.
  • a page directory entry can store a pointer to an address that points to the base address of the file page table, thereby linking the file page table to the process page table.
  • the process implements access to the file by operating the starting address of the second virtual space. Specifically, when the process accesses the file, the MMU first finds a page directory entry corresponding to the start address of the second virtual space, and the MMU uses the file page table because the base address of the file page table of the file is recorded in the page directory entry. Mapping the virtual address in the first virtual space to the physical address in the first physical space.
  • a mapping relationship between the first virtual space that is virtualized according to the first physical space of the storage file and the second virtual space in the process is established, and the file is based on the mapping relationship.
  • the file page table is linked into the page table of the process, and the file page table records the mapping relationship between the virtual address in the first virtual space and the physical address in the first physical space, so that the file page table can be linked
  • the page table of the post process implements access to the file by the process. Compared with the traditional way of accessing files by BIO, the process of copying data blocks from disk to memory is reduced, and the file access efficiency is improved.
  • the access request of the above file may be a read request or a write request.
  • the access request is a read request, or the access request is a write request, but the purpose of the write request is to utilize
  • the file page table of the second virtual space and the file can remain unchanged.
  • the access request is a write request
  • the access request carries the data to be written and the start address of the access request
  • the step 150 may include: determining that the access table is not available according to the page table of the process linked to the file page table The physical address corresponding to the start address; assign a new physical address to the file in memory; write the data to be written to the new physical address.
  • the start address of the access request is a virtual address in the process virtual space.
  • the address to be written to the data has exceeded the first address.
  • the address range of the virtual space In other words, the data to be written is not an overlay of the original data in the file, but a new data is added to the file.
  • the memory physical space is not pre-allocated for the file, but only data is written in the file. In the process, the memory physical space is allocated for the file according to the size of the data to be written.
  • the first virtual space may be larger than the physical space occupied by the file in the physical space of the memory, so that the second virtual space mapped according to the first virtual space may also be larger than the file in the memory.
  • the first virtual space and the second virtual space may be larger than the size of the file. In this case, if the file needs to be newly written, if the process page table linked to the file page table is queried according to the start address of the access request, the start address of the access request may not be found. Corresponding physical address.
  • the MMU will cause a page fault interrupt, requesting the operating system kernel to allocate the physical address of the memory for the process accessing the file.
  • the operating system kernel can allocate physical pages for the file from the free physical pages of memory according to the page fault interrupt request.
  • the method of FIG. 1 may further include: adding a new virtual address to the first virtual space, and establishing a new virtual address and a new one in the file page table.
  • the mapping between physical addresses Since the first virtual space is a virtual space mapped according to a physical space of a file stored in the memory, when a new physical address is allocated to the file in the memory, a new virtual space may be added according to the newly allocated physical address. Virtual address to Expand the first virtual space.
  • the apparatus 400 for accessing a file includes:
  • the receiving module 410 is configured to receive an access request for accessing the file, where the access request carries an identifier of the file to be accessed, and the file is any file in the file system, and data of all files in the file system is stored in the memory, and the memory is non-volatile storage. Media, the file is stored in the first physical space of the memory;
  • the obtaining module 420 is configured to obtain information about the first virtual space from the metadata of the file according to the identifier of the file, where the first virtual space is a virtual continuous address space according to the first physical space of the memory;
  • the establishing module 430 is configured to establish a mapping relationship between the first virtual space and the second virtual space of the process of accessing the file, where the second virtual space is a continuous address space in the virtual space of the process;
  • the link-in module 440 is configured to link the file page table of the file into the page table of the process according to the mapping relationship, where the file page table is used to map the virtual address in the first virtual space to the physical address in the first physical space. ;
  • the access module 450 is configured to access the physical address of the file in the memory according to the page table of the process linked to the file page table.
  • a mapping relationship between the first virtual space that is virtualized according to the first physical space of the storage file and the second virtual space in the process is established, and the file is based on the mapping relationship.
  • the file page table is linked into the page table of the process, and the file page table records the mapping relationship between the virtual address in the first virtual space and the physical address in the first physical space, so that the file page table can be linked
  • the page table of the post process implements access to the file by the process. Compared with the traditional way of accessing files by BIO, the process of copying data blocks from disk to memory is reduced, and the file access efficiency is improved.
  • the link-in module 440 is specifically configured to: determine, according to a starting address and a mapping relationship of the first virtual space, a starting address of the second virtual space; in a page table of the process A page directory entry corresponding to a start address of the second virtual space is determined; a base address of the file page table is recorded in the page directory entry.
  • the establishing module 430 is specifically configured to record a location offset of an address of the first virtual space and an address of the second virtual space.
  • the location offset of the address of the first virtual space and the address of the second virtual space may be zero.
  • the apparatus 400 may further include: a virtual module, configured to virtualize the first virtual space according to the first physical space of the memory.
  • the access request is a write request, where the access request carries the data to be written and the start address of the access request
  • the access module 450 may be specifically configured to: determine, according to the process after the file page table is linked The page table cannot obtain the physical address corresponding to the start address of the access request; assign a new physical address to the file in memory; and write the data to be written into the new physical address.
  • the apparatus 400 may further include: an adding module, configured to add a new virtual address to the first virtual space; the establishing module 430 is further configured to establish a new virtual address and a new one in the file page table. The mapping between physical addresses.
  • apparatus 400 for accessing the file of FIG. 4 can implement the various steps in FIG. 1.
  • each module reference may be made to the description of the foregoing method embodiments. To avoid repetition, details are not described herein again.
  • FIG. 5 is a schematic block diagram of a storage device according to an embodiment of the present invention. It should be understood that the storage device 500 of FIG. 5 can implement the various steps in FIG. 1. To avoid repetition, details are not described herein again.
  • the storage device 500 can include:
  • the memory 510 is configured to store a program.
  • memory 510 may include high speed RAM memory and may also include non-volatile memory, such as at least one disk memory.
  • the program can include program code, the program code including computer operating instructions.
  • the processor 520 is configured to execute a program, and when the program is executed, the processor 520 is configured to:
  • the access request carries an identifier of the file to be accessed, the file is an arbitrary file in the file system, and data of all files in the file system is stored in the memory, the memory is a non-volatile storage medium, and the file is stored in the memory In the first physical space;
  • the file page table of the file is linked into the page table of the process, wherein the file page table is used to map the virtual address in the first virtual space to the physical address in the first physical space;
  • the physical address of the file in memory is accessed according to the page table of the process that is linked into the file page table.
  • the processor 520 may be a CPU, an ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention.
  • ASIC Application Specific Integrated Circuit
  • a mapping relationship between the first virtual space that is virtualized according to the first physical space of the storage file and the second virtual space in the process is established, and the file is based on the mapping relationship.
  • the file page table is linked into the page table of the process, and the file page table records the mapping relationship between the virtual address in the first virtual space and the physical address in the first physical space, so that the file page table can be linked
  • the page table of the post process implements access to the file by the process. Compared with the traditional way of accessing files by BIO, the process of copying data blocks from disk to memory is reduced, and the file access efficiency is improved.
  • the processor 520 is specifically configured to determine a starting address of the second virtual space according to a starting address and a mapping relationship of the first virtual space, and determine a second virtual space in a page table of the process.
  • the page directory entry corresponding to the start address; the base address of the file page table is recorded in the page directory entry.
  • the processor 520 is specifically configured to record a location offset of an address of the first virtual space and an address of the second virtual space.
  • the location offset of the address of the first virtual space and the address of the second virtual space is 0.
  • the processor 520 is further configured to virtualize the first virtual space according to the first physical space of the memory.
  • the access request is a write request, where the access request carries a data to be written and a start address of the access request, and the processor 520 is specifically configured to determine, according to the link file page table.
  • the page table of the subsequent process cannot obtain the physical address corresponding to the start address of the access request; assign a new physical address to the file in the memory; write the to-be-written data to the new physics In the address.
  • the processor 520 is further configured to add to the first virtual space. a new virtual address; establishing a mapping relationship between the new virtual address and the new physical address in the file page table.
  • the term "and/or” is merely an association relationship describing an associated object, indicating that there may be three relationships.
  • a and/or B may indicate that A exists separately, and A and B exist simultaneously, and B cases exist alone.
  • the character "/" in this article generally indicates that the contextual object is an "or" relationship.
  • the disclosed systems, devices, and methods may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • there may be another division manner for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, or an electrical, mechanical or other form of connection.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the embodiments of the present invention.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
  • the integrated unit if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium.
  • the technical solution of the present invention contributes in essence or to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium.
  • a number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like. .
  • ROM read-only memory
  • RAM random access memory
  • magnetic disk or an optical disk, and the like.

Landscapes

  • Memory System Of A Hierarchy Structure (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Disclosed are a file access method and apparatus. The method is applied to a storage device in which a file system is established in a memory, and the memory is a non-volatile memory (NVM). The method comprises: receiving an access request for accessing a file, the file being stored in a first physical space of the memory; acquiring information of a first virtual space from metadata of the file, the first virtual space being a consecutive address space virtualized according to the first physical space of the memory; establishing a mapping relationship between the first virtual space and a second virtual space of a process for accessing the file; linking a file page table of the file to a page table of the process according to the mapping relationship; and accessing a physical address of the file in the memory according to the page table to which the file page table is linked. Compared with a conventional file access mode of BIO, the solution of embodiments of the present invention omits the process of copying data blocks to the memory from a disk, thereby improving the file access efficiency.

Description

访问文件的方法和装置Method and device for accessing files 技术领域Technical field
本发明涉及计算机领域,并且更具体地,涉及一种访问文件的方法和装置。The present invention relates to the field of computers and, more particularly, to a method and apparatus for accessing files.
背景技术Background technique
现有技术中,受到磁盘访问能力的限制,中央处理器(Central Processing Unit,CPU)直接从磁盘读取数据和存储数据的速度较慢,因此,CPU需要通过内存对磁盘中的数据进行访问。In the prior art, the central processing unit (CPU) reads data and stores data directly from the disk at a slow speed due to the limitation of the disk access capability. Therefore, the CPU needs to access the data in the disk through the memory.
在文件***中,CPU通过BIO(Block Input Output,块输入输出)的方式访问磁盘中的文件。具体而言,当需要从磁盘中读取文件时,CPU需要先将待读取文件的数据以块为单位从磁盘拷贝到内存中,再从内存中读取数据。当需要向磁盘中的文件写入数据时,CPU需要先将接收的数据写入内存,再将内存中的数据以块为单位写入磁盘中。In the file system, the CPU accesses the files on the disk by means of BIO (Block Input Output). Specifically, when a file needs to be read from a disk, the CPU needs to first copy the data of the file to be read from the disk into the memory in units of blocks, and then read the data from the memory. When you need to write data to a file on the disk, the CPU needs to write the received data to the memory first, and then write the data in the memory to the disk in block units.
随着NVM(non-volatile memory,非易失存储)技术的发展,下一代NVM,如PCM(Phase Change Memory,相变内存)、ReRAM(Resistive Random Access Memory,电阻式随机存取存储器)或MRAM(Magnetic RAM,磁性随机存取存储器)等,存取速度和访问能力具有很大程度的提升,使得NVM作为内存,由CPU直接访问成为可能。With the development of NVM (non-volatile memory) technology, next-generation NVM, such as PCM (Phase Change Memory), ReRAM (Resistive Random Access Memory) or MRAM (Magnetic RAM, magnetic random access memory), etc., access speed and accessibility have been greatly improved, making NVM as a memory, directly accessible by the CPU.
如上所述,现有技术中,CPU对文件***的访问采用传统的BIO方式进行,需要内存作为文件访问的桥梁。当下一代NVM介质作为内存时,由于NVM介质的非易失性,文件***中的文件可以长久存储在内存中,并由CPU直接访问,如果仍沿用传统的BIO方式对文件进行访问,势必会导致文件***访问效率低下。As described above, in the prior art, the CPU accesses the file system in a traditional BIO manner, and requires memory as a bridge for file access. When the next generation of NVM media is used as memory, due to the non-volatility of NVM media, files in the file system can be stored in memory for a long time and directly accessed by the CPU. If the file is accessed using the traditional BIO method, it is bound to be Causes file system access to be inefficient.
发明内容Summary of the invention
本发明实施例提供一种访问文件的方法和装置,以提高文件的访问效率。Embodiments of the present invention provide a method and apparatus for accessing a file to improve file access efficiency.
第一方面,提供一种访问文件的方法,所述方法应用于在内存中建立文件***的存储设备,其中,所述内存是非易失性存储器NVM,包括:接收 访问文件的访问请求,所述访问请求中携带有待访问文件的标识,所述文件***中所有文件的数据存储于内存中,所述内存是非易失性存储介质,所述文件存储在所述内存的第一物理空间中;根据所述文件的标识从所述文件的元数据中获取第一虚拟空间的信息,所述第一虚拟空间为根据所述内存的第一物理空间虚拟的连续的地址空间;建立所述第一虚拟空间和访问所述文件的进程的第二虚拟空间之间的映射关系,其中,所述第二虚拟空间为所述进程的虚拟空间中的一段连续的地址空间;根据所述映射关系,将所述文件的文件页表链入所述进程的页表中,其中,所述文件页表用于将所述第一虚拟空间中的虚拟地址映射至所述第一物理空间中的物理地址;根据链入所述文件页表后的进程的页表访问所述文件在所述内存中的物理地址。In a first aspect, a method of accessing a file is provided, the method being applied to a storage device that establishes a file system in a memory, wherein the memory is a non-volatile memory NVM, including: receiving An access request for accessing a file, where the access request carries an identifier of a file to be accessed, data of all files in the file system is stored in a memory, the memory is a non-volatile storage medium, and the file is stored in the memory Obtaining information of the first virtual space from the metadata of the file according to the identifier of the file, where the first virtual space is a virtual consecutive address according to the first physical space of the memory a mapping relationship between the first virtual space and a second virtual space of a process of accessing the file, wherein the second virtual space is a contiguous address space in a virtual space of the process; Linking a file page table of the file into a page table of the process according to the mapping relationship, wherein the file page table is configured to map a virtual address in the first virtual space to the first physics a physical address in the space; accessing the physical address of the file in the memory according to a page table of a process linked to the file page table.
结合第一方面,在第一方面的一种实现方式中,所述根据所述映射关系,将所述文件的文件页表链入所述进程的页表中,包括:根据所述第一虚拟空间的起始地址以及所述映射关系,确定所述第二虚拟空间的起始地址;在所述进程的页表中确定与所述第二虚拟空间的起始地址对应的页目录项;在所述页目录项中记录所述文件页表的基地址。With the first aspect, in an implementation manner of the first aspect, the linking, by the mapping, the file page table of the file into the page table of the process, according to the first virtual space Determining a starting address of the second virtual space; determining a page directory entry corresponding to a starting address of the second virtual space in a page table of the process; The base address of the file page table is recorded in the page directory entry.
结合第一方面或其上述实现方式的任一种,在第一方面的另一种实现方式中,所述建立所述第一虚拟空间和访问所述文件的进程的第二虚拟空间之间的映射关系,包括:记录所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量。In conjunction with the first aspect, or any one of the foregoing implementation manners, in another implementation manner of the first aspect, the establishing the first virtual space and the second virtual space of the process of accessing the file The mapping relationship includes: recording a location offset of an address of the first virtual space and an address of the second virtual space.
结合第一方面或其上述实现方式的任一种,在第一方面的另一种实现方式中,所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量为0。In conjunction with the first aspect, or any one of the foregoing implementation manners, in another implementation manner of the first aspect, the location offset of the address of the first virtual space and the address of the second virtual space is 0. .
结合第一方面或其上述实现方式的任一种,在第一方面的另一种实现方式中,还包括:根据所述内存的第一物理空间虚拟所述第一虚拟空间。In conjunction with the first aspect, or any one of the foregoing implementation manners, in another implementation manner of the first aspect, the method further includes: virtualizing the first virtual space according to the first physical space of the memory.
结合第一方面或其上述实现方式的任一种,在第一方面的另一种实现方式中,所述访问请求为写请求,所述访问请求中携带有待写入数据以及所述访问请求的起始地址,所述根据链入所述文件页表后的进程的页表访问所述文件在所述内存中的物理地址,包括:确定根据链入所述文件页表后的进程的页表无法获得所述访问请求的起始地址对应的物理地址;在所述内存中为所述文件分配新的物理地址;将所述待写入数据写入所述新的物理地址中。In conjunction with the first aspect, or any one of the foregoing implementation manners, in another implementation manner of the first aspect, the access request is a write request, where the access request carries data to be written and the access request a starting address, the accessing the physical address of the file in the memory according to a page table of a process linked to the file page table, comprising: determining a page table according to a process after linking the file page table The physical address corresponding to the start address of the access request cannot be obtained; a new physical address is allocated to the file in the memory; and the to-be-written data is written into the new physical address.
结合第一方面或其上述实现方式的任一种,在第一方面的另一种实现方 式中,所述在所述内存中为所述文件分配新的物理地址之后,所述方法还包括:向所述第一虚拟空间添加新的虚拟地址,并在所述文件页表中建立所述新的虚拟地址和所述新的物理地址之间的映射关系。In combination with the first aspect or any of the above implementations, another implementation in the first aspect Wherein after the new physical address is allocated to the file in the memory, the method further comprises: adding a new virtual address to the first virtual space, and establishing a location in the file page table A mapping relationship between the new virtual address and the new physical address.
第二方面,提供一种访问文件的装置,包括:接收模块,用于接收访问文件的访问请求,所述访问请求中携带有待访问文件的标识,所述文件为文件***中的任意文件,所述文件***中所有文件的数据存储于内存中,所述内存是非易失性存储介质,所述文件存储在所述内存的第一物理空间中;获取模块,用于根据所述文件的标识从所述文件的元数据中获取第一虚拟空间的信息,所述第一虚拟空间为根据所述内存的第一物理空间虚拟的连续的地址空间;建立模块,用于建立所述第一虚拟空间和访问所述文件的进程的第二虚拟空间之间的映射关系,其中,所述第二虚拟空间为所述进程的虚拟空间中的一段连续的地址空间;链入模块,用于根据所述映射关系,将所述文件的文件页表链入所述进程的页表中,其中,所述文件页表用于将所述第一虚拟空间中的虚拟地址映射至所述第一物理空间中的物理地址;访问模块,用于根据链入所述文件页表后的进程的页表访问所述文件在所述内存中的物理地址。The second aspect provides an apparatus for accessing a file, including: a receiving module, configured to receive an access request for accessing a file, where the access request carries an identifier of a file to be accessed, where the file is an arbitrary file in the file system. The data of all files in the file system is stored in a memory, the memory is a non-volatile storage medium, the file is stored in a first physical space of the memory, and an acquiring module is configured to: according to the identifier of the file Acquiring information of the first virtual space in the metadata of the file, where the first virtual space is a virtual continuous address space according to the first physical space of the memory; and an establishing module, configured to establish the first virtual space And a mapping relationship between the second virtual space of the process of accessing the file, wherein the second virtual space is a contiguous address space in the virtual space of the process; the linking module is configured to Mapping a file page table of the file into a page table of the process, wherein the file page table is used in the first virtual space Mapping a virtual address to a physical address of the first physical space; access module, the physical address for a page table memory in accordance with the process of accessing the file into the document after the page chain table.
结合第二方面,在第二方面的一种实现方式中,所述链入模块具体用于:根据所述第一虚拟空间的起始地址以及所述映射关系,确定所述第二虚拟空间的起始地址;在所述进程的页表中确定与所述第二虚拟空间的起始地址对应的页目录项;在所述页目录项中记录所述文件页表的基地址。With reference to the second aspect, in an implementation manner of the second aspect, the linking module is specifically configured to: determine, according to a starting address of the first virtual space, and the mapping relationship, the second virtual space a start address; a page directory entry corresponding to a start address of the second virtual space is determined in a page table of the process; a base address of the file page table is recorded in the page directory entry.
结合第二方面或其上述实现方式的任一种,在第二方面的另一种实现方式中,所述建立模块具体用于记录所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量。With reference to the second aspect, or any one of the foregoing implementation manners, in another implementation manner of the second aspect, the establishing module is specifically configured to record an address of the first virtual space and the second virtual space The position offset of the address.
结合第二方面或其上述实现方式的任一种,在第二方面的另一种实现方式中,所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量为0。In conjunction with the second aspect, or any one of the foregoing implementation manners, in another implementation manner of the second aspect, the location offset of the address of the first virtual space and the address of the second virtual space is 0. .
结合第二方面或其上述实现方式的任一种,在第二方面的另一种实现方式中,所述装置还包括:虚拟模块,用于根据所述内存的第一物理空间虚拟所述第一虚拟空间。In conjunction with the second aspect, or any one of the foregoing implementation manners, in another implementation manner of the second aspect, the device further includes: a virtual module, configured to virtualize the first physical space according to the memory A virtual space.
结合第二方面或其上述实现方式的任一种,在第二方面的另一种实现方式中,所述访问请求为写请求,所述访问请求中携带有待写入数据以及所述 访问请求的起始地址,所述访问模块具体用于:确定根据链入所述文件页表后的进程的页表无法获得所述访问请求的起始地址对应的物理地址;在所述内存中为所述文件分配新的物理地址;将所述待写入数据写入所述新的物理地址中。With reference to the second aspect, or any one of the foregoing implementation manners, in another implementation manner of the second aspect, the access request is a write request, where the access request carries data to be written and the Accessing the start address of the request, the access module is specifically configured to: determine that the physical address corresponding to the start address of the access request cannot be obtained according to the page table of the process linked to the file page table; in the memory Assigning a new physical address to the file; writing the data to be written to the new physical address.
结合第二方面或其上述实现方式的任一种,在第二方面的另一种实现方式中,还包括:添加模块,用于向所述第一虚拟空间添加新的虚拟地址;所述建立模块还用于在所述文件页表中建立所述新的虚拟地址和所述新的物理地址之间的映射关系。In conjunction with the second aspect, or any one of the foregoing implementation manners, in another implementation manner of the second aspect, the method further includes: adding a module, configured to add a new virtual address to the first virtual space; The module is further configured to establish a mapping relationship between the new virtual address and the new physical address in the file page table.
本发明实施例中,当进程访问文件时,建立根据存储文件的第一物理空间虚拟的第一虚拟空间和进程中的第二虚拟空间之间的映射关系,并基于该映射关系将该文件的文件页表链入该进程的页表中,由于该文件页表记录有第一虚拟空间中的虚拟地址和第一物理空间中的物理地址之间的映射关系,从而可以通过链入该文件页表后的进程的页表实现进程对文件的访问。这与传统的BIO访问文件的方式相比,少了从磁盘向内存中拷贝数据块的过程,提高了文件访问效率。In the embodiment of the present invention, when a process accesses a file, a mapping relationship between the first virtual space that is virtualized according to the first physical space of the storage file and the second virtual space in the process is established, and the file is based on the mapping relationship. The file page table is linked into the page table of the process, and the file page table records the mapping relationship between the virtual address in the first virtual space and the physical address in the first physical space, so that the file page table can be linked The page table of the post process implements access to the file by the process. Compared with the traditional way of accessing files by BIO, the process of copying data blocks from disk to memory is reduced, and the file access efficiency is improved.
附图说明DRAWINGS
为了更清楚地说明本发明实施例的技术方案,下面将对本发明实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings to be used in the embodiments of the present invention will be briefly described below. It is obvious that the drawings in the following description are only attached to some embodiments of the present invention. Figure.
图1是本发明实施例的访问文件的方法的示意性流程图。FIG. 1 is a schematic flowchart of a method for accessing a file according to an embodiment of the present invention.
图2是第一虚拟空间和第二虚拟空间映射关系的一个示例图。2 is an exemplary diagram of a mapping relationship between a first virtual space and a second virtual space.
图3是第一虚拟空间和第二虚拟空间映射关系的另一个示例图。FIG. 3 is another exemplary diagram of a mapping relationship between a first virtual space and a second virtual space.
图4是本发明实施例的访问文件的装置的示意性框图。4 is a schematic block diagram of an apparatus for accessing a file according to an embodiment of the present invention.
图5是本发明实施例的访问文件的装置的示意性框图。FIG. 5 is a schematic block diagram of an apparatus for accessing a file according to an embodiment of the present invention.
具体实施方式detailed description
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明的一部分实施例,而不是全部实施例。The technical solutions in the embodiments of the present invention are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present invention. It is obvious that the described embodiments are a part of the embodiments of the present invention, but not all embodiments.
为了更好的描述本发明实施例,先简单介绍一下虚拟存储器(virtual  memory)的概念。众所周知,程序要放到内存中运行。但随着程序规模的不断增大,内存容量很难容纳一个完整的程序,虚拟存储器的概念应运而生。虚拟存储器的基本思想是程序,数据,堆栈的总的大小可以超过物理存储器的大小,操作***把当前使用的部分保留在内存中,而把其他未被使用的部分保存在磁盘上。比如对一个16MB的程序和一个内存只有4MB的机器,操作***通过选择,可以决定各个时刻将哪4M的内容保留在内存中,并在需要时在内存和磁盘间交换程序片段,这样就可以把这个16M的程序运行在一个只具有4M内存的机器上了。In order to better describe the embodiment of the present invention, a brief introduction to virtual memory (virtual) Memory) concept. As we all know, the program should be put into memory to run. However, as the size of the program continues to increase, it is difficult to accommodate a complete program in memory capacity, and the concept of virtual memory has emerged. The basic idea of virtual memory is that the total size of the program, data, and stack can exceed the size of the physical memory. The operating system keeps the currently used part in memory and saves other unused parts on the disk. For example, for a 16MB program and a machine with only 4MB of memory, the operating system can choose which 4M content to keep in memory at each moment, and exchange program fragments between memory and disk when needed, so that This 16M program runs on a machine with only 4M of RAM.
本领域人员可以知道,在计算机***中,虚拟地址空间是进程能够访问的一段虚拟地址范围。虚拟地址空间的大小通常是由计算机的指令集体系结构(instruction set architecture)来确定的。例如,一个32位的中央处理器(Central Processing Unit,CPU),提供的虚拟地址空间为0~0xFFFFFFFF(4G),。虚拟地址空间中的某一个地址我们称之为虚拟地址。与虚拟地址空间和虚拟地址相对应的则是物理地址空间和物理地址。物理地址空间是指内存的物理地址范围。物理地址空间中的某一个地址我们称之为物理地址。通常,物理地址空间小于虚拟地址空间,物理地址空间可以映射到虚拟地址空间中。例如,对于一台内存为256M的32bit x86主机来说,它的虚拟地址空间范围是0~0xFFFFFFFF(4G),而物理地址空间范围是0x000000000~0x0FFFFFFF(256M)。Those skilled in the art will appreciate that in a computer system, a virtual address space is a range of virtual addresses that a process can access. The size of the virtual address space is typically determined by the computer's instruction set architecture. For example, a 32-bit Central Processing Unit (CPU) provides a virtual address space of 0 to 0xFFFFFFFF (4G). One of the addresses in the virtual address space is called a virtual address. Corresponding to the virtual address space and virtual address are the physical address space and the physical address. The physical address space refers to the physical address range of the memory. One of the addresses in the physical address space is called a physical address. Generally, the physical address space is smaller than the virtual address space, and the physical address space can be mapped into the virtual address space. For example, for a 32-bit x86 host with 256M of memory, its virtual address space ranges from 0 to 0xFFFFFFFF (4G), while the physical address space ranges from 0x000000000 to 0x0FFFFFFF (256M).
现有技术中,大多数机器均使用虚拟存储器,虚拟地址(或称线性地址)不是被直接送到内存地址总线上,而是送到MMU(Memory Management Unit,内存管理单元)中,从而把虚拟地址映射为物理地址。也就是说,MMU用于实现程序的虚拟地址到内存的物理地址的映射。In the prior art, most machines use virtual memory, and the virtual address (or linear address) is not directly sent to the memory address bus, but is sent to the MMU (Memory Management Unit), thereby virtualizing The address is mapped to a physical address. That is, the MMU is used to map the virtual address of the program to the physical address of the memory.
为了实现程序的虚拟地址到内存的物理地址的映射,MMU引入分页(paging)机制。具体地,在分页中,为了效率起见,虚拟地址空间以页(page)为单位被划分,可以将虚拟地址空间中的页称为虚拟页,而相应的物理地址空间也以页为单位被划分,可以将物理地址空间的页称为物理页(或称物理页框),其中,虚拟页和物理页的大小相同。In order to map the virtual address of the program to the physical address of the memory, the MMU introduces a paging mechanism. Specifically, in paging, for efficiency, the virtual address space is divided in units of pages, and pages in the virtual address space may be referred to as virtual pages, and corresponding physical address spaces are also divided in units of pages. A page of a physical address space can be referred to as a physical page (or a physical page frame), where the virtual page and the physical page are the same size.
在引入页这个概念的基础上,MMU采用多级页表的形式实现虚拟地址到物理地址的索引。具体而言,一个虚拟地址,大小4个字节(32bit),包含找到物理地址的信息,分为3个部分: Based on the concept of introducing a page, the MMU implements an index of a virtual address to a physical address in the form of a multi-level page table. Specifically, a virtual address, size 4 bytes (32 bits), contains information to find the physical address, divided into three parts:
第22位到第31位这10位(最高10位)是页目录中的索引;The 10th (up to 10th) from the 22nd to the 31st is the index in the page directory;
第12位到第21位这10位是页表中的索引;The 12th to the 21st bits are the indexes in the page table;
第0位到第11位这12位(低12位)是页内偏移。The 12th bit to the 11th bit (lower 12 bits) is an in-page offset.
对于一个要转换成物理地址的虚拟地址,CPU首先根据控制寄存器CR3中的值,找到页目录所在的物理页。然后根据虚拟地址的第22位到第31位这10位(最高的10bit)的值作为索引,找到相应的PDE(page directory entry,页目录项),PDE中有这个虚拟地址所对应页表的物理地址。有了页表的物理地址,根据虚拟地址的第12位到第21位这10位的值作为索引,找到该页表中相应的PTE(page table entry,页表项)。页表项中就有这个虚拟地址所对应物理页的物理地址。最后用虚拟地址的最低12位,也就是页内偏移,加上这个物理页的物理地址,就得到了该虚拟地址所对应的物理地址。For a virtual address to be converted to a physical address, the CPU first finds the physical page where the page directory is located based on the value in control register CR3. Then, according to the value of the 10th (the highest 10bit) of the 22nd to the 31st of the virtual address as the index, the corresponding PDE (page directory entry) is found, and the PDE has the page table corresponding to the virtual address. Physical address. With the physical address of the page table, according to the values of the 10th to the 21st bits of the virtual address as the index, the corresponding PTE (page table entry) in the page table is found. The physical address of the physical page corresponding to this virtual address is in the page table entry. Finally, the lowest 12 bits of the virtual address, that is, the intra-page offset, plus the physical address of the physical page, the physical address corresponding to the virtual address is obtained.
一个页目录有1024项,虚拟地址最高的10bit刚好可以索引1024项(2的10次方等于1024)。一个页表也有1024项,虚拟地址中间部分的10bit,刚好索引1024项。虚拟地址最低的12bit(2的12次方等于4096),作为页内偏移,刚好可以索引4KB,也就是一个物理页中的每个字节。A page directory has 1024 entries, and the highest virtual address of 10 bits can just index 1024 entries (2 to 10 powers equals 1024). A page table also has 1024 entries, 10 bits in the middle of the virtual address, just 1024 entries. The lowest 12-bit virtual address (2 to the 12th power equals 4096), as an intra-page offset, can just index 4KB, which is each byte in a physical page.
一个虚拟地址转换成物理地址的计算过程就是,处理器通过CR3找到当前页目录所在物理页,取虚拟地址的高10bit,然后把这10bit左移2bit(因为每个页目录项4个字节长,左移2bit相当于乘4)得到在该页中的地址,取出该地址处的PDE(4个字节),就找到了该虚拟地址对应页表所在物理页,取虚拟地址第12位到第21位这10位,然后把这10bit左移2bit(因为每个页表项4个字节长,左移2bit相当于乘4)得到在该页中的地址,取出该地址处的PTE(4个字节),就找到了该虚拟地址对应物理页的地址,最后加上12bit的页内偏移得到了物理地址。The calculation process of converting a virtual address into a physical address means that the processor finds the physical page of the current page directory through CR3, takes the upper 10 bits of the virtual address, and then shifts the 10 bit to the left by 2 bits (because each page directory entry is 4 bytes long). , shifting 2 bits to the left is equivalent to multiplying 4) to get the address in the page, and taking out the PDE (4 bytes) at the address, and finding the physical page of the page table corresponding to the virtual address, taking the 12th bit of the virtual address to The 21st bit of the 21st bit, then shift the 10 bit to the left by 2 bits (because each page table entry is 4 bytes long, 2 bits left shift is equivalent to multiplying 4) to get the address in the page, and take out the PTE at the address ( 4 bytes), the address of the physical page corresponding to the virtual address is found, and finally the 12-bit in-page offset is obtained to obtain the physical address.
一个32bit的指针,可以寻址范围0x00000000-0xFFFFFFFF,4GB大小。也就是说一个32bit的指针可以寻址整个4GB地址空间的每一个字节。一个页表项负责4K的地址空间和物理内存的映射,一个页表1024项,也就是负责1024*4k=4M的地址空间的映射。一个页目录项,对应一个页表。一个页目录有1024项,也就对应着1024个页表,每个页表负责4M地址空间的映射。1024个页表负责1024*4M=4G的地址空间映射。一个进程有一个页目录。所以以页为单位,页目录和页表可以保证4G的地址空间中的每页和物理内存的映射。 A 32-bit pointer that can address a range of 0x00000000-0xFFFFFFFF, 4GB. This means that a 32-bit pointer can address every byte of the entire 4GB address space. A page table entry is responsible for mapping the 4K address space and physical memory, and a page table of 1024 entries, that is, the mapping of the address space responsible for 1024*4k=4M. A page directory entry that corresponds to a page table. A page directory has 1024 entries, which corresponds to 1024 page tables. Each page table is responsible for mapping the 4M address space. 1024 page tables are responsible for address space mapping of 1024*4M=4G. A process has a page directory. So in page units, page directories and page tables can guarantee the mapping of each page and physical memory in the 4G address space.
每个进程都有自己的4G地址空间,从0x00000000-0xFFFFFFFF。通过每个进程自己的一套页目录和页表来实现。由于每个进程有自己的页目录和页表,所以每个进程的地址空间映射的物理内存是不一样的。两个进程的同一个虚拟地址处(如果都有物理内存映射)的值一般是不同的,因为他们往往对应不同的物理页。Each process has its own 4G address space, from 0x00000000-0xFFFFFFFF. This is achieved by each process's own set of page directories and page tables. Since each process has its own page directory and page table, the physical memory of each process's address space map is different. The values of the same virtual address of both processes (if there is a physical memory map) are generally different because they tend to correspond to different physical pages.
以上详细描述了MMU从程序的虚拟地址到内存的物理地址的映射过程。在本发明实施例中,采用NVM介质作为内存,利用基于paging的MMU,实现程序对文件的直接访问。The mapping process of the MMU from the virtual address of the program to the physical address of the memory is described in detail above. In the embodiment of the present invention, the NVM medium is used as the memory, and the paging-based MMU is used to implement direct access of the program to the file.
下面结合图1,详细描述本发明实施例的访问文件的方法。需要说明的是,本发明实施例涉及基于内存的文件***。在本发明实施例中,内存中存储有文件***和文件。本领域技术人员可以知道,文件***是操作***中负责管理和存储文件信息的软件结构。从***角度来看,文件***是对文件存储设备的空间进行组织和分配,负责文件存储并对存入的文件进行保护和检索的***。文件***由三部分组成:文件***的接口、对文件操纵和管理的软件集合、文件数据和属性。文件***的中心概念是超级块(superblock)、i节点(inode)、数据块(data block)、目录块(directory block)和间接块(indirection block)。超级块包括文件***的总体信息,比如文件***的大小。inode中包括除了文件名以外的一个文件的所有信息。文件名与inode数目一起存在目录块中,目录条目包括文件名和文件的inode数目。i节点中只有少量数据块数的空间,如果需要更多,会动态分配指向数据块的指针空间,这些动态分配的块是间接块。在本发明实施例中,内存中还可以存储文件的数据和元数据。需要说明的是,在本发明实施例中,内存为非易失性存储器NVM。The method for accessing a file according to an embodiment of the present invention is described in detail below with reference to FIG. It should be noted that the embodiments of the present invention relate to a memory-based file system. In the embodiment of the present invention, a file system and a file are stored in the memory. Those skilled in the art will appreciate that a file system is a software structure in the operating system that is responsible for managing and storing file information. From a system perspective, a file system is a system that organizes and allocates space for file storage devices, is responsible for file storage, and protects and retrieves stored files. A file system consists of three parts: an interface to a file system, a collection of software for file manipulation and management, file data, and attributes. The central concept of a file system is a superblock, an inode, a data block, a directory block, and an indirection block. The super block includes general information about the file system, such as the size of the file system. The inode includes all the information of a file other than the file name. The file name is stored in the directory block along with the number of inodes. The directory entry includes the file name and the number of inodes of the file. There is only a small amount of data block space in the i-node. If more is needed, the pointer space pointing to the data block is dynamically allocated. These dynamically allocated blocks are indirect blocks. In the embodiment of the present invention, data and metadata of the file may also be stored in the memory. It should be noted that, in the embodiment of the present invention, the memory is a non-volatile memory NVM.
图1是本发明实施例的访问文件的方法的示意性流程图。图1的方法包括:FIG. 1 is a schematic flowchart of a method for accessing a file according to an embodiment of the present invention. The method of Figure 1 includes:
110、接收访问文件的访问请求,所述访问请求中携带有待访问的文件的标识。可以理解的是,所述文件可以为文件***中的任意一个文件。在本发明实施例中,文件***中所有文件的数据存储于内存中,内存是非易失性存储介质,该文件的数据存储在该内存的第一物理空间中。实际应用中,文件标识可以为文件名。例如,File_1.doc。文件标识为文件***识别文件的唯一标识。 110. Receive an access request for accessing a file, where the access request carries an identifier of a file to be accessed. It can be understood that the file can be any file in the file system. In the embodiment of the present invention, data of all files in the file system is stored in the memory, and the memory is a non-volatile storage medium, and the data of the file is stored in the first physical space of the memory. In practical applications, the file identifier can be a file name. For example, File_1.doc. The file identifier is a unique identifier for the file system identification file.
现有技术中,由于内存无法长久保存数据,将文件***中文件的数据存储在磁盘中,内存作为CPU和磁盘之间的桥梁,实现文件的访问。本发明实施例中的内存采用的是NVM介质,该内存具有非易失性,能够长久存储数据,因此,可以将文件***中的所有文件存储在该内存中,这样就可以省去将磁盘中存储的数据拷贝到内存的过程,CPU可以直接访问存储在内存中的文件数据。In the prior art, since the memory cannot store data for a long time, the data of the file in the file system is stored in the disk, and the memory serves as a bridge between the CPU and the disk to implement file access. The memory in the embodiment of the present invention adopts an NVM medium, and the memory is non-volatile and can store data for a long time. Therefore, all files in the file system can be stored in the memory, so that the disk can be omitted. The process of copying stored data into memory, the CPU can directly access the file data stored in the memory.
120、根据所述文件标识从文件的元数据中获取第一虚拟空间的信息,第一虚拟空间为根据内存的第一物理空间虚拟的连续的地址空间。120. Obtain information of the first virtual space from the metadata of the file according to the file identifier, where the first virtual space is a virtual continuous address space according to the first physical space of the memory.
应理解,文件的数据通常以物理页的形式存储于内存中,在本发明实施例中,第一物理空间是指由存储文件数据的所有物理页组成的物理空间。举例来说,存储文件数据的物理页通常是非连续的,为了方便文件的管理,本发明实施例中将第一物理空间虚拟成一段连续的地址空间,即上述第一虚拟空间,并将该第一虚拟空间的信息存储在文件的元数据中。第一虚拟空间的信息可用于指示第一虚拟空间的地址范围,第一虚拟空间的信息的呈现方式可以有多种,例如,可以存储第一虚拟空间的起始地址和该第一虚拟空间的大小,或者,也可以直接存储第一虚拟地址空间的地址范围。It should be understood that the data of the file is usually stored in the memory in the form of a physical page. In the embodiment of the present invention, the first physical space refers to a physical space composed of all physical pages storing the file data. For example, the physical page storing the file data is usually non-contiguous. In order to facilitate the management of the file, the first physical space is virtualized into a continuous address space, that is, the first virtual space, and the first The information of a virtual space is stored in the metadata of the file. The information of the first virtual space may be used to indicate the address range of the first virtual space, and the information of the first virtual space may be presented in multiple manners, for example, the start address of the first virtual space and the first virtual space may be stored. The size, or, can also directly store the address range of the first virtual address space.
实际应用中,可以在建立文件***的过程中根据第一物理空间虚拟第一虚拟空间,也可以在接收请求后再根据接收的请求将第一物理空间虚拟为第一虚拟空间。在此不对虚拟第一虚拟空间的时间进行限制,也不对第一虚拟空间的虚拟方式进行限制。In the actual application, the first physical space may be virtualized according to the first physical space in the process of establishing the file system, or the first physical space may be virtualized into the first virtual space according to the received request after receiving the request. Here, the time of the virtual first virtual space is not limited, and the virtual mode of the first virtual space is not limited.
130、建立第一虚拟空间和访问文件的进程的第二虚拟空间之间的映射关系,其中,第二虚拟空间为进程的虚拟空间中的一段连续的地址空间。130. Establish a mapping relationship between the first virtual space and a second virtual space of the process of accessing the file, where the second virtual space is a continuous address space in the virtual space of the process.
具体而言,第二虚拟空间可用来表示文件在进程的虚拟空间中所占的地址空间,也就是说,进程需要通过该第二虚拟空间来实现文件的访问。第一虚拟空间和第二虚拟空间之间的映射方式可以是平行映射,也可以是偏移映射。Specifically, the second virtual space can be used to represent the address space occupied by the file in the virtual space of the process, that is, the process needs to access the file through the second virtual space. The mapping manner between the first virtual space and the second virtual space may be a parallel mapping or an offset mapping.
所谓“平行映射”,是指第一虚拟空间和第二虚拟空间的地址范围相同,图2是平行映射的示意图,在图2中,假设文件的数据通过4个物理页存储,该4个物理页组成了上述第一物理空间,且该4个物理页离散分布在内存物理空间中。本发明实施例中,先基于该4个物理页,虚拟出连续的4个虚拟页,这4个虚拟页构成第一虚拟空间,然后通过该文件的文件页表,建立第 一虚拟空间中的虚拟页和第一物理空间中的物理页的映射关系,从而建立了第一虚拟地址空间中的虚拟地址和第一物理空间中的物理地址的映射关系。当进程要访问文件时,将第一虚拟空间平行地映射至进程的虚拟空间中,得到第二虚拟地址空间,从图2可以看出,第一虚拟空间和第二虚拟空间的起始地址和大小均相同。The so-called "parallel mapping" means that the address ranges of the first virtual space and the second virtual space are the same, and FIG. 2 is a schematic diagram of the parallel mapping. In FIG. 2, it is assumed that the data of the file is stored by four physical pages, the four physicals. The page constitutes the first physical space, and the four physical pages are discretely distributed in the physical space of the memory. In the embodiment of the present invention, four consecutive virtual pages are virtualized based on the four physical pages, and the four virtual pages constitute a first virtual space, and then the first page is created by using the file page table of the file. A mapping relationship between a virtual page in a virtual space and a physical page in the first physical space, thereby establishing a mapping relationship between the virtual address in the first virtual address space and the physical address in the first physical space. When the process wants to access the file, the first virtual space is mapped in parallel to the virtual space of the process to obtain a second virtual address space. As can be seen from FIG. 2, the starting address of the first virtual space and the second virtual space are The size is the same.
所谓“偏移映射”,是指第一虚拟空间和第二虚拟空间的地址范围不同,图3是偏移映射的示意图,在图3中,假设文件的数据通过4个物理页存储,该4个物理页组成了上述第一物理空间,且该4个物理页离散分布在内存物理空间中。本发明实施例中,先基于该4个物理页,虚拟出连续的4个虚拟页,这4个虚拟页构成第一虚拟空间。然后通过该文件的文件页表,建立第一虚拟空间中的虚拟页和第一物理空间中的物理页的映射关系,从而建立了第一虚拟地址空间中的虚拟地址和第一物理空间中的物理地址的映射关系。当进程要访问文件时,将第一虚拟空间按照一定的偏移量映射至进程的虚拟空间中,得到第二虚拟地址空间,从图3可以看出,第一虚拟空间和第二虚拟空间的大小相同,但起始地址具有一定的偏移量。The so-called "offset mapping" means that the address ranges of the first virtual space and the second virtual space are different, and FIG. 3 is a schematic diagram of the offset mapping. In FIG. 3, it is assumed that the data of the file is stored by four physical pages. The physical pages constitute the first physical space, and the four physical pages are discretely distributed in the physical space of the memory. In the embodiment of the present invention, four consecutive virtual pages are virtualized based on the four physical pages, and the four virtual pages constitute a first virtual space. Then, by using the file page table of the file, establishing a mapping relationship between the virtual page in the first virtual space and the physical page in the first physical space, thereby establishing a virtual address in the first virtual address space and the first physical space Mapping of physical addresses. When the process wants to access the file, the first virtual space is mapped to the virtual space of the process according to a certain offset to obtain a second virtual address space. As can be seen from FIG. 3, the first virtual space and the second virtual space are The size is the same, but the starting address has a certain offset.
步骤130可包括:记录第一虚拟空间的地址和第二虚拟空间的地址的位置偏移量。可以理解的是,当采用平行映射时,第一虚拟空间的地址和第二虚拟空间的地址的位置偏移量为0;当采用偏移映射时,第一虚拟空间的地址和第二虚拟空间的地址的位置偏移量大于0。Step 130 may include recording a location offset of an address of the first virtual space and an address of the second virtual space. It can be understood that when the parallel mapping is adopted, the address offset of the address of the first virtual space and the address of the second virtual space is 0; when the offset mapping is adopted, the address of the first virtual space and the second virtual space The location offset of the address is greater than zero.
实际应用中,可以记录第一虚拟空间的大小、第一虚拟空间的起始地址和第二虚拟空间的起始地址的偏移量来确定第一虚拟空间和第二虚拟空间的映射关系。还可以记录第一虚拟空间的大小、记录第一虚拟空间的结束地址和第二虚拟空间的结束地址的偏移量来确定第一虚拟空间和第二虚拟空间的映射关系。还可以通过记录第一虚拟空间中的各个地址和对应的第二虚拟空间中的各个地址的偏移量来确定第一虚拟空间和第二虚拟空间的映射关系。In an actual application, the mapping between the size of the first virtual space, the starting address of the first virtual space, and the starting address of the second virtual space may be recorded to determine a mapping relationship between the first virtual space and the second virtual space. The mapping relationship between the first virtual space and the second virtual space may also be determined by recording an offset of the size of the first virtual space, recording an end address of the first virtual space, and an end address of the second virtual space. The mapping relationship between the first virtual space and the second virtual space may also be determined by recording offsets of respective addresses in the first virtual space and respective addresses in the corresponding second virtual space.
140、根据映射关系,将文件的文件页表链入进程的页表中,其中,文件页表用于将第一虚拟空间中的虚拟地址映射至第一物理空间中的物理地址。140. Link the file page table of the file into the page table of the process according to the mapping relationship, wherein the file page table is used to map the virtual address in the first virtual space to the physical address in the first physical space.
可选地,作为一个实施例,步骤140可包括:根据第一虚拟空间的起始地址以及映射关系,确定第二虚拟空间的起始地址;在进程的页表中确定与 第二虚拟空间的起始地址对应的页目录项;在页目录项中记录文件页表的基地址。Optionally, as an embodiment, step 140 may include: determining a starting address of the second virtual space according to a starting address of the first virtual space and a mapping relationship; determining and determining in a page table of the process The page directory entry corresponding to the start address of the second virtual space; the base address of the file page table is recorded in the page directory entry.
应理解,虚拟存储器是基于MMU的映射机制实现虚拟地址到内存的物理地址转换的,而MMU映射机制的实现需要利用进程的页表。实际中,进程的虚拟空间中的一个虚拟地址对应进程页表的一个页目录项。当建立第一虚拟空间和第二虚拟空间之间的映射关系后,就可以根据第一虚拟空间的起始地址以及该映射关系得到第二虚拟空间的起始地址。例如,在图2所示的映射方式下,由于第一虚拟空间平行映射到第二虚拟空间,第一虚拟空间和第二虚拟空间的起始地址相同,且第一虚拟空间和第二虚拟空间的大小相同。在图3所示的偏移映射方式下,虽然第一虚拟空间和第二虚拟空间的大小相同,但第一虚拟空间的起始地址与第二虚拟空间的起始地址不同,两者的差为位置偏移量。因此,在图3所示的映射方式下,可以根据第一虚拟空间的起始地址以及位置偏移量获得第二虚拟空间的起始地址。It should be understood that the virtual memory is based on the MMU mapping mechanism to implement virtual address to memory physical address translation, and the implementation of the MMU mapping mechanism needs to utilize the process's page table. In practice, a virtual address in the virtual space of a process corresponds to a page directory entry of the process page table. After the mapping relationship between the first virtual space and the second virtual space is established, the starting address of the second virtual space may be obtained according to the starting address of the first virtual space and the mapping relationship. For example, in the mapping mode shown in FIG. 2, since the first virtual space is parallel mapped to the second virtual space, the starting addresses of the first virtual space and the second virtual space are the same, and the first virtual space and the second virtual space are The same size. In the offset mapping mode shown in FIG. 3, although the sizes of the first virtual space and the second virtual space are the same, the start address of the first virtual space is different from the start address of the second virtual space, and the difference between the two is different. Is the position offset. Therefore, in the mapping mode shown in FIG. 3, the starting address of the second virtual space can be obtained according to the starting address of the first virtual space and the position offset.
在获得第二虚拟空间的起始地址之后,可以基于该第二虚拟空间的起始地址,从进程页表中找到对应的页目录项。页目录项中可以存储地址的指针,将该指针指向文件页表的基地址,从而将文件页表链入了进程页表。After obtaining the starting address of the second virtual space, the corresponding page directory entry can be found from the process page table based on the starting address of the second virtual space. A page directory entry can store a pointer to an address that points to the base address of the file page table, thereby linking the file page table to the process page table.
150、根据链入文件页表后的进程的页表访问文件在内存中的物理地址。150. Access the physical address of the file in memory according to the page table of the process linked to the file page table.
实际中,进程通过操作第二虚拟空间的起始地址实现对文件的访问。具体地,进程在访问文件时,MMU首先会找到第二虚拟空间起始地址对应的页目录项,由于该页目录项中记录了文件的文件页表的基地址,MMU就利用该文件页表,将第一虚拟空间中的虚拟地址映射至第一物理空间中的物理地址。In practice, the process implements access to the file by operating the starting address of the second virtual space. Specifically, when the process accesses the file, the MMU first finds a page directory entry corresponding to the start address of the second virtual space, and the MMU uses the file page table because the base address of the file page table of the file is recorded in the page directory entry. Mapping the virtual address in the first virtual space to the physical address in the first physical space.
本发明实施例中,当进程访问文件时,建立根据存储文件的第一物理空间虚拟的第一虚拟空间和进程中的第二虚拟空间之间的映射关系,并基于该映射关系将该文件的文件页表链入该进程的页表中,由于该文件页表记录有第一虚拟空间中的虚拟地址和第一物理空间中的物理地址之间的映射关系,从而可以通过链入该文件页表后的进程的页表实现进程对文件的访问。这与传统的BIO访问文件的方式相比,少了从磁盘向内存中拷贝数据块的过程,提高了文件访问效率。In the embodiment of the present invention, when a process accesses a file, a mapping relationship between the first virtual space that is virtualized according to the first physical space of the storage file and the second virtual space in the process is established, and the file is based on the mapping relationship. The file page table is linked into the page table of the process, and the file page table records the mapping relationship between the virtual address in the first virtual space and the physical address in the first physical space, so that the file page table can be linked The page table of the post process implements access to the file by the process. Compared with the traditional way of accessing files by BIO, the process of copying data blocks from disk to memory is reduced, and the file access efficiency is improved.
应理解,上述文件的访问请求可以是读请求,也可以是写请求。当该访问请求为读请求,或者该访问请求虽然为写请求,但该写请求的目的是利用 待写入数据覆盖文件中的原有数据时,第二虚拟空间和文件的文件页表可以保持不变。It should be understood that the access request of the above file may be a read request or a write request. When the access request is a read request, or the access request is a write request, but the purpose of the write request is to utilize When the original data in the data overlay file is to be written, the file page table of the second virtual space and the file can remain unchanged.
当该访问请求为写请求,但该写请求的目的是在文件的原有数据基础上增添新数据时,需要相应地扩大第一虚拟空间,并更新文件页表。例如,访问请求为写请求,访问请求中携带有待写入数据以及访问请求的起始地址,步骤150可包括:确定根据链入所述文件页表后的进程的页表无法获得访问请求的起始地址对应的物理地址;在内存中为文件分配新的物理地址;将待写入数据写入新的物理地址中。访问请求的起始地址是进程虚拟空间中的虚拟地址,若确定根据进程的页表无法获得访问请求的起始地址对应的物理地址,则表示待写入数据写入的地址已经超出了第一虚拟空间的地址范围。换句话说,待写入数据并非对文件中原有数据的覆盖,而是向文件增添新的数据。实际应用中,一种情况下,随着文件的扩展,可能会发生为该文件已分配的内存物理空间不够的情况,需要新增存储该文件的内存空间。在另一种情况下,为了灵活分配内存物理空间,节约空闲的内存,提高***的吞吐率,在创建新文件时,并不为文件预分配内存物理空间,而只是在该文件有数据写入的过程中,按照待写入数据的大小为文件分配内存物理空间。When the access request is a write request, but the purpose of the write request is to add new data based on the original data of the file, the first virtual space needs to be expanded accordingly, and the file page table is updated. For example, the access request is a write request, the access request carries the data to be written and the start address of the access request, and the step 150 may include: determining that the access table is not available according to the page table of the process linked to the file page table The physical address corresponding to the start address; assign a new physical address to the file in memory; write the data to be written to the new physical address. The start address of the access request is a virtual address in the process virtual space. If it is determined that the physical address corresponding to the start address of the access request cannot be obtained according to the page table of the process, the address to be written to the data has exceeded the first address. The address range of the virtual space. In other words, the data to be written is not an overlay of the original data in the file, but a new data is added to the file. In actual applications, in one case, as the file expands, it may happen that the physical space allocated for the file is insufficient, and the memory space for storing the file needs to be newly added. In another case, in order to flexibly allocate memory physical space, save free memory, and improve system throughput, when creating a new file, the memory physical space is not pre-allocated for the file, but only data is written in the file. In the process, the memory physical space is allocated for the file according to the size of the data to be written.
在本发明实施例中,第一虚拟空间可以大于所述文件在内存的物理空间中的实际占用的物理空间,从而根据第一虚拟空间映射的第二虚拟空间也可以大于所述文件在内存的物理空间中实际占用的物理空间。换一种表达方式,在本发明实施例中,第一虚拟空间和第二虚拟空间都可以大于所述文件的大小。在这种情况下,若需要对所述文件进行新增写,则根据访问请求的起始地址查询所述链入文件页表后的进程页表时,可能找不到访问请求的起始地址对应的物理地址。在这种情况下,MMU会引起缺页中断,请求操作***内核为所述访问所述文件的进程分配内存的物理地址。具体地,操作***内核可以根据缺页中断请求从内存的空闲物理页中为所述文件分配物理页。In the embodiment of the present invention, the first virtual space may be larger than the physical space occupied by the file in the physical space of the memory, so that the second virtual space mapped according to the first virtual space may also be larger than the file in the memory. The physical space actually occupied in the physical space. In another embodiment, in the embodiment of the present invention, the first virtual space and the second virtual space may be larger than the size of the file. In this case, if the file needs to be newly written, if the process page table linked to the file page table is queried according to the start address of the access request, the start address of the access request may not be found. Corresponding physical address. In this case, the MMU will cause a page fault interrupt, requesting the operating system kernel to allocate the physical address of the memory for the process accessing the file. Specifically, the operating system kernel can allocate physical pages for the file from the free physical pages of memory according to the page fault interrupt request.
进一步地,在内存中为文件分配新的物理地址之后,图1的方法还可包括:向所述第一虚拟空间添加新的虚拟地址,并在文件页表中建立新的虚拟地址和新的物理地址之间的映射关系。由于第一虚拟空间是根据内存中存储文件的物理空间映射的虚拟空间,当在内存中为所述文件分配新的物理地址后,可以根据新分配的物理地址向所述第一虚拟空间添加新的虚拟地址,以 扩展第一虚拟空间。采用这种方案,在将新的数据添加至文件后,及时更新第一虚拟空间中的虚拟地址和文件页表,能够保证后续对文件访问和管理的准确性。Further, after the file is assigned a new physical address in the memory, the method of FIG. 1 may further include: adding a new virtual address to the first virtual space, and establishing a new virtual address and a new one in the file page table. The mapping between physical addresses. Since the first virtual space is a virtual space mapped according to a physical space of a file stored in the memory, when a new physical address is allocated to the file in the memory, a new virtual space may be added according to the newly allocated physical address. Virtual address to Expand the first virtual space. With this scheme, after the new data is added to the file, the virtual address and the file page table in the first virtual space are updated in time to ensure the accuracy of subsequent file access and management.
上文结合图1至图3,详细描述了本发明实施例的访问文件的方法,下文结合图4至图5,详细描述本发明实施例的访问文件的装置。The method for accessing a file in the embodiment of the present invention is described in detail above with reference to FIG. 1 to FIG. 3, and the device for accessing a file according to an embodiment of the present invention is described in detail below with reference to FIG. 4 to FIG.
图4是本发明实施例的访问文件的装置的示意性框图。访问文件的装置400包括:4 is a schematic block diagram of an apparatus for accessing a file according to an embodiment of the present invention. The apparatus 400 for accessing a file includes:
接收模块410,用于接收访问文件的访问请求,访问请求中携带有待访问文件的标识,文件为文件***中的任意文件,文件***中所有文件的数据存储于内存中,内存是非易失性存储介质,文件存储在内存的第一物理空间中;The receiving module 410 is configured to receive an access request for accessing the file, where the access request carries an identifier of the file to be accessed, and the file is any file in the file system, and data of all files in the file system is stored in the memory, and the memory is non-volatile storage. Media, the file is stored in the first physical space of the memory;
获取模块420,用于根据文件的标识从文件的元数据中获取第一虚拟空间的信息,第一虚拟空间为根据内存的第一物理空间虚拟的连续的地址空间;The obtaining module 420 is configured to obtain information about the first virtual space from the metadata of the file according to the identifier of the file, where the first virtual space is a virtual continuous address space according to the first physical space of the memory;
建立模块430,用于建立第一虚拟空间和访问文件的进程的第二虚拟空间之间的映射关系,其中,第二虚拟空间为进程的虚拟空间中的一段连续的地址空间;The establishing module 430 is configured to establish a mapping relationship between the first virtual space and the second virtual space of the process of accessing the file, where the second virtual space is a continuous address space in the virtual space of the process;
链入模块440,用于根据映射关系,将文件的文件页表链入进程的页表中,其中,文件页表用于将第一虚拟空间中的虚拟地址映射至第一物理空间中的物理地址;The link-in module 440 is configured to link the file page table of the file into the page table of the process according to the mapping relationship, where the file page table is used to map the virtual address in the first virtual space to the physical address in the first physical space. ;
访问模块450,用于根据链入文件页表后的进程的页表访问文件在内存中的物理地址。The access module 450 is configured to access the physical address of the file in the memory according to the page table of the process linked to the file page table.
本发明实施例中,当进程访问文件时,建立根据存储文件的第一物理空间虚拟的第一虚拟空间和进程中的第二虚拟空间之间的映射关系,并基于该映射关系将该文件的文件页表链入该进程的页表中,由于该文件页表记录有第一虚拟空间中的虚拟地址和第一物理空间中的物理地址之间的映射关系,从而可以通过链入该文件页表后的进程的页表实现进程对文件的访问。这与传统的BIO访问文件的方式相比,少了从磁盘向内存中拷贝数据块的过程,提高了文件访问效率。In the embodiment of the present invention, when a process accesses a file, a mapping relationship between the first virtual space that is virtualized according to the first physical space of the storage file and the second virtual space in the process is established, and the file is based on the mapping relationship. The file page table is linked into the page table of the process, and the file page table records the mapping relationship between the virtual address in the first virtual space and the physical address in the first physical space, so that the file page table can be linked The page table of the post process implements access to the file by the process. Compared with the traditional way of accessing files by BIO, the process of copying data blocks from disk to memory is reduced, and the file access efficiency is improved.
可选地,作为一个实施例,链入模块440具体用于:根据第一虚拟空间的起始地址以及映射关系,确定第二虚拟空间的起始地址;在进程的页表中 确定与第二虚拟空间的起始地址对应的页目录项;在页目录项中记录文件页表的基地址。Optionally, as an embodiment, the link-in module 440 is specifically configured to: determine, according to a starting address and a mapping relationship of the first virtual space, a starting address of the second virtual space; in a page table of the process A page directory entry corresponding to a start address of the second virtual space is determined; a base address of the file page table is recorded in the page directory entry.
可选地,作为一个实施例,建立模块430具体用于记录第一虚拟空间的地址和第二虚拟空间的地址的位置偏移量。Optionally, as an embodiment, the establishing module 430 is specifically configured to record a location offset of an address of the first virtual space and an address of the second virtual space.
可选地,作为一个实施例,第一虚拟空间的地址和第二虚拟空间的地址的位置偏移量可以为0。Optionally, as an embodiment, the location offset of the address of the first virtual space and the address of the second virtual space may be zero.
可选地,作为一个实施例,装置400还可包括:虚拟模块,用于根据内存的第一物理空间虚拟第一虚拟空间。Optionally, as an embodiment, the apparatus 400 may further include: a virtual module, configured to virtualize the first virtual space according to the first physical space of the memory.
可选地,作为一个实施例,访问请求为写请求,访问请求中携带有待写入数据以及访问请求的起始地址,访问模块450可具体用于:确定根据链入文件页表后的进程的页表无法获得访问请求的起始地址对应的物理地址;在内存中为文件分配新的物理地址;将待写入数据写入新的物理地址中。Optionally, as an embodiment, the access request is a write request, where the access request carries the data to be written and the start address of the access request, and the access module 450 may be specifically configured to: determine, according to the process after the file page table is linked The page table cannot obtain the physical address corresponding to the start address of the access request; assign a new physical address to the file in memory; and write the data to be written into the new physical address.
可选地,作为一个实施例,装置400还可包括:添加模块,用于向第一虚拟空间添加新的虚拟地址;建立模块430还用于在文件页表中建立新的虚拟地址和新的物理地址之间的映射关系。Optionally, as an embodiment, the apparatus 400 may further include: an adding module, configured to add a new virtual address to the first virtual space; the establishing module 430 is further configured to establish a new virtual address and a new one in the file page table. The mapping between physical addresses.
应理解,图4的访问文件的装置400能够实现图1中的各个步骤,关于各个模块的具体描述可以参见前面的方法实施例的描述,为避免重复,此处不再赘述。It should be understood that the apparatus 400 for accessing the file of FIG. 4 can implement the various steps in FIG. 1. For a detailed description of each module, reference may be made to the description of the foregoing method embodiments. To avoid repetition, details are not described herein again.
图5是本发明实施例的存储设备的示意性框图。应理解,图5的存储设备500能够实现图1中的各个步骤,为避免重复,此处不再赘述。存储设备500可以包括:FIG. 5 is a schematic block diagram of a storage device according to an embodiment of the present invention. It should be understood that the storage device 500 of FIG. 5 can implement the various steps in FIG. 1. To avoid repetition, details are not described herein again. The storage device 500 can include:
存储器510,用于存储程序。具体地,存储器510可能包含高速RAM存储器,也可能还包括非易失性存储器(non-volatile memory),例如至少一个磁盘存储器。程序可以包括程序代码,所述程序代码包括计算机操作指令。The memory 510 is configured to store a program. In particular, memory 510 may include high speed RAM memory and may also include non-volatile memory, such as at least one disk memory. The program can include program code, the program code including computer operating instructions.
处理器520,用于执行程序,当所述程序被执行时,所述处理器520用于:The processor 520 is configured to execute a program, and when the program is executed, the processor 520 is configured to:
接收访问文件的访问请求,访问请求中携带有待访问文件的标识,文件为文件***中的任意文件,文件***中所有文件的数据存储于内存中,内存是非易失性存储介质,文件存储在内存的第一物理空间中;Receiving an access request for accessing a file, the access request carries an identifier of the file to be accessed, the file is an arbitrary file in the file system, and data of all files in the file system is stored in the memory, the memory is a non-volatile storage medium, and the file is stored in the memory In the first physical space;
根据文件的标识从文件的元数据中获取第一虚拟空间的信息,第一虚拟空间为根据内存的第一物理空间虚拟的连续的地址空间; Obtaining information of the first virtual space from the metadata of the file according to the identifier of the file, where the first virtual space is a virtual continuous address space according to the first physical space of the memory;
建立第一虚拟空间和访问文件的进程的第二虚拟空间之间的映射关系,其中,第二虚拟空间为进程的虚拟空间中的一段连续的地址空间;Establishing a mapping relationship between the first virtual space and a second virtual space of the process of accessing the file, where the second virtual space is a continuous address space in the virtual space of the process;
根据映射关系,将文件的文件页表链入进程的页表中,其中,文件页表用于将第一虚拟空间中的虚拟地址映射至第一物理空间中的物理地址;According to the mapping relationship, the file page table of the file is linked into the page table of the process, wherein the file page table is used to map the virtual address in the first virtual space to the physical address in the first physical space;
根据链入文件页表后的进程的页表访问文件在内存中的物理地址。The physical address of the file in memory is accessed according to the page table of the process that is linked into the file page table.
实际应用中,处理器520可能是一个CPU,或者是ASIC(Application Specific Integrated Circuit,应用特定集成电路),或者是被配置成实施本发明实施例的一个或多个集成电路。In practical applications, the processor 520 may be a CPU, an ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention.
本发明实施例中,当进程访问文件时,建立根据存储文件的第一物理空间虚拟的第一虚拟空间和进程中的第二虚拟空间之间的映射关系,并基于该映射关系将该文件的文件页表链入该进程的页表中,由于该文件页表记录有第一虚拟空间中的虚拟地址和第一物理空间中的物理地址之间的映射关系,从而可以通过链入该文件页表后的进程的页表实现进程对文件的访问。这与传统的BIO访问文件的方式相比,少了从磁盘向内存中拷贝数据块的过程,提高了文件访问效率。In the embodiment of the present invention, when a process accesses a file, a mapping relationship between the first virtual space that is virtualized according to the first physical space of the storage file and the second virtual space in the process is established, and the file is based on the mapping relationship. The file page table is linked into the page table of the process, and the file page table records the mapping relationship between the virtual address in the first virtual space and the physical address in the first physical space, so that the file page table can be linked The page table of the post process implements access to the file by the process. Compared with the traditional way of accessing files by BIO, the process of copying data blocks from disk to memory is reduced, and the file access efficiency is improved.
可选地,作为一个实施例,处理器520具体用于根据第一虚拟空间的起始地址以及映射关系,确定第二虚拟空间的起始地址;在进程的页表中确定与第二虚拟空间的起始地址对应的页目录项;在页目录项中记录文件页表的基地址。Optionally, as an embodiment, the processor 520 is specifically configured to determine a starting address of the second virtual space according to a starting address and a mapping relationship of the first virtual space, and determine a second virtual space in a page table of the process. The page directory entry corresponding to the start address; the base address of the file page table is recorded in the page directory entry.
可选地,作为一个实施例,处理器520具体用于记录所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量。Optionally, as an embodiment, the processor 520 is specifically configured to record a location offset of an address of the first virtual space and an address of the second virtual space.
可选地,作为一个实施例,所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量为0。Optionally, as an embodiment, the location offset of the address of the first virtual space and the address of the second virtual space is 0.
可选地,作为一个实施例,处理器520还可用于根据内存的第一物理空间虚拟第一虚拟空间。Optionally, as an embodiment, the processor 520 is further configured to virtualize the first virtual space according to the first physical space of the memory.
可选地,作为一个实施例,所述访问请求为写请求,所述访问请求中携带有待写入数据以及所述访问请求的起始地址,处理器520具体用于确定根据链入文件页表后的进程的页表无法获得所述访问请求的起始地址对应的物理地址;在所述内存中为所述文件分配新的物理地址;将所述待写入数据写入所述新的物理地址中。Optionally, as an embodiment, the access request is a write request, where the access request carries a data to be written and a start address of the access request, and the processor 520 is specifically configured to determine, according to the link file page table. The page table of the subsequent process cannot obtain the physical address corresponding to the start address of the access request; assign a new physical address to the file in the memory; write the to-be-written data to the new physics In the address.
可选地,作为一个实施例,处理器520还用于向所述第一虚拟空间添加 新的虚拟地址;在所述文件页表中建立所述新的虚拟地址和所述新的物理地址之间的映射关系。Optionally, as an embodiment, the processor 520 is further configured to add to the first virtual space. a new virtual address; establishing a mapping relationship between the new virtual address and the new physical address in the file page table.
应理解,在本发明实施例中,术语“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系。例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。It should be understood that in the embodiment of the present invention, the term "and/or" is merely an association relationship describing an associated object, indicating that there may be three relationships. For example, A and/or B may indicate that A exists separately, and A and B exist simultaneously, and B cases exist alone. In addition, the character "/" in this article generally indicates that the contextual object is an "or" relationship.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the various examples described in connection with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both, for clarity of hardware and software. Interchangeability, the composition and steps of the various examples have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the solution. A person skilled in the art can use different methods for implementing the described functions for each particular application, but such implementation should not be considered to be beyond the scope of the present invention.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的***、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。A person skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working process of the system, the device and the unit described above can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
在本申请所提供的几个实施例中,应该理解到,所揭露的***、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个***,或一些特征可以忽略,或不执行。另外,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口、装置或单元的间接耦合或通信连接,也可以是电的,机械的或其它的形式连接。In the several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the device embodiments described above are merely illustrative. For example, the division of the unit is only a logical function division. In actual implementation, there may be another division manner, for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, or an electrical, mechanical or other form of connection.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本发明实施例方案的目的。The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the embodiments of the present invention.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以是两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。 In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此。 The integrated unit, if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention contributes in essence or to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium. A number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like. . The above description is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto.

Claims (14)

  1. 一种访问文件的方法,所述方法应用于在内存中建立文件***的存储设备,其中,所述内存是非易失性存储器NVM,其特征在于,包括:A method for accessing a file, the method being applied to a storage device that establishes a file system in a memory, wherein the memory is a non-volatile memory NVM, and the method includes:
    接收访问文件的访问请求,所述访问请求中携带有待访问文件的标识,所述文件***中所有文件的数据存储于内存中,所述内存是非易失性存储介质,所述文件存储在所述内存的第一物理空间中;Receiving an access request for accessing a file, where the access request carries an identifier of a file to be accessed, data of all files in the file system is stored in a memory, the memory is a non-volatile storage medium, and the file is stored in the The first physical space of memory;
    根据所述文件的标识从所述文件的元数据中获取第一虚拟空间的信息,所述第一虚拟空间为根据所述内存的第一物理空间虚拟的连续的地址空间;Acquiring information of the first virtual space from the metadata of the file according to the identifier of the file, where the first virtual space is a virtual continuous address space according to the first physical space of the memory;
    建立所述第一虚拟空间和访问所述文件的进程的第二虚拟空间之间的映射关系,其中,所述第二虚拟空间为所述进程的虚拟空间中的一段连续的地址空间;Establishing a mapping relationship between the first virtual space and a second virtual space of a process of accessing the file, where the second virtual space is a continuous address space in a virtual space of the process;
    根据所述映射关系,将所述文件的文件页表链入所述进程的页表中,其中,所述文件页表用于将所述第一虚拟空间中的虚拟地址映射至所述第一物理空间中的物理地址;Linking a file page table of the file into a page table of the process according to the mapping relationship, wherein the file page table is configured to map a virtual address in the first virtual space to the first physics The physical address in space;
    根据链入所述文件页表后的进程的页表访问所述文件在所述内存中的物理地址。The physical address of the file in the memory is accessed according to a page table of a process linked to the file page table.
  2. 如权利要求1所述的方法,其特征在于,The method of claim 1 wherein
    所述根据所述映射关系,将所述文件的文件页表链入所述进程的页表中,包括:And linking, according to the mapping relationship, a file page table of the file into a page table of the process, including:
    根据所述第一虚拟空间的起始地址以及所述映射关系,确定所述第二虚拟空间的起始地址;Determining a starting address of the second virtual space according to a starting address of the first virtual space and the mapping relationship;
    在所述进程的页表中确定与所述第二虚拟空间的起始地址对应的页目录项;Determining, in a page table of the process, a page directory entry corresponding to a start address of the second virtual space;
    在所述页目录项中记录所述文件页表的基地址。The base address of the file page table is recorded in the page directory entry.
  3. 如权利要求1或2所述的方法,其特征在于,所述建立所述第一虚拟空间和访问所述文件的进程的第二虚拟空间之间的映射关系,包括:The method of claim 1 or 2, wherein the mapping between the first virtual space and the second virtual space of the process of accessing the file comprises:
    记录所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量。Recording a position offset of an address of the first virtual space and an address of the second virtual space.
  4. 如权利要求3所述的方法,其特征在于,所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量为0。The method of claim 3, wherein the address offset of the address of the first virtual space and the address of the second virtual space is zero.
  5. 如权利要求1-4中任意一项所述的方法,其特征在于,还包括: The method of any of claims 1-4, further comprising:
    根据所述内存的第一物理空间虚拟所述第一虚拟空间。The first virtual space is virtualized according to the first physical space of the memory.
  6. 如权利要求1-5中任一项所述的方法,其特征在于,所述访问请求为写请求,所述访问请求中携带有待写入数据以及所述访问请求的起始地址,The method according to any one of claims 1 to 5, wherein the access request is a write request, and the access request carries a data to be written and a start address of the access request,
    所述根据链入所述文件页表后的进程的页表访问所述文件在所述内存中的物理地址,包括:The accessing the physical address of the file in the memory according to the page table of the process linked to the file page table includes:
    确定根据链入所述文件页表后的进程的页表无法获得所述访问请求的起始地址对应的物理地址;Determining that the physical address corresponding to the start address of the access request cannot be obtained according to the page table of the process linked to the file page table;
    在所述内存中为所述文件分配新的物理地址;Allocating a new physical address to the file in the memory;
    将所述待写入数据写入所述新的物理地址中。Writing the data to be written into the new physical address.
  7. 如权利要求6所述的方法,其特征在于,所述在所述内存中为所述文件分配新的物理地址之后,所述方法还包括:The method of claim 6, wherein after the assigning a new physical address to the file in the memory, the method further comprises:
    向所述第一虚拟空间添加新的虚拟地址,并在所述文件页表中建立所述新的虚拟地址和所述新的物理地址之间的映射关系。Adding a new virtual address to the first virtual space, and establishing a mapping relationship between the new virtual address and the new physical address in the file page table.
  8. 一种访问文件的装置,其特征在于,包括:An apparatus for accessing a file, comprising:
    接收模块,用于接收访问文件的访问请求,所述访问请求中携带有待访问文件的标识,所述文件为文件***中的任意文件,所述文件***中所有文件的数据存储于内存中,所述内存是非易失性存储介质,所述文件存储在所述内存的第一物理空间中;a receiving module, configured to receive an access request for accessing a file, where the access request carries an identifier of a file to be accessed, where the file is an arbitrary file in a file system, and data of all files in the file system is stored in a memory. The memory is a non-volatile storage medium, and the file is stored in a first physical space of the memory;
    获取模块,用于根据所述文件的标识从所述文件的元数据中获取第一虚拟空间的信息,所述第一虚拟空间为根据所述内存的第一物理空间虚拟的连续的地址空间;An acquiring module, configured to acquire information of the first virtual space from the metadata of the file according to the identifier of the file, where the first virtual space is a virtual continuous address space according to the first physical space of the memory;
    建立模块,用于建立所述第一虚拟空间和访问所述文件的进程的第二虚拟空间之间的映射关系,其中,所述第二虚拟空间为所述进程的虚拟空间中的一段连续的地址空间;Establishing a module, configured to establish a mapping relationship between the first virtual space and a second virtual space of a process of accessing the file, where the second virtual space is a continuous segment in a virtual space of the process Address space
    链入模块,用于根据所述映射关系,将所述文件的文件页表链入所述进程的页表中,其中,所述文件页表用于将所述第一虚拟空间中的虚拟地址映射至所述第一物理空间中的物理地址;a link-in module, configured to link a file page table of the file into a page table of the process according to the mapping relationship, where the file page table is used to map a virtual address in the first virtual space To a physical address in the first physical space;
    访问模块,用于根据链入所述文件页表后的进程的页表访问所述文件在所述内存中的物理地址。And an access module, configured to access a physical address of the file in the memory according to a page table of a process linked to the file page table.
  9. 如权利要求8所述的装置,其特征在于,所述链入模块具体用于: The device according to claim 8, wherein the linking module is specifically configured to:
    根据所述第一虚拟空间的起始地址以及所述映射关系,确定所述第二虚拟空间的起始地址;Determining a starting address of the second virtual space according to a starting address of the first virtual space and the mapping relationship;
    在所述进程的页表中确定与所述第二虚拟空间的起始地址对应的页目录项;Determining, in a page table of the process, a page directory entry corresponding to a start address of the second virtual space;
    在所述页目录项中记录所述文件页表的基地址。The base address of the file page table is recorded in the page directory entry.
  10. 如权利要求8或9所述的装置,其特征在于,所述建立模块具体用于记录所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量。The apparatus according to claim 8 or 9, wherein the establishing module is specifically configured to record a position offset of an address of the first virtual space and an address of the second virtual space.
  11. 如权利要求10所述的装置,其特征在于,所述第一虚拟空间的地址和所述第二虚拟空间的地址的位置偏移量为0。The apparatus according to claim 10, wherein the address offset of the address of the first virtual space and the address of the second virtual space is zero.
  12. 如权利要求8-11中任意一项所述的装置,其特征在于,所述装置还包括:The device of any of claims 8-11, wherein the device further comprises:
    虚拟模块,用于根据所述内存的第一物理空间虚拟所述第一虚拟空间。a virtual module, configured to virtualize the first virtual space according to the first physical space of the memory.
  13. 如权利要求8-12中任一项所述的装置,其特征在于,所述访问请求为写请求,所述访问请求中携带有待写入数据以及所述访问请求的起始地址,所述访问模块具体用于:The device according to any one of claims 8 to 12, wherein the access request is a write request, and the access request carries a data to be written and a start address of the access request, the access The module is specifically used to:
    确定根据链入所述文件页表后的进程的页表无法获得所述访问请求的起始地址对应的物理地址;Determining that the physical address corresponding to the start address of the access request cannot be obtained according to the page table of the process linked to the file page table;
    在所述内存中为所述文件分配新的物理地址;Allocating a new physical address to the file in the memory;
    将所述待写入数据写入所述新的物理地址中。Writing the data to be written into the new physical address.
  14. 如权利要求13所述的装置,其特征在于,还包括:The device of claim 13 further comprising:
    添加模块,用于向所述第一虚拟空间添加新的虚拟地址;Adding a module, configured to add a new virtual address to the first virtual space;
    所述建立模块还用于在所述文件页表中建立所述新的虚拟地址和所述新的物理地址之间的映射关系。 The establishing module is further configured to establish a mapping relationship between the new virtual address and the new physical address in the file page table.
PCT/CN2014/092513 2014-11-28 2014-11-28 File access method and apparatus WO2016082191A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2014/092513 WO2016082191A1 (en) 2014-11-28 2014-11-28 File access method and apparatus
CN201480037874.2A CN105830022B (en) 2014-11-28 2014-11-28 The method and apparatus for accessing file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2014/092513 WO2016082191A1 (en) 2014-11-28 2014-11-28 File access method and apparatus

Publications (1)

Publication Number Publication Date
WO2016082191A1 true WO2016082191A1 (en) 2016-06-02

Family

ID=56073385

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/092513 WO2016082191A1 (en) 2014-11-28 2014-11-28 File access method and apparatus

Country Status (2)

Country Link
CN (1) CN105830022B (en)
WO (1) WO2016082191A1 (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110007869A (en) * 2019-04-12 2019-07-12 苏州浪潮智能科技有限公司 A kind of memory data copy method, apparatus, equipment and computer storage medium
CN111966608A (en) * 2020-08-14 2020-11-20 苏州浪潮智能科技有限公司 Direct internal memory access method and device of external memory
CN112099903A (en) * 2020-08-18 2020-12-18 海光信息技术股份有限公司 Memory management method and device of virtual machine, CPU chip and server
CN115061954A (en) * 2022-08-18 2022-09-16 统信软件技术有限公司 Missing page interrupt processing method, computing device and storage medium
CN116069689A (en) * 2023-03-02 2023-05-05 北京象帝先计算技术有限公司 Page table access method, system, electronic component and page table configuration method
CN116483738A (en) * 2023-06-20 2023-07-25 苏州浪潮智能科技有限公司 Data access method and device, storage medium and electronic device

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019127135A1 (en) * 2017-12-27 2019-07-04 华为技术有限公司 File page table management technique
CN111414248B (en) * 2019-01-04 2023-03-21 阿里巴巴集团控股有限公司 Memory management method and device and computing equipment
CN110046106B (en) * 2019-03-29 2021-06-29 海光信息技术股份有限公司 Address translation method, address translation module and system
CN110764995B (en) * 2019-09-05 2023-06-06 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for detecting file access abnormality
CN111143241A (en) * 2019-12-30 2020-05-12 深圳Tcl数字技术有限公司 Memory data migration method and device and storage medium
CN112256598B (en) * 2020-10-27 2022-10-28 上海壁仞智能科技有限公司 Memory allocation method and device and memory addressing method and device
CN112650603B (en) * 2020-12-28 2024-02-06 北京天融信网络安全技术有限公司 Memory management method, device, electronic equipment and storage medium
CN112732653A (en) * 2021-01-12 2021-04-30 中国工商银行股份有限公司 Concurrent file processing method and system
CN112732269B (en) * 2021-01-15 2024-05-24 北京博雅慧视智能技术研究院有限公司 Access method and device applied to physical address of AVS2 hardware encoder

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102609254A (en) * 2012-01-19 2012-07-25 中国科学院计算技术研究所 Method and device for obtaining object-level memory access behavior
CN102831069A (en) * 2012-06-30 2012-12-19 华为技术有限公司 Memory processing method and memory management equipment
CN103425502A (en) * 2012-05-15 2013-12-04 腾讯科技(深圳)有限公司 Prefetching starting method and prefetching starting device of operating system
WO2014025595A1 (en) * 2012-08-04 2014-02-13 Microsoft Corporation Function evaluation using lightweight process snapshots

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4742447A (en) * 1986-01-16 1988-05-03 International Business Machines Corporation Method to control I/O accesses in a multi-tasking virtual memory virtual machine type data processing system
US8204871B1 (en) * 2010-09-28 2012-06-19 Emc Corporation Extended file mapping cache for fast input-output
CN102707966B (en) * 2012-04-12 2014-09-03 腾讯科技(深圳)有限公司 Method and device for acceleratively starting operating system, and method, device and terminal for generating prefetched information
CN103218312B (en) * 2013-03-28 2017-07-11 中国科学院上海微***与信息技术研究所 file access method and system
CN103257929B (en) * 2013-04-18 2016-03-16 中国科学院计算技术研究所 A kind of virutal machine memory mapping method and system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102609254A (en) * 2012-01-19 2012-07-25 中国科学院计算技术研究所 Method and device for obtaining object-level memory access behavior
CN103425502A (en) * 2012-05-15 2013-12-04 腾讯科技(深圳)有限公司 Prefetching starting method and prefetching starting device of operating system
CN102831069A (en) * 2012-06-30 2012-12-19 华为技术有限公司 Memory processing method and memory management equipment
WO2014025595A1 (en) * 2012-08-04 2014-02-13 Microsoft Corporation Function evaluation using lightweight process snapshots

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110007869A (en) * 2019-04-12 2019-07-12 苏州浪潮智能科技有限公司 A kind of memory data copy method, apparatus, equipment and computer storage medium
CN110007869B (en) * 2019-04-12 2020-06-30 苏州浪潮智能科技有限公司 Memory data copying method, device, equipment and computer storage medium
CN111966608A (en) * 2020-08-14 2020-11-20 苏州浪潮智能科技有限公司 Direct internal memory access method and device of external memory
CN111966608B (en) * 2020-08-14 2023-06-06 苏州浪潮智能科技有限公司 Direct internal memory access method and device for external memory
CN112099903A (en) * 2020-08-18 2020-12-18 海光信息技术股份有限公司 Memory management method and device of virtual machine, CPU chip and server
CN112099903B (en) * 2020-08-18 2023-01-31 海光信息技术股份有限公司 Memory management method and device of virtual machine, CPU chip and server
CN115061954A (en) * 2022-08-18 2022-09-16 统信软件技术有限公司 Missing page interrupt processing method, computing device and storage medium
CN115061954B (en) * 2022-08-18 2022-11-29 统信软件技术有限公司 Missing page interrupt processing method, computing device and storage medium
CN116069689A (en) * 2023-03-02 2023-05-05 北京象帝先计算技术有限公司 Page table access method, system, electronic component and page table configuration method
CN116069689B (en) * 2023-03-02 2023-07-21 北京象帝先计算技术有限公司 Page table access method, system, electronic component and page table configuration method
CN116483738A (en) * 2023-06-20 2023-07-25 苏州浪潮智能科技有限公司 Data access method and device, storage medium and electronic device
CN116483738B (en) * 2023-06-20 2023-09-05 苏州浪潮智能科技有限公司 Data access method and device, storage medium and electronic device

Also Published As

Publication number Publication date
CN105830022A (en) 2016-08-03
CN105830022B (en) 2019-03-08

Similar Documents

Publication Publication Date Title
WO2016082191A1 (en) File access method and apparatus
JP6460497B2 (en) File access method, file access device, and storage device
US10452562B2 (en) File access method and related device
CN108804350B (en) Memory access method and computer system
CN111414248B (en) Memory management method and device and computing equipment
CN111061655B (en) Address translation method and device for storage device
US10296250B2 (en) Method and apparatus for improving performance of sequential logging in a storage device
US11237980B2 (en) File page table management technology
EP3489832A1 (en) File access method and apparatus, and storage system
TW201941197A (en) Hybrid memory system
TWI744111B (en) Method for establishing look-up table and inquiring memory address, method for establishing host memory address look-up table, and method for inquiring host memory address
US11835992B2 (en) Hybrid memory system interface
WO2016049893A1 (en) File page management unit, processing device and file page management method
CN115079957A (en) Request processing method, device, controller, equipment and storage medium
US20210132801A1 (en) Optimized access to high-speed storage device
JP2024525170A (en) Data compression method and device
Zhang et al. Research on persistent memory file system optimization

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14907022

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 14907022

Country of ref document: EP

Kind code of ref document: A1