CN113778908B - Memory access management method and system - Google Patents

Memory access management method and system Download PDF

Info

Publication number
CN113778908B
CN113778908B CN202111078307.XA CN202111078307A CN113778908B CN 113778908 B CN113778908 B CN 113778908B CN 202111078307 A CN202111078307 A CN 202111078307A CN 113778908 B CN113778908 B CN 113778908B
Authority
CN
China
Prior art keywords
pack
index
thread
data
index position
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111078307.XA
Other languages
Chinese (zh)
Other versions
CN113778908A (en
Inventor
阮华斌
杨涛
唐贺
陈晋红
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tsinghua University
Original Assignee
Tsinghua University
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 Tsinghua University filed Critical Tsinghua University
Priority to CN202111078307.XA priority Critical patent/CN113778908B/en
Publication of CN113778908A publication Critical patent/CN113778908A/en
Application granted granted Critical
Publication of CN113778908B publication Critical patent/CN113778908B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • G06F12/0615Address space extension
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • G06F12/0646Configuration or reconfiguration

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a memory access management method and a system, comprising the following steps: establishing a data storage pool in a memory, wherein the data storage pool comprises a plurality of data storage areas; if the index position to be accessed by a thread is positioned in the data packet currently accessed by the thread, directly returning the physical address of the index position in the storage area currently accessed by the thread, otherwise, screening out the pre-selected row and the affiliated column of the storage area of the index position, and returning the physical address of the index position in the screened storage area; and when the preselection row and the column of the storage area at the index position cannot be screened out, selecting the storage area for data replacement, performing data replacement on the data packet in the storage area and the data packet containing the index position in the virtual memory, and returning the physical address of the index position in the storage area after data replacement. The invention realizes the decoupling between the memory access control and the application program and avoids the problem that the application program fails to operate due to insufficient memory space.

Description

Memory access management method and system
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a memory access management method and system.
Background
The virtual memory technology is a technology widely used in an operating system, and the storage space of a physical memory is expanded by using the storage space of a physical disk, so that the problem that a program cannot run due to insufficient memory space of the program is solved at the level of the operating system.
For an application program with a large memory requirement, in order to ensure that the application amount of the memory in the program does not exceed the available amount of the current operating system, the application program usually adopts a mode of applying for a memory space not larger than the available memory capacity in advance, then loading data in batches, and if a batch of data is processed, loading the next batch of data, and ensuring that the program can normally operate on a computing node with a small memory capacity by repeatedly using the pre-allocated memory space.
Disclosure of Invention
In view of this, the present invention provides a memory access management method and system, which are independent of an application program, and utilize a space defined in advance in a memory as a data storage pool, and perform data access and data exchange with a virtual memory for each data storage area in the data storage pool by using different threads.
The technical scheme of the invention is realized as follows:
a memory access management method includes:
the method comprises the steps that a data storage pool is established in a memory for at least one thread to access, an application program accesses the data storage pool through the thread, the data storage pool comprises a plurality of data storage area packs which are arranged in at least two rows and at least two columns, each pack comprises at least two data storage unit units, the number of the units in each pack is equal, and when the number of the threads is at least two, each thread can access the data storage pool in parallel; the data in each unit in each pack is represented by the index of the data to represent the logical address, and the index of the data is continuous among the units in each pack; the data stored by one pack is a data packet;
when the index position to be accessed by a certain thread is located in the data packet currently accessed by the thread, the thread directly returns the physical address corresponding to the index position in the pack currently accessed by the thread to the application program;
when the index position is not located in the data packet currently accessed by the thread, obtaining a pack pre-selection line of the index position according to a first rule, and locking the pack pre-selection line by using a mutual exclusion lock;
in a pack pre-selection row, screening out a column to which a pack at the index position belongs according to a second rule, unlocking the pack pre-selection row, taking the pack positioned on the pack pre-selection row and the column to which the pack belongs as the pack to which the index position belongs, and returning a physical address corresponding to the index position in the pack to which the index position belongs to the thread to an application program;
and when the column to which the pack at the index position belongs cannot be screened out by the second rule, selecting the pack for data replacement in the pack pre-selection row based on a selection strategy, loading the data packet in the pack for data replacement into the virtual memory, loading the data packet containing the index position in the virtual memory into the pack for data replacement, unlocking the pack pre-selection row, and returning the physical address corresponding to the index position in the pack after data replacement to the application program by the thread.
Further, the method also includes that whether the index position to be accessed by a thread is located in the data packet currently accessed by the thread is judged by the following method:
comparing the index with the index address range of the data packet currently accessed by the thread, wherein if the index is located in the index address range of the data packet currently accessed by the thread, the index position is located in the data packet currently accessed by the thread, otherwise, the index position is not located in the data packet currently accessed by the thread; wherein,
the index address range of the data packet is the range from the start index address to the end index address of the data packet, wherein the end index address of the data packet is determined by the start index address of the data packet and the number of units in the pack.
Further, the obtaining a pack pre-selected row of the index position according to the first rule includes:
obtaining the logic number of the data packet where the data at the index position is located according to the index and the number of units contained in each pack;
and obtaining a pack pre-selection row of the index position according to the logic number of the data packet where the data of the index position is located and the total number of packs contained in each column of the data storage pool.
Further, after obtaining the logical number of the data packet where the data at the index position is located, the method further includes:
and if the logic number of the data packet where the data at the index position is located is not the logic number of the data packet currently accessed by the thread, reducing the thread number of the pack currently accessed by the thread by one.
Further, the screening, in the pack pre-selection row, a column to which the pack at the index position belongs according to a second rule, unlocking the pack pre-selection row, taking the pack located in the pack pre-selection row and the column to which the pack belongs as the pack to which the index position belongs, and returning, by the thread, to the application program, a physical address corresponding to the index position in the pack to which the index position belongs, includes:
traversing each pack in the pack pre-selection row, and performing the following traversal operations:
if the pack state is an empty state, then:
obtaining the starting index of each pack according to the index and the number of units contained in the pack,
the number of currently accessed threads of the pack is increased by one,
the pack state is updated to the allocated state,
the pack currently accessed by the thread is updated to the row number and column number of the pack,
obtaining the logic number of the data packet currently accessed by the thread according to the index and the number of units contained in each pack,
obtaining the initial index of the thread according to the index and the number of units contained in each pack,
the pack pre-selected row is unlocked and,
the thread returns the physical address corresponding to the index position in the currently accessed pack to the application program;
if the status of pack is allocated and the index is within the index address range of the pack, or if the status of pack is just loaded with data and the index is within the index address range of the pack:
the current number of accessing threads of the pack is increased by one,
the pack currently accessed by the thread is updated to the row number and column number of the pack,
obtaining the logic number of the data packet currently accessed by the thread according to the index and the number of units contained in each pack,
the pack pre-selected row is unlocked and,
the thread returns to the application the physical address corresponding to the index location in the pack it is currently accessing.
Further, after loading the data packet containing the index position in the virtual memory into the pack for data replacement, and before unlocking the pack pre-selected row, the method further includes:
obtaining the initial index of each pack according to the index and the number of units contained in the pack,
the current number of accessing threads of the pack is increased by one,
the pack state is updated to the just loaded data state,
the pack currently accessed by the thread is updated to the row number and column number of the pack,
obtaining the logic number of the data packet currently accessed by the thread according to the index and the number of units contained in each pack,
obtaining the initial index of the thread according to the index and the number of units contained in each pack;
the thread returns the physical address corresponding to the index position in the pack after data replacement to the application program, and the physical address comprises: the thread returns to the application the physical address corresponding to the index location in the pack it is currently accessing.
Further, the method further comprises:
when either thread completes accessing the data storage pool, and exits the multi-threaded environment,
the number of threads of the pack currently accessed by the thread is reduced by one.
A memory access management system, comprising:
the data storage pool is located in the memory for being accessed by at least one thread, the application program accesses the data storage pool through the thread, the data storage pool comprises a plurality of data storage area packs which are arranged in at least two rows and at least two columns, each pack comprises at least two data storage unit units, the number of the units in each pack is equal, and when the number of the threads is at least two, each thread can access the data storage pool in parallel; the data in each unit in each pack is represented by the index of the data to represent the logical address, and the index of the data is continuous among the units in each pack; the data stored by one pack is a data packet;
a data storage pool access management module to perform:
when the index position to be accessed by a certain thread is positioned in the data packet currently accessed by the thread, the thread directly returns the physical address corresponding to the index position in the pack currently accessed by the thread to the application program;
when the index position is not located in the data packet currently accessed by the thread, obtaining a pack pre-selection row of the index position according to a first rule, and locking the pack pre-selection row by using an exclusive lock;
in the pack pre-selection row, screening out the column to which the pack at the index position belongs according to a second rule, unlocking the pack pre-selection row, taking the pack positioned on the pack pre-selection row and the column to which the pack belongs as the pack to which the index position belongs, and returning the physical address corresponding to the index position in the pack to which the index position belongs to the thread to the application program;
and when the column to which the pack at the index position belongs cannot be screened out by the second rule, selecting the pack for data replacement in the pack pre-selection row based on a selection strategy, loading the data packet in the pack for data replacement into the virtual memory, loading the data packet containing the index position in the virtual memory into the pack for data replacement, unlocking the pack pre-selection row, and returning the physical address corresponding to the index position in the pack after data replacement to the application program by the thread.
A non-transitory computer readable storage medium storing instructions that, when executed by a processor, cause the processor to perform the steps in a memory access management method as in any one of the above.
An electronic device, comprising:
at least one processor;
a memory and a virtual memory carrier communicatively coupled to the at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to cause the at least one processor to perform the steps of the memory access management method as described in any one of the above.
The memory access management method and the memory access management system are used as an intermediate layer between an application program and a memory, a data storage pool is independently divided from the memory storage space and is independently managed, the application program does not need to directly manage and operate the address of the divided memory storage space, only the subscript index of data to be accessed by a thread needs to be informed, the memory access management method and the memory access management system can be used for obtaining the corresponding physical address position in the memory, in addition, the memory access management method and the memory access management system can also be used for realizing the data exchange between a pack in the data storage pool and the virtual memory, and when the data of the index position to be accessed by the application program is positioned in the virtual memory, the technical scheme of the invention can also be used for realizing the exchange between a data packet stored by a certain pack in the data storage pool and a data packet containing the data of the index position in the virtual memory according to the set relevant rules and selection strategies. The technical scheme of the invention is that a data storage pool is divided in a memory by an application program independently, the thread operating the data storage pool does not share the address space of the data storage pool with all processes on an operating system, and simultaneously, the subscript index of data and the initial index of a data packet all adopt a logical address mode, so that a virtual memory is expanded by means of the space capacity of a physical disk and data exchange is carried out with the pack of the data storage pool, the address space of the data is expanded to the maximum extent on the premise of the maximum data volume which can be accommodated by the virtual memory, and the problem of the requirement of the application program on large-memory data is solved. According to the invention, the common problem of data access conflict in a single-thread or multi-thread access mode can be effectively avoided by using the mutual exclusion lock, so that the problem that the application program cannot run due to insufficient memory space can be well solved.
Drawings
Fig. 1 is a flowchart of a memory access management method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of the structure of a data storage pool in an embodiment of the present invention;
fig. 3 is a schematic diagram of an electronic device in an embodiment of the invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to the accompanying drawings and examples.
The memory access management method provided by the embodiment of the invention is independent of the application program, is specially used for dividing the memory storage space, and the application program does not need to directly manage the memory space. The memory access management method provided by the embodiment of the invention is used as an intermediate layer between the application program and the memory, realizes the decoupling between the memory access control and the application program, and is beneficial to later development and maintenance. In addition, because the data storage pool in the memory is specially divided in the embodiment of the invention, the data storage pool does not share the memory address space with all processes of the operating system, so that the problem that the operation of the operating system process on the data storage pool fails due to insufficient memory space of the application program can not occur.
As shown in fig. 1, the memory access management method according to the embodiment of the present invention mainly includes:
step 1, establishing a data storage pool in a memory for at least one thread to access, wherein an application program accesses the data storage pool through the thread, the data storage pool comprises at least two rows and a plurality of packs (data storage areas) arranged in at least two columns, each pack comprises at least two units (data storage units), the number of the units in each pack is equal, and when the number of the threads is at least two, each thread can access the data storage pool in parallel; wherein, the data in each unit in each pack is represented by its logical address by its index (subscript index), and the indexes of the data are consecutive between the units in each pack; wherein, the data stored by one pack is a data packet;
step 2, when the index position to be accessed by a certain thread is positioned in the data packet currently accessed by the thread, the thread directly returns the physical address corresponding to the index position in the currently accessed pack to the application program;
step 3, when the index position is not located in the data packet currently accessed by the thread, obtaining a pack pre-selection line of the index position according to a first rule, and locking the pack pre-selection line by using a mutual exclusion lock;
step 4, screening out the column to which the pack at the index position belongs in the pack pre-selection row according to a second rule, unlocking the pack pre-selection row, taking the pack positioned on the column to which the pack pre-selection row and the pack belong as the pack to which the index position belongs, and returning the physical address corresponding to the index position in the pack to which the index position belongs to the thread to the application program;
and 5, when the column to which the pack at the index position belongs cannot be screened out by the second rule, selecting the pack for data replacement in the pack pre-selection row based on a selection strategy, loading the data packet in the pack for data replacement into the virtual memory, loading the data packet containing the index position in the virtual memory into the pack for data replacement, unlocking the pack pre-selection row, and returning the physical address corresponding to the index position in the pack after data replacement to the application program by the thread.
Fig. 2 illustrates a structure of a data storage pool in an embodiment of the present invention. In the structure of the data storage pool in the embodiment of the present invention, a plurality of pads are arranged in a multi-way (column) and multi-row (row) structure, for example, in a four-column (way 0, way1, way2, way3, respectively) and six-row (row 0, row1, row2, row3, row4, row5, respectively) structure in fig. 2, each pad may determine a position in the form of row and column coordinates, so that a pointer of a thread may select a specific pad in the row and column coordinates and return a reference of the pad, for example, directly return a physical address of a specific memory of the pad at a certain column position of a certain row, store data, and the like. Each pack contains a plurality of units, for example, each pack in fig. 2 contains four units, where a unit is a basic unit for storing data, and in an alternative embodiment, an integer, a floating point, or an image data may be placed in a storage unit of each unit. All the packs in the same way can be identified by the same way id (column number) and all the packs in the same row can be identified by the same row id (row number).
In the embodiment of the present invention, step 2 and step 3 are respectively performed to process two possible situations of whether the index position to be accessed by a thread is located in the data packet currently accessed by the thread. Therefore, it is necessary to determine whether the index location to be accessed by the thread is located in the data packet currently accessed by the thread, and therefore, before step 2 and step 3, the memory access management method according to the embodiment of the present invention determines whether the index location to be accessed by a thread is located in the data packet currently accessed by the thread by the following method:
comparing the index with the index address range of the data packet currently accessed by the thread, if the index is located in the index address range of the data packet currently accessed by the thread, the index position is located in the data packet currently accessed by the thread (step 2 is executed), otherwise, the index position is not located in the data packet currently accessed by the thread (step 3 is executed).
The index address range of the data packet is the range from the start index address to the end index address of the data packet, wherein the end index address of the data packet is determined by the start index address of the data packet and the number of units in the pack.
Wherein, index is a logical address, and the index address range is a logical address range.
In the computer execution layer, the judgment whether the index position to be accessed by a certain thread is located in the data packet currently accessed by the thread is carried out by the following conditions:
ThreadPackInfo[threadID].startIndex<=index<ThreadPackInfo[threadID]+packSize
wherein the thread id is a thread number of the thread, the ThreadPackInfo [ thread id ]. StartIndex is a start index address (start index address, that is, startIndex, is a logical address) of a packet currently accessed by the thread, the packSize is a number of units in one pack, and an index address range of the packet currently accessed by the thread is as follows:
[ThreadPackInfo[threadID].startIndex,ThreadPackInfo[threadID]+packSize)
therefore, if the index position to be accessed by the thread satisfies the above formula, that is, the index is located in the index address range of the data packet currently accessed by the thread, step 2 is executed, and if not, step 3 is executed.
In the initial state, the thread does not access the data storage pool, and the ThreadPackInfo [ threadID ]. StartIndex amplitude is a maximum value. Therefore, in this case, the index position to be accessed by the thread does not satisfy the above expression, and then step 3 is executed.
In an alternative embodiment, in step 2, the thread directly returns to the application the physical address corresponding to the index location in the pack it is currently accessing, for example, the following operations performed at the computer execution level:
&MemoryPool[ThreadPackInfo[threadID].lastPackWayID][ThreadPackInfo[threadID].lastPackRowID].packData[offset]
this operation is a reference to the member variable packData offset that directly returns the corresponding element in MemoryPool. Where, memoryPool [ ] [ ] is a memory pool pointer, which is a two-dimensional array of structures, and points to a memory space (i.e., a data storage pool) containing wayNum (total number of columns) way and rowNum (total number of rows) row. In the MemoryPool structure array, each array element contains a member variable packData [ packSize ] for storing packSize data, which is data in a pack. Where "&" is the fetch address operator. Wherein ThreadPackInfo [ threadID ]. LastPackWayID is the column number of the pack currently accessed by the thread, and ThreadPackInfo [ threadID ]. LastPackRowID is the row number of the pack currently accessed by the thread. Wherein Offset = index% padding size, i.e., index takes the remainder of padding size, or modulo.
In the embodiment of the present invention, the thread is operated on the data in the memory (not the virtual memory), so, in step 2, although it is described as a packet, it is obvious that the packet at this time is located in a certain pack in the data storage pool, so that, in step 2, the operation on a certain pack in the data storage pool in the memory is finally executed, which can be seen through two variables, namely threadpackwayid and threadpadfoi [ threeadid ]. LastPackRowID, directly for the specific row and column number of the data storage pool.
In this embodiment of the present invention, the obtaining of the pack pre-selected row of the index position according to the first rule in step 3 mainly includes:
step 31, obtaining the logic number of the data packet where the data at the index position is located according to the index and the number of units contained in each pack;
and step 32, obtaining a pack pre-selection row of the index position according to the logic number of the data packet where the data of the index position is located and the total number of packs contained in each column of the data storage pool.
Wherein step 31 is represented at the computer execution level as
packID=index/packSize
Here, index/packSize indicates that index is divided by packSize and rounded down, and packID is the logical number of the packet in which the data at the index position is located. It should be noted that, the logical number of the packet, the pack id, is not the number of the pack in the data storage pool, and the pack id is the number of the packet stored in the pack, because data exchange with the virtual memory may be required, the packet of the pack id may be exchanged into the virtual memory to be stored and recalled (or swapped back) into the data storage pool when required, and the pack in the data storage pool recalled (or swapped back) from the virtual memory is not necessarily the pack where the packet is located at the beginning, for example, a certain packet is in the pack of 0 th row in the 0 th column when creation (generation) is started, and is exchanged into the virtual memory in the subsequent data exchange process, and the management logic and policy adopted in the memory access management method according to the embodiment of the present invention may be placed in the pack that is not in the 0 th row in the 0 th column when data is swapped back again.
Wherein step 32 is represented at the computer execution level as
RowID=packID%waySize
Where RowID is the line number, the pack pre-selected line representing the index position in step 32, and waySize is the total number of packs in each way.
In step 32, the pack pre-selected row for the index position is obtained, but this does not mean that the index position is necessarily within the pack pre-selected row, and further confirmation is required in the following steps.
In an optional embodiment, after obtaining the logic number of the data packet where the data at the index location is located in step 31, the memory access management method according to the embodiment of the present invention further includes:
and if the logic number of the data packet where the data at the index position is located is not the logic number of the data packet currently accessed by the thread, reducing the number of threads of the pack currently accessed by the thread by one.
The purpose of reducing the number of threads of the pack that the thread currently accesses by one is to exit the thread from the pack that it currently accesses.
This step is represented at the computer execution level as if the packID satisfies the following condition:
packID!=ThreadPackInfo[threadID].lastPackID
the following operations are performed:
wayID=ThreadPackInfo[threadID].lastPackWayID,
rowID=ThreadPackInfo[threadID].lastPackRowID,
PackState[wayID][rowID].refCnt--;
wherein, threadPackInfo [ threadID ]. LastPackID is the logic number of the data packet currently accessed by the thread, threadPackInfo [ threadID ]. LastPackWayID is the column number of the Pack currently accessed by the thread, threadPackInfo [ threadID ]. LastPackRowID is the row number of the Pack currently accessed by the thread, packState [ wayID ] [ rowID ]. RefCnt-indicates that the number of threads of the Pack currently accessed by the thread is reduced by one, and refCnt indicates how many threads currently accessed by the Pack.
In step 3, the pack pre-selection row (row corresponding to the rowID) is locked by the mutual exclusion lock, and before the lock is not unlocked, the pack of one thread pack pre-selection row (row corresponding to the rowID) is allowed to access at a time, so that the access of other threads to the row and the screening of image packs in the subsequent screening process of the column to which the pack at the index position belongs are prevented. The problem of data access conflict during single-thread or multi-thread access can be effectively avoided by using the mutual exclusion lock.
In an alternative embodiment, in the step 4, in the pack pre-selection row, according to a second rule, the column to which the pack at the index position belongs is screened out, the pack pre-selection row is unlocked, the pack located in the pack pre-selection row and the column to which the pack belongs is taken as the pack to which the index position belongs, and the thread returns the physical address corresponding to the index position in the pack to which the index position belongs to the application program, which may specifically include the following steps:
traversing each pack in the pack pre-selection row, and performing the following traversing operation:
(41) If the pack state is an empty state, then:
(41-1) obtaining a start index of each pack according to the index and the number of units contained in the pack,
(41-2) adding one to the current number of threads accessed for the pack,
(41-3) updating the pack status to an allocated status,
(41-4) updating the pack currently accessed by the thread to the row number and the column number of the pack,
(41-5) obtaining the logic number of the data packet currently accessed by the thread according to the index and the number of units contained in each pack,
(41-6) obtaining a start index of the thread according to the index and the number of units contained in each pack,
(41-7) unlocking the pack pre-selected row,
(41-8) the thread returns to the application the physical address corresponding to the index location in the pack it is currently accessing;
(42) If the status of the pack is an allocated status and the index is within the index address range of the pack, or if the status of the pack is a just-loaded data status and the index is within the index address range of the pack:
(42-1) adding one to the current number of threads accessed for the pack,
(42-2) updating the pack currently accessed by the thread to the row number and column number of the pack,
(42-3) obtaining the logic number of the data packet currently accessed by the thread according to the index and the number of units contained in each pack,
(42-4) unlocking the pack pre-selected row,
(42-5) the thread returns to the application the physical address in the pack it is currently accessing that corresponds to the index location.
Step 4 represents in the computer execution level that i (0 < = i < wayNum) pack of row id corresponding row is traversed, and the following traversal operation is performed:
a) If the state of the pack accessed by the current thread meets the following condition:
PackState [ i ] [ RowID ]. PackStatus = = EMPTY (corresponding to (41))
The following state update operations are performed on the global state arrays PackState and ThreadPackInfo:
PackState [ i ] [ RowID ]. StartIndex = (index/packSize) × packSize (corresponding to (41-1)),
PackState [ i ] [ RowID ]. RefCnt + + (corresponding to (41-2)),
PackState [ i ] [ RowID ]. PackState = ALLOCATED (corresponding to (41-3)),
ThreadPackInfo [ threadID ]. Lastheadwayid = i (corresponding to (41-4)),
ThreadPackInfo [ threadID ]. Lastackrowid = RowID (corresponding to (41-4)),
ThreadPackInfo [ threadID ]. Lastpack id = index/packSize (corresponding to (41-5)),
ThreadPackInfo [ threadID ]. StartIndex = (index/packSize) × packSize (corresponding to (41-6));
after the updating operation is completed, all packs of the row corresponding to the RowID are unlocked, then the reference of the Unit corresponding to the index is obtained, and the reference is returned:
&MemoryPool[i][RowID].packData[offset]
wherein offset = index% packSize;
b) If the state of the Pack accessed by the current thread satisfies the following combination of the condition A and the condition C, or satisfies the following combination of the condition B and the condition C:
PackState [ i ] [ RowID ]. PackState = = ALLOCATED (condition A)
PackState [ i ] [ RowID ]. PackState = = LOAD _ FROM _ DISK (condition B)
PackState [ i ] [ rowID ]. StartIndex < = index < PackState [ i ] [ rowID ]. StartIndex + PackSize (Condition C)
A global state update operation (corresponding to (42)) is performed as follows:
PackState [ i ] [ RowID ]. RefCnt + + (corresponding to (42-1)),
ThreadPackInfo [ threadID ]. Lastheadwayid = i (corresponding to (42-2)),
ThreadPackInfo [ threadID ]. Lastackrowid = RowID (corresponding to (42-2)),
ThreadPackInfo [ threadID ]. LastPackID = index/packSize (corresponding to (42-3));
after the operation is completed, all packs of the row corresponding to the RowID are unlocked, then the reference of the Unit corresponding to the index is obtained, and the reference is returned:
&MemoryPool[i][RowID].packData[offset]
where offset = index% packSize.
Referring to the above description, in the code corresponding to (41), pack state [ i ] [ RowID ]. Pack state denotes the state of pack in the ith column of the pack pre-selected row, EMPTY denotes an unused state;
the code corresponding to (41-1) is specifically a code obtained by dividing the index by the packSize, rounding down, and multiplying the resultant by the packSize to obtain the start index of the pack;
in the code corresponding to (41-3), ALLOCATED indicates an ALLOCATED status;
the code corresponding to (41-5), specifically, the logical number of the currently accessed packet of the thread is obtained by dividing the index by the packaksize and rounding down;
the code corresponding to (41-6) is specifically the start index of the thread obtained by dividing the index by the padsize, rounding down, and multiplying the result by the padsize;
in the code corresponding to the condition B, LOAD _ FROM _ DISK represents a just-loaded data state;
the code corresponding to (42-3) is specifically the logical number of the packet currently accessed by the thread, which is obtained by dividing the index by the packSize and rounding down.
In the embodiment of the present invention, the second rule is the conditional policy about (41) and (42) above. In an alternative embodiment, when the second rule fails to screen out the column to which the pack at the index position belongs, that is, when no pack at any column in the pack pre-selected row satisfies the conditions of (41) and (42), it indicates that the packet at the index position is not currently located in the data storage pool but located in the virtual memory, which requires performing subsequent data exchange with the virtual memory based on the selection policy to dispatch the packet containing the index position in the virtual memory to a pack in the data storage pool for the current thread to access.
In alternative embodiments, the selection policy may be implemented by the prior art, for example, a selection policy based on LRU algorithm or LIFO algorithm, which is not described herein.
In step 5, the data packet containing the index position in the virtual memory is loaded into the pack for data replacement, which can be implemented by using the prior art and is not described herein again.
In step 5, after loading the data packet containing the index position in the virtual memory into the pack for data replacement and before unlocking the pack preselected row, the memory access management method according to the embodiment of the present invention further includes:
(51) Obtaining the starting index of each pack according to the index and the number of units contained in the pack,
(52) The current number of accessing threads of the pack is increased by one,
(53) The pack state is updated to the just loaded data state,
(54) The pack currently accessed by the thread is updated to the row number and column number of the pack,
(55) Obtaining the logic number of the data packet currently accessed by the thread according to the index and the number of units contained in each pack,
(56) Obtaining the initial index of the thread according to the index and the number of units contained in each pack;
wherein, the computer execution level is expressed as:
PackState [ i ] [ RowID ]. StartIndex = (index/packSize) × packSize (corresponding to (51)),
PackState [ i ] [ RowID ]. RefCnt + + (corresponding to (52)),
PackState [ i ] [ RowID ]. PackState = LOAD _ FROM _ DISK (corresponding to (53)),
ThreadPackInfo [ threadID ]. Lastheadwayid = i (corresponding to (54)),
ThreadPackInfo [ threadID ]. Lastackrowid = RowID (corresponding to (54)),
ThreadPackInfo [ threadID ]. Lastpack id = index/packSize (corresponding to (55)),
ThreadPackInfo [ threadID ]. StartIndex = (index/packSize) × packSize (corresponding to (56)).
Of the codes corresponding to (51), the index is specifically divided by the packSize, rounded down, and multiplied by the packSize to obtain the start index of the pack;
the code corresponding to (55) is specifically the logical number of the currently accessed packet of the thread after dividing the index by the packSize and rounding down;
the code corresponding to (56) specifically divides the index by the padsize, rounds it down, and multiplies it by the padsize to obtain the start index of the thread.
In this embodiment of the present invention, the step 5 of returning, by the thread to the application program, the physical address corresponding to the index position in the pack after data replacement includes: the thread returns to the application the physical address in the pack it is currently accessing that corresponds to the index location.
Wherein the following operations are included, which are performed at the computer execution level:
&MemoryPool[selectWayID][RowID].packData[offset]
where offset = index% packSize, where selectWayID is the WayID calculated according to the selection policy.
In addition to the above description, the memory access management method according to the embodiment of the present invention further includes:
when any thread completes access to the data storage pool and exits the multi-threaded environment, the number of threads of the pack currently accessed by the thread is reduced by one.
By doing so, it can be ensured that other threads that have not completed data access can obtain the mutex lock in time.
Wherein, the computer execution level is expressed as:
wayID=ThreadPackInfo[threadID].lastPackWayID,
rowID=ThreadPackInfo[threadID].lastPackRowID,
PackState[wayID][rowID].refCnt--。
the embodiment of the invention also provides a memory access management system, which comprises a data storage pool and a data storage pool access management module. The data storage pool is located in the memory and used for being accessed by at least one thread, the application program accesses the data storage pool through the thread, the data storage pool comprises a plurality of packs arranged in at least two rows and at least two columns, each pack comprises at least two units, the number of the units in each pack is equal, and when the number of the threads is at least two, each thread can access the data storage pool in parallel; the data in each unit in each pack represents the logical address thereof by the index of the data, and the index of the data is continuous among the units in each pack; the data stored in one pack is a data packet.
A data storage pool access management module to perform:
when the index position to be accessed by a certain thread is located in the data packet currently accessed by the thread, the thread directly returns the physical address corresponding to the index position in the pack currently accessed by the thread to the application program;
when the index position is not located in the data packet currently accessed by the thread, obtaining a pack pre-selection line of the index position according to a first rule, and locking the pack pre-selection line by using a mutual exclusion lock;
in a pack pre-selection row, screening out a column to which a pack at the index position belongs according to a second rule, unlocking the pack pre-selection row, taking the pack positioned on the pack pre-selection row and the column to which the pack belongs as the pack to which the index position belongs, and returning a physical address corresponding to the index position in the pack to which the index position belongs to the thread to an application program;
and when the second rule fails to screen out the column to which the pack at the index position belongs, selecting the pack for data replacement in a pack pre-selection row based on a selection strategy, loading the data packet in the pack for data replacement into the virtual memory, loading the data packet containing the index position in the virtual memory into the pack for data replacement, unlocking the pack pre-selection row, and returning the physical address corresponding to the index position in the pack after data replacement to the application program by the thread.
Embodiments of the present invention also provide a non-volatile computer-readable storage medium, which stores instructions that, when executed by a processor, cause the processor to perform the steps of the memory access management method as described in the foregoing description.
An embodiment of the present invention further provides an electronic device for executing the memory access management method, where as shown in fig. 3, the electronic device includes: at least one processor 1, memory 2, a virtual memory carrier 3, and storage 4. The memory 2, the virtual memory carrier 3 and the storage 4 are communicatively connected to the at least one processor 1, for example by a bus. The memory 4 stores instructions executable by the at least one processor 1 to cause the at least one processor 1 to perform the steps of the memory access management method as described in the foregoing description. The virtual memory is disposed in a virtual memory carrier 3, where the virtual memory carrier 3 is, for example, a magnetic disk, a hard disk, and the hard disk is, for example, a solid state disk, a mechanical hard disk, a hybrid hard disk, and the like. The virtual memory carrier 3 (e.g. a hard disk, etc.) may also be used as the storage 4 to store instructions for executing each step in the memory access management method, and the storage 4 may also be a storage device independent of the virtual memory carrier 3 and dedicated to store instructions for executing each step in the memory access management method, for example, a storage device different from other hard disks, etc. except the virtual memory carrier 3.
The memory access management method and the memory access management system of the embodiment of the invention are used as an intermediate layer between an application program and a memory, a data storage pool is independently divided from the memory storage space and is independently managed, the application program does not need to directly perform address management and operation on the divided memory storage space, and only needs to inform a thread of a subscript index of data to be accessed, so that the corresponding physical address position in the memory can be obtained by using the memory access management method and the memory access management system of the embodiment of the invention. The embodiment of the invention solely divides the data storage pool in the memory aiming at the application program, the thread operating the data storage pool does not share the address space of the data storage pool with all processes on the operating system, and simultaneously, the subscript index of the data and the initial index of the data packet all adopt the mode of logical address, thereby expanding the virtual memory by means of the space capacity of the physical disk and exchanging data with the pack of the data storage pool, realizing the purpose of expanding the address space of the data to the maximum extent on the premise of the maximum data volume which can be accommodated by the virtual memory, and solving the problem of the requirement of the application program on the large-memory data. In the embodiment of the invention, the problem of common data access conflict in a single-thread or multi-thread access mode can be effectively avoided by using the mutual exclusion lock, so that the problem that the application program cannot run due to insufficient memory space can be well solved.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (10)

1. A memory access management method, comprising:
the method comprises the steps that a data storage pool is established in a memory for at least one thread to access, an application program accesses the data storage pool through the thread, the data storage pool comprises a plurality of data storage area packs which are arranged in at least two rows and at least two columns, each pack comprises at least two data storage unit units, the number of the units in each pack is equal, and when the number of the threads is at least two, each thread can access the data storage pool in parallel; the data in each unit in each pack is represented by the index of the data to represent the logical address, and the index of the data is continuous among the units in each pack; the data stored by one pack is a data packet;
when the index position to be accessed by a certain thread is located in the data packet currently accessed by the thread, the thread directly returns the physical address corresponding to the index position in the pack currently accessed by the thread to the application program;
when the index position is not located in the data packet currently accessed by the thread, obtaining a pack pre-selection line of the index position according to a first rule, and locking the pack pre-selection line by using a mutual exclusion lock;
in a pack pre-selection row, screening out a column to which a pack at the index position belongs according to a second rule, unlocking the pack pre-selection row, taking the pack positioned on the pack pre-selection row and the column to which the pack belongs as the pack to which the index position belongs, and returning a physical address corresponding to the index position in the pack to which the index position belongs to the thread to an application program;
and when the second rule fails to screen out the column to which the pack at the index position belongs, selecting the pack for data replacement in a pack pre-selection row based on a selection strategy, loading the data packet in the pack for data replacement into the virtual memory, loading the data packet containing the index position in the virtual memory into the pack for data replacement, unlocking the pack pre-selection row, and returning the physical address corresponding to the index position in the pack after data replacement to the application program by the thread.
2. The memory access management method of claim 1, further comprising determining whether an index location to be accessed by a thread is located in a packet currently accessed by the thread by:
comparing the index with the index address range of the data packet currently accessed by the thread, wherein if the index is located in the index address range of the data packet currently accessed by the thread, the index position is located in the data packet currently accessed by the thread, otherwise, the index position is not located in the data packet currently accessed by the thread; wherein,
the index address range of the data packet is the range from the start index address to the end index address of the data packet, wherein the end index address of the data packet is determined by the start index address of the data packet and the number of units in the pack.
3. The memory access management method of claim 1, wherein obtaining the pack pre-selected row of index locations according to a first rule comprises:
according to the index and the number of units contained in each pack, obtaining the logic number of a data packet where the data at the index position is located;
and obtaining a pack pre-selection row of the index position according to the logic number of the data packet where the data of the index position is located and the total number of packs contained in each column of the data storage pool.
4. The memory access management method according to claim 3, wherein after obtaining the logical number of the packet where the data at the index location is located, the method further comprises:
and if the logic number of the data packet where the data at the index position is located is not the logic number of the data packet currently accessed by the thread, reducing the thread number of the pack currently accessed by the thread by one.
5. The memory access management method according to claim 1, wherein the screening out the column to which the pack at the index position belongs in the pack pre-selected row according to a second rule, unlocking the pack pre-selected row, and using the pack at the pack pre-selected row and the column to which the pack belongs as the pack to which the index position belongs, the thread returning the physical address corresponding to the index position in the pack to which the index position belongs to the application program, comprises:
traversing each pack in the pack pre-selection row, and performing the following traversal operations:
if the pack state is an empty state, then:
obtaining the starting index of each pack according to the index and the number of units contained in the pack,
the number of currently accessed threads of the pack is increased by one,
the pack state is updated to the allocated state,
the pack currently accessed by the thread is updated with the row number and column number of the pack,
obtaining the logic number of the data packet currently accessed by the thread according to the index and the number of units contained in each pack,
obtaining the initial index of the thread according to the index and the number of units contained in each pack,
the pack pre-selected row is unlocked and,
the thread returns the physical address corresponding to the index position in the pack currently accessed by the thread to the application program;
if the status of the pack is an allocated status and the index is within the index address range of the pack, or if the status of the pack is a just-loaded data status and the index is within the index address range of the pack:
the current number of accessing threads of the pack is increased by one,
the pack currently accessed by the thread is updated with the row number and column number of the pack,
obtaining the logic number of the data packet currently accessed by the thread according to the index and the number of units contained in each pack,
the pack pre-selected row is unlocked and,
the thread returns to the application the physical address in the pack it is currently accessing that corresponds to the index location.
6. The memory access management method according to claim 1, characterized in that:
after the data packet containing the index position in the virtual memory is loaded into the pack for data replacement, and before the pack pre-selected row is unlocked, the method further comprises the following steps:
obtaining the starting index of each pack according to the index and the number of units contained in the pack,
the current number of accessing threads of the pack is increased by one,
the pack state is updated to the just loaded data state,
the pack currently accessed by the thread is updated with the row number and column number of the pack,
obtaining the logic number of the data packet currently accessed by the thread according to the index and the number of units contained in each pack,
obtaining the initial index of the thread according to the index and the number of units contained in each pack;
the thread returns the physical address corresponding to the index position in the pack after data replacement to the application program, and the physical address comprises: the thread returns to the application the physical address corresponding to the index location in the pack it is currently accessing.
7. The memory access management method of claim 1, further comprising:
when any thread completes access to the data storage pool, and exits the multi-threaded environment,
the number of threads of the pack currently accessed by the thread is reduced by one.
8. A memory access management system, comprising:
the data storage pool is located in the memory for being accessed by at least one thread, the application program accesses the data storage pool through the thread, the data storage pool comprises a plurality of data storage area packs which are arranged in at least two rows and at least two columns, each pack comprises at least two data storage unit units, the number of the units in each pack is equal, and when the number of the threads is at least two, each thread can access the data storage pool in parallel; the data in each unit in each pack is represented by the index of the data to represent the logical address, and the index of the data is continuous among the units in each pack; the data stored by one pack is a data packet;
a data storage pool access management module to perform:
when the index position to be accessed by a certain thread is located in the data packet currently accessed by the thread, the thread directly returns the physical address corresponding to the index position in the pack currently accessed by the thread to the application program;
when the index position is not located in the data packet currently accessed by the thread, obtaining a pack pre-selection line of the index position according to a first rule, and locking the pack pre-selection line by using a mutual exclusion lock;
in the pack pre-selection row, screening out the column to which the pack at the index position belongs according to a second rule, unlocking the pack pre-selection row, taking the pack positioned on the pack pre-selection row and the column to which the pack belongs as the pack to which the index position belongs, and returning the physical address corresponding to the index position in the pack to which the index position belongs to the thread to the application program;
and when the second rule fails to screen out the column to which the pack at the index position belongs, selecting the pack for data replacement in a pack pre-selection row based on a selection strategy, loading the data packet in the pack for data replacement into the virtual memory, loading the data packet containing the index position in the virtual memory into the pack for data replacement, unlocking the pack pre-selection row, and returning the physical address corresponding to the index position in the pack after data replacement to the application program by the thread.
9. A non-transitory computer readable storage medium storing instructions which, when executed by a processor, cause the processor to perform the steps in the memory access management method of any of claims 1 to 7.
10. An electronic device, comprising:
at least one processor;
a memory and virtual memory carrier in communicative connection with the at least one processor; and (c) a second step of,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to cause the at least one processor to perform the steps of the memory access management method of any one of claims 1 to 7.
CN202111078307.XA 2021-09-15 2021-09-15 Memory access management method and system Active CN113778908B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111078307.XA CN113778908B (en) 2021-09-15 2021-09-15 Memory access management method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111078307.XA CN113778908B (en) 2021-09-15 2021-09-15 Memory access management method and system

Publications (2)

Publication Number Publication Date
CN113778908A CN113778908A (en) 2021-12-10
CN113778908B true CN113778908B (en) 2022-10-11

Family

ID=78843960

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111078307.XA Active CN113778908B (en) 2021-09-15 2021-09-15 Memory access management method and system

Country Status (1)

Country Link
CN (1) CN113778908B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102169459A (en) * 2010-11-29 2011-08-31 北京握奇数据系统有限公司 Method, device and intelligent card for accessing data
CN110554911A (en) * 2018-05-30 2019-12-10 阿里巴巴集团控股有限公司 Memory access and allocation method, memory controller and system

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP6880769B2 (en) * 2017-01-24 2021-06-02 富士通株式会社 Information processing equipment, control programs and information processing methods

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102169459A (en) * 2010-11-29 2011-08-31 北京握奇数据系统有限公司 Method, device and intelligent card for accessing data
CN110554911A (en) * 2018-05-30 2019-12-10 阿里巴巴集团控股有限公司 Memory access and allocation method, memory controller and system

Also Published As

Publication number Publication date
CN113778908A (en) 2021-12-10

Similar Documents

Publication Publication Date Title
US7716448B2 (en) Page oriented memory management
CN104115133A (en) Data migration for composite non-volatile storage device
US20090031315A1 (en) Scheduling Method and Scheduling Apparatus
WO2014141566A1 (en) Semiconductor device and entry address write/read method for semiconductor device
US11074179B2 (en) Managing objects stored in memory
CN113835901A (en) Read lock operation method, write lock operation method and system
CN106716348A (en) Shared resources in a data processing appartus for executing a plurality of threads
CN111881643A (en) Integrated circuit layout optimization method based on frequency domain electromagnetic response and capable of automatically starting and stopping process
CN111880940A (en) Data processing method, device, equipment and storage medium in storage system
KR20110060815A (en) Method, device and storage system for building and allowing cache access
CN113778908B (en) Memory access management method and system
van der Vegt et al. A parallel compact hash table
CN102855122A (en) Processing pipeline control
CN114116194A (en) Memory allocation method and system
CN101375257B (en) Cache locking without interference from normal allocation
CN110990299A (en) Non-regular group associative cache group address mapping method
CN110162483B (en) Static memory defragmentation method, device, computer equipment and storage medium
CN113377549B (en) Queue data control method, system and queue data structure
CN112988064B (en) Concurrent multitask-oriented disk graph processing method
CN109783145A (en) A method of multi-functional embedded system of the creation based on multi-mapping
US20070074193A1 (en) Device, system and method for maintaining a pre-defined number of free registers within an instrumented program
CN108563507A (en) A kind of EMS memory management process, device, equipment and readable storage medium storing program for executing
US20130166887A1 (en) Data processing apparatus and data processing method
CN113868292A (en) Data reading method, data writing method, device and system
US7447875B1 (en) Method and system for management of global queues utilizing a locked state

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant