技术领域Technical Field
本申请涉及电子设备技术领域,具体涉及一种内存回收方法、装置、存储介质及电子设备。The present application relates to the technical field of electronic equipment, and in particular to a memory recovery method, device, storage medium and electronic equipment.
背景技术Background Art
随着技术的发展,电子设备中安装的各类应用程序越来越多,例如视频类应用、游戏类应用以及即时通讯类应用等。这使得电子设备经常需要在前台和后台运行很多个应用程序,容易在用户交互场景中出现卡顿现象。With the development of technology, more and more applications are installed in electronic devices, such as video applications, game applications, and instant messaging applications, etc. This requires electronic devices to often run many applications in the foreground and background, which easily causes freezes in user interaction scenarios.
发明内容Summary of the invention
本申请实施例提供一种内存回收方法、装置、存储介质及电子设备,能够减少交互场景下的卡顿现象。Embodiments of the present application provide a memory recovery method, device, storage medium, and electronic device, which can reduce the jamming phenomenon in interactive scenarios.
第一方面,本申请实施例提供一种内存回收方法,包括:In a first aspect, an embodiment of the present application provides a memory recovery method, comprising:
当接收到线程发送的内存分配请求时,确定当前的空闲内存量;When receiving a memory allocation request sent by a thread, determine the current amount of free memory;
若所述空闲内存量小于预设阈值,则确定所述线程的类型,其中,将线程划分为优先级不同的多类线程,其中,第一类线程具有最高优先级,所述第一类线程为执行用户交互事件中相关任务的线程;If the amount of free memory is less than a preset threshold, determining the type of the thread, wherein the threads are divided into a plurality of types of threads with different priorities, wherein a first type of thread has a highest priority, and the first type of thread is a thread that executes a task related to a user interaction event;
获取与所述线程的类型对应的内存回收比例,并按照所述内存回收比例对已分配内存空间中的内存页进行回收,其中,所述内存回收比例用于表征多种内存回收对象之间的比例,不同种类的内存回收对象的回收效率不同,线程的优先级越高,则对应的内存回收比例中回收效率高的内存回收对象的占比越大。Obtain a memory recovery ratio corresponding to the type of the thread, and recycle memory pages in the allocated memory space according to the memory recovery ratio, wherein the memory recovery ratio is used to characterize the ratio between multiple memory recovery objects, and different types of memory recovery objects have different recovery efficiencies. The higher the thread priority, the greater the proportion of memory recovery objects with high recovery efficiency in the corresponding memory recovery ratio.
第二方面,本申请实施例还提供一种内存回收装置,包括:In a second aspect, an embodiment of the present application further provides a memory recovery device, comprising:
内存检测模块,用于当接收到线程发送的内存分配请求时,确定当前的空闲内存量;A memory detection module, used to determine the current amount of free memory when receiving a memory allocation request sent by a thread;
线程识别模块,用于若所述空闲内存量小于预设阈值,则确定所述线程的类型,其中,将线程划分为优先级不同的多类线程,其中,第一类线程具有最高优先级,所述第一类线程为执行用户交互事件中相关任务的线程;a thread identification module, configured to determine the type of the thread if the amount of free memory is less than a preset threshold, wherein the threads are divided into a plurality of classes of threads with different priorities, wherein a first class of threads has the highest priority, and the first class of threads are threads that execute related tasks in a user interaction event;
内存回收模块,用于获取与所述线程的类型对应的内存回收比例,并按照所述内存回收比例对已分配内存空间中的内存页进行回收,其中,所述内存回收比例用于表征多种内存回收对象之间的比例,不同种类的内存回收对象的回收效率不同,线程的优先级越高,则对应的内存回收比例中回收效率高的内存回收对象的占比越大。A memory recovery module is used to obtain a memory recovery ratio corresponding to the type of the thread, and to recycle memory pages in the allocated memory space according to the memory recovery ratio, wherein the memory recovery ratio is used to characterize the ratio between multiple memory recovery objects, and different types of memory recovery objects have different recovery efficiencies. The higher the priority of the thread, the greater the proportion of memory recovery objects with high recovery efficiency in the corresponding memory recovery ratio.
第三方面,本申请实施例还提供一种存储介质,其上存储有计算机程序,当所述计算机程序在计算机上运行时,使得所述计算机执行如本申请任一实施例提供的内存回收方法。In a third aspect, an embodiment of the present application further provides a storage medium on which a computer program is stored. When the computer program is run on a computer, the computer executes a memory recovery method provided in any embodiment of the present application.
第四方面,本申请实施例还提供一种电子设备,包括处理器和存储器,所述存储器有计算机程序,所述处理器通过调用所述计算机程序,用于执行如本申请任一实施例提供的内存回收方法。In a fourth aspect, an embodiment of the present application further provides an electronic device, comprising a processor and a memory, wherein the memory has a computer program, and the processor is used to execute a memory recovery method provided in any embodiment of the present application by calling the computer program.
本申请实施例提供的技术方案,在接收到线程发送的内存分配请求时,先确定当前的空闲内存量,如果空闲内存量小于预设阈值,则要先进行内存回收,接下来对线程的类型进行识别,在内存回收时,根据请求内存的线程的类型的不同,采用不同的内存回收比例进行内存回收,该内存回收比例用于表征多种内存回收对象之间的比例,由于不同种类的内存回收对象的回收效率不同,因此若内存回收比例不同,则整体的回收效率也不相同。其中,第一类线程为执行用户交互事件中相关任务的线程,具有最高优先级,也就是说,第一类线程对应的内存回收比例中回收效率高的内存回收对象的占比在所有类别的线程中为最大占比,因此,对于第一类线程来说,在全部线程中具有最高效率的内存回收机制,可以尽快完成内存回收,提高了第一类线程的内存分配效率,避免第一类线程因为不能及时得到内存而导致出现交互场景下的卡顿现象,提升用户体验。The technical solution provided by the embodiment of the present application, when receiving a memory allocation request sent by a thread, first determines the current amount of free memory. If the amount of free memory is less than a preset threshold, memory recovery must be performed first, and then the type of thread is identified. When memory is recovered, different memory recovery ratios are used for memory recovery according to the type of thread requesting memory. The memory recovery ratio is used to characterize the ratio between multiple memory recovery objects. Since the recovery efficiency of different types of memory recovery objects is different, if the memory recovery ratio is different, the overall recovery efficiency is also different. Among them, the first type of thread is the thread that executes the relevant tasks in the user interaction event, and has the highest priority. That is to say, the proportion of memory recovery objects with high recovery efficiency in the memory recovery ratio corresponding to the first type of thread is the largest proportion among all types of threads. Therefore, for the first type of thread, the memory recovery mechanism with the highest efficiency among all threads can complete memory recovery as soon as possible, improve the memory allocation efficiency of the first type of thread, avoid the jamming phenomenon in the interactive scene caused by the failure of the first type of thread to obtain memory in time, and improve the user experience.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
图1为本申请实施例提供的内存回收方法的第一种流程示意图。FIG1 is a schematic diagram of a first flow chart of a memory recycling method provided in an embodiment of the present application.
图2为本申请实施例提供的内存回收方法的第二种流程示意图。FIG. 2 is a schematic diagram of a second flow chart of the memory recycling method provided in an embodiment of the present application.
图3为本申请实施例提供的内存回收装置的结构示意图。FIG3 is a schematic diagram of the structure of a memory recovery device provided in an embodiment of the present application.
图4为本申请实施例提供的电子设备的第一种结构示意图。FIG. 4 is a schematic diagram of a first structure of an electronic device provided in an embodiment of the present application.
图5为本申请实施例提供的电子设备的第二种结构示意图。FIG5 is a schematic diagram of a second structure of an electronic device provided in an embodiment of the present application.
具体实施方式DETAILED DESCRIPTION
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述。显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域技术人员在没有付出创造性劳动前提下所获得的所有其他实施例,都属于本申请的保护范围。The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
在本文中提及“实施例”意味着,结合实施例描述的特定特征、结构或特性可以包含在本申请的至少一个实施例中。在说明书中的各个位置出现该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本文所描述的实施例可以与其它实施例相结合。Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
本申请实施例提供一种内存回收方法,该内存回收方法的执行主体可以是本申请实施例提供的内存回收装置,或者集成了该内存回收装置的电子设备,其中该内存回收装置可以采用硬件或者软件的方式实现。其中,电子设备可以是智能手机、平板电脑、掌上电脑、笔记本电脑、或者台式电脑等设备。The embodiment of the present application provides a memory recovery method, and the execution subject of the memory recovery method can be a memory recovery device provided in the embodiment of the present application, or an electronic device integrated with the memory recovery device, wherein the memory recovery device can be implemented in hardware or software. The electronic device can be a smart phone, a tablet computer, a PDA, a laptop computer, or a desktop computer.
请参阅图1,图1为本申请实施例提供的内存回收方法的第一种流程示意图。本申请实施例提供的内存回收方法的具体流程可以如下:Please refer to Figure 1, which is a schematic diagram of a first process flow of a memory recovery method provided in an embodiment of the present application. The specific process flow of the memory recovery method provided in an embodiment of the present application may be as follows:
在101中,当接收到线程发送的内存分配请求时,确定当前的空闲内存量。In 101, when a memory allocation request sent by a thread is received, the current amount of free memory is determined.
本申请实施例中,电子设备的操作系统可以是基于linux内核的系统,例如,安卓操作系统等。电子设备的系统进程和应用程序的进程的运行,都需要系统内核为其分配内存空间。并且随着系统的运行情况,内核不断地进行着内存的回收与分配等。In the embodiment of the present application, the operating system of the electronic device may be a system based on the Linux kernel, such as an Android operating system. The operation of the system process and the application process of the electronic device requires the system kernel to allocate memory space for them. And as the system runs, the kernel continuously recycles and allocates memory.
线程是进程的一条执行路径,是程序执行时的最小单位,也是内存分配的基本单位。一个进程可以有多个线程,但至少有一个线程。A thread is an execution path of a process, the smallest unit of program execution, and the basic unit of memory allocation. A process can have multiple threads, but at least one thread.
对于内核来说,在进行资源调度时,比如CPU调度,都是具体到某个线程的。进程内有一个主线程,它也会创建出很多子线程来协助工作。比如一个内容交互应用程序的进程,它会创建一个主线程来执行代码,执行途中也会创建其它子线程来协助运行各部分的任务代码。For the kernel, when scheduling resources, such as CPU scheduling, it is specific to a certain thread. There is a main thread in the process, and it will also create many sub-threads to assist in the work. For example, a process of a content interactive application will create a main thread to execute code, and during the execution, it will also create other sub-threads to assist in running the task code of each part.
本申请实施例中,进程有任务需要执行时,会创建一个新的线程来执行该任务,而线程需要内核为之分配一定量的内存空间供其运行。因此,线程在执行任务前,会向内核发送内存分配请求。In the embodiment of the present application, when a process has a task to execute, a new thread will be created to execute the task, and the thread requires the kernel to allocate a certain amount of memory space for it to run. Therefore, before executing the task, the thread will send a memory allocation request to the kernel.
内核在接收到内存分配请求时,先确定当前的空闲内存量。When the kernel receives a memory allocation request, it first determines the current amount of free memory.
其中,Linux内核使用三个内存水线来标记系统空闲内存量的状态,按照从小至大的顺序,依次分别为:high水线、low水线和min水线。当系统空闲内存量低于low水线时,系统会唤醒内存回收进程kswapd进行内存回收,直到空闲内存量不低于high水线为止。内存回收进程kswapd进行内存回收时,内存消耗的速度会相对变缓,但是内存分配也会进入慢速分配路径(slowpath),意味着内存分配效率也会变慢。需要说明的是,这里的慢速分配路径是一种抽象的概念,是指系统由于需要在后台进行内存回收而对线程的内存分配效率变慢。其中,上述low水线为本申请实施例中的预设阈值。Among them, the Linux kernel uses three memory watermarks to mark the state of the system's free memory, in order from small to large, respectively: high watermark, low watermark and min watermark. When the system's free memory is lower than the low watermark, the system will wake up the memory recovery process kswapd to recycle memory until the free memory is no lower than the high watermark. When the memory recovery process kswapd recycles memory, the speed of memory consumption will be relatively slow, but the memory allocation will also enter the slow allocation path (slowpath), which means that the memory allocation efficiency will also be slower. It should be noted that the slow allocation path here is an abstract concept, which means that the system slows down the memory allocation efficiency of the thread due to the need to recycle memory in the background. Among them, the above-mentioned low watermark is a preset threshold in the embodiment of the present application.
此外,内核主要通过回收匿名页和文件页实现内存回收。回收匿名页和文件页的策略不一样,回收匿名页一般是将其压缩后存放在RAM中,由于该过程需要使用CPU将其压缩,使用时再解压缩,回收过程需要消耗一定的CPU时间,相对较慢。回收文件页分两种,如果文件内容没有被修改过,直接将文件页内容丢弃;如果文件内容被修改了,需要将内容写回磁盘再将文件页丢弃,再次需要时重新从磁盘读取。一般而言,很多文件页是没有被修改的,回收过程相对较快。常规的回收手段,一般会倾向于回收匿名页,保留文件页,以降低再次重新读磁盘数据IO带来的代价,但是这种回收机制下,在一些场景下,可能会因为内存回收较慢可能导致卡顿,影响用户体验。In addition, the kernel mainly implements memory recycling by recycling anonymous pages and file pages. The strategies for recycling anonymous pages and file pages are different. Recycling anonymous pages generally compresses them and stores them in RAM. Since this process requires the CPU to compress them and then decompress them when they are used, the recycling process consumes a certain amount of CPU time and is relatively slow. There are two ways to recycle file pages. If the file content has not been modified, the file page content is directly discarded; if the file content has been modified, the content needs to be written back to the disk and the file page is discarded. When it is needed again, it needs to be read from the disk again. Generally speaking, many file pages have not been modified, and the recycling process is relatively fast. Conventional recycling methods generally tend to recycle anonymous pages and retain file pages to reduce the cost of re-reading disk data IO. However, under this recycling mechanism, in some scenarios, slow memory recycling may cause freezes and affect user experience.
为了改善这种缺陷,本申请实施例中,从全部线程中将那些与用户体验相关的线程标记出来,对于这些用户体验相关的线程来说,采取一种高效的内存回收方式,例如,全部通过回收内存页来进行内存回收,提升内存回收速度,尽快回收到需要的内存,缩短慢速路径的时间。In order to improve this defect, in an embodiment of the present application, threads related to user experience are marked out from all threads. For these threads related to user experience, an efficient memory recovery method is adopted. For example, all memory recovery is performed by recycling memory pages, thereby improving the memory recovery speed, recovering the required memory as soon as possible, and shortening the time of the slow path.
在102中,若空闲内存量小于预设阈值,则确定线程的类型,其中,将线程划分为优先级不同的多类线程,其中,第一类线程具有最高优先级,第一类线程为执行用户交互事件中相关任务的线程。In 102, if the amount of free memory is less than a preset threshold, the type of thread is determined, wherein the threads are divided into multiple types of threads with different priorities, wherein the first type of thread has the highest priority, and the first type of thread is a thread that executes related tasks in the user interaction event.
执行用户交互事件中相关任务的线程是否能够流畅运行决定着是否会在用户交互事件中产生用户可感知的卡顿,故本申请实施例中,确定出执行用户交互事件中相关任务的线程,并将这些与用户体验紧密相关的线程记为ux(user experience,用户体验)线程,即第一类线程。本申请实施例中,将除ux线程之外的线程记为第二类线程。第二类线程的运行情况一般不会影响用户体验,或者对用户体验影响较小。Whether the thread that executes the relevant tasks in the user interaction event can run smoothly determines whether the user-perceivable lag will occur in the user interaction event. Therefore, in the embodiment of the present application, the thread that executes the relevant tasks in the user interaction event is determined, and these threads that are closely related to the user experience are recorded as ux (user experience) threads, that is, first-class threads. In the embodiment of the present application, threads other than ux threads are recorded as second-class threads. The operation of the second-class threads generally does not affect the user experience, or has little impact on the user experience.
其中,电子设备的系统架构至少包括应用框架(framework)层和内核(kernel)层,本申请实施例,从应用框架层和内核层的角度对ux线程进行识别和标记,例如,应用框架层为一些直接执行用户交互事件中相关任务的线程添加预设标签,以将这些线程标记为静态ux线程,内核层将一些间接地影响到用户交互事件中相关任务执行的线程标记为动态ux线程。Among them, the system architecture of the electronic device includes at least an application framework layer and a kernel layer. In an embodiment of the present application, ux threads are identified and marked from the perspective of the application framework layer and the kernel layer. For example, the application framework layer adds preset labels to some threads that directly execute related tasks in user interaction events to mark these threads as static ux threads, and the kernel layer marks some threads that indirectly affect the execution of related tasks in user interaction events as dynamic ux threads.
本申请实施例中的进程包括系统级进程和应用级进程。由于产生用户可感知的界面的卡顿的场景多是相对于运行在前台的进程来说的。因此,本申请实施例的方案中,“确定出执行用户交互事件中相关任务的线程”包括:在检测到有进程切换到前台运行时,确定前台进程;从该前台进程的线程中确定出用于执行用户交互事件中相关任务的线程,作为目标线程。The processes in the embodiments of the present application include system-level processes and application-level processes. Since the scenarios that cause user-perceivable interface freezes are mostly relative to the process running in the foreground. Therefore, in the scheme of the embodiments of the present application, "determining the thread that executes the relevant tasks in the user interaction event" includes: when it is detected that a process switches to the foreground, determining the foreground process; determining the thread used to execute the relevant tasks in the user interaction event from the thread of the foreground process as the target thread.
例如,在一实施例中,“从前台进程的线程中确定出用于执行用户交互事件中相关任务的目标线程,并将目标线程标记为第一类线程”包括:从前台进程的线程中识别出用于执行用户交互事件中相关任务的第一预设线程,作为目标线程;为目标线程添加预设标签,以将线程标记为第一类线程。For example, in one embodiment, "determining a target thread for executing relevant tasks in a user interaction event from the threads of the foreground process, and marking the target thread as a first-class thread" includes: identifying a first preset thread for executing relevant tasks in a user interaction event from the threads of the foreground process as the target thread; adding a preset label to the target thread to mark the thread as a first-class thread.
例如,上述第一预设线程包括进程运行时创建的一些用于直接执行用户交互事件的相关任务的线程,如UI(user interface,用户界面)线程,Render(渲染)线程,GL线程,用户输入事件的分发线程,用户输入事件的检测线程等。这些线程是否能够流畅运行决定着是否会在用户与该进程的交互界面中产生用户可感知的卡顿。For example, the first preset thread includes some threads created when the process is running and used to directly execute tasks related to user interaction events, such as UI (user interface) thread, Render thread, GL thread, user input event distribution thread, user input event detection thread, etc. Whether these threads can run smoothly determines whether user-perceivable lag will occur in the interaction interface between the user and the process.
比如,用户使用聊天软件与某一好友聊天,用户在对话框输入文字,电子设备通过服务器将用户输入的文字发送至该好友的电子设备。在这次交互事件中,需要UI线程、Render线程、用户输入事件的分发线程、用户输入事件的检测线程等线程共同工作,以完成本次用户交互事件,其中,每一个线程的运行都需要系统为其分配资源。因此,在检测到该聊天软件在前台运行时,识别出这些线程,将其标记为ux线程。For example, a user uses a chat software to chat with a friend. The user enters text in the dialog box, and the electronic device sends the text entered by the user to the friend's electronic device through the server. In this interaction event, the UI thread, Render thread, user input event distribution thread, user input event detection thread and other threads need to work together to complete this user interaction event. The operation of each thread requires the system to allocate resources for it. Therefore, when the chat software is detected to be running in the foreground, these threads are identified and marked as ux threads.
其中,第一预设线程一般是应用级线程,这些线程可以是通过对实际的卡顿场景进行分析来确定。比如,在测试中,如果某一用户交互场景下发生了应用卡顿,通过对该场景分析发现卡顿现象是某个线程处理任务太慢导致的,则可以认为该线程是用于执行用户交互事件中相关任务的,该线程的运行与用户体验紧密相关,可以将该线程作为第一预设线程。Among them, the first preset thread is generally an application-level thread, which can be determined by analyzing the actual jamming scenario. For example, in the test, if an application jam occurs in a certain user interaction scenario, and the analysis of the scenario finds that the jamming phenomenon is caused by a certain thread processing tasks too slowly, then it can be considered that the thread is used to execute related tasks in the user interaction event, and the operation of the thread is closely related to the user experience, and the thread can be used as the first preset thread.
基于此,可以通过对各种可能的卡顿场景进行测试,记录这些导致卡顿出现的线程。电子设备中存储这些第一预设线程的相关信息,当进程切换到前台运行时,将该进程下的属于预先记录的第一预设线程的线程都标记为ux线程。Based on this, various possible jamming scenarios can be tested to record the threads that cause jamming. The electronic device stores the relevant information of the first preset threads, and when the process is switched to the foreground, all threads belonging to the pre-recorded first preset threads under the process are marked as ux threads.
可以理解的是,对于电子设备来说,存储的第一预设线程的相关信息并不是不可修改的,当进行系统升级时,可以对第一预设线程的相关信息进行更新。It is understandable that, for the electronic device, the stored relevant information of the first preset thread is not unmodifiable, and when the system is upgraded, the relevant information of the first preset thread can be updated.
此外,在另一实施例中,该方法还包括:当检测到有第二预设线程创建时,将创建的第二预设线程标记为第一类线程,其中,第二预设线程为系统级线程。In addition, in another embodiment, the method further includes: when it is detected that a second preset thread is created, marking the created second preset thread as a first-type thread, wherein the second preset thread is a system-level thread.
由于在执行用户交互事件的过程中,除了应用级线程之外,可能还涉及到一些系统级的线程来完成任务,系统框架层也需要将这些系统级线程标记为ux线程。一般这些线程在系统启动时就会创建,因此,可以在检测到系统启动时,识别出这些线程并进行标记,比如,Surfaceflinger线程、系统动画线程等。或者,在系统运行过程中,如果检测到有新的系统进程的线程创建并用来执行用户交互事件中相关任务,系统框架层也将这些线程标记为ux线程。比如,SystemUI线程。其中,第二预设线程也可以通过对实际的卡顿场景进行分析来确定。比如,在测试中,如果某一用户交互场景下发生了应用卡顿,通过对该场景分析发现卡顿现象是某个系统级线程处理任务太慢导致的,则可以认为该系统级线程是用于执行用户交互事件中相关任务的,该系统级线程的运行与用户体验紧密相关,可以将该系统级线程作为第二预设线程。电子设备中存储这些第二预设线程的相关信息,如果检测到系统创建了这些线程,则将其标记为ux线程。Since in the process of executing user interaction events, in addition to application-level threads, some system-level threads may be involved to complete tasks, the system framework layer also needs to mark these system-level threads as ux threads. Generally, these threads are created when the system starts, so when the system starts, these threads can be identified and marked, such as Surfaceflinger threads, system animation threads, etc. Alternatively, during the operation of the system, if it is detected that a new system process thread is created and used to perform related tasks in the user interaction event, the system framework layer also marks these threads as ux threads. For example, SystemUI threads. Among them, the second preset thread can also be determined by analyzing the actual jamming scene. For example, in the test, if an application jam occurs in a certain user interaction scene, and the jamming phenomenon is found to be caused by a system-level thread processing task too slowly through the analysis of the scene, it can be considered that the system-level thread is used to perform related tasks in the user interaction event, and the operation of the system-level thread is closely related to the user experience, and the system-level thread can be used as the second preset thread. The electronic device stores the relevant information of these second preset threads, and if it is detected that the system has created these threads, they are marked as ux threads.
其中,预设标签可以为ux标签,其添加方式如下:Linux使用task_struct结构体描述和记录线程,每个线程都有对应的task_struct结构体。task_struct中记录了线程的名称、标识符、状态、优先级、内存指针、上下文数据等属性信息。因此,应用框架层可以在task_struct结构体中增加对应的ux flag成员,以将前台进程的UI线程、Render线程、GL线程等执行用户交互事件中相关任务的线程,通过标记ux flag位,使内核层能够识别该线程的任务属性。Among them, the preset tag can be a ux tag, which is added as follows: Linux uses the task_struct structure to describe and record threads, and each thread has a corresponding task_struct structure. The task_struct records the name, identifier, state, priority, memory pointer, context data and other attribute information of the thread. Therefore, the application framework layer can add a corresponding ux flag member to the task_struct structure to mark the UI thread, Render thread, GL thread and other threads of the foreground process that perform related tasks in the user interaction event with the ux flag bit, so that the kernel layer can identify the task attributes of the thread.
需要说明的是,上述几种静态ux线程仅为举例说明,并不局限于此,只要是直接地执行用户交互事件中相关任务的线程,使得其运行情况直接地影响到用户体验的线程,都可以将其标记为静态ux线程。对于应用框架层来说,在检测到新创建的线程是用来执行用户交互事件,或者检测到某些常驻系统级线程是用以处理用户交互事件时,为这些线程添加ux标签,以将其标记为静态ux线程。It should be noted that the above-mentioned static ux threads are only examples and are not limited to them. As long as it is a thread that directly executes tasks related to user interaction events and its operation directly affects the user experience, it can be marked as a static ux thread. For the application framework layer, when it is detected that the newly created thread is used to execute user interaction events, or when it is detected that some resident system-level threads are used to process user interaction events, these threads are added with ux tags to mark them as static ux threads.
在另一实施例中,“从前台进程的线程中确定出用于执行用户交互事件中相关任务的目标线程,并将目标线程标记为第一类线程”还包括:在前台进程的运行过程中,当检测到有新线程创建时,确定新创建的线程是否用于执行用户交互事件中的相关任务;当新创建的线程用于执行用户交互事件中的相关任务时,将新创建的线程标记为第一类线程。In another embodiment, "determining a target thread for executing relevant tasks in a user interaction event from threads of a foreground process, and marking the target thread as a first-class thread" also includes: during the running of the foreground process, when it is detected that a new thread is created, determining whether the newly created thread is used to execute relevant tasks in the user interaction event; when the newly created thread is used to execute relevant tasks in the user interaction event, marking the newly created thread as a first-class thread.
前台进程在运行过程中,如果有用户交互事件发生,除了上述应用级的第一预设线程和系统级的第二预设线程之外,还可能会有一些临时创建的任务线程,这些任务线程的运行也会直接影响到是否会在用户与该进程的交互界面中产生用户可感知的卡顿。因此,应用框架层会将这些线程也标记为ux线程。When a foreground process is running, if a user interaction event occurs, in addition to the first preset thread at the application level and the second preset thread at the system level, there may be some temporarily created task threads. The operation of these task threads will also directly affect whether there will be user-perceivable lag in the user's interaction interface with the process. Therefore, the application framework layer will also mark these threads as ux threads.
其中,电子设备根据检测到的用户指令确定发生的用户交互事件。用户交互事件一般是指用户触发了某指令后,电子设备需要即时的对该指令进行响应,进行某种处理并将处理结果显示在界面上的情况。例如,用户使用电子设备观看视频、编辑短信、使用聊天软件、使用游戏软件、控制电子设备界面的切换、使用浏览浏览网页等,都属于用户交互事件。比如,用户使用聊天软件与某一好友聊天,用户在对话框输入文字,电子设备通过服务器将用户输入的文字发送至该好友的电子设备。在这个过程中,电子设备需要调度多个线程以完成本次用户交互事件,从该用户交互事件的开始到完成的整个过程中,进程创建的用来完成这次用户交互事件的线程都可以认为是与用户体验相关的线程。Among them, the electronic device determines the user interaction event that occurs based on the detected user instruction. A user interaction event generally refers to a situation where after a user triggers a certain instruction, the electronic device needs to respond to the instruction immediately, perform some processing and display the processing result on the interface. For example, users use electronic devices to watch videos, edit text messages, use chat software, use game software, control the switching of electronic device interfaces, use browsing to browse web pages, etc., all of which are user interaction events. For example, a user uses chat software to chat with a friend, the user enters text in the dialog box, and the electronic device sends the text entered by the user to the friend's electronic device through the server. In this process, the electronic device needs to schedule multiple threads to complete this user interaction event. From the start to the completion of the user interaction event, the threads created by the process to complete this user interaction event can be considered as threads related to user experience.
在另一实施例中,为目标线程添加预设标签之后,该方法还包括:若前台进程为应用进程,则在检测到前台进程切换至后台运行时,删除第一预设线程的预设标签。当前台进程切换到后台运行时,该进程的运行情况已经与用户体验无关,其线程的重要程度也有所下降,因此,可以将该进程对应的第一预设线程的ux标记删除,将这些ux线程恢复为普通线程。In another embodiment, after adding a preset tag to the target thread, the method further includes: if the foreground process is an application process, when it is detected that the foreground process switches to background operation, deleting the preset tag of the first preset thread. When the foreground process switches to background operation, the operation of the process is no longer related to the user experience, and the importance of its thread is also reduced. Therefore, the ux tag of the first preset thread corresponding to the process can be deleted, and these ux threads can be restored to ordinary threads.
此外,对于那些在用户交互事件中临时创建的任务线程来说,在执行完对应的任务后就会被销毁,其自然会丢失掉ux标签。而对于系统级的第二预设线程来说,即使发生了进程的前后台切换,这些线程始终与用户体验相关,所以始终保有ux标签。In addition, for those task threads temporarily created in user interaction events, they will be destroyed after completing the corresponding tasks, and they will naturally lose the ux tag. For the second preset threads at the system level, even if the foreground and background switching of the process occurs, these threads are always related to the user experience, so they always retain the ux tag.
通过上述实施例,框架层识别出那些直接影响到用户体验的线程并为其添加标记。而线程的运行,需要内核为之分配系统资源。因此,线程在执行任务前,会向内核请求资源。内核在基于该请求为其分配资源时,可以先判断该线程是否为ux线程,对于ux线程和非ux线程采用不同的资源分配方式。Through the above embodiments, the framework layer identifies threads that directly affect the user experience and adds tags to them. The operation of threads requires the kernel to allocate system resources for them. Therefore, before executing a task, the thread will request resources from the kernel. When the kernel allocates resources to it based on the request, it can first determine whether the thread is a ux thread, and use different resource allocation methods for ux threads and non-ux threads.
需要说明的是,这里的第一类线程和第二类线程中的“第一类”和“第二类”,仅仅是为了区分线程是否具有ux标签,而不是说将系统中的线程只划分为这两种类别。本申请的资源分配优化方案是从线程是否具有ux标签这一角度出发的,如果线程同时还具有其他属性,则在资源分配时,考虑了是否具有ux标签这一属性后,仍然会考虑其他属性。It should be noted that the "first category" and "second category" in the first category of threads and the second category of threads here are only to distinguish whether the threads have ux tags, rather than to divide the threads in the system into only these two categories. The resource allocation optimization scheme of this application is based on whether the thread has a ux tag. If the thread also has other attributes, then when allocating resources, after considering whether it has a ux tag, other attributes will still be considered.
上述实施例介绍了静态ux线程的识别。还有一些线程虽然并没有直接地执行用户交互事件的相关任务,但是这些线程的运行情况也会影响到静态ux线程的运行情况,进而间接地影响到用户交互事件的相关任务的执行。也就是说,这些线程并不是总是与用户体验相关,但是这些线程在执行过程的某段时间内,可能通过资源约束与静态ux线程产生关联,因此,在一些实施例中,为了进一步地减少交互场景下的卡顿现象,内核层将这些与静态ux线程之间有约束关系的线程也标记为ux线程。而一旦这种约束关系结束,就会将该线程恢复至非ux线程。本申请实施例中将这类线程定义为动态ux线程。其中,具体的约束关系包括但不限于进程间通信、线程间通信或者持有临界资源等。比如,静态ux线程通过进程间通信请求的普通线程,静态ux线程通过某种线程间通信方式请求的普通线程,持有静态ux线程需要的等待信号量、读写信号量、互斥锁等临界资源的普通线程等,本申请实施例中将这类线程标记为动态ux线程。The above embodiment introduces the identification of static ux threads. Although some threads do not directly execute tasks related to user interaction events, the operation of these threads will also affect the operation of static ux threads, and then indirectly affect the execution of tasks related to user interaction events. In other words, these threads are not always related to user experience, but these threads may be associated with static ux threads through resource constraints during a certain period of time during the execution process. Therefore, in some embodiments, in order to further reduce the jamming phenomenon in the interactive scenario, the kernel layer also marks these threads with constraints between static ux threads as ux threads. Once this constraint relationship ends, the thread will be restored to a non-ux thread. In the embodiment of the present application, such threads are defined as dynamic ux threads. Among them, the specific constraint relationship includes but is not limited to inter-process communication, inter-thread communication, or holding critical resources. For example, ordinary threads requested by static ux threads through inter-process communication, ordinary threads requested by static ux threads through some inter-thread communication method, ordinary threads holding critical resources such as waiting semaphores, read-write semaphores, and mutexes required by static ux threads, etc., in the embodiment of the present application, such threads are marked as dynamic ux threads.
基于此,在一些实施例中,该方法还包括:对第一类线程的运行状态进行检测;当检测到有第一类线程进入阻塞状态,则确定与进入阻塞状态的第一类线程之间有约束关系的关联线程;为关联线程添加预设标签,以将关联线程标记为第一类线程。Based on this, in some embodiments, the method also includes: detecting the running status of the first-class thread; when it is detected that the first-class thread has entered a blocked state, determining an associated thread that has a constraint relationship with the first-class thread that has entered the blocked state; and adding a preset label to the associated thread to mark the associated thread as a first-class thread.
在一些实施例中,将关联线程标记为第一类线程之后,还包括:当检测到约束关系解除时,删除关联线程的预设标签。In some embodiments, after marking the associated thread as a first-category thread, the method further includes: when it is detected that the constraint relationship is released, deleting the preset label of the associated thread.
其中,关于线程的阻塞状态,在内核层面一般会区分为D状态(Uninterruptablesleep状态,不可中断的睡眠状态)和S状态(interruptable sleep状态,可中断的睡眠状态),比如,线程发起IO请求但得不到满足,就进入D状态;线程发起同步Binder请求,就会进入S状态。线程进入这些状态一般都是因为这些都是线程任务执行途中因为某些原因或者逻辑,需要主动或者被动地放弃CPU资源。Among them, regarding the blocking state of a thread, it is generally divided into D state (Uninterruptable sleep state) and S state (interruptable sleep state) at the kernel level. For example, if a thread initiates an IO request but is not satisfied, it enters the D state; if a thread initiates a synchronous Binder request, it enters the S state. Threads generally enter these states because they need to actively or passively give up CPU resources due to some reasons or logic during the execution of the thread task.
该实施例中,内核层对静态ux线程的状态进行检测,当检测到ux线程进入到堵塞状态时,确定出与进入堵塞状态的ux线程之间具有约束关系的关联线程,如果这些关联线程没有及时分配到资源,比如IO资源,而导致运行受阻,则由于关联线程的运行缓慢又会导致该ux线程长时间处于阻塞状态,因此,为了避免该ux线程长时间处于阻塞状态,内核层会将识别出的关联线程也标记为ux线程,以提高其IO处理效率,保证其及时执行,进而快速解除该ux线程的阻塞状态。In this embodiment, the kernel layer detects the state of the static ux thread. When it is detected that the ux thread enters a blocked state, the kernel layer determines the associated threads that have a constraint relationship with the ux thread that enters the blocked state. If these associated threads are not allocated resources in time, such as IO resources, resulting in operation obstruction, the slow operation of the associated threads will cause the ux thread to be in a blocked state for a long time. Therefore, in order to avoid the ux thread being in a blocked state for a long time, the kernel layer will also mark the identified associated threads as ux threads to improve their IO processing efficiency and ensure their timely execution, thereby quickly releasing the blocked state of the ux thread.
上文中介绍了应用框架层和内核层识别并标记ux线程的方式。对于内核来说,对于每一种线程设置有不同的内存回收比例,本申请实时中,内存回收对象包括匿名页和文件页,回收文件页的效率高于回收匿名页的效率。内存回收比例为文件页和匿名页的比例。由于对于用户体验来说,ux线程的重要程度大于非ux线程的重要程度,因此,设置ux线程的优先级大于非ux线程的优先级,ux线程的内存回收比例中文件页的占比,大于非ux线程中文件页的占比。比如,在一实施例中,ux线程的内存回收比例为200:0,非ux线程的内存回收比例为60:140。也就是说,当前线程为ux线程时,回收对象可以全部是文件页。而当前线程为非ux线程时,大部分回收对象为匿名页。需要说明的是,上述数值为举例说明,不构成对本方案的限制,只要ux线程的内存回收比例中文件页的占比大于非ux线程的内存回收比例中文件页的占比即可。The above describes the way in which the application framework layer and the kernel layer identify and mark ux threads. For the kernel, a different memory recovery ratio is set for each thread. In the present application, the memory recovery objects include anonymous pages and file pages, and the efficiency of recovering file pages is higher than the efficiency of recovering anonymous pages. The memory recovery ratio is the ratio of file pages to anonymous pages. Since the importance of ux threads is greater than that of non-ux threads for user experience, the priority of ux threads is set to be greater than that of non-ux threads, and the proportion of file pages in the memory recovery ratio of ux threads is greater than the proportion of file pages in non-ux threads. For example, in one embodiment, the memory recovery ratio of ux threads is 200:0, and the memory recovery ratio of non-ux threads is 60:140. In other words, when the current thread is a ux thread, all the recovery objects can be file pages. When the current thread is a non-ux thread, most of the recovery objects are anonymous pages. It should be noted that the above values are for example only and do not constitute a limitation on this solution, as long as the proportion of file pages in the memory recovery ratio of ux threads is greater than the proportion of file pages in the memory recovery ratio of non-ux threads.
在103中,获取与线程的类型对应的内存回收比例,并按照内存回收比例对已分配内存空间中的内存页进行回收,其中,内存回收比例用于表征多种内存回收对象之间的比例,不同种类的内存回收对象的回收效率不同,线程的优先级越高,则对应的内存回收比例中回收效率高的内存回收对象的占比越大。In 103, a memory recovery ratio corresponding to the thread type is obtained, and memory pages in the allocated memory space are recovered according to the memory recovery ratio, wherein the memory recovery ratio is used to characterize the ratio between multiple memory recovery objects. Different types of memory recovery objects have different recovery efficiencies. The higher the thread priority, the greater the proportion of memory recovery objects with high recovery efficiency in the corresponding memory recovery ratio.
内核在接收到内存分配请求后,可以先根据该线程的标签确定该线程的类型。并按照与线程对应的内存回收比例,对已分配内存空间中的内存页进行回收。仍然以ux线程的内存回收比例为200:0,非ux线程的内存回收比例为60:140为例。例如,要回收到内存量为200M,当前线程为ux线程时,200M的内存量全部通过回收文件页得到。当前线程为非ux线程时,其中60M的内存量通过回收文件页得到,另外140M的内存量通过回收匿名页得到。其中,已分配内存空间是指由已经分配给线程、处于被占用状态的内存页构成的内存空间。After receiving a memory allocation request, the kernel can first determine the type of the thread based on the thread's label. And reclaim the memory pages in the allocated memory space according to the memory reclaim ratio corresponding to the thread. Still take the memory reclaim ratio of ux thread as 200:0 and the memory reclaim ratio of non-ux thread as 60:140 as an example. For example, to reclaim 200M of memory, when the current thread is a ux thread, all 200M of memory is obtained by reclaiming file pages. When the current thread is a non-ux thread, 60M of memory is obtained by reclaiming file pages, and the other 140M of memory is obtained by reclaiming anonymous pages. Among them, the allocated memory space refers to the memory space composed of memory pages that have been allocated to the thread and are in an occupied state.
具体实施时,本申请不受所描述的各个步骤的执行顺序的限制,在不产生冲突的情况下,某些步骤还可以采用其它顺序进行或者同时进行。In specific implementation, the present application is not limited by the execution order of the various steps described. If no conflict occurs, some steps can be performed in other orders or simultaneously.
由上可知,本申请实施例提供的内存回收方法,在接收到线程发送的内存分配请求时,先确定当前的空闲内存量,如果空闲内存量小于预设阈值,则要先进行内存回收,接下来对线程的类型进行识别,在内存回收时,根据请求内存的线程的类型的不同,采用不同的内存回收比例进行内存回收,该内存回收比例用于表征多种内存回收对象之间的比例,由于不同种类的内存回收对象的回收效率不同,因此若内存回收比例不同,则整体的回收效率也不相同。其中,第一类线程为执行用户交互事件中相关任务的线程,具有最高优先级,也就是说,第一类线程对应的内存回收比例中回收效率高的内存回收对象的占比在所有类别的线程中为最大占比,因此,对于第一类线程来说,在全部线程中具有最高效率的内存回收机制,可以尽快完成内存回收,提高了第一类线程的内存分配效率,避免第一类线程因为不能及时得到内存而导致出现交互场景下的卡顿现象,提升用户体验。As can be seen from the above, the memory recovery method provided in the embodiment of the present application, when receiving the memory allocation request sent by the thread, first determines the current amount of free memory. If the amount of free memory is less than the preset threshold, memory recovery must be performed first, and then the type of thread is identified. When memory is recovered, different memory recovery ratios are used for memory recovery according to the type of thread requesting memory. The memory recovery ratio is used to characterize the ratio between multiple memory recovery objects. Since the recovery efficiency of different types of memory recovery objects is different, if the memory recovery ratio is different, the overall recovery efficiency is also different. Among them, the first type of thread is the thread that executes the relevant tasks in the user interaction event, and has the highest priority. That is to say, the proportion of memory recovery objects with high recovery efficiency in the memory recovery ratio corresponding to the first type of thread is the largest proportion among all types of threads. Therefore, for the first type of thread, the memory recovery mechanism with the highest efficiency among all threads can complete memory recovery as soon as possible, improve the memory allocation efficiency of the first type of thread, avoid the jamming phenomenon in the interactive scene caused by the failure of the first type of thread to obtain memory in time, and improve the user experience.
根据前面实施例所描述的方法,以下将举例作进一步详细说明。The method described in the above embodiments is further described in detail below with examples.
请参阅图2,图2为本发明实施例提供的内存回收方法的第二流程示意图。Please refer to FIG. 2 , which is a second flow chart of the memory recycling method provided by an embodiment of the present invention.
方法包括:Methods include:
在201中,当接收到线程发送的内存分配请求时,确定当前的空闲内存量。In 201, when a memory allocation request sent by a thread is received, the current amount of free memory is determined.
在上文的一些实施例中,将线程分为两类:ux线程和非ux线程,进行处理。在该实施例中,可以将线程分为三类进行处理,根据线程的运行情况对用户体验的影响程度的大小,将系统中的线程划分为优先级由高至低的ux线程、前台线程和后台线程。其中,ux线程的识别与标记方式请参照上述实施例,在此不再赘述。In some of the above embodiments, threads are divided into two categories: ux threads and non-ux threads for processing. In this embodiment, threads can be divided into three categories for processing. According to the degree of influence of the running status of the threads on the user experience, the threads in the system are divided into ux threads, foreground threads and background threads with high to low priorities. Among them, the identification and marking method of ux threads can refer to the above embodiments, which will not be repeated here.
将ux线程记为第一类线程,当检测到有线程切换至前台运行时,判断切换至前台运行的线程是否为第一类线程;若否,则为线程添加第二预设标签,以将线程标记为第二类线程;当检测到有线程切换至后台运行时,判断切换至后台运行的线程是否为第一类线程;若否,则为线程添加第三预设标签,以将线程标记为第三类线程。The ux thread is recorded as a first-class thread. When it is detected that a thread is switched to the foreground, it is determined whether the thread switched to the foreground is a first-class thread; if not, a second preset label is added to the thread to mark the thread as a second-class thread; when it is detected that a thread is switched to the background, it is determined whether the thread switched to the background is a first-class thread; if not, a third preset label is added to the thread to mark the thread as a third-class thread.
通过这种方式,将除了ux线程之外的其他线程中运行在前台的线程作为第二类线程,记为FG线程,将除了ux线程之外的其他线程中运行在后台的线程作为第三类线程,记为BG线程。In this way, threads running in the foreground among threads other than the ux thread are regarded as second-category threads, recorded as FG threads, and threads running in the background among threads other than the ux thread are regarded as third-category threads, recorded as BG threads.
其中,对于用户体验来说,ux线程的重要程度大于FG线程的重要程度,FG线程的重要程度大于BG线程的重要程度。因此,设置ux线程的优先级大于FG线程的优先级,FG线程的优先级大于BG线程的优先级。ux线程的内存回收比例中文件页的占比,大于FG线程中文件页的占比;FG线程的内存回收比例中文件页的占比,大于BG线程中文件页的占比。Among them, for user experience, the importance of ux thread is greater than that of FG thread, and that of FG thread is greater than that of BG thread. Therefore, the priority of ux thread is set higher than that of FG thread, and that of FG thread is set higher than that of BG thread. The proportion of file pages in the memory recovery ratio of ux thread is greater than that of FG thread; the proportion of file pages in the memory recovery ratio of FG thread is greater than that of BG thread.
在202中,若空闲内存量小于预设阈值,则获取线程携带的标签,并根据标签确定线程的类型。In 202, if the amount of free memory is less than a preset threshold, a tag carried by the thread is obtained, and the type of the thread is determined according to the tag.
内核在接收到内存分配请求后,可以先根据该线程的标签确定该线程的类型。其中,若标签为第一预设标签,则判定线程为第一类线程;若标签为第二预设标签,则判定线程为第二类线程;若标签为第三预设标签,则判定线程为第三类线程。After receiving the memory allocation request, the kernel may first determine the type of the thread according to the tag of the thread. If the tag is a first preset tag, the thread is determined to be a first type of thread; if the tag is a second preset tag, the thread is determined to be a second type of thread; if the tag is a third preset tag, the thread is determined to be a third type of thread.
在203中,当线程为第一类线程时,按照第一内存回收比例对已分配内存空间中的内存页进行回收,其中,第一类线程为执行用户交互事件中相关任务的线程。In 203, when the thread is a first type thread, memory pages in the allocated memory space are reclaimed according to a first memory reclaim ratio, wherein the first type thread is a thread that executes tasks related to the user interaction event.
在204中,当线程为第二类线程时,按照第二内存回收比例对已分配内存空间中的内存页进行回收,其中,第一内存回收比例中回收效率高的内存回收对象的占比,高于第二内存回收比例中回收效率高的内存回收对象的占比。In 204, when the thread is a second type of thread, memory pages in the allocated memory space are reclaimed according to the second memory reclaim ratio, wherein the proportion of memory reclaim objects with high reclaim efficiency in the first memory reclaim ratio is higher than the proportion of memory reclaim objects with high reclaim efficiency in the second memory reclaim ratio.
在205中,当线程为第三类线程时,按照第三内存回收比例对已分配内存空间中的内存页进行回收,其中,第二内存回收比例中回收效率高的内存回收对象的占比,高于第三内存回收比例中回收效率高的内存回收对象的占比。In 205, when the thread is a third type of thread, memory pages in the allocated memory space are reclaimed according to the third memory reclaim ratio, wherein the proportion of memory reclaim objects with high reclaim efficiency in the second memory reclaim ratio is higher than the proportion of memory reclaim objects with high reclaim efficiency in the third memory reclaim ratio.
确定该线程的类型后,按照与线程对应的内存回收比例,对已分配内存空间中的内存页进行回收。以ux线程的内存回收比例为200:0,FG线程的内存回收比例为140:60为例,BG线程的内存回收比例为0:200。当前线程为ux线程时,以最快速度回收到所需内存,200M的内存量全部通过回收文件页得到。当前线程为FG线程时,需要较快地回收到内存,其中140M的内存量通过回收文件页得到,另外60M的内存量通过回收匿名页得到。当前线程为BG线程时,200M的内存量全部通过回收匿名页得到,尽量地保护文件页。上述参数仅作举例说明,实际使用时可以根据实际测试结果做参数调整。After determining the type of the thread, reclaim the memory pages in the allocated memory space according to the memory reclaim ratio corresponding to the thread. Taking the memory reclaim ratio of the ux thread as 200:0 and the memory reclaim ratio of the FG thread as 140:60 as an example, the memory reclaim ratio of the BG thread is 0:200. When the current thread is a ux thread, the required memory is reclaimed at the fastest speed, and the 200M memory is all obtained by reclaiming file pages. When the current thread is a FG thread, the memory needs to be reclaimed quickly, of which 140M of memory is obtained by reclaiming file pages, and the other 60M of memory is obtained by reclaiming anonymous pages. When the current thread is a BG thread, the 200M memory is all obtained by reclaiming anonymous pages, and the file pages are protected as much as possible. The above parameters are only for example. In actual use, the parameters can be adjusted according to the actual test results.
由上可知,本发明实施例提出的内存回收方法,根据线程的运行情况对用户体验的影响程度的大小,将系统中的线程划分为优先级由高至低的ux线程、前台线程和后台线程。在进行内存回收时,根据线程类型的不同,采用不同的内存回收比例回收内存,线程的优先级越高,则对应的内存回收比例中文件页的占比越大。因此,当前线程为ux线程时的回收速度大于为前台线程时的回收速度,当前线程为前台线程时的回收速度大于为后台线程时的回收速度,并且在当前线程为后台线程时,能够尽量保护文件页不被回收。在避免第一类线程因为不能及时得到内存而导致出现交互场景下的卡顿现象,提升用户体验的同时,降低再次重新读磁盘数据IO带来的代价。As can be seen from the above, the memory recovery method proposed in the embodiment of the present invention divides the threads in the system into ux threads, foreground threads and background threads with priorities from high to low according to the degree of influence of the running conditions of the threads on the user experience. When performing memory recovery, different memory recovery ratios are used to recover the memory according to the different thread types. The higher the priority of the thread, the greater the proportion of file pages in the corresponding memory recovery ratio. Therefore, the recovery speed when the current thread is a ux thread is greater than the recovery speed when it is a foreground thread, the recovery speed when the current thread is a foreground thread is greater than the recovery speed when it is a background thread, and when the current thread is a background thread, the file pages can be protected from being recovered as much as possible. This avoids the jamming phenomenon in the interactive scenario caused by the first type of thread not being able to obtain memory in time, improves the user experience, and reduces the cost of re-reading disk data IO again.
在一实施例中还提供一种内存回收装置。请参阅图3,图3为本申请实施例提供的内存回收装置300的结构示意图。其中该内存回收装置300应用于电子设备,该内存回收装置300包括内存检测模块301、线程识别模块302以及内存回收模块303,如下:In one embodiment, a memory recovery device is also provided. Please refer to FIG. 3, which is a schematic diagram of the structure of a memory recovery device 300 provided in an embodiment of the present application. The memory recovery device 300 is applied to an electronic device, and the memory recovery device 300 includes a memory detection module 301, a thread identification module 302, and a memory recovery module 303, as follows:
内存检测模块301,用于当接收到线程发送的内存分配请求时,确定当前的空闲内存量;The memory detection module 301 is used to determine the current amount of free memory when receiving a memory allocation request sent by a thread;
线程识别模块302,用于若空闲内存量小于预设阈值,则确定线程的类型,其中,将线程划分为优先级不同的多类线程,其中,第一类线程具有最高优先级,第一类线程为执行用户交互事件中相关任务的线程;A thread identification module 302, for determining the type of thread if the amount of free memory is less than a preset threshold, wherein the threads are divided into multiple types of threads with different priorities, wherein the first type of thread has the highest priority, and the first type of thread is a thread that executes related tasks in the user interaction event;
内存回收模块303,用于获取与线程的类型对应的内存回收比例,并按照内存回收比例对已分配内存空间中的内存页进行回收,其中,内存回收比例用于表征多种内存回收对象之间的比例,不同种类的内存回收对象的回收效率不同,线程的优先级越高,则对应的内存回收比例中回收效率高的内存回收对象的占比越大。The memory recovery module 303 is used to obtain the memory recovery ratio corresponding to the thread type, and to recycle the memory pages in the allocated memory space according to the memory recovery ratio, wherein the memory recovery ratio is used to characterize the ratio between multiple memory recovery objects, and different types of memory recovery objects have different recovery efficiencies. The higher the thread priority, the greater the proportion of memory recovery objects with high recovery efficiency in the corresponding memory recovery ratio.
在一些实施例中,内存回收模块303还用于:当线程为第一类线程时,按照第一内存回收比例对已分配内存空间中的内存页进行回收;In some embodiments, the memory recycling module 303 is further used to: when the thread is a first type of thread, reclaim memory pages in the allocated memory space according to a first memory recycling ratio;
当线程为第二类线程时,按照第二内存回收比例对已分配内存空间中的内存页进行回收,其中,第一内存回收比例中回收效率高的内存回收对象的占比,高于第二内存回收比例中回收效率高的内存回收对象的占比。When the thread is a second type of thread, memory pages in the allocated memory space are reclaimed according to the second memory reclaim ratio, wherein the proportion of memory reclaim objects with high reclaim efficiency in the first memory reclaim ratio is higher than the proportion of memory reclaim objects with high reclaim efficiency in the second memory reclaim ratio.
在一些实施例中,将线程划分为优先级不同的三类线程;内存回收模块303还用于:当线程为第三类线程时,按照第三内存回收比例对已分配内存空间中的内存页进行回收,其中,第二内存回收比例中回收效率高的内存回收对象的占比,高于第三内存回收比例中回收效率高的内存回收对象的占比。In some embodiments, threads are divided into three categories of threads with different priorities; the memory recovery module 303 is also used to: when the thread is a third category of thread, reclaim memory pages in the allocated memory space according to a third memory recovery ratio, wherein the proportion of memory recovery objects with high recovery efficiency in the second memory recovery ratio is higher than the proportion of memory recovery objects with high recovery efficiency in the third memory recovery ratio.
在一些实施例中,线程识别模块302还用于:获取线程携带的标签;In some embodiments, the thread identification module 302 is further used to: obtain a tag carried by the thread;
若标签为第一预设标签,则判定线程为第一类线程;If the tag is the first preset tag, the thread is determined to be a first-category thread;
若标签为第二预设标签,则判定线程为第二类线程;If the tag is the second preset tag, the thread is determined to be a second type of thread;
若标签为第三预设标签,则判定线程为第三类线程。If the tag is the third preset tag, the thread is determined to be a third type of thread.
在一些实施例中,该内存回收装置300还包括线程标记模块,该线程标记模块用于:确定出执行用户交互事件中相关任务的目标线程;为所述目标线程添加所述预设标签,以将所述目标线程标记为第一类线程。In some embodiments, the memory recovery device 300 further includes a thread marking module, which is used to: determine a target thread that executes a related task in a user interaction event; and add the preset label to the target thread to mark the target thread as a first-category thread.
在一些实施例中,线程标记模块还用于:在检测到有进程切换到前台运行时,确定前台进程;从所述前台进程的线程中识别出用于执行用户交互事件中相关任务的第一预设线程,作为目标线程。In some embodiments, the thread marking module is also used to: determine the foreground process when detecting that a process has switched to the foreground; identify a first preset thread for executing related tasks in the user interaction event from the threads of the foreground process as the target thread.
在一些实施例中,线程标记模块还用于:对第一类线程的运行状态进行检测;当检测到有第一类线程进入阻塞状态,则确定与进入阻塞状态的第一类线程之间有约束关系的关联线程;为关联线程添加预设标签,以将关联线程标记为第一类线程。In some embodiments, the thread marking module is also used to: detect the running status of the first type of thread; when it is detected that the first type of thread has entered a blocked state, determine the associated threads that have a constraint relationship with the first type of thread that has entered the blocked state; add a preset label to the associated thread to mark the associated thread as a first type of thread.
在一些实施例中,线程标记模块还用于:当检测到有线程切换至前台运行时,判断切换至前台运行的线程是否为第一类线程;In some embodiments, the thread marking module is further used to: when detecting that a thread is switched to the foreground to run, determine whether the thread switched to the foreground to run is a first-category thread;
若否,则为线程添加第二预设标签,以将线程标记为第二类线程;If not, adding a second preset label to the thread to mark the thread as a second type of thread;
当检测到有线程切换至后台运行时,判断切换至后台运行的线程是否为第一类线程;When it is detected that a thread is switched to the background, it is determined whether the thread switched to the background is a first-class thread;
若否,则为线程添加第三预设标签,以将线程标记为第三类线程。If not, a third preset tag is added to the thread to mark the thread as a third type of thread.
应当说明的是,本申请实施例提供的内存回收装置与上文实施例中的内存回收方法属于同一构思,通过该内存回收装置可以实现内存回收方法实施例中提供的任一方法,其具体实现过程详见内存回收方法实施例,此处不再赘述。It should be noted that the memory recovery device provided in the embodiment of the present application belongs to the same concept as the memory recovery method in the above embodiment. Any method provided in the memory recovery method embodiment can be implemented through the memory recovery device. The specific implementation process is detailed in the memory recovery method embodiment, which will not be repeated here.
由上可知,本申请实施例提出的内存回收装置,在接收到线程发送的内存分配请求时,先确定当前的空闲内存量,如果空闲内存量小于预设阈值,则要先进行内存回收,接下来对线程的类型进行识别,在内存回收时,根据请求内存的线程的类型的不同,采用不同的内存回收比例进行内存回收,该内存回收比例用于表征多种内存回收对象之间的比例,由于不同种类的内存回收对象的回收效率不同,因此若内存回收比例不同,则整体的回收效率也不相同。其中,第一类线程为执行用户交互事件中相关任务的线程,具有最高优先级,也就是说,第一类线程对应的内存回收比例中回收效率高的内存回收对象的占比在所有类别的线程中为最大占比,因此,对于第一类线程来说,在全部线程中具有最高效率的内存回收机制,可以尽快完成内存回收,提高了第一类线程的内存分配效率,避免第一类线程因为不能及时得到内存而导致出现交互场景下的卡顿现象,提升用户体验。As can be seen from the above, the memory recovery device proposed in the embodiment of the present application, when receiving the memory allocation request sent by the thread, first determines the current amount of free memory. If the amount of free memory is less than the preset threshold, memory recovery must be performed first, and then the type of thread is identified. When memory is recovered, different memory recovery ratios are used for memory recovery according to the type of thread requesting memory. The memory recovery ratio is used to characterize the ratio between multiple memory recovery objects. Since the recovery efficiency of different types of memory recovery objects is different, if the memory recovery ratio is different, the overall recovery efficiency is also different. Among them, the first type of thread is the thread that executes the relevant tasks in the user interaction event, and has the highest priority. That is to say, the proportion of memory recovery objects with high recovery efficiency in the memory recovery ratio corresponding to the first type of thread is the largest proportion among all types of threads. Therefore, for the first type of thread, the memory recovery mechanism with the highest efficiency among all threads can complete memory recovery as soon as possible, improve the memory allocation efficiency of the first type of thread, avoid the jamming phenomenon in the interactive scene caused by the failure of the first type of thread to obtain memory in time, and improve the user experience.
本申请实施例还提供一种电子设备。所述电子设备可以是智能手机、平板电脑等设备。请参阅图4,图4为本申请实施例提供的电子设备的第一种结构示意图。电子设备400包括处理器401和存储器402。其中,处理器401与存储器402电性连接。The embodiment of the present application also provides an electronic device. The electronic device may be a smart phone, a tablet computer, or other device. Please refer to FIG. 4, which is a schematic diagram of the first structure of the electronic device provided in the embodiment of the present application. The electronic device 400 includes a processor 401 and a memory 402. The processor 401 is electrically connected to the memory 402.
处理器401是电子设备400的控制中心,利用各种接口和线路连接整个电子设备的各个部分,通过运行或调用存储在存储器402内的计算机程序,以及调用存储在存储器402内的数据,执行电子设备的各种功能和处理数据,从而对电子设备进行整体监控。The processor 401 is the control center of the electronic device 400. It uses various interfaces and lines to connect various parts of the entire electronic device. It executes various functions of the electronic device and processes data by running or calling computer programs stored in the memory 402, and calling data stored in the memory 402, thereby monitoring the electronic device as a whole.
存储器402可用于存储计算机程序和数据。存储器402存储的计算机程序中包含有可在处理器中执行的指令。计算机程序可以组成各种功能模块。处理器401通过调用存储在存储器402的计算机程序,从而执行各种功能应用以及数据处理。The memory 402 may be used to store computer programs and data. The computer programs stored in the memory 402 include instructions that can be executed in the processor. The computer programs may constitute various functional modules. The processor 401 executes various functional applications and data processing by calling the computer programs stored in the memory 402.
在本实施例中,电子设备400中的处理器401会按照如下的步骤,将一个或一个以上的计算机程序的进程对应的指令加载到存储器402中,并由处理器401来运行存储在存储器402中的计算机程序,从而实现各种功能:In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to the processes of one or more computer programs into the memory 402 according to the following steps, and the processor 401 runs the computer programs stored in the memory 402 to implement various functions:
当接收到线程发送的内存分配请求时,确定当前的空闲内存量;When receiving a memory allocation request sent by a thread, determine the current amount of free memory;
若所述空闲内存量小于预设阈值,则确定所述线程的类型,其中,将线程划分为优先级不同的多类线程,其中,第一类线程具有最高优先级,所述第一类线程为执行用户交互事件中相关任务的线程;If the amount of free memory is less than a preset threshold, determining the type of the thread, wherein the threads are divided into a plurality of types of threads with different priorities, wherein a first type of thread has a highest priority, and the first type of thread is a thread that executes a task related to a user interaction event;
获取与所述线程的类型对应的内存回收比例,并按照所述内存回收比例对已分配内存空间中的内存页进行回收,其中,所述内存回收比例用于表征多种内存回收对象之间的比例,不同种类的内存回收对象的回收效率不同,线程的优先级越高,则对应的内存回收比例中回收效率高的内存回收对象的占比越大。Obtain a memory recovery ratio corresponding to the type of the thread, and recycle memory pages in the allocated memory space according to the memory recovery ratio, wherein the memory recovery ratio is used to characterize the ratio between multiple memory recovery objects, and different types of memory recovery objects have different recovery efficiencies. The higher the priority of the thread, the greater the proportion of memory recovery objects with high recovery efficiency in the corresponding memory recovery ratio.
在一些实施例中,请参阅图5,图5为本申请实施例提供的电子设备的第二种结构示意图。电子设备400还包括:射频电路403、显示屏404、控制电路405、输入单元406、音频电路407、传感器408以及电源409。其中,处理器401分别与射频电路403、显示屏404、控制电路405、输入单元406、音频电路407、传感器408以及电源409电性连接。In some embodiments, please refer to FIG5, which is a second structural diagram of an electronic device provided in an embodiment of the present application. The electronic device 400 further includes: a radio frequency circuit 403, a display screen 404, a control circuit 405, an input unit 406, an audio circuit 407, a sensor 408, and a power supply 409. Among them, the processor 401 is electrically connected to the radio frequency circuit 403, the display screen 404, the control circuit 405, the input unit 406, the audio circuit 407, the sensor 408, and the power supply 409, respectively.
射频电路403用于收发射频信号,以通过无线通信与网络设备或其他电子设备进行通信。The radio frequency circuit 403 is used to send and receive radio frequency signals to communicate with network devices or other electronic devices through wireless communication.
显示屏404可用于显示由用户输入的信息或提供给用户的信息以及电子设备的各种图形用户接口,这些图形用户接口可以由图像、文本、图标、视频和其任意组合来构成。The display screen 404 may be used to display information input by a user or information provided to a user and various graphical user interfaces of the electronic device. These graphical user interfaces may be composed of images, texts, icons, videos and any combination thereof.
控制电路405与显示屏404电性连接,用于控制显示屏404显示信息。The control circuit 405 is electrically connected to the display screen 404 and is used to control the display screen 404 to display information.
输入单元406可用于接收输入的数字、字符信息或用户特征信息(例如指纹),以及产生与用户设置以及功能控制有关的键盘、鼠标、操作杆、光学或者轨迹球信号输入。其中,输入单元406可以包括指纹识别模组。The input unit 406 can be used to receive input numbers, character information or user feature information (such as fingerprints), and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control. The input unit 406 can include a fingerprint recognition module.
音频电路407可通过扬声器、传声器提供用户与电子设备之间的音频接口。其中,音频电路407包括麦克风。所述麦克风与所述处理器401电性连接。所述麦克风用于接收用户输入的语音信息。The audio circuit 407 can provide an audio interface between the user and the electronic device through a speaker and a microphone. The audio circuit 407 includes a microphone. The microphone is electrically connected to the processor 401. The microphone is used to receive voice information input by the user.
传感器408用于采集外部环境信息。传感器408可以包括环境亮度传感器、加速度传感器、陀螺仪等传感器中的一种或多种。The sensor 408 is used to collect external environment information and may include one or more sensors such as an environment brightness sensor, an acceleration sensor, and a gyroscope.
电源409用于给电子设备400的各个部件供电。在一些实施例中,电源409可以通过电源管理系统与处理器401逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。The power supply 409 is used to supply power to various components of the electronic device 400. In some embodiments, the power supply 409 may be logically connected to the processor 401 through a power management system, so that the power management system can manage charging, discharging, power consumption, and other functions.
虽然图中未示出,电子设备400还可以包括摄像头、蓝牙模块等,在此不再赘述。Although not shown in the figure, the electronic device 400 may also include a camera, a Bluetooth module, etc., which will not be described in detail here.
在本实施例中,电子设备400中的处理器401会按照如下的步骤,将一个或一个以上的计算机程序的进程对应的指令加载到存储器402中,并由处理器401来运行存储在存储器402中的计算机程序,从而实现各种功能:In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to the processes of one or more computer programs into the memory 402 according to the following steps, and the processor 401 runs the computer programs stored in the memory 402 to implement various functions:
当接收到线程发送的内存分配请求时,确定当前的空闲内存量;When receiving a memory allocation request sent by a thread, determine the current amount of free memory;
若所述空闲内存量小于预设阈值,则确定所述线程的类型,其中,将线程划分为优先级不同的多类线程,其中,第一类线程具有最高优先级,所述第一类线程为执行用户交互事件中相关任务的线程;If the amount of free memory is less than a preset threshold, determining the type of the thread, wherein the threads are divided into a plurality of types of threads with different priorities, wherein a first type of thread has a highest priority, and the first type of thread is a thread that executes a task related to a user interaction event;
获取与所述线程的类型对应的内存回收比例,并按照所述内存回收比例对已分配内存空间中的内存页进行回收,其中,所述内存回收比例用于表征多种内存回收对象之间的比例,不同种类的内存回收对象的回收效率不同,线程的优先级越高,则对应的内存回收比例中回收效率高的内存回收对象的占比越大。Obtain a memory recovery ratio corresponding to the type of the thread, and recycle memory pages in the allocated memory space according to the memory recovery ratio, wherein the memory recovery ratio is used to characterize the ratio between multiple memory recovery objects, and different types of memory recovery objects have different recovery efficiencies. The higher the thread priority, the greater the proportion of memory recovery objects with high recovery efficiency in the corresponding memory recovery ratio.
由上可知,本申请实施例提供了一种电子设备,所述电子设备在接收到线程发送的内存分配请求时,先确定当前的空闲内存量,如果空闲内存量小于预设阈值,则要先进行内存回收,接下来对线程的类型进行识别,在内存回收时,根据请求内存的线程的类型的不同,采用不同的内存回收比例进行内存回收,该内存回收比例用于表征多种内存回收对象之间的比例,由于不同种类的内存回收对象的回收效率不同,因此若内存回收比例不同,则整体的回收效率也不相同。其中,第一类线程为执行用户交互事件中相关任务的线程,具有最高优先级,也就是说,第一类线程对应的内存回收比例中回收效率高的内存回收对象的占比在所有类别的线程中为最大占比,因此,对于第一类线程来说,在全部线程中具有最高效率的内存回收机制,可以尽快完成内存回收,提高了第一类线程的内存分配效率,避免第一类线程因为不能及时得到内存而导致出现交互场景下的卡顿现象,提升用户体验。As can be seen from the above, an embodiment of the present application provides an electronic device, which, when receiving a memory allocation request sent by a thread, first determines the current amount of free memory. If the amount of free memory is less than a preset threshold, memory recovery is performed first, and then the type of thread is identified. When memory is recovered, different memory recovery ratios are used for memory recovery according to the type of thread requesting memory. The memory recovery ratio is used to characterize the ratio between multiple memory recovery objects. Since the recovery efficiency of different types of memory recovery objects is different, if the memory recovery ratio is different, the overall recovery efficiency is also different. Among them, the first type of thread is a thread that executes related tasks in a user interaction event and has the highest priority. That is to say, the proportion of memory recovery objects with high recovery efficiency in the memory recovery ratio corresponding to the first type of thread is the largest proportion among all types of threads. Therefore, for the first type of thread, the memory recovery mechanism with the highest efficiency among all threads can complete memory recovery as soon as possible, thereby improving the memory allocation efficiency of the first type of thread, avoiding the jamming phenomenon in the interactive scene caused by the failure of the first type of thread to obtain memory in time, and improving the user experience.
本申请实施例还提供一种存储介质,所述存储介质中存储有计算机程序,当所述计算机程序在计算机上运行时,所述计算机执行上述任一实施例所述的内存回收方法。An embodiment of the present application further provides a storage medium, in which a computer program is stored. When the computer program runs on a computer, the computer executes the memory recovery method described in any of the above embodiments.
需要说明的是,本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步骤是可以通过计算机程序来指令相关的硬件来完成,所述计算机程序可以存储于计算机可读存储介质中,所述存储介质可以包括但不限于:只读存储器(ROM,Read OnlyMemory)、随机存取存储器(RAM,Random Access Memory)、磁盘或光盘等。It should be noted that, those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the storage medium can include but is not limited to: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
此外,本申请中的术语“第一”、“第二”和“第三”等是用于区别不同对象,而不是用于描述特定顺序。此外,术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或模块的过程、方法、系统、产品或设备没有限定于已列出的步骤或模块,而是某些实施例还包括没有列出的步骤或模块,或某些实施例还包括对于这些过程、方法、产品或设备固有的其它步骤或模块。In addition, the terms "first", "second", and "third" in this application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or device that includes a series of steps or modules is not limited to the listed steps or modules, but some embodiments also include steps or modules that are not listed, or some embodiments also include other steps or modules inherent to these processes, methods, products, or devices.
以上对本申请实施例所提供的内存回收方法、装置、存储介质及电子设备进行了详细介绍。本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。The above is a detailed introduction to the memory recovery method, device, storage medium and electronic device provided in the embodiments of the present application. This article uses specific examples to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core ideas of the present application; at the same time, for technicians in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present application.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010628802.2ACN111831440B (en) | 2020-07-01 | 2020-07-01 | Memory recovery method, device, storage medium and electronic device |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010628802.2ACN111831440B (en) | 2020-07-01 | 2020-07-01 | Memory recovery method, device, storage medium and electronic device |
| Publication Number | Publication Date |
|---|---|
| CN111831440A CN111831440A (en) | 2020-10-27 |
| CN111831440Btrue CN111831440B (en) | 2024-10-01 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202010628802.2AActiveCN111831440B (en) | 2020-07-01 | 2020-07-01 | Memory recovery method, device, storage medium and electronic device |
| Country | Link |
|---|---|
| CN (1) | CN111831440B (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113778662B (en)* | 2021-07-28 | 2022-12-06 | 荣耀终端有限公司 | Memory recovery method and device |
| CN114020461B (en)* | 2021-11-03 | 2022-10-11 | 无锡沐创集成电路设计有限公司 | Memory allocation method, system, storage medium and electronic equipment |
| CN114253872B (en)* | 2022-02-28 | 2022-07-12 | 荣耀终端有限公司 | Electronic device and memory recovery method and medium thereof |
| CN117170856A (en)* | 2022-05-28 | 2023-12-05 | 华为技术有限公司 | A memory management method and related devices |
| CN115509951A (en)* | 2022-08-18 | 2022-12-23 | 广东明创软件科技有限公司 | Memory recovery method and device, electronic equipment and storage medium |
| CN117130767B (en)* | 2023-02-08 | 2024-08-16 | 荣耀终端有限公司 | Method for recycling memory, electronic device and storage medium |
| CN116185890B (en)* | 2023-04-23 | 2023-09-19 | 荣耀终端有限公司 | Memory recycling method and electronic equipment |
| CN116225976B (en)* | 2023-05-05 | 2023-08-08 | 麒麟软件有限公司 | Water line self-adjusting method and system under Linux operating system |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109783028A (en)* | 2019-01-16 | 2019-05-21 | Oppo广东移动通信有限公司 | Optimization method, device, storage medium and the intelligent terminal of I/O scheduling |
| CN109992400A (en)* | 2017-12-29 | 2019-07-09 | 广东欧珀移动通信有限公司 | Resource allocation method, device, mobile terminal, and computer-readable storage medium |
| CN110727607A (en)* | 2019-09-27 | 2020-01-24 | Oppo(重庆)智能科技有限公司 | Memory recovery method and device and electronic equipment |
| CN111158910A (en)* | 2019-12-27 | 2020-05-15 | Oppo广东移动通信有限公司 | Memory management method, device, storage medium and electronic device |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5515538A (en)* | 1992-05-29 | 1996-05-07 | Sun Microsystems, Inc. | Apparatus and method for interrupt handling in a multi-threaded operating system kernel |
| US5428789A (en)* | 1993-08-27 | 1995-06-27 | Waldron, Iii; Theodore C. | Method and apparatus for optimizing user response time in a priority preemptive operating system |
| CN110018900B (en)* | 2018-01-10 | 2023-01-24 | Oppo广东移动通信有限公司 | Memory processing method and device, electronic device, computer-readable storage medium |
| CN109213596B (en)* | 2018-08-01 | 2023-03-10 | 青岛海信移动通信技术股份有限公司 | Method and equipment for allocating terminal memory |
| CN111078408B (en)* | 2019-12-10 | 2022-10-21 | Oppo(重庆)智能科技有限公司 | Memory allocation method and device, storage medium and electronic equipment |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109992400A (en)* | 2017-12-29 | 2019-07-09 | 广东欧珀移动通信有限公司 | Resource allocation method, device, mobile terminal, and computer-readable storage medium |
| CN109783028A (en)* | 2019-01-16 | 2019-05-21 | Oppo广东移动通信有限公司 | Optimization method, device, storage medium and the intelligent terminal of I/O scheduling |
| CN110727607A (en)* | 2019-09-27 | 2020-01-24 | Oppo(重庆)智能科技有限公司 | Memory recovery method and device and electronic equipment |
| CN111158910A (en)* | 2019-12-27 | 2020-05-15 | Oppo广东移动通信有限公司 | Memory management method, device, storage medium and electronic device |
| Publication number | Publication date |
|---|---|
| CN111831440A (en) | 2020-10-27 |
| Publication | Publication Date | Title |
|---|---|---|
| CN111831440B (en) | Memory recovery method, device, storage medium and electronic device | |
| CN111831441B (en) | Memory recovery method, device, storage medium and electronic device | |
| CN111813520B (en) | Thread scheduling method, device, storage medium and electronic device | |
| CN111831437B (en) | Device management method and device, storage medium and electronic device | |
| US10067790B2 (en) | Method and apparatus for displaying information to a user and the user optimizing running of the processes | |
| CN111158910B (en) | Memory management method and device, storage medium and electronic equipment | |
| CN111831436B (en) | IO request scheduling method and device, storage medium and electronic equipment | |
| CN111831438B (en) | Resource allocation method, device, storage medium and electronic device | |
| CN111831414A (en) | Thread migration method, device, storage medium and electronic device | |
| CN111831433A (en) | Resource allocation method, device, storage medium and electronic device | |
| CN111831434A (en) | Resource allocation method, device, storage medium and electronic device | |
| CN111831413B (en) | Thread scheduling method, device, storage medium and electronic device | |
| CN111813521B (en) | Thread scheduling method, device, storage medium and electronic device | |
| CN110865888A (en) | Resource loading method and device, server and storage medium | |
| CN113495780B (en) | Task scheduling method and device, storage medium and electronic equipment | |
| CN111831409B (en) | Thread scheduling method, device, storage medium and electronic device | |
| CN111475299B (en) | Memory allocation method and device, storage medium and electronic equipment | |
| CN111831442A (en) | A method, device, storage medium and electronic device for resource allocation | |
| CN111831435A (en) | Memory allocation method, device, storage medium and electronic device | |
| CN113495787A (en) | Resource allocation method, device, storage medium and electronic equipment | |
| CN111831462B (en) | IO request processing method, device, storage medium and electronic device | |
| CN111831411B (en) | Task processing method and device, storage medium and electronic equipment | |
| CN111831432B (en) | IO request scheduling method, device, storage medium and electronic equipment | |
| CN111831439A (en) | IO request processing method, device, storage medium and electronic device | |
| CN111831443A (en) | Processor state adjustment method, device, storage medium and electronic device |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |