Real-time replacement mechanism and mapping management method of internal and external memory in limited resource system
By defining the storage management structure and real-time permutation mechanism of memory and external memory in a finite resource system, the problem of insufficient hardware storage resources is solved, and the memory space expansion and efficient execution of tasks are achieved.
Patent Information
- Application Number
- CN202111630744.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2041-12-28
AI Technical Summary
In limited resource systems, insufficient storage resources of hardware memory lead to limited system function operation. Existing methods such as extended memory or data compression algorithms have problems with high cost and poor stability.
By defining the storage management structure of memory and external memory, including the page allocation table of the memory management page and the external memory management page, real-time permutation mechanism and mapping management between memory and external memory, provision storage resources as needed, and expand the available memory space.
It effectively expands the memory space of the finite resource system, realizes the need to complete a large number of intensive tasks under the condition of memory resource constraints, and improves the operating efficiency and stability of the system.
Smart Images

Figure CN114281721B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of internal and external memory reading and writing optimization, and in particular relates to a real-time replacement mechanism and mapping management method for internal and external memories in a limited resource system. Background Art
[0002] System-level software runtime requires direct access to and write access to hardware memory to support system functionality. Hardware memory resources are limited in some applications, and specific system functions often require more than a certain minimum amount of storage space. Specifically, hardware memory typically consists of two types: internal and external. Most core functions frequently read and write data structures, making internal memory, which is fast and small in capacity, suitable for this purpose. External memory, on the other hand, is slower but has a larger capacity and is resistant to power failure, making it suitable for storing large amounts of data that need to be recorded.
[0003] In actual applications, certain system functions require frequent reading and writing of data, thus requiring storage support far exceeding the internal memory capacity. Alternatively, the expected internal memory capacity planned during hardware planning is less than the internal memory capacity actually required by the system function, resulting in the internal memory capacity limiting the operation of the system function. Common methods to address this issue include: expanding the internal memory capacity using reserved slots, or expanding the slots via an expansion bus and connecting memory modules with compatible protocols, or expanding network-type memory devices using network-compatible protocols. These various methods increase system costs and place requirements on system compatibility and scalability, thus having certain limitations. Alternatively, a software solution can be employed, namely: using a data compression algorithm to compress structured data in memory. The compression effect is reflected in the compression ratio, which is highly uncertain and depends on whether the data structure and content are suitable for compression. While this method can alleviate memory space limitations to a certain extent, it suffers from poor stability. Summary of the Invention
[0004] In view of the defects of the prior art, the present invention provides a real-time replacement mechanism and mapping management method for internal and external memory in a limited resource system, which can effectively solve the above problems.
[0005] The technical solution adopted in the present invention is as follows:
[0006] The present invention provides a real-time internal and external memory replacement mechanism and mapping management method in a limited resource system, comprising the following steps:
[0007] Step 1: Define the storage management structure of the memory space, including:
[0008] Step 1.1, assume that the storage capacity of the memory space is V1; based on the storage capacity of the memory space V1, determine the storage capacity of a single memory page as W1, thereby dividing the memory space into n = V1 / W1 memory pages, which are represented in sequence as: mem_Page_1, mem_Page_2, ..., mem_Page_n;
[0009] In step 1.2, the first memory page mem_Page_1 is called the memory management page mem_Page_1; the second memory page mem_Page_2 to the nth memory page mem_Page_n are called memory storage pages;
[0010] Step 1.3, define the management structure of the memory management page mem_Page_1;
[0011] The memory management page mem_Page_1 is divided into an external memory management structure storage area and a global variable storage area; the external memory management structure storage area is used to call the page allocation table of the external memory management page Page_1; the global variable storage area is used to store global variables for system operation, including page identifiers of each memory storage page, which are used to identify the available state of each memory storage page, that is, to identify the unavailable state or available state of the memory storage page;
[0012] Step 2: Define the storage management structure of the external memory space by:
[0013] Step 2.1, define the storage capacity of a single external memory page Page to be equal to the storage capacity of a single internal memory page mem_Page, both are W1;
[0014] Assume that the storage capacity of the external memory space is V2, and thus the external memory space is divided into m = V2 / W1 external memory pages, which are represented as: Page_1, Page_2, ..., Page_m;
[0015] In step 2.2, the first external memory page Page_1 is called the external memory management page Page_1; the second external memory page Page to the mth external memory page Page_m are called external memory storage pages;
[0016] Step 2.3, define the management structure of the external memory management page Page_1:
[0017] The external memory management page Page_1 is used to store a page allocation table formed by the page management information of Page_1, Page_2, ..., Page_m;
[0018] Wherein: for any external memory storage page Page_i in Page_1, Page_2, ..., Page_m, i = 1, 2, 3, ..., m, the external memory management page Page_1 stores the following page management information: page attribute information and task attribute information;
[0019] The page attribute information includes the page number; the task attribute information includes the task number, task priority, dirty data mechanism identifier, dirty data identifier, real-time mechanism identifier, page data task read and write start time and page data task read and write duration;
[0020] in:
[0021] Page number, which is the unique page identifier of the external memory storage page;
[0022] The task number identifies the number of the task reading and writing corresponding to the page data, so that the external memory storage page and the task correspond to each other. Among them, one external memory storage page uniquely corresponds to one task number; one task number can correspond to multiple external memory storage pages;
[0023] Task priority, used to identify the read and write priority of the task corresponding to the page, providing a reference for the page allocation strategy;
[0024] The dirty data mechanism flag indicates whether a page is subject to the "dirty" data mechanism, which invalidates modifications and clears changes. Dirty data refers to data that cannot be modified by other tasks during a minimum operation unit, or task read or write. The data is exclusive within this minimum operation unit. The implementation principle is: after a series of normal data modification operations are performed in this minimum operation unit, the data flag is calculated. The data flag represents the data status. If the data flag changes at the start and end of a task read or write, it indicates that the data has changed during the task, and is therefore defined as dirty data.
[0025] Real-time mechanism identifier, indicating whether the page is applicable to the real-time data mechanism that determines the effective start and end time;
[0026] The page data task reading and writing start time, which indicates the starting time when the page begins to be used;
[0027] Page data task read and write duration, which indicates the maximum duration for which page data is valid. This is used to determine whether the page data is within its life cycle, thereby ensuring the effectiveness of real-time data processing.
[0028] Step 2.4, define the storage structure of the external memory storage pages Page_2, ..., Page_m, including:
[0029] Step 2.4.1, the page headers of the pages Page_2, ..., Page_m are stored in the external memory to store the corresponding page attribute information and task attribute information;
[0030] Step 2.4.2, after the page header, the variable identifiers of the page data are stored continuously, which are used to address and read variables and write variables by address;
[0031] Step 2.4.3: Starting from the end of the page and gradually extending to lower addresses, write the variable data content; where: the variable identifier and variable content are stored in pairs;
[0032] Step 3: Start the task and allocate storage resources. The method is as follows:
[0033] Step 3.1, during the task scheduling process, when a new task needs to be started new When configuring the task attribute information;
[0034] Step 3.2, determine the new task new The number of pages required for operation is s;
[0035] Step 3.3, transfer the page allocation table stored in the current external memory management page Page_1 to the memory management page mem_Page_1;
[0036] Step 3.4, read the page allocation table, obtain the s external memory storage pages that are not assigned to the task, and assign the s external memory storage pages to the new task task new , the allocation method is:
[0037] The new task task new The task attribute information is written into the page management information of the corresponding external memory storage page in the page allocation table, thereby obtaining a new page allocation table;
[0038] Step 3.5: Determine whether there is a task read / write operation to be executed. If so, execute step 4. If not, write the new page allocation table to the external memory management page Page_1 of the external memory space.
[0039] This completes the task startup and storage resource allocation process;
[0040] Step 4: Real-time swapping mechanism between internal and external memory during task reading and writing:
[0041] Step 4.1, during the task scheduling process, when a task task1 needs to be scheduled for execution to perform a read / write operation, the task number task_num1 of task task1 is obtained;
[0042] Step 4.2, transfer the page allocation table stored in the current external memory management page Page_1 into the external memory management structure storage area of the memory management page mem_Page_1; wherein the global variable storage area of the memory management page mem_Page_1 stores the system global variables and the page identifiers of each memory storage page;
[0043] Step 4.3, according to the task number task_num1, search the page allocation table in the memory management page mem_Page_1, and read the page number Page_num1 of the external memory storage page corresponding to the task number task_num1 from the page allocation table;
[0044] Step 4.4, based on the page identifiers of each memory storage page, traverse each memory storage page in the memory space that has a page identifier that is in an available state, and determine whether there is a memory storage page with page number Page_num1; if not, execute steps 4.5 to 4.7; if so, execute step 4.8;
[0045] Step 4.5, traverse each external memory storage page in the external memory space to determine whether there is an external memory storage page with page number Page_num1; if not, an error is returned, and the task scheduling strategy starts the task of this task and performs the storage resource allocation process, that is, executing step 3, or proceeding to the next task reading and writing process;
[0046] If it exists, go to step 4.6;
[0047] Step 4.6: Read the external memory page with page number Page_num1, obtain the priority of task 1, and determine whether to execute task 1 according to the task scheduling policy set and the task priority. If task 1 needs to be executed, execute step 4.7.
[0048] If yes, proceed to step 4.7;
[0049] Step 4.7: Create a mapping between the memory storage page and the external memory storage page. The method is:
[0050] Locate the external memory storage page with the page number Page_num1 in the external memory space, and load the external memory storage page with the page number Page_num1 into a certain memory storage page in the internal memory space. At this time, the page number of the memory storage page is also Page_num1, that is, a mapping between the internal memory storage page and the external memory storage page is established;
[0051] Then proceed to step 4.8;
[0052] Step 4.8: In the memory space, read the memory storage page with page number Page_num1, obtain the page content management information, and determine whether to execute the dirty data mechanism and the real-time mechanism based on the dirty data mechanism identifier and the real-time mechanism identifier. If not, execute step 4.10.
[0053] If yes, go to step 4.9;
[0054] Step 4.9: Check whether the data in the memory storage page with page number Page_num1 is dirty data and whether it meets the page timeliness requirements; if it is not dirty data and meets the page timeliness requirements, execute step 4.10;
[0055] If the data is dirty, the dirty data processing process is executed; if the page timeliness requirements are not met, the real-time mechanism timeout processing process is executed;
[0056] The dirty data processing process is the same as the real-time mechanism timeout processing process, which is: clear the corresponding page allocation information in the page allocation table of the memory management page mem_Page_1, set the page flag of the corresponding memory storage page to unavailable; then execute step 4.10;
[0057] Step 4.10, transfer the page allocation table stored in the memory management page mem_Page_1 to the external memory management page Page_1;
[0058] Step 4.11, execute the reading and writing process of this task;
[0059] During the reading and writing process of this task, the memory management page mem_Page_1 no longer stores the page allocation table. Instead, the storage space of the memory management page mem_Page_1 is used to store temporary global variables.
[0060] During the task reading and writing process, normal data modification will also change the corresponding dirty data flag. If the dirty data flag does not correspond to the page data, it is determined that a third party has modified the data in the minimum task unit, that is, the page is dirty data.
[0061] Step 4.12: After the reading and writing of this task is completed, the following method is used to replace the memory page with the external memory page:
[0062] Step 4.12.1, load the page allocation table stored in the external memory management page Page_1 into the memory management page mem_Page_1;
[0063] Step 4.12.2: Based on the task number task_num1 and the page number Page_num1, the page allocation table is searched to determine whether page allocation information corresponding to the task number task_num1 and the page number Page_num1 exists. If not, an error is returned, and the task scheduling policy starts the task and performs the storage resource allocation process, that is, executing step 3, or proceeding to the next task read / write process.
[0064] If it exists, go to step 4.12.3;
[0065] Step 4.12.3: Use the dirty data mechanism to determine whether the memory storage page with page number Page_num1, which is loaded at the start of the task read / write and the page at the completion of the task read / write, constitutes dirty data. Write a dirty data flag to the corresponding page of the page allocation table stored in the memory management page mem_Page_1, thereby forming a new page allocation table.
[0066] If dirty data is generated, clear the memory storage page with page number Page_num1 and then execute step 4.12.4;
[0067] If no dirty data is generated, the memory storage page with page number Page_num1 is transferred to the external memory storage page with page number Page_num1; then step 4.12.4 is executed;
[0068] Step 4.12.4, load the latest page allocation table stored in the memory management page mem_Page_1 to the external memory management page Page_1;
[0069] Then, the memory management page mem_Page_1 no longer stores the page allocation table, but uses the storage space of the memory management page mem_Page_1 to store temporary global variables.
[0070] Preferably, step 4.11 executes the reading and writing process of this task, specifically including the addressing and reading and writing operations of variable data, including:
[0071] Step 4.11.1, define the addressing identifier var_addr(page, num), where page is the page number and num is the variable number;
[0072] Define variable length identifier var_len(page,num);
[0073] Step 4.11.2, based on the addressing identifier var_addr(page, num) and the variable length identifier var_len(page, num), search the memory storage page with page number Page_num_f1 and locate the variable identification data of this read / write;
[0074] Perform data read and write operations on variable identification data.
[0075] Preferably, the page attribute information further includes: a page name, which is used to store the name information of the page data; the task attribute information further includes: a task name, which is used to store the name information related to the task.
[0076] Preferably, the task attribute information further includes: a sharing flag and a sharing data length;
[0077] Sharing flag, indicating whether the page data contains data that needs to be shared;
[0078] Shared data length, indicating the shared data length.
[0079] The present invention provides a real-time internal and external memory replacement mechanism and mapping management method for a limited resource system, which has the following advantages:
[0080] The present invention provides a real-time replacement mechanism for internal and external memory in a limited resource system and a mapping management method, realizing a mapping algorithm for data during the function runtime of a computer system. By defining a mechanism for orderly and accurate mapping of runtime data between internal and external memory space and real-time replacement on demand, the memory space available during runtime is expanded, effectively meeting the technical requirement of completing a large number of intensive tasks under conditions of limited memory resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0081] Figure 1 A diagram showing the structure and correspondence between the external storage space and the internal storage space provided by the present invention;
[0082] Figure 2 A diagram showing the spatial organization and management of external memory pages provided by the present invention and their corresponding relationships;
[0083] Figure 3 This is a corresponding relationship diagram of the memory management page, internal memory storage page and external memory storage page provided by the present invention. DETAILED DESCRIPTION
[0084] In order to make the technical problems, technical solutions and beneficial effects solved by the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0085] When the computer system software or operating system is running, the execution of system functions and operations requires the support of corresponding data storage. Since the system-level software needs to access data frequently during operation, and needs to complete read and write operations in a relatively short time (the data reading and writing of an independent system task is referred to as task reading and writing), the fast reading and writing, large bandwidth, and high throughput of the internal memory supported by the multi-channel parallel bus are very suitable for system-level task reading and writing. The complex operation mechanism of some system functions requires a large amount of well-designed complex structured data support; in some application scenarios, the physical memory capacity is limited due to hardware conditions, such as the high-intensity industrial control environment where only single-chip microcomputers or MCUs can be used. Therefore, it is necessary to complete the reading and writing of complex functions to support tasks, and there is a situation where physical memory resources are limited. At this time, it is not feasible to expand the physical memory, and compressed data is even less deterministic. To solve the above problems, the present invention provides a real-time replacement mechanism and mapping management method for internal and external memory in a limited resource system, realizes a mapping algorithm for data when a computer system function is running, and expands the memory space available at runtime by defining a mechanism for orderly and accurate mapping of operating data between the internal memory space and the external memory space and real-time replacement on demand, effectively meeting the technical requirements for completing a large number of intensive tasks under the condition of limited memory resources.
[0086] The present invention provides a real-time internal and external memory replacement mechanism and mapping management method for a limited resource system. The prerequisites for its effective implementation are based on the following assumptions:
[0087] (1) The task units that the system needs to execute are independent of each other (i.e., there is no logical relationship between tasks and no sharing of key data);
[0088] (2) The maximum memory required for reading and writing by a single or several tasks can be supported by the system physical memory;
[0089] (3) The processing of task units must be rapid and uninterrupted, and there must be a certain tolerance for switching between task units;
[0090] (4) The system's task units are numerous and dense, or have sudden or unpredictable idle states.
[0091] The present invention provides a real-time internal and external memory replacement mechanism and mapping management method for a limited resource system, comprising the following steps:
[0092] Step 1: Define the storage management structure of the memory space, including:
[0093] Step 1.1, assume that the storage capacity of the memory space is V1; based on the storage capacity of the memory space V1, determine the storage capacity of a single memory page as W1, thereby dividing the memory space into n = V1 / W1 memory pages, which are represented in sequence as: mem_Page_1, mem_Page_2, ..., mem_Page_n;
[0094] In step 1.2, the first memory page mem_Page_1 is called the memory management page mem_Page_1; the second memory page mem_Page_2 to the nth memory page mem_Page_n are called memory storage pages;
[0095] Step 1.3, define the management structure of the memory management page mem_Page_1;
[0096] The memory management page mem_Page_1 is divided into an external memory management structure storage area and a global variable storage area; the external memory management structure storage area is used to call the page allocation table of the external memory management page Page_1; the global variable storage area is used to store global variables for system operation, including page identifiers of each memory storage page, which are used to identify the available state of each memory storage page, that is, to identify the unavailable state or available state of the memory storage page;
[0097] Step 2: Define the storage management structure of the external memory space by:
[0098] Step 2.1, define the storage capacity of a single external memory page Page to be equal to the storage capacity of a single internal memory page mem_Page, both are W1;
[0099] Assume that the storage capacity of the external memory space is V2, and thus the external memory space is divided into m = V2 / W1 external memory pages, which are represented as: Page_1, Page_2, ..., Page_m;
[0100] In step 2.2, the first external memory page Page_1 is called the external memory management page Page_1; the second external memory page Page to the mth external memory page Page_m are called external memory storage pages;
[0101] Step 2.3, define the management structure of the external memory management page Page_1:
[0102] The external memory management page Page_1 is used to store a page allocation table formed by the page management information of Page_1, Page_2, ..., Page_m;
[0103] Wherein: for any external memory storage page Page_i in Page_1, Page_2, ..., Page_m, i = 1, 2, 3, ..., m, the external memory management page Page_1 stores the following page management information: page attribute information and task attribute information;
[0104] The page attribute information includes the page number; the task attribute information includes the task number, task priority, dirty data mechanism identifier, dirty data identifier, real-time mechanism identifier, page data task read and write start time and page data task read and write duration;
[0105] in:
[0106] Page number, which is the unique page identifier of the external memory storage page;
[0107] The task number identifies the number of the task reading and writing corresponding to the page data, so that the external memory storage page and the task correspond to each other. Among them, one external memory storage page uniquely corresponds to one task number; one task number can correspond to multiple external memory storage pages;
[0108] Task priority, used to identify the read and write priority of the task corresponding to the page, providing a reference for the page allocation strategy;
[0109] The dirty data mechanism flag indicates whether a page is subject to the "dirty" data mechanism, which invalidates modifications and clears changes. Dirty data refers to data that cannot be modified by other tasks during a minimum operation unit, or task read or write. The data is exclusive within this minimum operation unit. The implementation principle is: after a series of normal data modification operations are performed in this minimum operation unit, the data flag is calculated. The data flag represents the data status. If the data flag changes at the start and end of a task read or write, it indicates that the data has changed during the task, and is therefore defined as dirty data.
[0110] Real-time mechanism identifier, indicating whether the page is applicable to the real-time data mechanism that determines the effective start and end time;
[0111] The page data task reading and writing start time, which indicates the starting time when the page begins to be used;
[0112] Page data task read and write duration, which indicates the maximum duration for which page data is valid. This is used to determine whether the page data is within its life cycle, thereby ensuring the effectiveness of real-time data processing.
[0113] The page attribute information also includes: page name, which is used to store the name information of the page data;
[0114] The task attribute information also includes: task name, which is used to store task-related name information. The task attribute information also includes: sharing flag and shared data length;
[0115] Sharing flag, indicating whether the page data contains data that needs to be shared;
[0116] Shared data length, indicating the shared data length.
[0117] Step 2.4, define the storage structure of the external memory storage pages Page_2, ..., Page_m, including:
[0118] Step 2.4.1, the page headers of the pages Page_2, ..., Page_m are stored in the external memory to store the corresponding page attribute information and task attribute information;
[0119] Step 2.4.2, after the page header, the variable identifiers of the page data are stored continuously, which are used to address and read variables and write variables by address;
[0120] Step 2.4.3: Starting from the end of the page and gradually extending to lower addresses, write the variable data content; where: the variable identifier and variable content are stored in pairs;
[0121] Step 3: Start the task and allocate storage resources. The method is as follows:
[0122] Step 3.1, during the task scheduling process, when a new task needs to be started new When configuring the task attribute information;
[0123] Step 3.2, determine the new task new The number of pages required for operation is s;
[0124] Step 3.3, transfer the page allocation table stored in the current external memory management page Page_1 to the memory management page mem_Page_1;
[0125] Step 3.4, read the page allocation table, obtain the s external memory storage pages that are not assigned to the task, and assign the s external memory storage pages to the new task task new , the allocation method is:
[0126] The new task task new The task attribute information is written into the page management information of the corresponding external memory storage page in the page allocation table, thereby obtaining a new page allocation table;
[0127] Step 3.5: Determine whether there is a task read / write operation to be executed. If so, execute step 4. If not, write the new page allocation table to the external memory management page Page_1 of the external memory space.
[0128] This completes the task startup and storage resource allocation process;
[0129] Step 4: Real-time swapping mechanism between internal and external memory during task reading and writing:
[0130] Step 4.1, during the task scheduling process, when a task task1 needs to be scheduled for execution to perform a read / write operation, the task number task_num1 of task task1 is obtained;
[0131] Step 4.2, transfer the page allocation table stored in the current external memory management page Page_1 into the external memory management structure storage area of the memory management page mem_Page_1; wherein the global variable storage area of the memory management page mem_Page_1 stores the system global variables and the page identifiers of each memory storage page;
[0132] Step 4.3, according to the task number task_num1, search the page allocation table in the memory management page mem_Page_1, and read the page number Page_num1 of the external memory storage page corresponding to the task number task_num1 from the page allocation table;
[0133] Step 4.4, based on the page identifiers of each memory storage page, traverse each memory storage page in the memory space that has a page identifier that is in an available state, and determine whether there is a memory storage page with page number Page_num1; if not, execute steps 4.5 to 4.7; if so, execute step 4.8;
[0134] Step 4.5, traverse each external memory storage page in the external memory space to determine whether there is an external memory storage page with page number Page_num1; if not, an error is returned, and the task scheduling strategy starts the task of this task and performs the storage resource allocation process, that is, executing step 3, or proceeding to the next task reading and writing process;
[0135] If it exists, go to step 4.6;
[0136] Step 4.6: Read the external memory page with page number Page_num1, obtain the priority of task 1, and determine whether to execute task 1 according to the task scheduling policy set and the task priority. If task 1 needs to be executed, execute step 4.7.
[0137] If yes, proceed to step 4.7;
[0138] Step 4.7: Create a mapping between the memory storage page and the external memory storage page. The method is:
[0139] Locate the external memory storage page with the page number Page_num1 in the external memory space, and load the external memory storage page with the page number Page_num1 into a certain memory storage page in the internal memory space. At this time, the page number of the memory storage page is also Page_num1, that is, a mapping between the internal memory storage page and the external memory storage page is established;
[0140] Then proceed to step 4.8;
[0141] Step 4.8: In the memory space, read the memory storage page with page number Page_num1, obtain the page content management information, and determine whether to execute the dirty data mechanism and the real-time mechanism based on the dirty data mechanism identifier and the real-time mechanism identifier. If not, execute step 4.10.
[0142] If yes, go to step 4.9;
[0143] Step 4.9: Check whether the data in the memory storage page with page number Page_num1 is dirty data and whether it meets the page timeliness requirements; if it is not dirty data and meets the page timeliness requirements, execute step 4.10;
[0144] If the data is dirty, the dirty data processing process is executed; if the page timeliness requirements are not met, the real-time mechanism timeout processing process is executed;
[0145] The dirty data processing process is the same as the real-time mechanism timeout processing process, which is: clear the corresponding page allocation information in the page allocation table of the memory management page mem_Page_1, set the page flag of the corresponding memory storage page to unavailable; then execute step 4.10;
[0146] Step 4.10, transfer the page allocation table stored in the memory management page mem_Page_1 to the external memory management page Page_1;
[0147] Step 4.11, execute the reading and writing process of this task;
[0148] During the reading and writing process of this task, the memory management page mem_Page_1 no longer stores the page allocation table. Instead, the storage space of the memory management page mem_Page_1 is used to store temporary global variables.
[0149] During the task reading and writing process, normal data modification will also change the corresponding dirty data flag. If the dirty data flag does not correspond to the page data, it is determined that a third party has modified the data in the minimum task unit, that is, the page is dirty data.
[0150] In this step, the read and write process of this task is executed, specifically including the addressing and read and write operations of variable data, including:
[0151] Step 4.11.1, define the addressing identifier var_addr(page, num), where page is the page number and num is the variable number;
[0152] Define variable length identifier var_len(page,num);
[0153] Step 4.11.2, based on the addressing identifier var_addr(page, num) and the variable length identifier var_len(page, num), search the memory storage page with page number Page_num_f1 and locate the variable identification data of this read / write;
[0154] Perform data read and write operations on variable identification data.
[0155] Step 4.12: After the reading and writing of this task is completed, the following method is used to replace the memory page with the external memory page:
[0156] Step 4.12.1, load the page allocation table stored in the external memory management page Page_1 into the memory management page mem_Page_1;
[0157] Step 4.12.2: Based on the task number task_num1 and the page number Page_num1, the page allocation table is searched to determine whether page allocation information corresponding to the task number task_num1 and the page number Page_num1 exists. If not, an error is returned, and the task scheduling policy starts the task and performs the storage resource allocation process, that is, executing step 3, or proceeding to the next task read / write process.
[0158] If it exists, go to step 4.12.3;
[0159] Step 4.12.3: Use the dirty data mechanism to determine whether the memory storage page with page number Page_num1, which is loaded at the start of the task read / write and the page at the completion of the task read / write, constitutes dirty data. Write a dirty data flag to the corresponding page of the page allocation table stored in the memory management page mem_Page_1, thereby forming a new page allocation table.
[0160] If dirty data is generated, clear the memory storage page with page number Page_num1 and then execute step 4.12.4;
[0161] If no dirty data is generated, the memory storage page with page number Page_num1 is transferred to the external memory storage page with page number Page_num1; then step 4.12.4 is executed;
[0162] Step 4.12.4, load the latest page allocation table stored in the memory management page mem_Page_1 to the external memory management page Page_1;
[0163] Then, the memory management page mem_Page_1 no longer stores the page allocation table, but uses the storage space of the memory management page mem_Page_1 to store temporary global variables.
[0164] An embodiment is described below:
[0165] Step 1: Define the storage management structure of the memory space, including:
[0166] Step 1.1: The storage capacity V1 of the memory space is 4K = 4096 bytes. The storage capacity W1 of a single memory page is defined as 1K = 1024 bytes. Thus, the memory space is divided into four memory pages, which are represented as: mem_Page_1, mem_Page_2, mem_Page_3, mem_Page_4.
[0167] Step 1.2, the first memory page mem_Page_1 is called the memory management page mem_Page_1; mem_Page_2, mem_Page_3, mem_Page_4 are called memory storage pages;
[0168] Step 1.3, define the management structure of the memory management page mem_Page_1;
[0169] The memory management page mem_Page_1 is divided into the external memory management structure storage area and the global variable storage area;
[0170] Step 2: Define the storage management structure of the external memory space by:
[0171] Step 2.1, define the storage capacity of a single external memory page Page to be equal to the storage capacity of a single internal memory page mem_Page, both of which are 1K = 1024 bytes;
[0172] The external memory space is divided into multiple external memory pages according to the page size of 1K. For example, the external memory space of the microcontroller is 56K, which is further divided into 56 external memory pages.
[0173] In step 2.2, the first external memory page Page_1 is called the external memory management page Page_1; the second external memory page Page to the mth external memory page Page_m are called external memory storage pages;
[0174] Step 2.3, define the management structure of the external memory management page Page_1:
[0175] The external memory management page Page_1 is used to store a page allocation table formed by the page management information of Page_1, Page_2, ..., Page_m;
[0176] For any external memory page Page_i (i = 1, 2, 3, ..., m) among Page_1, Page_2, ..., Page_m, the external memory management page Page_1 stores the following page management information: page attribute information and task attribute information. The external memory management page Page_1 uses a page allocation table. Each external memory page contains 29 bytes of page management information, and the external memory management page Page_1 is 1024 bytes. Therefore, the external memory management page Page_1 can store page management information for up to 30 external memory pages (occupying 29 × 30 = 1015 bytes).
[0177] The page management information of each external memory storage page has the following C language management structure:
[0178]
[0179]
[0180] in:
[0181] Page number page_num: defines the page number, which can be used to locate the first address of the page through the page length 1024, and is used to load and store external memory storage pages;
[0182] Page name page_name: identifies the name of the page data;
[0183] The data variable identifiers in the external memory storage page are organized using the offset + length format;
[0184] Page storage variable number var_def_num: used to record the number of variables, used to identify and parse each data variable;
[0185] Task number task_num: identifies the number of the task reading and writing corresponding to the data in the page, so that the storage page and the task are related;
[0186] Task name information task_name: identifies the name of the task associated with the page;
[0187] Task priority task_prior: identifies the priority of page-related tasks for reading and writing, and provides a reference for task page allocation strategies;
[0188] Shared flag shared_var: identifies whether the data in the page needs to be shared;
[0189] Shared data length shared_def_num: indicates the length of the shared data;
[0190] Dirty data flag: Indicates whether the current state of the data in the page is "dirty", that is, whether it is irreversibly modified or has timed out. It is used as a flag for data clearing or adjustment.
[0191] Page data task read and write start time valid_start_time and page data task read and write duration valid_duration: identify the time when the storage page starts to be used and the maximum duration of the page validity, to ensure the effectiveness of real-time data processing.
[0192] The structure and correspondence between external memory space and internal memory space are as follows Figure 1 .
[0193] Step 2.4, define the storage structure of the external memory storage pages Page_2,...,Page_m, such as Figure 2 Shown, including:
[0194] Step 2.4.1, the page headers of the pages Page_2, ..., Page_m are stored in the external memory to store the corresponding page attribute information and task attribute information;
[0195] The page header information structure is defined as follows:
[0196]
[0197] in:
[0198] The page information structure indicates the page data usage and the identifiers required when the page corresponding task is read and written.
[0199] Page number page_num: identifies the page during page processing, used to locate the first address of the page and determine the corresponding page when executing task read and write. The value of the page number is the same as the page_num item in the page management information;
[0200] Task number task_num: identifies the task number corresponding to the page. Combined with the page number, it determines the corresponding page in the task execution. The value of the task number is the same as the task_num item in the page management information.
[0201] Shared flag shared_pos: records the starting position of the access identifier of the shared data in the page. If there is no shared data, the value is set to -1;
[0202] Number of shared variables shared_num: identifies the length of the shared data starting at the starting position;
[0203] Dirty data mechanism flag modify_flag: Indicates whether the page is subject to the "dirty" data mechanism where modifications are invalidated and changes are cleared;
[0204] Real-time mechanism identifier valid_realtime: indicates whether the page is applicable to the real-time data mechanism that determines the effective start and end time.
[0205] Step 2.4.2, after the page header, the variable identifiers of the page data are stored continuously, which are used to address and read variables and write variables by address;
[0206] For example, a variable identifier uses the form of 2-byte offset + 2-byte length {offset, len}, which is used to address and read variables and write variables by address.
[0207] Step 2.4.3: Starting from the end of the page and gradually extending to lower addresses, write the variable data content; where: the variable identifier and variable content are stored in pairs;
[0208] Therefore, the variable data content is actually stored after the variable identification space, where the variable identification starts after the page information structure and extends to higher addresses, and the variable data content starts at the end of the page and extends to lower addresses. The corresponding variable identification and variable content are stored in pairs toward the middle of the page to maximize space utilization. The spatial organization and management of external memory storage pages and the corresponding relationship are as follows: Figure 2 .
[0209] Step 3: The task starts and storage resource allocation process is carried out;
[0210] Step 4: Real-time replacement mechanism of internal and external memory during task reading and writing;
[0211] The main principles of the real-time internal and external memory replacement mechanism during task reading and writing are:
[0212] When executing a task read or write in a memory-constrained system, the page allocation table stored in external memory management page Page_1 is loaded into memory management page mem_Page_1 to identify and allocate page data for the task. Memory management page mem_Page_1 stores both the page allocation table and system-defined global variables. Global variables are stored after the page allocation table and are used to store variables essential for system operation and temporary global variables related to the task. After mem_Page_1 is allocated, the page allocation table stored in mem_Page_1 is moved to external memory, freeing up memory space in mem_Page_1. Before the task read or write begins, temporary global variables are stored in mem_Page_1, effectively utilizing the available memory space. When executing a task read or write, the corresponding external memory storage page is loaded into the corresponding internal memory storage page based on the task's corresponding page number. This allows for independent and rapid completion of a group of task reads and writes. Simultaneously, the next task to be read or written is selected and loaded into the storage page based on the scheduling policy and task priority.
[0213] For example, a 4K memory space is divided into 4 memory pages, of which the memory management page mem_Page_1 is a 1K memory space used to store global variables and page allocation tables; the other 3K space is divided into three memory storage pages, which can be transferred to the 3 external memory storage pages of the external memory space for task reading and writing; the external memory space is more than 30K, divided into 30 external memory pages, with a single task data usage space of 1 to 3K as the standard. Under this condition, the real-time internal and external memory replacement mechanism runs, which can handle 10 to 30 concurrent tasks. When the tasks are intensive and fast, the task reading and writing are continuously converted, and it is expected to handle a task throughput of up to 100 tasks / second. The correspondence between the memory management page, memory storage page and external memory storage page is as follows: Figure 3 .
[0214] Real-time replacement mechanism of internal and external memory during task reading and writing: During task processing, the task processing starts loading the task and checks whether the task-related storage page is in the memory. If it is in the memory, the task reading and writing is executed directly, and the memory data supports the task; if it is not in the memory, the corresponding external memory storage page of the external memory is transferred to the memory storage page, and the data checking and verification mechanism is executed, the processing page data is deployed, and then the related task reading and writing is executed.
[0215] When the task reading and writing is completed or the task execution ends, the next task is determined according to the scheduling policy and task priority. At this time, if there is insufficient memory space, the memory storage page that has completed the task reading and writing is mapped and stored in the corresponding external memory storage page; if there is enough remaining space in the memory, the page is not replaced for the time being and is stored in the memory.
[0216] Define two internal and external memory replacement execution operations: permute_inner_mem_to_ext(page,task,dirty,current) and permute_inner_mem_from_ext(page,task,*dirty,current), which respectively perform the functions of replacing the internal memory storage page with the external memory storage page during task read / write scheduling and loading the relevant external memory storage page when the task read / write is started. The parameter page identifies the page number to be replaced; task identifies the task number corresponding to the page; dirty identifies whether the read data is adjusted when the page is loaded, and whether it is adjusted when the page is swapped out. The dirty data mechanism identifier modify_flag of the page information structure is used to determine whether the dirty data mechanism is executed for clearing and adjustment; current refers to the current time, and checks whether the page data is outdated when the page is loaded in or swapped out of the memory. The real-time mechanism identifier valid_realtime determines whether the real-time mechanism page timeout data discard is executed.
[0217] Calling in external memory storage page to execute the implementation process:
[0218] Step 4.1, during the task scheduling process, when a task task1 needs to be scheduled for execution to perform a read / write operation, the task number task_num1 of task task1 is obtained;
[0219] Step 4.2, the page allocation table (a total of 29×30=1015 bytes) stored in the current external memory management page Page_1 is transferred to the external memory management structure storage area of the memory management page mem_Page_1;
[0220] Step 4.3, according to the task number task_num1, search the page allocation table in the memory management page mem_Page_1, and read the page number Page_num1 of the external memory storage page corresponding to the task number task_num1 from the page allocation table;
[0221] Step 4.3, according to the task number task_num1, search the page allocation table in the memory management page mem_Page_1, and read the page number Page_num1 of the external memory storage page corresponding to the task number task_num1 from the page allocation table;
[0222] Step 4.5, traverse each external memory storage page in the external memory space to determine whether there is an external memory storage page with page number Page_num1; if not, an error is returned, and the task scheduling strategy starts the task of this task and performs the storage resource allocation process, that is, executing step 3, or proceeding to the next task reading and writing process;
[0223] If it exists, go to step 4.6;
[0224] Step 4.6: Read the external memory page with page number Page_num1, obtain the priority of task 1, and determine whether to execute task 1 according to the task scheduling policy set and the task priority. If task 1 needs to be executed, execute step 4.7.
[0225] If yes, proceed to step 4.7;
[0226] Step 4.7: Create a mapping between the memory storage page and the external memory storage page. The method is:
[0227] The external memory storage page with the page number Page_num1 is located in the external memory space. The positioning method may be: locating the page head address in the external memory by using the page number Page_num1, and transferring the external memory storage page with the page number Page_num1 to a certain memory storage page in the internal memory space, that is, placing 1024 bytes of the page head address in an empty position of a certain memory storage page. At this time, the page number of the memory storage page is also Page_num1, that is, establishing a mapping between the internal memory storage page and the external memory storage page;
[0228] Then proceed to step 4.8;
[0229] Step 4.8: In the memory space, read the memory storage page with page number Page_num1, obtain the page content management information, and determine whether to execute the dirty data mechanism and the real-time mechanism based on the dirty data mechanism identifier and the real-time mechanism identifier. If not, execute step 4.10.
[0230] If yes, go to step 4.9;
[0231] Step 4.9: Check whether the data in the memory storage page with page number Page_num1 is dirty data and whether it meets the page timeliness requirements; if it is not dirty data and meets the page timeliness requirements, execute step 4.10;
[0232] If the data is dirty, the dirty data processing process is executed; if the page timeliness requirements are not met, the real-time mechanism timeout processing process is executed;
[0233] The dirty data processing process is the same as the real-time mechanism timeout processing process, which is: clear the corresponding page allocation information in the page allocation table of the memory management page mem_Page_1, set the page flag of the corresponding memory storage page to unavailable; then execute step 4.10;
[0234] For example, the dirty data processing flow may be: reading the dirty data flag dirty of the page management structure, returning the pointer, and judging the dirty data flag dirty and the dirty data mechanism flag modify_flag of the page information structure.
[0235] If modify_flag=1 and dirty=1, perform "dirty" data processing (clear or adjust the page); then execute step 4.10;
[0236] If modify and dirty are other values, go directly to step 4.10;
[0237] The real-time mechanism timeout processing process can be:
[0238] Determine the current time current and the valid_start_time and valid_duration of the page management structure, and refer to the real-time mechanism identifier valid_realtime of the page information structure to determine the timeliness of the page.
[0239] If valid_realtime is 1, the start time, duration, and current system time are judged to determine whether the task reading or writing has timed out and whether the page is valid.
[0240] The page data times out and does not comply with the real-time mechanism. The real-time mechanism timeout is executed and discarded, the data in the memory page is cleared, and then step 4.10 is executed;.
[0241] If valid_realtime is 0, or valid_realtime is 1 and the page data has not timed out, proceed directly to step 4.10;
[0242] Step 4.10, transfer the page allocation table stored in the memory management page mem_Page_1 to the external memory management page Page_1;
[0243] The first 1015 bytes of the memory management page mem_Page_1 are used for temporary global variables.
[0244] Identifies the page loaded into the memory as in-use data and the existence of global variables.
[0245] Step 4.11, execute the reading and writing process of this task;
[0246] During the reading and writing process of this task, the memory management page mem_Page_1 no longer stores the page allocation table. Instead, the storage space of the memory management page mem_Page_1 is used to store temporary global variables.
[0247] During the task reading and writing process, normal data modification will also change the corresponding dirty data flag. If the dirty data flag does not correspond to the page data, it is determined that a third party has modified the data in the minimum task unit, that is, the page is dirty data.
[0248] In this step, the read and write process of this task is executed, specifically including the addressing and read and write operations of variable data, including:
[0249] Step 4.11.1, define the addressing identifier var_addr(page, num), where page is the page number and num is the variable number; define the variable length identifier var_len(page, num);
[0250] Step 4.11.2, based on the addressing identifier var_addr(page, num) and the variable length identifier var_len(page, num), search the memory storage page with page number Page_num_f1 and locate the variable identification data of this read / write;
[0251] Perform data read and write operations on variable identification data.
[0252] For example:
[0253] Define the addressing identifier var_addr(page,num) to return a void* address, identifying the absolute address of the variable in memory, where page is the page number and num is the variable number; define the variable length identifier var_len(page,num) to return a 16-bit integer identifying the variable length, with the same parameters as var_addr.
[0254] The addressing identifier and length identifier are used to identify the specific variable of a specific storage page. Their function is the same as the variable read and write statements defined in the language. The variable stored in the storage page is read and written through the variable address and length. The addressing implementation can be:
[0255] 1) Search for the variable identifier, starting after the page information structure, and locate the addressing identifier according to the variable identifier 2 bytes + 2 bytes length. The second parameter variable number num refers to the variable identifier.
[0256] 2) The first two bytes of the variable identifier represent the offset of the variable storage location from the page first address. The variable location first address in the memory space address is calculated through the page first address identifier PAGE_ADDRESS.
[0257] 3) The memory space address is returned as void* type.
[0258] The length is implemented in the same way as the aforementioned addressing method. The 2 bytes after the variable identifier represent the length, and step 3) returns the value as int16 type.
[0259] Memory replacement external memory execution implementation process:
[0260] Step 4.12: After the reading and writing of this task is completed, the following method is used to replace the memory page with the external memory page:
[0261] Step 4.12.1, load the page allocation table stored in the external memory management page Page_1 (occupying 29×30=1015 bytes) into the memory management page mem_Page_1;
[0262] Step 4.12.2: Based on the task number task_num1 and the page number Page_num1, the page allocation table is searched to determine whether page allocation information corresponding to the task number task_num1 and the page number Page_num1 exists. If not, an error is returned, and the task scheduling policy starts the task and performs the storage resource allocation process, that is, executing step 3, or proceeding to the next task read / write process.
[0263] If it exists, go to step 4.12.3;
[0264] Step 4.12.3: Use the dirty data mechanism to determine whether the memory storage page with page number Page_num1, which is loaded at the start of the task read / write and the page at the completion of the task read / write, constitutes dirty data. Write a dirty data flag to the corresponding page of the page allocation table stored in the memory management page mem_Page_1, thereby forming a new page allocation table.
[0265] If dirty data is generated, clear the memory storage page with page number Page_num1 and then execute step 4.12.4;
[0266] If no dirty data is generated, the memory storage page with page number Page_num1 is transferred to the external memory storage page with page number Page_num1; then step 4.12.4 is executed;
[0267] Step 4.12.4: The latest page allocation table stored in the memory management page mem_Page_1 is transferred to the external memory management page Page_1. The first 1015 bytes of the memory management page mem_Page_1 are used for temporary global variables.
[0268] Then, the memory management page mem_Page_1 no longer stores the page allocation table, but uses the storage space of the memory management page mem_Page_1 to store temporary global variables.
[0269] The real-time internal and external memory replacement mechanism and mapping management method provided by the present invention in a limited resource system focuses on protecting the following:
[0270] (1) Design method of self-organizing and managing external memory pages in page management structure.
[0271] (2) Page information structure and page space allocation method, as well as dirty data processing mechanism and real-time mechanism for effective inspection.
[0272] (3) The mapping mechanism of internal and external memory pages, and the technology of time-sharing memory management page space for global variables and temporary global variables.
[0273] (IV) System tasks read and write indirect addressing variables to perform read and write operations, and the mapping technology of absolute address corresponding to variable number and relative address.
[0274] (5) Task read and write scheduling selects tasks with the same priority, and the real-time replacement technology of internal and external memory data after task read and write is transferred to the external memory storage page and the read and write is completed and stored in the external memory storage page.
[0275] (6) Technology for executing a large number of memory-intensive tasks on a hardware system with limited memory resources based on the above technology.
[0276] The present invention provides a real-time internal and external memory replacement mechanism and mapping management method for a limited resource system. Through the real-time internal and external memory replacement mechanism, data variable storage in the execution of computer system-level tasks is optimized and scheduled, so that the data required for data reading and writing in task execution and the data that needs to be quickly processed are stored in the internal memory to support the task function, and the data of suspended standby tasks are stored in the external memory with a relatively large space. A complete mapping and replacement mechanism and management scheduling method are established. The present invention achieves the effect of the system executing a large number of intensive tasks under the conditions of limited hardware resources and restricted memory resources, and running stably, effectively and at high speed. In systems with certain conditions, such as systems supported by single-chip microcomputers or single-board SoCs or embedded systems with limited hardware resources, and occasions where operation is required in extreme environments, it is typically applicable and has good results.
[0277] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A real-time replacement mechanism and mapping management method for internal and external memory in a limited resource system, characterized in that: The following steps are involved: Step 1: Define the storage management structure of the memory space, including: Step 1.1, assume that the storage capacity of the memory space is V1; based on the storage capacity of the memory space V1, determine the storage capacity of a single memory page as W1, thereby dividing the memory space into n = V1 / W1 memory pages, which are represented in sequence as: mem_Page_1, mem_Page_2, ..., mem_Page_n; In step 1.2, the first memory page mem_Page_1 is called the memory management page mem_Page_1; the second memory page mem_Page_2 to the nth memory page mem_Page_n are called memory storage pages; Step 1.3, define the management structure of the memory management page mem_Page_1; The memory management page mem_Page_1 is divided into an external memory management structure storage area and a global variable storage area; the external memory management structure storage area is used to call the page allocation table of the external memory management page Page_1; the global variable storage area is used to store global variables for system operation, including page identifiers of each memory storage page, which are used to identify the available state of each memory storage page, that is, to identify the unavailable state or available state of the memory storage page; Step 2: Define the storage management structure of the external memory space by: Step 2.1, define the storage capacity of a single external memory page Page to be equal to the storage capacity of a single internal memory page mem_Page, both are W1; Assume that the storage capacity of the external memory space is V2, and thus the external memory space is divided into m = V2 / W1 external memory pages, which are represented as: Page_1, Page_2, ..., Page_m; In step 2.2, the first external memory page Page_1 is called the external memory management page Page_1; the second external memory page Page to the mth external memory page Page_m are called external memory storage pages; Step 2.3, define the management structure of the external memory management page Page_1: The external memory management page Page_1 is used to store a page allocation table formed by the page management information of Page_1, Page_2, ..., Page_m; Wherein: for any external memory storage page Page_i in Page_1, Page_2, ..., Page_m, i = 1, 2, 3, ..., m, the external memory management page Page_1 stores the following page management information: page attribute information and task attribute information; The page attribute information includes the page number; the task attribute information includes the task number, task priority, dirty data mechanism identifier, dirty data identifier, real-time mechanism identifier, page data task read and write start time and page data task read and write duration; in: Page number, which is the unique page identifier of the external memory storage page; The task number identifies the number of the task reading and writing corresponding to the page data, so that the external memory storage page and the task correspond to each other. Among them, one external memory storage page uniquely corresponds to one task number; one task number can correspond to multiple external memory storage pages; Task priority, used to identify the read and write priority of the task corresponding to the page, providing a reference for the page allocation strategy; The dirty data mechanism flag indicates whether a page is subject to the "dirty" data mechanism, which invalidates modifications and clears changes. Dirty data refers to data that cannot be modified by other tasks during a minimum operation unit, or task read or write. The data is exclusive within this minimum operation unit. The implementation principle is: after a series of normal data modification operations are performed within this minimum operation unit, the data flag is calculated. The data flag represents the data status. If the data flag changes at the start and end of a task read or write, it indicates that the data has changed during the task, and is therefore defined as dirty data. Real-time mechanism identifier, indicating whether the page is applicable to the real-time data mechanism that determines the effective start and end time; The page data task reading and writing start time, which indicates the starting time when the page begins to be used; Page data task read and write duration, which indicates the maximum duration for which page data is valid. This is used to determine whether the page data is within its life cycle, thereby ensuring the effectiveness of real-time data processing. Step 2.4, define the storage structure of the external memory storage pages Page_2, ..., Page_m, including: Step 2.4.1, the page headers of the pages Page_2, ..., Page_m are stored in the external memory to store the corresponding page attribute information and task attribute information; Step 2.4.2, after the page header, the variable identifiers of the page data are stored continuously, which are used to address and read variables and write variables by address; Step 2.4.3: Starting from the end of the page and gradually extending to lower addresses, write the variable data content; where: the variable identifier and variable content are stored in pairs; Step 3: Start the task and allocate storage resources. The method is as follows: Step 3.1, during the task scheduling process, when a new task needs to be started new When configuring the task attribute information; Step 3.2, determine the new task new The number of pages required for operation is s; Step 3.3, transfer the page allocation table stored in the current external memory management page Page_1 to the memory management page mem_Page_1; Step 3.4, read the page allocation table, obtain the s external memory storage pages that are not assigned to the task, and assign the s external memory storage pages to the new task task new , the allocation method is: The new task task new The task attribute information is written into the page management information of the corresponding external memory storage page in the page allocation table, thereby obtaining a new page allocation table; Step 3.5: Determine whether there is a task read / write operation to be executed. If so, execute step 4. If not, write the new page allocation table to the external memory management page Page_1 of the external memory space. This completes the task startup and storage resource allocation process; Step 4: Real-time swapping mechanism between internal and external memory during task reading and writing: Step 4.1, during the task scheduling process, when a task task1 needs to be scheduled for execution to perform a read / write operation, the task number task_num1 of task task1 is obtained; Step 4.2, transfer the page allocation table stored in the current external memory management page Page_1 into the external memory management structure storage area of the memory management page mem_Page_1; wherein the global variable storage area of the memory management page mem_Page_1 stores the system global variables and the page identifiers of each memory storage page; Step 4.3, according to the task number task_num1, search the page allocation table in the memory management page mem_Page_1, and read the page number Page_num1 of the external memory storage page corresponding to the task number task_num1 from the page allocation table; Step 4.4, based on the page identifiers of each memory storage page, traverse each memory storage page in the memory space that has a page identifier that is in an available state, and determine whether there is a memory storage page with page number Page_num1; if not, execute steps 4.5 to 4.7; if so, execute step 4.8; Step 4.5, traverse each external memory storage page in the external memory space to determine whether there is an external memory storage page with page number Page_num1; if not, an error is returned, and the task scheduling strategy starts the task of this task and performs the storage resource allocation process, that is, executing step 3, or proceeding to the next task reading and writing process; If it exists, go to step 4.6; Step 4.6: Read the external memory page with page number Page_num1, obtain the priority of task 1, and determine whether to execute task 1 according to the task scheduling policy set and the task priority. If task 1 needs to be executed, execute step 4.
7. If yes, proceed to step 4.7; Step 4.7: Create a mapping between the memory storage page and the external memory storage page. The method is: Locate the external memory storage page with the page number Page_num1 in the external memory space, and load the external memory storage page with the page number Page_num1 into a certain memory storage page in the internal memory space. At this time, the page number of the memory storage page is also Page_num1, that is, a mapping between the internal memory storage page and the external memory storage page is established; Then proceed to step 4.8; Step 4.8: In the memory space, read the memory storage page with page number Page_num1, obtain the page content management information, and determine whether to execute the dirty data mechanism and the real-time mechanism based on the dirty data mechanism identifier and the real-time mechanism identifier. If not, execute step 4.
10. If yes, go to step 4.9; Step 4.9: Check whether the data in the memory storage page with page number Page_num1 is dirty data and whether it meets the page timeliness requirements; if it is not dirty data and meets the page timeliness requirements, execute step 4.10; If the data is dirty, the dirty data processing process is executed; if the page timeliness requirements are not met, the real-time mechanism timeout processing process is executed; The dirty data processing process is the same as the real-time mechanism timeout processing process, which is: clear the corresponding page allocation information in the page allocation table of the memory management page mem_Page_1, set the page flag of the corresponding memory storage page to unavailable; then execute step 4.10; Step 4.10, transfer the page allocation table stored in the memory management page mem_Page_1 to the external memory management page Page_1; Step 4.11, execute the reading and writing process of this task; During the reading and writing process of this task, the memory management page mem_Page_1 no longer stores the page allocation table. Instead, the storage space of the memory management page mem_Page_1 is used to store temporary global variables. During the task reading and writing process, normal data modification will also change the corresponding dirty data flag. If the dirty data flag does not correspond to the page data, it is determined that a third party has modified the data in the minimum task unit, that is, the page is dirty data. Step 4.12: After the reading and writing of this task is completed, the following method is used to replace the memory page with the external memory page: Step 4.12.1, load the page allocation table stored in the external memory management page Page_1 into the memory management page mem_Page_1; Step 4.12.2: Based on the task number task_num1 and the page number Page_num1, the page allocation table is searched to determine whether page allocation information corresponding to the task number task_num1 and the page number Page_num1 exists. If not, an error is returned, and the task scheduling policy starts the task and performs the storage resource allocation process, that is, executing step 3, or proceeding to the next task read / write process. If it exists, go to step 4.12.3; Step 4.12.3: Use the dirty data mechanism to determine whether the memory storage page with page number Page_num1, which is loaded at the start of the task read / write and the page at the completion of the task read / write, constitutes dirty data. Write a dirty data flag to the corresponding page of the page allocation table stored in the memory management page mem_Page_1, thereby forming a new page allocation table. If dirty data is generated, clear the memory storage page with page number Page_num1 and then execute step 4.12.4; If no dirty data is generated, the memory storage page with page number Page_num1 is transferred to the external memory storage page with page number Page_num1; then step 4.12.4 is executed; Step 4.12.4, load the latest page allocation table stored in the memory management page mem_Page_1 to the external memory management page Page_1; Then, the memory management page mem_Page_1 no longer stores the page allocation table, but uses the storage space of the memory management page mem_Page_1 to store temporary global variables.
2. The real-time internal and external memory replacement mechanism and mapping management method in a limited resource system according to claim 1, characterized in that: Step 4.11: Execute the read and write process of this task, which specifically includes the addressing and read and write operations of variable data, including: Step 4.11.1, define the addressing identifier var_addr(page, num), where page is the page number and num is the variable number; Define variable length identifier var_len(page,num); Step 4.11.2, based on the addressing identifier var_addr(page, num) and the variable length identifier var_len(page, num), search the memory storage page with page number Page_num_f1 and locate the variable identification data of this read / write; Perform data read and write operations on variable identification data.
3. A real-time internal and external memory replacement mechanism and mapping management method for a limited resource system according to claim 1, characterized in that: The page attribute information also includes: a page name, which is used to store the name information of the page data; the task attribute information also includes: a task name, which is used to store the name information related to the task.
4. A real-time internal and external memory replacement mechanism and mapping management method for a limited resource system according to claim 1, characterized in that: The task attribute information also includes: sharing flag and sharing data length; Sharing flag, indicating whether the page data contains data that needs to be shared; Shared data length, indicating the shared data length.