Movatterモバイル変換


[0]ホーム

URL:


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
CN114510342ACN202011290406.XACN202011290406ACN114510342ACN 114510342 ACN114510342 ACN 114510342ACN 202011290406 ACN202011290406 ACN 202011290406ACN 114510342 ACN114510342 ACN 114510342A
Authority
CN
China
Prior art keywords
memory
electronic device
function
thread local
cache
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 LtdfiledCriticalBeijing Xiaomi Mobile Software Co Ltd
Priority to CN202011290406.XApriorityCriticalpatent/CN114510342A/en
Publication of CN114510342ApublicationCriticalpatent/CN114510342A/en
Pendinglegal-statusCriticalCurrent

Links

Images

Classifications

Landscapes

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

Translated fromChinese
缓存处理方法、装置及存储介质Cache processing method, device and storage medium

技术领域technical field

本公开涉及内存管理领域,尤其涉及一种缓存处理方法、装置及存储介质。The present disclosure relates to the field of memory management, and in particular, to a cache processing method, device and storage medium.

背景技术Background technique

为了满足广大用户的使用需求,可以针对不同的电子设备设置多种不同的内存配置。以电子设备是手机为例,同一款手机既可以设置2G内存配置,即总内存容量为2GB=2048MB(兆字节);也可以设置3G内存配置,即总内存容量为3GB=3072MB(兆字节),在实现的过程中,可以基于内存分配器来进行内存的分配。In order to meet the needs of users, a variety of different memory configurations can be set for different electronic devices. Taking the electronic device as a mobile phone as an example, the same mobile phone can be set to a 2G memory configuration, that is, the total memory capacity is 2GB=2048MB (megabytes); it can also be set to a 3G memory configuration, that is, the total memory capacity is 3GB=3072MB (megabytes). Section), in the process of implementation, memory allocation can be performed based on the memory allocator.

相关技术中,内存分配器能够实现多线程并发,且为了提升多线程并发分配的性能,设置了线程局部缓存功能,以减少多线程之间的同步所导致的性能损耗,但是,线程局部缓存功能会使得内存的消耗增加。由于相关技术中在编译过程中就决定了是否开启线程局部缓存功能,无法针对不同的电子设备进行差异化配置,且如果在编译期间就确定了缓存策略,在电子设备使用的过程中无法动态调整缓存策略。In the related art, the memory allocator can realize multi-thread concurrency, and in order to improve the performance of multi-thread concurrent allocation, the thread local cache function is set to reduce the performance loss caused by synchronization between multiple threads. However, the thread local cache function Will increase memory consumption. In the related art, it is determined during the compilation process whether to enable the thread local cache function, so it is impossible to perform differential configuration for different electronic devices, and if the cache strategy is determined during compilation, it cannot be dynamically adjusted during the use of electronic devices. caching strategy.

发明内容SUMMARY OF THE INVENTION

本公开提供一种缓存处理方法、装置及存储介质。The present disclosure provides a cache processing method, device and storage medium.

根据本公开实施例的第一方面,提供一种缓存处理方法,应用于电子设备,包括:According to a first aspect of the embodiments of the present disclosure, a cache processing method is provided, applied to an electronic device, including:

获取所述电子设备的当前内存状态;obtaining the current memory state of the electronic device;

根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。According to the cache policy corresponding to the current memory state, it is determined whether to enable the thread local cache function of the application process.

可选的,所述获取所述电子设备的当前内存状态,包括:Optionally, the acquiring the current memory state of the electronic device includes:

在检测到开启所述电子设备的开启指令时,获取所述电子设备的总内存;Obtaining the total memory of the electronic device when detecting an opening instruction to turn on the electronic device;

所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:The determining whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state includes:

在所述总内存大于或者等于第一设定内存的情况下,开启所述电子设备中所有所述应用程序进程的线程局部缓存功能。In the case that the total memory is greater than or equal to the first set memory, the thread local caching function of all the application processes in the electronic device is enabled.

可选的,所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:Optionally, the determining whether to enable the thread-local caching function of the application process according to the cache policy corresponding to the current memory state includes:

在所述总内存小于所述第一设定内存的情况下,关闭所述电子设备中所有应用程序进程的线程局部缓存功能。In the case that 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.

可选的,所述方法还包括:Optionally, the method further includes:

在所述电子设备运行时,获取所述电子设备的当前可用内存;When the electronic device is running, obtain the currently available memory of the electronic device;

所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:The determining whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state includes:

在所述当前可用内存小于或者等于第二设定内存的情况下,维持处于启动状态下的应用程序进程的线程局部缓存功能处于开启状态,并关闭待启动的应用程序进程的线程局部缓存功能。When the currently available memory is less than or equal to the second set memory, the thread local cache function of the application process in the activated state is maintained in the enabled state, and the thread local cache function of the application process to be activated is disabled.

可选的,所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:Optionally, the determining whether to enable the thread-local caching function of the application process according to the cache policy corresponding to the current memory state includes:

在所述当前可用内存大于所述第二设定内存的情况下,维持所述电子设备中所有应用程序进程的线程局部缓存功能处于开启状态。In the case that the currently available memory is greater than the second set memory, the thread-local caching function of all application processes in the electronic device is maintained in an enabled state.

根据本公开实施例的第二方面,提供一种缓存处理装置,应用于电子设备,包括:According to a second aspect of the embodiments of the present disclosure, there is provided a cache processing apparatus, which is applied to an electronic device, including:

第一获取模块,配置为获取所述电子设备的当前内存状态;a first acquisition module, configured to acquire the current memory state of the electronic device;

确定模块,配置为根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。The determining module is configured to determine whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state.

可选的,所述第一获取模块,还配置为:Optionally, the first obtaining module is further configured as:

在检测到开启所述电子设备的开启指令时,获取所述电子设备的总内存;Obtaining the total memory of the electronic device when detecting an opening instruction to turn on the electronic device;

所述确定模块,还配置为:The determining module is further configured as:

在所述总内存大于或者等于第一设定内存的情况下,开启所述电子设备中所有所述应用程序进程的线程局部缓存功能。In the case that the total memory is greater than or equal to the first set memory, the thread local caching function of all the application processes in the electronic device is enabled.

可选的,所述确定模块,还配置为:Optionally, the determining module is further configured as:

在所述总内存小于所述第一设定内存的情况下,关闭所述电子设备中所有应用程序进程的线程局部缓存功能。In the case that 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.

可选的,所述装置还包括:Optionally, the device further includes:

第二获取模块,配置为在所述电子设备运行时,获取所述电子设备的当前可用内存;a second acquiring module, configured to acquire the currently available memory of the electronic device when the electronic device is running;

所述确定模块,还配置为:The determining module is further configured as:

在所述当前可用内存小于或者等于第二设定内存的情况下,维持处于启动状态下的应用程序进程的线程局部缓存功能处于开启状态,并关闭待启动的应用程序进程的线程局部缓存功能。When the currently available memory is less than or equal to the second set memory, the thread local cache function of the application process in the activated state is maintained in the enabled state, and the thread local cache function of the application process to be activated is disabled.

可选的,所述确定模块,还配置为:Optionally, the determining module is further configured as:

在所述当前可用内存大于所述第二设定内存的情况下,维持所述电子设备中所有应用程序进程的线程局部缓存功能处于开启状态。In the case that the currently available memory is greater than the second set memory, the thread-local caching function of all application processes in the electronic device is maintained in an enabled state.

根据本公开实施例的第三方面,提供一种缓存处理装置,包括:According to a third aspect of the embodiments of the present disclosure, there is provided a cache processing apparatus, including:

处理器;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 the first aspect when executed.

根据本公开实施例的第四方面,提供一种非临时性计算机可读存储介质,当所述存储介质中的指令由缓存处理装置的处理器执行时,使得所述装置能够执行时实现上述第一方面中任一种缓存处理方法中的步骤。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 execute the above-mentioned first The steps in any one of the cache processing methods in one aspect.

本公开的实施例提供的技术方案可以包括以下有益效果:The technical solutions provided by the embodiments of the present disclosure may include the following beneficial effects:

本公开实施例中,可以通过获取电子设备的当前内存状态,并根据与当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。相较于相关技术中在编译期间就确定缓存策略,并按照该固定的缓存策略开启或者关闭应用程序进程的线程局部缓存功能。本公开实施例中,能够根据电子设备的内存状态灵活调整缓存策略,即根据电子设备的内存状态开启或者关闭应用程序进程的线程局部缓存功能,能够实现缓存策略的动态调整。In the embodiment of the present disclosure, it can be determined whether to enable the thread local cache function of the application process by acquiring the current memory state of the electronic device and according to the cache policy corresponding to the current memory state. Compared with the related art, the cache policy is determined during compilation, and the thread-local cache function of the application process is enabled or disabled according to the fixed cache policy. In the embodiment of the present disclosure, the caching strategy can be flexibly adjusted according to the memory state of the electronic device, that is, the thread local caching function of the application process can be enabled or disabled according to the memory state of the electronic device, and the dynamic adjustment of the caching strategy can be realized.

应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本公开。It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure.

附图说明Description of 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.

图1是根据一示例性实施例示出的缓存处理的流程示意图一。FIG. 1 is a schematic flowchart 1 of a cache process according to an exemplary embodiment.

图2是根据一示例性实施例示出的缓存处理的流程示意图二。FIG. 2 is a second schematic flowchart of cache processing according to an exemplary embodiment.

图3是根据一示例性实施例示出的缓存处理的流程示意图三。FIG. 3 is a third schematic flowchart of cache processing according to an exemplary embodiment.

图4是根据一示例性实施例示出的一种缓存处理装置框图。Fig. 4 is a block diagram of a cache processing apparatus according to an exemplary embodiment.

图5是根据一示例性实施例示出的一种缓存处理装置的框图。Fig. 5 is a block diagram of a cache processing apparatus according to an exemplary embodiment.

具体实施方式Detailed ways

这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本发明相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本发明的一些方面相一致的装置和方法的例子。Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. Where the following description refers to the drawings, the same numerals in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the illustrative examples below are not intended to represent all implementations consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with some aspects of the invention as recited in the appended claims.

本公开实施例中提供了一种缓存处理方法,该方法可以应用于电子设备。图1是根据一示例性实施例示出的缓存处理的流程示意图一,如图1所示,该方法主要包括以下步骤:An embodiment of the present disclosure provides a cache processing method, which can be applied to an electronic device. FIG. 1 is a schematic flow chart 1 of cache processing according to an exemplary embodiment. As shown in FIG. 1 , the method mainly includes the following steps:

在步骤101中,获取所述电子设备的当前内存状态;Instep 101, the current memory state of the electronic device is obtained;

在步骤102中,根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。Instep 102, according to the cache policy corresponding to the current memory state, it is determined whether to enable the thread local cache function of the application process.

本公开实施例中所涉及的缓存处理方法可以应用于电子设备,这里,电子设备包括终端设备,如移动终端和固定终端,其中,移动终端包括:手机、平板电脑、笔记本电脑等;固定终端包括:个人计算机。在其他可选的实施例中,该缓存处理方法也可以适用行于配置安卓(Android)操作系统的嵌入式电子设备。The cache processing method involved in the embodiments of the present disclosure can be applied to electronic devices, where the electronic devices include terminal devices, such as mobile terminals and fixed terminals, wherein the mobile terminals include: mobile phones, tablet computers, notebook computers, etc.; fixed terminals include :Personal computer. In other optional embodiments, the cache processing method may also be applicable to embedded electronic devices configured with an Android (Android) operating system.

这里,当前内存状态可以包括:电子设备在开启过程中的内存状态,以及电子设备开启成功后的内存状态。在获取到电子设备的当前内存状态后,能够确定与该当前内存状态对应的缓存策略,并根据该缓存策略确定是否开启应用程序进程的线程局部缓存功能。Here, the current memory state may include: the memory state of the electronic device during the booting process, and the memory state after the electronic device is successfully powered on. After acquiring the current memory state of the electronic device, a cache policy corresponding to the current memory state can be determined, and whether to enable the thread local cache function of the application process is determined according to the cache policy.

在一些实施例中,该电子设备具有设定类型的操作系统,针对该操作系统,可以设置对应的内存分配器,且该内存分配器配置有线程局部缓存功能。例如,如果该设定类型的操作系统为Android操作系统,则可以使用Jemalloc作为内存分配器,对应的,该内存分配器配置有线程局部缓存功能。其中,线程局部缓存功能是针对各个应用程序进程中的各个线程设置的,在实现的过程中,如果开启了线程局部缓存功能,则可以针对各个线程配置对应的线程局部缓存区域,并基于该局部缓存区域存储各个线程的对象。In some embodiments, the electronic device has an operating system of a set type, and for the operating system, a corresponding memory allocator can be set, and the memory allocator is configured with a thread local cache function. For example, if the operating system of the set type is the Android operating system, Jemalloc can be used as the memory allocator, and correspondingly, the memory allocator is configured with a thread local cache function. Among them, the thread local cache function is set for each thread in each application process. During the implementation process, if the thread local cache function is enabled, the corresponding thread local cache area can be configured for each thread. The cache area stores objects for individual threads.

以电子设备是具有Android操作系统的电子设备为例,由于Jemalloc具有优秀的多线程并发分配性能,Android操作系统可以使用Jemalloc作为内存分配器。由于持续开启线程局部缓存功能会使得电子设备的内存消耗增加,在实现的过程中,可以获取电子设备的当前内存状态,并根据当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。Taking an electronic device having an Android operating system as an example, since Jemalloc has excellent multi-threaded concurrent allocation performance, the Android operating system can use Jemalloc as a memory allocator. Since the continuous opening of the thread local cache function will increase the memory consumption of the electronic device, during the implementation process, the current memory state of the electronic device can be obtained, and according to the cache policy corresponding to the current memory state, it is determined whether to open the thread local of the application process. cache function.

例如,可以获取电子设备的总内存,在电子设备的总内存大于或者等于第一设定内存的情况下,开启电子设备中所有应用程序进程的线程局部缓存功能。再例如,可以在电子设备的总内存小于第一设定内存的情况下,关闭电子设备中所有应用程序进程的线程局部缓存功能。For example, the total memory of the electronic device may be acquired, and the thread local cache function of all application processes in the electronic device is enabled when the total memory of the electronic device is greater than or equal to the first set memory. For another example, when the total memory of the electronic device is less than the first set memory, the thread local caching function of all application processes in the electronic device may be disabled.

本公开实施例中,可以通过获取电子设备的当前内存状态,并根据与当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。相较于相关技术中在编译期间就确定缓存策略,并按照该固定的缓存策略开启或者关闭应用程序进程的线程局部缓存功能,本公开实施例中,能够根据电子设备的内存状态灵活调整缓存策略,即根据电子设备的内存状态开启或者关闭应用程序进程的线程局部缓存功能,能够实现缓存策略的动态调整。In the embodiment of the present disclosure, it can be determined whether to enable the thread local cache function of the application process by acquiring the current memory state of the electronic device and according to the cache policy corresponding to the current memory state. Compared with the related art in which the cache policy is determined during compilation, and the thread local cache function of the application process is enabled or disabled 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, according to the memory state of the electronic device, the thread local caching function of the application process is turned on or off, so that the dynamic adjustment of the caching strategy can be realized.

在一些实施例中,所述获取所述电子设备的当前内存状态,包括:In some embodiments, the acquiring the current memory state of the electronic device includes:

在检测到开启所述电子设备的开启指令时,获取所述电子设备的总内存;Obtaining the total memory of the electronic device when detecting an opening instruction to turn on the electronic device;

所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:The determining whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state includes:

在所述总内存大于或者等于第一设定内存的情况下,开启所述电子设备中所有所述应用程序进程的线程局部缓存功能。In the case that the total memory is greater than or equal to the first set memory, the thread local caching function of all the application processes in the electronic device is enabled.

这里,开启指令可以是用户基于电子设备上的控件触发的指令,其中,控件可以是虚拟控件,也可以是物理按键。本公开实施例中,电子设备在检测到该开启指令的时候,可以启动该电子设备,并在启动该电子设备时获取电子设备的总内存。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 start-up instruction, the electronic device can be activated, and the total memory of the electronic device can be acquired when the electronic device is activated.

例如,可以通过电子设备开机的过程中启动的第一个进程读取电子设备的总内存。再例如,可以在电子设备开机的过程中,基于init()函数读取电子设备的总内存。For example, the total memory of the electronic device can be read through the first process started during the process of turning on 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 can be compared with the first set memory to obtain a first comparison result, and according to the first comparison result, it is determined whether to open the thread of the application process in the electronic device Local cache function.

例如,在第一比较结果表征电子设备的总内存大于或者等于第一设定内存的情况下,开启电子设备中所有应用程序进程的线程局部缓存功能。由于开启局部缓存功能会消耗电子设备的内存,本公开实施例中,在电子设备的总内存充足的情况下,开启所有应用程序进程的线程局部缓存功能,能够在保证电子设备的可用内存充足的基础上,保证应用程序进行的运行速度。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 caching function of all application processes in the electronic device is enabled. Since enabling the local cache function will consume the memory of the electronic device, in the embodiment of the present disclosure, when the total memory of the electronic device is sufficient, enabling the thread local cache function of all application processes can ensure that the available memory of the electronic device is sufficient. On the basis, the running speed of the application is guaranteed.

在另一些实施例中,在电子设备的总内存大于或者等于第一设定内存的情况下,可以开启电子设备中部分应用程序进程的线程局部缓存功能。例如,在电子设备的总内存大于或者等于第一设定内存的情况下,可以开启电子设备中的N个应用程序进程的线程局部缓存功能,其中,N可以根据需要设定,例如,可以是3或者5等,在此不做具体限定。In other embodiments, when the total memory of the electronic device is greater than or equal to the first set memory, the thread-local caching function of some application processes in the electronic device may be enabled. For example, when the total memory of the electronic device is greater than or equal to the first set memory, the thread local caching function of N application processes in the electronic device can be enabled, where N can be set as required, for example, it can be 3 or 5, etc., are not specifically limited here.

本公开实施例中,能够在电子设备开启过程中,就能够获取到电子设备的总内存,并对该电子设备的总内存进行评估,在确定该总内存足以保证电子设备在开启线程局部缓存功能后还能正常运行的情况下,再开启电子设备中所有或者部分应用程序进程的线程局部缓存功能,能够实现电子设备的内存占用和分配上的均衡。In the embodiment of the present disclosure, the total memory of the electronic device can be obtained during the process of turning on the electronic device, and the total memory of the electronic device can be evaluated, and after it is determined that the total memory is sufficient to ensure that the electronic device enables the thread local cache function In the case that the electronic device can still run normally, the thread local cache function of all or part of the application processes in the electronic device can be turned on, which can realize the balance of the memory occupation and allocation of the electronic device.

在一些实施例中,所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:In some embodiments, the determining whether to enable the thread-local caching function of the application process according to the caching policy corresponding to the current memory state includes:

在所述总内存小于所述第一设定内存的情况下,关闭所述电子设备中所有应用程序进程的线程局部缓存功能。In the case that 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.

在另一些实施例中,在电子设备的总内存小于第一设定内存的情况下,可以关闭电子设备中部分应用程序进程的线程局部缓存功能。例如,在电子设备的总内存小于第一设定内存的情况下,可以关闭电子设备中的K个应用程序进程的线程局部缓存功能,其中,K可以根据需要设定,例如,可以是2或者6等,在此不做具体限定。In other embodiments, when the total memory of the electronic device is less than the first set memory, the thread local caching function of some application processes in the electronic device may be disabled. For example, when the total memory of the electronic device is less than the first set memory, the thread local caching function of K application processes in the electronic device may be disabled, where K may be set as required, for example, may be 2 or 6, etc., which are not specifically limited here.

本公开实施例中,在电子设备开启过程中,就能够获取到电子设备的总内存,并对该电子设备的总内存进行评估,在确定该总内存不足以保证电子设备在开启线程局部缓存功能后还能正常运行的情况下,关闭电子设备中所有或者部分应用程序进程的线程局部缓存功能,能够实现电子设备的内存占用和分配上的均衡。In the embodiment of the present disclosure, during the process of starting the electronic device, the total memory of the electronic device can be obtained, and the total memory of the electronic device can be evaluated, and when it is determined that the total memory is not enough to ensure that the electronic device enables the thread local cache function Under the condition that the electronic device can still run normally, the thread local cache function of all or part of the application processes in the electronic device is turned off, so that the balance of the memory occupation and allocation of the electronic device can be realized.

在一些实施例中,所述方法还包括:In some embodiments, the method further includes:

在所述电子设备运行时,获取所述电子设备的当前可用内存;When the electronic device is running, obtain the currently available memory of the electronic device;

所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:The determining whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state includes:

在所述当前可用内存小于或者等于第二设定内存的情况下,维持处于启动状态下的应用程序进程的线程局部缓存功能处于开启状态,并关闭待启动的应用程序进程的线程局部缓存功能。When the currently available memory is less than or equal to the second set memory, the thread local cache function of the application process in the activated state is maintained in the enabled state, and the thread local cache function of the application process to be activated is disabled.

这里,在电子设备运行的过程中,可以获取电子设备的当前可用内存,其中,当前可用内存可以是指电子设备中当前没被占用的内存。本公开实施例中,在电子设备的使用过程中,可以获取电子设备的当前可用内存,并将当前可用内存与第二设定内存进行比较,得到第二比较结果,并根据第二比较结果确定是否启动应用程序进行的线程局部缓存功能。Here, during the operation of the electronic device, the currently available memory of the electronic device may be acquired, where the currently available memory may refer to the memory that is not currently occupied in the electronic device. In the embodiment of the present disclosure, during the use of the electronic device, the currently available memory of the electronic device can be obtained, and the currently available memory can be compared with the second set memory to obtain a second comparison result, which is determined according to the second comparison result. Whether to enable thread-local caching by the application.

例如,在第二比较结果表征当前可用内存小于或者等于第二设定内存的情况下,可以维持处于启动状态下的应用程序进程的线程局部缓存功能处于开启状态,并关闭待启动的应用程序进程的线程局部缓存功能。For example, when the second comparison result indicates that the currently available memory is less than or equal to the second set memory, the thread local cache function of the application process in the activated state can be maintained in the open state, and the application process to be activated can be closed. Thread-local caching capabilities.

本公开实施例中,在电子设备运行的过程中,可以获取电子设备的当前可用内存,并对该当前可用内存进行评估,在确定该当前可用内存不足以保证电子设备在开启线程局部缓存功能的基础上还能正常运行的情况下,可以维持处于启动状态下的应用程序进程的线程局部缓存功能处于开启状态,并关闭待启动的应用程序进程的线程局部缓存功能,能够实现电子设备的内存占用和分配上的均衡。In this embodiment of the present disclosure, during the operation of the electronic device, the currently available memory of the electronic device may be obtained, and the currently available memory may be evaluated. On the basis of the normal operation, the thread local cache function of the application process in the startup state can be kept on, and the thread local cache function of the application process to be started can be turned off, which can realize the memory usage of the electronic device. and distributional balance.

在一些实施例中,所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:In some embodiments, the determining whether to enable the thread-local caching function of the application process according to the caching policy corresponding to the current memory state includes:

在所述当前可用内存大于所述第二设定内存的情况下,维持所述电子设备中所有应用程序进程的线程局部缓存功能处于开启状态。In the case that the currently available memory is greater than the second set memory, the thread-local caching function of all application processes in the electronic device is maintained in an enabled state.

本公开实施例中,在电子设备运行的过程中,可以获取电子设备的当前可用内存,并对该当前可用内存进行评估,在确定该当前可用内存足以保证电子设备在开启线程局部缓存功能的基础上还能正常运行的情况下,可以维持电子设备中所有应用程序进程的线程局部缓存功能处于开启状态,能够实现电子设备的内存占用和分配上的均衡。In this embodiment of the present disclosure, during the running process of the electronic device, the currently available memory of the electronic device can be obtained, and the currently available memory can be evaluated, after determining that the currently available memory is sufficient to ensure that the electronic device enables the thread local cache function on the basis of Under the condition that the computer can still run normally, the thread local cache function of all application processes in the electronic device can be maintained in an open state, which can realize the balance of memory occupation and allocation of the electronic device.

在一些实施例中,以电子设备是具有Android操作系统的电子设备为例,由于Jemalloc具有优秀的多线程并发分配性能,Android操作系统可以使用Jemalloc作为内存分配器。In some embodiments, taking the electronic device having an Android operating system as an example, since Jemalloc has excellent multi-threaded concurrent allocation performance, the Android operating system can use Jemalloc as a memory allocator.

Jemalloc为了提升多线程并发分配性能使用了线程局部缓存功能,以避免多线程间同步导致的性能损耗,但是开启线程局部缓存功能会使得内存消耗增加。相关技术中,线程局部缓存功能是默认开启的,例如,Jemalloc默认在编译期间就选择了开启或关闭线程局部缓存功能,比如,可以在低内存配置的电子设备上选择关闭线程局部缓存功能以节省内存消耗。相关技术中,Jemalloc在编译脚本中定义了决定是否开启线程局部缓存功能的宏变量,Jemalloc在初始化代码中根据是否设置宏变量决定是否开启线程局部缓存功能,在实现的过程中,需要修改编译脚本来实现打开或关闭线程局部缓存功能的目的。Jemalloc uses the thread-local cache function to improve the concurrent allocation performance of multiple threads to avoid performance loss caused by synchronization between multiple threads, but enabling the thread-local cache function will increase memory consumption. In the related art, the thread local cache function is enabled by default. For example, Jemalloc chooses to enable or disable the thread local cache function by default during compilation. For example, the thread local cache function can be disabled on electronic devices with low memory configurations to save memory consumption. In the related art, Jemalloc defines a macro variable in the compilation script to determine whether to enable the thread local cache function. Jemalloc determines whether to enable the thread local cache function according to whether the macro variable is set in the initialization code. During the implementation process, the compilation script needs to be modified. To achieve the purpose of opening or closing the thread local cache function.

电子设备产品一般存在多个内存配置,比如同一款手机可以具有2G、3G或者4G的内存,在实现的过程中,具有2G和3G内存配置的手机需要关闭线程局部缓存功能以节省内存,而具有4G内存配置的手机则可以开启线程局部缓存功能获得更好的性能。Jemalloc默认在编译期间就选择了开启或关闭线程局部缓存功能,无法在具有不同内存的同一款电子设备上进行差异化配置。Electronic equipment products generally have multiple memory configurations. For example, the same mobile phone can have 2G, 3G or 4G of memory. During the implementation process, the mobile phone with 2G and 3G memory configurations needs to turn off the thread local cache function to save memory. Mobile phones with 4G memory configuration can turn on the thread local cache function for better performance. Jemalloc chooses to enable or disable the thread local cache function by default during compilation, and cannot be configured differently on the same electronic device with different memory.

且在Android操作系统中,Jemalloc无法根据电子设备在使用过程中的内存压力动态调整缓存策略,比如在内存压力大的时候对新启动的进程关闭线程局部缓存功能,在内存压力小的时候对新启动的进程开启线程局部缓存功能。And in the Android operating system, Jemalloc cannot dynamically adjust the caching strategy according to the memory pressure of the electronic device during use. The started process enables thread-local caching.

在一些实施例中,本公开实施例中的技术方案由Jemalloc,libc,Framework三个部分组成。在实现的过程中,可以修改内存分配器的用于控制线程局部缓存功能的全局变量的配置函数,由运行时只读修改为运行时可读可写。例如,可以修改Jemalloc的config模块中控制线程局部缓存功能的全局变量opt_tcache的配置函数,由运行时只读修改为运行时可读可写,并在libc的mallopt函数中新增参数选项OPT_TCACHE,用于在单线程情况下修改Jemalloc的全局变量opt_tcache,以便关闭或开启线程局部缓存功能。In some embodiments, the technical solutions in the embodiments of the present disclosure consist 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 runtime to readable and writable at runtime. For example, you can modify the configuration function of the global variable opt_tcache that controls the thread-local cache function in the config module of Jemalloc, from read-only at runtime to readable and writable at runtime, and add the parameter option OPT_TCACHE to the mallopt function of libc, using Modify the global variable opt_tcache of Jemalloc in the case of a single thread to turn off or turn on the thread local cache function.

图2是根据一示例性实施例示出的缓存处理的流程示意图二,如图2所示,该方法主要包括以下步骤:Fig. 2 is a second schematic flowchart of cache processing according to an exemplary embodiment. As shown in Fig. 2, the method mainly includes the following steps:

在步骤201中,读取电子设备的总内存。Instep 201, the total memory of the electronic device is read.

这里,可以通过电子设备开机的过程中启动的第一个进程读取电子设备的总内存。再例如,可以在电子设备开机的过程中,基于init()函数读取电子设备的总内存。Here, the total memory of the electronic device can be read through the first process started during the process of starting 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.

在步骤202中,确定电子设备的总内存是否小于第一设定内存。Instep 202, it is determined whether the total memory of the electronic device is less than the first set memory.

这里,可以根据电子设备的总内存决定打开或关闭线程局部缓存功能。例如,在获取到电子设备的总内存之后,可以将电子设备的总内存与第一设定内存进行比较,得到第一比较结果,并根据第一比较结果确定是否开启电子设备中的应用程序进程的线程局部缓存功能。比如,在总内存小于第一设定内存的情况下,关闭电子设备中所有应用程序进程的线程局部缓存功能。Here, the thread local cache function can be turned on or off 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 according to the first comparison result, it is determined whether to start the application process in the electronic device Thread-local caching capabilities. For example, when the total memory is less than the first set memory, the thread local caching function of all application processes in the electronic device is disabled.

在步骤203中,如果总内存小于第一设定内存,则设置属性ro.boot.disable_tcache为true。Instep 203, if the total memory is less than the first set memory, the property ro.boot.disable_tcache is set to true.

这里,如果需要关闭线程局部缓存功能,可以设置属性ro.boot.disable_tcache为true。Here, if you need to turn off the thread local cache function, you can set the property ro.boot.disable_tcache to true.

在步骤204中,init进程fork(派生)子进程。Instep 204, the init process forks (forks) the child process.

在步骤205中,确定init进程fork出的子进程读取到的ro.boot.disable_tcache属性是否为true。Instep 205, it is determined whether the ro.boot.disable_tcache attribute read by the child process fork from the init process is true.

在步骤206中,如果子进程读取到的ro.boot.disable_tcache属性为true,则将环境变量JEMALLOC_DISABLE_TCACHE设置为1。Instep 206, if the ro.boot.disable_tcache property read by the child process is true, the environment variable JEMALLOC_DISABLE_TCACHE is set to 1.

这里,在后续的开机过程中,如果init进程fork出的子进程读取到ro.boot.disable_tcache属性为true,则可以将环境变量JEMALLOC_DISABLE_TCACHE设置为1。Here, in the subsequent boot process, if the child process of the init process fork reads that the ro.boot.disable_tcache attribute is true, the environment variable JEMALLOC_DISABLE_TCACHE can be set to 1.

在步骤207中,如果子进程读取到的ro.boot.disable_tcache属性不为true,则子进程使用exec系统调用执行新的可执行文件时,libc会重新初始化。Instep 207, if the ro.boot.disable_tcache attribute read by the child process is not true, libc will be reinitialized when the child process uses the exec system call to execute a new executable file.

在步骤208中,确定环境变量JEMALLOC_DISABLE_TCACHE是否为1。Instep 208, it is determined whether the environment variable JEMALLOC_DISABLE_TCACHE is 1.

这里,可以在libc初始化的过程中读取JEMALLOC_DISABLE_TCACHE环境变量,并确定环境变量JEMALLOC_DISABLE_TCACHE是否为1。Here, you can read the JEMALLOC_DISABLE_TCACHE environment variable during libc initialization, and determine whether the environment variable JEMALLOC_DISABLE_TCACHE is 1.

在步骤209中,如果JEMALLOC_DISABLE_TCACHE环境变量存在且值为1,则直接将决定线程局部缓存是否打开的全局变量opt_tcache设置为false,以关闭线程局部缓存功能。Instep 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 enabled is directly set to false to disable the thread local cache function.

在一些实施例中,由于Android应用程序(Application,App)是通过zygote进程fork出来的,而zygote是通过init进程fork出来的,因此我们只要在电子设备(例如,手机)启动过程中将zygote进程的线程局部缓存功能关闭,后续所有应用程序进程的线程局部缓存都会被关闭。In some embodiments, since the Android application (Application, App) is forked through the zygote process, and the zygote is forked through the init process, we only need to fork the zygote process during the startup process of the electronic device (eg, mobile phone). The thread-local cache function of the application process is turned off, and the thread-local cache of all subsequent application processes will be turned off.

图3是根据一示例性实施例示出的缓存处理的流程示意图三,如图3所示,该方法主要包括以下步骤:FIG. 3 is a schematic diagram 3 of a cache processing flow according to an exemplary embodiment. As shown in FIG. 3 , the method mainly includes the following steps:

在步骤301中,请求zygote进程启动新应用程序进程。Instep 301, the zygote process is requested to start a new application process.

在步骤302中,基于zygote进程fork子进程。Instep 302, the child process is fork based on the zygote process.

在步骤303中,确定电子设备的当前可用内存是否小于或者等于第二设定内存。Instep 303, it is determined whether the current available memory of the electronic device is less than or equal to the second set memory.

在步骤304中,在电子设备的当前可用内存小于或者等于第二设定内存时,使用新增的mallopt选项OPT_TCACHE将决定线程局部缓存是否打开的全局变量opt_tcache设置为false,以关闭线程局部缓存功能。Instep 304, when the current available memory of the electronic device is less than or equal to the second set memory, use the newly added mallopt option OPT_TCACHE to set the global variable opt_tcache that determines whether the thread local cache is turned on to false to disable 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 enable or disable the thread local cache function of the newly started application process can 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 caching function of the newly started application process can be turned off to save memory.

在一些实施例中,在zygote进程fork出的应用程序进程处于单线程状态使,可以使用新增的mallopt选项OPT_TCACHE将决定线程局部缓存是否打开的全局变量opt_tcache设置为false,以关闭线程局部缓存功能。In some embodiments, when the application process forked from the zygote process is in a single-threaded state, the new mallopt option OPT_TCACHE can be used to set the global variable opt_tcache that determines whether the thread local cache is enabled to false to disable the thread local cache function .

在一些实施例中,可以在电子设备的开启过程中,根据电子设备的整体内存状态调整缓存策略。还是以电子设备是手机为例,如某款手机存在3G,4G内存两种配置,且两种内存配置的手机烧录的是相同的软件包,在实现的过程中,可以通过修改Jemalloc底层函数,实现手机支持运行时打开或者关闭线程局部缓存功能,并在手机开机过程中判断手机实际内存大小(总内存),并基于该实际内存大小确定是否开启线程局部缓存功能。例如,对3G手机中的所有应用程序进程关闭线程局部缓存功能,对4G手机中的所有应用程序进程打开线程局部缓存功能。In some embodiments, the cache policy may be adjusted according to the overall memory state of the electronic device during the turning-on process of the electronic device. Or take the electronic device as a mobile phone as an example. For example, a mobile phone has two configurations of 3G and 4G memory, and the mobile phones with the two memory configurations are programmed with the same software package. In the process of implementation, the underlying function of Jemalloc can be modified by , to realize that the mobile phone supports turning on or off the thread local cache function at runtime, and judges the actual memory size (total memory) of the mobile phone during the mobile phone boot process, and determines whether to enable the thread local cache function based on the actual memory size. For example, the thread local caching function is disabled for all application processes in a 3G mobile phone, and the thread local caching function is enabled for all application 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, during the operation of the mobile phone, the cache strategy can be adjusted according to the overall memory status of the mobile phone. For example, the current memory status of the mobile phone can be monitored, and the newly started application process can be monitored when the memory pressure is high. Turn off the thread local cache function, and enable the thread local cache function for the newly started application process when the memory pressure is small.

通过本公开的技术方案,一方面,解决了在电子设备运行时,如何根据内存大小或者其它状态信息决定是否开启或关闭系统所有应用程序进程的线程局部缓存功能的问题。另一方面,解决了如如何根据具体策略对部分应用程序进程开启线程局部缓存功能,同时对另外一部分应用程序进程关闭线程局部缓存功能的问题。而且采用了本公开的技术方案后,实现了内存占用和分配上的均衡,2G内存配置的电子设备能够节省60-100M内存,3G内存配置的电子设备能够节省100-300M内存。The technical solution of the present disclosure, on the one hand, solves the problem of how to determine whether to enable or disable the thread local cache function of all application processes of the system according to the memory size or other state information when the electronic device is running. On the other hand, it solves the problem of how to enable the thread local cache function for some application processes according to a specific strategy, while turning off the thread local cache function for another part of the application process. Moreover, after adopting the technical solution of the present disclosure, the balance of memory occupation and allocation is realized, 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.

图4是根据一示例性实施例示出的一种缓存处理装置框图。如图4所示,该缓存处理装置400应用于电子设备,主要包括:Fig. 4 is a block diagram of a cache processing apparatus according to an exemplary embodiment. As shown in FIG. 4 , thecache processing apparatus 400 is applied to electronic equipment, and mainly includes:

第一获取模块401,配置为获取所述电子设备的当前内存状态;The first obtainingmodule 401 is configured to obtain the current memory state of the electronic device;

确定模块402,配置为根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。The determiningmodule 402 is configured to determine whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state.

在一些实施例中,所述第一获取模块401,还配置为:In some embodiments, the first obtainingmodule 401 is further configured to:

在检测到开启所述电子设备的开启指令时,获取所述电子设备的总内存;Obtaining the total memory of the electronic device when detecting an opening instruction to turn on the electronic device;

所述确定模块,还配置为:The determining module is further configured as:

在所述总内存大于或者等于第一设定内存的情况下,开启所述电子设备中所有所述应用程序进程的线程局部缓存功能。In the case that the total memory is greater than or equal to the first set memory, the thread local caching function of all the application processes in the electronic device is enabled.

在一些实施例中,所述确定模块402,还配置为:In some embodiments, the determiningmodule 402 is further configured to:

在所述总内存小于所述第一设定内存的情况下,关闭所述电子设备中所有应用程序进程的线程局部缓存功能。In the case that 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.

在一些实施例中,所述装置400还包括:In some embodiments, theapparatus 400 further includes:

第二获取模块,配置为在所述电子设备运行时,获取所述电子设备的当前可用内存;a second acquiring module, configured to acquire the currently available memory of the electronic device when the electronic device is running;

所述确定模块,还配置为:The determining module is further configured as:

在所述当前可用内存小于或者等于第二设定内存的情况下,维持处于启动状态下的应用程序进程的线程局部缓存功能处于开启状态,并关闭待启动的应用程序进程的线程局部缓存功能。When the currently available memory is less than or equal to the second set memory, the thread local cache function of the application process in the activated state is maintained in the enabled state, and the thread local cache function of the application process to be activated is disabled.

在一些实施例中,所述确定模块402,还配置为:In some embodiments, the determiningmodule 402 is further configured to:

在所述当前可用内存大于所述第二设定内存的情况下,维持所述电子设备中所有应用程序进程的线程局部缓存功能处于开启状态。In the case that the currently available memory is greater than the second set memory, the thread-local caching function of all application processes in the electronic device is maintained in an enabled state.

关于上述实施例中的装置,其中各个模块执行操作的具体方式已经在有关该方法的实施例中进行了详细描述,此处将不做详细阐述说明。Regarding the apparatus in the above-mentioned embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment of the method, and will not be described in detail here.

图5是根据一示例性实施例示出的一种缓存处理装置1200的框图。例如,装置1200可以是移动电话,计算机,数字广播终端,消息收发设备,游戏控制台,平板设备,医疗设备,健身设备,个人数字助理等。FIG. 5 is a block diagram of acache processing apparatus 1200 according to an exemplary embodiment. For example,apparatus 1200 may be a mobile phone, computer, digital broadcast terminal, messaging device, game console, tablet device, medical device, fitness device, personal digital assistant, and the like.

参照图5,装置1200可以包括以下一个或多个组件:处理组件1202,存储器1204,电源组件1206,多媒体组件1208,音频组件1210,输入/输出(I/O)接口1212,传感器组件1214,以及通信组件1216。5,apparatus 1200 may include one or more of the following components:processing component 1202,memory 1204,power supply component 1206,multimedia component 1208,audio component 1210, input/output (I/O)interface 1212,sensor component 1214, andCommunication component 1216.

处理组件1202通常控制装置1200的整体操作,诸如与显示,电话呼叫,数据通信,相机操作和记录操作相关联的操作。处理组件1202可以包括一个或多个处理器1220来执行指令,以完成上述的方法的全部或部分步骤。此外,处理组件1202可以包括一个或多个模块,便于处理组件1202和其他组件之间的交互。例如,处理组件1202可以包括多媒体模块,以方便多媒体组件1208和处理组件1202之间的交互。Theprocessing component 1202 generally controls the overall operation of thedevice 1200, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. Theprocessing component 1202 can include one ormore processors 1220 to execute instructions to perform all or some of the steps of the above-described methods. Additionally,processing component 1202 may include one or more modules that facilitate interaction betweenprocessing component 1202 and other components. For example,processing component 1202 may include a multimedia module to facilitate interaction betweenmultimedia component 1208 andprocessing component 1202.

存储器1204被配置为存储各种类型的数据以支持在设备1200的操作。这些数据的示例包括用于在装置1200上操作的任何应用程序或方法的指令,联系人数据,电话簿数据,消息,图片,视频等。存储器1204可以由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。Memory 1204 is configured to store various types of data to support operation atdevice 1200 . Examples of such data include instructions for any application or method operating ondevice 1200, contact data, phonebook data, messages, pictures, videos, and the like.Memory 1204 may be implemented by any type of volatile or nonvolatile storage device or 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 or Optical Disk.

电源组件1206为装置1200的各种组件提供电力。电源组件1206可以包括电源管理系统,一个或多个电源,及其他与为装置1200生成、管理和分配电力相关联的组件。Power component 1206 provides power to various components ofdevice 1200.Power supply components 1206 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power todevice 1200 .

多媒体组件1208包括在所述装置1200和用户之间的提供一个输出接口的屏幕。在一些实施例中,屏幕可以包括液晶显示器(LCD)和触摸面板(TP)。如果屏幕包括触摸面板,屏幕可以被实现为触摸屏,以接收来自用户的输入信号。触摸面板包括一个或多个触摸传感器以感测触摸、滑动和触摸面板上的手势。所述触摸传感器可以不仅感测触摸或滑动动作的边界,而且还检测与所述触摸或滑动操作相关的持续时间和压力。在一些实施例中,多媒体组件1208包括一个前置摄像头和/或后置摄像头。当设备1200处于操作模式,如拍摄模式或视频模式时,前置摄像头和/或后置摄像头可以接收外部的多媒体数据。每个前置摄像头和后置摄像头可以是一个固定的光学透镜系统或具有焦距和光学变焦能力。Multimedia component 1208 includes a screen that provides an output interface between thedevice 1200 and the 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 input signals from a user. The touch panel includes one or more touch sensors to sense touch, swipe, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or swipe action, but also detect the duration and pressure associated with the touch or swipe action. In some embodiments, themultimedia component 1208 includes a front-facing camera and/or a rear-facing camera. When thedevice 1200 is in an operation mode, such as a shooting mode or a video mode, the front camera and/or the rear camera may receive external multimedia data. Each of the front and rear cameras can be a fixed optical lens system or have focal length and optical zoom capability.

音频组件1210被配置为输出和/或输入音频信号。例如,音频组件1210包括一个麦克风(MIC),当装置1200处于操作模式,如呼叫模式、记录模式和语音识别模式时,麦克风被配置为接收外部音频信号。所接收的音频信号可以被进一步存储在存储器1204或经由通信组件1216发送。在一些实施例中,音频组件1210还包括一个扬声器,用于输出音频信号。Audio component 1210 is configured to output and/or input audio signals. For example,audio component 1210 includes a microphone (MIC) that is configured to receive external audio signals whendevice 1200 is in operating modes, such as call mode, recording mode, and voice recognition mode. The received audio signal may be further stored inmemory 1204 or transmitted viacommunication component 1216 . In some embodiments,audio component 1210 also includes a speaker for outputting audio signals.

I/O接口1212为处理组件1202和外围接口模块之间提供接口,上述外围接口模块可以是键盘,点击轮,按钮等。这些按钮可包括但不限于:主页按钮、音量按钮、启动按钮和锁定按钮。The I/O interface 1212 provides an interface between theprocessing component 1202 and a peripheral interface module, which may be a keyboard, a click wheel, a button, or the like. These buttons may include, but are not limited to: home button, volume buttons, start button, and lock button.

传感器组件1214包括一个或多个传感器,用于为装置1200提供各个方面的状态评估。例如,传感器组件1214可以检测到设备1200的打开/关闭状态,组件的相对定位,例如所述组件为装置1200的显示器和小键盘,传感器组件1214还可以检测装置1200或装置1200一个组件的位置改变,用户与装置1200接触的存在或不存在,装置1200方位或加速/减速和装置1200的温度变化。传感器组件1214可以包括接近传感器,被配置用来在没有任何的物理接触时检测附近物体的存在。传感器组件1214还可以包括光传感器,如CMOS或CCD图像传感器,用于在成像应用中使用。在一些实施例中,该传感器组件1214还可以包括加速度传感器,陀螺仪传感器,磁传感器,压力传感器或温度传感器。Sensor assembly 1214 includes one or more sensors for providing status assessment of various aspects ofdevice 1200 . For example, thesensor assembly 1214 can detect the on/off state of thedevice 1200, the relative positioning of components, such as the display and keypad of thedevice 1200, and thesensor assembly 1214 can also detect a change in the position of thedevice 1200 or a component of thedevice 1200 , the presence or absence of user contact with thedevice 1200 , the orientation or acceleration/deceleration of thedevice 1200 and the temperature change of thedevice 1200 .Sensor assembly 1214 may include a proximity sensor configured to detect the presence of nearby objects in the absence of any physical contact.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, thesensor assembly 1214 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

通信组件1216被配置为便于装置1200和其他设备之间有线或无线方式的通信。装置1200可以接入基于通信标准的无线网络,如WiFi,2G或3G,或它们的组合。在一个示例性实施例中,通信组件1216经由广播信道接收来自外部广播管理系统的广播信号或广播相关信息。在一个示例性实施例中,所述通信组件1216还包括近场通信(NFC)模块,以促进短程通信。例如,在NFC模块可基于射频识别(RFID)技术,红外数据协会(IrDA)技术,超宽带(UWB)技术,蓝牙(BT)技术和其他技术来实现。Communication component 1216 is configured to facilitate wired or wireless communication betweenapparatus 1200 and other devices.Device 1200 may access wireless networks based on communication standards, such as WiFi, 2G or 3G, or a combination thereof. In one exemplary embodiment, thecommunication component 1216 receives broadcast signals or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, thecommunication component 1216 also includes a near field communication (NFC) module to facilitate short-range communication. 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.

在示例性实施例中,装置1200可以被一个或多个应用专用集成电路(ASIC)、数字信号处理器(DSP)、数字信号处理设备(DSPD)、可编程逻辑器件(PLD)、现场可编程门阵列(FPGA)、控制器、微控制器、微处理器或其他电子元件实现,用于执行上述方法。In an exemplary embodiment,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 A gate array (FPGA), controller, microcontroller, microprocessor or other electronic component implementation for performing the above method.

在示例性实施例中,还提供了一种包括指令的非临时性计算机可读存储介质,例如包括指令的存储器1204,上述指令可由装置1200的处理器1220执行以完成上述方法。例如,所述非临时性计算机可读存储介质可以是ROM、随机存取存储器(RAM)、CD-ROM、磁带、软盘和光数据存储设备等。In an exemplary embodiment, there is also provided a non-transitory computer-readable storage medium including instructions, such as amemory 1204 including instructions, executable by theprocessor 1220 of theapparatus 1200 to perform the method described above. For example, the non-transitory computer-readable storage medium may be ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, optical data storage device, and the like.

一种非临时性计算机可读存储介质,当所述存储介质中的指令由缓存处理装置的处理器执行时,使得缓存处理装置能够执行一种缓存处理方法,所述方法包括:A non-transitory computer-readable storage medium, when an instruction in the storage medium is executed by a processor of a cache processing device, the cache processing device can execute a cache processing method, the method comprising:

获取所述电子设备的当前内存状态;obtaining the current memory state of the electronic device;

根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。According to the cache policy corresponding to the current memory state, it is determined whether to enable the thread local cache function of the application process.

本领域技术人员在考虑说明书及实践这里公开的发明后,将容易想到本公开的其它实施方案。本公开旨在涵盖本公开的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本公开的一般性原理并包括本公开未公开的本技术领域中的公知常识或惯用技术手段。说明书和实施例仅被视为示例性的,本公开的真正范围和精神由下面的权利要求指出。Other embodiments of the present disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common general knowledge or techniques in the technical field not disclosed by this disclosure . The specification and examples are to be regarded as exemplary only, with the true scope and spirit of the disclosure being indicated by the following claims.

应当理解的是,本公开并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本公开的范围仅由所附的权利要求来限制。It is to be understood that the present disclosure is not limited to the precise structures described above and illustrated in the accompanying 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)

Translated fromChinese
1.一种缓存处理方法,其特征在于,应用于电子设备,包括:1. a cache processing method, is characterized in that, is applied to electronic equipment, comprises:获取所述电子设备的当前内存状态;obtaining the current memory state of the electronic device;根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。According to the cache policy corresponding to the current memory state, it is determined whether to enable the thread local cache function of the application process.2.根据权利要求1所述的方法,其特征在于,所述获取所述电子设备的当前内存状态,包括:2. The method according to claim 1, wherein the acquiring the current memory state of the electronic device comprises:在检测到开启所述电子设备的开启指令时,获取所述电子设备的总内存;Obtaining the total memory of the electronic device when detecting an opening instruction to turn on the electronic device;所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:The determining whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state includes:在所述总内存大于或者等于第一设定内存的情况下,开启所述电子设备中所有所述应用程序进程的线程局部缓存功能。In the case that the total memory is greater than or equal to the first set memory, the thread local caching function of all the application processes in the electronic device is enabled.3.根据权利要求2所述的方法,其特征在于,所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:3. The method according to claim 2, wherein the determining whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state, comprising:在所述总内存小于所述第一设定内存的情况下,关闭所述电子设备中所有应用程序进程的线程局部缓存功能。In the case that 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.4.根据权利要求1所述的方法,其特征在于,所述方法还包括:4. The method according to claim 1, wherein the method further comprises:在所述电子设备运行时,获取所述电子设备的当前可用内存;When the electronic device is running, obtain the currently available memory of the electronic device;所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:The determining whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state includes:在所述当前可用内存小于或者等于第二设定内存的情况下,维持处于启动状态下的应用程序进程的线程局部缓存功能处于开启状态,并关闭待启动的应用程序进程的线程局部缓存功能。When the currently available memory is less than or equal to the second set memory, the thread local cache function of the application process in the activated state is maintained in the enabled state, and the thread local cache function of the application process to be activated is disabled.5.根据权利要求4所述的方法,其特征在于,所述根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能,包括:5. The method according to claim 4, wherein the determining whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state, comprising:在所述当前可用内存大于所述第二设定内存的情况下,维持所述电子设备中所有应用程序进程的线程局部缓存功能处于开启状态。In the case that the currently available memory is greater than the second set memory, the thread-local caching function of all application processes in the electronic device is maintained in an enabled state.6.一种缓存处理装置,其特征在于,应用于电子设备,包括:6. A cache processing device, characterized in that, applied to electronic equipment, comprising:第一获取模块,配置为获取所述电子设备的当前内存状态;a first acquisition module, configured to acquire the current memory state of the electronic device;确定模块,配置为根据与所述当前内存状态对应的缓存策略,确定是否开启应用程序进程的线程局部缓存功能。The determining module is configured to determine whether to enable the thread local cache function of the application process according to the cache policy corresponding to the current memory state.7.根据权利要求6所述的装置,其特征在于,所述第一获取模块,还配置为:7. The device according to claim 6, wherein the first acquisition module is further configured to:在检测到开启所述电子设备的开启指令时,获取所述电子设备的总内存;Obtaining the total memory of the electronic device when detecting an opening instruction to turn on the electronic device;所述确定模块,还配置为:The determining module is further configured as:在所述总内存大于或者等于第一设定内存的情况下,开启所述电子设备中所有所述应用程序进程的线程局部缓存功能。In the case that the total memory is greater than or equal to the first set memory, the thread local caching function of all the application processes in the electronic device is enabled.8.根据权利要求7所述的装置,其特征在于,所述确定模块,还配置为:8. The apparatus according to claim 7, wherein the determining module is further configured to:在所述总内存小于所述第一设定内存的情况下,关闭所述电子设备中所有应用程序进程的线程局部缓存功能。In the case that 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.9.根据权利要求6所述的装置,其特征在于,所述装置还包括:9. The apparatus of claim 6, wherein the apparatus further comprises:第二获取模块,配置为在所述电子设备运行时,获取所述电子设备的当前可用内存;a second acquiring module, configured to acquire the currently available memory of the electronic device when the electronic device is running;所述确定模块,还配置为:The determining module is further configured as:在所述可用内存小于或者等于第二设定内存的情况下,维持处于启动状态下的应用程序进程的线程局部缓存功能处于开启状态,并关闭待启动的应用程序进程的线程局部缓存功能。When the available memory is less than or equal to the second set memory, the thread local cache function of the application process in the activated state is maintained in the enabled state, and the thread local cache function of the application process to be activated is disabled.10.根据权利要求9所述的装置,其特征在于,所述确定模块,还配置为:10. The device according to claim 9, wherein the determining module is further configured to:在所述当前可用内存大于所述第二设定内存的情况下,维持所述电子设备中所有应用程序进程的线程局部缓存功能处于开启状态。In the case that the currently available memory is greater than the second set memory, the thread-local caching function of all application processes in the electronic device is maintained in an enabled state.11.一种缓存处理装置,其特征在于,包括:11. A cache processing device, comprising:处理器;processor;配置为存储处理器可执行指令的存储器;a memory configured to store processor executable instructions;其中,所述处理器配置为:执行时实现上述权利要求1至5中任一种缓存处理方法中的步骤。Wherein, the processor is configured to: implement the steps in any one of the above-mentioned cache processing methods in claims 1 to 5 during execution.12.一种非临时性计算机可读存储介质,当所述存储介质中的指令由缓存处理装置的处理器执行时,使得所述装置能够执行上述权利要求1至5中任一种缓存处理方法中的步骤。12. A non-transitory computer-readable storage medium, when the instructions in the storage medium are executed by a processor of a cache processing apparatus, the apparatus enables the apparatus to execute any one of the above cache processing methods in claims 1 to 5 steps in .
CN202011290406.XA2020-11-172020-11-17Cache processing method and device and storage mediumPendingCN114510342A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202011290406.XACN114510342A (en)2020-11-172020-11-17Cache processing method and device and storage medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202011290406.XACN114510342A (en)2020-11-172020-11-17Cache processing method and device and storage medium

Publications (1)

Publication NumberPublication Date
CN114510342Atrue CN114510342A (en)2022-05-17

Family

ID=81546585

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202011290406.XAPendingCN114510342A (en)2020-11-172020-11-17Cache processing method and device and storage medium

Country Status (1)

CountryLink
CN (1)CN114510342A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN115033306A (en)*2022-06-292022-09-09维沃移动通信有限公司Application exit method and device
CN116301578A (en)*2022-12-022023-06-23平安银行股份有限公司Parameter configuration method, device, medium and equipment for cache function
WO2024032430A1 (en)*2022-08-092024-02-15华为技术有限公司Memory management method and electronic device

Cited By (5)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN115033306A (en)*2022-06-292022-09-09维沃移动通信有限公司Application exit method and device
CN115033306B (en)*2022-06-292024-05-24维沃移动通信有限公司 Application exit method and device
WO2024032430A1 (en)*2022-08-092024-02-15华为技术有限公司Memory management method and electronic device
CN117632446A (en)*2022-08-092024-03-01华为技术有限公司 Methods and electronic devices for managing memory
CN116301578A (en)*2022-12-022023-06-23平安银行股份有限公司Parameter configuration method, device, medium and equipment for cache function

Similar Documents

PublicationPublication DateTitle
JP7498779B2 (en) Screen display method and electronic device
JP7497943B2 (en) Device with foldable screen, touch control method for foldable screen device, computer-readable storage medium and computer program
CN105955765B (en)Application preloading method and device
CN105955766B (en) Application preloading method and device
JP6355735B2 (en) Method and apparatus for initiating an energy saving mode
WO2015172518A1 (en)Method and device for processing application program
WO2017152621A1 (en)Temperature control method and device
CN109254849B (en) Application program running method and device
WO2016188060A1 (en)Method and apparatus for processing application program package
CN114510342A (en)Cache processing method and device and storage medium
CN107608561A (en)Touch-screen control method and device
RU2626089C2 (en)Method and device for subject application download
CN105807894B (en)Using the treating method and apparatus for holding lock
WO2016065820A1 (en)Memory optimization method and device
CN105930213A (en)Application running method and apparatus
US9678868B2 (en)Method and device for optimizing memory
CN105930151A (en)Application compilation method and apparatus as well as terminal
WO2017173765A1 (en)Method and device for launching application interface
CN108958911A (en)The control method and device of process
CN107390936A (en)Trigger action processing method, device and computer-readable recording medium
CN108874450B (en)Method and device for waking up voice assistant
CN107135362A (en) Image quality processing method and device of split TV and split TV
CN112905096B (en) Display control method, device, terminal equipment and storage medium
CN106502740B (en) Application installation method and device
CN107371222B (en)Virtual card disabling method and device

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination

[8]ページ先頭

©2009-2025 Movatter.jp