Cache processing method and apparatus, and storage medium
By obtaining the current memory state of the electronic device and dynamically adjusting the thread-local cache function, the problem of increased memory consumption caused by fixed configuration in the existing technology is solved, and the balance of memory usage and efficiency improvement are achieved.
Patent Information
- Application Number
- CN202011290406.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-17
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2040-11-17
AI Technical Summary
In existing technologies, thread-local caching is configured at a fixed time during compilation and cannot be dynamically adjusted according to the memory status of electronic devices, resulting in increased memory consumption and the inability to be configured differently.
By obtaining the current memory state of the electronic device, the thread-local caching function can be dynamically adjusted to enable or disable, including the assessment of total memory and available memory, to determine whether to enable or disable the thread-local caching function of the application process.
It enables flexible adjustment of caching strategies based on memory status, reducing memory consumption, improving memory utilization efficiency, and balancing memory usage and allocation.
Smart Images

Figure CN114510342B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the field of memory management, and particularly relates to a cache processing method and device and storage medium. BACKGROUND
[0002] In order to meet the use requirements of a large number of users, different memory configurations can be set for different electronic devices. Taking a mobile phone as an example, the same mobile phone can be set with a 2G memory configuration, i.e., a total memory capacity of 2GB = 2048MB (megabytes), or a 3G memory configuration, i.e., a total memory capacity of 3GB = 3072MB (megabytes). In the implementation process, memory allocation can be performed based on a memory allocator.
[0003] In the related art, the memory allocator can implement multi-thread concurrency, and in order to improve the performance of multi-thread concurrent allocation, a thread local cache function is set to reduce the performance loss caused by synchronization between multiple threads. However, the thread local cache function increases the consumption of memory. Since the related art determines whether to enable the thread local cache function during the compilation process, it is unable to perform differentiated configuration for different electronic devices, and if the cache strategy is determined during the compilation, the cache strategy cannot be dynamically adjusted during the use of the electronic device. SUMMARY
[0004] The present disclosure provides a cache processing method, device and storage medium.
[0005] According to a first aspect of an embodiment of the present disclosure, a cache processing method is provided, applied to an electronic device, comprising:
[0006] obtaining a current memory state of the electronic device;
[0007] determining whether to enable a thread local cache function of an application program process according to a cache strategy corresponding to the current memory state.
[0008] Optionally, the obtaining of the current memory state of the electronic device comprises:
[0009] when an enabling instruction of the electronic device is detected, obtaining a total memory of the electronic device;
[0010] The determining whether to enable the thread local cache function of the application program process according to the cache strategy corresponding to the current memory state comprises:
[0011] in a case where the total memory is greater than or equal to a first set memory, enabling the thread local cache function of all the application program processes in the electronic device.
[0012] Optionally, the determining whether to start the thread-local cache function of the application process according to the cache strategy corresponding to the current memory state comprises:
[0013] In a case where the total memory is less than the first set memory, the thread-local cache function of all application processes in the electronic device is closed.
[0014] Optionally, the method further comprises:
[0015] acquiring a current available memory of the electronic device when the electronic device is running;
[0016] the determining whether to start the thread-local cache function of the application process according to the cache strategy corresponding to the current memory state comprises:
[0017] In a case where the current available memory is less than or equal to a second set memory, maintaining the thread-local cache function of the application process in the starting state in a started state, and closing the thread-local cache function of the application process to be started.
[0018] Optionally, the determining whether to start the thread-local cache function of the application process according to the cache strategy corresponding to the current memory state comprises:
[0019] In a case where the current available memory is greater than the second set memory, maintaining the thread-local cache function of all application processes in the electronic device in a started state.
[0020] According to a second aspect of the embodiments of the present disclosure, a cache processing apparatus applied to an electronic device is provided, comprising:
[0021] a first acquiring module configured to acquire a current memory state of the electronic device;
[0022] a determining module configured to determine whether to start a thread-local cache function of an application process according to a cache strategy corresponding to the current memory state.
[0023] Optionally, the first acquiring module is further configured to:
[0024] acquire a total memory of the electronic device when starting instruction of the electronic device is detected;
[0025] the determining module is further configured to:
[0026] In a case where the total memory is greater than or equal to a first set memory, start the thread-local cache function of all the application processes in the electronic device.
[0027] Optionally, the determining module is further configured to:
[0028] In a case where the total memory is less than the first set memory, the thread local cache function of all application processes in the electronic device is closed.
[0029] Optionally, the apparatus further comprises:
[0030] The second obtaining module is configured to obtain the current available memory of the electronic device when the electronic device is running.
[0031] The determining module is further configured to:
[0032] In a case where the current available memory is less than or equal to the second set memory, the thread local cache function of the application process in the starting state is maintained in the open state, and the thread local cache function of the application process to be started is closed.
[0033] Optionally, the determining module is further configured to:
[0034] In a case where the current available memory is greater than the second set memory, the thread local cache function of all application processes in the electronic device is maintained in the open state.
[0035] According to a third aspect of the embodiments of the present disclosure, a cache processing apparatus is provided, comprising:
[0036] a processor;
[0037] a memory configured to store processor-executable instructions;
[0038] The processor is configured to implement the steps in any of the cache processing methods in the first aspect when executed.
[0039] According to a fourth aspect of the embodiments of the present disclosure, a non-transitory computer-readable storage medium is provided, when instructions in the storage medium are executed by a processor of a cache processing apparatus, the apparatus can implement the steps in any of the cache processing methods in the first aspect when executed.
[0040] The technical solutions provided by the embodiments of the present disclosure can include the following beneficial effects:
[0041] In the embodiments of the present disclosure, the current memory state of the electronic device can be acquired, and whether to start the thread local cache function of the application process can be determined according to the cache strategy corresponding to the current memory state. Compared with the related art, the cache strategy is determined during compilation, and the thread local cache function of the application process is started or stopped according to the fixed cache strategy. In the embodiments of the present disclosure, the cache strategy 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 started or stopped according to the memory state of the electronic device, and the dynamic adjustment of the cache strategy can be realized.
[0042] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF DRAWINGS
[0043] The accompanying drawings, which are incorporated into and form part of the specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the application.
[0044] Figure 1 is a flowchart of a cache processing according to an exemplary embodiment Figure 1 .
[0045] Figure 2 is a flowchart of a cache processing according to an exemplary embodiment Figure 2 .
[0046] Figure 3 is a flowchart of a cache processing according to an exemplary embodiment Figure 3 .
[0047] Figure 4 is a block diagram of a cache processing device according to an exemplary embodiment.
[0048] Figure 5 is a block diagram of a cache processing device according to an exemplary embodiment. DETAILED DESCRIPTION
[0049] The exemplary embodiments will be described in detail herein with reference to the attached drawings. In the following description, the same numbers in different drawings represent the same or similar elements unless otherwise represented. The embodiments described in the following exemplary embodiments do not represent all the embodiments consistent with the present application. Instead, they are merely examples of apparatuses and methods consistent with some aspects of the present application as detailed in the appended claims.
[0050] In the embodiments of the present disclosure, a cache processing method is provided, which can be applied to an electronic device. Figure 1 is a flowchart of a cache processing according to an exemplary embodimentFigure 1 As shown in Figure 1 The method mainly comprises the following steps:
[0051] In step 101, the current memory state of the electronic device is acquired.
[0052] In step 102, according to the cache strategy corresponding to the current memory state, it is determined whether to start the thread-local cache function of the application process.
[0053] The cache processing method involved in the embodiments of the present disclosure can be applied to an electronic device. Here, the electronic device includes a terminal device, such as a mobile terminal and a fixed terminal, wherein the mobile terminal includes a mobile phone, a tablet computer, a notebook computer, etc.; the fixed terminal includes a personal computer. In other optional embodiments, the cache processing method can also be applied to an embedded electronic device configured with an Android operating system.
[0054] Here, the current memory state can include the memory state of the electronic device during the booting process and the memory state of the electronic device after the booting is successful. After the current memory state of the electronic device is acquired, the cache strategy corresponding to the current memory state can be determined, and whether to start the thread-local cache function of the application process can be determined according to the cache strategy.
[0055] In some embodiments, the electronic device has a set type of operating system, for which a corresponding memory allocator can be set, and the memory allocator is configured with a thread-local cache function. For example, if the set type of operating system is an Android operating system, Jemalloc can be used as a memory allocator, and the memory allocator is configured with a thread-local cache function. The thread-local cache function is set for each thread in each application process. In the implementation process, if the thread-local cache function is started, a corresponding thread-local cache area can be configured for each thread, and the objects of each thread can be stored based on the local cache area.
[0056] Taking an electronic device with an Android operating system as an example, since Jemalloc has excellent multi-thread concurrent allocation performance, the Android operating system can use Jemalloc as a memory allocator. Since continuously starting the thread-local cache function will increase the memory consumption of the electronic device, in the implementation process, the current memory state of the electronic device can be acquired, and whether to start the thread-local cache function of the application process can be determined according to the cache strategy corresponding to the current memory state.
[0057] For example, the total memory of the electronic device can be acquired, and in a case where 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 enabled. For another example, in a case where the total memory of the electronic device is less than the first set memory, the thread local cache function of all application processes in the electronic device is disabled.
[0058] In the embodiments of the present disclosure, the current memory state of the electronic device can be acquired, and whether to enable the thread local cache function of the application process can be determined according to the cache strategy corresponding to the current memory state. Compared with the related art in which the cache strategy is determined during compilation, and the thread local cache function of the application process is enabled or disabled according to the fixed cache strategy, in the embodiments of the present disclosure, the cache strategy 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 enabled or disabled according to the memory state of the electronic device, and the dynamic adjustment of the cache strategy can be implemented.
[0059] In some embodiments, the current memory state of the electronic device is acquired by:
[0060] When the enabling instruction of the electronic device is detected, the total memory of the electronic device is acquired.
[0061] The cache strategy corresponding to the current memory state is determined, and whether to enable the thread local cache function of the application process is determined.
[0062] In a case where the total memory is greater than or equal to the first set memory, the thread local cache function of all the application processes in the electronic device is enabled.
[0063] Here, the enabling instruction can be an instruction triggered by a user based on a control on the electronic device, where the control can be a virtual control or a physical button. In the embodiments of the present disclosure, when the enabling instruction is detected, the electronic device can be started, and the total memory of the electronic device can be acquired when the electronic device is started.
[0064] For example, the total memory of the electronic device can be read by the first process started in the process of starting the electronic device. For another example, the total memory of the electronic device can be read based on the init() function in the process of starting the electronic device.
[0065] After the total memory of the electronic device is acquired, the total memory of the electronic device can be compared with the first set memory to obtain a first comparison result, and whether to enable the thread local cache function of the application process in the electronic device is determined according to the first comparison result.
[0066] For example, in a case where the first comparison result represents 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 processes in the electronic device is enabled. Since enabling the local cache function consumes the memory of the electronic device, in the embodiment of the present disclosure, in a case where the total memory of the electronic device is sufficient, the thread local cache function of all application processes is enabled, which can ensure the running speed of the application on the basis of ensuring that the available memory of the electronic device is sufficient.
[0067] In some other embodiments, in a case where the total memory of the electronic device is greater than or equal to the first set memory, the thread local cache function of part of the application processes in the electronic device can be enabled. For example, in a case where 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 processes in the electronic device can be enabled, where N can be set as needed, for example, can be 3 or 5, and the like, which is not specifically limited herein.
[0068] In the embodiment of the present disclosure, the total memory of the electronic device can be obtained during the booting of the electronic device, and the total memory of the electronic device is evaluated. In a case where it is determined that the total memory is sufficient to ensure that the electronic device can normally run after the thread local cache function is enabled, the thread local cache function of all or part of the application processes in the electronic device is enabled, which can balance the memory occupation and allocation of the electronic device.
[0069] In some embodiments, the determining whether to enable the thread local cache function of the application process according to the cache strategy corresponding to the current memory state comprises:
[0070] In a case where the total memory is less than the first set memory, the thread local cache function of all application processes in the electronic device is disabled.
[0071] In some other embodiments, in a case where the total memory of the electronic device is less than the first set memory, the thread local cache function of part of the application processes in the electronic device can be disabled. For example, in a case where the total memory of the electronic device is less than the first set memory, the thread local cache function of K application processes in the electronic device can be disabled, where K can be set as needed, for example, can be 2 or 6, and the like, which is not specifically limited herein.
[0072] In the embodiment of the present disclosure, the total memory of the electronic device can be obtained during the booting of the electronic device, and the total memory of the electronic device is evaluated. In a case where it is determined that the total memory is insufficient to ensure that the electronic device can normally run after the thread local cache function is enabled, the thread local cache function of all or part of the application processes in the electronic device is disabled, which can balance the memory occupation and allocation of the electronic device.
[0073] In some embodiments, the method further comprises:
[0074] acquiring a current available memory of the electronic device while the electronic device is running;
[0075] determining whether to start the thread-local cache function of the application process according to the cache strategy corresponding to the current memory state, comprising:
[0076] maintaining the thread-local cache function of the application process in the starting state in the open state and closing the thread-local cache function of the application process to be started in the case that the current available memory is less than or equal to the second set memory.
[0077] Here, the current available memory of the electronic device can be acquired during the running of the electronic device, wherein the current available memory can refer to the memory in the electronic device that is not currently occupied. In the embodiment of the present disclosure, the current available memory of the electronic device can be acquired during the use of the electronic device, and the current available memory is compared with the second set memory to obtain a second comparison result, and whether to start the thread-local cache function of the application process is determined according to the second comparison result.
[0078] For example, in the case that the second comparison result represents that the current available memory is less than or equal to the second set memory, the thread-local cache function of the application process in the starting state can be maintained in the open state, and the thread-local cache function of the application process to be started can be closed.
[0079] In the embodiment of the present disclosure, the current available memory of the electronic device can be acquired during the running of the electronic device, and the current available memory is evaluated. In the case that it is determined that the current available memory is insufficient to ensure that the electronic device can normally run on the basis of starting the thread-local cache function, the thread-local cache function of the application process in the starting state can be maintained in the open state, and the thread-local cache function of the application process to be started can be closed, which can realize the balance of the memory occupation and allocation of the electronic device.
[0080] In some embodiments, the determining whether to start the thread-local cache function of the application process according to the cache strategy corresponding to the current memory state, comprises:
[0081] maintaining the thread-local cache function of all application processes in the electronic device in the open state in the case that the current available memory is greater than the second set memory.
[0082] In the embodiments of the present disclosure, during the running of the electronic device, the current available memory of the electronic device can be acquired, and the current available memory is evaluated. In the case that the current available memory is sufficient to ensure that the electronic device can normally run on the basis of starting the thread local cache function, the thread local cache function of all application processes in the electronic device can be maintained in the starting state, and the balance of the memory occupation and allocation of the electronic device can be achieved.
[0083] In some embodiments, taking an electronic device with an Android operating system as an example, since Jemalloc has excellent multi-thread concurrent allocation performance, the Android operating system can use Jemalloc as a memory allocator.
[0084] In order to improve the multi-thread concurrent allocation performance, Jemalloc uses the thread local cache function to avoid the performance loss caused by the synchronization between multiple threads. However, starting the thread local cache function will increase the memory consumption. In the related art, the thread local cache function is started by default. For example, Jemalloc selects to start or close the thread local cache function during the compilation. For example, the thread local cache function can be selected to be closed on the electronic device with a low memory configuration to save the memory consumption. In the related art, Jemalloc defines a macro variable in the compilation script to determine whether to start the thread local cache function. Jemalloc determines whether to start the thread local cache function according to whether the macro variable is set in the initialization code. In the implementation process, the compilation script needs to be modified to achieve the purpose of starting or closing the thread local cache function.
[0085] Electronic device products generally have multiple memory configurations. For example, a mobile phone can have 2G, 3G or 4G memory. In the implementation process, the mobile phone with 2G and 3G memory configurations needs to close the thread local cache function to save memory, and the mobile phone with 4G memory configuration can start the thread local cache function to obtain better performance. Jemalloc selects to start or close the thread local cache function during the compilation by default, and cannot be differentiated on the same electronic device with different memory.
[0086] In the Android operating system, Jemalloc cannot dynamically adjust the cache strategy according to the memory pressure of the electronic device in use. For example, the thread local cache function is closed for the newly started process when the memory pressure is large, and the thread local cache function is started for the newly started process when the memory pressure is small.
[0087] In some embodiments, the technical solutions in the embodiments of the present disclosure are composed of three parts of 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 runtime read-only to runtime readable and writable. For example, the configuration function of the global variable opt_tcache of Jemalloc in the config module for controlling the thread local cache function can be modified from runtime read-only to runtime readable and writable, and a parameter option OPT_TCACHE is added in the mallopt function of libc, which is used to modify the global variable opt_tcache of Jemalloc in the single-threaded case, so as to close or open the thread local cache function.
[0088] Figure 2 is a flowchart of cache processing according to an exemplary embodiment Figure 2 As shown in Figure 3 , the method mainly includes the following steps:
[0089] In step 201, the total memory of the electronic device is read.
[0090] Here, the total memory of the electronic device can be read by the first process started in the process of turning on the electronic device. For another example, the total memory of the electronic device can be read based on the init() function in the process of turning on the electronic device.
[0091] In step 202, it is determined whether the total memory of the electronic device is less than the first set memory.
[0092] Here, the thread local cache function can be determined to be opened or closed according to the total memory of the electronic device. For example, after obtaining the total memory of the electronic device, the total memory of the electronic device can be compared with the first set memory to obtain a first comparison result, and whether to enable the thread local cache function of the application process in the electronic device is determined according to the first comparison result. For example, in the case where the total memory is less than the first set memory, the thread local cache function of all application processes in the electronic device is closed.
[0093] In step 203, if the total memory is less than the first set memory, the attribute ro.boot.disable_tcache is set to true.
[0094] Here, if it is necessary to close the thread local cache function, the attribute ro.boot.disable_tcache can be set to true.
[0095] In step 204, the init process forks a child process.
[0096] In step 205, it is determined whether the ro.boot.disable_tcache attribute read by the child process forked by the init process is true.
[0097] In step 206, if the ro.boot.disable_tcache attribute read by the child process is true, the environment variable JEMALLOC_DISABLE_TCACHE is set to 1.
[0098] Here, in the subsequent boot process, if the init process forked child process reads the ro.boot.disable_tcache attribute as true, the environment variable JEMALLOC_DISABLE_TCACHE can be set to 1.
[0099] In step 207, if the ro.boot.disable_tcache attribute read by the child process is not true, the libc will be reinitialized when the child process executes a new executable file using the exec system call.
[0100] In step 208, it is determined whether the environment variable JEMALLOC_DISABLE_TCACHE is 1.
[0101] Here, the JEMALLOC_DISABLE_TCACHE environment variable can be read during the initialization of libc, and it is determined whether the environment variable JEMALLOC_DISABLE_TCACHE is 1.
[0102] In step 209, if the JEMALLOC_DISABLE_TCACHE environment variable exists and the value is 1, the global variable opt_tcache that determines whether the thread local cache is open is directly set to false to close the thread local cache function.
[0103] In some embodiments, since the Android application (Application, App) is forked from the zygote process, and the zygote is forked from the init process, we only need to close the thread local cache function of the zygote process during the startup process of the electronic device (for example, a mobile phone), and the thread local cache of all subsequent application processes will be closed.
[0104] Figure 3 The flowchart of the cache processing according to an exemplary embodiment is shown. Figure 4 As shown in Figure 4 , the method mainly includes the following steps:
[0105] In step 301, the zygote process is requested to start a new application process.
[0106] In step 302, the zygote process forks a child process.
[0107] In step 303, it is determined whether the current available memory of the electronic device is less than or equal to the second set memory.
[0108] In step 304, when the current available memory of the electronic device is less than or equal to the second set memory, the global variable opt_tcache that determines whether the thread cache is opened is set to false using the newly added mallopt option OPT_TCACHE, so as to close the thread cache function.
[0109] Here, taking the electronic device as a mobile phone as an example, during the use of the mobile phone, it can be determined whether to open or close the thread cache function of the newly started application process according to the overall memory state of the mobile phone. For example, when the overall memory state is poor, the thread cache function of the newly started application process can be closed to save memory.
[0110] In some embodiments, when the application process forked by the zygote process is in a single-thread state, the global variable opt_tcache that determines whether the thread cache is opened can be set to false using the newly added mallopt option OPT_TCACHE, so as to close the thread cache function.
[0111] In some embodiments, the cache strategy can be adjusted according to the overall memory state of the electronic device during the booting process of the electronic device. Still taking the electronic device as a mobile phone as an example, for example, a certain mobile phone has two configurations of 3G and 4G memory, and the mobile phones with the two memory configurations are burned with the same software package. During the implementation, the mobile phone can support opening or closing the thread cache function at runtime by modifying the Jemalloc underlying function, and the actual memory size (total memory) of the mobile phone can be determined during the booting process of the mobile phone, and whether to open the thread cache function can be determined based on the actual memory size. For example, the thread cache function of all application processes in the 3G mobile phone is closed, and the thread cache function of all application processes in the 4G mobile phone is opened.
[0112] In some embodiments, the cache strategy can be adjusted according to the overall memory state of the electronic device during the running of the electronic device. Still taking the electronic device as a mobile phone as an example, the cache strategy can be adjusted according to the overall memory state of the mobile phone during the running of the mobile phone. For example, the current memory state of the mobile phone can be monitored, and the thread local cache function of the newly started application process can be closed when the memory pressure is large, and the thread local cache function of the newly started application process can be started when the memory pressure is small.
[0113] By the technical solution of the present disclosure, on the one hand, the problem of how to decide whether to start or close the thread local cache function of all application processes of the electronic device according to the memory size or other state information is solved. On the other hand, the problem of how to start the thread local cache function of part of the application processes according to a specific strategy, while closing the thread local cache function of another part of the application processes is solved. Moreover, after the technical solution of the present disclosure is adopted, the balance of memory occupation and allocation is achieved, and the electronic device with 2G memory configuration can save 60-100M memory, and the electronic device with 3G memory configuration can save 100-300M memory.
[0114] Figure 5 is a block diagram of a cache processing device according to an exemplary embodiment. As shown in Figure 5 the cache processing device 400 is applied to an electronic device, and mainly includes:
[0115] A first obtaining module 401 is configured to obtain the current memory state of the electronic device.
[0116] A determining module 402 is configured to determine whether to start the thread local cache function of the application process according to the cache strategy corresponding to the current memory state.
[0117] In some embodiments, the first obtaining module 401 is further configured to:
[0118] when the starting instruction of the electronic device is detected, obtain the total memory of the electronic device;
[0119] The determining module is further configured to:
[0120] in the case that the total memory is greater than or equal to the first set memory, start the thread local cache function of all the application processes in the electronic device.
[0121] In some embodiments, the determining module 402 is further configured to:
[0122] in the case that the total memory is less than the first set memory, close the thread local cache function of all the application processes in the electronic device.
[0123] In some embodiments, the apparatus 400 further includes:
[0124] a second obtaining module, configured to obtain a current available memory of the electronic device when the electronic device is running;
[0125] the determining module is further configured to:
[0126] maintain the thread local cache function of the application process in the starting state in an open state, and close the thread local cache function of the application process to be started, in the case that the current available memory is less than or equal to the second set memory.
[0127] In some embodiments, the determining module 402 is further configured to:
[0128] maintain the thread local cache function of all application processes in the electronic device in an open state, in the case that the current available memory is greater than the second set memory.
[0129] As to the apparatus in the above embodiments, specific manners in which various modules perform operations have been described in details in the embodiments of the method, and thus will not be repeated here.
[0130] is a block diagram of a cache processing apparatus 1200 according to an exemplary embodiment. The apparatus 1200 can be a mobile phone, computer, digital broadcast terminal, message communicator, game console, tablet device, medical device, fitness device, personal digital assistant, or the like, for example.
[0131] Referring to , the apparatus 1200 can include one or more of the following components: a processing component 1202, a memory 1204, a power supply component 1206, a multimedia component 1208, an audio component 1210, an input / output (I / O) interface 1212, a sensor component 1214, and a communication component 1216.
[0132] The processing component 1202 usually controls overall operations of the apparatus 1200, such as operations associated with displaying, making phone calls, data communications, camera operations, and recording operations. The processing component 1202 can include one or more processors 1220 to execute instructions to complete all or part of steps of the above method. Further, the processing component 1202 can include one or more modules to facilitate interaction between the processing component 1202 and other components. For example, the processing component 1202 can include a multimedia module to facilitate the interaction between the multimedia component 1208 and the processing component 1202.
[0133] The memory 1204 is configured to store various types of data to support operations of the device 1200. Examples of these data include instructions for any application or method operating on the device 1200, contact data, phonebook data, messages, pictures, videos, and the like. The memory 1204 can be implemented by any type of volatile or nonvolatile memory, or a combination thereof 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 disc or optical disc.
[0134] The power supply component 1206 supplies power for various components of the device 1200. The power supply component 1206 can include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 1200.
[0135] The multimedia component 1208 includes a screen providing an output interface between the device 1200 and a user. In some embodiments, the screen can include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, swiping, and gestures on the touch panel. The touch sensors can not only sense a boundary of a touching or swiping action, but also detect duration and pressure related to the touching or swiping action. In some embodiments, the multimedia component 1208 includes a front camera and / or a rear camera. The front and / or rear camera can receive external multimedia data when the device 1200 is in an operating mode, such as a shooting mode or a video mode. Each of the front and rear camera can be a fixed optical lens system or have a focal length and optical zoom capability.
[0136] The audio component 1210 is configured to output and / or input audio signals. For example, the audio component 1210 includes a microphone (MIC) configured to receive external audio signals when the device 1200 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals can be further stored in the memory 1204 or transmitted via the communication component 1216. In some embodiments, the audio component 1210 also includes a speaker for outputting audio signals.
[0137] The I / O interface 1212 provides an interface between the processing component 1202 and peripheral interface modules, which can be a keyboard, a click wheel, a button, and the like. The buttons can include, but are not limited to, a home button, a volume button, a start button, and a lock button.
[0138] The sensor component 1214 includes one or more sensors for providing status assessments for various aspects of the device 1200. For example, the sensor component 1214 can detect an open / closed position of the device 1200, relative positioning of components of the device 1200, such as a display and keypad of the device 1200, a change in position of the device 1200 or a component of the device 1200, presence or absence of user contact with the device 1200, orientation or acceleration / deceleration of the device 1200, and temperature changes of the device 1200. The sensor component 1214 can include proximity sensor(s) configured to detect presence of nearby objects without any physical contact. The sensor component 1214 can further include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor component 1214 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0139] The communication component 1216 is configured to facilitate wired or wireless communication between the device 1200 and another device. The device 1200 can access a wireless network based on a corresponding communication standard, such as WiFi, 2G, or 3G, or a combination thereof. In an exemplary embodiment, the communication component 1216 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1216 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, Infrared Data Association (IrDA) technology, Ultra-WideBand (UWB) technology, Bluetooth (BT) technology and other technologies.
[0140] In an exemplary embodiment, the device 1200 can be implemented with 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, microcontrollers, or other electronic units to perform the above-described methods.
[0141] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions, such as the memory 1204 including instructions, is also provided, which can be executed by the processor 1220 of the device 1200 to complete the above-described methods. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disc, and an optical data storage device, etc.
[0142] A non-transitory computer readable storage medium, when instructions in the storage medium are executed by a processor of a cache processing device, enable the cache processing device to perform a cache processing method, the method comprising:
[0143] obtaining a current memory state of the electronic device;
[0144] determining whether to enable a thread-local cache function of an application process according to a cache policy corresponding to the current memory state.
[0145] Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the features disclosed herein. The disclosure is intended to cover any variations, uses or adaptations of the disclosure following, in general, the principles of the disclosure and including such features that are evident to those skilled in the art or are known in the art and can be used in place of or in conjunction with features described herein. The specification and examples are to be regarded as illustrative only, and the true scope and spirit of the disclosure are indicated by the following claims.
[0146] It should be understood that the present disclosure is not limited to the precise structures herein described and illustrated in the drawings, and that various modifications and changes can be made without departing from its scope. The scope of the present disclosure is limited only by the claims that follow.
Claims
1. A cache processing method characterized by, The application is applied to an electronic device, comprising: acquiring a current memory state of the electronic device; determining whether to start a thread local cache function of an application process according to a cache strategy corresponding to the current memory state; the determining whether to start the thread local cache function of the application process according to the cache strategy corresponding to the current memory state comprises: in a case where a total memory of the electronic device is greater than or equal to a first set memory, starting the thread local cache function of all or part of the application processes in the electronic device; in a case where the total memory is less than the first set memory, closing the thread local cache function of all or part of the application processes in the electronic device.
2. The method of claim 1, wherein, the acquiring the current memory state of the electronic device comprises: acquiring the total memory of the electronic device when a starting instruction of the electronic device is detected.
3. The method of claim 1, wherein, the method further comprises: acquiring a current available memory of the electronic device when the electronic device is running; the determining whether to start the thread local cache function of the application process according to the cache strategy corresponding to the current memory state comprises: in a case where the current available memory is less than or equal to a second set memory, maintaining the thread local cache function of an application process in a starting state in a starting state, and closing the thread local cache function of an application process to be started.
4. The method of claim 3, wherein, the determining whether to start the thread local cache function of the application process according to the cache strategy corresponding to the current memory state comprises: in a case where the current available memory is greater than the second set memory, maintaining the thread local cache function of all the application processes in the electronic device in a starting state.
5. A cache processing device, characterized by, The application is applied to an electronic device, comprising: a first acquisition module configured to acquire a current memory state of the electronic device; a determination module configured to determine whether to start a thread local cache function of an application process according to a cache strategy corresponding to the current memory state; the determination module is further configured to: in a case where a total memory of the electronic device is greater than or equal to a first set memory, start the thread local cache function of all or part of the application processes in the electronic device; in a case where the total memory is less than the first set memory, close the thread local cache function of all or part of the application processes in the electronic device.
6. The apparatus of claim 5, wherein, the first acquisition module is further configured to: acquire the total memory of the electronic device when a starting instruction of the electronic device is detected.
7. The apparatus of claim 5, wherein, the device further comprises: a second acquisition module configured to acquire a current available memory of the electronic device when the electronic device is running; the determination module is further configured to: in a case where the available memory is less than or equal to a second set memory, maintain the thread local cache function of an application process in a starting state in a starting state, and close the thread local cache function of an application process to be started.
8. The apparatus of claim 7, wherein, the determination module is further configured to: in a case where the current available memory is greater than the second set memory, maintain the thread local cache function of all the application processes in the electronic device in a starting state. In a case that the current available memory is greater than the second set memory, the thread local cache function of all application processes in the electronic device is maintained in an open state.
9. A cache processing device, characterized by, Comprise: a processor; a memory configured to store processor-executable instructions; wherein the processor is configured to implement the steps in any one of the cache processing methods in claims 1-4 when executed.
10. A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of a cache processing apparatus, enable the apparatus to implement the steps in any one of the cache processing methods in claims 1-4.
Citation Information
Patent Citations
Memory management method used for parallel processing of streaming data
CN105094751A
Method and device of collecting memory
CN107526641A