CN112286684B - Memory usage control method, device, equipment and medium - Google Patents

Memory usage control method, device, equipment and medium Download PDF

Info

Publication number
CN112286684B
CN112286684B CN202011181125.0A CN202011181125A CN112286684B CN 112286684 B CN112286684 B CN 112286684B CN 202011181125 A CN202011181125 A CN 202011181125A CN 112286684 B CN112286684 B CN 112286684B
Authority
CN
China
Prior art keywords
stack space
preset
execution entity
usage
control parameter
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011181125.0A
Other languages
Chinese (zh)
Other versions
CN112286684A (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.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent 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 Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202011181125.0A priority Critical patent/CN112286684B/en
Publication of CN112286684A publication Critical patent/CN112286684A/en
Application granted granted Critical
Publication of CN112286684B publication Critical patent/CN112286684B/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

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application discloses a method, a device, equipment and a medium for controlling memory usage, wherein the method comprises the following steps: acquiring the stack space usage amount of an execution entity running in target equipment according to a preset rule; determining a stack space control parameter of the execution entity based on the stack space usage; judging whether the stack space control parameter is a preset stack space control parameter or not; and if the stack space control parameter is not the preset stack space control parameter, issuing the stack space control parameter to the execution entity so that the execution entity can control the memory usage amount according to the stack space control parameter. Therefore, the use amount of the stack space of the execution entity can be controlled, unnecessary memory consumption is avoided, and the system memory is saved.

Description

Memory usage control method, device, equipment and medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a medium for controlling memory usage.
Background
The process of executing the application program by the CPU is to execute a strip of instructions in sequence until an exit instruction is executed. The advent of high-level languages has made possible the advent of amateur-type software projects, such as the Linux project in C and assembly languages. The object files containing CPU executable instructions after compiling or interpreting these large items are very large, and when they are loaded into memory, they are the first memory consumption when the application is executed. Many techniques are currently available to reduce this memory consumption, such as dynamic libraries; the programming technology level is also embodied, such as the code reuse rate is improved as much as possible, functions are also realized, and the like.
The execution of the function may involve the storage and alteration of intermediate processes of the execution logic, temporary variables are present in the function to save this intermediate state, the life cycle is only present in the current function, and the data structure stack is well suited to fulfill this requirement, including the function call function semantics. The stack is actually allocated with a memory, and the biggest difference from the stack is that different memory areas are used and have different life cycles.
How many executable instructions and heap memory usage are closely related to the experience of the programmer and cannot be predicted and dynamically adjusted based on real-time monitoring. The use amount of the stack memory is different, different programs use stacks with different sizes, the same program executes different task flows and also uses different stack sizes, and the requirement on the stack size is stable in a relatively stable time period. Therefore, how to control the usage amount of the stack memory becomes a problem to be solved by those skilled in the art.
Disclosure of Invention
In view of this, an object of the present application is to provide a method, an apparatus, a device, and a medium for controlling stack space usage, which can control the stack space usage of an execution entity, avoid unnecessary memory consumption, and save system memory. The specific scheme is as follows:
in a first aspect, the present application discloses a memory usage amount control method, including:
acquiring the stack space usage amount of an execution entity running in target equipment according to a preset rule;
determining a stack space control parameter of the execution entity based on the stack space usage;
judging whether the stack space control parameter is a preset stack space control parameter or not;
and if the stack space control parameter is not the preset stack space control parameter, issuing the stack space control parameter to the execution entity so that the execution entity can control the memory usage amount according to the stack space control parameter.
Optionally, the obtaining, according to a preset rule, a stack space usage amount of an execution entity running in the target device includes:
acquiring the stack space usage amount of an execution entity running in target equipment according to a preset time interval;
and storing the acquired stack space usage into a preset cyclic array.
Optionally, the determining a stack space control parameter of the execution entity based on the stack space usage includes:
predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amounts of the preset number when the sampling values of the preset number of the stack space use amounts of the execution entity are obtained;
judging whether the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold value, wherein the maximum usage amount of the reference stack space is the determined maximum usage amount of the stack space before the maximum usage amount of the current stack space is determined;
and if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold value, taking the maximum usage amount of the current stack space as the stack space control parameter of the execution entity.
Optionally, the predicting a current maximum stack space usage amount of the execution entity based on the sampling values of the preset number of stack space usage amounts includes:
and predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amounts of the preset number and preset adjusting parameters.
Optionally, the predicting the maximum usage amount of the current stack space of the execution entity based on the sampling value of the stack space usage amount of the preset number and a preset adjustment parameter includes:
determining a first correction quantity based on a first sampling value and a first preset adjusting parameter in the sampling values of the stack space usage of the preset number, wherein the first sampling value is the latest acquired stack space usage in the sampling values of the stack space usage of the preset number;
determining a second correction quantity based on a second sampling value and a second preset adjusting parameter in the sampling values of the stack space usage of the preset number, wherein the second sampling value is a sampling value except the first sampling value in the sampling values of the stack space usage of the preset number;
and taking the sum of the first correction quantity and the second correction quantity as the maximum usage amount of the current stack space of the execution entity.
Optionally, after determining whether a difference between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold, the method further includes:
and if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is smaller than a preset deviation threshold value, taking the preset stack space control parameter as the stack space control parameter.
Optionally, the obtaining, according to a preset rule, a stack space usage amount of an execution entity running in the target device includes:
acquiring the stack space usage amount of an execution entity running in the target equipment according to a preset rule through a first process in the target equipment;
correspondingly, after determining the stack space control parameter of the execution entity based on the stack space usage, the method further includes:
and synchronizing the stack space usage and the stack space control parameters to a second process in the target device, wherein the first process and the second process are in a copy relationship, the first process is a master copy, and the second process is a slave copy.
In a second aspect, the present application discloses a memory usage control device, including:
the data acquisition module is used for acquiring the stack space usage amount of an execution entity running in the target equipment according to a preset rule;
a parameter determining module, configured to determine a stack space control parameter of the execution entity based on the stack space usage;
the judging module is used for judging whether the stack space control parameter is a preset stack space control parameter or not;
and the data issuing module is used for issuing the stack space control parameter to the execution entity when the stack space control parameter is not the preset stack space control parameter, so that the execution entity can control the memory usage according to the stack space control parameter.
In a third aspect, the present application discloses an electronic device, comprising:
a memory and a processor;
wherein the memory is used for storing a computer program;
the processor is configured to execute the computer program to implement the memory usage amount control method disclosed above.
In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the memory usage control method disclosed above.
It can be seen that, in the present application, stack space usage of an execution entity running in a target device is obtained according to a preset rule, then, a stack space control parameter of the execution entity can be determined based on the stack space usage, and it is determined whether the stack space control parameter is a preset stack space control parameter, if the stack space control parameter is not the preset stack space control parameter, the stack space control parameter is issued to the execution entity, so that the execution entity controls memory usage according to the stack space control parameter. Therefore, the stack space usage of the execution entity running in the target device can be obtained firstly, then the stack space control parameter can be determined based on the obtained stack space usage, when the stack space control parameter is not the preset stack space control parameter, the stack space usage is indicated to be required to be controlled, the stack space control parameter is issued to the execution entity, and the execution entity can control the memory usage according to the stack space control parameter, so that the stack space usage of the execution entity can be controlled, unnecessary memory consumption is avoided, the requirement of the execution entity on the stack space is always kept at the lowest available level, and the system memory is saved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a flow chart of a memory usage control method disclosed in the present application;
FIG. 2 is a flow chart of a specific memory usage control method disclosed herein;
FIG. 3 is a flow chart of a specific memory usage control method disclosed herein;
fig. 4 is a schematic structural diagram of a memory usage control apparatus according to the present disclosure;
fig. 5 is a block diagram of an electronic device disclosed in the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Referring to fig. 1, an embodiment of the present application discloses a memory usage amount control method, including:
step S11: and acquiring the stack space usage amount of the execution entity operated in the target equipment according to a preset rule.
In a specific implementation process, stack space usage of an execution entity running in a target device needs to be obtained according to a preset rule, wherein the target device is a device that needs to perform memory usage control, and the execution entity is a program or the like running in the target device. The usage of stack space, i.e. the memory usage of the stack
Specifically, the stack space usage of the execution entity running in the target device may be obtained according to a preset time interval, and the obtained stack space usage is stored in a preset loop array, where the loop array may store values of a preset number of stack space usage, and when a first stack space usage is obtained, the first stack space usage is stored in a first position of the loop array, and until the loop array is fully written, overwriting is started from the first position again.
That is, the stack space usage of each execution entity running in the target device is sampled at preset time intervals to obtain a plurality of corresponding sampling values, and the obtained sampling values are stored in a preset cyclic array.
For example, Bni ═ S1, S2, …, Sm } may represent stack space usage of the execution entity, where Bni represents m stack space usage of the nth execution entity in the latest period of time (at most, m is reserved, and m is a preset value), i represents a position where the latest stack space usage sample is located in Bni, and 1 ≦ i ≦ m, which may refer to S2 or S3, or the like. The meaning of the cyclic array Bni is explained by taking i ═ 3, m ═ 6, and n ═ 8 as examples: wherein S3 represents the value of the last stack space usage amount stored in the loop array B83 of the 8 th execution entity, B83 only holds 6 values of the latest sampling, that is, the latest sampling value in B83 is S3, and the oldest sampling point is S4, and S4< S5< S6< S1< S2< S3 are sorted by sampling time points in order from far to near. If the 8 th execution entity is sampled again, new sample values are stored by S4, S5< S6< S1< S2< S3< S4 in chronological order, S5 is the oldest sampling feature, S4 is the newest sample point, and the loop array of the 8 th execution entity is represented by B84.
Step S12: and determining stack space control parameters of the execution entity based on the stack space usage.
It is to be understood that after the stack space usage is obtained, the stack space control parameters of the execution entity may be determined based on the stack space usage. Specifically, the stack space usage of the execution entity within a future period of time is predicted based on the stack space usage, so as to obtain the stack space control parameter.
Step S13: and judging whether the stack space control parameter is a preset stack space control parameter.
Accordingly, after the stack space control parameter is obtained, it is further required to determine whether the stack space control parameter is a preset stack space control parameter. If the stack space control parameter is a preset stack space control parameter, it indicates that the stack space usage of the execution entity in a future period of time is basically unchanged from the current stack space usage, so that a new stack space control parameter does not need to be issued. If the stack space control parameter is not the preset stack space control parameter, the stack space usage amount of the execution entity in a future period of time is greatly changed compared with the current amount, so that the stack space control parameter needs to be issued to the execution entity. Wherein, the preset stack space control parameter may be-1.
Step S14: and if the stack space control parameter is not a preset stack space control parameter, issuing the stack space control parameter to the execution entity so that the execution entity can control the memory usage amount according to the stack space control parameter.
After judging whether the stack space control parameter is a preset stack space control parameter, if the stack space control parameter is not the preset stack space control parameter, the stack space control parameter is sent to the execution entity, so that the execution entity controls the memory usage according to the stack space control parameter.
It can be seen that, in the present application, stack space usage of an execution entity running in a target device is obtained according to a preset rule, then, a stack space control parameter of the execution entity can be determined based on the stack space usage, and it is determined whether the stack space control parameter is a preset stack space control parameter, if the stack space control parameter is not the preset stack space control parameter, the stack space control parameter is issued to the execution entity, so that the execution entity controls memory usage according to the stack space control parameter. Therefore, the stack space usage of the execution entity running in the target device can be obtained firstly, then the stack space control parameter can be determined based on the obtained stack space usage, when the stack space control parameter is not the preset stack space control parameter, the stack space usage is indicated to be required to be controlled, the stack space control parameter is issued to the execution entity, and the execution entity can control the memory usage according to the stack space control parameter, so that the stack space usage of the execution entity can be controlled, unnecessary memory consumption is avoided, the requirement of the execution entity on the stack space is always kept at the lowest available level, and the system memory is saved.
Referring to fig. 2, an embodiment of the present application discloses a specific memory usage amount control method, including:
step S21: and acquiring the stack space usage amount of the execution entity operated in the target equipment according to a preset rule.
In a specific implementation process, the stack space usage amount of the execution entity running in the target device may be obtained by the first process in the target device according to a preset rule.
Step S22: and predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amount of the preset number when the preset number of sampling values of the stack space use amount of the execution entity are obtained.
And when the stack space usage is acquired and every preset number of sampling values of the stack space usage of the execution entity is acquired, predicting the maximum usage of the current stack space of the execution entity based on the sampling values of the preset number of stack space usage. The preset number is also the number of data that can be stored in the above-mentioned cyclic array.
Specifically, the maximum usage amount of the current stack space of the execution entity may be predicted based on the sampling values of the stack space usage amounts of the preset number and a preset adjustment parameter.
First, determining a first correction quantity based on a first sampling value and a first preset adjustment parameter in the sampling values of the preset number of stack space usage amounts, wherein the first sampling value is a latest acquired stack space usage amount in the sampling values of the preset number of stack space usage amounts; determining a second correction quantity based on a second sampling value and a second preset adjusting parameter in the sampling values of the stack space usage of the preset number, wherein the second sampling value is a sampling value except the first sampling value in the sampling values of the stack space usage of the preset number; and taking the sum of the first correction quantity and the second correction quantity as the maximum usage amount of the current stack space of the execution entity. The first preset adjustment parameter may be a difference between 1 and the second preset adjustment parameter, and the second sampling value may be a plurality of values.
The above process is formulated as P n0 =(1-a)*S i +a*(S 1 +S 2 +S i-1 +S i+1 …+S m ) Pn0 represents the maximum usage of stack space generated by the nth execution entity according to the current Bni, where Pn0 represents the latest calculated predicted value, and Pn0 may be replaced by Pn1, which represents the last calculated predicted value. a represents the second preset regulation parameter, 0<a<1。
Step S23: and judging whether the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold value, wherein the maximum usage amount of the reference stack space is the determined maximum usage amount of the stack space before the maximum usage amount of the current stack space is determined.
After the maximum usage amount of the stack space is obtained, it is further required to determine whether a difference between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold, where the maximum usage amount of the reference stack space is a determined maximum usage amount of the stack space before the maximum usage amount of the current stack space is determined.
That is, it is determined whether the deviation between the maximum usage of the current stack space and the maximum usage of the stack space determined at the previous time is greater than or equal to a preset deviation threshold.
Step S24: and if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold value, taking the maximum usage amount of the current stack space as the stack space control parameter of the execution entity.
After judging whether the difference between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold, if the difference between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than the preset deviation threshold, the maximum usage amount of the current stack space can be used as the stack space control parameter of the execution entity.
The stack space control parameter is a percentage value, the smaller the value is, the higher the adjustment frequency is, the finer the control on the resources is, and meanwhile, the more calculation cost is paid.
Step S25: and if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is smaller than a preset deviation threshold value, taking the preset stack space control parameter as the stack space control parameter.
And after judging whether the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold value, if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is less than the preset deviation threshold value, taking the preset stack space control parameter as the stack space control parameter. Wherein, the preset stack space control parameter may be-1.
The stack space usage and the stack space control parameter also need to be synchronized to a second process in the target device, where the first process and the second process are in a copy relationship, the first process is a master copy, and the second process is a slave copy. The second process may include a plurality of processes. The first process and the second process can use paxos protocol for data synchronization. Therefore, when the first process fails, a new primary copy can be elected and generated by the process in the second process, so that the stability and reliability of the memory usage amount control are ensured.
Step S26: and if the stack space control parameter is not the preset stack space control parameter, issuing the stack space control parameter to the execution entity so that the execution entity can control the memory usage amount according to the stack space control parameter.
In practical applications, the memory usage control method disclosed in the foregoing may be performed by a controller module, and as shown in fig. 3, the specific steps are as follows:
A. initializing a controller and determining a primary copy;
B. sampling all execution entities of the system, collecting stack space usage, and filling a loop array Bni;
C. until Bni in the flow B has m sampling points, wherein m is the size of the loop array;
D. reporting the data of the cyclic array to a controller;
E. generating stack space control parameters by the primary copy of the controller;
F. the master copy of the controller synchronizes data such as stack space control parameters and the like to all slave copies;
G. the primary copy of the controller judges whether the stack space control parameter is to be sent to the nth execution entity, namely whether the stack space control parameter is-1;
H. sending the stack space control parameter to the nth execution entity, or continuing to start processing from the flow D;
I. the nth execution entity application stack space control parameter controls the memory usage amount;
J. processing continues from flow D.
Referring to fig. 4, an embodiment of the present application discloses a memory usage control device, including:
the data acquisition module 11 is configured to acquire a stack space usage amount of an execution entity running in the target device according to a preset rule;
a parameter determining module 12, configured to determine a stack space control parameter of the execution entity based on the stack space usage;
a judging module 13, configured to judge whether the stack space control parameter is a preset stack space control parameter;
and the data issuing module 14 is configured to issue the stack space control parameter to the execution entity when the stack space control parameter is not the preset stack space control parameter, so that the execution entity controls the memory usage according to the stack space control parameter.
It can be seen that, in the present application, stack space usage of an execution entity running in a target device is obtained according to a preset rule, then, a stack space control parameter of the execution entity can be determined based on the stack space usage, and it is determined whether the stack space control parameter is a preset stack space control parameter, if the stack space control parameter is not the preset stack space control parameter, the stack space control parameter is issued to the execution entity, so that the execution entity controls memory usage according to the stack space control parameter. Therefore, the stack space usage of the execution entity running in the target device can be obtained firstly, then the stack space control parameter can be determined based on the obtained stack space usage, when the stack space control parameter is not the preset stack space control parameter, the stack space usage is indicated to be required to be controlled, the stack space control parameter is issued to the execution entity, and the execution entity can control the memory usage according to the stack space control parameter, so that the stack space usage of the execution entity can be controlled, unnecessary memory consumption is avoided, the requirement of the execution entity on the stack space is always kept at the lowest available level, and the system memory is saved.
In some specific embodiments, the data obtaining module 11 is configured to: acquiring the stack space usage amount of an execution entity running in target equipment according to a preset time interval; and storing the acquired stack space usage into a preset cyclic array.
In some specific embodiments, the parameter determining module 12 is configured to: predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amount of the preset number when the sampling values of the preset number of the stack space use amount of the execution entity are obtained; judging whether the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold value, wherein the maximum usage amount of the reference stack space is the determined maximum usage amount of the stack space before the maximum usage amount of the current stack space is determined; and if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold value, taking the maximum usage amount of the current stack space as the stack space control parameter of the execution entity.
In some specific embodiments, the parameter determining module 12 is configured to: and predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amounts of the preset number and preset adjusting parameters.
In some specific embodiments, the parameter determining module 12 is configured to: determining a first correction quantity based on a first sampling value and a first preset adjusting parameter in the sampling values of the stack space usage of the preset number, wherein the first sampling value is the latest acquired stack space usage in the sampling values of the stack space usage of the preset number; determining a second correction quantity based on a second sampling value and a second preset adjusting parameter in the sampling values of the stack space usage of the preset number, wherein the second sampling value is a sampling value except the first sampling value in the sampling values of the stack space usage of the preset number; and taking the sum of the first correction quantity and the second correction quantity as the maximum usage amount of the current stack space of the execution entity.
In some specific embodiments, the parameter determining module 12 is configured to: and if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is smaller than a preset deviation threshold value, taking the preset stack space control parameter as the stack space control parameter.
In some specific embodiments, the data obtaining module 11 is configured to: acquiring the stack space usage amount of an execution entity running in the target equipment according to a preset rule through a first process in the target equipment;
correspondingly, the method further comprises the following steps:
and the data synchronization module is used for synchronizing the stack space usage and the stack space control parameters to a second process in the target device, wherein the first process and the second process are in a copy relationship, the first process is a master copy, and the second process is a slave copy.
Referring to fig. 5, a schematic structural diagram of an electronic device 20 provided in an embodiment of the present application is shown, where the electronic device 20 may specifically implement the memory usage amount control method disclosed in the foregoing embodiment.
In general, the electronic device 20 in the present embodiment includes: a processor 21 and a memory 22.
The processor 21 may include one or more processing cores, such as a four-core processor, an eight-core processor, and so on. The processor 21 may be implemented by at least one hardware of a DSP (digital signal processing), an FPGA (field-programmable gate array), and a PLA (programmable logic array). The processor 21 may also include a main processor and a coprocessor, where the main processor is a processor for processing data in an awake state, and is also called a Central Processing Unit (CPU); a coprocessor is a low power processor for processing data in a standby state. In some embodiments, the processor 21 may be integrated with a GPU (graphics processing unit) which is responsible for rendering and drawing images to be displayed on the display screen. In some embodiments, the processor 21 may include an AI (artificial intelligence) processor for processing computing operations related to machine learning.
Memory 22 may include one or more computer-readable storage media, which may be non-transitory. Memory 22 may also include high speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In this embodiment, the memory 22 is at least used for storing the following computer program 221, wherein after the computer program is loaded and executed by the processor 21, the steps of the memory usage amount control method disclosed in any of the foregoing embodiments can be implemented.
In some embodiments, the electronic device 20 may further include a display 23, an input/output interface 24, a communication interface 25, a sensor 26, a power supply 27, and a communication bus 28.
Those skilled in the art will appreciate that the configuration shown in FIG. 5 is not limiting of electronic device 20 and may include more or fewer components than those shown.
Further, an embodiment of the present application also discloses a computer-readable storage medium for storing a computer program, where the computer program is executed by a processor to implement the memory usage amount control method disclosed in any of the foregoing embodiments.
For the specific process of the memory usage amount control method, reference may be made to corresponding contents disclosed in the foregoing embodiments, and details are not repeated here.
The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
Finally, it is further noted that, herein, 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 other elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The method, the device, the equipment and the medium for controlling the memory usage provided by the application are introduced in detail, specific examples are applied in the description to explain the principle and the implementation of the application, and the description of the above embodiments is only used for helping to understand the method and the core idea of the application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (7)

1. A memory usage control method is characterized by comprising the following steps:
acquiring the stack space usage amount of an execution entity running in target equipment according to a preset rule;
determining a stack space control parameter of the execution entity based on the stack space usage;
judging whether the stack space control parameter is a preset stack space control parameter or not;
if the stack space control parameter is not the preset stack space control parameter, the stack space control parameter is sent to the execution entity, so that the execution entity can control the memory usage amount according to the stack space control parameter;
the determining the stack space control parameter of the execution entity based on the stack space usage includes: predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amounts of the preset number when the sampling values of the preset number of the stack space use amounts of the execution entity are obtained; judging whether the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold value, wherein the maximum usage amount of the reference stack space is the determined maximum usage amount of the stack space before the maximum usage amount of the current stack space is determined; if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not smaller than a preset deviation threshold value, taking the maximum usage amount of the current stack space as a stack space control parameter of the execution entity;
predicting the maximum usage amount of the current stack space of the execution entity based on the sampling value of the stack space usage amount of the preset number, including: predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amounts of the preset number and preset adjusting parameters;
predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amounts of the preset number and preset adjusting parameters, wherein the predicting comprises the following steps of: determining a first correction quantity based on a first sampling value and a first preset adjusting parameter in the sampling values of the stack space usage of the preset number, wherein the first sampling value is the latest acquired stack space usage in the sampling values of the stack space usage of the preset number; determining a second correction quantity based on a second sampling value and a second preset adjusting parameter in the sampling values of the stack space usage of the preset number, wherein the second sampling value is a sampling value except the first sampling value in the sampling values of the stack space usage of the preset number; and taking the sum of the first correction quantity and the second correction quantity as the maximum usage amount of the current stack space of the execution entity.
2. The method according to claim 1, wherein the obtaining of the stack space usage amount of the execution entity running in the target device according to the preset rule includes:
acquiring the stack space usage amount of an execution entity running in target equipment according to a preset time interval;
and storing the acquired stack space usage into a preset cyclic array.
3. The method for controlling memory usage according to claim 1, wherein after determining whether a difference between a current maximum usage of stack space and a reference maximum usage of stack space is not less than a preset deviation threshold, the method further comprises:
and if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is smaller than a preset deviation threshold value, taking the preset stack space control parameter as the stack space control parameter.
4. The memory usage control method according to any one of claims 1 to 3, wherein the obtaining of the stack space usage of the execution entity running in the target device according to the preset rule includes:
acquiring the stack space usage amount of an execution entity running in the target equipment according to a preset rule through a first process in the target equipment;
correspondingly, after determining the stack space control parameter of the execution entity based on the stack space usage, the method further includes:
and synchronizing the stack space usage and the stack space control parameters to a second process in the target device, wherein the first process and the second process are in a copy relationship, the first process is a master copy, and the second process is a slave copy.
5. A memory usage control device, comprising:
the data acquisition module is used for acquiring the stack space usage amount of an execution entity running in the target equipment according to a preset rule;
a parameter determining module, configured to determine a stack space control parameter of the execution entity based on the stack space usage;
the judging module is used for judging whether the stack space control parameter is a preset stack space control parameter or not;
the data issuing module is used for issuing the stack space control parameter to the execution entity when the stack space control parameter is not a preset stack space control parameter, so that the execution entity can control the memory usage amount according to the stack space control parameter;
the parameter determination module is specifically configured to: predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amounts of the preset number when the sampling values of the preset number of the stack space use amounts of the execution entity are obtained; judging whether the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not less than a preset deviation threshold value, wherein the maximum usage amount of the reference stack space is the determined maximum usage amount of the stack space before the maximum usage amount of the current stack space is determined; if the difference value between the maximum usage amount of the current stack space and the maximum usage amount of the reference stack space is not smaller than a preset deviation threshold value, taking the maximum usage amount of the current stack space as a stack space control parameter of the execution entity;
predicting the maximum usage amount of the current stack space of the execution entity based on the sampling value of the stack space usage amount of the preset number, including: predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amounts of the preset number and preset adjusting parameters;
predicting the maximum use amount of the current stack space of the execution entity based on the sampling values of the stack space use amounts of the preset number and preset adjusting parameters, wherein the predicting comprises the following steps of: determining a first correction quantity based on a first sampling value and a first preset adjusting parameter in the sampling values of the stack space usage of the preset number, wherein the first sampling value is the latest acquired stack space usage in the sampling values of the stack space usage of the preset number; determining a second correction quantity based on a second sampling value and a second preset adjusting parameter in the sampling values of the stack space usage of the preset number, wherein the second sampling value is a sampling value except the first sampling value in the sampling values of the stack space usage of the preset number; and taking the sum of the first correction quantity and the second correction quantity as the maximum usage amount of the current stack space of the execution entity.
6. An electronic device, comprising:
a memory and a processor;
wherein the memory is used for storing a computer program;
the processor is configured to execute the computer program to implement the memory usage amount control method according to any one of claims 1 to 4.
7. A computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the memory usage control method according to any one of claims 1 to 4.
CN202011181125.0A 2020-10-29 2020-10-29 Memory usage control method, device, equipment and medium Active CN112286684B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011181125.0A CN112286684B (en) 2020-10-29 2020-10-29 Memory usage control method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011181125.0A CN112286684B (en) 2020-10-29 2020-10-29 Memory usage control method, device, equipment and medium

Publications (2)

Publication Number Publication Date
CN112286684A CN112286684A (en) 2021-01-29
CN112286684B true CN112286684B (en) 2022-08-02

Family

ID=74352462

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011181125.0A Active CN112286684B (en) 2020-10-29 2020-10-29 Memory usage control method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN112286684B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107895115A (en) * 2017-12-04 2018-04-10 北京元心科技有限公司 Method and device for preventing stack overflow and terminal equipment
CN108228344A (en) * 2017-08-22 2018-06-29 珠海市魅族科技有限公司 Multi-process internal memory processing method and device, computer installation and readable storage medium storing program for executing
CN108563507A (en) * 2018-04-12 2018-09-21 郑州云海信息技术有限公司 A kind of EMS memory management process, device, equipment and readable storage medium storing program for executing
CN111367588A (en) * 2018-12-25 2020-07-03 杭州海康威视数字技术股份有限公司 Method and device for acquiring stack usage

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108228344A (en) * 2017-08-22 2018-06-29 珠海市魅族科技有限公司 Multi-process internal memory processing method and device, computer installation and readable storage medium storing program for executing
CN107895115A (en) * 2017-12-04 2018-04-10 北京元心科技有限公司 Method and device for preventing stack overflow and terminal equipment
CN108563507A (en) * 2018-04-12 2018-09-21 郑州云海信息技术有限公司 A kind of EMS memory management process, device, equipment and readable storage medium storing program for executing
CN111367588A (en) * 2018-12-25 2020-07-03 杭州海康威视数字技术股份有限公司 Method and device for acquiring stack usage

Also Published As

Publication number Publication date
CN112286684A (en) 2021-01-29

Similar Documents

Publication Publication Date Title
US20100017740A1 (en) Pan and zoom control
CN107992344B (en) Coroutine implementation method and coroutine implementation device
CN112131164B (en) Data scheduling method and device applied to acceleration board card, acceleration board card and medium
US9262233B1 (en) Second-order tuning of spin loops
CN111858200B (en) Throughput control method and device in system test and electronic equipment
US11249737B2 (en) Methods, apparatuses and computer program products for improving productivity for building applications
CN112286684B (en) Memory usage control method, device, equipment and medium
JP6786010B2 (en) Information processing equipment, tuning method and tuning program
CN111555987B (en) Current limiting configuration method, device, equipment and computer storage medium
CN115858667A (en) Method, apparatus, device and storage medium for synchronizing data
JP6673083B2 (en) Parallel processing device, power control program for parallel processing device, and power control method for parallel processing device
CN111274211B (en) Application file storage method, device and system
CN114020717A (en) Method, device, equipment and medium for acquiring performance data of distributed storage system
JP6724631B2 (en) Information processing device and program
CN112486555A (en) Software increment upgrading method, device, equipment and computer readable storage medium
CN117591267B (en) Task processing method, device, medium and system
CN115291797A (en) Capacity expansion method, capacity expansion device, capacity expansion equipment and readable storage medium
CN110162561B (en) Offline compression method, offline compression device, computer equipment and storage medium
CN111858508B (en) Regulation and control method and device of log system, storage medium and electronic equipment
US9483303B2 (en) Differential stack-based symmetric co-routines
JP2009110455A (en) Programmable operation indicator and its program
CN116107634A (en) Instruction control method and device and related equipment
CN116302349A (en) Method for accelerating Java application program starting speed and related components thereof
JP2014232361A (en) Program code generation device
CN115113817A (en) Network card-based storage optimization method and system, electronic device and storage medium

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