Specific embodiment
The feature and exemplary embodiment of various aspects of the invention is described more fully below, in order to make mesh of the invention
, technical solution and advantage be more clearly understood, with reference to the accompanying drawings and embodiments, the present invention is further retouched in detail
It states.It should be understood that specific embodiment described herein is only configured to explain the present invention, it is not configured as limiting the present invention.
To those skilled in the art, the present invention can be real in the case where not needing some details in these details
It applies.Below the description of embodiment is used for the purpose of better understanding the present invention to provide by showing example of the invention.
It should be noted that, in this document, relational terms such as first and second and the like are used merely to a reality
Body or operation are distinguished with another entity or operation, are deposited without necessarily requiring or implying between these entities or operation
In any actual relationship or order or sequence.Moreover, the terms "include", "comprise" or its any other variant are intended to
Non-exclusive inclusion, so that the process, method, article or equipment including a series of elements is not only wanted including those
Element, but also including other elements that are not explicitly listed, or further include for this process, method, article or equipment
Intrinsic element.In the absence of more restrictions, the element limited by sentence " including ... ", it is not excluded that including
There is also other identical elements in the process, method, article or equipment of the element.
In order to better understand the present invention, it below in conjunction with attached drawing, is described in detail according to an embodiment of the present invention and is stored back to
Receiving method and Memory recycle device, it should be noted that these embodiments are not for limiting the scope of the present disclosure.
Fig. 1 shows the applicable system architecture schematic diagram of method for recovering internal storage according to an embodiment of the present invention.Such as Fig. 1 institute
Show, operating system may include two kinds of access modules: user mode and kernel mode in the embodiment of the present invention, and kernel mode can be with
The kernel spacing of access operation system, the user's space of the accessible operating system of user mode.Kernel spacing Kernel
Space is the running space of operating system nucleus, and kernel spacing can run core functions module, and storage kernel code and
Kernel data;User's space User Space is the running space of user program, and user's space can store user's application with user
Code and data.
For security consideration, in the operating system for providing user mode and kernel mode, the program of user's space cannot be with
The data that meaning operation kernel spacing saves, even if the application crash of user's space, kernel spacing are also unaffected.
In the embodiment of the present invention, the operating system OperatingSystem of terminal configuration includes at least master operating system
(HostOperatingSystem).In one embodiment, terminal can configure multiple operating systems, such as master operating system
One or more containers are created with using container Container virtualization technology, installs and is run from operating system in a reservoir.
As an example, each container can be equivalent to a virtual machine.
Therefore, the user's space in the embodiment of the present invention may include user's space in master operating system and operate in appearance
The user's space of slave operating system in device, the application run in slave operating system in a reservoir are known as container and answer
With.
In the host or container of user's space, user program can at least correspond to a process in the process of running, into
Journey can indicate primary operation activity of the application program about data acquisition system of terminal operating, be that system carries out resource allocation and tune
The basic unit of degree.In order to make it easy to understand, process can be considered as to the implementation procedure of user program;And thread is operating system
Basic scheduling unit, a process may include at least one thread, and thread, which is that one in process is relatively independent, can be performed
Unit.If a process is known as a task task, thread then can be the subtask for including in the task.
Those skilled in the art are it will also be appreciated that the method for recovering internal storage of the embodiment of the present invention is applicable to a variety of offers
The operating system of user mode and kernel mode, such as Unix operating system, (SuSE) Linux OS, Android Android operation
System etc..For simplicity, this paper following multiple embodiments can illustrate that the present invention is real by taking (SuSE) Linux OS as an example
Apply the method for recovering internal storage of example.But the description can not be read as the range or operational feasibility of limitation this programme, Linux behaviour
Make in the operating system for providing user mode and kernel mode other than system, the method for recovering internal storage of the embodiment of the present invention is same
Sample is applicable in.
As shown in Figure 1, kernel spacing may include group recycling thread and a Memory recycle thread, Memory recycle thread can be
The method for recovering internal storage of the embodiment of the present invention is executed under the calling of group recycling thread.
As an example, in (SuSE) Linux OS, the group recycling thread of kernel spacing for example can be group_
Reclaim_thread, Memory recycle thread for example can be kswapd.
It continues to refer to figure 1, operating system can pass through kernel resources control group (Control Group, Cgroup) technology
The resource used user's space intermediate range sort run controls.Kernel resources control group technology is that operating system nucleus provides
A kind of mechanism of system resource used in limitation, isolation and record the process, system resource for example may include CPU, memory, defeated
Enter output interface etc..
In kernel resources control group, a task can be considered as a process of system.Kernel resources control group into
The function of Cheng Jinhang resource management can be realized by way of controller or subsystem.Kernel resources control group may include more
Different resource management functions may be implemented in a scheduling of resource controller or subsystem, each subsystem.
As an example, in the resource control system of kernel resources control group, CPU control subsystem can be used for
The control of time, i.e. the CPU control subsystem occupancy that can be used for control CPU are used using scheduler program control process CPU
Rate;Memory subsystem can be used for setting process to memory using limitation, and can automatically generate these processes to memory source
The report of service condition;Freeze subsystem, can be used for hanging up or restoring the process in kernel resources control group.
It as an example, include CPU control subsystem or cpu controller cpuctl, memory in kernel resources control group
Subsystem or Memory Controller Hub memory and freeze subsystem freezer.
As an example, the CPU usage of thread can be recycled, by CPU control subsystem control group currently to answer
With the influence reduced in terms of Memory recycle bring system fluency when carrying out Memory recycle.
In embodiments of the present invention, each process can create corresponding memory subsystem, and itself can be added to
Corresponding memory subsystem, to call the corresponding memory subsystem of the process to realize, the corresponding memory of the process is recycled.
In embodiments of the present invention, kernel resources control group can manage being grouped of process, and operating system can be with
Process is classified to obtain process grouping, each process can be added specified process according to the type of own services and be grouped.
In one embodiment, process can include but is not limited to according to the type of own services: foreground application process is delayed
Deposit into journey, local basis service processes, the local service processes of starting on demand, binding service process, unbundlings service processes and container
Application process.
As an example, foreground application process can indicate that foreground is currently running using corresponding process;Cache into
Journey can indicate that resident process such as background application in memory corresponds to corresponding process;Container application process can indicate cloth
Set in the operating system of container using corresponding process.
As an example, the Starting mode of the service in system may include automatic starting and starting on demand.This ground
Plinth service usually indicates the service of load simultaneously automatically when system starting, to run other on the basis of local basis services
Using;The local service of starting on demand can indicate the service started after system starting according to user demand.It in this example, can be with
Local basis is serviced into corresponding process as local service process, will locally start the corresponding process of service on demand and be known as locally
Starting service processes on demand.
As an example, binding service provides a kind of mechanism with binding mode starting service, can by binding service
To start the service from other application component in a manner of binding, request is sent to the service of the other application component, is received
Response, binding service can be in active state when providing service for other application component, will not indefinitely be transported on backstage
Row;The service that unbundlings service starts for unbinding mode.In this example, can using the corresponding process of binding service as
Binding service process will unbind the process of service processes as unbundlings service processes.
Description through the foregoing embodiment it is found that the process grouping in kernel resources control group can include but is not limited to as
Lower process is grouped one or more: foreground application group, caching are using group, binding service group, unbundlings service group, local basis clothes
Business group, local starting service group and container group on demand.
In one embodiment, corresponding process can be added in process and is grouped according to the type of process own services.Make
For an example, foreground application process can be added to foreground application group, caching process is added caching and applies group, and local process adds
Enter local basis service group, container group, binding service method binding service group is added in container application process, and unbundlings service is put into solution
The service of tying up.
In embodiments of the present invention, the process of each classification can be set the value model of rank controlling value in system
It encloses, passes through the grade of rank controlling value identification process.As an example, the rank controlling value of process is higher, indicates the process
Lower grade, the lower grade of process grouping where the process.Lower grade process is more inessential, in operating system memory
The memory source that the process group uses when insufficient more early can be also recovered.
In one embodiment, the rank controlling value of process can be importance value, and importance value is higher, and indicating should
The significance level of process is lower, then the lower grade of process group where process;Importance value is lower, indicates the important of the process
Degree is higher, then the higher grade of the process group where process.As an example, the importance value of process can the process
Oom_adj value.
Therefore, in embodiments of the present invention, process can also be grouped according to the rank controlling value of process.Rank is controlled
It is worth process identical or that rank controlling value is in same value range and identical process grouping is added.
As an example, the rank controlling value of foreground process for example can be set to 1;The rank controlling value of caching process
Such as can be set to numerical value between 9-16, the rank controlling value example of the local basis service processes in local basis service group
It such as can be set to negative value such as -17.
In one embodiment, the rank controlling value of process can be equal in the same process group, i.e., in the process group into
The rank controlling value of journey is exactly the value range of the rank controlling value of process in the rank controlling value or process group of the process group
It is exactly the value range of the rank controlling value of the process group.
In one embodiment, Process identifier (ProcessIdentifier, PID) can be used for unique identification one
Process.Process is grouped in be created after may include corresponding process group file, corresponding process group is written into Process identifier
The corresponding process grouping can be added in the process of the Process identifier unique identification by file.
In one embodiment, the rank controlling value of process can be according to the practical application field of target application in operating system
Scape is adjusted, and the grouping where the process is accordingly made adjustment.As an example, in os starting Memory recycle
When, in order to not influence the normal operation of current application, service relevant to current application can temporarily be added to foreground process group,
It is not involved in current memory removal process;When current application is switched to backstage, service relevant to the current application then returns to original
The process group at place.
It in embodiments of the present invention, is to guarantee that operating system operates normally, during Memory recycle, foreground application group can be with
It is not involved in Memory recycle, i.e. foreground process in foreground application group, is had in the binding service group of binding relationship with foreground process
Process is not involved in current memory removal process;If current reference is not container application, the process in container application group can be with
It is preferential to participate in recycling.
Fig. 2 shows the flow charts of method for recovering internal storage according to an embodiment of the present invention.As shown in Fig. 2, implementing at one
In example, method for recovering internal storage 10 may include:
Step S101, using switching, i.e. the current application of user's space switches, which enters weight
It is new to return to state.
In this step, after current application enters the state of returning to, which can be added to foreground application group.
Step S102 obtains memory size needed for application is run according to applicating history operation information.
In this step, memory size needed for which runs can be preset in configuration file.
Front end applications group is added, to guarantee that this is applied in Memory recycle process in the association service of the application by step S103
In normal operation.
In this step, the association service of the application is referred to as being to have the service for relying on short breath with the application.
Step S104 notifies the group of kernel spacing to recycle thread and recycled.
The Memory recycle request of current application is transferred to kernel spacing by S101-S104 through the above steps, user's space
Group recycle thread, the Memory recycle request in include current application needed for memory size.
With continued reference to Fig. 2, in kernel spacing, method for recovering internal storage 10 may include:
Step S201, group recycling thread are waken up.
Memory size to be recycled is arranged equal to memory size needed for current application in step S202.
It is big to check whether the free memory size free_mem for working as system is greater than memory needed for current application by step S203
It is small, if free memory size selects in the maximum process grouping of rank controlling value less than memory size needed for current application
Memory is maximum and not yet recycles the process of memory headroom.
In this step, rank controlling value is bigger, and the process important level in corresponding process grouping is lower, process recycling
When the process grouping in process be recovered at first.
Specifically, the maximum process grouping of current level controlling value can be obtained, such as according to rank controlling value from big to small
Process that is maximum there are memory and not discharging memory headroom, then return the corresponding memory of the process in the grouping of the fruit process
It receives.
Step S204, if there are the maximum process for not discharging memory headroom of memory, recycling in current process grouping
File Mapping memory in the process.
In this step, the corresponding File Mapping memory of the file that can be accessed process recycles.The text of process
Part mapping refers to that the position of file on disk is closed with corresponding between the identical region of memory of size in process logic address space
System.During memory maps, this document is not loaded into memory headroom actually, but process pair is mapped to from Documents Logical
In the memory answered.
In embodiments of the present invention, the purpose of shared drive can be realized between process by mapping same file,
Improve file access efficiency.
Step S205 after recycling the File Mapping memory in the process, is checked when whether the free memory size of system is big
The memory size needed for current application, if free memory recycles hideing in the process less than memory size needed for current application
Name mapping memory.
In this step, anonymous mapping belongs to one of File Mapping mode.As an example, there is kinship
Process such as parent process and subprocess between when realizing shared drive, can be using anonymous map by the way of.Anonymity mapping can
Not to be related to specific filename, so as to avoid the frequent creation of file and opening, improve between parent process and subprocess
The communication efficiency of file-sharing.
It, can should after carrying out File Mapping Memory recycle and anonymous Memory recycle to current process in step S205
Current process packet marking is scanning mode.
Repeat the above steps S203 to S205, from big to small according to rank controlling value, successively most to memory in process grouping
The big process for not discharging memory headroom carries out Memory recycle.
As shown in step S206, if free memory is less than required memory, and there is no do not swept in the grouping of all processes
The process retouched then directly selects rank and controls the maximum process of memory in maximum process grouping.
Step S207 judges the rank controlling value of the maximum process of the memory and the rank controlling value of caching application group, such as
The rank controlling value of the maximum process of the fruit memory is greater than the rank controlling value of caching application group, then can disconnect memory maximum
Process all memory headrooms, recycle all memory headrooms of the maximum process of the memory.
Step S208 after all memory headrooms for recycling the maximum process of the memory, terminates the maximum process of the memory.
In this step, journey signal terminating Memory recycle thread can be entered by sending.As an example, journey is entered
Signal can be kill-9 signal.
Step S209, group recycling thread enter suspend mode Sleep state.
In one embodiment, if in above-mentioned steps S203, free memory is obtained greater than current application institute if checked
When free memory being needed in memory size or step S206 to be greater than required memory, illustrate that free memory has met current application
Memory requirements, then can by group recycling a thread be set as dormant state.
In another embodiment, if in step S207, free memory is unsatisfactory for the memory requirements of current application, owns
Process grouping to execute the operation of recycling memory, and in the maximum process grouping of adj value the maximum process of memory rank
When controlling value is less than or equal to the rank controlling value of caching application group, step S209 can be executed, stops recycling memory to guarantee to work as
Preceding to cache the operation applied, the group recycling thread waiting in kernel is triggered next time.
It in embodiments of the present invention, can be in conjunction with the concrete application field of user's application for the ease of the management of Installed System Memory
Scape and rank controlling value are grouped application layer process process, each process can add according to the type of own services as foundation
Enter into the grouping of a certain process, and a process can correspond to a Memory recycle subsystem, and the process is added to pair
The Memory recycle subsystem answered facilitates group recycling thread dispatching Memory recycle subsystem to recycle the corresponding memory of the process.
Method for recovering internal storage according to an embodiment of the present invention, kernel resources control group can recycle thread by limitation group
CPU usage reduces the influence in terms of Memory recycle process is current application bring fluency.
Fig. 3 shows the flow diagram of method for recovering internal storage according to another embodiment of the present invention.As shown in figure 3,
In the embodiment, method for recovering internal storage 300 may include:
Step S310, receives the Memory Allocation request of application, includes the required memory size of application in Memory Allocation request.
In this step, the required memory size of user's space application can be obtained from preset configuration file.
Step S320 compares the size of amount of free memory and required memory size.
Step S330, when amount of free memory is less than required memory size, based on the process in kernel resources control group
Grade, recycle kernel resources control group in the corresponding memory of process.
In this step, the process in kernel resources control group is configured as adding according to the type of the corresponding service of process
Enter the corresponding process grouping of rank controlling value.As an example, kernel resources control group may include multiple process groupings, more
A process grouping includes one or more in following item: foreground application group, caching apply group, local service group, container service
Group, binding service group and unbundlings service group.
In one embodiment, the process in each process grouping includes corresponding rank controlling value, and rank controlling value is used
In the grade for identifying corresponding process, rank controlling value is bigger, and the lower grade of the corresponding process of rank controlling value;Kernel resources control
Process in processed group is additionally configured to the rank controlling value according to process, and the corresponding process grouping of rank controlling value is added
In one embodiment, the process grouping where the related service of available user's application, by related service pair
The process answered is promoted to foreground application group, and the corresponding process of service in foreground application group is arranged to without Memory recycle.
In this step, in specific application scenarios, due to the corresponding memory money of the related service of active user's application
Source will not be usually recovered, therefore initial processes belonging to the corresponding process of related service of available current application are grouped,
Before carrying out Memory recycle, foreground application group, active user are set by the affiliated process grouping of the corresponding process of related service
Application switching be background application after, can by process belonging to the corresponding process of related service be grouped be re-set as this initially into
Journey grouping.
In one embodiment, the corresponding memory of process in foreground application group is configured as without Memory recycle;When
When using corresponding process not being container using corresponding process, the corresponding memory of process in container group be configured as preferentially into
Row Memory recycle.
As an example, when user's space application is not container in application, can be by the process in container service group
Rank controlling value is set as highest, indicates that the progress levels in container service group are minimum.The important level of container service group is set
When being set to minimum, preferentially the proceeding internal memory in the container service group can be recycled.
In one embodiment, the grade based on the process in kernel resources control group in step S330, collection process pair
It the step of memory answered, can specifically include:
According to the grade sequence from low to high of the process in kernel resources control group, Memory recycle is executed to process, directly
Memory size to recycling has been more than or equal to the corresponding memory of process in required memory size or kernel resources control group
It is recovered.
In one embodiment, the step of executing Memory recycle to process in step S330 can specifically include:
Step S330-01, selection target process, target process corresponding memory in the process in kernel resources control group
Capacity is maximum and corresponding memory is not recovered, and corresponding memory includes File Mapping memory and anonymous mapping memory.
Step S330-02, the corresponding File Mapping memory of recycling target process.
Step S330-03, if the amount of free memory obtained after File Mapping Memory recycle is less than required memory size,
Recycle the corresponding anonymous mapping memory of target process.
In embodiments of the present invention, the purpose of Memory recycle is not configured to destruction process, but in order to not influence currently
In the case where using normal operation, recycling memory size as much as possible, therefore, the method for recovering internal storage of the embodiment of the present invention,
When amount of free memory is less than required memory size, the grade of the process in the kernel resources control group based on pre-configuration is from low
To height, the corresponding memory of process in kernel resources control group is recycled, improves the service efficiency that user applies run-time memory, is guaranteed
The system normally operation with smoothness.
Fig. 4 shows the structural schematic diagram of Memory recycle device according to an embodiment of the present invention.As shown in figure 4, at one
In embodiment, Memory recycle device 400 may include:
Memory request receiving module 410 is requested for the Memory Allocation for receiving application, includes in Memory Allocation request
The required memory size of application;
Memory comparison module 420, the size for amount of free memory and required memory size in comparison system;
Group recycling module 430, for being based on kernel resources control group when amount of free memory is less than required memory size
In process grade, the corresponding memory of collection process.
In embodiments of the present invention, kernel resources control group includes multiple process groupings, and multiple process groupings include as follows
One or more in: foreground application group, caching apply group, local basis service group, container group, binding service group and unbundlings
Service group;Process in kernel resources control group is configured as the type according to the corresponding service of process, and multiple processes point are added
At least one of group.
In one embodiment, the process in each process grouping includes corresponding rank controlling value, and rank controlling value is used
In the grade for identifying corresponding process, rank controlling value is bigger, and the lower grade of the corresponding process of rank controlling value;Kernel resources control
Process in processed group is additionally configured to the rank controlling value according to process, and the corresponding process grouping of rank controlling value is added.
Specifically, the process in each process grouping includes corresponding rank controlling value, and rank controlling value is for mark pair
The important level for the process answered, rank controlling value is bigger, and the important level of the corresponding process of rank controlling value is lower.
In one embodiment, the corresponding memory of process in foreground application group is configured as without Memory recycle;When
When using corresponding process not being container using corresponding process, the corresponding memory of process in container group be configured as preferentially into
Row Memory recycle.
In one embodiment, group recycling module 430 specifically can be used for:
The related service for obtaining application sets the process other than the corresponding process of related service to participate in Memory recycle
Process;Based on the grade of the process in kernel resources control group, the corresponding memory of process for participating in Memory recycle is recycled.
In one embodiment, group recycling module 430 specifically can be used for:
According to the grade sequence from low to high of the process in kernel resources control group, Memory recycle is executed to process, directly
Memory size to recycling has been more than or equal to the corresponding memory of process in required memory size or kernel resources control group
It is recovered.
In one embodiment, group recycling module 430 can specifically include:
Target process selecting unit is used for selection target process, and target process is in the process in kernel resources control group
Corresponding memory size is maximum and corresponding memory is not recovered, and corresponding memory includes in File Mapping memory and anonymous mapping
It deposits;
File Mapping Memory recycle unit, for recycling the corresponding File Mapping memory of target process;
Anonymity mapping Memory recycle unit, if the amount of free memory for obtaining after File Mapping Memory recycle is less than
Required memory size, the corresponding anonymous mapping memory of recycling target process.
In another embodiment, group recycling module 430 may include:
Process is grouped determining module, for being recovered when the corresponding memory of process in kernel resources control group, and
When amount of free memory in system is less than required memory size, the minimum process place of kernel resources control group middle grade is determined
Process grouping;
Target process selecting module is used for selection target process, and target process is in the process where elementary process
Corresponding memory size is maximum in grouping;
When group recycling module is specifically also used to apply the grade of the process in group lower than caching when the grade of target process, return
Receive the corresponding full memory of target process.
Memory recycle device through the embodiment of the present invention is based on when amount of free memory is less than required memory size
The important level of the kernel resources control group of pre-configuration from low to high, recycles the corresponding memory of process in kernel resources control group,
The service efficiency that user applies run-time memory is improved, guarantees the normal and smooth operation of system.
The basis that the other details of Memory recycle device according to an embodiment of the present invention combine Fig. 1 to Fig. 3 to describe with more than
The method for recovering internal storage of the embodiment of the present invention is similar, and details are not described herein.
Fig. 5 is to show the calculating equipment that method for recovering internal storage and device according to an exemplary embodiment of the present invention may be implemented
Exemplary hardware architecture structure chart.
As shown in figure 5, Memory recycle system 500 includes input equipment 501, input interface 502, central processing unit 503, deposits
Reservoir 504, output interface 505 and output equipment 506.Wherein, input interface 502, central processing unit 503, memory 504,
And output interface 505 is connected with each other by bus 510, input equipment 501 and output equipment 506 pass through input interface respectively
502 and output interface 505 connect with bus 510, and then connect with the other assemblies of Memory recycle system 500.
That is, calculating equipment shown in fig. 5 also may be implemented as a kind of Memory recycle system, the Memory recycle system
System may include: the memory for being stored with computer executable instructions;And processor, the processor is for reading in memory
The executable program code of storage is to execute the method for recovering internal storage and device that above-mentioned combination Fig. 1 to Fig. 4 describes.
In the above-described embodiments, can come wholly or partly by software, hardware, firmware or any combination thereof real
It is existing.It when implemented in software, can be entirely or partly with the shape of computer program product or computer readable storage medium
Formula is realized.The computer program product or computer readable storage medium include one or more computer instructions.It is calculating
When being loaded on machine and executing the computer program instructions, entirely or partly generate according to process described in the embodiment of the present invention
Or function.The computer can be general purpose computer, special purpose computer, computer network or other programmable devices.Institute
Stating computer instruction may be stored in a computer readable storage medium, or from a computer readable storage medium to another
A computer readable storage medium transmission, for example, the computer instruction can be from web-site, computer, a server
Or data center is (such as infrared, wireless, micro- by wired (such as coaxial cable, optical fiber, Digital Subscriber Line (DSL)) or wireless
Wave etc.) mode transmitted to another web-site, computer, server or data center.The computer-readable storage
Medium can be any usable medium that computer can access or include the integrated service of one or more usable mediums
The data storage devices such as device, data center.The usable medium can be magnetic medium, (for example, floppy disk, hard disk, tape), light
Medium (for example, DVD) or semiconductor medium (such as solid state hard disk Solid State Disk (SSD)) etc..
It should be clear that the invention is not limited to specific configuration described above and shown in figure and processing.
For brevity, it is omitted here the detailed description to known method.In the above-described embodiments, several tools have been described and illustrated
The step of body, is as example.But method process of the invention is not limited to described and illustrated specific steps, this field
Technical staff can be variously modified, modification and addition after understanding spirit of the invention, or suitable between changing the step
Sequence.
The above description is merely a specific embodiment, it is apparent to those skilled in the art that,
For convenience of description and succinctly, the system, module of foregoing description and the specific work process of unit can refer to preceding method
Corresponding process in embodiment, details are not described herein.It should be understood that scope of protection of the present invention is not limited thereto, it is any to be familiar with
Those skilled in the art in the technical scope disclosed by the present invention, can readily occur in various equivalent modifications or substitutions,
These modifications or substitutions should be covered by the protection scope of the present invention.