Memory management method and device and electronic equipment
By registering the shrinker of the module in the corresponding sub-link list and traversing according to priority, the problem of low memory recycling efficiency in the Linux kernel is solved, and efficient system memory recycling and power consumption saving is achieved.
Patent Information
- Application Number
- CN202310742883.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-20
- Publication Date
- 2024-12-20
AI Technical Summary
In the Linux kernel, when the system memory is insufficient, the existing technology may lead to invalid or inefficient recycling by traversing the global linked list, resulting in wasted system power consumption and difficult to improve memory recovery efficiency.
By registering the shrinkers of different types of modules in the corresponding sub-link list, and traversing and recycling memory according to the priority of the sub-link list, invalid traversing is reduced and the efficiency of the system's memory recycling is improved.
It realizes the improvement of memory recovery efficiency and system performance while saving system power consumption.
Smart Images

Figure CN119166539A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic devices, and more specifically, to a method, device and electronic device for managing memory. Background Art
[0002] In the Linux kernel, when the system memory is insufficient, memory needs to be reclaimed. To ensure that the system can reclaim memory, each module needs to register the shrinker in the global linked list first. When reclaiming memory, the shrinkers in the global linked list will be traversed. However, for different types of modules, registering shrinkers in the global linked list may cause invalid or inefficient memory recovery during memory recycling, and also waste system power consumption.
[0003] Therefore, how to improve the efficiency of system memory recovery while saving system power consumption, thereby improving system performance is a problem that needs to be solved urgently. Summary of the invention
[0004] The embodiments of the present application provide a method, device and electronic device for managing memory. Shrinkers of different modules can be registered in corresponding linked lists, so that when the system recycles memory, it can traverse the shrinkers in the corresponding linked lists, which can save system power consumption and improve the efficiency of system memory recycling.
[0005] In a first aspect, a method for managing memory is provided, comprising: determining at least two sub-linked lists, the at least two sub-linked lists being related to a global linked list; registering a recycler of a first module in the first sub-linked list, the first sub-linked list belonging to one of the at least two sub-linked lists, wherein information of the first module comprises at least one of the following: a type of file system, a disk device path corresponding to the file system, and a mount directory of the file system; and traversing at least one of the at least two sub-linked lists according to the priority of the at least two sub-linked lists.
[0006] Exemplarily, the global linked list may be shrinker_list. The at least two sub-linked lists may be at least two of the shrinker_now linked list, the shrinker_delay linked list, and the shrinker_skip linked list.
[0007] Exemplarily, the type of the file system can be obtained through the magic number of the file system. For example, the type of the file system can be mapped through the magic number of the file system, or the type of the file system can be directly matched through the magic number of the file system. The magic number can also be understood as a mark, which can be applicable to Linux systems or Windows systems. For example, the starting bytes of some file systems can be used as magic numbers to determine the type of the file system.
[0008] It should be noted that at least two sub-linked lists can be obtained by splitting the global linked list. The sub-linked lists split from the global linked list include but are not limited to the above three sub-linked lists. According to actual conditions, the global linked list can be split into any other number (at least two) of sub-linked lists.
[0009] It should be noted that there is a corresponding relationship between the module and the file system. For example, the type of file system corresponding to the F2fs module is F2fs; the type of file system corresponding to the tmpfs module is tmpfs; the type of file system corresponding to the Ext4 module is Ext4. The first module includes but is not limited to the above-mentioned F2fs module, tmpfs module and Ext4 module. Depending on the actual situation, it may also include a gpu module, an erofs module, etc. This application does not limit the specific type of the module.
[0010] Based on the above scheme, at least two sub-linked lists related to the global linked list disassembly can be determined, the shrinker of the module can be registered in the corresponding sub-linked list, and when the system recycles memory, the corresponding sub-linked list can be traversed. Compared with traversing the global linked list when reclaiming memory, it can save system power consumption and improve the efficiency of the system in reclaiming memory.
[0011] In combination with the first aspect, in certain implementations of the first aspect, the method also includes: calling a memory recovery function corresponding to the recycler in the at least two sub-linked lists to recycle memory; the information of the first module also includes the amount of memory of the first module, and the amount of memory of the first module and the system recovery priority are used to determine the amount of reclaimed memory.
[0012] Exemplarily, the recycler can be understood as a shrinker. The amount of memory of the first module can be understood as the total amount of memory of the first module, and the amount of reclaimed memory can be understood as the amount of memory reclaimed by the first module each time. In other words, the amount of memory reclaimed by the first module each time can be calculated by the total amount of memory of the first module and the system recycling priority. When the calculated value is greater than or equal to 1, it means that the recycling is effective; when the calculated value is less than 1, memory recycling will not be performed, which will cause power consumption waste.
[0013] It should be noted that memory recycling can be achieved by calling the memory recycling function corresponding to the shrinker in the sub-link list. For example, calling the recycling function corresponding to F2fs_shrinker can realize memory recycling of the F2fs module.
[0014] Based on the above solution, since the shrinkers of different modules are registered in the corresponding sub-linked lists, when the system recycles memory, it can traverse the corresponding sub-linked lists and call the corresponding recycling function of the shrinker in the sub-linked lists to realize memory recycling of the corresponding modules, which can improve the efficiency of memory recycling of the system.
[0015] In combination with the first aspect, in certain implementations of the first aspect, the at least two sub-linked lists include at least two of the following: a sub-linked list of a first priority, a sub-linked list of a second priority, and a sub-linked list of a third priority; wherein the first priority is higher than the second priority, and the second priority is higher than the third priority.
[0016] It should be noted that different sub-linked lists have different priorities. At least two sub-linked lists with different priorities can be determined according to the global linked list.
[0017] For example, the first priority sub-list is the shrinker_now list, the second priority sub-list is the shrinker_delay list, and the third priority sub-list is the shrinker_skip list. The priority of the sub-list reflects the order of the system traversal. It is understandable that the system can traverse the list with a higher priority first.
[0018] Based on the above scheme, the global linked list can be divided into at least two sub-linked lists with different priorities, so that the module can register the shrinker in the sub-linked list of the corresponding priority, and when reclaiming memory subsequently, traverse the sub-linked list according to the priority order to improve the efficiency of memory recovery.
[0019] In combination with the first aspect, in some implementations of the first aspect, when the type of the file system is the first type, the first sub-link list is a sub-link list of the third priority.
[0020] Exemplarily, the first type is tmpfs. When the type of the file system is tmpfs, the first module is the tmpfs module, and the shrinker of the tmpfs module is registered in the shrinker_skip linked list.
[0021] Based on the above solution, when the file system type is tmpfs, and the large page function is not enabled in the file system, the requested memory will be released after use, and the memory will not be cached. Therefore, the shrinker of the file system can be registered in the third priority sub-list, so that when the memory is subsequently recovered, the traversal of the third priority sub-list can be skipped to avoid wasting system power consumption.
[0022] In combination with the first aspect, in certain implementations of the first aspect, when the disk device path corresponding to the file system is the first path, and / or when the mount directory of the file system is the first directory, the first sub-list is a sub-list of the second priority.
[0023] Exemplarily, the first path is a string starting with / dev / block / loop, and the first directory is a string starting with modem. When the disk path corresponding to the file system is a string starting with / dev / block / loop, or when the mount directory of the file system is a string starting with modem, the shrinker of the module is registered in the shrinker_delay linked list.
[0024] It should be noted that when the disk path corresponding to the file system is the first path, and / or the mounted directory is the first directory, it can be understood that the total memory of the file system is small. For modules with a small total memory, the shrinker can be registered in the second priority sub-list.
[0025] Based on the above scheme, when the amount of memory in the file system is small, the system will not recycle memory when the memory recovery priority value is large. Therefore, the shrinker of the module can be registered in the sub-list of the second priority, and the sub-list of the second priority can be traversed when the system memory recovery priority value is small, which can save a certain amount of system power consumption.
[0026] In combination with the first aspect, in certain implementations of the first aspect, when the type of the file system is the second type, and the disk device path corresponding to the file system is not the first path, and the mount directory of the file system is not the first directory, the first sub-list is a sub-list of the first priority.
[0027] Exemplarily, the second type is Ext4. When the type of the file system is Ext4, the first module is an Ext4 module, and when the disk path corresponding to the file system is not a string starting with / dev / block / loop, and the mount directory of the file system is not a string starting with modem (for example, a string starting with / dev / block / sdd), the shrinker of the module is registered in the shrinker_now linked list.
[0028] Based on the above solution, when the file system type is not tmpfs, the disk path corresponding to the file system type is not the first path, and the mount directory of the file system is not the first directory, the shrinker of the module can be registered in the first priority sub-linked list. The first priority sub-linked list is the highest priority sub-linked list. When the system reclaims memory, it will first traverse the first priority sub-linked list to facilitate effective memory recovery.
[0029] In combination with the first aspect, in certain implementations of the first aspect, traversing at least one of the at least two sub-linked lists according to the priorities of the at least two sub-linked lists includes: traversing the sub-linked list of the first priority according to the priorities of the at least two sub-linked lists; and traversing the sub-linked list of the second priority when the system recycling priority is lower than a threshold.
[0030] Exemplarily, the threshold value may be 8.
[0031] It should be noted that when the system reclaims memory, the shrinker_now linked list is traversed each time. When the system reclaim priority is lower than 8, the shrinker_delay linked list can be traversed.
[0032] For example, when the system recycles memory, only the shrinker_now linked list of the first priority is traversed during the first traversal (the priority value of the system recycling is 12) to the fifth traversal (the priority value of the system recycling is 8), and during the sixth traversal (the priority value of the system recycling is 7), the shrinker_now linked list of the first priority is traversed first, and then the shrinker_delay linked list of the second priority is traversed. The total amount of memory corresponding to the module of the shrinker in the sub-linked list of the second priority is small. If the sub-linked list of the second priority is also traversed in the first five traversals, memory recycling may not be performed, resulting in a waste of system power consumption.
[0033] Based on the above solution, the invalid or inefficient traversal process when the system recycles memory is reduced, the system power consumption is saved, and the efficiency of the system reclaiming memory is improved.
[0034] In combination with the first aspect, in certain implementations of the first aspect, the method is applied to an electronic device that displays a first interface. Before determining at least two sub-link lists based on the global linked list, the method also includes: in response to a user operation on a first option on the first interface, displaying a second interface, the second interface including a first control; in response to the user operation on the first control, displaying a first prompt message, the first prompt message being used to prompt the electronic device to apply the method for managing memory, and / or the first prompt message being used to prompt the electronic device to apply a first threshold.
[0035] In combination with the first aspect, in certain implementations of the first aspect, the second interface includes a second control, and the method also includes: in response to a user operation of the second control, displaying a second prompt message, the second prompt message being used to prompt the electronic device to apply the method for managing memory, and / or the second prompt message being used to prompt the electronic device to apply a second threshold, the second threshold being less than the first threshold.
[0036] It should be noted that the first prompt information and the second prompt information can prompt the electronic device that the method for managing memory is applied by displaying the effect produced by the method.
[0037] Based on the above scheme, the user can implement the method of managing memory applied on the electronic device through the interaction of the user interface of the electronic device, or personalize the method of managing memory applied on the electronic device (for example, the first threshold or the second threshold). Since the second threshold is smaller than the first threshold, the electronic device can save more power consumption by using the second threshold to manage memory compared with using the first threshold to manage memory; the electronic device can recycle memory more efficiently by using the first threshold to manage memory compared with using the second threshold to manage memory.
[0038] In combination with the first aspect, in certain implementations of the first aspect, registering the recycler of the first module in the first sub-link list includes: according to the type of the file system being the first type, not registering the recycler of the first module in the at least two sub-link lists.
[0039] Based on the above solution, when the file system type is tmpfs, the shrinker of the module can be not registered in any sub-list. When the module needs to be uninstalled, there is no need to delete the shrinker of the module from the list, which can further save power consumption.
[0040] In a second aspect, a device for managing memory is provided, including: a processing unit, used to root determine at least two sub-linked lists, and the at least two sub-linked lists are related to a global linked list; the processing unit is also used to register a recycler of a first module in the first sub-linked list, and the first sub-linked list belongs to one of the at least two sub-linked lists, wherein the information of the first module includes at least one of the following: the type of file system, the disk device path corresponding to the file system, and the mount directory of the file system; the processing unit is also used to traverse at least one of the at least two sub-linked lists according to the priority of the at least two sub-linked lists.
[0041] In combination with the second aspect, in certain implementations of the second aspect, the processing unit is also used to call the memory recovery function corresponding to the recycler in the at least two sub-linked lists to recycle memory; the information of the first module also includes the amount of memory of the first module, and the amount of memory of the first module and the system recovery priority are used to determine the amount of reclaimed memory.
[0042] In combination with the second aspect, in certain implementations of the second aspect, the at least two sub-linked lists include at least two of the following: a sub-linked list of a first priority, a sub-linked list of a second priority, and a sub-linked list of a third priority; wherein the first priority is higher than the second priority, and the second priority is higher than the third priority.
[0043] In combination with the second aspect, in some implementations of the second aspect, when the type of the file system is the first type, the first sub-linked list is a sub-linked list of the third priority.
[0044] In combination with the second aspect, in certain implementations of the second aspect, when the disk device path corresponding to the file system is the first path, and / or the mount directory of the file system is the first directory, the first sub-list is a sub-list of the second priority.
[0045] In combination with the second aspect, in certain implementations of the second aspect, when the type of the file system is the second type, and the disk device path corresponding to the file system is not the first path, and the mount directory of the file system is not the first directory, the first sub-list is a sub-list of the first priority.
[0046] In combination with the second aspect, in certain implementations of the second aspect, at least one of the at least two sub-linked lists is traversed according to the priorities of the at least two sub-linked lists, and the processing unit is specifically used to traverse the sub-linked list of the first priority according to the priorities of the at least two sub-linked lists; the processing unit is also used to traverse the sub-linked list of the second priority when the system recycling priority is lower than a threshold.
[0047] In combination with the second aspect, in certain implementations of the second aspect, the device also includes a display unit, which displays a first interface, and the display unit is used to display a second interface in response to a user operation on a first option on the first interface, and the second interface includes a first control; the display unit is also used to display a first prompt message in response to the user operation on the first control, and the first prompt message is used to prompt the electronic device to apply the method for managing memory, and / or the first prompt message is used to prompt the electronic device to apply a first threshold.
[0048] In combination with the second aspect, in certain implementations of the second aspect, the second interface includes a second control, and the display unit is further used to display a second prompt message in response to a user operation of the second control, and the second prompt message is used to prompt the electronic device to apply the method for managing memory, and / or the second prompt message is used to prompt the electronic device to apply a second threshold, and the second threshold is less than the first threshold.
[0049] In combination with the second aspect, in certain implementations of the second aspect, the processing unit is specifically used to not register the recycler of the first module in the at least two sub-linked lists according to the type of the file system being the first type.
[0050] In a third aspect, an electronic device is provided, comprising: one or more processors; one or more memories; the one or more memories storing one or more computer programs, the one or more computer programs comprising instructions, which, when executed by the one or more processors, enable the electronic device to execute the method in the above-mentioned first aspect and any possible implementation thereof.
[0051] In a fourth aspect, a device for managing memory is provided, characterized in that it includes: a processor coupled to a memory, the memory being used to store a computer program, and the processor being used to run the computer program, so that the device for managing memory executes the method in the above-mentioned first aspect and any possible implementation thereof.
[0052] In combination with the fourth aspect, some implementations of the fourth aspect also include one or more of the memory and the transceiver, and the transceiver is used to receive signals and / or send signals.
[0053] In a fifth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a computer, the computer executes the above-mentioned first aspect and any method for managing memory that can be implemented in the first aspect.
[0054] In a sixth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the above-mentioned first aspect and any method for managing memory that can be implemented in the first aspect.
[0055] It should be noted that the above-mentioned computer program code can be stored in whole or in part on the first storage medium, wherein the first storage medium can be packaged together with the processor or separately packaged with the processor, and the embodiments of the present application do not specifically limit this.
[0056] In a seventh aspect, a chip is provided, which includes a processor and a data interface, and the processor reads instructions stored in a memory through the data interface to execute the above-mentioned first aspect and any method for managing memory that can be implemented in the first aspect.
[0057] In combination with the seventh aspect, in one possible implementation, the processor is coupled to the memory via an interface.
[0058] In combination with the seventh aspect, in a possible implementation, the chip system also includes a memory, in which a computer program or computer instructions are stored. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Figure 1 It is a structural diagram of an electronic device.
[0060] Figure 2 It is a software structure block diagram of the electronic device provided in the embodiment of the present application.
[0061] Figure 3 It is a schematic flowchart of a method for managing memory provided in an embodiment of the present application.
[0062] Figure 4 This is a schematic diagram of a chain representation provided by an embodiment of the present application.
[0063] Figure 5 It is a schematic flowchart of shrinker registration provided in an embodiment of the present application.
[0064] Figure 6 It is a schematic flowchart of traversing a linked list provided in an embodiment of the present application.
[0065] Figure 7 It is a set of GUIs provided by the embodiments of the present application.
[0066] Figure 8 It is a schematic flowchart of a method for managing memory provided in an embodiment of the present application.
[0067] Fig. 9 is a schematic block diagram of a memory management device provided in an embodiment of the present application DETAILED DESCRIPTION
[0068] The terms used in the following embodiments are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one, two or more. The term "and / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0069] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear at different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0070] The following describes an electronic device, a user interface for such an electronic device, and embodiments for using such an electronic device. In some embodiments, the electronic device may be a portable electronic device that also includes other functions such as a personal digital assistant and / or a music player function, such as a mobile phone, a tablet computer, a wearable electronic device with wireless communication function (such as a smart watch), etc. Exemplary embodiments of portable electronic devices include but are not limited to devices equipped with Or a portable electronic device with other operating systems. The portable electronic device may also be other portable electronic devices, such as a laptop computer, etc. It should also be understood that in some other embodiments, the electronic device may not be a portable electronic device, but a desktop computer.
[0071] For example, Figure 1 The schematic diagram of the structure of the electronic device 100 is shown. The electronic device 100 may include a processor 110, an audio module 120, a display screen 130, a camera 140, an internal memory 150, an external memory interface 160, a sensor module 170, an antenna 1, an antenna 2, a mobile communication module 180, and a wireless communication module 190. The sensor module 170 may include a gyroscope sensor 170A, a magnetic sensor 170B, a fingerprint sensor 170C, a touch sensor 170D, etc. The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and / or a neural network processor (neural-network processing unit, NPU), etc.
[0072] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0073] Figure 2 1 is a software structure diagram of the electronic device 100 of the embodiment of the present application. Exemplarily, the operating system of the electronic device 100 may be an Android system, a Linux system, a Microsoft Windows system, an Apple mobile operating system (iOS) or a Harmony OS. The method provided in the present application is particularly applicable to a Linux system or other systems derived from a Linux system.
[0074] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer. The application layer can include a series of application packages.
[0075] like Figure 2 As shown, the application layer may include camera, settings, skin module, user interface (UI), third-party applications, etc. Among them, the third-party applications may include gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.
[0076] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer may include some predefined functions.
[0077] like Figure 2 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0078] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc. The content provider is used to store and obtain data and make this data accessible to applications. This data can include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0079] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. The display interface can be composed of one or more views.
[0080] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).
[0081] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0082] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0083] Android runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0084] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0085] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0086] The system library may include multiple functional modules, such as surface manager, media libraries, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0087] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0088] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0089] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0090] A 2D graphics engine is a drawing engine for 2D drawings.
[0091] In addition, the system library may also include status monitoring service modules, such as a physical status recognition module for analyzing and identifying user gestures; a sensor service module for monitoring sensor data uploaded by various sensors at the hardware layer to determine the physical status of the electronic device 100.
[0092] The kernel layer is a layer between hardware and software. The kernel layer includes at least display driver, camera driver, audio driver, sensor driver and memory management. The method for managing memory provided in the present application can be implemented in the kernel layer, more specifically, in the memory management of the kernel layer.
[0093] The hardware layer can include various types of sensors, such as Figure 1 Various types of sensors introduced in.
[0094] Combined with the above Figure 1 and Figure 2 The electronic device introduced in the embodiment of the present application may be a smart phone, a tablet computer, a smart screen or other smart device. The physical devices involved in the electronic device 100 mainly include hardware components such as sensors, decision support systems (DSS) display chips, touch screens, fingerprint recognition modules, etc.; as well as kernel software layers such as screen management modules, display drivers, fingerprint drivers, and anti-mistouch; application framework layer functions such as anti-mistouch input, screen control, always on display (AOD) services, and power management; as well as application layer services such as special adaptation applications (camera), third-party applications, system sleep, and AOD.
[0095] Before introducing the technical solutions in the embodiments of the present application, some related concepts in the embodiments of the present application are first introduced.
[0096] Slab: A memory allocation mechanism in the Linux kernel. It mainly works on objects that are frequently allocated and released (for example, process descriptors). In Linux, memory is generally managed and allocated through the buddy system in units of pages (for example, 4KB). However, in actual applications, most objects that need to be allocated and released are in bytes, and the size of these objects is generally small. If they are allocated and released through the buddy system, it will cause a certain waste of memory and the processing speed will be slow. For example, if you need to apply for 20 bytes, allocating a page for 20 bytes will waste a certain amount of memory. The slab manager manages objects based on the above-mentioned bytes. The slab manager classifies objects of the same type into one category. Whenever such an object is to be applied, the slab manager will allocate a unit of the corresponding size from a slab list, and when it needs to be released, it will be saved in the slab list again. The slab allocator does not break away from the buddy system, but further subdivides the large memory allocated by the buddy system into small memory allocations.
[0097] Shrinker: A structure in the Linux kernel. The structure contains slab memory recovery functions (scan objects) implemented by each module. The Linux kernel implements the slab memory requested by each module by calling the memory recovery function.
[0098] In the Linux kernel, each module will apply for slab memory. When the system memory reaches a certain threshold, it can be considered that the system memory is insufficient at this time, and the memory needs to be reclaimed to avoid the operating efficiency of electronic devices being affected by insufficient system memory, or causing the electronic devices to freeze and thus affect the user experience. In order to ensure that the system can recycle slab memory, each module first needs to register its own shrinker in the global linked list (shrinker list). When the module is initialized, the shrinker needs to be registered on the global linked list; when the module is uninstalled, the shrinker needs to be deleted from the global linked list. Among them, the global linked list (shrinker list) is a linked list under the Linux system in C language.
[0099] Since the global linked list includes the shrinkers of each module, when the system reclaims memory, it first needs to traverse the global linked list, access the shrinkers registered by each module in the global linked list in turn, and call the recycling function in the shrinker to reclaim the slab memory of each module.
[0100] The amount of slab memory that each module reclaims each time is related to the total amount of slab memory of the module and the priority of the system to reclaim memory (the amount of slab memory that each module reclaims each time = the total amount of slab memory / 2 raised to the priority power). Among them, the priority can be 12, and the calculated amount of slab memory that each module reclaims each time is an integer. That is to say, when the total amount of slab memory is greater than or equal to 2 raised to the priority power, the amount of slab memory that each module reclaims each time is obtained. If the result of dividing the total amount of slab memory by 2 raised to the priority power is greater than zero and less than 1, the amount of slab memory that each module reclaims each time is 0. For example, the total amount of slab memory of a module is 4096, and the current priority of memory reclaiming is 10. Therefore, the amount of slab memory that this module reclaims this time is 4096 / 2. 10 =4.
[0101] It should be noted that when the system memory is insufficient, the kernel needs to reclaim memory. Usually, the priority of system memory reclaiming starts from 12. If the system memory is still insufficient after the current reclaiming, the priority of system memory reclaiming is reduced by one, and the priority of system memory reclaiming is set to 11 to obtain the amount of slab memory to be reclaimed next time. And so on, until the priority of system memory reclaiming is reduced to 0.
[0102] In the current Linux kernel, the shrinkers of each module will be registered in a unique global linked list, resulting in the possibility that the global linked list includes multiple types of shrinkers. It is understandable that the shrinker types of each module can be different, and there is a one-to-one correspondence between the module and the shrinker type. If different types of shrinkers are registered in a global linked list, when the system reclaims memory, system power consumption will be wasted to a certain extent.
[0103] For example, some modules, corresponding to the tmpfs file system, will not cache slab memory if the large page function is not enabled, and will release the requested slab memory after use. In other words, the number of slabs corresponding to some modules is 0. When the system needs to reclaim slab memory, it traverses the global linked list and calls the shrinker registered by the module. There will be no slab memory to reclaim, which will cause a waste of system power consumption.
[0104] For another example, some modules correspond to the Ext4 file system. The number of slabs generated by the module is related to the number of files in the disk partition corresponding to the file system. Take the loop partition of an Android phone as an example. This disk partition corresponds to the Ext4 file system. There are more than 20 loop partitions in the phone, and each loop partition has 20 to 200 preset files. Therefore, the number of slabs generated by each partition is at most 20 to 200. It can be seen that the number of slabs is at most 200, which is no more than 2 to the 8th power (2 8 =256). According to the above content, the amount of slab memory reclaimed by each module each time is related to the priority of memory reclaiming by the system. When the total amount of slab memory is 200 and the priority of memory reclaiming by the system is 12, 11, 10, 9, 8, the calculated value is less than 1, and memory reclaiming will not be performed, which will cause a waste of system power consumption.
[0105] Therefore, in order to solve the above technical problems, the present application provides a method, device and electronic device for managing memory. Multiple types of linked lists can be determined so that different types of shrinkers corresponding to different modules can be registered in the corresponding linked lists, which can optimize system power consumption to a certain extent, improve the efficiency of system memory recovery, and improve system performance. Among them, the method for managing memory provided by the present application can be used in Figure 2 The kernel layer implementation shown in .
[0106] like Figure 3 As shown, the main steps of the memory management method provided by the present application are shown. The method can be applied to the slab memory management of the Linux kernel. The method is described in detail below.
[0107] S301, split the global linked list.
[0108] Exemplarily, the global linked list is split into at least one linked list, such as a shrinker_now linked list, a shrinker_delay linked list, and a shrinker_skip linked list.
[0109] like Figure 4 As shown, a schematic diagram of the global linked list and the split linked list is shown.
[0110] Figure 4(a) in FIG. 1 shows a global linked list, which may include shrinkers of different file system types. For example, the file system types are F2fs, tmpfs, Ext4, etc. It should be noted that the modules in the above text correspond to the file system, and each module corresponds to a different file system type one by one. For example, the file system type corresponding to the F2fs module is F2fs; the file system type corresponding to the tmpfs module is tmpfs; and the file system type corresponding to the Ext4 module is Ext4.
[0111] It should be noted that the modules include but are not limited to the above-mentioned F2fs module, tmpfs module and Ext4 module, and may also include a gpu module, an erofs module, etc.
[0112] It is understandable that the temporary file system (tmpfs) is a memory-based file system with fast read and write speeds. When the large page function is turned on, it does not cache memory and can support Linux systems. The flash friendly file system (F2fs) is a new open source flash file system designed based on flash (not and, NAND) storage devices that can support Linux systems. The fourth extended file system (Ext4) is a log file system under the Linux system. The enhanced read-only file system (erofs) is a read-only file system under the Linux system, which is used to save storage space while ensuring the end-to-end performance of embedded devices.
[0113] Various types of file systems are registered in the global linked list. For example, Figure 4 "F2fs_shrinker" shown in (a) indicates the shrinker registered by the F2fs file system in the global linked list; "tmpfs_shrinker" indicates the shrinker registered by the tmpfs file system in the global linked list; "Ext4_fs_shrinker / dev / block / sdd" indicates the shrinker registered by the Ext4 file system in the global linked list; "Ext4_fs_shrinker / dev / block / loop" indicates the shrinker registered by the Ext4 file system in the global linked list.
[0114] For example, the order of shrinkers in the global linked list can be sorted according to the time when each module registered the shrinker. The earliest registered shrinker is ranked first. Figure 4In the global linked list shown in (a), the order of shrinkers is F2fs_shrinker, tmpfs_shrinker, Ext4_fs_shrinker / dev / block / sdd, and Ext4_fs_shrinker / dev / block / loop.
[0115] Figure 4 (b) in FIG. 1 shows the split linked lists, for example, the shrinker_now linked list, the shrinker_delay linked list, and the shrinker_skip linked list.
[0116] For example, the order of the shrinkers in the split linked list can be sorted according to the time when each module registered the shrinker. The earliest registered shrinker is sorted first. Figure 4 In the shrinker_now linked list shown in (b), the order of shrinkers is F2fs_shrinker, Ext4_fs_shrinker / dev / block / sdd.
[0117] S302, register shrinker.
[0118] It should be noted that when each module registers the shrinker, it carries the additional information of the module. The additional information includes the type of file system, the disk partition path corresponding to the file system, the mount directory of the file system, etc. The system can register the shrinker of the module to the corresponding linked list based on the additional information of the module.
[0119] Specifically, you can follow Figure 5 The specific steps of registering the shrinker in the file system are shown, and the shrinker of each module is registered to the corresponding linked list.
[0120] S501, the file system registers the shrinker.
[0121] S502: Determine whether the file system type is tmpfs.
[0122] S503, register the shrinker to the shrinker_skip linked list.
[0123] S504: Determine whether the disk device path corresponding to the file system starts with / dev / block / loop.
[0124] S505, register the shrinker to the shrinker_delay linked list.
[0125] S506, register the shrinker to the shrinker_now linked list.
[0126] It should be noted that Figure 5 This is just an example of how to register a shrinker. Figure 5 The procedure shown in which the type of file system is first determined and then the disk device path corresponding to the file system is only one of the sequences. In the present application, the type of file system may be determined first and then the disk device path corresponding to the file system may be determined, thereby registering the shrinker in the corresponding linked list.
[0127] In one implementation, Figure 5 The specific steps of registering the shrinker shown may also include step S507. Figure 5 Not shown.
[0128] S507, determining whether the mount directory of the file system starts with modem.
[0129] It should be noted that the execution order of step S507 is not limited, and it can be executed before the above step S504, or after the above step S505, or it can be executed optionally with step S504.
[0130] Exemplarily, when registering a shrinker in a file system, the type of the file system is first determined. When the type of the file system is tmpfs, the shrinker of the file system is registered to the shrinker_skip linked list obtained by splitting the global linked list in step S301. When the type of the file system is not tmpfs, step S504 is continued to be executed to further determine the disk device path corresponding to the file system. When the type of the file system is not tmpfs, and the disk device path corresponding to the file system is a string starting with / dev / block / loop, or step S507 is continued to be executed to further determine the mount directory of the file system, when the type of the file system is not tmpfs, and the mount directory of the file system is a string starting with modem, the shrinker of the file system is registered to the shrinker_delay linked list. Alternatively, when the disk device path corresponding to the file system is a string starting with / dev / block / loop, or the mount directory of the file system is a string starting with modem, or both of the above conditions are met, the shrinker of the file system is registered to the shrinker_delay linked list. When the file system type is not tmpfs, and the disk device path corresponding to the file system is not a string starting with / dev / block / loop, and the mount directory of the file system is not a string starting with modem, the shrinker of the file system is registered to the shrinker_now list. Among them, "dev" in the / dev / block / loop string represents the device directory, "block" represents the block device directory, and "loop" represents the disk device named loop.
[0131] For example, Figure 4 As shown in (b), the tmpfs type file system registers shrinker in the shrinker_skip list. The file system type is Ext4, and the disk device path corresponding to the file system starts with the string / dev / block / loop. The file system registers shrinker in the shrinker_delay list. The file system type is F2fs, and the disk path corresponding to the file system does not start with the string / dev / block / loop, and the mount directory of the file system does not start with modem. The file system registers shrinker in the shrinker_now list. Similarly, the file system type is Ext4, and the disk path corresponding to the file system does not start with the string / dev / block / loop, and the mount directory of the file system does not start with modem. The file system also registers shrinker in the shrinker_now list.
[0132] The type of the above-mentioned file system, the disk device path corresponding to the file system, and the mount directory of the file system can be understood as the conditions for the file system to register the shrinker to the corresponding linked list. These three conditions can be combined arbitrarily to determine the target linked list for the file system to register the shrinker.
[0133] S303, traverse the corresponding linked list.
[0134] like Figure 6 As shown, the specific process of traversing the corresponding linked list is shown.
[0135] S601, traverse the shrinker_now linked list and recycle memory.
[0136] S602: Determine whether the priority of the system to reclaim memory is lower than a threshold.
[0137] S603, do not traverse the shrinker_delay linked list.
[0138] S604, traverse the shrinker_delay linked list and reclaim memory.
[0139] For example, when the priority of system memory recycling is greater than or equal to the threshold, the shrinker_now list is traversed and memory is recycled; when the priority of system memory recycling is less than the threshold, the shrinker_now list and the shrinker_delay list are traversed and memory is recycled. The shrinker_skip list is skipped and the shrinker_skip list is not traversed. The threshold value can be 8.
[0140] That is to say, when the system reclaims memory, regardless of the type of file system and the priority of system memory reclaim, it will first traverse the shrinker_now list and call the memory reclaim function corresponding to each shrinker in the shrinker_now list to realize memory reclaim. Secondly, when the priority of system memory reclaim is greater than or equal to the threshold, it is not necessary to traverse the shrinker_delay list; when the priority of system memory reclaim is less than the threshold, it is necessary to traverse the shrinker_delay list again and call the memory reclaim function corresponding to each shrinker in the shrinker_delay list to realize memory reclaim.
[0141] It should be noted that steps S601 to S604 can be executed in each cycle of traversing the linked list. For example, in the first traversal, the priority value of system recycling is 12, in the second traversal, the priority value of system recycling is 11, and so on. In the sixth traversal, the priority value of system recycling is 7. According to the above step S602, it is determined that the system recycling priority at this time is lower than the threshold value 8. After traversing the shrinker_now linked list, the shrinker_delay linked list can be traversed. In the previous first traversal to the fifth traversal, since the priority of system recycling is higher than or equal to the threshold value 8, only the shrinker_now linked list is traversed, and the shrinker_delay linked list is not traversed.
[0142] It should be noted that if a certain file system does not apply for slab memory, and the number of slabs corresponding to the file system is 0 (for example, a tmpfs type file system), the shrinker will be registered in the shrinker_skip list. When the system reclaims memory, access to the shrinker of the file system can be skipped to save system power consumption. If the number of slabs generated by a certain file system is related to the corresponding disk path, and the preset files of the disk partition corresponding to the file system are limited, therefore, the number of slabs generated by the disk partition is also limited, then the shrinker will be registered in the shrinker_delay list. When the system reclaims memory, it can start from the appropriate priority of the system to reclaim memory, avoiding the problem that the memory cannot be reclaimed when the number of slab partitions is small and the priority of the system to reclaim memory is high, which wastes system power consumption.
[0143] For example, when the file system type is Ext4 and the disk path corresponding to the file system is a string starting with / dev / block / loop, the module registers the shrinker to the shrinker_delay list. Since the disk partition corresponding to the file system has a maximum of 200 preset files, the number of slabs generated by the disk partition corresponding to the system file is a maximum of 200, which does not exceed 2 to the eighth power (2 8=256). When the system recycles memory, if it is determined that the priority of the system's recycling is less than the threshold (the threshold is 8), the system will continue to traverse the shrinker_delay list after traversing the shrinker_now list, that is, continue to traverse the list corresponding to the shrinker registered by the file system. Call the memory recycling function corresponding to each shrinker in the shrinker_delay list, and start recycling memory from the priority of the system memory recycling memory of 7. If the current memory recycling is completed and the system memory is still insufficient, the priority of the system recycling memory is reduced by one to obtain the amount of memory to be recycled next time. And so on, until the priority of the system recycling memory is reduced to 0.
[0144] It should be noted that the above steps S301 to S303 may be performed in the following manner: Figure 2 It is implemented in the kernel layer as shown in .
[0145] According to the above steps, the shrinkers of different file systems (or modules) will be registered in each linked list after the global linked list is split. Therefore, when a file system (or module) is uninstalled, the shrinker of the file system needs to be uninstalled from the corresponding linked list. For example, the tmpfs file system is uninstalled from the shrinker_skip linked list. Among them, uninstalling the shrinker of a file system from the corresponding linked list means deleting the shrinker from the corresponding linked list.
[0146] It should be noted that the above is only an example of the specific way of registering shrinkers in different linked lists for various modules. The module with the tmpfs file system mentioned above may have the phenomenon of invalid memory recovery; the module with the Ext4 file system may have the phenomenon of inefficient memory recovery. It should be understood that if modules of other file system types also have similar invalid memory recovery or inefficient memory recovery as mentioned above, and cause system power consumption waste to a certain extent, when registering the shrinker, the shrinker can be registered in the corresponding linked list according to the module-specific additional information (for example, the type of file system, the disk partition path corresponding to the file system, etc.), so that when the system memory is insufficient, efficient memory recovery can be completed while saving system power consumption.
[0147] In one implementation, the user can choose whether to apply the memory management method provided in the embodiment of the present application, or personalize the memory management method provided in the present application, through the user interface of the electronic device, so as to more intuitively experience the experience brought by the memory management method provided in the present application. Figure 7A set of graphical user interfaces (GUIs) is provided, and the electronic device is taken as a mobile phone terminal as an example to further describe the embodiments of the present application.
[0148] like Figure 7 (a) in FIG. 7 shows the setting interface of the user's mobile terminal. The setting interface includes multiple options, including display, battery, storage, security and privacy options. When the user clicks on an option, the mobile terminal can display the setting interface corresponding to the option. In response to the user clicking on the battery option 701, the mobile terminal can display the following Figure 7 GUI shown in (b) in .
[0149] like Figure 7 As shown in (b), in response to the user clicking on the battery option 701, the mobile phone terminal displays a battery settings interface. Among them, the battery settings interface includes multiple controls, and the multiple controls include a performance mode control 702 and a power saving mode control 703. Among them, a control is a visual graphical interface element presented to the user. It is a software component included in an application, which controls the data processed by the application and the interactive operations on the data. The user can interact with the control through touch, sliding and other operations to read and edit the relevant information of the application. Generally speaking, a control may include visual interface elements such as icons, buttons, menus, tabs, text boxes, status bars, etc. In response to the user's operation on different controls (for example: touch operation, or click operation), different interfaces can be displayed on the screen of the electronic device. In response to the user clicking on the performance mode control 702, the mobile phone terminal can display the following. Figure 7 In response to the user clicking the power saving mode control 703, the mobile terminal may display the following Figure 7 In one implementation, in response to the user clicking the power saving mode control 703, the mobile terminal may display the following: Figure 7 GUI shown in (e) in .
[0150] like Figure 7 As shown in (c) in FIG. 1 , in response to the user clicking the performance mode control 702, the battery setting interface of the mobile terminal may display a prompt message 704, which is used to prompt that the performance mode has been turned on, and may display the estimated usage time of the mobile terminal and the effect of turning on the performance mode. For example, it may display "It is expected to continue to be used for 2 hours and 20 minutes, which can improve the performance of the device, but will increase power consumption and heat generation".
[0151] It is understandable that the mobile phone terminal can respond to the user's operation of turning on the performance mode, reclaim memory using the memory management method provided in the present application, and set the threshold value to 8, which can achieve better efficiency in reclaiming memory.
[0152] like Figure 7 As shown in (d) in FIG. 1 , in response to the user clicking the power saving mode control 703, the battery setting interface of the mobile terminal may display a prompt message 705, which is used to prompt that the power saving mode has been turned on, and may display the estimated usage time of the mobile terminal and the effect of turning on the power saving mode. For example, it may display "It is expected to continue to be used for 3 hours and 02 minutes, and the functions such as the screen off display will be turned off to reduce heat generation".
[0153] It should be noted that the user interface may directly display or not display prompt information on whether the electronic device adopts the method for managing memory provided in this application, and this application does not limit this.
[0154] It is understandable that the mobile phone terminal can respond to the user's operation of turning on the power saving mode by using the memory management method provided in the present application to reclaim memory and lower the threshold value (for example, to 6), which can save more power consumption.
[0155] In one implementation, Figure 7 As shown in (e), in response to the user clicking the power saving mode control 703, the mobile terminal displays a power saving mode setting interface. Among them, the power saving mode setting interface includes multiple controls, and the multiple controls include a high power saving mode control 706 and a low power saving mode control 707. In response to the user clicking the high power saving mode control 706, the mobile terminal turns on the high power saving mode; in response to the user clicking the low power saving mode control 707, the mobile terminal turns on the low power saving mode. It can be understood that the high power saving mode will save more power than the low power saving mode. In other words, the power saving mode of the mobile terminal can also be further divided into multiple gears to provide users with a more personalized experience.
[0156] It is understandable that the mobile phone terminal can respond to the user's operation of turning on the high power saving mode control, and will use the method of managing memory provided by this application to recycle memory, and adopt a lower threshold (for example, a threshold of 5), which can further save power consumption. The mobile phone terminal can also respond to the user clicking the low power saving mode control operation, and will use the method of managing memory provided by this application, and set the threshold value to 6, so that the mobile phone terminal can also save power consumption to a certain extent. In other words, the smaller the threshold value, the more power consumption of the mobile phone terminal can be saved, and the larger the threshold value, the efficiency of memory recovery can be improved to a certain extent.
[0157] Above Figure 7 (a) to Figure 7(e) in FIG. 1 shows a method of interaction between a user and a mobile terminal, such as Figure 7 (f) in FIG. 1 shows another interaction mode between a user and a mobile phone terminal.
[0158] like Figure 7 (f) in the figure shows a notification bar interface of a mobile terminal, which includes multiple icons, including mobile data, automatic rotation, power saving mode, and performance mode. In response to the user clicking the power saving mode icon 708, the mobile terminal turns on the power saving mode; in response to the user clicking the performance mode icon 709, the mobile terminal turns on the performance mode.
[0159] Based on the above scheme, the user can choose whether to use the method for managing memory provided by the present application on the electronic device, or personalize the method for managing memory used on the electronic device, through a series of interactive operations on the user interface of the electronic device. It should be understood that the above user interaction mode is optional for the specific implementation of the method for managing memory provided by the present application, that is, the electronic device can also be pre-set to use the method provided by the present application for memory management when it leaves the factory.
[0160] like Figure 8 , a schematic flow chart of a method for managing memory provided by an embodiment of the present application is shown, and the method can be implemented in the kernel layer of the software structure of an electronic device. The method 800 is described in detail below.
[0161] S801, determine at least two sub-link lists.
[0162] It should be noted that at least two sub-linked lists are related to the global linked list.
[0163] Exemplarily, the global linked list can be as follows Figure 4 The at least two sublists can be as follows: Figure 4 At least two of the shrinker_now linked list, shrinker_delay linked list, and shrinker_skip linked list shown in (b).
[0164] It should be noted that at least two sub-linked lists can be obtained by splitting the global linked list. The sub-linked lists split from the global linked list include but are not limited to the above three sub-linked lists. According to actual conditions, the global linked list can be split into any other number (at least two) of sub-linked lists.
[0165] It should be noted that different sub-chained lists have different priorities. Exemplarily, at least two sub-chained lists include at least two of the following: a sub-chained list of a first priority, a sub-chained list of a second priority, and a sub-chained list of a third priority. The first priority is higher than the second priority, and the second priority is higher than the third priority. In other words, at least two sub-chained lists with different priorities can be determined based on the global chained list.
[0166] For example, the first priority sub-list is the shrinker_now list, the second priority sub-list is the shrinker_delay list, and the third priority sub-list is the shrinker_skip list. The priority of the sub-list reflects the order of the system traversal. It is understandable that the system can traverse the list with a higher priority first.
[0167] S802, registering the recycler of the first module in the first sub-link list.
[0168] Exemplarily, the information of the first module includes at least one of the following: the type of the file system, the disk device path corresponding to the file system, and the mount directory of the file system.
[0169] It should be noted that the first sub-link list belongs to one of the at least two sub-link lists.
[0170] It should be noted that there is a correspondence between the module and the file system. For example, the type of the file system corresponding to the F2fs module is F2fs; the type of the file system corresponding to the tmpfs module is tmpfs; and the type of the file system corresponding to the Ext4 module is Ext4.
[0171] It should be noted that the first module includes but is not limited to the above-mentioned F2fs module, tmpfs module and Ext4 module. Depending on the actual situation, it may also include a gpu module, an erofs module, etc. This application does not limit the specific type of the module.
[0172] It should be noted that the recyclers of different modules are registered in the corresponding sub-link lists.
[0173] In one implementation, when the type of the file system is the first type, the first sub-linked list is a sub-linked list of the third priority.
[0174] That is, when the type of the file system is tmpfs, the first module is the tmpfs module, and the shrinker of the tmpfs module is registered in the shrinker_skip linked list.
[0175] In one implementation, when the type of the file system is the first type, the recycler of the first module may not be registered in at least two sub-linked lists according to the type of the file system being the first type.
[0176] That is to say, when the file system type is tmpfs, the shrinker of the tmpfs module may not be registered in any of the above sub-lists. When the module needs to be uninstalled, there is no need to delete the shrinker of the module from a certain list, which can further save power consumption.
[0177] In one implementation, when the disk device path corresponding to the file system is the first path, and / or when the mount directory of the file system is the first directory, the first sub-link list is a sub-link list of the second priority.
[0178] That is to say, when the disk device path corresponding to the file system is a string starting with / dev / block / loop, or when the mount directory of the file system is a string starting with modem, the shrinker of the module is registered in the shrinker_delay list.
[0179] In one implementation, when the type of the file system is the second type, and the disk device path of the file system is the first path, the first sub-linked list is a sub-linked list of the second priority. When the type of the file system is the second type, and the mount directory of the file system is the first directory, the first sub-linked list is a sub-linked list of the second priority. When the type of the file system is the second type, and the disk device path of the file system is the first path, and the mount directory of the file system is the first directory, the first sub-linked list is a sub-linked list of the second priority.
[0180] That is to say, when the file system type is Ext4, the first module is an Ext4 module, and when the disk path corresponding to the file system is a string starting with / dev / block / loop, the shrinker of the module is registered in the shrinker_delay list. Or when the file system type is Ext4, the first module is an Ext4 module, and when the mount directory of the file system is a string starting with modem, the shrinker of the module is registered in the shrinker_delay list. Or when the file system type is Ext4, and when the disk path corresponding to the file system is a string starting with / dev / block / loop, and when the mount directory of the file system is a string starting with modem, the shrinker of the module is registered in the shrinker_delay list.
[0181] That is to say, when any one of the disk device path corresponding to the module's file system and the mount directory of the file system meets the conditions, the shinker of the module can be registered in the shrinker_delay list.
[0182] It can be seen that when determining the registered sub-list of the shrinker of a certain module, it can be based on at least one of the type of the module's file system, the disk device path corresponding to the file system, and the mount directory of the file system. In addition, the present application does not limit the order of determining whether the conditions are met. That is to say, the method for managing memory provided by the present application can first determine whether the type of the file system meets the conditions, then determine whether the disk device path corresponding to the file system meets the conditions, and then determine whether the mount directory of the file system meets the conditions; it can also first determine whether the disk device path corresponding to the file system meets the conditions; then determine whether the mount directory of the file system meets the conditions, and then determine whether the type of the file system meets the conditions. To avoid redundancy, other orders for determining whether the conditions are met are not listed here. Any other orders that can be thought of by any technician familiar with the field within the technical scope of the above-disclosed order of determining whether the conditions are met are covered within the protection scope of the present application.
[0183] In one implementation, when the file system is of the second type, and the device path corresponding to the file system is not the first path, and the mount directory of the file system is not the first directory, the first sub-list is a sub-list of the first priority.
[0184] That is to say, when the file system type is Ext4, the first module is an Ext4 module, and when the disk path corresponding to the file system is not a string starting with / dev / block / loop (for example, a string starting with / dev / block / sdd), and the mount directory of the file system is not a string starting with modem, the shrinker of the module is registered in the shrinker_now linked list.
[0185] S803: traverse at least one of the at least two sub-linked lists according to the priorities of the at least two sub-linked lists.
[0186] In one implementation, memory reclaiming functions corresponding to reclaimers in at least two sub-linked lists are called to reclaim memory.
[0187] It should be noted that memory recycling can be achieved by calling the memory recycling function corresponding to the shrinker in the sub-list. For example, calling the recycling function corresponding to F2fs_shrinker can realize memory recycling of the module.
[0188] In one implementation, the information of the first module may further include the amount of memory of the first module, and the amount of memory of the first module and the system recycling priority are used to determine the amount of recycled memory.
[0189] It should be noted that the amount of memory of the first module can be understood as the total amount of memory of the first module, and the amount of reclaimed memory can be understood as the amount of memory reclaimed each time by the first module.
[0190] In one implementation, according to the priorities of at least two sub-lists, the sub-list of the first priority is traversed; when the system recycling priority is lower than a threshold, the sub-list of the second priority is traversed.
[0191] Exemplarily, the threshold value may be 8.
[0192] It is understandable that the shrinker_now linked list is traversed each time. When the system recycling priority is lower than 8, the shrinker_delay linked list can be traversed.
[0193] In one implementation, the method 800 can be applied to an electronic device, such as a mobile phone terminal. The electronic device displays a first interface, and before determining at least two sub-linked lists according to the global linked list, the method further includes: in response to a user's operation on a first option on the first interface, displaying a second interface, the second interface including a first control; in response to a user's operation on the first control, displaying a first prompt message, the first prompt message is used to prompt the electronic device to apply the method for managing memory, and / or the first prompt message is used to prompt the electronic device to apply a first threshold.
[0194] Exemplarily, the first interface is Figure 7 In the setting interface shown in (a), the first option is Figure 7 The battery option 701 shown in (a) of FIG. 1 is as follows. The second interface is Figure 7 In the battery setting interface shown in (b), the first control is Figure 7 The performance mode control 702 shown in (b) in FIG. 1 is a first prompt message. Figure 7 In the prompt information 704 shown in (c), the first threshold value can be 8.
[0195] It should be noted that the first prompt information can prompt the electronic device that the method for managing memory is applied by displaying the effect produced by the method.
[0196] In one implementation, the second interface of the electronic device includes a second control, and in response to a user operation on the second control, a second prompt message is displayed, and the second prompt message is used to prompt the electronic device to apply a method for managing memory, and / or the second prompt message is used to prompt the electronic device to apply a second threshold, and the second threshold is less than the first threshold.
[0197] Exemplarily, the second control is Figure 7 In the power saving mode control 703 shown in (b), the second prompt information is Figure 7In the prompt information 705 shown in (d), the second threshold value can be 6.
[0198] The specific method of the above-mentioned user interaction with the electronic device can be referred to above. Figure 7 To avoid redundancy, the description is not repeated here.
[0199] Based on the above solution, the shrinker of the module can be registered in the corresponding sub-list according to the module information, and the corresponding sub-list can be traversed when the system recycles memory. This avoids the waste of system power consumption caused by invalid or inefficient calls to the recycling function when the system recycles memory, and improves the efficiency of memory recycling.
[0200] Fig. 9 is a schematic block diagram of a memory management device according to an embodiment of the present application. Fig. 9 The management memory device 900 shown may include: a processor 910, a transceiver 920, and a memory 930. The processor 910, the transceiver 920, and the memory 930 are connected via an internal connection path, the memory 930 is used to store instructions, the processor 910 is used to execute the instructions stored in the memory 930, and the transceiver 930 receives / sends part of the parameters. Optionally, the memory 930 may be coupled to the processor 910 via an interface, or may be integrated with the processor 910.
[0201] It should be noted that the transceiver 920 may include but is not limited to a transceiver device such as an input / output interface to achieve communication between the management memory device 900 and other devices or communication networks.
[0202] In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 910 or an instruction in the form of software. The method disclosed in conjunction with the embodiment of the present application can be directly embodied as a hardware processor for execution, or a combination of hardware and software modules in the processor for execution. The software module can be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 930, and the processor 910 reads the information in the memory 930 and completes the steps of the above method in conjunction with its hardware. To avoid repetition, it is not described in detail here.
[0203] It should also be understood that in the embodiment of the present application, the memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the processor may also include a non-volatile random access memory. For example, the processor may also store information about the device type.
[0204] The embodiment of the present application provides a computer program product, which, when executed on a device, enables the device to execute the technical solution in the above embodiment. Its implementation principle and technical effect are similar to those of the above method-related embodiments, and will not be described in detail here.
[0205] The embodiment of the present application provides a readable storage medium, which contains instructions. When the instructions are executed on a device, the device executes the technical solution of the above embodiment. The implementation principle and technical effect are similar and will not be repeated here.
[0206] The embodiment of the present application provides a chip, which is used to execute instructions. When the chip is running, the technical solution in the above embodiment is executed. The implementation principle and technical effect are similar and will not be repeated here.
[0207] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present application.
[0208] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and units (modules) can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0209] In the several embodiments provided in the present application, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the unit is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0210] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0211] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0212] If the above functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0213] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for managing memory, characterized in that: include: Determine at least two sub-linked lists, wherein the at least two sub-linked lists are related to the global linked list; Register the recycler of the first module in the first sub-linked list, where the first sub-linked list belongs to one of the at least two sub-linked lists, wherein the information of the first module includes at least one of the following: The type of file system, the disk device path corresponding to the file system, and the mount directory of the file system; At least one of the at least two sub-linked lists is traversed according to the priorities of the at least two sub-linked lists.
2. The method according to claim 1, characterized in that: The method further comprises: Calling the memory recovery function corresponding to the recycler in the at least two sub-linked lists to recycle memory; The information of the first module also includes the amount of memory of the first module. The amount of memory of the first module and the system recycling priority are used to determine the amount of recycled memory.
3. The method according to claim 1 or 2, characterized in that: The at least two sub-link lists include at least two of the following: The sub-linked list of the first priority, the sub-linked list of the second priority, and the sub-linked list of the third priority; The first priority is higher than the second priority, and the second priority is higher than the third priority.
4. The method according to claim 3, characterized in that When the type of the file system is the first type, the first sub-link list is a sub-link list of the third priority.
5. The method according to claim 3, characterized in that: When the disk device path corresponding to the file system is the first path, and / or when the mount directory of the file system is the first directory, the first sub-link list is a sub-link list of the second priority.
6. The method according to claim 3, characterized in that When the type of the file system is the second type, the disk device path corresponding to the file system is not the first path, and the mount directory of the file system is not the first directory, the first sub-list is a sub-list of the first priority.
7. The method according to any one of claims 3 to 6, characterized in that The traversing at least one of the at least two sub-linked lists according to the priorities of the at least two sub-linked lists comprises: According to the priorities of the at least two sub-linked lists, traverse the sub-linked list of the first priority; When the system recycling priority is lower than a threshold, the sub-link list of the second priority is traversed.
8. The method according to any one of claims 1 to 7, characterized in that The method is applied to an electronic device, the electronic device displays a first interface, and before determining at least two sub-link lists according to the global link list, the method further includes: In response to a user's operation on a first option on the first interface, displaying a second interface, wherein the second interface includes a first control; In response to the user's operation on the first control, a first prompt message is displayed, where the first prompt message is used to prompt the electronic device to apply the method for managing memory, and / or the first prompt message is used to prompt the electronic device to apply a first threshold.
9. The method according to claim 8, characterized in that The second interface includes a second control, and the method further includes: In response to the user's operation on the second control, a second prompt message is displayed, and the second prompt message is used to prompt the electronic device to apply the method for managing memory, and / or the second prompt message is used to prompt the electronic device to apply a second threshold, and the second threshold is less than the first threshold.
10. The method according to any one of claims 1 to 3, characterized in that The step of registering the recycler of the first module in the first sub-chain list includes: According to the type of the file system being the first type, the recycler of the first module is not registered in the at least two sub-linked lists.
11. An electronic device, comprising: one or more processors; one or more memories; The one or more memories store one or more computer programs, and the one or more computer programs include instructions, which, when executed by the one or more processors, enable the electronic device to perform the method of any one of claims 1 to 10.
12. A device for managing memory, characterized in that: include: A processor coupled to a memory, wherein the memory is used to store a computer program, and the processor is used to run the computer program, so that the device for managing memory performs the method according to any one of claims 1 to 10.
13. The memory management device according to claim 12, characterized in that: Also included is one or more of the memory and the transceiver, wherein the transceiver is used to receive signals and / or send signals.
14. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a computer, the computer is caused to implement the method according to any one of claims 1 to 10.
15. A computer program product comprising instructions, characterized in that When the computer program product is run on a computer, the computer is caused to perform the method according to any one of claims 1 to 10.
16. A chip, characterized in that: The chip includes a processor and a data interface, and the processor reads instructions stored in a memory through the data interface to execute the method according to any one of claims 1 to 10.
