Memory fragmentation processing method and device, and vehicle

CN123030516APending Publication Date: 2026-11-03ZHEJIANG GEELY HLDG GRP CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611322427.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-28
Publication Date
2026-11-03

AI Technical Summary

Technical Problem

The Android system in the smart cockpit uses the Linux buddy allocator to manage physical memory. After running for a long time, this leads to memory fragmentation, making it impossible to allocate large, contiguous blocks of physical memory, which affects the stable operation of the system.

Method used

By acquiring target memory state data, calculating and fusing fragmentation scores for different fragment types, and generating memory fragmentation handling strategies that adapt to the current system load and business needs, including lightweight, targeted, and urgent defragmentation operations.

Benefits of technology

It improves the accuracy and efficiency of memory fragmentation handling, reduces the probability of system failure, enhances user experience, and ensures the stability and smoothness of the vehicle system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123030516A_ABST
    Figure CN123030516A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of vehicles and discloses a memory fragmentation processing method and device and a vehicle.The memory fragmentation processing method comprises the following steps: obtaining original memory state data of a target kernel; based on the original memory state data, fragmentation scores corresponding to various fragmentation types are respectively calculated, and the fragmentation scores are fused to obtain a comprehensive fragmentation score; according to the comprehensive fragmentation score and real-time running state data of the target kernel, a memory fragmentation processing strategy is generated; and based on the memory fragmentation processing strategy, corresponding fragmentation processing operations are performed on the target kernel.The application can meet the demand of long-term stable operation of an intelligent cabin system, reduce the occurrence probability of cabin application collapse, system lag and even restart, and improve the use experience of the intelligent cabin of the vehicle.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of vehicle technology, and more specifically to a method, apparatus, and vehicle for handling memory fragmentation. Background Technology

[0002] In related technologies, the Android system running in smart cockpits typically uses a Linux buddy allocator to manage physical memory. Therefore, after prolonged operation, this can lead to severe memory fragmentation. Due to memory fragmentation, even if the total amount of available memory remains sufficient, it cannot allocate large, contiguous blocks of physical memory, resulting in memory allocation failures and failing to meet the long-term stable operation requirements of the smart cockpit system. Summary of the Invention

[0003] This invention provides a memory fragmentation processing method, apparatus, and vehicle to solve the problem that in related technologies, the Android system in smart cockpits uses the Linux buddy allocator to manage physical memory, which leads to memory fragmentation during long-term operation. Furthermore, due to memory fragmentation, even if the total amount of available memory in the system is sufficient, it is impossible to allocate large, continuous blocks of physical memory, thus affecting the long-term stable operation of the system.

[0004] In a first aspect, the present invention provides a memory fragmentation processing method, comprising: acquiring raw memory state data of a target kernel; calculating fragmentation scores corresponding to each fragment type based on the raw memory state data, and fusing them to obtain a comprehensive fragmentation score; generating a memory fragmentation processing strategy based on the comprehensive fragmentation score and real-time running state data of the target kernel; and performing corresponding fragmentation processing operations on the target kernel based on the memory fragmentation processing strategy.

[0005] The memory fragmentation processing method provided by this invention obtains a comprehensive score by integrating fragmentation scores of different fragmentation types, which can effectively improve the accuracy of fragmentation degree judgment. By combining the real-time running status of the target kernel to generate an adapted fragmentation processing strategy, the intensity and method of fragmentation processing can be flexibly adjusted according to the current system load and business needs. This avoids excessive system resource consumption during fragmentation defragmentation operations when the system is under high load, balancing the fragmentation processing effect and system performance. It can meet the long-term stable operation requirements of intelligent cockpit systems, reduce the probability of cockpit application crashes, system lag, or even restarts, and improve the user experience of vehicle intelligent cockpits.

[0006] In one optional implementation, based on the original memory state data, fragmentation scores corresponding to each fragment type are calculated and fused to obtain a comprehensive fragmentation score. This includes: obtaining free page data of each memory management area in the target kernel and memory load data of the target kernel based on the original memory state data; calculating fragmentation scores for external fragments, contiguous fragments, and immovable page fragments based on the free page data to obtain a first fragmentation score, where contiguous fragments are used to characterize contiguous free memory blocks with page sizes greater than or equal to a higher-order memory threshold; calculating fragmentation scores for internal fragments based on the memory load data to obtain a second fragmentation score; and weightedly fusing the first fragmentation score and the second fragmentation score to obtain a comprehensive fragmentation score.

[0007] The memory fragmentation processing method provided by this invention calculates fragmentation scores based on the characteristics of different fragment types, which can more accurately reflect the impact of various fragments on overall memory usage. By obtaining a comprehensive fragmentation score through weighted fusion, it can more comprehensively and objectively reflect the overall memory fragmentation level of the target kernel, providing an accurate basis for subsequent generation of reasonable fragmentation processing strategies, ensuring the adaptability and effectiveness of the memory fragmentation processing process, and further reducing the probability of intelligent cockpit operation failures caused by memory problems.

[0008] In one optional implementation, based on the free page data, fragmentation scores are calculated for external fragments, continuous fragments, and immovable page fragments to obtain a first fragmentation score. This includes: if the fragment type is external fragments, calculating the contribution deficiency of each level of free pages in the first target level to the total free pages, and merging the contribution deficiency scores of each level to obtain an external fragmentation score; if the fragment type is continuous fragments, obtaining a continuous fragmentation score based on the contribution rate of free pages in the second target level to the total free pages; if the fragment type is immovable page fragments, obtaining an immovable page fragmentation score based on the contribution rate of immovable free pages to the total free pages and the migration weight; and obtaining the first fragmentation score based on the external fragmentation score, the continuous fragmentation score, and the immovable page fragmentation score.

[0009] The memory fragmentation processing method provided by this invention, for external fragmentation, obtains an external fragmentation score by integrating the contribution deficiency of free pages at each level, which can accurately quantify the impact of uneven distribution of free page levels on external fragmentation; for continuous fragmentation, it completes continuous fragmentation scoring based on contribution rate, reducing computational overhead while ensuring scoring accuracy; for immovable page fragmentation, it calculates immovable page fragmentation score by combining migration weight, which can accurately reflect the degree of obstruction of immovable fragmentation to memory defragmentation; the accurate first fragmentation score can provide a reliable decision basis for subsequent memory defragmentation strategies, effectively improving the targeting and efficiency of vehicle memory defragmentation, reducing the computational power consumption caused by unnecessary defragmentation operations, and reducing the risk of vehicle system lag, response delay or even program crash due to memory fragmentation, thus improving the user's driving experience.

[0010] In one optional implementation, a fragmentation score for internal fragmentation is calculated based on memory load data to obtain a second fragmentation score, including: obtaining the swap partition utilization, memory availability, and memory full blocking pressure of the target kernel based on memory load data; and calculating the fragmentation score for internal fragmentation based on swap partition utilization, memory availability, and memory full blocking pressure to obtain a second fragmentation score.

[0011] The memory fragmentation processing method provided by this invention can directly utilize the memory load parameters available to the system to obtain the swap partition utilization rate, memory availability rate and memory full blocking pressure of the target kernel, and then calculate the fragmentation score of the internal fragmentation. It does not require a full traversal and statistical analysis of the kernel memory allocation blocks. While ensuring the accuracy of the quantification of the internal fragmentation degree, it further reduces the computing power and memory overhead caused by the scoring calculation process.

[0012] In one optional implementation, a memory fragmentation handling strategy is generated based on a comprehensive fragmentation score and real-time runtime status data of the target kernel, including: determining the fragmentation level of the target kernel based on the comprehensive fragmentation score; determining an initial handling strategy based on the fragmentation level; and generating the memory fragmentation handling strategy based on the real-time runtime status data and the initial handling strategy.

[0013] The memory fragmentation processing method provided by this invention first classifies fragmentation levels based on a comprehensive fragmentation score, and then adjusts the final fragmentation processing strategy in conjunction with the real-time running status of the target kernel. This method can match the corresponding strength of defragmentation actions to different degrees of memory fragmentation, avoiding unnecessary defragmentation operations that waste computing power when the fragmentation level is low, and preventing insufficient defragmentation strength from failing to resolve memory allocation anomalies when the fragmentation level is high. By adjusting the processing strategy in conjunction with the real-time running status of the vehicle's target kernel, non-urgent defragmentation actions can be postponed when the vehicle system is under high load (such as simultaneously running the autonomous driving perception module, navigation module, and multimedia entertainment module). This avoids defragmentation consuming system resources and causing lag and response delays in core vehicle services, ensuring the smoothness and stability of the vehicle system and effectively improving the user's driving experience.

[0014] In one optional implementation, an initial processing strategy is determined based on the fragmentation level, including: if the fragmentation level is level one, the initial processing strategy is to not perform a defragmentation operation; if the fragmentation level is level two, the initial processing strategy is to perform asynchronous background defragmentation based on a first defragmentation amount, where the overall score corresponding to level two is greater than or equal to the first score and less than the second score; if the fragmentation level is level three, the initial processing strategy is to perform targeted defragmentation based on a second defragmentation amount, and to allow the termination of processes with process values ​​greater than a first value, where the second defragmentation amount is greater than the first defragmentation amount, and the overall score corresponding to level three is greater than or equal to the second score. And less than the third score; if the fragmentation level is the fourth level, then the initial processing strategy is to perform deep global cleanup based on the third cleanup amount, and to allow the termination of processes with a process value greater than the second value, the third cleanup amount is greater than the second cleanup amount, the second value is less than the first value, and the comprehensive score corresponding to the fourth level is greater than or equal to the third score and less than the fourth score; if the fragmentation level is the fifth level, then the initial processing strategy is to perform emergency global cleanup based on the fourth cleanup amount, and to allow the termination of processes with a process value greater than the third value, the fourth cleanup amount is greater than the second cleanup amount, the third value is less than the second value, and the comprehensive score corresponding to the fifth level is greater than or equal to the fourth score.

[0015] The memory fragmentation handling method provided by this invention adopts a strategy of no defragmentation or lightweight asynchronous background defragmentation when the fragmentation level is low. This will not interfere with the response of the vehicle's front-end business and will ensure the smooth operation of core functions such as vehicle-machine interaction, vehicle power control, and driving assistance. For different levels of fragmentation, the defragmentation amount and the threshold for terminated processes are adjusted accordingly. This can not only clean up and alleviate fragmentation problems in a timely manner, but also prioritize the normal operation of core processes with low process values, avoid abnormal termination of core vehicle functions, and ensure vehicle driving safety. When the fragmentation level reaches the highest level in an emergency scenario, a strong global defragmentation is used to quickly restore memory availability, which can effectively avoid the risk of vehicle system lag, crashes, or even functional failures.

[0016] In one optional implementation, the initial processing strategy is adjusted based on real-time runtime status data to obtain a memory fragmentation handling strategy, including: obtaining the target kernel's memory availability, swap partition utilization, memory full-blocking pressure, fragmentation trend, and continuous fragmentation score based on the real-time runtime status data; adjusting the amount and method of defragmentation in the initial processing strategy based on a first relationship between memory availability and a preset utilization threshold, and / or the direction of fragmentation trend change; adjusting the threshold value of processes allowed to terminate in the initial processing strategy based on a second relationship between swap partition utilization and a preset swap threshold, and / or a third relationship between continuous fragmentation score and a preset continuous score threshold; and adjusting the defragmentation method in the initial processing strategy based on the relationship between memory full-blocking pressure and a preset pressure threshold.

[0017] The memory fragmentation handling method provided by this invention can release sufficient contiguous memory space in a timely manner when memory pressure is high and fragmentation is severe, ensuring the smooth operation of core processes. When memory pressure is low, it can reduce the interference of defragmentation on the foreground interaction process, avoid stuttering and response delays in vehicle interaction, effectively improve the smoothness and stability of vehicle system operation, improve the user's vehicle interaction experience, and at the same time reduce unnecessary memory read and write losses, extending the service life of related hardware in the vehicle system.

[0018] In one optional implementation, based on a memory fragmentation handling strategy, a corresponding fragmentation operation is performed on the target kernel, including: obtaining kernel throttling control parameters, which include at least one of cooling duration, execution frequency, defragmentation interval, and process termination interval; performing throttling verification on the memory fragmentation handling strategy based on the throttling control parameters to obtain the verification result; and performing a corresponding fragmentation operation on the target kernel based on the verification result and the memory fragmentation handling strategy.

[0019] The memory fragmentation processing method provided by this invention can effectively avoid the fragmentation processing operation being frequently triggered and excessively occupying system computing power and memory resources by completing the throttling verification of defragmentation based on kernel throttling control parameters. At the same time, it can also prevent the fragmentation problem from continuing to worsen due to the long-term non-execution of defragmentation, and realize dynamic and reasonable control over the timing and intensity of defragmentation triggering.

[0020] In a second aspect, the present invention provides a memory fragmentation processing device, comprising: The data acquisition module is used to acquire the raw memory state data of the target kernel; The scoring fusion module is used to calculate the fragmentation score corresponding to each fragment type based on the original memory state data, and then fuse them to obtain a comprehensive fragmentation score. The strategy generation module is used to generate memory fragmentation handling strategies based on the comprehensive fragmentation score and the real-time running status data of the target kernel. The fragmentation processing module is used to perform corresponding fragmentation processing operations on the target kernel based on memory fragmentation processing strategies.

[0021] Thirdly, the present invention provides a vehicle comprising: a cockpit and an on-board terminal, the on-board terminal comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the memory fragmentation processing method of the first aspect or any corresponding embodiment described above.

[0022] Fourthly, the present invention provides an electronic device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the memory fragmentation processing method of the first aspect or any corresponding embodiment described above.

[0023] Fifthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the memory fragmentation processing method of the first aspect or any corresponding embodiment thereof.

[0024] In a sixth aspect, the present invention provides a computer program product, including computer instructions for causing a computer to execute the memory fragmentation processing method of the first aspect or any corresponding embodiment described above. Attached Figure Description

[0025] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0026] Figure 1 This is a schematic flowchart of a first method for handling memory fragmentation according to an embodiment of the present invention; Figure 2 This is a schematic diagram of a second process for a memory fragmentation handling method according to an embodiment of the present invention; Figure 3 This is a structural block diagram of a memory fragmentation processing device according to an embodiment of the present invention; Figure 4 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0027] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0028] It is understood that before using the technical solutions disclosed in the various embodiments of the present invention, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in the present invention and their authorization should be obtained in accordance with relevant laws and regulations through appropriate means.

[0029] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.

[0030] According to an embodiment of the present invention, a memory fragmentation processing method embodiment is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0031] This embodiment provides a method for handling memory fragmentation. Figure 1 This is a flowchart of a memory fragmentation handling method according to an embodiment of the present invention, such as... Figure 1 As shown, the process includes the following steps: Step S101: Obtain the raw memory state data of the target kernel.

[0032] The target kernel is the Linux kernel of the Android system running on the smart cockpit. The raw memory state data of the target kernel includes free page data of each memory management area in the target kernel and memory load data of the target kernel.

[0033] In some optional implementations, when obtaining raw memory state data of the target kernel, free page data of each memory management area can be obtained by reading the target kernel's file system interface, and memory load data can be obtained by reading the target kernel's file system interface and virtual file interface. Free page data includes the number of free pages at each order in the buddy allocator of each memory management area, and page distribution information categorized by migration type within each memory management area; the buddy allocator organizes memory into free page blocks from order 0 to order 10 in power-of-2 sizes. Memory load data includes swap partition utilization, memory availability, and memory full-blocking pressure.

[0034] The acquisition of raw memory state data is performed by the Native execution layer, which interacts with the Framework business layer through the intermediate bridge layer JNI. This acquisition operation can be triggered periodically at preset time intervals, which can be dynamically configured through system properties or configuration interfaces, and can be set to 30 seconds. This acquisition operation can also be proactively triggered by memory pressure exceeding limits, application foreground / background switching events, and system entering an idle state. This avoids unnecessary system resource consumption caused by periodic triggering and ensures timely acquisition of raw memory state data at critical points where memory fragmentation accumulates rapidly, guaranteeing the timeliness of subsequent memory fragmentation processing operations.

[0035] Step S102: Based on the original memory state data, calculate the fragmentation score corresponding to each fragment type, and then merge them to obtain a comprehensive fragmentation score.

[0036] Fragmentation types can include external fragmentation, contiguous fragmentation, non-movable page fragmentation, and internal fragmentation. Contiguous fragmentation is used to characterize contiguous free memory blocks with a page size greater than or equal to a higher-order memory threshold. Fragmentation scores are used to quantify the severity of system memory fragmentation.

[0037] In some optional implementations, when calculating the fragmentation score corresponding to each fragment type based on the original memory state data and fusing them to obtain a comprehensive fragmentation score, the free page data of each memory management area in the target kernel and the memory load data of the target kernel can be obtained based on the original memory state data; based on the free page data, the fragmentation scores for fragment types external fragments, contiguous fragments, and non-movable page fragments are calculated respectively to obtain a first fragmentation score; based on the memory load data, the fragmentation score for fragment type internal fragments is calculated to obtain a second fragmentation score; the first fragmentation score and the second fragmentation score are weighted and fused to obtain a comprehensive fragmentation score.

[0038] Specifically, the fragmentation score for external fragmentation can be calculated based on the number of free blocks in each memory management area, the total number of free pages, and the percentage of the largest free block. The severity of external fragmentation can be quantified by combining the average size of free blocks with the percentage of the largest free block to the total free size. The fragmentation score for non-movable page fragmentation is calculated based on the percentage of non-movable pages to all non-free pages and the percentage of non-movable free blocks to all free blocks, reflecting the degree of memory segmentation by non-movable pages. The second fragmentation score for internal fragmentation is calculated based on the percentage of unused space in the memory allocated to each process in the memory load data. During the weighted fusion process, the weights of the two types of scores can be adaptively adjusted based on the current total memory usage of the target kernel: if the total memory usage is lower than the preset first threshold, it indicates that the system still has a lot of spare memory. At this time, external fragmentation has a greater impact on memory allocation efficiency, so the weight of the first fragmentation score is increased; if the total memory usage is higher than the preset second threshold, it indicates that the system memory is already under high load, and internal fragmentation and unmovable fragmentation have a more significant impact on operational stability. Therefore, the weight of the second fragmentation score and the unmovable page fragmentation score within it is increased. The final comprehensive fragmentation score can accurately match the current memory operating status of the system.

[0039] As an example, assume the target kernel currently has a total memory of 16GB, and the total memory usage is 35%, which is lower than the preset first threshold of 50%. Based on the original memory state data, the fragmentation score for external fragmentation is calculated to be 0.28, for contiguous fragmentation to be 0.19, and for non-movable page fragmentation to be 0.13, therefore the first fragmentation score is 0.6. Simultaneously, based on memory load data, the second fragmentation score for internal fragmentation is calculated to be 0.4. Following the adaptive weighting rule, the weight of the first fragmentation score is set to 0.7, and the weight of the second fragmentation score is set to 0.3. After weighted fusion, the comprehensive fragmentation score is 0.6 × 0.7 + 0.4 × 0.3 = 0.54.

[0040] If the total system memory usage increases to 82%, exceeding the preset second threshold of 70%, the weight of the first fragmentation score is adjusted to 0.4 and the weight of the second fragmentation score is adjusted to 0.6 according to the rules. At the same time, the proportion of the fragmentation score of non-movable pages in the first fragmentation score is increased from 1 / 3 to 1 / 2. The comprehensive fragmentation score obtained by re-weighting can accurately reflect that non-movable fragments and internal fragments have become the main factors affecting the stable operation of memory in high-load scenarios. This score can provide accurate data support for subsequent judgment of the triggering time of defragmentation.

[0041] The memory fragmentation processing method provided by this invention calculates fragmentation scores based on the characteristics of different fragment types, which can more accurately reflect the impact of various fragments on overall memory usage. By obtaining a comprehensive fragmentation score through weighted fusion, it can more comprehensively and objectively reflect the overall memory fragmentation level of the target kernel, providing an accurate basis for subsequent generation of reasonable fragmentation processing strategies, ensuring the adaptability and effectiveness of the memory fragmentation processing process, and further reducing the probability of intelligent cockpit operation failures caused by memory problems.

[0042] In some optional implementations, when calculating fragmentation scores for external fragments, consecutive fragments, and immovable page fragments based on idle page data to obtain a first fragmentation score, the following can be further implemented: When the fragment type is external fragments, the contribution deficiency of each level of idle pages in the first target level to the total idle pages can be calculated based on the contribution rate of each level of idle pages to the total idle pages. The contribution deficiency of each level of idle pages can then be merged to obtain the external fragmentation score. When the fragment type is consecutive fragments, the consecutive fragmentation score is obtained based on the contribution rate of idle pages in the second target level to the total idle pages. When the fragment type is immovable page fragments, the immovable page fragmentation score is obtained based on the contribution rate of immovable idle pages to the total idle pages and the migration weight. Finally, the first fragmentation score is obtained based on the external fragmentation score, the consecutive fragmentation score, and the immovable page fragmentation score.

[0043] Specifically, when the fragmentation type is external fragmentation, the first target order can be determined first. The first target order corresponds to the target contiguous memory allocation size, which can be set to 4, corresponding to 64KB. Starting from the first target order, iterate sequentially to the maximum order. For each order, calculate the ratio of the number of free pages in that order to the total number of free pages to obtain the contribution rate of that order. Calculate the difference between 1 and the contribution rate to obtain the contribution insufficiency of that order. Calculate the order-related weight of that order, which is the square of (current order - first target order + 1). Multiply the contribution insufficiency by the order-related weight to obtain the weighted insufficiency of that order. Accumulate the weighted insufficiency of all orders to obtain the total weighted insufficiency. Accumulate the order-related weights of all orders to obtain the total weight. Multiply the ratio of the total weighted insufficiency to the total weight by 100 to obtain the external fragmentation score.

[0044] When the fragmentation type is contiguous fragmentation, a second target order can be determined. The second target order corresponds to the high-order memory threshold, which can be set to 7, corresponding to 512KB. The number of free pages at the second target order and above is accumulated to obtain the number of high-order available pages. The number of free pages at all orders is accumulated to obtain the total number of free pages. The ratio of the number of high-order available pages to the total number of free pages is calculated. The difference between 1 and the ratio is calculated, and the difference is multiplied by 100 to obtain the contiguous fragmentation score.

[0045] When the fragment type is non-movable page fragment, the number of free pages of non-movable type at each level can be accumulated to obtain the number of non-movable free pages; the number of free pages of movable type at each level can be accumulated to obtain the number of movable free pages; the ratio of the number of non-movable free pages to the sum of the number of non-movable free pages and the number of movable free pages can be calculated; the ratio can be multiplied by 100, and then multiplied by the preset migration weight coefficient to obtain the non-movable page fragmentation score. The preset migration weight coefficient can be set to 1.5.

[0046] The first fragmentation score is obtained by multiplying the external fragmentation score by the first weighting coefficient, the continuous fragmentation score by the second weighting coefficient, and the non-movable page fragmentation score by the third weighting coefficient, and then summing them up. Among them, the first weighting coefficient is 0.35 (which most directly affects the ability to allocate continuous memory and is the core indicator of fragmentation), the second weighting coefficient is 0.25 (which affects the allocation of large blocks of memory such as cameras and GPUs and is of high importance), and the third weighting coefficient is 0.25 (which hinders the memory defragmentation effect and directly affects the effectiveness of the defragmentation strategy).

[0047] The memory fragmentation processing method provided by this invention, for external fragmentation, obtains an external fragmentation score by integrating the contribution deficiency of free pages at each level, which can accurately quantify the impact of uneven distribution of free page levels on external fragmentation; for continuous fragmentation, it completes continuous fragmentation scoring based on contribution rate, reducing computational overhead while ensuring scoring accuracy; for immovable page fragmentation, it calculates immovable page fragmentation score by combining migration weight, which can accurately reflect the degree of obstruction of immovable fragmentation to memory defragmentation; the accurate first fragmentation score can provide a reliable decision basis for subsequent memory defragmentation strategies, effectively improving the targeting and efficiency of vehicle memory defragmentation, reducing the computational power consumption caused by unnecessary defragmentation operations, and reducing the risk of vehicle system lag, response delay or even program crash due to memory fragmentation, thus improving the user's driving experience.

[0048] In some optional implementations, when calculating the fragmentation score of internal fragmentation based on memory load data to obtain the second fragmentation score, the target kernel's swap partition utilization, memory availability, and memory full blocking pressure can also be obtained based on memory load data; and the fragmentation score of internal fragmentation can be calculated based on swap partition utilization, memory availability, and memory full blocking pressure to obtain the second fragmentation score.

[0049] Specifically, swap partition utilization, memory availability, and memory full blocking pressure can be extracted from memory load data; the swap partition utilization is multiplied by the first internal weight to obtain the swap partition pressure component, with the first internal weight being 20; the difference between 1 and memory availability is calculated, and the product of the difference and the second internal weight is used as the memory stress component, with the second internal weight being 30; the normalized memory full blocking pressure PSI is multiplied by the third internal weight to obtain the blocking pressure component, with the third internal weight being 50; the swap pressure component, memory stress component, and blocking pressure component are summed to obtain the internal fragmentation score.

[0050] Multiply the internal fragmented score by the fourth weighting coefficient of 0.15 (relatively minor factors, estimated using indirect indicators, with lower weight) to obtain the second fragmented score; add the first fragmented score and the second fragmented score to obtain the comprehensive fragmented score.

[0051] The memory fragmentation processing method provided by this invention can directly utilize the memory load parameters available to the system to obtain the swap partition utilization rate, memory availability rate and memory full blocking pressure of the target kernel, and then calculate the fragmentation score of the internal fragmentation. It does not require a full traversal and statistical analysis of the kernel memory allocation blocks. While ensuring the accuracy of the quantification of the internal fragmentation degree, it further reduces the computing power and memory overhead caused by the scoring calculation process.

[0052] Step S103: Generate a memory fragmentation handling strategy based on the comprehensive fragmentation score and the real-time running status data of the target kernel.

[0053] The real-time runtime status data of the target kernel is used to dynamically correct the initial processing strategy and generate a memory fragmentation processing strategy that adapts to the current system load.

[0054] In some optional implementations, when generating a memory fragmentation handling strategy based on the comprehensive fragmentation score and the real-time runtime status data of the target kernel, the fragmentation level of the target kernel can be determined based on the comprehensive fragmentation score; an initial handling strategy can be determined based on the fragmentation level; and a memory fragmentation handling strategy can be generated based on the real-time runtime status data and the initial handling strategy.

[0055] Specifically, based on the range of the comprehensive fragmentation score, the fragmentation level can be divided into three levels: low, medium, and high. When the comprehensive fragmentation score is below 10, it is judged as a low fragmentation level, and the initial processing strategy is set to not actively trigger memory defragmentation, but only to perform light free page block merging when the system enters idle standby state; when the comprehensive fragmentation score is between 10 and 30, it is judged as a medium fragmentation level, and the initial processing strategy is set to perform medium defragmentation at preset intervals, only defragmenting memory areas with consecutive free page blocks below a preset threshold; when the comprehensive fragmentation score is not lower than 30, it is judged as a high fragmentation level, and the initial processing strategy is set to immediately trigger full memory defragmentation, migrating non-urgent memory pages to merge large-span consecutive free memory blocks.

[0056] After determining the initial processing strategy, if real-time running status data shows that the current CPU load exceeds 70%, or there are foreground running tasks with a priority higher than the preset threshold, the initial strategy corresponding to the medium fragmentation level will be adjusted to postpone defragmentation, and the initial strategy corresponding to the high fragmentation level will be adjusted to defragment only the free memory areas corresponding to non-core processes, so as to avoid affecting the operation of the current core business. If the current system load is lower than the preset free threshold, the initial processing strategy will be executed directly to ensure the continuity of memory space to meet the system operation requirements.

[0057] The memory fragmentation processing method provided by this invention first classifies fragmentation levels based on a comprehensive fragmentation score, and then adjusts the final fragmentation processing strategy in conjunction with the real-time running status of the target kernel. This method can match the corresponding strength of defragmentation actions to different degrees of memory fragmentation, avoiding unnecessary defragmentation operations that waste computing power when the fragmentation level is low, and preventing insufficient defragmentation strength from failing to resolve memory allocation anomalies when the fragmentation level is high. By adjusting the processing strategy in conjunction with the real-time running status of the vehicle's target kernel, non-urgent defragmentation actions can be postponed when the vehicle system is under high load (such as simultaneously running the autonomous driving perception module, navigation module, and multimedia entertainment module). This avoids defragmentation consuming system resources and causing lag and response delays in core vehicle services, ensuring the smoothness and stability of the vehicle system and effectively improving the user's driving experience.

[0058] In some optional implementations, when determining the initial processing strategy based on the fragmentation level, if the fragmentation level is level one, the initial processing strategy is to not perform a defragmentation operation; if the fragmentation level is level two, the initial processing strategy is to perform asynchronous background defragmentation based on a first defragmentation amount, where the overall score corresponding to level two is greater than or equal to the first score and less than the second score; if the fragmentation level is level three, the initial processing strategy is to perform targeted defragmentation based on a second defragmentation amount, and to allow the termination of processes with process values ​​greater than a first value, where the second defragmentation amount is greater than the first defragmentation amount, and the overall score corresponding to level three is greater than or equal to the second score. And less than the third score; if the fragmentation level is the fourth level, then the initial processing strategy is to perform deep global cleanup based on the third cleanup amount, and to allow the termination of processes with a process value greater than the second value, the third cleanup amount is greater than the second cleanup amount, the second value is less than the first value, and the comprehensive score corresponding to the fourth level is greater than or equal to the third score and less than the fourth score; if the fragmentation level is the fifth level, then the initial processing strategy is to perform emergency global cleanup based on the fourth cleanup amount, and to allow the termination of processes with a process value greater than the third value, the fourth cleanup amount is greater than the second cleanup amount, the third value is less than the second value, and the comprehensive score corresponding to the fifth level is greater than or equal to the fourth score.

[0059] Specifically, the first level is the NONE level, corresponding to a comprehensive fragmentation score of less than 20 points. The initial processing strategy is ACTION_NONE, which means no defragmentation operation is performed, and monitoring continues. The second level is the LOW level, corresponding to a comprehensive fragmentation score greater than or equal to 20 points and less than 40 points. The initial processing strategy is BACKGROUND_COMPACT, which includes: the defragmentation method flag is ASYNC (asynchronous) + LIGHT (lightweight), using a background asynchronous execution method to avoid blocking normal system operation; the defragmentation amount is 4MB, which is limited by writing a trigger value to the kernel interface file / proc / sys / vm / compact_memory and limiting the defragmentation range; the process is not terminated, and the process termination value OOM adj is allowed to be invalid. The third level is the MEDIUM level, corresponding to a comprehensive fragmentation score greater than or equal to 40 and less than 60. The initial processing strategy is TARGETED_COMPACT, which includes setting the defragmentation method to LIGHT, using a lightweight defragmentation approach; a defragmentation size of 16MB, performing defragmentation on the memory management area with the highest fragmentation score; and allowing the termination of processes with an OOM adj value between 700 and 900, prioritizing cache processes with a process value greater than 900. The fourth level is the HIGH level, corresponding to a comprehensive fragmentation score greater than or equal to 60 and less than 80. The initial processing strategy is FULL_COMPACT, which includes setting the defragmentation method to AGGRESSIVE, using a deep defragmentation approach; a defragmentation size of 64MB, performing global defragmentation covering all memory management areas; and allowing the termination of processes with an OOM adj value between 500 and 700, prioritizing service processes and cache processes with a process value greater than 500. The fifth level is the CRITICAL level, with a comprehensive fragmentation score greater than or equal to 80. The initial processing strategy is CRITICAL_KILL, which includes: the defragmentation method is marked as AGGRESSIVE+GLOBAL, using a deep and global defragmentation method; the defragmentation amount is 256MB, performing emergency global defragmentation; the allowed process termination value OOM adj ranges from 300 to 500, prioritizing perception processes, service processes, and cache processes with a process value greater than 300; the maximum number of processes that can be terminated in an emergency is 3.

[0060] The larger the allowed process termination value OOM adj, the lower the process priority and the higher the termination priority. Among processes with the same allowed process termination value OOM adj, the process with the higher total physical memory RSS usage is selected first; the reason for process termination and the current comprehensive fragmentation score are recorded for subsequent trend analysis.

[0061] The memory fragmentation handling method provided by this invention adopts a strategy of no defragmentation or lightweight asynchronous background defragmentation when the fragmentation level is low. This will not interfere with the response of the vehicle's front-end business and will ensure the smooth operation of core functions such as vehicle-machine interaction, vehicle power control, and driving assistance. For different levels of fragmentation, the defragmentation amount and the threshold for terminated processes are adjusted accordingly. This can not only clean up and alleviate fragmentation problems in a timely manner, but also prioritize the normal operation of core processes with low process values, avoid abnormal termination of core vehicle functions, and ensure vehicle driving safety. When the fragmentation level reaches the highest level in an emergency scenario, a strong global defragmentation is used to quickly restore memory availability, which can effectively avoid the risk of vehicle system lag, crashes, or even functional failures.

[0062] In some optional implementations, when adjusting the initial processing strategy based on real-time runtime status data to obtain a memory fragmentation handling strategy, the memory availability, swap partition utilization, memory full-blocking pressure, fragmentation trend, and continuous fragmentation score of the target kernel can be obtained based on the real-time runtime status data. Based on a first relationship between memory availability and a preset utilization threshold, and / or the direction of fragmentation trend change, the amount and method of defragmentation in the initial processing strategy are adjusted. Based on a second relationship between swap partition utilization and a preset swap threshold, and / or a third relationship between continuous fragmentation score and a preset continuous score threshold, the threshold value of processes allowed to terminate in the initial processing strategy is adjusted. Based on the relationship between memory full-blocking pressure and a preset pressure threshold, the defragmentation method in the initial processing strategy is adjusted.

[0063] Specifically, two levels of utilization thresholds can be set, with the second preset utilization threshold being lower than the first preset utilization threshold. The first preset utilization threshold can be set to 50%, and the second preset utilization threshold can be selected as 20% or 15%. When the system's available memory rate is higher than the first preset utilization threshold, the total amount of memory defragmentation in a single operation corresponding to the initial processing strategy is reduced, or the current memory defragmentation mode is maintained. When the system's available memory rate is lower than the second preset utilization threshold, the throttling cooling wait time is shortened, and the execution entry conditions for memory defragmentation are relaxed. If a continuous upward deterioration of the fragmentation trend is detected, the defragmentation cooling wait constraint is directly canceled, and the defragmentation process is immediately started. This control logic can stably output a sufficient amount of continuous physical memory, avoiding problems such as system lag and memory allocation failure caused by memory resource shortages.

[0064] For a multi-round historical comprehensive fragmentation score sequence stored within a preset fixed time window, the fitting slope obtained from linear regression can be used to characterize the fragmentation trend, while setting two trend thresholds: a first trend threshold of +5 and a second trend threshold of -5. If the fitting slope is greater than the first trend threshold, it is determined that the fragmentation is in a continuously worsening trend. The comprehensive score threshold for triggering defragmentation is lowered (preferably by 10%~15%), and scenarios that did not originally meet the triggering conditions are re-evaluated, and defragmentation is initiated in advance to prevent the continuous accumulation of fragmentation. If the system's available memory rate is lower than the second preset utilization rate threshold at this time, the scheduling priority of the memory defragmentation kernel thread is simultaneously increased, prioritizing page migration and merging operations, and prioritizing the generation of contiguous free memory blocks to avoid the risks of memory allocation failure, system lag, and memory overflow. If the fitting slope is less than the second trend threshold, it is determined that the degree of fragmentation is continuously improving, and the defragmentation trigger threshold is raised or the throttling cooling-off waiting time is extended to reduce unnecessary defragmentation overhead.

[0065] A preset swap threshold can be set, for example, 80%. When the overall system swap partition utilization exceeds the preset threshold, the total amount of memory compaction per cycle is reduced or the throttling cooling interval is extended to reduce the CPU overhead caused by page migration. Two consecutive exceedance thresholds are also set, with the second preset consecutive exceedance being greater than the first. The first preset consecutive exceedance can be 3 times, and the second preset consecutive exceedance can be 5 times. When the number of times the overall fragmentation score exceeds the current level threshold reaches the first preset consecutive exceedance, the amount of memory compaction per cycle is increased by 50%. When the number of consecutive exceedances reaches the second preset consecutive exceedance, the fragmentation management action intensity level is upgraded, switching from incremental local fragmentation to deep compaction of the entire memory management area (i.e., deep global compaction). Simultaneously, the scheduling priority of the compaction thread is increased, prioritizing the merging of free pages across all partitions to quickly generate large blocks of contiguous physical memory, ensuring the memory allocation needs of the vehicle's core processes and preventing system lag.

[0066] The memory full-blocking pressure metric is a quantified value of memory blocking latency output by the target kernel, with a preset pressure threshold of 50. When the memory full-blocking pressure exceeds the preset threshold, the regular silent background defragmentation is upgraded to a priority-preemptive active forced defragmentation. Simultaneously, non-urgent user background processes are paused to reclaim idle memory, and system computing power is concentrated to complete full partition fragmentation scanning and page merging. This quickly alleviates memory blocking, ensuring the stable operation of core in-vehicle services such as smart cockpits and autonomous driving, and mitigating the risks of slow function response and system crashes. When the memory full-blocking pressure is less than or equal to the preset pressure threshold, the current defragmentation method remains unchanged.

[0067] The memory fragmentation handling method provided by this invention can release sufficient contiguous memory space in a timely manner when memory pressure is high and fragmentation is severe, ensuring the smooth operation of core processes. When memory pressure is low, it can reduce the interference of defragmentation on the foreground interaction process, avoid stuttering and response delays in vehicle interaction, effectively improve the smoothness and stability of vehicle system operation, improve the user's vehicle interaction experience, and at the same time reduce unnecessary memory read and write losses, extending the service life of related hardware in the vehicle system.

[0068] In some optional implementations, the adjusted defragmentation methods, ranked from lowest to highest intensity, are: background asynchronous defragmentation (executed asynchronously and without blocking the system); lightweight defragmentation (executed synchronously but with limitations on the scope and duration); targeted defragmentation (executed on specific memory management areas); deep global defragmentation (covering all memory management areas); and emergency global defragmentation (using the maximum defragmentation amount and allowing for process termination). Adjustments to the process value thresholds allowed for termination in the initial processing strategy include: lowering the process value threshold and expanding the range of terminateable processes when the action intensity needs to be escalated; and raising the process value threshold and narrowing the range of terminateable processes when the action intensity needs to be downgraded.

[0069] Step S104: Based on the memory fragmentation handling strategy, perform the corresponding fragmentation processing operation on the target kernel.

[0070] Specifically, based on the defragmentation type, defragmentation strength, defragmentation range, and process termination threshold parameters carried by the memory fragmentation handling strategy, the corresponding memory management interface of the target kernel can be called to trigger the corresponding fragmentation processing process.

[0071] If the final determined memory fragmentation handling strategy is not to perform defragmentation, the current memory allocation and management state will be maintained, and memory distribution data and comprehensive fragmentation scores will continue to be updated according to the preset collection cycle before entering the next round of monitoring and judgment process. If the strategy is marked as delayed defragmentation, the defragmentation mark and initial strategy information will be stored, and the real-time running status data of the target kernel will be re-acquired every preset detection cycle. The defragmentation operation will be triggered only after the system load meets the running requirements to avoid preempting the system resources of core business. If the strategy is to perform lightweight background asynchronous defragmentation, the unlocked free page blocks will only be scanned during the idle intervals of system scheduling, and a small-scale page block merging will be completed without blocking the execution of user processes. If the strategy is to perform emergency global defragmentation, all processes in the system will be sorted according to the terminateable process value OOM adj, and processes with low priority and large memory consumption that meet the conditions will be terminated first. After reclaiming the memory space occupied by them, a full page block scan and merging will be performed on all memory management areas of the target kernel to integrate contiguous free memory blocks that meet the large memory allocation requirements. After the fragmentation process is completed, the trigger time, the overall fragmentation score before processing, the overall fragmentation score after processing, the strategy adjustment parameters, and the process termination information are recorded in the system log partition.

[0072] The memory fragmentation processing method provided in this embodiment obtains a comprehensive score by integrating fragmentation scores of different fragmentation types, which can effectively improve the accuracy of fragmentation degree judgment. By combining the real-time running status of the target kernel to generate an adapted fragmentation processing strategy, the intensity and method of fragmentation processing can be flexibly adjusted according to the current system load and business needs. This avoids excessive system resource consumption during fragmentation defragmentation operations when the system is under high load, balancing the fragmentation processing effect and system performance. It can meet the long-term stable operation requirements of the intelligent cockpit system, reduce the probability of cockpit application crashes, system lag, or even restarts, and improve the user experience of the vehicle's intelligent cockpit.

[0073] This embodiment provides a method for handling memory fragmentation. Figure 2 This is a flowchart of a memory fragmentation handling method according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps: Step S201: Obtain the raw memory state data of the target kernel. For details, please refer to [link to relevant documentation]. Figure 1 Step S101 of the illustrated embodiment will not be described again here.

[0074] Step S202: Based on the original memory state data, calculate the fragmentation score corresponding to each fragmentation type, and then merge them to obtain a comprehensive fragmentation score. For details, please refer to [link to relevant documentation]. Figure 1 Step S102 of the illustrated embodiment will not be described again here.

[0075] Step S203: Based on the comprehensive fragmentation score and the real-time runtime status data of the target kernel, a memory fragmentation handling strategy is generated. For details, please refer to [link to relevant documentation]. Figure 1 Step S103 of the illustrated embodiment will not be described again here.

[0076] Step S204: Based on the memory fragmentation handling strategy, perform the corresponding fragmentation processing operation on the target kernel.

[0077] Specifically, step S204 includes: Step S2041: Obtain kernel throttling control parameters.

[0078] The kernel throttling control parameters include at least one of the following: cooling duration, execution frequency, cleanup interval, and process termination interval.

[0079] Specifically, the cooldown time can be 60 seconds, representing the minimum waiting time from the last action to the next action; the execution frequency can be up to 10 times per hour, representing the maximum number of actions executed per unit time; the defragmentation interval can be 5 minutes, representing the minimum interval between two memory defragmentation actions; and the process termination interval can be 1 minute, representing the minimum interval between two process termination actions.

[0080] Step S2042: Perform throttling verification on the memory fragmentation handling strategy based on the throttling control parameters, and obtain the verification result.

[0081] Specifically, the system can obtain the execution time of the current action and the execution time of the last action, and calculate the time difference between them. If the time difference is less than the cooldown time, the verification fails, and the verification result is set to "reject execution." If the cumulative number of actions executed per unit time reaches the execution frequency, the verification fails, and the verification result is set to "reject execution." If the memory fragmentation handling policy includes a memory defragmentation action, and the time interval since the last memory defragmentation is less than the defragmentation interval, the verification fails, and the verification result is set to "reject execution." If the memory fragmentation handling policy includes a process termination action, and the time interval since the last process termination is less than the process termination interval, the verification fails, and the verification result is set to "reject execution." If none of the above conditions are met, the verification passes, and the verification result is set to "allow execution."

[0082] Step S2043: Based on the verification results and memory fragmentation handling strategy, perform the corresponding fragmentation processing operation on the target kernel.

[0083] Specifically, if the verification result allows execution, the corresponding operation is performed according to the action type in the memory fragmentation handling policy: If the action type is memory compaction, global memory compaction is triggered by writing a trigger value to the virtual interface / proc / sys / vm / compact_memory provided by the target kernel, or the compaction aggressiveness is controlled by adjusting the value of the kernel parameter interface / proc / sys / vm / compaction_proactiveness. If the action type includes process termination, target processes are filtered according to the process value threshold in the memory fragmentation handling policy, prioritizing processes with OOM adj values ​​higher than the process value threshold and high RSS usage, executing termination operations and recording the termination reason and the current comprehensive fragmentation score; if the verification result is rejection, the memory fragmentation handling policy is added to the execution queue, waiting for re-verification in the next timed check cycle.

[0084] In some optional implementations, after performing the fragmentation processing operation, the time of the last action execution and the cumulative number of action executions can be updated; the current comprehensive fragmentation score and the executed actions can be recorded to historical data for subsequent trend analysis; and the next fragmentation check can be scheduled with an interval of 30 seconds.

[0085] As an example, when the vehicle is in a parked and dormant state, the total available memory of the target vehicle Linux kernel is 8GB. The fragmentation scores for each type of fragment are calculated as follows: external fragmentation score 0.85, internal fragmentation score 0.78, and idle fragmentation score 0.82. After merging, the overall fragmentation score is 0.82, which is higher than the preset active processing threshold of 0.7. Considering that the target kernel is currently running under low load, the final memory fragmentation handling strategy is to first trigger global memory defragmentation, and then re-evaluate the fragmentation level after defragmentation. If the score is still not up to standard, then low-priority idle background processes will be terminated.

[0086] During the throttling check, it was found that the last processing action was executed 75 seconds ago, exceeding the 60-second cooldown period; the cumulative execution count within the current hour was 2, not exceeding the hourly limit of 10 executions; the last memory compaction action occurred 42 minutes ago, exceeding the minimum compaction interval of 5 minutes. Therefore, the check result was allowed to proceed. Subsequently, a trigger value of 1 was written to the target kernel's virtual interface / proc / sys / vm / compact_memory, triggering global memory compaction. After compaction, the memory status was re-collected, and the overall fragmentation score was calculated to be 0.23, below the acceptable threshold of 0.3. Therefore, no further process termination was required. Finally, the last action execution time was updated to the current time, the cumulative action execution count was updated, and the overall fragmentation score and execution action record were stored in the historical log. Simultaneously, the next fragmentation check was scheduled after 30 seconds.

[0087] The memory fragmentation handling method provided in this embodiment can effectively avoid the fragmentation handling operation being frequently triggered and excessively occupying system computing power and memory resources by completing the throttling verification of defragmentation based on kernel throttling control parameters. At the same time, it can also prevent the fragmentation problem from continuing to worsen due to the long-term non-execution of defragmentation, and achieve dynamic and reasonable control over the timing and intensity of defragmentation triggering.

[0088] This embodiment also provides a memory fragmentation processing device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0089] This embodiment provides a memory fragmentation processing device, such as... Figure 3 As shown, it includes: The data acquisition module 301 is used to acquire the raw memory state data of the target kernel; The scoring fusion module 302 is used to calculate the fragmentation score corresponding to each fragment type based on the original memory state data, and then fuse them to obtain a comprehensive fragmentation score. The strategy generation module 303 is used to generate a memory fragmentation handling strategy based on the comprehensive fragmentation score and the real-time running status data of the target kernel. The fragmentation processing module 304 is used to perform corresponding fragmentation processing operations on the target kernel based on the memory fragmentation processing strategy.

[0090] In some alternative implementations, the scoring fusion module 302 includes: The raw data acquisition unit is used to acquire free page data of each memory management area in the target kernel and memory load data of the target kernel based on the raw memory state data. The first fragmentation scoring unit is used to calculate the fragmentation scores of external fragments, continuous fragments and immovable page fragments based on the idle page data, and obtain the first fragmentation score. The second fragmentation scoring unit is used to calculate the fragmentation score of internal fragmentation based on memory load data, and obtain the second fragmentation score. The comprehensive fragment scoring unit is used to weight and fuse the first fragment score and the second fragment score to obtain the comprehensive fragment score.

[0091] In some alternative implementations, the first fragment scoring unit includes: The external fragmentation scoring subunit is used to calculate the contribution deficiency of each level of free page based on the contribution rate of each level of free page to the total free page if the fragment type is external fragmentation. The contribution deficiency of each level of free page is then merged to obtain the external fragmentation score. The contiguous memory scoring subunit is used to obtain a contiguous fragmentation score based on the contribution rate of free pages in the second target stage to the total free pages if the fragmentation type is contiguous fragmentation. The page fragmentation scoring subunit is used to obtain the fragmentation score of an immovable page based on the contribution rate of immovable free pages to the total free pages and the migration weight if the fragment type is an immovable page fragment. The first fragmentation scoring subunit is used to obtain the first fragmentation score based on external fragmentation scoring, continuous fragmentation scoring, and non-movable page fragmentation scoring.

[0092] In some alternative implementations, the second fragment scoring unit includes: The load data acquisition subunit is used to obtain the target kernel's swap partition utilization, memory availability, and memory full-blocking pressure based on memory load data. The second fragmentation scoring subunit is used to calculate the fragmentation score of internal fragmentation based on swap partition utilization, memory availability, and memory full blocking pressure, thus obtaining the second fragmentation score.

[0093] In some optional implementations, the policy generation module 303 includes: Fragmentation level determination unit, used to determine the fragmentation level of the target kernel based on the comprehensive fragmentation score; The initial strategy determination unit is used to determine the initial processing strategy based on the fragmentation level. The contiguous memory processing unit is used to generate a memory fragmentation handling strategy based on real-time running status data and the initial processing strategy.

[0094] In some optional implementations, the initial strategy determination unit includes: The first strategy determines the sub-unit, which is used to determine the initial processing strategy as not performing a defragmentation operation if the fragmentation level is the first level. The second strategy determines the sub-unit, which is used to determine the initial processing strategy as background asynchronous processing based on the first processing amount if the fragmentation level is the second level. The comprehensive score corresponding to the second level is greater than or equal to the first score and less than the second score. The third strategy determination subunit is used to determine the initial processing strategy based on the second consolidation amount if the fragmentation level is the third level. It allows the termination of processes with a process value greater than the first value. The second consolidation amount is greater than the first consolidation amount. The comprehensive score corresponding to the third level is greater than or equal to the second score and less than the third score. The fourth strategy determination subunit is used to determine the initial processing strategy as deep global reorganization based on the third reorganization amount if the fragmentation level is the fourth level. It allows the termination of processes with a process value greater than the second value. The third reorganization amount is greater than the second reorganization amount, the second value is less than the first value, and the comprehensive score corresponding to the fourth level is greater than or equal to the third score and less than the fourth score. The fifth strategy determination sub-unit is used to determine the initial processing strategy as emergency global reorganization based on the fourth reorganization amount if the fragmentation level is the fifth level. It allows the termination of processes with a process value greater than the third value. The fourth reorganization amount is greater than the second reorganization amount, the third value is less than the second value, and the comprehensive score corresponding to the fifth level is greater than or equal to the fourth score.

[0095] In some alternative implementations, the memory fragmentation processing unit includes: The status data acquisition subunit is used to obtain the target kernel's memory availability, swap partition utilization, memory full blocking pressure, fragmentation trend, and continuous fragmentation score based on real-time running status data. The first strategy adjustment subunit is used to adjust the amount and method of the initial processing strategy based on the first relationship between memory availability and a preset usage threshold, and / or the direction of change in the fragmentation trend. The second strategy adjustment subunit is used to adjust the threshold value of the process value that can be terminated in the initial processing strategy based on the second relationship between the swap partition utilization rate and the preset swap threshold, and / or the third relationship between the continuous fragmentation score and the preset continuous score threshold. The third strategy adjustment subunit is used to adjust the sorting method in the initial processing strategy based on the relationship between the memory full blocking pressure and the preset pressure threshold.

[0096] In some alternative implementations, the fragmentation processing module 304 includes: The parameter acquisition unit is used to acquire kernel throttling control parameters, which include at least one of the following: cooldown duration, execution frequency, cleanup interval, and process termination interval. The throttling verification unit is used to perform throttling verification on the memory fragmentation handling strategy based on throttling control parameters and obtain the verification result. The fragmentation processing unit is used to perform corresponding fragmentation processing operations on the target kernel based on the verification results and memory fragmentation processing strategies.

[0097] The memory fragmentation processing apparatus provided in this embodiment of the invention can execute the memory fragmentation processing method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects for executing the method. Further functional descriptions of the various modules and units described above are the same as those in the corresponding embodiments described above, and will not be repeated here.

[0098] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.

[0099] The following is a detailed reference. Figure 4 This diagram illustrates a structural schematic suitable for implementing an electronic device according to embodiments of the present invention. The electronic device may include a processor (e.g., a central processing unit, graphics processor, etc.) 401, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 402 or a program loaded from memory 408 into random access memory (RAM) 403. The RAM 403 also stores various programs and data required for the operation of the electronic device. The processor 401, ROM 402, and RAM 403 are interconnected via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0100] Typically, the following devices can be connected to I / O interface 405: input devices 406 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 407 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; memory devices 408 including, for example, magnetic tapes, hard disks, etc.; and communication devices 409. Communication device 409 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 4 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.

[0101] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 409, or installed from a memory 408, or installed from a ROM 402. When the computer program is executed by the processor 401, it performs the functions defined in the memory fragmentation handling method of the embodiments of the present invention.

[0102] Figure 4The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of the present invention.

[0103] The present invention provides a vehicle comprising: a cockpit and an on-board terminal, the on-board terminal comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the memory fragmentation processing method of the first aspect or any corresponding embodiment described above.

[0104] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the memory fragmentation handling method shown in the above embodiments is implemented.

[0105] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.

[0106] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.

Claims

1. A method for handling memory fragmentation, characterized in that, The method includes: Obtain the raw memory state data of the target kernel; Based on the original memory state data, the fragmentation score corresponding to each fragment type is calculated and then fused to obtain a comprehensive fragmentation score. Based on the comprehensive fragmentation score and the real-time running status data of the target kernel, a memory fragmentation handling strategy is generated; Based on the memory fragmentation handling strategy, the corresponding fragmentation processing operation is performed on the target kernel.

2. The method according to claim 1, characterized in that, Based on the original memory state data, fragmentation scores corresponding to each fragment type are calculated and then fused to obtain a comprehensive fragmentation score, including: Based on the original memory state data, obtain the free page data of each memory management area in the target kernel and the memory load data of the target kernel; Based on the free page data, the fragmentation scores for external fragments, contiguous fragments, and immovable page fragments are calculated respectively to obtain the first fragmentation score. The contiguous fragments are used to characterize contiguous free memory blocks with a page size greater than or equal to the higher-order memory threshold. Based on the memory load data, calculate the fragmentation score for the fragmentation type as internal fragmentation to obtain a second fragmentation score; The first fragmented score and the second fragmented score are weighted and fused to obtain the comprehensive fragmented score.

3. The method according to claim 2, characterized in that, The fragmentation score is calculated based on the idle page data for external fragments, consecutive fragments, and immovable page fragments, respectively, to obtain a first fragmentation score, including: If the fragment type is external fragment, the contribution deficiency of each level of free page in the first target level is calculated based on the contribution rate of each level of free page to the total free page. The contribution deficiency of each level of free page is then merged to obtain the external fragmentation score. If the fragment type is continuous fragment, the continuous fragmentation score is obtained based on the contribution rate of free pages to the total free pages in the second target stage. If the fragment type is an immovable page fragment, then the immovable page fragmentation score is obtained based on the contribution rate of immovable free pages to the total free pages and the migration weight. The first fragmentation score is obtained based on the external fragmentation score, the continuous fragmentation score, and the non-movable page fragmentation score.

4. The method according to claim 2, characterized in that, The step involves calculating a fragmentation score for internal fragmentation based on the memory load data, resulting in a second fragmentation score, which includes: Based on the memory load data, the swap partition utilization, memory availability, and memory full-blocking pressure of the target kernel are obtained. Based on the swap partition utilization, memory availability, and memory full blocking pressure, a fragmentation score is calculated for the fragmentation type being internal fragmentation, resulting in the second fragmentation score.

5. The method according to claim 1, characterized in that, The step of generating a memory fragmentation handling strategy based on the comprehensive fragmentation score and the real-time runtime status data of the target kernel includes: The fragmentation level of the target kernel is determined based on the comprehensive fragmentation score; Based on the fragmentation level, determine the initial processing strategy; Based on the real-time running status data and the initial processing strategy, the memory fragmentation processing strategy is generated.

6. The method according to claim 5, characterized in that, The determination of the initial processing strategy based on the fragmentation level includes: If the fragmentation level is the first level, then the initial processing strategy is determined to be not to perform a defragmentation operation; If the fragmentation level is the second level, then the initial processing strategy is determined to be asynchronous background processing based on the first processing volume. The comprehensive score corresponding to the second level is greater than or equal to the first score and less than the second score. If the fragmentation level is the third level, then the initial processing strategy is determined to be targeted processing based on the second processing amount, and processes with a process value greater than the first value are allowed to be terminated. The second processing amount is greater than the first processing amount, and the comprehensive score corresponding to the third level is greater than or equal to the second score and less than the third score. If the fragmentation level is the fourth level, then the initial processing strategy is determined to be a deep global cleanup based on the third cleanup amount, and processes with a process value greater than the second value are allowed to be terminated. The third cleanup amount is greater than the second cleanup amount, the second value is less than the first value, and the comprehensive score corresponding to the fourth level is greater than or equal to the third score and less than the fourth score. If the fragmentation level is level 5, then the initial processing strategy is determined to be emergency global cleanup based on the fourth cleanup amount, and processes with a process value greater than the third value are allowed to be terminated. The fourth cleanup amount is greater than the second cleanup amount, the third value is less than the second value, and the comprehensive score corresponding to the fifth level is greater than or equal to the fourth score.

7. The method according to claim 5, characterized in that, The adjustment of the initial processing strategy based on the real-time operating status data to obtain the memory fragmentation processing strategy includes: Based on the real-time running status data, obtain the target kernel's memory availability, swap partition usage, memory full-block pressure, fragmentation trend, and continuous fragmentation score; Based on the first relationship between the memory availability rate and the preset usage rate threshold, and / or the direction of change of the fragmentation trend, the amount and method of the initial processing strategy are adjusted. Based on the second relationship between the swap partition utilization rate and the preset swap threshold, and / or the third relationship between the continuous fragmentation score and the preset continuous score threshold, the threshold value of the process value that is allowed to be terminated in the initial processing strategy is adjusted. Based on the relationship between the memory full-blocking pressure and the preset pressure threshold, the sorting method in the initial processing strategy is adjusted.

8. The method according to any one of claims 1 to 7, characterized in that, The step of performing corresponding fragmentation processing operations on the target kernel based on the memory fragmentation processing strategy includes: Obtain kernel throttling control parameters, which include at least one of the following: cooldown duration, execution frequency, cleanup interval, and process termination interval; Based on the throttling control parameters, the memory fragmentation handling strategy is throttled and verified to obtain the verification result. Based on the verification result and the memory fragmentation handling strategy, the corresponding fragmentation processing operation is performed on the target kernel.

9. A memory fragmentation processing device, characterized in that, The device includes: The data acquisition module is used to acquire the raw memory state data of the target kernel; The scoring fusion module is used to calculate the fragmentation score corresponding to each fragment type based on the original memory state data, and then fuse them to obtain a comprehensive fragmentation score. The strategy generation module is used to generate a memory fragmentation handling strategy based on the comprehensive fragmentation score and the real-time running status data of the target kernel. The fragmentation processing module is used to perform corresponding fragmentation processing operations on the target kernel based on the memory fragmentation processing strategy.

10. A vehicle, characterized in that, include: A cockpit and vehicle-mounted terminal, the vehicle-mounted terminal including a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the method of any one of claims 1 to 8.