CN105843735A - Terminal memory consumption method and apparatus - Google Patents
Terminal memory consumption method and apparatus Download PDFInfo
- Publication number
- CN105843735A CN105843735A CN201610158390.4A CN201610158390A CN105843735A CN 105843735 A CN105843735 A CN 105843735A CN 201610158390 A CN201610158390 A CN 201610158390A CN 105843735 A CN105843735 A CN 105843735A
- Authority
- CN
- China
- Prior art keywords
- memory
- terminal
- threshold value
- processes
- low
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 217
- 238000004140 cleaning Methods 0.000 claims description 3
- 238000010586 diagram Methods 0.000 description 3
- 230000000694 effects Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 2
- 230000006870 function Effects 0.000 description 2
- 230000007246 mechanism Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 238000009434 installation Methods 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3698—Environments for analysis, debugging or testing of software
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Telephone Function (AREA)
Abstract
一种终端内存的消耗方法,包括:创建n个进程,所述n个进程中的第i+1进程由第i进程创建,n为不小于2的正整数,i为小于n的正整数;利用所述n个进程共同消耗终端的内存,使所述终端处于低内存状态。还提供相应的装置。该技术方案可以使终端快速达到低内存状态且稳定的处于低内存状态。
A method for consuming terminal memory, comprising: creating n processes, wherein the i+1th process among the n processes is created by the i-th process, n is a positive integer not less than 2, and i is a positive integer smaller than n; The terminal is in a low-memory state by using the n processes to jointly consume the memory of the terminal. Corresponding devices are also provided. The technical solution can make the terminal quickly reach the low memory state and be stably in the low memory state.
Description
技术领域technical field
本发明涉及终端技术领域,具体涉及一种终端内存的消耗方法及装置。The present invention relates to the technical field of terminals, in particular to a terminal memory consumption method and device.
背景技术Background technique
目前,手机的发展非常迅捷,随着手机内存越来越大,手机的性能也越来越好。为了保证手机的性能,通常需要对手机做各种测试。其中,有时候,需要使手机处于低内存状态,以便于做相关的低内存测试。At present, the development of mobile phones is very fast. As the memory of mobile phones becomes larger and larger, the performance of mobile phones is also getting better and better. In order to ensure the performance of the mobile phone, it is usually necessary to perform various tests on the mobile phone. Among them, sometimes, it is necessary to make the mobile phone in a low-memory state, so as to do related low-memory tests.
目前,通常采用在手机中安装和运行大量的app(application,应用程序),例如在采用安卓(Android)平台的手机中安装和运行大量apk(AndroidPackage,安卓安装包),来消耗Android平台的内存,使手机处于低内存状态。At present, it is usual to install and run a large amount of app (application, application program) in the mobile phone, such as installing and running a large amount of apk (Android Package, Android installation package) in a mobile phone using the Android (Android) platform, to consume the memory of the Android platform , put the phone in a low memory state.
实践发现,这种方法过程繁琐,耗时较长,且不稳定。Practice has found that this method is cumbersome, time-consuming, and unstable.
发明内容Contents of the invention
本发明实施例提供一种终端内存的消耗方法及装置,以使终端快速达到低内存状态且稳定的处于低内存状态。Embodiments of the present invention provide a terminal memory consumption method and device, so that the terminal quickly reaches a low memory state and remains in a low memory state stably.
为解决上述技术问题及达到上述有益效果,本发明提供一种终端内存的消耗方法,包括:创建n个进程,所述n个进程中的第i+1进程由第i进程创建,n为不小于2的正整数,i为小于n的正整数;利用所述n个进程共同消耗终端的内存,使所述终端处于低内存状态。In order to solve the above-mentioned technical problems and achieve the above-mentioned beneficial effects, the present invention provides a terminal memory consumption method, including: creating n processes, the i+1th process in the n processes is created by the i-th process, and n is not A positive integer less than 2, i is a positive integer less than n; using the n processes to jointly consume the memory of the terminal, so that the terminal is in a low memory state.
本发明还提供一种装置,包括:进程创建模块,用于创建n个进程,所述n个进程中的第i+1进程由第i进程创建,n为不小于2的正整数,i为小于n的正整数;内存管理模块,用于利用所述n个进程共同消耗终端的内存,使所述终端处于低内存状态。The present invention also provides a device, including: a process creation module, used to create n processes, the i+1th process among the n processes is created by the i-th process, n is a positive integer not less than 2, and i is A positive integer smaller than n; a memory management module, configured to use the n processes to jointly consume the memory of the terminal, so that the terminal is in a low-memory state.
本发明还提供一种存储一个或多个程序的存储器,当所述一个或多个程序被包括一个或多个处理器的终端执行时,使所述终端执行如上文所述的终端内存的消耗方法。The present invention also provides a memory for storing one or more programs which, when executed by a terminal comprising one or more processors, cause the terminal to perform the terminal memory consumption described above. method.
本发明还提供一种终端,包括:一个或多个处理器;存储器;收发器;所述处理器与存储器通过总线连接,当所述终端运行时,所述处理器执行所述存储器存储的程序,以使所述终端执行如上文所述的终端内存的消耗方法。The present invention also provides a terminal, including: one or more processors; a memory; a transceiver; the processor is connected to the memory through a bus, and when the terminal is running, the processor executes the program stored in the memory , so that the terminal executes the method for consuming terminal memory as described above.
相对现有技术,本发明一些可行的实施方式中,终端可以创建n个进程,且n个进程中的第i+1进程由第i进程创建,即,这n个进程是由第1个创建第2个,第2个创建第3个,直到第n个,也就是说,这n个进程为链式父子进程,这样,一方面,可以使终端快速的达到低内存状态,且方案实现简单;另一方面,可以极大降低一些进程被终端安卓平台的low memory killer(低内存清理)杀死的风险,可以使终端稳定的处于低内存状态。Compared with the prior art, in some feasible implementations of the present invention, the terminal can create n processes, and the i+1th process among the n processes is created by the i-th process, that is, the n processes are created by the first The second one, the second one creates the third one, until the nth one, that is to say, these n processes are chained parent-child processes, so that, on the one hand, the terminal can quickly reach a low memory state, and the solution is simple to implement ; On the other hand, it can greatly reduce the risk of some processes being killed by the low memory killer (low memory cleanup) of the terminal Android platform, and can keep the terminal in a low memory state stably.
附图说明Description of drawings
为了更清楚地说明本发明实施例技术方案,下面将对现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the accompanying drawings that need to be used in the description of the prior art. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For Those of ordinary skill in the art can also obtain other drawings based on these drawings without making creative efforts.
图1是本发明实施例提供的终端内存的消耗方法的流程示意图;FIG. 1 is a schematic flowchart of a terminal memory consumption method provided by an embodiment of the present invention;
图2是本发明实施例中终端创建进程的具体流程图;Fig. 2 is the specific flowchart of terminal creation process in the embodiment of the present invention;
图3是本发明实施例的一个测试效果图;Fig. 3 is a test effect figure of the embodiment of the present invention;
图4是本发明实施例提供的终端内存的消耗装置的结构示意图;FIG. 4 is a schematic structural diagram of a terminal memory consumption device provided by an embodiment of the present invention;
图5是本发明实施例提供的终端的结构示意图。FIG. 5 is a schematic structural diagram of a terminal provided by an embodiment of the present invention.
具体实施方式detailed description
为了使本技术领域的人员更好地理解本发明方案,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分的实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本发明保护的范围。In order to enable those skilled in the art to better understand the solutions of the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only It is an embodiment of a part of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present invention.
如背景技术部分所述,目前,通常采用在手机中安装和运行大量的app,例如在采用Android平台的手机中安装和运行大量apk,来消耗Android平台的内存,使手机处于低内存状态。As described in the background technology section, at present, a large number of apps are usually installed and run in a mobile phone, for example, a large number of apks are installed and run in a mobile phone using the Android platform to consume the memory of the Android platform and make the mobile phone in a low-memory state.
然而,Android有一套内存管理机制,在手机可用内存低于某一阈值时,就会触发low memory killer(低内存清理)机制来清理一些优先级较低的进程,以释放内存。具体来说,Android是一个多任务系统,也就是说可以同时运行多个程序;一般来说,启动运行一个程序是有一定的时间开销的,因此为了加快运行速度,当退出一个程序时,Android并不会立即杀掉它,这样下次再运行该程序时,可以很快的启动;随着系统中保留的程序越来越多,内存肯定会出现不足,low memory killer就是在系统内存低于某一阈值时,清除相关的程序,保障系统保持拥有一定数量的空闲内存。However, Android has a set of memory management mechanisms. When the available memory of the mobile phone is lower than a certain threshold, it will trigger the low memory killer (low memory cleaning) mechanism to clean up some processes with lower priority to release memory. Specifically, Android is a multitasking system, which means it can run multiple programs at the same time; generally speaking, starting and running a program has a certain time overhead, so in order to speed up the operation, when exiting a program, Android It will not kill it immediately, so that the next time you run the program, it can be started quickly; as more and more programs are reserved in the system, there will definitely be insufficient memory. Low memory killer is when the system memory is lower than When a certain threshold is reached, related programs are cleared to ensure that the system maintains a certain amount of free memory.
Low memory killer根据两个原则,进程的重要性和释放这个进程可获取的空闲内存数量,来决定释放的进程。每个程序都会有一个oom_adj值,这个值越小,程序越重要,被杀的可能性越低。另外,在相同的oom_adj下,内存大的进程,优先被杀。Low memory killer decides the process to release based on two principles, the importance of the process and the amount of free memory that can be obtained by releasing the process. Each program will have an oom_adj value, the smaller the value, the more important the program and the lower the possibility of being killed. In addition, under the same oom_adj, processes with large memory are killed first.
因此,采用现有技术在Android平台中安装和运行大量apk,当消耗内存较多时,不可避免的,其中一些apk进程会被杀死,这些apk的内存会被释放,这就导致,通过运行大量apk使手机处于低内存状态的过程中,会出现进程被杀死再被运行的反复问题,过程比较繁琐,到达低内存状态的耗时较长,且一旦有进程被杀死可能就会退出低内存状态,导致低内存状态不稳定。Therefore, when a large number of apks are installed and run on the Android platform using existing technologies, when a large amount of memory is consumed, it is inevitable that some of the apk processes will be killed, and the memory of these apks will be released, which leads to running a large number of apks When the apk keeps the phone in a low-memory state, there will be repeated problems of processes being killed and then re-run. The process is cumbersome, and it takes a long time to reach the low-memory state. Once a process is killed, it may exit the low-memory state. memory state, resulting in an unstable low memory state.
为解决上述问题,本发明实施例提供一种终端内存的消耗方法和相应的装置,以使终端快速达到低内存状态且稳定的处于低内存状态。In order to solve the above problems, an embodiment of the present invention provides a terminal memory consumption method and a corresponding device, so that the terminal quickly reaches a low memory state and remains in a low memory state stably.
下面通过具体实施例,分别进行详细的说明。In the following, specific examples will be used to describe in detail respectively.
实施例一、Embodiment one,
请参考图1,本发明实施例提供一种终端内存的消耗方法,该方法尤其适用于采用安卓平台的终端,例如手机或平板电脑等,所述方法可包括:Please refer to FIG. 1 , an embodiment of the present invention provides a method for consuming terminal memory, which is especially suitable for a terminal using an Android platform, such as a mobile phone or a tablet computer. The method may include:
110、创建n个进程,所述n个进程中的第i+1进程由第i进程创建,n为不小于2的正整数,i为小于n的正整数;110. Create n processes, the i+1th process among the n processes is created by the i-th process, n is a positive integer not less than 2, and i is a positive integer smaller than n;
120、利用所述n个进程共同消耗终端的内存,使所述终端处于低内存状态。120. Use the n processes to jointly consume memory of the terminal, so that the terminal is in a low memory state.
其中,所述进程用于消耗内存,也可以称为内存消耗进程。Wherein, the process is used to consume memory, and may also be referred to as a memory consumption process.
可选的,一些实施例中,所述n个进程为native程序的进程;其它一些实施例中,所述n个进程也可以是其它程序的进程。Optionally, in some embodiments, the n processes are processes of a native program; in some other embodiments, the n processes may also be processes of other programs.
可选的,所述n个native程序的执行路径可以在具有shell权限的目录,例如采用Android平台的终端的/data/local/tmp目录,该目录为shell权限的目录。Optionally, the execution paths of the n native programs may be in a directory with shell authority, such as the /data/local/tmp directory of a terminal using the Android platform, which is a directory with shell authority.
Android的每个目录都是有相应权限的,比如root(根源,最高)权限、system(系统)权限、shell(壳)权限等等。上面举例的/data/local/tmp目录的权限是shell权限,shell权限很低,通常任何数据都可以放进去,包括用adb(AndroidDebug Bridge,安卓调试桥)push(推送)进去,所以选择shell权限的目录,常规的手机等终端都可以实现。Each directory of Android has corresponding permissions, such as root (root, highest) permissions, system (system) permissions, shell (shell) permissions, and so on. The permissions of the /data/local/tmp directory in the example above are shell permissions, and the shell permissions are very low. Usually, any data can be put in, including push (push) with adb (AndroidDebug Bridge, Android Debug Bridge), so choose shell permissions The directory, conventional mobile phones and other terminals can be realized.
当然,所述n个native程序的执行路径也可以放到其他目录。如果终端进行了root,获得了更高的root权限,那么,native程序的执行路径也可以在具有root权限的目录,例如system/bin目录。Of course, the execution paths of the n native programs can also be placed in other directories. If the terminal has been rooted and obtained a higher root authority, then the execution path of the native program can also be in a directory with root authority, such as the system/bin directory.
或者,native程序的执行路径还可以在具有system权限的目录。Alternatively, the execution path of the native program can also be in a directory with system permissions.
可选的,可以利用所述n个进程中的每个进程占用终端内存中的pM内存,p的取值越小,进程被low memory killer杀死的风险就越小,但为了提高效率,p的取值又不能太小,优选的,可以取p=30,即,为每个进程分配30M内存,或者,也可以30附近的值例如20或25等。Optionally, each of the n processes can be used to occupy pM memory in the terminal memory. The smaller the value of p, the smaller the risk of the process being killed by the low memory killer, but in order to improve efficiency, p The value of p cannot be too small. Preferably, p=30 can be used, that is, 30M memory is allocated for each process, or a value near 30 such as 20 or 25 can also be used.
可选的,在所述终端处于低内存状态时,即可进行低内存相关的测试。Optionally, when the terminal is in a low-memory state, low-memory-related tests can be performed.
由上可见,本发明实施例方法中,采用的技术手段主要包括:As can be seen from the above, in the method of the embodiment of the present invention, the technical means adopted mainly include:
(1)所述进程可以为native程序的进程,也就是说,执行个体是native程序。(1) The process may be a process of a native program, that is, the execution entity is a native program.
Android系统的实现可以分为多个层,包括:Java应用程序,Java框架层,native(本地框架)层,内核层即Linux内核空间等。native层这部分常见一些本地服务和一些链接库等。native的一个特点就是一般通过C和C++语言实现。比如要执行一个复杂运算,如果通过java代码去实现,那么效率会非常低,此时可以选择通过C或C++代码去实现,然后和上层的Java代码通信。又比如终端需要运行,那么必然要和底层的硬件驱动交互,也要通过native层。The implementation of the Android system can be divided into multiple layers, including: Java application program, Java framework layer, native (local framework) layer, kernel layer, namely Linux kernel space, etc. Some local services and some link libraries are common in the native layer. A feature of native is that it is generally implemented in C and C++ languages. For example, to perform a complex operation, if it is implemented through java code, the efficiency will be very low. At this time, you can choose to implement it through C or C++ code, and then communicate with the upper-level Java code. Another example is that if the terminal needs to run, it must interact with the underlying hardware driver and pass through the native layer.
由于native程序介于内核与java程序之间,因此,native程序具有可控性、独立性和稳定性等特点,有助于快速、稳定的进行内存消耗。当然,本文中并不限制所述进程的程序类型,具体实现中,也可以采用其它类型程序的进程。Since the native program is between the kernel and the java program, the native program has the characteristics of controllability, independence and stability, which is helpful for fast and stable memory consumption. Of course, the program type of the process is not limited herein, and other types of program processes may also be used in specific implementation.
(2)native程序的执行路径可以在/data/local/tmp目录,此目录为shell权限,这样就可以在Android user(用户)版本使用。(2) The execution path of the native program can be in the /data/local/tmp directory, which has shell permissions, so it can be used in the Android user (user) version.
Android分为user(用户)与eng(工程)至少两种版本。普通用户使用的一般就是Android user版本。由于native程序的执行路径一般在/data/local/tmp目录,而此目录为shell权限。Shell俗称壳,用来区别于核,是指“提供使用者使用界面”的软件(命令解析器)。由于具有shell权限,这样,本发明实施例采用native程序的进程来消耗内存的方案就可以在Android user版本使用了,从而方便对普通的安卓终端进行低内存检测。Android is divided into at least two versions: user (user) and eng (engineering). Ordinary users generally use the Android user version. Because the execution path of the native program is generally in the /data/local/tmp directory, and this directory has shell permissions. Shell is commonly known as the shell, which is used to distinguish it from the core, and refers to software (command parser) that "provides a user interface". Due to the shell authority, the solution of the embodiment of the present invention to consume memory by the process of the native program can be used in the Android user version, so as to facilitate low-memory detection on common Android terminals.
(3)多个进程共同耗尽指定内存,分摊被low memory killer杀死的风险。(3) Multiple processes jointly exhaust the specified memory and share the risk of being killed by the low memory killer.
本发明实施例中,采用多个进程共同消耗内存,可以分摊被low memorykiller杀死的风险。In the embodiment of the present invention, multiple processes are used to jointly consume memory, and the risk of being killed by the low memory killer can be shared.
(4)内存消耗进程为链式父子进程,降低被low memory killer杀死的风险。(4) The memory consumption process is a chained parent-child process, reducing the risk of being killed by the low memory killer.
本发明实施例中,用于消耗内存的n个进程中,第1进程产生第2进程,第2进程产生第3进程,…第i进程产生第i+1进程…,或者说,进程A产生进程B,进程B产生进程C,进程C产生进程D,以此类推,所有的n个进程为链式父子进程,彼此互相关,重要性基本相同,各个进程的oom_adj值基本相同,没有oom_adj值特别低的进程,从而,可以大大降低被low memory killer杀死的风险。需要说明的是,Android的每个程序都会有一个oom_adj值,这个值越小,程序越重要,被杀的可能性越低。In the embodiment of the present invention, among the n processes used to consume memory, the first process generates the second process, the second process generates the third process, ...the i-th process generates the i+1-th process..., or, process A generates Process B, process B generates process C, process C generates process D, and so on, all n processes are chained parent-child processes, interrelated with each other, and the importance is basically the same. The oom_adj value of each process is basically the same, and there is no oom_adj value Especially low memory processes, thus, can greatly reduce the risk of being killed by the low memory killer. It should be noted that each Android program will have an oom_adj value, the smaller the value, the more important the program and the lower the possibility of being killed.
(5)每个内存消耗进程通过分配pM内存来占用终端内存,优选p=30。(5) Each memory consumption process occupies the terminal memory by allocating pM memory, preferably p=30.
本发明实施例优选方案中,每个进程消耗的内存可以是基本相等的,例如为每个进程分配30M内存,或者说,每个进程占用终端内存中的30M内存,这样,避免部分进程由于内存占用较大而容易被杀死,多个进程可以分摊被lowmemory killer杀死的风险。In the preferred solution of the embodiment of the present invention, the memory consumed by each process can be basically equal, for example, allocate 30M memory for each process, or in other words, each process occupies 30M memory in the terminal memory. It takes up a lot and is easy to be killed. Multiple processes can share the risk of being killed by the lowmemory killer.
请参考图2,本发明一些实施例中,终端创建n个进程的具体流程图,包括:Please refer to FIG. 2, in some embodiments of the present invention, the specific flow chart of the terminal creating n processes, including:
S1、获取预先设定的阈值desired_size(所需的大小);desired_size表示最终需要的内存大小,也就是说,运行n个进程后的空闲内存的大小。S1. Obtain a preset threshold desired_size (required size); desired_size represents the final required memory size, that is, the size of free memory after running n processes.
可选的,所述阈值默认为low memory killer的阈值。不同的终端中,lowmemory killer的阈值可能是不同的。Optionally, the threshold defaults to the threshold of the low memory killer. In different terminals, the threshold of lowmemory killer may be different.
S2、判断当前的空闲内存是否大于所述阈值,若是,则进入步骤S3,否则结束;S2, judging whether the current free memory is greater than the threshold, if so, then enter step S3, otherwise end;
本步骤中,判断当前的空闲内存(Free_RAMSize)是否大于阈值desired_size,即,判断Free_RAMSize>desired_size是否成立,如果成立,说明空闲内存过大,尚未到达低内存状态,则需要进入步骤S3创建内存消耗进程。In this step, determine whether the current free memory (Free_RAMSize) is greater than the threshold desired_size, that is, determine whether Free_RAMSize>desired_size is true, if true, it means that the free memory is too large and has not yet reached the low memory state, and you need to enter step S3 to create a memory consumption process .
反之,如果判断当前的空闲内存不大于所述阈值,说明空闲内存较小,已经到达低内存状态,不需要再消耗内存,因此不必再继续创建内存消耗进程,流程至此即可结束。Conversely, if it is judged that the current free memory is not greater than the threshold, it means that the free memory is small and has reached a low memory state, and there is no need to consume memory, so there is no need to continue to create a memory consumption process, and the process ends here.
S3、创建进程,包括:在当前没有进程时,创建第1进程;在当前已有第i进程时,利用当前的第i进程创建第i+1进程。S3. Create a process, including: when there is no process currently, create a first process; when there is an i-th process, use the current i-th process to create an i+1-th process.
本步骤中,创建内存,容易理解,在当前没有进程时,终端创建第1进程;在当前已经有进程,且当前进程为第i进程时,则利用当前的第i进程创建第i+1进程,以实现链式父子进程的创建。其中,每创建一个进程后,例如创建第1进程或第i+1进程后,第1进程或第i+1进程可以通过例如malloc函数向Android系统申请一定量的内存例如30M内存。In this step, memory is created, which is easy to understand. When there is no current process, the terminal creates the first process; when there is already a process and the current process is the i-th process, the current i-th process is used to create the i+1-th process , to realize the creation of chained parent-child processes. Wherein, after each process is created, for example, after the 1st process or the i+1th process is created, the 1st process or the i+1th process can apply for a certain amount of memory, such as 30M memory, to the Android system through, for example, a malloc function.
本步骤完成一个进程的创建后,返回步骤S2,通过判断当前的空闲内存来判断是否已经处于低内存状态,根据判断结果继续流程,整个流程是一个while()循环流程,最终判断终端处于低内存状态时,结束流程。然后,即可开始进行各种低内存相关的测试了。After the creation of a process is completed in this step, return to step S2, judge whether it is already in a low memory state by judging the current free memory, and continue the process according to the judgment result. The whole process is a while () loop process, and finally judge that the terminal is in a low memory state state, end the process. Then, you can start various low memory related tests.
需要说明的是,当上述阈值过小时,如果继续创建的进程的内存过大,有可能使整个手机的剩余内存变为0,导致手机死机或卡死。为了避免该情况,可选的,本发明实施例中可以设定一个最小值例如100M,步骤S2中判断当前的空闲内存大于所述阈值时,还进一步判断当前的空闲内存是否大于100M,如果是,才进入步骤S3,否则结束。也就是说,要同时满足以下两个关系式:It should be noted that when the above threshold is too small, if the memory of the process that continues to be created is too large, the remaining memory of the entire mobile phone may become 0, causing the mobile phone to crash or freeze. In order to avoid this situation, optionally, a minimum value such as 100M can be set in the embodiment of the present invention. When it is judged in step S2 that the current free memory is greater than the threshold, it is further judged whether the current free memory is greater than 100M. , enter step S3, otherwise end. That is to say, the following two relations must be satisfied at the same time:
Free_RAMSize>desired_size;Free_RAMSize>desired_size;
Free_RAMSize>100M;Free_RAMSize>100M;
才进入步骤S3,创建内存消耗进程。Then enter step S3, create a memory consumption process.
这样可以避免整个手机的内存被完全消耗导致死机或卡死。This can prevent the memory of the entire mobile phone from being completely consumed and cause the system to crash or freeze.
需要说明的是,上述设为100M的最小值仅为示例,实际应用中,也可以更改为其它值例如150M,或者120M等等。It should be noted that the above-mentioned minimum value of 100M is only an example, and in practical applications, it can also be changed to other values such as 150M or 120M.
本文中,还示出了对本发明实施例技术方案的验证结果:In this paper, the verification results of the technical solutions of the embodiments of the present invention are also shown:
请参考图3所示的测试效果图,在一个应用例中,假设mvg_app为内存消耗进程的名字,则最终达到的效果如图3所示。图3中:第一个虚线框为内存消耗进程的进程id;第二个虚线框为内存消耗进程的父进程id;第三个虚线框为每个内存消耗进程的占用内存的大小,大概为30M。可见,可以轻易的使手机达到且稳定的处于低内存状态。Please refer to the test effect diagram shown in Figure 3. In an application example, assuming that mvg_app is the name of the memory-consuming process, the final effect is shown in Figure 3. In Figure 3: the first dotted box is the process id of the memory consuming process; the second dotted box is the parent process id of the memory consuming process; the third dotted box is the size of memory occupied by each memory consuming process, approximately 30M. It can be seen that the mobile phone can be easily reached and stabilized in a low memory state.
可以理解,本发明实施例上述方案例如可以在手机等终端设备具体实施。It can be understood that the above solutions of the embodiments of the present invention can be specifically implemented in terminal devices such as mobile phones, for example.
综上,相对现有技术,本发明一些可行的实施方式中,终端创建n个进程,且n个进程中的第i+1进程由第i进程创建,即,这n个进程是由第1个创建第2个,第2个创建第3个,直到第n个,也就是说,这n个进程为链式父子进程,这样,一方面,可以使终端快速的达到低内存状态,且方案实现简单;另一方面,可以极大降低一些进程被终端安卓平台的low memory killer杀死的概率,可以使终端稳定的处于低内存状态;再一方面,所述进程可以是native程序的进程,这样整个方案可应用于Android user版本。To sum up, compared with the prior art, in some feasible implementations of the present invention, the terminal creates n processes, and the i+1th process among the n processes is created by the ith process, that is, the n processes are created by the 1st One creates the second one, the second one creates the third one, until the nth one, that is to say, these n processes are chained parent-child processes, so that, on the one hand, the terminal can quickly reach the low memory state, and the scheme The implementation is simple; on the other hand, it can greatly reduce the probability of some processes being killed by the low memory killer of the terminal Android platform, and can make the terminal stably in a low memory state; on the other hand, the process can be a process of a native program, This whole scheme can be applied to the Android user version.
为了更好的实施本发明实施例的上述方案,下面还提供用于配合实施上述方案的相关装置。In order to better implement the above solutions of the embodiments of the present invention, related devices for coordinating the implementation of the above solutions are also provided below.
实施例二、Embodiment two,
请参考图4,本发明实施例提供一种终端内存的消耗装置,可包括:Please refer to FIG. 4, an embodiment of the present invention provides a device for consuming terminal memory, which may include:
进程创建模块410,用于创建n个进程,所述n个进程中的第i+1进程由第i进程创建,n为不小于2的正整数,i为小于n的正整数;A process creation module 410, configured to create n processes, the i+1th process in the n processes is created by the i-th process, n is a positive integer not less than 2, and i is a positive integer smaller than n;
内存管理模块420,用于利用所述n个进程共同消耗终端的内存,使所述终端处于低内存状态。The memory management module 420 is configured to use the n processes to jointly consume the memory of the terminal, so that the terminal is in a low memory state.
在本发明一些实施例中,所述n个进程为native程序的进程。In some embodiments of the present invention, the n processes are native program processes.
在本发明一些实施例中,所述native程序的执行路径在具有shell权限的目录。In some embodiments of the present invention, the execution path of the native program is in a directory with shell authority.
在本发明一些实施例中,所述进程创建模块410包括:In some embodiments of the present invention, the process creation module 410 includes:
获取单元,用于获取预先设定的阈值;an acquisition unit, configured to acquire a preset threshold;
判断单元,用于判断当前的空闲内存是否大于所述阈值,若是,则指示创建单元创建进程,否则结束;A judgment unit, configured to judge whether the current free memory is greater than the threshold, if so, instruct the creation unit to create a process, otherwise end;
所述创建单元,用于在所述判断单元判断为是时创建进程,包括:在当前没有进程时,创建第1进程;在当前已有第i进程时,利用当前的第i进程创建第i+1进程。The creating unit is used to create a process when the judging unit judges yes, including: creating a first process when there is no process currently; creating an i-th process using the current i-th process when there is an i-th process currently +1 for the process.
在本发明一些实施例中,所述判断单元,具体用于判断当前的空闲内存是否大于所述阈值,若是,则进一步判断当前的空闲内存是否大于100M,若是,则指示创建单元创建进程,否则结束,其中,所述阈值为low memory killer的阈值。In some embodiments of the present invention, the judging unit is specifically used to judge whether the current free memory is greater than the threshold, if so, then further judge whether the current free memory is greater than 100M, if so, instruct the creation unit to create a process, otherwise end, wherein the threshold is the threshold of the low memory killer.
本发明实施例终端内存的消耗装置例如可以是手机等终端设备或者可以是终端设备上运行的功能实体。The device for consuming terminal memory in this embodiment of the present invention may be, for example, a terminal device such as a mobile phone, or may be a functional entity running on the terminal device.
可以理解,本发明实施例的终端内存的消耗装置的各个功能模块的功能可根据上述方法实施例中的方法具体实现,其具体实现过程可参照上述方法实施例中的相关描述,此处不再赘述。It can be understood that the functions of each functional module of the device for consuming terminal memory in the embodiment of the present invention can be specifically implemented according to the method in the above method embodiment, and the specific implementation process can refer to the relevant description in the above method embodiment, and will not be repeated here. repeat.
由上可见,在本发明的一些可行的实施方式中,终端创建n个进程,且n个进程中的第i+1进程由第i进程创建,即,这n个进程是由第1个创建第2个,第2个创建第3个,直到第n个,也就是说,这n个进程为链式父子进程,这样,一方面,可以使终端快速的达到低内存状态,且方案实现简单;另一方面,可以极大降低一些进程被终端安卓平台的low memory killer杀死的概率,可以使终端稳定的处于低内存状态;再一方面,所述进程可以是native程序的进程,这样整个方案可应用于Android user版本。It can be seen from the above that in some feasible implementation manners of the present invention, the terminal creates n processes, and the i+1th process among the n processes is created by the i-th process, that is, the n processes are created by the first The second one, the second one creates the third one, until the nth one, that is to say, these n processes are chained parent-child processes, so that, on the one hand, the terminal can quickly reach a low memory state, and the solution is simple to implement ; On the other hand, it can greatly reduce the probability that some processes are killed by the low memory killer of the terminal Android platform, and can make the terminal stably in a low memory state; on the other hand, the process can be a process of a native program, so that the entire The scheme can be applied to the Android user version.
实施例三、Embodiment three,
本发明实施例还提供一种存储一个或多个程序的存储器,所述一个或多个程序包括执行如上述实施例所述的终端内存的消耗的指令,当所述一个或多个程序被包括一个或多个处理器的终端执行时,使所述终端执行如上文实施例所述的终端内存的消耗。An embodiment of the present invention also provides a memory for storing one or more programs, the one or more programs include instructions for executing the terminal memory consumption described in the above embodiments, when the one or more programs are included When the terminals of one or more processors are executed, the terminals are executed to consume terminal memory as described in the above embodiments.
实施例四、Embodiment four,
请参考图5,本发明实施例还提供一种终端500,该终端500可包括:Please refer to FIG. 5 , the embodiment of the present invention also provides a terminal 500, which may include:
一个或多个处理器501;存储器502;总线504;收发器505;以及一个或多个程序503,其中所述一个或多个程序被存储在所述存储器502中并被配置为被所述一个或多个处理器501执行,所述一个或多个程序503包括用于执行如上文方法实施例所述的终端内存的消耗方法。其中,所述处理器501与存储器502可通过总线504连接。当所述终端500运行时,所述处理器501执行所述存储器502存储的所述程序503,以使所述终端500执行如上文方法实施例所述的终端内存的消耗方法。One or more processors 501; memory 502; bus 504; transceiver 505; and one or more programs 503, wherein the one or more programs are stored in the memory 502 and configured to be used by the one or a plurality of processors 501, and the one or more programs 503 include a method for consuming terminal memory as described in the method embodiment above. Wherein, the processor 501 and the memory 502 may be connected through a bus 504 . When the terminal 500 is running, the processor 501 executes the program 503 stored in the memory 502, so that the terminal 500 executes the method for consuming terminal memory as described in the method embodiment above.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详细描述的部分,可以参见其它实施例的相关描述。In the foregoing embodiments, the descriptions of each embodiment have their own emphases, and for parts not described in detail in a certain embodiment, reference may be made to relevant descriptions of other embodiments.
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本发明并不受所描述动作顺序的限制,因为依据本发明,某些步骤可以采用其它顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本发明所必须的。It should be noted that for the foregoing method embodiments, for the sake of simple description, they are expressed as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because Certain steps may be performed in other orders or simultaneously in accordance with the present invention. Secondly, those skilled in the art should also know that the embodiments described in the specification belong to preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步骤是可以通过程序来指令相关的硬件来完成,该程序可以存储于一计算机可读存储介质中,存储介质可以包括:ROM、RAM、磁盘或光盘等。Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above-mentioned embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, and the storage medium can include: ROM, RAM, disk or CD, etc.
以上对本发明实施例所提供的终端内存的消耗方法及装置进行了详细介绍,本文中应用了具体个例对本发明的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本发明的方法及其核心思想;同时,对于本领域的一般技术人员,依据本发明的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本发明的限制。The method and device for consuming terminal memory provided by the embodiments of the present invention are described above in detail. In this paper, specific examples are used to illustrate the principle and implementation of the present invention. The descriptions of the above embodiments are only used to help understand the present invention. method and its core idea; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation and scope of application. In summary, the content of this specification should not be understood as Limitations on the Invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610158390.4A CN105843735B (en) | 2016-03-18 | 2016-03-18 | A kind of consumption method and device of terminal memory |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610158390.4A CN105843735B (en) | 2016-03-18 | 2016-03-18 | A kind of consumption method and device of terminal memory |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105843735A true CN105843735A (en) | 2016-08-10 |
CN105843735B CN105843735B (en) | 2018-12-11 |
Family
ID=56588383
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610158390.4A Active CN105843735B (en) | 2016-03-18 | 2016-03-18 | A kind of consumption method and device of terminal memory |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105843735B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106844136A (en) * | 2016-12-06 | 2017-06-13 | 北京智能管家科技有限公司 | The collection method and system of a kind of program crashing information |
CN112702576A (en) * | 2020-12-24 | 2021-04-23 | 浙江赫千电子科技有限公司 | Data acquisition plug-flow display method for vehicle-mounted video |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20110004883A1 (en) * | 2009-06-30 | 2011-01-06 | International Business Machines Corporation | Method and System for Job Scheduling |
CN102768637A (en) * | 2011-05-05 | 2012-11-07 | 阿里巴巴集团控股有限公司 | Method and device for controlling test execution |
CN103455416A (en) * | 2013-07-18 | 2013-12-18 | 北京航空航天大学 | Pressure test method based on Android system intelligent device memory usage and CPU |
-
2016
- 2016-03-18 CN CN201610158390.4A patent/CN105843735B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20110004883A1 (en) * | 2009-06-30 | 2011-01-06 | International Business Machines Corporation | Method and System for Job Scheduling |
CN102768637A (en) * | 2011-05-05 | 2012-11-07 | 阿里巴巴集团控股有限公司 | Method and device for controlling test execution |
CN103455416A (en) * | 2013-07-18 | 2013-12-18 | 北京航空航天大学 | Pressure test method based on Android system intelligent device memory usage and CPU |
Non-Patent Citations (1)
Title |
---|
I AM V.V: "Android低内存模拟", 《HEWWCN.FARBOX.COM/POST/TECH/ANDROIDDI-NEI-CUN-MO-NI》 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106844136A (en) * | 2016-12-06 | 2017-06-13 | 北京智能管家科技有限公司 | The collection method and system of a kind of program crashing information |
CN112702576A (en) * | 2020-12-24 | 2021-04-23 | 浙江赫千电子科技有限公司 | Data acquisition plug-flow display method for vehicle-mounted video |
Also Published As
Publication number | Publication date |
---|---|
CN105843735B (en) | 2018-12-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111768006B (en) | Training method, device, equipment and storage medium for artificial intelligent model | |
Miao et al. | Spotserve: Serving generative large language models on preemptible instances | |
US9292359B2 (en) | System and method for memory management | |
CN109995677B (en) | Resource allocation method, device and storage medium | |
US8904386B2 (en) | Running a plurality of instances of an application | |
US11520633B2 (en) | Thread associated memory allocation and memory architecture aware allocation | |
CN110750336A (en) | OpenStack virtual machine memory hot-expanding method | |
CN108509280B (en) | A local scheduling method of distributed computing cluster based on push model | |
CN110580195A (en) | Memory allocation method and device based on memory hot plug | |
US8966212B2 (en) | Memory management method, computer system and computer readable medium | |
CN111666210A (en) | Chip verification method and device | |
CN105138405A (en) | To-be-released resource list based MapReduce task speculation execution method and apparatus | |
CN113419715A (en) | Dynamic memory management method and device based on linked list | |
JP2010102513A (en) | Information processing apparatus and memory management method | |
CN105843735B (en) | A kind of consumption method and device of terminal memory | |
CN112685174A (en) | Container creation method, device, equipment and medium | |
CN104281587A (en) | Connection establishing method and device | |
EP2854036B1 (en) | Storage space mapping method and device | |
CN114610484B (en) | Network simulation method and device for distributed AI cluster | |
KR101558807B1 (en) | Processor scheduling method for the cooperation processing between host processor and cooperation processor and host processor for performing the method | |
CN114116068A (en) | Service starting optimization method and device, electronic equipment and readable storage medium | |
CN106528254A (en) | APP rapid loading method | |
CN113742646A (en) | Compiling a single language compound function into a single entity | |
US20140298352A1 (en) | Computer with plurality of processors sharing process queue, and process dispatch processing method | |
CN111221535B (en) | Thread allocation method, server and computer readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CP01 | Change in the name or title of a patent holder |
Address after: Changan town in Guangdong province Dongguan 523860 usha Beach Road No. 18 Patentee after: OPPO Guangdong Mobile Communications Co., Ltd. Address before: Changan town in Guangdong province Dongguan 523860 usha Beach Road No. 18 Patentee before: Guangdong Opel Mobile Communications Co., Ltd. |
|
CP01 | Change in the name or title of a patent holder |