CN114510342A - Cache processing method and device and storage medium - Google Patents

Cache processing method and device and storage medium Download PDF

Info

Publication number
CN114510342A
CN114510342A CN202011290406.XA CN202011290406A CN114510342A CN 114510342 A CN114510342 A CN 114510342A CN 202011290406 A CN202011290406 A CN 202011290406A CN 114510342 A CN114510342 A CN 114510342A
Authority
CN
China
Prior art keywords
memory
application program
thread local
local cache
electronic equipment
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.)
Pending
Application number
CN202011290406.XA
Other languages
Chinese (zh)
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 Xiaomi Mobile Software Co Ltd
Original Assignee
Beijing Xiaomi Mobile Software 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 Xiaomi Mobile Software Co Ltd filed Critical Beijing Xiaomi Mobile Software Co Ltd
Priority to CN202011290406.XA priority Critical patent/CN114510342A/en
Publication of CN114510342A publication Critical patent/CN114510342A/en
Pending legal-status Critical Current

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/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0893Caches characterised by their organisation or structure

Abstract

The disclosure relates to a cache processing method, a cache processing device and a storage medium. The method is applied to the electronic equipment and comprises the following steps: acquiring the current memory state of the electronic equipment; and determining whether to start a thread local cache function of the application program process according to the cache strategy corresponding to the current memory state. Therefore, whether the thread local cache function of the application program process is started or not can be determined by acquiring the current memory state of the electronic equipment and according to the cache strategy corresponding to the current memory state. Compared with the prior art that the cache policy is determined during the compiling period, and the thread local cache function of the application program process is opened or closed according to the fixed cache policy, in the embodiment of the disclosure, the cache policy can be flexibly adjusted according to the memory state of the electronic device, that is, the thread local cache function of the application program process is opened or closed according to the memory state of the electronic device, and the dynamic adjustment of the cache policy can be realized.

Description

Cache processing method and device and storage medium
Technical Field
The present disclosure relates to the field of memory management, and in particular, to a cache processing method and apparatus, and a storage medium.
Background
In order to meet the use requirements of the majority of users, a plurality of different memory configurations can be set for different electronic devices. Taking the example that the electronic device is a mobile phone, the same mobile phone may set a 2G memory configuration, that is, the total memory capacity is 2GB 2048MB (megabyte); a 3G memory configuration may also be set, that is, the total memory capacity is 3GB 3072MB (megabyte), and in the implementation process, the memory allocation may be performed based on a memory allocator.
In the related art, the memory allocator can implement multi-thread concurrent allocation, and in order to improve performance of the multi-thread concurrent allocation, a thread local cache function is provided to reduce performance loss caused by synchronization among multiple threads, but the thread local cache function increases consumption of the memory. Because whether the thread local cache function is started or not is determined in the compiling process in the related technology, differential configuration cannot be carried out on different electronic equipment, and if the cache strategy is determined in the compiling process, the cache strategy cannot be dynamically adjusted in the using process of the electronic equipment.
Disclosure of Invention
The disclosure provides a cache processing method, a cache processing device and a storage medium.
According to a first aspect of the embodiments of the present disclosure, there is provided a cache processing method applied to an electronic device, including:
acquiring the current memory state of the electronic equipment;
and determining whether to start a thread local cache function of the application program process according to the cache strategy corresponding to the current memory state.
Optionally, the obtaining the current memory state of the electronic device includes:
when a starting instruction for starting the electronic equipment is detected, acquiring a total memory of the electronic equipment;
the determining whether to start a thread local cache function of the application program process according to the cache policy corresponding to the current memory state includes:
and starting the thread local cache function of all the application program processes in the electronic equipment under the condition that the total memory is greater than or equal to a first set memory.
Optionally, the determining whether to start a thread local cache function of an application program process according to the cache policy corresponding to the current memory state includes:
and closing the thread local cache function of all application program processes in the electronic equipment under the condition that the total memory is smaller than the first set memory.
Optionally, the method further includes:
when the electronic equipment runs, acquiring a current available memory of the electronic equipment;
the determining whether to start a thread local cache function of the application program process according to the cache policy corresponding to the current memory state includes:
and under the condition that the current available memory is less than or equal to a second set memory, maintaining the thread local cache function of the application program process in the starting state in an opening state, and closing the thread local cache function of the application program process to be started.
Optionally, the determining whether to start a thread local cache function of an application program process according to the cache policy corresponding to the current memory state includes:
and maintaining the thread local cache functions of all application program processes in the electronic equipment in an open state under the condition that the current available memory is larger than the second set memory.
According to a second aspect of the embodiments of the present disclosure, there is provided a cache processing apparatus applied to an electronic device, including:
the first acquisition module is configured to acquire the current memory state of the electronic equipment;
and the determining module is configured to determine whether to start a thread local cache function of the application program process according to the cache policy corresponding to the current memory state.
Optionally, the first obtaining module is further configured to:
when a starting instruction for starting the electronic equipment is detected, acquiring a total memory of the electronic equipment;
the determination module is further configured to:
and starting the thread local cache function of all the application program processes in the electronic equipment under the condition that the total memory is greater than or equal to a first set memory.
Optionally, the determining module is further configured to:
and closing the thread local cache function of all application program processes in the electronic equipment under the condition that the total memory is smaller than the first set memory.
Optionally, the apparatus further comprises:
the second obtaining module is configured to obtain a current available memory of the electronic device when the electronic device runs;
the determination module is further configured to:
and under the condition that the current available memory is less than or equal to a second set memory, maintaining the thread local cache function of the application program process in the starting state in an opening state, and closing the thread local cache function of the application program process to be started.
Optionally, the determining module is further configured to:
and maintaining the thread local cache functions of all application program processes in the electronic equipment in an open state under the condition that the current available memory is larger than the second set memory.
According to a third aspect of the embodiments of the present disclosure, there is provided a cache processing apparatus, including:
a processor;
a memory configured to store processor-executable instructions;
wherein the processor is configured to: when executed, implement the steps in any of the above-described cache processing methods of the first aspect.
According to a fourth aspect of embodiments of the present disclosure, there is provided a non-transitory computer-readable storage medium, wherein instructions of the storage medium, when executed by a processor of a cache processing apparatus, enable the apparatus to perform the steps of any one of the above cache processing methods according to the first aspect.
The technical scheme provided by the embodiment of the disclosure can have the following beneficial effects:
in the embodiment of the disclosure, whether to start the thread local cache function of the application program process may be determined by obtaining the current memory state of the electronic device and according to the cache policy corresponding to the current memory state. Compared with the prior art, the cache policy is determined during compiling, and the thread local cache function of the application program process is turned on or off according to the fixed cache policy. In the embodiment of the present disclosure, the cache policy can be flexibly adjusted according to the memory state of the electronic device, that is, the thread local cache function of the application process is turned on or turned off according to the memory state of the electronic device, and dynamic adjustment of the cache policy can be achieved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
Fig. 1 is a first flowchart illustrating a caching process according to an example embodiment.
Fig. 2 is a flow diagram illustrating a caching process in accordance with an illustrative embodiment.
FIG. 3 is a third flowchart illustrating a caching process, according to an example embodiment.
Fig. 4 is a block diagram illustrating a cache processing apparatus according to an example embodiment.
Fig. 5 is a block diagram illustrating a cache processing apparatus according to an example embodiment.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the invention, as detailed in the appended claims.
The embodiment of the disclosure provides a cache processing method, which can be applied to electronic equipment. Fig. 1 is a first flowchart illustrating a caching process according to an exemplary embodiment, and as shown in fig. 1, the method mainly includes the following steps:
in step 101, obtaining a current memory state of the electronic device;
in step 102, it is determined whether to start a thread local cache function of the application program process according to the cache policy corresponding to the current memory state.
The cache processing method in the embodiments of the present disclosure may be applied to an electronic device, where the electronic device includes a terminal device, such as a mobile terminal and a fixed terminal, where the mobile terminal includes: mobile phones, tablet computers, notebook computers, and the like; the fixed terminal includes: a personal computer. In other optional embodiments, the cache processing method may also be applied to an embedded electronic device configured with an Android operating system.
Here, the current memory state may include: the memory state of the electronic equipment in the starting process and the memory state of the electronic equipment after the electronic equipment is successfully started. After the current memory state of the electronic equipment is obtained, a cache strategy corresponding to the current memory state can be determined, and whether a thread local cache function of an application program process is started or not is determined according to the cache strategy.
In some embodiments, the electronic device has a set type of operating system, and a corresponding memory allocator may be configured for the operating system, and the memory allocator is configured with a thread local cache function. For example, if the operating system of the set type is an Android operating system, the memory allocator may be a Jemalloc, and correspondingly, the memory allocator is configured with a thread local cache function. In the implementation process, if the thread local cache function is started, a corresponding thread local cache region can be configured for each thread, and the object of each thread is stored based on the local cache region.
Taking the electronic device as an example, which is an electronic device with an Android operating system, the Android operating system may use the Jemalloc as a memory allocator because the Jemalloc has excellent multithreading concurrent allocation performance. The memory consumption of the electronic device is increased due to the fact that the thread local cache function is continuously started, in the implementation process, the current memory state of the electronic device can be obtained, and whether the thread local cache function of the application program process is started or not is determined according to the cache strategy corresponding to the current memory state.
For example, the total memory of the electronic device may be obtained, and when the total memory of the electronic device is greater than or equal to the first set memory, the thread local cache function of all application processes in the electronic device is started. For another example, the thread local cache function of all application program processes in the electronic device may be turned off when the total memory of the electronic device is smaller than the first set memory.
In the embodiment of the disclosure, whether to start the thread local cache function of the application program process may be determined by obtaining the current memory state of the electronic device and according to the cache policy corresponding to the current memory state. Compared with the prior art that the cache policy is determined during the compiling period, and the thread local cache function of the application program process is opened or closed according to the fixed cache policy, in the embodiment of the disclosure, the cache policy can be flexibly adjusted according to the memory state of the electronic device, that is, the thread local cache function of the application program process is opened or closed according to the memory state of the electronic device, and the dynamic adjustment of the cache policy can be realized.
In some embodiments, the obtaining the current memory state of the electronic device includes:
when a starting instruction for starting the electronic equipment is detected, acquiring a total memory of the electronic equipment;
the determining whether to start a thread local cache function of the application program process according to the cache policy corresponding to the current memory state includes:
and starting the thread local cache function of all the application program processes in the electronic equipment under the condition that the total memory is greater than or equal to a first set memory.
Here, the opening instruction may be an instruction triggered by a user based on a control on the electronic device, where the control may be a virtual control or a physical button. In the embodiment of the present disclosure, when the electronic device detects the opening instruction, the electronic device may be started, and when the electronic device is started, the total memory of the electronic device is obtained.
For example, the total memory of the electronic device may be read by a first process started in the process of booting the electronic device. For another example, the total memory of the electronic device may be read based on the init () function during the booting process of the electronic device.
After the total memory of the electronic device is obtained, the total memory of the electronic device may be compared with a first set memory to obtain a first comparison result, and whether to start a thread local cache function of an application program process in the electronic device is determined according to the first comparison result.
For example, when the first comparison result indicates that the total memory of the electronic device is greater than or equal to the first set memory, the thread local cache function of all application program processes in the electronic device is started. Since the memory of the electronic device is consumed by starting the local cache function, in the embodiment of the present disclosure, the thread local cache function of all application processes is started under the condition that the total memory of the electronic device is sufficient, and the running speed of the application can be ensured on the basis of ensuring that the available memory of the electronic device is sufficient.
In other embodiments, the thread local cache function of a part of the application program processes in the electronic device may be started when the total memory of the electronic device is greater than or equal to the first set memory. For example, when the total memory of the electronic device is greater than or equal to the first set memory, the thread local cache function of N application program processes in the electronic device may be turned on, where N may be set as needed, for example, 3 or 5, and the like, and is not limited herein.
In the embodiment of the disclosure, the total memory of the electronic device can be acquired and evaluated in the starting process of the electronic device, and the thread local cache function of all or part of the application program processes in the electronic device is started again under the condition that it is determined that the total memory is enough to ensure that the electronic device can normally run after the thread local cache function is started, so that the memory occupation and allocation of the electronic device can be balanced.
In some embodiments, the determining whether to start a thread local caching function of an application program process according to a caching policy corresponding to the current memory state includes:
and closing the thread local cache function of all application program processes in the electronic equipment under the condition that the total memory is smaller than the first set memory.
In other embodiments, the thread local cache function of a part of the application program processes in the electronic device may be turned off when the total memory of the electronic device is smaller than the first set memory. For example, in a case that the total memory of the electronic device is smaller than the first set memory, the thread local cache function of K application processes in the electronic device may be turned off, where K may be set as needed, for example, K may be 2 or 6, and the like, and is not limited in this respect.
In the embodiment of the disclosure, in the starting process of the electronic device, the total memory of the electronic device can be acquired and evaluated, and under the condition that it is determined that the total memory is not enough to ensure that the electronic device can normally operate after the thread local cache function is started, the thread local cache function of all or part of the application program processes in the electronic device is closed, so that the balance of memory occupation and allocation of the electronic device can be realized.
In some embodiments, the method further comprises:
when the electronic equipment runs, acquiring a current available memory of the electronic equipment;
the determining whether to start a thread local cache function of the application program process according to the cache policy corresponding to the current memory state includes:
and under the condition that the current available memory is less than or equal to a second set memory, maintaining the thread local cache function of the application program process in the starting state in an opening state, and closing the thread local cache function of the application program process to be started.
Here, in the process of operating the electronic device, a currently available memory of the electronic device may be obtained, where the currently available memory may refer to a memory that is not currently occupied in the electronic device. In the embodiment of the disclosure, in the using process of the electronic device, the current available memory of the electronic device may be obtained, the current available memory is compared with the second set memory to obtain a second comparison result, and whether the thread local caching function performed by the application program is started is determined according to the second comparison result.
For example, when the second comparison result indicates that the current available memory is less than or equal to the second set memory, the thread local cache function of the application program process in the starting state may be maintained in the open state, and the thread local cache function of the application program process to be started may be closed.
In the embodiment of the disclosure, in the running process of the electronic device, the current available memory of the electronic device may be obtained, and the current available memory is evaluated, and under the condition that it is determined that the current available memory is not enough to ensure that the electronic device can run normally on the basis of starting the thread local cache function, the thread local cache function of the application program process in the starting state may be maintained in the starting state, and the thread local cache function of the application program process to be started is closed, so that the balance of memory occupation and allocation of the electronic device can be realized.
In some embodiments, the determining whether to start a thread local caching function of an application program process according to a caching policy corresponding to the current memory state includes:
and maintaining the thread local cache functions of all application program processes in the electronic equipment in an open state under the condition that the current available memory is larger than the second set memory.
In the embodiment of the disclosure, in the process of operating the electronic device, the current available memory of the electronic device may be obtained and evaluated, and under the condition that it is determined that the current available memory is sufficient to ensure that the electronic device can normally operate on the basis of starting the thread local cache function, the thread local cache functions of all application program processes in the electronic device may be maintained in the starting state, so that the memory occupation and allocation of the electronic device may be balanced.
In some embodiments, for example, the electronic device is an electronic device with an Android operating system, since the Jemalloc has excellent multithreading concurrent allocation performance, the Android operating system may use the Jemalloc as a memory allocator.
The Jemalloc uses a thread local cache function to improve the multithreading concurrent allocation performance so as to avoid performance loss caused by synchronization among multiple threads, but the memory consumption is increased by starting the thread local cache function. In the related art, the thread local cache function is turned on by default, for example, the Jemalloc selects to turn on or turn off the thread local cache function during compilation by default, for example, the thread local cache function can be selected to be turned off on an electronic device with a low memory configuration to save memory consumption. In the related technology, the Jemalloc defines a macro variable for determining whether to start the local cache function of the thread in a compiling script, the Jemalloc determines whether to start the local cache function of the thread in an initialization code according to whether the macro variable is set, and in the implementation process, the compiling script needs to be modified to achieve the purpose of starting or closing the local cache function of the thread.
Generally, a plurality of memory configurations exist in an electronic device product, for example, the same mobile phone may have a 2G, 3G or 4G memory, and in the implementation process, the mobile phone having the 2G and 3G memory configurations needs to turn off the thread local cache function to save the memory, while the mobile phone having the 4G memory configuration may turn on the thread local cache function to obtain better performance. The Jemalloc default is that the thread local cache function is selected to be started or closed during compiling, and differential configuration cannot be carried out on the same electronic equipment with different memories.
In the Android operating system, the Jemalloc cannot dynamically adjust the cache policy according to the memory pressure of the electronic device during the use process, for example, when the memory pressure is high, the thread local cache function is closed for the newly started process, and when the memory pressure is low, the thread local cache function is opened for the newly started process.
In some embodiments, the technical solution in the embodiments of the present disclosure is composed of three parts, Jemalloc, libc, and Framework. In the implementation process, the configuration function of the global variable of the memory allocator for controlling the thread local cache function can be modified from read-only at run-time to readable and writable at run-time. For example, the configuration function of the global variable OPT _ TCACHE in the config module of the Jemalloc, which controls the thread local caching function, can be modified from read-only at runtime to readable and writable at runtime, and a parameter option OPT _ TCACHE is newly added in the mallop function of libc, so as to modify the global variable OPT _ TCACHE of the Jemalloc in the case of a single thread, so as to close or open the thread local caching function.
Fig. 2 is a schematic flow chart of a caching process according to an exemplary embodiment, where as shown in fig. 2, the method mainly includes the following steps:
in step 201, the total memory of the electronic device is read.
Here, the total memory of the electronic device may be read by a first process started in the process of booting the electronic device. For another example, the total memory of the electronic device may be read based on the init () function during the booting process of the electronic device.
In step 202, it is determined whether the total memory of the electronic device is less than a first set memory.
Here, the thread local cache function may be turned on or off according to the total memory of the electronic device. For example, after the total memory of the electronic device is obtained, the total memory of the electronic device may be compared with a first set memory to obtain a first comparison result, and whether to start a thread local cache function of an application program process in the electronic device is determined according to the first comparison result. For example, when the total memory is smaller than the first set memory, the thread local cache function of all application program processes in the electronic device is turned off.
In step 203, if the total memory is less than the first set memory, the attribute ro.
Here, if the thread local cache function needs to be turned off, the attribute ro.
In step 204, the init process fork (spawn) child process.
In step 205, it is determined whether the ro.
In step 206, if the ro.
Here, in the subsequent boot process, if the child process of the init process fork reads that the ro.
In step 207, if the ro, boot, disable, tcache attribute read by the sub-process is not true, the libc will be reinitialized when the sub-process executes a new executable file using exec system call.
In step 208, it is determined whether the environment variable JEMALLOC _ DISABLE _ TCACHE is 1.
Here, it is possible to read the environment variable JEMALLOC _ DISABLE _ TCACHE during libc initialization and determine whether the environment variable JEMALLOC _ DISABLE _ TCACHE is 1.
In step 209, if the JEMALLOC _ DISABLE _ TCACHE environment variable exists and has a value of 1, the global variable opt _ TCACHE that determines whether the thread local cache is open is directly set to false to turn off the thread local cache function.
In some embodiments, since an Android Application (App) comes out through a zygate process fork and zygate comes out through an init process fork, the thread local cache of all subsequent Application processes is closed as long as the thread local cache function of the zygate process is closed during the starting process of the electronic device (e.g., a mobile phone).
Fig. 3 is a schematic flow chart of a caching process according to an exemplary embodiment, where as shown in fig. 3, the method mainly includes the following steps:
in step 301, a zygate process is requested to start a new application process.
In step 302, a fork sub-process is based on the zygate process.
In step 303, it is determined whether the currently available memory of the electronic device is less than or equal to a second set memory.
In step 304, when the current available memory of the electronic device is less than or equal to the second set memory, a newly added mallopt option OPT _ TCACHE is used to set a global variable OPT _ TCACHE that determines whether the thread local cache is opened to false, so as to close the thread local cache function.
Here, taking the electronic device as a mobile phone as an example, during the use of the mobile phone, whether to turn on or turn off the thread local cache function of the newly started application program process may be determined according to the overall memory state of the mobile phone. For example, if the current overall memory state is poor, the thread local cache function of the newly started application program process may be closed, so as to save the memory.
In some embodiments, when the application program process from the zygate process fork is in a single-thread state, the global variable OPT _ TCACHE that determines whether the thread local cache is opened may be set to false using the newly added mallopt option OPT _ TCACHE, so as to close the thread local cache function.
In some embodiments, the cache policy may be adjusted according to the overall memory state of the electronic device during the startup process of the electronic device. Or taking the electronic device as a mobile phone as an example, if a certain mobile phone has two configurations of 3G and 4G memories, and the two configurations of the two memories are the same software package, in the implementation process, by modifying the Jemalloc underlying function, the thread local cache function is opened or closed when the mobile phone supports running, and the actual memory size (total memory) of the mobile phone is determined in the starting process of the mobile phone, and whether the thread local cache function is opened or not is determined based on the actual memory size. For example, the thread local cache function is closed for all application program processes in a 3G mobile phone, and the thread local cache function is opened for all application program processes in a 4G mobile phone.
In other embodiments, the cache policy may be adjusted according to the overall memory state of the electronic device during the operation of the electronic device. Taking the electronic device as a mobile phone as an example, in the running process of the mobile phone, the cache policy may be adjusted according to the overall memory state of the mobile phone, for example, the current memory state of the mobile phone may be monitored, the thread local cache function may be closed for a newly started application program process when the memory pressure is high, and the thread local cache function may be opened for the newly started application program process when the memory pressure is low.
According to the technical scheme, on one hand, the problem of how to determine whether to start or close the thread local cache function of all application program processes of the system according to the memory size or other state information when the electronic equipment runs is solved. On the other hand, the problem of how to open the thread local cache function for part of the application program processes according to a specific strategy and close the thread local cache function for the other part of the application program processes is solved. By adopting the technical scheme, the balance of memory occupation and allocation is realized, 60-100M memory can be saved by the electronic equipment configured by the 2G memory, and 100-300M memory can be saved by the electronic equipment configured by the 3G memory.
Fig. 4 is a block diagram illustrating a cache processing apparatus according to an example embodiment. As shown in fig. 4, the cache processing apparatus 400 is applied to an electronic device, and mainly includes:
a first obtaining module 401 configured to obtain a current memory state of the electronic device;
a determining module 402, configured to determine whether to start a thread local cache function of an application program process according to a cache policy corresponding to the current memory state.
In some embodiments, the first obtaining module 401 is further configured to:
when a starting instruction for starting the electronic equipment is detected, acquiring a total memory of the electronic equipment;
the determination module is further configured to:
and starting the thread local cache function of all the application program processes in the electronic equipment under the condition that the total memory is greater than or equal to a first set memory.
In some embodiments, the determining module 402 is further configured to:
and closing the thread local cache function of all application program processes in the electronic equipment under the condition that the total memory is smaller than the first set memory.
In some embodiments, the apparatus 400 further comprises:
the second obtaining module is configured to obtain a current available memory of the electronic device when the electronic device runs;
the determination module is further configured to:
and under the condition that the current available memory is less than or equal to a second set memory, maintaining the thread local cache function of the application program process in the starting state in an opening state, and closing the thread local cache function of the application program process to be started.
In some embodiments, the determining module 402 is further configured to:
and maintaining the thread local cache functions of all application program processes in the electronic equipment in an open state under the condition that the current available memory is larger than the second set memory.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Fig. 5 is a block diagram illustrating a cache processing apparatus 1200 according to an example embodiment. For example, the apparatus 1200 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, an exercise device, a personal digital assistant, and the like.
Referring to fig. 5, the apparatus 1200 may include one or more of the following components: processing component 1202, memory 1204, power component 1206, multimedia component 1208, audio component 1210, input/output (I/O) interface 1212, sensor component 1214, and communications component 1216.
The processing component 1202 generally controls overall operation of the apparatus 1200, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 1202 may include one or more processors 1220 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 1202 can include one or more modules that facilitate interaction between the processing component 1202 and other components. For example, the processing component 1202 can include a multimedia module to facilitate interaction between the multimedia component 1208 and the processing component 1202.
The memory 1204 is configured to store various types of data to support operation at the device 1200. Examples of such data include instructions for any application or method operating on the device 1200, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 1204 may be implemented by any type or combination of volatile or non-volatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
A power supply component 1206 provides power to the various components of the device 1200. Power components 1206 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for apparatus 1200.
The multimedia components 1208 include a screen that provides an output interface between the device 1200 and a user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 1208 includes a front facing camera and/or a rear facing camera. The front camera and/or the rear camera may receive external multimedia data when the device 1200 is in an operating mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
Audio component 1210 is configured to output and/or input audio signals. For example, audio component 1210 includes a Microphone (MIC) configured to receive external audio signals when apparatus 1200 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 1204 or transmitted via the communication component 1216. In some embodiments, audio assembly 1210 further includes a speaker for outputting audio signals.
The I/O interface 1212 provides an interface between the processing component 1202 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor assembly 1214 includes one or more sensors for providing various aspects of state assessment for the apparatus 1200. For example, the sensor assembly 1214 may detect an open/closed state of the device 1200, the relative positioning of the components, such as a display and keypad of the apparatus 1200, the sensor assembly 1214 may also detect a change in the position of the apparatus 1200 or a component of the apparatus 1200, the presence or absence of user contact with the apparatus 1200, an orientation or acceleration/deceleration of the apparatus 1200, and a change in the temperature of the apparatus 1200. The sensor assembly 1214 may include a proximity sensor configured to detect the presence of a nearby object in the absence of any physical contact. The sensor assembly 1214 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1214 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communications component 1216 is configured to facilitate communications between the apparatus 1200 and other devices in a wired or wireless manner. The apparatus 1200 may access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 1216 receives the broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communications component 1216 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the apparatus 1200 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic components for performing the above-described methods.
In an exemplary embodiment, a non-transitory computer readable storage medium comprising instructions, such as memory 1204 comprising instructions, executable by processor 1220 of apparatus 1200 to perform the above-described method is also provided. For example, the non-transitory computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
A non-transitory computer readable storage medium in which instructions, when executed by a processor of a cache processing apparatus, enable the cache processing apparatus to perform a cache processing method, the method comprising:
acquiring the current memory state of the electronic equipment;
and determining whether to start a thread local cache function of the application program process according to the cache strategy corresponding to the current memory state.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (12)

1. The cache processing method is applied to electronic equipment and comprises the following steps:
acquiring the current memory state of the electronic equipment;
and determining whether to start a thread local cache function of the application program process according to the cache strategy corresponding to the current memory state.
2. The method of claim 1, wherein the obtaining the current memory state of the electronic device comprises:
when a starting instruction for starting the electronic equipment is detected, acquiring a total memory of the electronic equipment;
the determining whether to start a thread local cache function of the application program process according to the cache policy corresponding to the current memory state includes:
and starting the thread local cache function of all the application program processes in the electronic equipment under the condition that the total memory is greater than or equal to a first set memory.
3. The method according to claim 2, wherein the determining whether to start a thread local caching function of the application program process according to the caching policy corresponding to the current memory state comprises:
and closing the thread local cache function of all application program processes in the electronic equipment under the condition that the total memory is smaller than the first set memory.
4. The method of claim 1, further comprising:
when the electronic equipment runs, acquiring a current available memory of the electronic equipment;
the determining whether to start a thread local cache function of the application program process according to the cache policy corresponding to the current memory state includes:
and under the condition that the current available memory is less than or equal to a second set memory, maintaining the thread local cache function of the application program process in the starting state in an opening state, and closing the thread local cache function of the application program process to be started.
5. The method according to claim 4, wherein the determining whether to start a thread local caching function of the application program process according to the caching policy corresponding to the current memory state comprises:
and maintaining the thread local cache functions of all application program processes in the electronic equipment in an open state under the condition that the current available memory is larger than the second set memory.
6. The cache processing device is applied to electronic equipment and comprises:
the first acquisition module is configured to acquire the current memory state of the electronic equipment;
and the determining module is configured to determine whether to start a thread local cache function of the application program process according to the cache policy corresponding to the current memory state.
7. The apparatus of claim 6, wherein the first obtaining module is further configured to:
when a starting instruction for starting the electronic equipment is detected, acquiring a total memory of the electronic equipment;
the determination module is further configured to:
and starting the thread local cache function of all the application program processes in the electronic equipment under the condition that the total memory is greater than or equal to a first set memory.
8. The apparatus of claim 7, wherein the determination module is further configured to:
and closing the thread local cache function of all application program processes in the electronic equipment under the condition that the total memory is smaller than the first set memory.
9. The apparatus of claim 6, further comprising:
the second obtaining module is configured to obtain a current available memory of the electronic device when the electronic device runs;
the determination module is further configured to:
and under the condition that the available memory is less than or equal to a second set memory, maintaining the thread local cache function of the application program process in the starting state to be in the starting state, and closing the thread local cache function of the application program process to be started.
10. The apparatus of claim 9, wherein the determining module is further configured to:
and maintaining the thread local cache functions of all application program processes in the electronic equipment in an open state under the condition that the current available memory is larger than the second set memory.
11. A cache processing apparatus, comprising:
a processor;
a memory configured to store processor-executable instructions;
wherein the processor is configured to: when executed, implement the steps of any of the above-mentioned cache processing methods of claims 1 to 5.
12. A non-transitory computer readable storage medium having instructions stored thereon that, when executed by a processor of a cache processing apparatus, enable the apparatus to perform the steps of the cache processing method of any of claims 1 to 5.
CN202011290406.XA 2020-11-17 2020-11-17 Cache processing method and device and storage medium Pending CN114510342A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011290406.XA CN114510342A (en) 2020-11-17 2020-11-17 Cache processing method and device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011290406.XA CN114510342A (en) 2020-11-17 2020-11-17 Cache processing method and device and storage medium

Publications (1)

Publication Number Publication Date
CN114510342A true CN114510342A (en) 2022-05-17

Family

ID=81546585

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011290406.XA Pending CN114510342A (en) 2020-11-17 2020-11-17 Cache processing method and device and storage medium

Country Status (1)

Country Link
CN (1) CN114510342A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024032430A1 (en) * 2022-08-09 2024-02-15 华为技术有限公司 Memory management method and electronic device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024032430A1 (en) * 2022-08-09 2024-02-15 华为技术有限公司 Memory management method and electronic device

Similar Documents

Publication Publication Date Title
EP3572936B1 (en) Method, terminal and computer-readable storage medium for displaying interface of application program
CN105955765B (en) Application preloading method and device
US9860844B2 (en) Method and apparatus of temperature control
JP6072362B2 (en) Application program processing method, apparatus, program, and storage medium
CN109254849B (en) Application program running method and device
US20170060599A1 (en) Method and apparatus for awakening electronic device
CN111610912B (en) Application display method, application display device and storage medium
CN112905089B (en) Equipment control method and device
US9678868B2 (en) Method and device for optimizing memory
RU2626089C2 (en) Method and device for subject application download
CN107632835B (en) Application installation method and device
CN107371222B (en) Virtual card disabling method and device
CN107436782B (en) Application silent installation method and device
CN114510342A (en) Cache processing method and device and storage medium
CN106201738B (en) System broadcast calling method and device
CN105786561B (en) Method and device for calling process
CN112307229A (en) Data processing method and device, electronic equipment and computer readable storage medium
CN106354657B (en) Register access method, device and system
CN112905096B (en) Display control method, device, terminal equipment and storage medium
CN110569037B (en) Data writing method and device
CN114442789A (en) Dark screen control method, device, equipment and storage medium
CN107360315B (en) Information display method and device
CN112230982A (en) Material processing method and device, electronic equipment and storage medium
US11894009B2 (en) Audio processing method, audio processing apparatus and computer storage medium
CN107124505B (en) Recording method and device

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