A QNX memory page management method and system

By establishing a priority page mapping table and configuring a priority inheritance mode mutex in the QNX memory management system, the problem of inconsistent thread response latency requirements for memory page compression and reclamation in existing technologies is solved, ensuring the real-time performance and stability of the system and improving memory utilization.

CN123068313APending Publication Date: 2026-11-10HUIZHOU DESAY SV AUTOMOTIVE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611286606.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-24
Publication Date
2026-11-10

AI Technical Summary

Technical Problem

In the existing QNX memory management system, the memory page compression and reclamation mechanism fails to effectively consider the response latency requirements of threads. This causes threads with high response latency to wait for decompression when accessing memory, affecting system real-time performance. Furthermore, the memory compression and decompression process may be blocked due to shared resources being occupied.

Method used

A priority page mapping table for physical memory pages is established. The priority page mapping table records the thread identifier. The memory reclamation thread scans from low to high according to the baseline priority and prioritizes the compression of memory pages of threads with low effective priority. During the decompression process, a mutex lock configuration with priority inheritance mode is used to ensure that the memory pages of threads with high response latency are retained in physical memory and automatically yield when accessing shared resources.

Benefits of technology

This approach allows memory pages for threads with high response latency to be retained in physical memory, avoiding unpredictable delays and prolonged blocking, ensuring the real-time performance and stability of the system, and improving memory utilization and the determinism of system execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123068313A_ABST
    Figure CN123068313A_ABST
Patent Text Reader

Abstract

This application provides a QNX memory page management method and system. The method includes: establishing a priority page mapping table for physical memory pages, with each entry recording the thread identifier of the thread to which the physical memory page belongs; in response to available memory falling below a preset level, a memory reclamation thread scans the priority page mapping table from low to high according to a baseline priority, queries the effective priority of candidate memory pages in real time based on the thread identifier, and prioritizes compressing memory pages of threads with lower effective priorities. The baseline priority is the original scheduling priority of the thread, and the effective priority is the actual scheduling priority adjusted by the priority inheritance protocol. This application alleviates memory pressure while ensuring system real-time performance by compressing and reclaiming memory pages differently based on thread importance and simultaneously decompressing them upon page faults.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of memory management technology, and in particular to a QNX memory page management method and system. Background Technology

[0002] In scenarios with stringent real-time requirements, such as vehicle control and industrial automation, the QNX (QNX Neutrino Real-Time Operating System) system is widely used due to its microkernel architecture and precise thread scheduling capabilities. Different threads in the system have significantly different requirements for response latency, and if the latency of some threads exceeds expectations, it will directly affect the normal operation of the system.

[0003] As system functions become increasingly complex, physical memory resources are becoming increasingly scarce. To alleviate memory pressure, existing technologies typically employ memory compression and reclamation, compressing temporarily unused memory pages and storing them in memory to free up available memory space, then decompressing and restoring them when needed. However, existing memory compression and reclamation mechanisms usually select pages for compression based solely on page attributes such as access frequency and recent usage time. This can lead to memory pages for threads with high latency requirements being compressed, causing them to wait for decompression and resulting in unpredictable delays. Furthermore, the compression and decompression processes can be blocked due to shared resource occupation, further increasing waiting time and compromising system real-time performance. Summary of the Invention

[0004] This application provides a QNX memory page management method and system to solve the above-mentioned technical problems.

[0005] This application provides a QNX memory page management method, including the following steps: establishing a priority page mapping table for physical memory pages, with each entry recording the thread identifier of the thread to which the physical memory page belongs; in response to available memory falling below a preset level, a memory reclamation thread scans the priority page mapping table from low to high according to a baseline priority, queries the effective priority of candidate memory pages in real time based on the thread identifier corresponding to each candidate memory page, and prioritizes compressing memory pages of threads with lower effective priorities, where the baseline priority is the original scheduling priority of the thread, and the effective priority is the actual scheduling priority adjusted by a priority inheritance protocol; in response to a page fault exception triggered by a thread accessing a compressed physical memory page, the physical memory page is synchronously decompressed in the context of the page faulting thread, wherein the mutex lock of the shared resource accessed during decompression is configured in priority inheritance mode so that the holding thread is promoted to the effective priority of the page faulting thread.

[0006] Preferably, this application also provides a QNX memory page management system, the system comprising: a processor and a memory; the processor is communicatively connected to the memory, the memory storing a priority page mapping table and a computer program; the processor loads and executes the computer program stored in the memory to enable the system to perform the QNX memory page management method as described above.

[0007] The beneficial effects of this application are as follows: On the one hand, the selection of compression objects for memory reclamation no longer depends solely on the page's own attributes, but is consistent with the scheduling semantics of the system's thread importance. The memory pages of threads with high response latency requirements are retained in physical memory, and their execution process no longer suffers unpredictable delays due to page compression. Access latency changes from unpredictable to predictable, ensuring the real-time performance of the system.

[0008] On the other hand, the decompression process is completed instantly by the party accessing the page in its own execution environment, without the need for additional thread scheduling and switching overhead. Furthermore, when shared resources are occupied, the occupying party can automatically yield to the waiting party, changing the waiting time from unbounded to bounded, thus avoiding long-term blocking of high-demand threads.

[0009] On the other hand, memory pressure is continuously alleviated through compression and recycling. At the same time, the deterministic execution of threads with high real-time requirements is not affected by the recycling process. Memory utilization and system real-time performance have changed from being mutually restrictive to being mutually balanced, which improves the overall stability and reliability of the system. Attached Figure Description

[0010] Figure 1 This is a flowchart of the QNX memory page management method described in this application.

[0011] Figure 2 This is a flowchart of the memory reclamation thread scanning and compression process in one embodiment.

[0012] Figure 3 This is a diagram of the QNX memory page management system architecture as an example. Detailed Implementation

[0013] The technical methods of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0014] Furthermore, the accompanying drawings are merely illustrative of this application and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor methods and / or microcontroller methods.

[0015] It should be understood that although the terms "first," "second," etc., may be used herein to describe various units, these units should not be limited by these terms. These terms are used merely to distinguish one unit from another. For example, without departing from the scope of the exemplary embodiments, a first unit may be referred to as a second unit, and similarly, a second unit may be referred to as a first unit. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.

[0016] To achieve the above objectives, please refer to Figures 1 to 3 This application provides a QNX memory page management method, which mainly includes steps S100-S300.

[0017] S100: Establish a priority page mapping table for physical memory pages, with each entry recording the thread identifier of the thread to which the physical memory page belongs.

[0018] S200: In response to the available memory falling below a preset level, the memory reclamation thread scans the priority page mapping table from low to high according to the baseline priority, queries the effective priority of the candidate memory page in real time based on the thread identifier corresponding to the candidate memory page, and prioritizes compressing the memory pages of threads with lower effective priorities. The baseline priority is the original scheduling priority of the thread, and the effective priority is the actual scheduling priority after adjustment by the priority inheritance protocol.

[0019] S300: In response to a page fault triggered by a thread accessing a compressed physical memory page, the physical memory page is synchronously decompressed in the context of the page faulting thread, wherein the mutex lock of the shared resource accessed for decompression is configured in priority inheritance mode so that the holding thread is promoted to the effective priority of the page faulting thread.

[0020] Preferably, the method further includes: in response to the allocation of a physical memory page, establishing an entry corresponding to the physical memory page in the priority page mapping table, and writing the thread identifier of the thread to which the physical memory page belongs into the entry.

[0021] In this context, each entry in the priority page mapping table is a record unit that corresponds one-to-one with a physical memory page. Optionally, the priority page mapping table is indexed by the physical page frame number, with one entry corresponding to each physical page frame. The priority page mapping table is stored in kernel space. The thread identifier is a unique number assigned to each thread by the QNX kernel.

[0022] In some embodiments, when a thread requests memory during runtime, a physical page frame can be allocated to it from a free physical page frame; alternatively, when a thread accesses a virtual page that does not yet have a corresponding physical page frame for the first time, a physical page frame is allocated to it, and a virtual-physical address mapping is established. Upon completion of the physical page frame allocation, an entry is created in the priority page mapping table using the page frame number of the newly allocated physical page frame as an index. The thread that triggered this allocation is identified as the thread owning the physical memory page, and its thread identifier is written into the entry. Because the write operation and allocation operation are completed synchronously, each physical memory page has a definite ownership record from the moment it is put into use, and there will be no physical memory pages that are in use but have no ownership record.

[0023] In some embodiments, the entry records the thread identifier instead of the thread's priority value. This is because the QNX system provides a priority inheritance protocol, and a thread's effective priority may change frequently due to holding or waiting for shared resources. If the entry records the priority value, each change in effective priority would require synchronously modifying the entries for all physical memory pages under that thread's name, resulting in significant update overhead. The thread identifier, however, remains unchanged during the thread's lifetime. Once the entry records the thread identifier, it does not need to be updated with priority changes. When the effective priority of a thread is needed, it can be queried in real-time using the thread identifier in the entry through the kernel-provided thread query interface.

[0024] For example, the thread identifier of the display thread in the vehicle system is 1001. When this thread requests memory during its operation, a physical page frame with page frame number 2048 is allocated to it. Then, an entry corresponding to page frame number 2048 is created in the priority page mapping table, and the thread identifier 1001 is written into this entry.

[0025] In response to the release of the physical memory page, the entry corresponding to the physical memory page in the priority page mapping table is cleared.

[0026] In some embodiments, during thread execution, the memory it requests is released, and the corresponding physical page frame is reclaimed to a free physical page frame; or, when a thread exits, the memory under its name is reclaimed in its entirety, and the corresponding physical page frame is reclaimed to a free physical page frame. Simultaneously with reclaiming the physical page frame to a free state, the corresponding entry in the priority page mapping table is found using the page frame number of that physical page frame as an index, and that entry is cleared.

[0027] In some embodiments, clearing an entry means invalidating the entry, such as clearing the thread identifier recorded in the entry or marking the entry as unused. Cleared entries will no longer participate in subsequent garbage collection scan decisions. The clearing of entries corresponds to their creation, ensuring that the lifespan of an entry is consistent with the lifespan of a physical memory page; that is, the entry becomes effective when a physical memory page is allocated and becomes invalid when the physical memory page is released.

[0028] The reason for this approach is that free physical page frames will be reassigned to any thread later. If the entries are not cleared in time, the priority page mapping table will retain records of the ownership of physical memory pages and their original threads. After the physical page frames are reassigned, this may lead to confusion in the ownership relationships. Furthermore, since the QNX kernel reuses the thread identifiers of exited threads, residual records may also lead to incorrect thread information being retrieved. Clearing the entries in a timely manner can avoid these problems.

[0029] For example, following the previous example, the thread identifier of the display thread is 1001. It releases the memory corresponding to the physical page frame with page frame number 2048, reclaims the physical page frame to an idle state, and simultaneously invalidates the entry corresponding to page frame number 2048. Subsequently, if this physical page frame is reassigned to the communication thread with thread identifier 2001, the thread identifier 2001 is rewritten into the entry, ensuring that the ownership record is always accurate.

[0030] Preferably, the memory reclamation thread performs hierarchical management of physical memory pages according to baseline priority.

[0031] The step S200 involves scanning the priority page mapping table from low to high according to the baseline priority, including step S201.

[0032] S201: Scan the memory pages in each layer in order of baseline priority from low to high, and stop scanning when the number of compressed memory pages reaches the target of this reclamation.

[0033] In this context, layering is a way for memory reclamation threads to organize physical memory pages. Each layer corresponds to a baseline priority level or a baseline priority range. Memory pages linked within the same layer have a baseline priority belonging to the level or range corresponding to that layer. The reclamation target refers to the amount of memory to be released in a single reclamation cycle. Optionally, the reclamation target is determined based on memory pressure, such as the difference between the current available memory and a preset threshold.

[0034] In some embodiments, the memory reclamation thread starts scanning from the layer with the lowest baseline priority, processes the memory pages in that layer one by one, and uses the processed memory pages as candidate memory pages. It then queries the effective priority and makes a compression decision in the manner described above. When all memory pages in the current layer have been processed and the number of compressed memory pages has not yet reached the current reclamation target, it enters the layer with the next higher baseline priority to continue scanning. Each time a memory page is compressed, the number of compressed memory pages is accumulated. Once the accumulated number reaches the current reclamation target, the scanning stops immediately, and the remaining memory pages in the current layer are no longer processed, nor is the thread moved to a higher layer.

[0035] In some embodiments, the reason for organizing the hierarchy according to baseline priority rather than effective priority is that the baseline priority is the thread's original scheduling priority, which remains unchanged or changes only occasionally during thread execution. Memory pages do not frequently migrate between hierarchies due to priority fluctuations, and the hierarchical structure can remain stable. On the other hand, the effective priority changes frequently due to the priority inheritance protocol. If the hierarchy is based on the effective priority, memory pages will migrate frequently, resulting in high maintenance overhead. When the baseline priority of a thread changes, the memory reclamation thread can migrate the thread's memory pages to the hierarchy corresponding to the changed baseline priority.

[0036] In some embodiments, the scanning starts from the lowest level because threads with lower baseline priority usually have lower requirements for response latency, and compressing their memory pages has the least impact on system real-time performance; the scanning stops when the current reclamation target is reached because the amount of memory to be released has been met, and continuing to scan would only incur unnecessary overhead, thus reclamation can be completed without traversing all physical memory pages.

[0037] For example, the memory reclamation thread organizes physical memory pages into four layers according to baseline priority, corresponding to baseline priorities 10, 20, 30, and 40 respectively. When a low memory event is triggered, the target for reclamation is determined to be 500 pages. The memory reclamation thread starts scanning from the layer corresponding to baseline priority 10. After processing this layer, 300 pages are compressed, which does not reach the reclamation target. Therefore, it continues scanning from the layer corresponding to baseline priority 20. After compressing another 200 pages in this layer, the cumulative number reaches 500 pages, and the scanning stops immediately. The memory pages in the layers corresponding to baseline priorities 30 and 40 are not affected in this instance.

[0038] Preferably, when the candidate memory page is shared by multiple threads, the table entry corresponding to the candidate memory page records the thread identifiers of the multiple threads.

[0039] In step S200, the effective priority of a candidate memory page is queried in real time based on the thread identifier corresponding to the candidate memory page, including step S202.

[0040] S202: Query the effective priorities of the multiple threads in real time, and determine the highest effective priority among the multiple threads as the effective priority of the candidate memory page.

[0041] In some embodiments, when the memory reclamation thread scans a candidate memory page, it reads the corresponding entry in the table. When the entry records multiple thread identifiers, the memory reclamation thread queries the thread query interface provided by the kernel to find the current effective priority of the thread corresponding to each thread identifier. Since the query action occurs during the reclamation scan, the query result shows the actual scheduling priority of each thread at the current moment, and the temporary priority escalation of threads due to the priority inheritance protocol can be accurately reflected in the query result.

[0042] In some embodiments, the memory reclamation thread sorts and compares multiple valid priorities obtained from the query, selects the highest valid priority, and uses the highest valid priority as the overall valid priority of the candidate memory pages for subsequent compression decisions. The reason for using the highest valid priority, rather than other values, as the valid priority of shared memory pages is that shared memory pages are accessed by multiple threads. Compressing shared memory pages will affect all shared threads. If a lower valid priority is used as the decision criterion, threads with high latency requirements among the shared threads will still need to wait for decompression when accessing compressed shared memory pages, affecting their real-time performance. Using the highest valid priority as the valid priority of shared memory pages ensures that the protection level of shared memory pages matches the thread with the highest real-time requirements among the shared threads, ensuring that the real-time performance of any shared thread is not compromised by the compression of shared memory pages.

[0043] For example, the physical memory page with page frame number 4096 is a graphics buffer page, shared by the display thread (thread ID 1001) and the rendering thread (thread ID 1002). The corresponding table entries record thread IDs 1001 and 1002. When the memory reclamation thread scans this candidate memory page, it checks and finds that the display thread's current effective priority is 50, while the rendering thread's current effective priority is 40. Therefore, 50 is determined as the effective priority of this candidate memory page. In this way, even if the rendering thread has a lower priority, this shared memory page will participate in the compression decision according to the protection level corresponding to the effective priority of 50, and will not be compressed due to the lower priority of the rendering thread, thus avoiding decompression waiting when the display thread accesses this graphics buffer page.

[0044] Preferably, the preset water level in S200 includes a normal water level and an emergency water level lower than the normal water level.

[0045] In response to available memory falling below the normal water level but above the emergency water level, only memory pages of threads with low effective priority are compressed.

[0046] In response to available memory falling below the critical water level, memory pages of threads with high effective priority are included in the compression scope.

[0047] The "normal water level" and "emergency water level" are both preset thresholds for the amount of available memory. The emergency water level is lower than the normal water level and is used to distinguish different levels of memory pressure. Optionally, the normal water level and emergency water level can be represented by specific numerical values ​​or as a percentage of the total physical memory. The values ​​of both can be configured by the system, and this application embodiment does not limit them.

[0048] In some embodiments, when available memory is below the normal level but above the emergency level, memory pressure is at a normal level, and the memory reclamation thread only compresses the memory pages of threads with low effective priority, while the memory pages of threads with high effective priority do not participate in the compression.

[0049] In some embodiments, when available memory further decreases and falls below the emergency water level, memory pressure reaches a critical level. If only low-priority thread memory pages are compacted, the amount of memory that can be released may not meet the reclamation needs, and the system will face the risk of memory exhaustion. Therefore, at this time, memory pages of high-priority threads are also included in the compaction scope to expand the source of reclaimable memory and prioritize ensuring that the overall system does not fail due to memory exhaustion. It should be noted that even at the emergency water level, memory reclamation threads still compact memory pages in order of effective priority from low to high. Memory pages of high-priority threads are only compacted when low-priority memory pages are insufficient to meet the current reclamation target, and the probability and amount of their compaction are limited to a minimum.

[0050] Preferably, the memory reclamation thread in S200 is an independent kernel thread, and the baseline priority of the memory reclamation thread is a configurable priority, which is lower than the priority of the real-time thread.

[0051] The memory reclamation thread listens for low memory events and, in response to the low memory event, determines that the available memory is below the preset level.

[0052] Low memory events are notifications issued by the kernel when it detects that the amount of available memory has reached a preset level, informing threads subscribed to the event that memory is currently under pressure. Real-time threads are threads with deterministic requirements for response latency and need to complete responses within a specified time limit, such as control threads and data acquisition threads in an in-vehicle system. The baseline priority of real-time threads is in the higher range of the system priority scale.

[0053] In some embodiments, the memory reclamation thread is a kernel thread independent of the business threads, dedicated to performing memory page compaction and reclamation. The baseline priority of the memory reclamation thread is configurable, and the configuration principle is to set it lower than the priority of real-time threads in the system, typically a lower priority that the system can schedule. This configuration is based on the fact that compaction and reclamation are background maintenance tasks whose execution timing does not affect business correctness, while the execution timing of real-time threads directly impacts system functionality. Configuring the priority of the memory reclamation thread lower than that of real-time threads prevents the memory reclamation thread from preempting processor resources from real-time threads, ensuring that the reclamation process does not interfere with the execution of real-time tasks.

[0054] In some embodiments, the available memory level of the system is continuously monitored. When the available memory level reaches a preset threshold, a low memory event is issued. The memory reclamation thread remains in a sleep state when no low memory event is detected, consuming no processor resources. When a low memory event is detected, it is awakened, determines that the current available memory is below the preset threshold, and then performs tiered scanning and compaction reclamation as described above. After the current reclamation target is completed, the memory reclamation thread re-enters a sleep state and continues to listen for the next low memory event. By triggering reclamation through event listening rather than polling, the memory reclamation thread incurs no processor overhead when memory is sufficient.

[0055] For example, in an in-vehicle system, the baseline priority of real-time threads is distributed in the range above 50, while the baseline priority of memory reclamation threads is configured to 10. During periods of ample memory, the memory reclamation thread is in a dormant state. When available memory is detected to drop below the normal level, a low memory event is issued, waking the memory reclamation thread. After confirming that available memory is below the preset level, it begins performing compaction and reclamation. After reclamation is complete, it returns to dormancy. During the reclamation process, if a real-time thread becomes ready, the memory reclamation thread will be preempted by the real-time thread. The reclamation action proceeds during the idle intervals of the real-time thread, without affecting its responsiveness.

[0056] Preferably, in S300, the mutex is configured in priority inheritance mode, including: in response to the initialization of the shared resource, configuring the protocol attribute of the mutex from the default no-priority protection mode to the priority inheritance mode.

[0057] Shared resources refer to resources that are accessed by multiple executors during compression, reclamation, and decompression. For example, a compression pool for storing compressed data; the memory reclamation thread needs to access this pool when compressing memory pages, and the page fault thread also needs to access it when decompressing memory pages. A mutex lock provides mutual exclusion protection for access to shared resources, allowing only one executor to access the shared resource at a time. Protocol attributes are configuration items for mutex locks, determining the priority handling method when mutex lock contention occurs. No priority protection mode means that no priority adjustment is performed during mutex lock contention, while priority inheritance mode means that the kernel automatically elevates the priority of the holding thread during mutex lock contention.

[0058] In some embodiments, the initialization of shared resources occurs during the system startup phase, executed by the driver or module corresponding to the memory compression function during initialization. During initialization, when creating the mutex lock corresponding to the shared resource, a mutex lock attribute object is first created, and the protocol attribute in the attribute object is set to priority inheritance mode. Then, the mutex lock is created based on this attribute object. It should be noted that the default value of the mutex lock protocol attribute in the QNX system is no-priority protection mode. If the protocol attribute is not explicitly set when creating the mutex lock, the created mutex lock will operate in no-priority protection mode, and the holding thread will not be elevated during subsequent lock contention. Therefore, this application explicitly sets the protocol attribute during shared resource initialization, rewriting the default value to priority inheritance mode.

[0059] In some embodiments, the protocol attribute is set only once when the shared resource is initialized. After the setting is completed, the mutex operates in priority inheritance mode throughout its lifetime. Subsequent executors do not need to perform any additional priority-related operations when requesting and releasing the mutex. Privilege escalation and restoration are automatically completed by the kernel during the lock operation.

[0060] For example, during system startup, the memory compression module initializes the compression pool and creates a mutex lock to protect it. During creation, the protocol attribute of the attribute object is first set to priority inheritance mode, and then the mutex lock is created based on that attribute object. Subsequently, when the memory reclamation thread compresses memory pages, it holds the mutex lock; when the page fault thread decompresses memory pages, it requests the mutex lock. When contention occurs, the kernel automatically elevates the holding thread's privileges in the aforementioned manner, without requiring any code in the compression module or decompression path to participate in priority handling.

[0061] Preferably, the method further includes step S400.

[0062] S400: In response to the holding thread releasing the mutex, restore the effective priority of the holding thread to the baseline priority of the holding thread.

[0063] In some embodiments, after the holding thread completes its access to the shared resource, it releases the mutex. When the mutex is released, the kernel detects that the inheritance relationship between the holding thread and the waiting thread has been broken, and automatically restores the effective priority of the holding thread to its baseline priority. The restoration is performed by the kernel during the lock release process, and neither the holding thread nor the waiting thread needs to perform any additional operations related to priority restoration.

[0064] In some embodiments, the reason for restoring the effective priority is that the previous priority escalation of the holding thread was a temporary escalation based on inheritance. The purpose of the escalation was to allow the holding thread to complete access to the shared resource and release the mutex lock as quickly as possible with the effective priority of the waiting thread. The reason for the escalation disappeared when the mutex lock was released, and the holding thread should return to its own baseline priority to continue being scheduled. If the priority is not restored after the escalation, the holding thread with the originally lower priority will continue to participate in scheduling with the escalated priority, which may preempt the processor resources of real-time threads, disrupt the normal scheduling order of the system, and violate the design goal that memory reclamation threads should not interfere with real-time tasks.

[0065] For example, following the previous example, the memory reclamation thread has a baseline priority of 10. It holds the mutex lock of the compaction pool and performs compaction. After the thread triggers a page fault, it requests the mutex lock with an effective priority of 50. The kernel raises the effective priority of the memory reclamation thread to 50, and the memory reclamation thread quickly completes the compaction and releases the mutex lock at priority 50. Upon release, the kernel automatically restores the effective priority of the memory reclamation thread to 10, and the thread acquires the mutex lock and continues to perform decompression. Afterward, the memory reclamation thread continues to perform reclamation work with a baseline priority of 10, which can be preempted by real-time threads. The system's scheduling order does not undergo any residual changes due to this priority escalation.

[0066] Preferably, the method further includes steps S501-S503.

[0067] S501: Calculate at least one of the following for each baseline priority: compression hit rate, decompression latency, and access frequency of memory pages.

[0068] Here, compression hit rate refers to the proportion of compressed memory pages corresponding to a certain baseline priority that are accessed again after compression, reflecting the degree to which memory pages corresponding to that baseline priority are still needed after compression. Decompression latency refers to the time taken for a memory page corresponding to a certain baseline priority to complete decompression from the triggering of a page fault, which can be the average decompression time for each decompression of that baseline priority. Access frequency refers to the number of times a memory page corresponding to a certain baseline priority is accessed per unit time. The above statistics can be executed by a dynamic feedback regulator, a functional module used to dynamically adjust the reclamation strategy based on the reclamation effect, working in conjunction with the memory reclamation thread.

[0069] In some embodiments, the dynamic feedback regulator records events related to memory reclamation during system operation: Each time a memory reclamation thread compresses a memory page, it records the baseline priority of that memory page and its associated thread; when a compressed memory page is accessed and decompression is triggered, a hit is recorded, along with the time consumed for this decompression; when a memory page is accessed, the number of accesses to the baseline priority of that memory page is accumulated. The dynamic feedback regulator uses baseline priority as the statistical dimension and summarizes the above records according to a preset statistical period to obtain the compression hit rate, decompression latency, and access frequency corresponding to each baseline priority. Optionally, the preset statistical period can be set to a fixed duration or based on the number of reclamations; this embodiment does not limit this.

[0070] In some embodiments, the above three statistics reflect the appropriateness of the reclamation decision from different perspectives: a higher compression hit rate indicates that memory pages of the corresponding baseline priority are still frequently needed after compression, suggesting that the compression decision for these memory pages is inappropriate; a longer decompression latency indicates that threads of the corresponding baseline priority are more affected by the reclamation process; and a higher access frequency indicates that memory pages of the corresponding baseline priority are more active and less suitable for compression. Only one of the above statistics may be counted, or multiple statistics may be counted. The more types of statistics are counted, the more comprehensive the reflection of the appropriateness of the reclamation decision.

[0071] For example, within a statistical period, the dynamic feedback regulator statistics show that: the compression hit rate of memory pages corresponding to baseline priority 10 is 60%, the average decompression latency is 0.8 milliseconds, and the access frequency is 200 times per second; the compression hit rate of memory pages corresponding to baseline priority 30 is 5%, the average decompression latency is 0.2 milliseconds, and the access frequency is 10 times per second. The statistical results indicate that although the memory pages corresponding to baseline priority 10 belong to low-priority threads, they are actually frequently accessed, and most of them are accessed again after compression. Therefore, the compression of these memory pages did not achieve the expected recycling effect.

[0072] S502: Based on the statistical results, adjust the scanning threshold of the memory reclamation thread and the compression tendency coefficient of the memory pages corresponding to each baseline priority.

[0073] The scan threshold is the condition that the memory reclamation thread stops scanning in a single reclamation cycle. For example, it can be a threshold for the number of memory pages to be compressed. The larger the scan threshold, the more memory pages are reclaimed in a single cycle. The compression tendency coefficient is a parameter that characterizes the degree to which memory pages corresponding to a certain baseline priority are selected as compression targets. The larger the value of the compression tendency coefficient, the easier it is for memory pages of the corresponding baseline priority to be compressed; the smaller the value, the less likely it is for memory pages of the corresponding baseline priority to be compressed.

[0074] In some embodiments, the dynamic feedback regulator performs adjustments based on the statistical results of each statistical period at the end of each statistical period: for baseline priorities with a compression hit rate higher than the hit threshold, its compression tendency coefficient is reduced, indicating that the memory pages corresponding to this baseline priority are frequently accessed again after compression, suggesting that it is not suitable as a compression target; for baseline priorities with an access frequency higher than the frequency threshold, its compression tendency coefficient is reduced, so that active memory pages are kept in physical memory as much as possible; for baseline priorities with a low compression hit rate and low access frequency, its compression tendency coefficient is increased, so that the reclamation action falls more on memory pages that are truly not used for a long time; for cases where the overall decompression latency is relatively long, the scan threshold is reduced, the amount of memory reclaimed in a single instance is reduced, and the impact of the reclamation process on the system is reduced; for cases where the compression hit rate of each baseline priority is generally low and memory pressure occurs repeatedly, the scan threshold is increased, the amount of memory reclaimed in a single instance is increased, and the number of reclamation initiations is reduced.

[0075] It should be clarified that the specific adjustment method for reducing the compression tendency coefficient can be any of the following: The first is a step-by-step adjustment, where whenever the statistical results meet the reduction conditions, the compression tendency coefficient is subtracted from its current value by a preset step size. The preset step size can be between 0.1 and 0.3. When the reduction conditions are met consecutively for multiple statistical periods, the compression tendency coefficient decreases periodically. The second is a proportional adjustment, where the reduction magnitude is determined based on the degree to which the compression hit rate exceeds the hit threshold or the access frequency exceeds the frequency threshold; the greater the degree of exceedance, the greater the reduction magnitude. The third is a tiered adjustment, where several discrete coefficient tiers are preset, and the compression tendency coefficient is directly lowered to the corresponding target tier based on the degree of exceedance. Correspondingly, increasing the compression tendency coefficient can be done using a symmetrical incremental method. In some embodiments, the compression tendency coefficient is adjusted with a preset lower limit and a preset upper limit. The preset lower limit is greater than zero, for example, set to 0.1, so that the compression tendency coefficient corresponding to any baseline priority will not be adjusted to zero. This ensures that under emergency conditions, memory pages corresponding to any baseline priority still have the possibility of being compressed, maintaining consistency with the reclamation strategy under emergency conditions. The preset upper limit is used to limit reclamation actions from being excessively concentrated on memory pages corresponding to a certain baseline priority. Through the constraints of the preset lower and upper limits, the compression tendency coefficient always changes smoothly within a limited range, avoiding drastic fluctuations in the reclamation strategy due to fluctuations in a single statistical result.

[0076] In some embodiments, the adjusted scan threshold and compression tendency coefficient take effect in the next reclamation of the memory reclamation thread: the memory reclamation thread determines when to stop scanning according to the adjusted scan threshold, and when making a compression decision on candidate memory pages, it determines whether to compress them by combining the effective priority of the candidate memory page with the compression tendency coefficient corresponding to its baseline priority. The lower the compression tendency coefficient, the later the memory page is compressed.

[0077] For example, using the previous statistical results, the compression hit rate of the memory pages corresponding to baseline priority 10 is 60%, with an access frequency of 200 times per second. The dynamic feedback regulator lowers the compression tendency coefficient for baseline priority 10 from 1.0 to 0.2; the compression hit rate of the memory pages corresponding to baseline priority 30 is 5%, with an access frequency of 10 times per second. The dynamic feedback regulator raises the compression tendency coefficient for baseline priority 30 from 1.0 to 1.5. In the next round of recycling, the memory pages corresponding to baseline priority 10 are basically no longer selected as compression targets. The recycling action focuses on the memory pages corresponding to baseline priority 30 that have not been accessed for a long time, and the phenomenon of repeated compression and decompression no longer occurs.

[0078] S503: In response to the fact that the frequency of access to the memory page of a thread with low effective priority by a thread with high effective priority exceeds a preset frequency, the compression tendency coefficient of the memory page is reduced.

[0079] The preset frequency is a threshold for determining how frequently a memory page is accessed by a high-priority thread. It is used to identify memory pages that nominally belong to low-priority threads but actually serve high-priority threads. Such memory pages can be called pseudo-low-priority memory pages.

[0080] In some embodiments, the dynamic feedback regulator monitors the access of memory pages of threads with low effective priority during the statistical process: whenever such a memory page is accessed, the accessing thread is recorded, and the effective priority of the accessing thread is compared with the effective priority of the thread to which the memory page belongs. When the effective priority of the accessing thread is higher than the effective priority of the thread to which the memory page belongs, the number of high-priority accesses to the memory page is accumulated. In each statistical period, the accumulated number of high-priority accesses is converted into access frequency and compared with a preset frequency. If the frequency exceeds the preset frequency, the memory page is determined to be a false low-priority memory page, and the compression tendency coefficient of the memory page is reduced.

[0081] In some embodiments, the reason for individually reducing the compression bias of such memory pages is that although these memory pages belong to low-priority threads, high-priority threads continuously access them. Once the memory page is compressed, the next access by a high-priority thread will trigger a page fault and wait for decompression. The high-priority threads that the reclamation mechanism should protect are instead affected by the delay in reclamation. Furthermore, the continuous access by high-priority threads causes the memory page to switch repeatedly between compression and decompression, resulting in decompression delay and consuming processor resources. After reducing its compression bias, the memory page is placed lower in the compression decision, thus remaining in physical memory. It should be noted that the adjustment granularity in this step is for individual memory pages, which complements the method of adjusting the compression bias overall according to the baseline priority. The former is used to correct misjudgments of individual pages, while the latter is used to correct the overall bias of a certain priority level.

[0082] For example, a log thread with an effective priority of 10 has a memory page under its name used for exchanging control data. A control thread with an effective priority of 60 reads this memory page once every 50 milliseconds, meaning that the memory page is accessed by high-priority threads 20 times per second, exceeding the preset frequency of 5 times per second. The dynamic feedback regulator determines that this memory page is a false low-priority memory page and lowers its compression tendency coefficient from 1.0 to 0.1. Afterward, this memory page remains in physical memory for a long time, and the control thread does not need to wait for decompression each time it reads it. Before the adjustment, this memory page was repeatedly compressed, and each read by the control thread generated an average of 0.8 milliseconds of decompression waiting; after the adjustment, this waiting no longer occurs.

[0083] Preferably, this application also provides a QNX memory page management system, the system including a processor and a memory.

[0084] In some embodiments, the system may be an in-vehicle embedded device running the QNX operating system, such as an in-vehicle domain controller or an in-vehicle cockpit host, or other embedded devices running the QNX operating system. The embodiments of this application do not limit the device form of the system.

[0085] The memory is communicatively connected to the processor. Optionally, the memory and the processor are communicatively connected via a system bus, and the processor accesses the memory for read and write operations via the system bus. The memory is used to store computer programs and provide the physical memory space required for system operation. The memory can be random access memory; this application embodiment does not limit the specific type of memory.

[0086] The processor loads and executes the computer program stored in the memory, causing the system to perform the QNX memory page management method as described above. When the processor executes the computer program, it establishes a priority page mapping table in the kernel. When available memory falls below a preset level, it performs differentiated compression and reclamation of memory pages through a memory reclamation thread. In the event of a page fault, it performs synchronous decompression within the context of the page fault thread and protects the shared resources accessed during decompression based on a mutex configured in priority inheritance mode. The specific execution process of each of the above functions is the same as described in the above method embodiments, and can be found in the above method embodiments; it will not be repeated here.

[0087] It should be noted that the system described only shows the processor and memory directly related to the solution of the embodiment of this application. In actual products, the system may also include other components such as communication interfaces, power modules, and peripheral devices. These other components are conventional configurations in the art and do not affect the implementation of the solution of the embodiment of this application, and are not limited here.

[0088] Therefore, the embodiments should be regarded as exemplary and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, it is intended to encompass all variations that fall within the meaning and scope of the equivalents of the application.

[0089] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features of the invention herein.

Claims

1. A QNX memory page management method, characterized in that, Includes the following steps: Establish a priority page mapping table for physical memory pages, with each entry recording the thread identifier of the thread to which the physical memory page belongs; In response to the available memory falling below a preset level, the memory reclamation thread scans the priority page mapping table from low to high according to the baseline priority. It queries the effective priority of the candidate memory page in real time based on the thread identifier corresponding to the candidate memory page, and prioritizes compressing the memory pages of threads with low effective priority. The baseline priority is the original scheduling priority of the thread, and the effective priority is the actual scheduling priority after adjustment by the priority inheritance protocol. In response to a page fault triggered by a thread accessing a compressed physical memory page, the physical memory page is synchronously decompressed in the context of the page faulting thread. The mutex lock of the shared resource accessed for decompression is configured in priority inheritance mode so that the holding thread is promoted to the effective priority of the page faulting thread.

2. The QNX memory page management method according to claim 1, characterized in that, The method further includes: In response to the allocation of a physical memory page, an entry corresponding to the physical memory page is created in the priority page mapping table, and the thread identifier of the thread to which the physical memory page belongs is written into the entry. In response to the release of the physical memory page, the entry corresponding to the physical memory page in the priority page mapping table is cleared.

3. The QNX memory page management method according to claim 1, characterized in that, The memory reclamation thread manages physical memory pages in a hierarchical manner according to baseline priority; The step of scanning the priority page mapping table from low to high according to the baseline priority includes: The memory pages in each layer are scanned sequentially according to the baseline priority from low to high, and the scanning stops when the number of compressed memory pages reaches the target of this reclamation.

4. The QNX memory page management method according to claim 2, characterized in that, When the candidate memory page is shared by multiple threads, the table entry corresponding to the candidate memory page records the thread identifiers of the multiple threads; The step of querying the effective priority of a candidate memory page in real time based on the thread identifier corresponding to the candidate memory page includes: The effective priorities of the multiple threads are queried in real time, and the highest effective priority among the multiple threads is determined as the effective priority of the candidate memory page.

5. The QNX memory page management method according to claim 1, characterized in that, The preset water level includes the normal water level and an emergency water level below the normal water level; In response to available memory falling below the normal water level but above the emergency water level, only the memory pages of threads with low effective priority are compressed; In response to available memory falling below the critical water level, memory pages of threads with high effective priority are included in the compression scope.

6. The QNX memory page management method according to claim 1, characterized in that, The memory reclamation thread is an independent kernel thread, and its baseline priority is a configurable priority, which is lower than the priority of the real-time thread. The memory reclamation thread listens for low memory events and, in response to the low memory event, determines that the available memory is below the preset level.

7. The QNX memory page management method according to claim 1, characterized in that, The mutex is configured in priority inheritance mode, including: In response to the initialization of the shared resource, the protocol attributes of the mutex are configured from the default no-priority protection mode to the priority inheritance mode.

8. The QNX memory page management method according to claim 7, characterized in that, The method further includes: In response to the holding thread releasing the mutex, the effective priority of the holding thread is restored to the baseline priority of the holding thread.

9. The QNX memory page management method according to claim 3, characterized in that, The method further includes: Calculate at least one of the following for each baseline priority: compression hit rate, decompression latency, and access frequency of memory pages. Based on the statistical results, adjust the scanning threshold of the memory reclamation thread and the compression tendency coefficient of the memory pages corresponding to each baseline priority; In response to the fact that the frequency of access to the memory page of a thread with low effective priority by a thread with high effective priority exceeds a preset frequency, the compression tendency coefficient of the memory page is reduced.

10. A QNX memory page management system, characterized in that, The system includes: Processor and memory; The processor is communicatively connected to the memory, which stores a priority page mapping table and a computer program. The processor loads and executes the computer program stored in the memory to cause the system to perform the QNX memory page management method as described in any one of claims 1 to 9.