CN112363828A - Memory fragment management method and device, vehicle-mounted system and vehicle - Google Patents

Memory fragment management method and device, vehicle-mounted system and vehicle Download PDF

Info

Publication number
CN112363828A
CN112363828A CN202011186943.XA CN202011186943A CN112363828A CN 112363828 A CN112363828 A CN 112363828A CN 202011186943 A CN202011186943 A CN 202011186943A CN 112363828 A CN112363828 A CN 112363828A
Authority
CN
China
Prior art keywords
memory
fragmentation
task
index
determining
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202011186943.XA
Other languages
Chinese (zh)
Other versions
CN112363828B (en
Inventor
方彦彬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Rockwell Technology Co Ltd
Original Assignee
Beijing Rockwell Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Rockwell Technology Co Ltd filed Critical Beijing Rockwell Technology Co Ltd
Priority to CN202011186943.XA priority Critical patent/CN112363828B/en
Publication of CN112363828A publication Critical patent/CN112363828A/en
Application granted granted Critical
Publication of CN112363828B publication Critical patent/CN112363828B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System (AREA)

Abstract

The disclosure relates to a memory fragment management method and device, a vehicle-mounted system and a vehicle. The method comprises the following steps: acquiring allocation information of a memory address space; determining a memory fragmentation degree index based on the distribution information; determining to re-allocate the memory based on the index of the fragmentation degree of the memory; and acquiring a safety identification of the task in current operation, and immediately restarting the task in current operation based on the safety identification or restarting the task in current operation after waiting for safety time. The technical scheme provided by the embodiment of the disclosure is applicable to an application layer, and can improve the problem of memory fragmentation while realizing task security protection by using the security identifier, thereby being beneficial to ensuring the task operation security and simultaneously improving the memory utilization rate.

Description

Memory fragment management method and device, vehicle-mounted system and vehicle
Technical Field
The present disclosure relates to the field of vehicle technologies, and in particular, to a memory fragmentation management method and apparatus, a vehicle-mounted system, and a vehicle.
Background
With the continuous development of vehicle technology and internet technology, the degree of intelligence and interchangeability of vehicles are higher and higher. In which, the information communication between the vehicles and people, and between the vehicles and the outside (for example, between the vehicles and between the vehicles, and between the vehicles and the remote control center) is usually realized by the vehicle-mounted system. In the prior art, part of software programs in a vehicle-mounted system need to execute services with higher complexity, and the requirements on software quality (including reliability, running time delay and the like) are higher at the moment. The complexity of the service means more personnel involved in the development, so that the overall quality of the software may be reduced. Meanwhile, because of the problem of the operation delay, the programming language which can avoid the resource automatic management behavior of the language itself is usually based on C, C + +, etc., but the memory resources are scattered and disordered. One of the more easily occurring problems is the problem of fragmentation outside the memory, that is, the larger continuous memory cannot be allocated while the number of remaining memory controls is large, which further causes failure of service execution, and fragmentation is an irreversible process.
In the prior art, a memory fragmentation management method generally includes memory pooling and memory migration. The size of the allocated memory can be planned in advance by adopting the memory pool, the allocation and the use of the memory can be limited in a memory range planned in advance, and fragmentation is prevented from extending to the whole system. However, when the service is complex and is changing, the memory pool cannot meet the service requirement. Memory migration is usually applied to the kernel level, and is used for fragmentation of a memory after long-time use. After the memory migration, page table modification is needed, which is not applicable to the service scenario of the application layer. In addition, the existing memory fragmentation management method is poor in safety.
Disclosure of Invention
In order to solve the technical problems or at least partially solve the technical problems, the present disclosure provides a memory fragmentation management method, device, vehicle-mounted system and vehicle.
The embodiment of the disclosure provides a memory fragment management method, which includes:
acquiring allocation information of a memory address space;
determining a memory fragmentation degree index based on the distribution information;
determining to re-allocate the memory based on the index of the fragmentation degree of the memory;
and acquiring a safety identification of the task in current operation, and immediately restarting the task in current operation based on the safety identification or restarting the task in current operation after waiting for safety time.
In some embodiments, the obtaining allocation information of the memory address space includes:
scanning the occupation information of the memory address space;
and determining the size of the maximum continuous free memory space and the size of the total free memory space based on the occupation information.
In some embodiments, the determining the index of memory fragmentation degree based on the allocation information includes:
and calculating the memory fragmentation degree index f by adopting f-1-M/T based on the size M of the maximum continuous free memory space and the size T of the total free memory space.
In some embodiments, the determining to re-allocate memory based on the index of degree of memory fragmentation comprises:
acquiring a fragmentation safety threshold;
and if the index of the fragmentation degree of the memory is larger than the fragmentation safety threshold, determining to perform memory allocation again.
In some embodiments, the method further comprises:
and if the index of the fragmentation degree of the memory is equal to or smaller than the fragmentation safety threshold, not performing memory allocation again.
In some embodiments, the restarting the currently running task immediately or after waiting the security time based on the security identifier comprises:
acquiring a code segment associated with the security identifier, wherein the code segment is at least part of codes of a task in current operation;
acquiring an auxiliary threshold; wherein the auxiliary threshold is used for protecting the code segment defined by the security identifier to run, and the auxiliary threshold is greater than the fragmentation security threshold;
if the index of the memory fragmentation degree is equal to or smaller than the auxiliary threshold value and the currently running task runs in the code segment, continuing to run the currently running task;
and restarting the currently running task until the code segment is determined to finish running.
In some embodiments, the method further comprises:
and if the index of the memory fragmentation degree is larger than the auxiliary threshold value, immediately restarting the currently running task.
In some embodiments, the method further comprises:
and performing data backup on the currently running task before restarting.
The embodiment of the present disclosure further provides a device for managing memory fragments, where the device includes:
the allocation information acquisition module is used for acquiring the allocation information of the memory address space;
the fragmentation degree index determining module is used for determining the fragmentation degree index of the memory based on the distribution information;
the memory reallocation determining module is used for determining to reallocate the memory based on the memory fragmentation degree index;
and the memory reallocation execution module is used for acquiring the security identifier of the task in current operation, and immediately restarting the task in current operation based on the security identifier or restarting the task in current operation after waiting for the security time.
In some embodiments, the allocation information obtaining module includes:
the occupation information acquisition submodule is used for scanning the occupation information of the memory address space;
and the characteristic parameter determining submodule is used for determining the size of the maximum continuous free memory space and the size of the total free memory space based on the occupation information.
In some embodiments, the fragmentation degree index determination module is specifically configured to: and calculating the memory fragmentation degree index f by adopting f-1-M/T based on the size M of the maximum continuous free memory space and the size T of the total free memory space.
In some embodiments, the memory reallocation determination module comprises:
the first threshold value obtaining submodule is used for obtaining a fragmentation safety threshold value;
and the allocation determining submodule is used for determining to perform memory allocation again if the memory fragmentation degree index is greater than the fragmentation safety threshold.
In some embodiments, the apparatus further comprises:
and the memory allocation maintaining module is used for not performing memory allocation again if the memory fragmentation degree index is equal to or smaller than the fragmentation safety threshold.
In some embodiments, the memory reallocation execution module comprises:
the characteristic code segment determining submodule is used for acquiring the code segment associated with the safety identification, and the code segment is at least part of codes of the task in current operation;
a second threshold value obtaining submodule for obtaining an auxiliary threshold value; wherein the auxiliary threshold is used for protecting the code segment defined by the security identifier to run, and the auxiliary threshold is greater than the fragmentation security threshold;
the task keeping submodule in current operation is used for continuing to operate the task in current operation if the index of the memory fragmentation degree is equal to or smaller than the auxiliary threshold value and the task in current operation is operated in the code segment;
and the task restarting submodule in current operation is used for restarting the task in current operation until the code segment is determined to finish operation.
In some embodiments, the apparatus further comprises:
and the task in current operation is restarted immediately, and if the index of the fragmentation degree of the memory is greater than the auxiliary threshold value, the task in current operation is restarted immediately.
In some embodiments, the apparatus further comprises:
and the data backup module is used for performing data backup on the currently running task before restarting.
The embodiment of the present disclosure further provides an on-vehicle system, which includes:
a processor and a memory;
the processor is configured to perform the steps of any of the above methods by calling a program or instructions stored in the memory.
The embodiment of the disclosure also provides a vehicle, which comprises the vehicle-mounted system.
Compared with the prior art, the technical scheme provided by the embodiment of the disclosure has the following advantages:
in the memory fragment management method provided by the embodiment of the disclosure, allocation information of a memory address space is acquired; determining a memory fragmentation degree index based on the distribution information; determining to re-allocate the memory based on the index of the fragmentation degree of the memory; and acquiring a safety identification of the task in current operation, and immediately restarting the task in current operation based on the safety identification or restarting the task in current operation after waiting for safety time. Therefore, the memory fragment management method can be suitable for an application layer, improves the problem of memory fragmentation while performing service security protection by using the security identifier, is beneficial to reducing the adverse effect of memory fragmentation on service operation and improving the service operation security, reduces memory fragments through memory fragmentation, and can improve the memory utilization rate.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure.
In order to more clearly illustrate the embodiments or technical solutions in the prior art of the present disclosure, the drawings used in the description of the embodiments or prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without inventive exercise.
Fig. 1 is a schematic flow chart illustrating a memory fragmentation management method according to an embodiment of the present disclosure;
fig. 2 is a schematic flow chart illustrating another memory fragmentation management method according to an embodiment of the present disclosure;
fig. 3 is a schematic flow chart illustrating another memory fragmentation management method according to an embodiment of the present disclosure;
fig. 4 is a schematic flow chart illustrating another memory fragmentation management method according to an embodiment of the present disclosure;
fig. 5 is a schematic flow chart illustrating another memory fragmentation management method according to an embodiment of the present disclosure;
fig. 6 is a schematic structural diagram of a memory fragmentation management apparatus according to an embodiment of the present disclosure;
fig. 7 is a schematic structural diagram of another memory fragmentation management apparatus according to an embodiment of the present disclosure;
fig. 8 is a schematic structural diagram of another memory fragmentation management apparatus according to an embodiment of the present disclosure;
fig. 9 is a schematic structural diagram of an in-vehicle system according to an embodiment of the present disclosure.
Detailed Description
In order that the above objects, features and advantages of the present disclosure may be more clearly understood, aspects of the present disclosure will be further described below. It should be noted that the embodiments and features of the embodiments of the present disclosure may be combined with each other without conflict.
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present disclosure, but the present disclosure may be practiced in other ways than those described herein; it is to be understood that the embodiments disclosed in the specification are only a few embodiments of the present disclosure, and not all embodiments.
In the prior art, when memory allocation is performed, memory allocation requests are sequentially allocated according to a time sequence of the memory allocation requests, and the memory size of each allocation request is not equal. For example, six memory resources of 30M, 10M, 15M, 50M, 10M, and 30M may be sequentially allocated to the processes in response to the time sequence of the memory allocation request, and after the memory resources are allocated to different processes, the memory resources may be released according to the states of the processes. For example, the above six memory resources, wherein the process using two 10M memory resources is finished, and at this time, the two memory resources are also released; however, the two memory resources are physically separated and cannot be allocated to a process at the same time, and the memory allocation cannot be performed if an allocation request for allocating 20M memory resources is received. In addition, for example, if 50M memory resources are allocated to processes requiring 45M memory after being released, 5M memory resources cannot be allocated, so that the problem of fragmentation exists in the memory using process in the prior art.
Aiming at the problem of memory fragmentation, a memory fragmentation management method is provided. The existing memory fragmentation management method mainly comprises a memory pool and memory migration. The main disadvantages of using the memory pool to manage the memory fragments are as follows: first, if the service is complex and is changing continuously, the memory requirement is changing continuously, and finding a suitable memory pool according to the service change requires a more complete test, resulting in a longer period of memory matching. Meanwhile, it is difficult to ensure all the service execution paths, so that it is impossible to ensure that the memory pool completely adapts to the service requirements. Secondly, the service may also join some three-party libraries frequently, or may use some kernel-level interfaces, and the memory of this part is uncontrollable, and when the number of uses is large, the fragmentation of the memory may also be caused.
The memory fragmentation management by adopting memory migration is executed on a kernel level, supports memory organization (memory compact), is used for fragmentation of a memory after long-time use, and has the following defects that: after the memory is required to be migrated, the page table is modified correspondingly. Not applicable to application level business scenarios.
In other memory fragmentation management methods, the sorting of the memory fragmentation may also affect the running service, resulting in a problem that the service runs incorrectly or is terminated forcibly, i.e. the security of memory fragmentation management is poor.
In view of at least some of the above problems, the present disclosure provides a new and simpler memory fragment management method, which is applicable to an application level service scenario and a more complex system, and provides a way for restarting service security by matching a security point (i.e., a security identifier) with an exception callback way, so as to reallocate memory space and integrate a continuous large block of idle memory while ensuring service security; the problem that the system performance is poor due to the fact that the number of the memory fragments is large after the system runs for a long time is solved, and meanwhile the problem that the service cannot run normally due to the interference of memory fragment arrangement is solved, so that the service running safety is guaranteed.
Specifically, first, the memory fragmentation management method provided in the embodiment of the present disclosure performs reallocation of a memory address space by using a system restart mode when it is determined that the degree of memory fragmentation is relatively severe, so that each memory size can be flexibly allocated according to the memory requirement size of a task, thereby avoiding the problem that a memory pool is used for memory fragmentation management, that is, the memory size is planned in advance, and the existing memory allocation is not flexible and cannot be applied to a complex system. Meanwhile, the memory size planned in advance does not need to be matched with the memory size required by the task, and the memory is allocated again based on the memory size required by the task, so that the matching process is saved, the period of memory defragmentation is favorably shortened, and the memory allocation speed is high. Meanwhile, three-party libraries do not need to be converged or an interface of a kernel layer is not needed, so that the memory fragments are avoided, the controllability of the memory fragments is good, and the defragmentation effect is good. Secondly, the memory management method provided by the embodiment of the disclosure restarts tasks in the system, and reallocates the memory address space based on the principle of memory continuous allocation, thereby reducing the fragmentation degree of the memory; the method does not relate to a memory migration process, does not need page table modification, and is applicable to service scenes of an application layer. Thirdly, the memory fragmentation management method provided by the embodiment of the disclosure performs security protection on the currently running service by using the security identifier, so that the currently running task with the security identifier is not forcibly terminated, the problem of running errors due to memory fragmentation is avoided, and the security of memory fragmentation management is improved.
The memory fragmentation management method provided by the embodiment of the disclosure can be applied to memory fragmentation sorting of any memory to reduce the severity of memory fragmentation, thereby improving the memory utilization rate and ensuring safe operation of tasks. For example, the method may be applied to a fixed terminal (e.g., a smart tv or a computer) or a mobile terminal (e.g., a smartphone, a tablet, a mobile computer, or a smart vehicle). When the memory fragmentation management method is applied to a vehicle (e.g., an intelligent vehicle), the method may be executed by any system having a memory in the vehicle, and an on-board system (including a vehicle machine) is taken as an example and is described below.
The following describes, with reference to fig. 1 to fig. 9, a memory fragmentation management method, a memory fragmentation management device, an on-board system, and a vehicle provided in the embodiments of the present disclosure.
Exemplarily, fig. 1 is a schematic flow chart of a memory fragmentation management method according to an embodiment of the present disclosure. Referring to fig. 1, the method includes:
and S110, acquiring the allocation information of the memory address space.
The allocation information of the memory address space (hereinafter, may also be referred to as "memory") is used to represent the allocation of the memory address space, for example, the allocation of occupied space and unoccupied space in the memory address space can be represented. The unoccupied space includes the space which is not occupied from the beginning and also includes the space which is released after being occupied. The occupied space may include a continuous space occupied by a single service, or a continuous space occupied by a plurality of services, which is not distinguished by the present embodiment, and the continuous spaces occupied by one or more tasks may be regarded as the same occupied space.
Illustratively, the allocation information may be: in the memory address space, the space of 0-100M is occupied, the space of 100-. It will be appreciated that the allocation information may vary based on the application scenario of the method.
For example, the allocation condition in this step may be obtained based on the historical memory allocation request record and the space release record. In combination with the above, in a period of time, in response to the time sequence of the memory allocation requests, six memory resources of 30M, 10M, 15M, 50M, 10M, and 30M are allocated in sequence. When two tasks using 10M memory resources are finished, the two memory resources are released. The allocation information may then be: in the memory address space, the space of 0-30M is occupied, the space of 30-40M is unoccupied, the space of 40-105M is occupied, the space of 105-115M is unoccupied, and the space of 115-145M is occupied. Further, a task with 50M memory resources allocated to 45M memory requirements after being released will have 5M memory resources released. The allocation information may then be: in the memory address space, the space of 0-30M is occupied, the space of 30-40M is unoccupied, the space of 40-100M is occupied, the space of 100-. This is merely an exemplary illustration, and does not constitute a limitation on the memory allocation condition in the memory fragmentation management method provided in the embodiment of the present disclosure.
In other embodiments, the allocation status may be obtained by periodically scanning the memory address space based on the occupied information, which is exemplarily described below with reference to fig. 2; or may be implemented based on other ways, which are not limited by the embodiments of the present disclosure.
And S120, determining the index of the fragmentation degree of the memory based on the distribution information.
The memory fragmentation degree index (hereinafter, also referred to as "fragmentation degree index") is used to characterize the fragmentation degree of the memory. With reference to the description of S110, each occupied space and each free space in the memory may be determined by using the allocation information, and based on the relative sizes of the occupied space and the free space, or based on the total amount of the free space and the continuous size of each free space, the fragmentation degree of the memory may be determined, that is, the index of the fragmentation degree of the memory is determined, which is exemplarily described below with reference to fig. 3.
And S130, determining to perform memory allocation again based on the memory fragmentation degree index.
The index of the fragmentation degree of the memory can represent the severity of the fragmentation of the memory.
When fragmentation of the memory is serious, there are many memory fragments, that is, there are many fragments that cannot be effectively utilized, and at this time, in order to gather the memory fragments together to form a large continuous memory space, memory allocation needs to be performed again, that is, in this step, if fragmentation is serious, it is determined that memory allocation is performed again.
When the fragmentation of the memory is slight, the fragmentation of the memory can be utilized to a certain extent, and at this time, in order to keep the continuity of the system operation, the memory reallocation can not be carried out.
For example, when the fragmentation of the memory is serious, the fragmentation degree index of the memory may be larger, and when the fragmentation of the memory is slight, the fragmentation degree index of the memory may be smaller; or, when the memory fragmentation is serious, the index of the memory fragmentation degree may be smaller, and when the memory fragmentation is slight, the index of the memory fragmentation degree may be larger. The correspondence between the severity of the memory fragmentation and the index of the memory fragmentation degree may be different based on different calculation methods of the index of the memory fragmentation degree, which is not limited in the embodiments of the present disclosure. The latter is exemplified below with reference to fig. 4.
S140, acquiring the safety identification of the task in current operation, and immediately restarting the task in current operation based on the safety identification or restarting the task in current operation after waiting for safety time.
The security identifier is used for distinguishing a task security boundary, and in the security boundary, the system cannot forcibly terminate the process of the currently running task, but can restart the currently running task after the processes in the security boundary run completely (the time required here is the security time). Therefore, the normal operation of the program in the security boundary is ensured, the problem that the task in the current operation is in error or is forcibly stopped to be executed due to the memory defragmentation is reduced, and the operation security of the task in the current operation is improved, namely the overall security of the memory defragmentation is improved.
The security identifier may be added based on the importance level of each task before performing memory fragmentation management. Whether the task is important or not is relative to the function of the system, and if the task is necessary for the system to realize the function, the task is an important task; if a task is not necessary for the system to perform its function, then the task is an unimportant task. At this time, the security identifier may be set at the end of the complete code corresponding to the task. Alternatively, when part of the code in the task needs to be protected, the security identifier may be set at both ends of the code segment that needs to be protected, as described in detail below. Illustratively, the security identification may be implemented by a function cs _ start (), cs _ end ().
In the step, the memory address space is redistributed based on the mode of restarting the task in current operation, the memory space does not need to be planned in advance, the process of matching the task size with the planned memory size does not exist, and the memory address space is continuously and flexibly distributed based on the size of the memory required by the restarted task in current operation, so that the memory fragments are reduced. Therefore, compared with the mode of performing fragment management by using a memory pool, the memory fragment management mode provided by the embodiment of the disclosure has higher flexibility of memory reallocation, is applicable to complex and changeable service scenes, saves the process of memory matching, and has higher allocation speed and shorter period when memory allocation is performed again. Meanwhile, the memory fragment management method does not relate to interfaces of a three-party library and a kernel layer, is suitable for service scenes of an application layer, and has the advantages of high controllability of memory fragments and good sorting effect of the memory fragments.
In the memory fragment management method provided by the embodiment of the disclosure, allocation information of a memory address space is acquired; determining a memory fragmentation degree index based on the distribution information; determining to re-allocate the memory based on the index of the fragmentation degree of the memory; and acquiring a safety identification of the task in current operation, and immediately restarting the task in current operation based on the safety identification or restarting the task in current operation after waiting for safety time. Therefore, the method is applicable to an application layer, the problem of memory fragmentation is solved while task safety protection is realized by using the safety identification, and the influence on task operation safety is reduced while the memory utilization rate is improved.
The memory fragment management method may be executed based on external triggering or may be executed automatically and periodically, which is not limited in the embodiment of the present disclosure.
In some embodiments, fig. 2 is a flowchart illustrating another memory fragmentation management method according to this disclosure, and shows a detailed execution flow of S110. On the basis of fig. 1, referring to fig. 2, in the method, S110 may include:
and S111, scanning the occupation information of the memory address space.
Wherein, the occupation information comprises the size and the position of the occupied memory space, so that the size and the position of the free memory space can be determined.
Illustratively, in conjunction with the above, the occupancy information may be: in the memory address space, the space of 0-100M is occupied, the space of 110M-190M is occupied, and the space of 200-300M is occupied. Or the occupancy information may be: in the memory address space, the space of 0-30M is occupied, the space of 40-105M is occupied, and the space of 115-145M is occupied. Or the occupancy information may be: in the memory address space, the space of 0-30M is occupied, the space of 40-100M is occupied, and the space of 115-145M is occupied. This is merely an exemplary illustration and does not constitute a limitation of the occupancy information in the embodiments of the present disclosure. Based on this, the unoccupied space between two adjacent occupied spaces is the free memory space, so that the position and size of each free memory space can be determined.
In this step, the occupancy information of the memory address space may be scanned periodically or aperiodically. For example, the occupation information of the memory address space may be periodically scanned according to a preset time, where the preset time may be 1 hour, 3 hours, 1 day, or other time duration, and may be set according to a scenario to which the method is applied, which is not limited in this disclosure. Based on this, through the occupation information of periodically scanning the memory address space, the periodic monitoring of the fragmentation degree of the memory is convenient to realize, and the periodic arrangement of the memory fragments is favorable to realize the effective management of the memory address space, and the influence of the memory fragments on the system performance is favorable to be reduced.
In other embodiments, defragmentation may be performed on an irregular basis based on the use of the memory in combination with the memory defragmentation management requirement, which is not limited in the embodiments of the present disclosure.
And S112, determining the size of the maximum continuous free memory space and the size of the total free memory space based on the occupation information.
The size of each free memory space can be determined based on the occupation information, and the size of the maximum continuous free memory space can be obtained by comparing the sizes of the free memory spaces or by utilizing a maximum function; the size of the total free memory space can be obtained by summing the sizes of the free memory spaces.
Exemplarily, in connection with the above exemplary description of the occupancy information in S111, when the occupancy information is: in the memory address space, when the space of 0-100M is occupied, the space of 110-190M is occupied, and the space of 200-300M is occupied, two idle memory spaces with the size of 10M exist; based on this, the size of the maximum continuous free memory space is 10M, and the size of the total free memory space is 20M. When the occupation information is: in the memory address space, the space of 0-30M is occupied, the space of 40-105M is occupied, and when the space of 115-145M is occupied, two free memory spaces with the size of 10M exist; based on this, the size of the maximum continuous free memory space is 10M, and the size of the total free memory space is 20M. When the occupation information is: in the memory address space, 0-30M of space is occupied, 40-100M of space is occupied, and 115-145M of space is occupied, two free memory spaces exist, the size of which is 10M and 15M respectively; based on this, the size of the maximum continuous free memory space is 15M, and the size of the total free memory space is 25M. This is merely an exemplary illustration and does not constitute a limitation on the free memory space in the embodiments of the present disclosure.
By this, S110 is completed.
It can be understood that, in this step, the characteristic parameters corresponding to the allocation information are the size of the maximum continuous free memory space and the size of the total free memory space. Therefore, the method is beneficial to simplifying the determination mode of the memory fragmentation degree index in the subsequent step, simplifying the memory fragmentation management method, saving time and improving the memory fragmentation management efficiency.
In other embodiments, when determining the memory fragmentation degree index in a manner different from that shown below, the allocation information may further include other characteristic parameters, which is not limited in this disclosure.
Other steps shown in fig. 2 are the same as those in fig. 1, and can be understood by referring to the above, which is not described herein again. The steps in fig. 3 to 5 that are the same as those in fig. 1 may also be understood with reference to the explanation of fig. 1, and are not described in detail below.
In some embodiments, fig. 3 is a flowchart illustrating a detailed execution flow of S120 of another memory fragmentation management method according to another embodiment of the present disclosure. Based on fig. 1, referring to fig. 3, S120 may specifically include:
and calculating a memory fragmentation degree index f by adopting f as 1-M/T based on the size M of the maximum continuous free memory space and the size T of the total free memory space.
Thus, M/T is obtained by dividing the size M of the maximum continuous free memory space by the size T of the total free memory space; and then subtracting M/T from 1 to obtain the memory fragmentation degree index f, wherein the calculation mode is simpler.
For example, when M is 5M and T is 100M, f is 1-5M/100M, 1-1/20 is 19/20. This is merely an example and does not constitute a limitation on the embodiments of the present disclosure. In other embodiments, the sizes of M and F are determined based on memory footprint information.
Therefore, the calculation of the memory fragmentation degree index f can be realized by adopting a simpler mode, the memory fragmentation management method is facilitated to be simplified, and the memory fragmentation management efficiency is improved.
In other embodiments, other characteristic parameters related to fragmentation may also be determined based on the allocation information, and the memory fragmentation degree index may be calculated in a corresponding manner, which may be set according to the requirement of the memory fragmentation management method, which is not limited in this disclosure.
In some embodiments, fig. 4 is a flowchart illustrating a detailed execution flow of S130 of another memory fragmentation management method according to another embodiment of the present disclosure. On the basis of fig. 1, referring to fig. 4, S130 may include:
s131, acquiring a fragmentation safety threshold.
The fragmentation security threshold is a reference value for determining whether the fragmentation degree of the memory is serious, and may also be referred to as a fragmentation security index. Subsequently, by comparing the index of the fragmentation degree of the memory with the fragmentation safety threshold, whether the fragmentation of the memory is serious can be determined.
Illustratively, the fragmentation security threshold may be stored in a memory space, and the step may directly call the fragmentation security threshold; alternatively, the fragmentation security threshold may be selected or set by a user based on the interactive system in the process of performing memory fragmentation management, which is not limited in the embodiment of the present disclosure.
S132, if the index of the fragmentation degree of the memory is larger than the fragmentation safety threshold, determining to perform memory allocation again.
In combination with the above calculation method of the fragmentation degree index f in S120, when the fragmentation degree index f is larger, it indicates that the occupation ratio of the maximum continuous free memory space in the total free memory space is smaller, and the size of each of the other continuous free memory spaces is smaller than that of the maximum continuous free memory space, so that each of the continuous free memory spaces in the free memory space is smaller and the memory fragmentation is serious. On the contrary, when the fragmentation degree index f is smaller, it indicates that the occupation ratio of the maximum continuous free memory space in the total free memory space is larger, and at this time, there may be also other continuous free memory spaces with larger occupation ratios in the total free memory space, so that there are continuous free memory spaces that can be utilized, and thus, the memory fragmentation is not serious.
Based on this, a fragmentation security threshold is set, and when the memory fragmentation degree index is greater than the fragmentation security threshold, the memory fragmentation is serious, and at this time, the memory allocation is determined to be performed again, so as to improve the memory fragmentation degree.
For example, the value of the fragmentation security threshold may be any value greater than 80% and less than 90%, or the value of the fragmentation security threshold may be any value greater than 0 and less than 1 according to the memory defragmentation requirement, which is not limited in this disclosure.
For example, the value of the fragmentation safety threshold may be a fixed value, or an adjustable value according to different requirements of the system; the fragmentation safety threshold may be set by a fixed value built in the software program, or directly inputting a point value through interaction, or may be set through sliding selection, which is not limited in the embodiment of the present disclosure.
In other embodiments, when the fragmentation degree index f is calculated in other manners, the value of the fragmentation safety threshold may be set correspondingly based on the calculation principle of the fragmentation degree index f, which is not limited in this disclosure.
On the basis of fig. 4, if the fragmentation degree indicator does not exceed the fragmentation safety threshold, that is, the fragmentation degree indicator is smaller, or the fragmentation safety threshold and the fragmentation safety threshold are equal, the influence of the memory fragmentation on the system is smaller, and at this time, the memory reallocation is not required.
In combination with the above, the method may further comprise:
and if the index of the fragmentation degree of the memory is equal to or less than the fragmentation safety threshold, not performing memory allocation again.
When the memory fragmentation degree index is smaller than or equal to the fragmentation safety threshold, the memory fragmentation is not serious, and the influence of the memory fragmentation on the system is small. At this time, the priority is given to the continuous operation of the system, and the memory does not need to be reallocated.
In the memory fragmentation management method provided by the embodiment of the disclosure, the fragmentation degree index can be determined in a simpler calculation manner, and whether memory reallocation is required or not is determined based on the relative size of the fragmentation degree index and the fragmentation safety threshold. Therefore, the measuring mode of the memory fragmentation degree is simple, and the memory fragmentation sorting efficiency is improved. Meanwhile, the size of the fragmentation safety threshold can be flexibly set based on the memory fragmentation sorting requirement, so that the memory fragmentation sorting method can be flexibly suitable for various different service scenes.
In the foregoing embodiment, when the degree of memory fragmentation is severe and the currently running task needs to be restarted, the degree of urgency for restarting the currently running task may be determined according to the severity level of memory fragmentation (hereinafter, two levels are taken as examples for illustration). For example, in an emergency, the currently running program may be restarted immediately; in non-emergency situations, after the operation of the code segment limited by the security identifier (i.e. the code segment associated with the security identifier) is finished, the task is restarted. As exemplified below in connection with fig. 5.
In some embodiments, fig. 5 is a flowchart illustrating a detailed execution flow of S140 of another memory fragmentation management method according to another embodiment of the present disclosure. On the basis of fig. 1, referring to fig. 5, S140 may include:
and S141, acquiring an auxiliary threshold value.
Wherein the auxiliary threshold is used to measure the severity of memory fragmentation.
In conjunction with the above, the secondary threshold is greater than the fragmentation safety threshold. When the memory fragmentation degree index is between the fragmentation safety threshold and the auxiliary threshold, the memory fragmentation degree is not serious, and the memory does not need to be redistributed immediately; at this time, the task can be restarted after the safe running task or the safe code segment of the current running task is finished running. When the index of the fragmentation degree of the memory is larger than the auxiliary threshold, the fragmentation degree of the memory is serious, at the moment, the performance of the system is seriously influenced by the fragmentation of the memory, and all tasks need to be restarted immediately.
For example, the secondary threshold may be set correspondingly based on the setting of the fragmentation safety threshold. For example, when the fragmentation safety threshold is 85%, the auxiliary threshold may be 88%, 90%, 95%, or any value greater than 85% and less than 1, which is not limited by the embodiments of the present disclosure.
In other embodiments, when the memory fragmentation degree index is calculated in other manners, if the fragmentation safety threshold is smaller than the memory fragmentation degree index, which indicates that the memory fragmentation is serious, the auxiliary threshold is set smaller than the fragmentation safety threshold.
And S142, if the index of the fragmentation degree of the memory is equal to or smaller than the auxiliary threshold, determining the code segment limited by the safety mark.
If the index of the fragmentation degree of the memory is equal to or smaller than the auxiliary threshold, the fragmentation degree of the surface memory is not very serious, the memory allocation can be not required to be carried out again immediately, and at the moment, the task can be restarted after the running of the code segment which is protected by the security is finished.
Wherein, the code segment defined by the security identification is the code segment which is protected by security, and the code segment is at least part of the code corresponding to the current running task.
In some embodiments, when the code segment is a partial code of the currently running task, the currently running task may be restarted after the process corresponding to the code segment is finished, without waiting for all codes of the currently running task to be finished running.
In some embodiments, the code segment may also be all codes of the currently running task, and at this time, all codes of the currently running task are protected safely, so that the task is restarted only after all the complete codes of the currently running task are run.
Illustratively, in conjunction with the above, when the function cs _ start (), cs _ end () is adopted as the security identifier, the code segment defined by the security identifier can be determined by recognizing the function.
And S143, if the current running task runs in the code segment, continuing to run the current running task.
When the task in current operation runs in the code segment limited by the safety identification, the system does not actively stop the running of the code segment, but needs to wait for the running of the code segment to finish, so that the process limited by the safety identification or the complete task in current operation is ensured to run normally.
And S144, restarting the task in the current operation until the code segment is determined to be operated and finished.
The time period is the safety time from the time when the code segment protected by the safety mark is determined to the time when the code segment protected by the safety mark is operated to the end. Thus, after waiting the security time, the execution of the secured code segment ends, at which point the task may be restarted.
By this point, S140 is completed, that is, the memory allocation is performed again.
The essence of restarting the task is to restart the system in which the task is located, so that the memory in the system is continuously allocated again, thereby reducing the fragmentation degree of the memory. In an actual implementation mode, the system can be restarted after all tasks are finished running; or, starting the task restart from the initial storable position of the memory of the system, namely starting the system restart; when encountering a task which is safely protected or a part of code segments in the task, suspending restarting; and when the operation of the task or part of code segments in the task which is safely protected is finished, continuing the system restart until the system restart is completed.
In other embodiments, the code segment associated with the security identifier may be obtained first, and then the auxiliary threshold may be obtained, which is not limited in this disclosure.
On the basis of fig. 5, if the fragmentation degree is severe, the currently running task may be restarted immediately to reduce the impact of the memory fragmentation on the system. That is, the method may further include: and if the index of the fragmentation degree of the memory is larger than the auxiliary threshold value, immediately restarting the task in current operation.
In the above embodiment, before restarting, the related data of the currently running task may be backed up, which is beneficial to ensure that the restarted task can run normally.
In some embodiments, the execution flow of the method may include:
firstly, a task in a service judges whether a related code segment P needs to be limited by a security identifier according to the service property of the task, and if the restart can cause serious consequences, the related code is protected by a security protection implementation function cs _ start (), cs _ end ().
The function cs _ start () and cs _ end () are implemented to distinguish the service security identifier (define the location of the security boundary). In the safety identification, the system can not actively restart the process of the service, thereby ensuring the normal operation of the program in the safety identification.
And then, the occupation information of the memory address space of the task process in the current operation is scanned, and the distribution information of the memory address space is obtained.
And then, calculating the memory fragmentation degree index of the memory address space according to the distribution information so as to represent the memory fragmentation condition.
The specific mode can be as follows: based on the occupation information of the memory address space, obtaining the size M of the maximum continuous free memory space and the size T of the total free memory space, and calculating to obtain a fragmentation degree index f which is 1-M/T;
and then, acquiring a fragmentation safety threshold fs which is an adjustable parameter.
The fragmentation degree index f is compared with a fragmentation safety threshold fs.
If the fragmentation degree index f is smaller than the fragmentation safety threshold fs, no processing is performed at this time.
If the fragmentation degree index f is greater than the fragmentation security threshold fs, a restart notification is issued.
After receiving the notification, each service can perform ending work before restarting.
And after finishing the ending work of each service, judging whether the current service is still in the safe code segment P.
If P is not done, a reboot is performed.
If P is in progress, the restart is suspended and the P operation is waited to end.
When P ends, system restart continues.
In the memory fragment management method, due to the fact that the system after restarting can reinitialize the service, and the memory can be redistributed, the memory fragmentation condition is reduced, and the memory utilization rate is improved; meanwhile, the protection of the code segment corresponding to the service is realized based on the safety identification, and the service operation safety can be improved.
The memory fragment management method provided by the embodiment of the disclosure can ensure the service safety by using the safety identification, and simultaneously can avoid the problem that the service cannot normally operate due to the memory failure in the critical time caused by the deterioration of the memory fragments after the system operates for a long time, i.e. the memory utilization rate is improved, thereby being beneficial to reducing the condition that the service cannot normally operate and ensuring the normal operation of the service and the whole system; meanwhile, the calculation mode of the memory fragmentation degree index and the determination mode of the memory fragmentation degree are simple, so that the difficulty of the memory fragmentation overall method is reduced, the execution efficiency is improved, and the system performance is further improved.
On the basis of the foregoing embodiments, an embodiment of the present disclosure further provides a memory fragmentation management device. The memory fragmentation management apparatus can be used to execute any memory fragmentation management method in the foregoing embodiments, and therefore, the memory fragmentation management apparatus also has the beneficial effects of any memory fragmentation management method in the foregoing embodiments, and the same points can be understood with reference to the explanation of the memory fragmentation management method in the foregoing, and are not described again in the following.
Fig. 6 is a schematic structural diagram of a memory fragmentation management device according to an embodiment of the present disclosure. Referring to fig. 6, the apparatus may include: an allocation information obtaining module 310, configured to obtain allocation information of a memory address space; a fragmentation degree index determining module 320, configured to determine a memory fragmentation degree index based on the allocation information; a memory reallocation determination module 330, configured to determine to reallocate memory based on the index of the degree of memory fragmentation; the memory reallocation execution module 340 is configured to obtain a security identifier of the currently running task, and immediately restart the currently running task based on the security identifier or restart the currently running task after waiting for a security time.
In the memory fragmentation management apparatus provided in the embodiment of the present disclosure, the allocation information obtaining module 310 may obtain allocation information of a memory address space; the fragmentation degree index determination module 320 may determine a memory fragmentation degree index based on the allocation information; the memory reallocation determination module 330 may determine to reallocate the memory based on the index of the degree of fragmentation of the memory; the memory reallocation execution module 340 may obtain the security identifier of the currently running task, and immediately restart the currently running task based on the security identifier or restart the currently running task after waiting for the security time. Therefore, the method is applicable to an application layer, realizes task safety protection by using the safety identification, avoids the task from being forcibly terminated, ensures the operation safety of the system, improves the fragmentation problem of the memory, and is favorable for improving the utilization rate of the memory and reducing the influence on the operation safety of the task.
Meanwhile, the memory reallocation execution module 340 in the device realizes the reallocation of the memory address space based on the mode of restarting the task in current operation, does not need to plan the memory space in advance, does not have the process of matching the task size with the planned memory size, and continuously flexibly allocates the memory address space based on the size of the memory required by the restarted task in current operation so as to reduce memory fragments. Therefore, compared with the mode of performing fragment management by adopting the memory pool, the device can realize higher flexibility of memory reallocation of the memory management mode, is suitable for complex and changeable service scenes, saves the process of memory matching, and has higher allocation speed and shorter period when memory allocation is performed again. Meanwhile, when the device realizes the memory fragment management method, the device does not relate to interfaces of a three-party library and a kernel layer, can be applied to service scenes of an application layer, and has higher controllability of the memory fragments and better sorting effect of the memory fragments.
In some embodiments, fig. 7 is a schematic structural diagram of another memory fragmentation management device according to the present disclosure. Referring to fig. 7 in addition to fig. 6, the allocation information acquiring module 310 includes: an occupation information acquisition submodule 311, configured to scan occupation information of a memory address space; the characteristic parameter determining sub-module 312 is configured to determine, based on the occupancy information, a size of the maximum continuous free memory space and a size of the total free memory space.
Therefore, the occupied information acquisition submodule 311 and the characteristic parameter determination submodule 312 can be used to acquire the allocation information of the memory address space, the number of the characteristic parameters used for determining the fragmentation index of the memory in the allocation information is small, the acquisition mode is simple, the subsequent calculation process is simplified, and the memory fragmentation management efficiency is improved.
In some embodiments, with continued reference to fig. 7, the fragmentation degree index determination module 320 is specifically configured to: and calculating a memory fragmentation degree index f by adopting f as 1-M/T based on the size M of the maximum continuous free memory space and the size T of the total free memory space.
Thus, the fragmentation degree index determination module 320 may determine the memory fragmentation degree index based on the allocation information; meanwhile, the memory fragmentation degree index f can be determined by adopting the mode of directly calculating the ratio, the calculation mode is simple, the error rate is low, the memory fragmentation management method is facilitated to be simplified, and the memory fragmentation management efficiency is improved.
In some embodiments, with continued reference to fig. 7, the memory reallocation determination module 330 includes: a first threshold obtaining sub-module 331, configured to obtain a fragmentation safety threshold; the allocation determining submodule 332 is configured to determine to re-allocate the memory if the memory fragmentation degree index is greater than the fragmentation security threshold.
Thus, the memory allocation can be determined to be performed again in combination with the fragmentation security threshold.
In some embodiments, with continued reference to fig. 7, the apparatus further comprises: the memory allocation maintaining module 350 is configured to not perform memory allocation again if the memory fragmentation degree index is equal to or smaller than the fragmentation security threshold.
Therefore, the system can be continuously operated when the fragmentation of the memory is not serious.
Meanwhile, whether the memory needs to be reallocated or not is determined based on the relative size of the fragmentation safety threshold and the fragmentation degree index, so that the measuring mode of the fragmentation degree of the memory is simpler, and the improvement of the memory defragmentation efficiency is facilitated. And the size of the fragmentation safety threshold can be flexibly set based on the memory fragmentation sorting requirement, so that the memory fragmentation sorting method can be flexibly suitable for various different service scenes.
In some embodiments, with continued reference to fig. 7, the memory reallocation execution module 340 includes: the characteristic code segment determining sub-module 342 is configured to obtain a code segment associated with the security identifier, where the code segment is at least part of a code of a currently running task; a second threshold value obtaining sub-module 341, configured to obtain an auxiliary threshold value; wherein the auxiliary threshold is used for protecting the code segment defined by the security identifier to run, and the auxiliary threshold is greater than the fragmentation security threshold; a task-in-current-operation keeping sub-module 343, configured to continue to operate the task in current operation if the index of the memory fragmentation degree is equal to or smaller than the auxiliary threshold and the task in current operation is operated in the code segment; and the task restarting submodule 344 in current operation is used for restarting the task in current operation until the operation of the code segment is determined to be finished.
Therefore, when the fragmentation of the memory is not serious, the system can be restarted after the operation of the safety-protected code segment is finished, so that the operation of at least part of tasks can be ensured to be finished, and the influence of the defragmentation of the memory on the operation state and the performance of the system can be reduced.
In some embodiments, with continued reference to fig. 7, the apparatus further comprises: the task in current operation is restarted immediately module 345, which is used to restart the task in current operation immediately if the index of the fragmentation degree of the memory is greater than the auxiliary threshold.
Thus, the system can be restarted immediately when the fragmentation of the memory is serious.
In some embodiments, fig. 8 is a schematic structural diagram of another memory fragmentation management device according to an embodiment of the present disclosure. On the basis of fig. 6, referring to fig. 8, the apparatus further includes: and the data backup module 360 is used for performing data backup on the currently running task before restarting.
Thus, data security can be ensured.
On the basis of the above embodiments, the embodiments of the present disclosure also provide a computer-readable storage medium on which a computer program is stored; the computer program, when executed by a processor, performs the steps of any of the methods described above. Therefore, the storage medium also has the advantages of the method in the above embodiments, and the same points can be understood by referring to the explanation of the method in the above, which is not repeated herein.
From the above description of the embodiments, it is obvious for a person skilled in the art that the present disclosure can be implemented by software and necessary general hardware, and certainly can be implemented by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the present disclosure may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions (computer programs) for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the method in any of the above embodiments of the present disclosure.
On the basis of the above embodiment, the embodiment of the present disclosure further provides an in-vehicle system, which may include a processor and a memory; the processor is operative to perform the steps of any of the methods of the embodiments of the present disclosure by calling a program or instructions stored in the memory. Therefore, the vehicle-mounted system also has the advantages of any method and device in the above embodiments, and the same points can be understood by referring to the explanation of the method and device in the above description, which is not repeated herein.
For example, the vehicle-mounted system may be a vehicle control unit, a driving system controller, a video and audio system controller, a driving assistance system controller, or other device devices or constituent components in the vehicle that can execute a software program, which is not limited in this disclosure.
In some embodiments, fig. 9 is a schematic structural diagram of an on-board system according to an embodiment of the present disclosure. Referring to fig. 9, the in-vehicle system may include: a memory 401, one or more processors 402 (one processor 402 is illustrated in fig. 9 for example); the in-vehicle system may further include: an input device 403 and an output device 404.
The processor 401, the memory 402, the input device 403, and the output device 404 in the in-vehicle system may be connected by a bus or in other manners, and fig. 9 illustrates an example of a connection manner by a bus.
The memory 402 may be a non-transitory computer-readable storage medium, which may be used to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the memory fragmentation management method for increasing the memory allocation speed in the embodiment of the present disclosure (for example, the allocation information obtaining module 310, the fragmentation degree index determining module 320, the memory reallocation determining module 330, and the memory reallocation executing module 340 shown in fig. 6). The processor 401 executes various functional applications and data processing of the server by running software programs, instructions and modules stored in the memory 402, that is, implements the memory fragmentation management method of the above-described method embodiment.
The memory 402 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to use of the electronic device, and the like.
Further, the memory 402 may include high speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device.
In some embodiments, memory 402 may optionally include memory located remotely from processor 401, which may be connected to the terminal device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 403 may be used to receive input numeric or character information and generate key signal inputs related to user settings and function control of the electronic apparatus. The output device 404 may include a display device such as a display screen.
In this embodiment, the vehicle-mounted system performs memory fragment management in a passable manner, that is, obtains allocation information of a memory address space; determining a memory fragmentation degree index based on the distribution information; determining to re-allocate the memory based on the index of the fragmentation degree of the memory; and acquiring a safety identification of the task in current operation, and immediately restarting the task in current operation based on the safety identification or restarting the task in current operation after waiting for safety time. Therefore, the problem of memory fragmentation is solved, and meanwhile, the task safety protection is realized by using the safety identification, so that the influence on the task operation safety is reduced while the memory utilization rate is improved.
On the basis of the above embodiments, the embodiments of the present disclosure further provide a vehicle, where the vehicle includes the on-board system of the embodiments of the present disclosure, and a processor in the on-board system may execute the steps of any one of the methods of the embodiments of the present disclosure by calling a program or instructions stored in a memory. Therefore, the memory recovery speed of the vehicle-mounted system in the vehicle is high, the memory distribution speed is high, the response speed of the vehicle-mounted system to a user or an external instruction is high, the vehicle-mounted system of the intelligent vehicle runs more smoothly, and the user experience is improved.
In other embodiments, the vehicle may further include other structural or functional components known to those skilled in the art, which are not described or limited in this disclosure.
It is noted that, in this document, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus.
The foregoing are merely exemplary embodiments of the present disclosure, which enable those skilled in the art to understand or practice the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the disclosure. Thus, the present disclosure is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (15)

1. A memory fragmentation management method is characterized by comprising the following steps:
acquiring allocation information of a memory address space;
determining a memory fragmentation degree index based on the distribution information;
determining to re-allocate the memory based on the index of the fragmentation degree of the memory;
and acquiring a safety identification of the task in current operation, and immediately restarting the task in current operation based on the safety identification or restarting the task in current operation after waiting for safety time.
2. The method of claim 1, wherein the obtaining allocation information of memory address space comprises:
scanning the occupation information of the memory address space;
and determining the size of the maximum continuous free memory space and the size of the total free memory space based on the occupation information.
3. The method of claim 2, wherein determining a memory fragmentation level indicator based on the allocation information comprises:
and calculating the memory fragmentation degree index f by adopting f-1-M/T based on the size M of the maximum continuous free memory space and the size T of the total free memory space.
4. The method of claim 1, wherein determining to re-allocate memory based on the index of extent of memory fragmentation comprises:
acquiring a fragmentation safety threshold;
and if the index of the fragmentation degree of the memory is larger than the fragmentation safety threshold, determining to perform memory allocation again.
5. The method of claim 5, further comprising:
and if the index of the fragmentation degree of the memory is less than or equal to the fragmentation safety threshold, not performing memory allocation again.
6. The method of claim 4, wherein the restarting the currently running task immediately or after waiting a security time based on the security identifier comprises:
acquiring a code segment associated with the security identifier, wherein the code segment is at least part of codes of a task in current operation;
acquiring an auxiliary threshold, wherein the auxiliary threshold is used for protecting the code segment defined by the security identifier to run, and the auxiliary threshold is greater than the fragmentation security threshold;
if the index of the memory fragmentation degree is equal to or smaller than the auxiliary threshold value and the currently running task runs in the code segment, continuing to run the currently running task;
and restarting the currently running task until the code segment is determined to finish running.
7. The method of claim 6, further comprising:
and if the index of the memory fragmentation degree is larger than the auxiliary threshold value, immediately restarting the currently running task.
8. The method of claim 6 or 7, further comprising:
and performing data backup on the currently running task before restarting.
9. A memory fragmentation management apparatus, comprising:
the allocation information acquisition module is used for acquiring the allocation information of the memory address space;
the fragmentation degree index determining module is used for determining the fragmentation degree index of the memory based on the distribution information;
the memory reallocation determining module is used for determining to reallocate the memory based on the memory fragmentation degree index;
and the memory reallocation execution module is used for acquiring the security identifier of the task in current operation, and immediately restarting the task in current operation based on the security identifier or restarting the task in current operation after waiting for the security time.
10. The apparatus of claim 9, wherein the allocation information obtaining module comprises:
the occupation information acquisition submodule is used for scanning the occupation information of the memory address space;
and the characteristic parameter determining submodule is used for determining the size of the maximum continuous free memory space and the size of the total free memory space based on the occupation information.
11. The apparatus according to claim 10, wherein the fragmentation level indicator determining module is specifically configured to: and calculating the memory fragmentation degree index f by adopting f-1-M/T based on the size M of the maximum continuous free memory space and the size T of the total free memory space.
12. The apparatus of claim 11, wherein the memory reallocation determination module comprises: (ii) a
The first threshold value obtaining submodule is used for obtaining a fragmentation safety threshold value;
and the allocation determining submodule is used for determining to perform memory allocation again if the memory fragmentation degree index is greater than the fragmentation safety threshold.
13. The apparatus of claim 12, wherein the memory reallocation execution module comprises:
the characteristic code segment determining submodule is used for acquiring the code segment associated with the safety identification, and the code segment is at least part of codes of the task in current operation;
a second threshold value obtaining submodule for obtaining an auxiliary threshold value; the auxiliary threshold is used for protecting the code segment defined by the safety identification to run, and the auxiliary threshold is larger than the fragmentation safety threshold;
the task keeping submodule in current operation is used for continuing to operate the task in current operation if the index of the memory fragmentation degree is equal to or smaller than the auxiliary threshold value and the task in current operation is operated in the code segment;
and the task restarting submodule in current operation is used for restarting the task in current operation until the code segment is determined to finish operation.
14. An in-vehicle system, comprising:
a processor and a memory;
the processor is adapted to perform the steps of the method of any one of claims 1-8 by calling a program or instructions stored in the memory.
15. A vehicle characterized by comprising the on-board system of claim 14.
CN202011186943.XA 2020-10-30 2020-10-30 Memory fragment management method and device, vehicle-mounted system and vehicle Active CN112363828B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011186943.XA CN112363828B (en) 2020-10-30 2020-10-30 Memory fragment management method and device, vehicle-mounted system and vehicle

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011186943.XA CN112363828B (en) 2020-10-30 2020-10-30 Memory fragment management method and device, vehicle-mounted system and vehicle

Publications (2)

Publication Number Publication Date
CN112363828A true CN112363828A (en) 2021-02-12
CN112363828B CN112363828B (en) 2024-01-12

Family

ID=74513787

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011186943.XA Active CN112363828B (en) 2020-10-30 2020-10-30 Memory fragment management method and device, vehicle-mounted system and vehicle

Country Status (1)

Country Link
CN (1) CN112363828B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114741208A (en) * 2022-06-13 2022-07-12 北京智芯微电子科技有限公司 Electric energy meter, memory stack management method, memory stack management device and storage medium thereof

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120303916A1 (en) * 2011-05-25 2012-11-29 International Business Machines Corporation Defragmentation of data storage pools
CN104899153A (en) * 2015-06-04 2015-09-09 上海卓易科技股份有限公司 Background application cleaning method and system
CN105975398A (en) * 2015-12-07 2016-09-28 国家电网公司 Method for memory fragmentation management
CN106708746A (en) * 2016-12-30 2017-05-24 郑州云海信息技术有限公司 On-line memory defragmentation method and device
CN111506426A (en) * 2020-04-17 2020-08-07 翱捷科技(深圳)有限公司 Memory management method and device and electronic equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120303916A1 (en) * 2011-05-25 2012-11-29 International Business Machines Corporation Defragmentation of data storage pools
CN104899153A (en) * 2015-06-04 2015-09-09 上海卓易科技股份有限公司 Background application cleaning method and system
CN105975398A (en) * 2015-12-07 2016-09-28 国家电网公司 Method for memory fragmentation management
CN106708746A (en) * 2016-12-30 2017-05-24 郑州云海信息技术有限公司 On-line memory defragmentation method and device
CN111506426A (en) * 2020-04-17 2020-08-07 翱捷科技(深圳)有限公司 Memory management method and device and electronic equipment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114741208A (en) * 2022-06-13 2022-07-12 北京智芯微电子科技有限公司 Electric energy meter, memory stack management method, memory stack management device and storage medium thereof

Also Published As

Publication number Publication date
CN112363828B (en) 2024-01-12

Similar Documents

Publication Publication Date Title
CN110532197B (en) Memory recovery method and device, electronic equipment and storage medium
CN111338779B (en) Resource allocation method, device, computer equipment and storage medium
CN109766172B (en) Asynchronous task scheduling method and device
CN113064748B (en) Process succession method, device, electronic equipment and storage medium
CN112527489A (en) Task scheduling method, device and equipment and computer readable storage medium
US8806497B2 (en) System and method for altering the work definitions in an iterative parallel opportunistic work stealing scheduler
CN111638953B (en) Method, device and storage medium for realizing GPU virtualization
CN115617497A (en) Thread processing method, scheduling component, monitoring component, server and storage medium
CN106557404B (en) Application control method and mobile terminal
CN112363828B (en) Memory fragment management method and device, vehicle-mounted system and vehicle
CN108897603B (en) Memory resource management method and device
CN107315631B (en) Task scheduling method and device
CN110555009B (en) Processing method and device for Network File System (NFS) service
CN109284137B (en) Hypervisor-based QNX operating system starting method and device
CN112286559A (en) Upgrading method and device for vehicle-mounted intelligent terminal
CN112068960A (en) CPU resource allocation method, device, storage medium and equipment
CN116450328A (en) Memory allocation method, memory allocation device, computer equipment and storage medium
CN115658295A (en) Resource scheduling method and device, electronic equipment and storage medium
CN115587049A (en) Memory recovery method and device, electronic equipment and storage medium
CN106375372B (en) big data resource allocation method and device
CN113965611A (en) SaaS (software as a service) industrial APP (application) operation method based on resource release and recovery
CN113867145A (en) Application control method and device, electronic equipment and storage medium
CN114077493A (en) Resource allocation method and related equipment
CN111309627A (en) Method and system for preventing test conflict in software test
CN115168057B (en) Resource scheduling method and device based on k8s cluster

Legal Events

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