WO2022089452A1 - 内存管理方法、装置、电子设备以及计算机可读存储介质 - Google Patents

内存管理方法、装置、电子设备以及计算机可读存储介质 Download PDF

Info

Publication number
WO2022089452A1
WO2022089452A1 PCT/CN2021/126523 CN2021126523W WO2022089452A1 WO 2022089452 A1 WO2022089452 A1 WO 2022089452A1 CN 2021126523 W CN2021126523 W CN 2021126523W WO 2022089452 A1 WO2022089452 A1 WO 2022089452A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
application
data
control group
thirty
Prior art date
Application number
PCT/CN2021/126523
Other languages
English (en)
French (fr)
Inventor
韩伟
解畅
潘钦旭
陈健
高强
刘嵩
方锦轩
胡源枫
唐祥兵
周未来
孙采
吴祚煜
夏青
杜维
何彪
王法
王承珂
罗梓月
李宗峰
王绪
周喜渝
刘宇
李涛
金龙
房帝
Original Assignee
华为终端有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为终端有限公司 filed Critical 华为终端有限公司
Priority to EP21885179.8A priority Critical patent/EP4220400A4/en
Priority to US18/251,157 priority patent/US20240054079A1/en
Publication of WO2022089452A1 publication Critical patent/WO2022089452A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0877Cache access modes
    • G06F12/0882Page mode
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/12Replacement control
    • G06F12/121Replacement control using replacement algorithms
    • G06F12/123Replacement control using replacement algorithms with age lists, e.g. queue, most recently used [MRU] list or least recently used [LRU] list
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/14Protection against unauthorised use of memory or access to memory
    • G06F12/1416Protection against unauthorised use of memory or access to memory by checking the object accessibility, e.g. type of access defined by the memory independently of subject rights
    • G06F12/1425Protection against unauthorised use of memory or access to memory by checking the object accessibility, e.g. type of access defined by the memory independently of subject rights the protection being physical, e.g. cell, word, block
    • G06F12/1441Protection against unauthorised use of memory or access to memory by checking the object accessibility, e.g. type of access defined by the memory independently of subject rights the protection being physical, e.g. cell, word, block for a range
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/14Protection against unauthorised use of memory or access to memory
    • G06F12/1458Protection against unauthorised use of memory or access to memory by checking the subject access rights
    • G06F12/1483Protection against unauthorised use of memory or access to memory by checking the subject access rights using an access-table, e.g. matrix or list
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/14Protection against unauthorised use of memory or access to memory
    • G06F12/1458Protection against unauthorised use of memory or access to memory by checking the subject access rights
    • G06F12/1491Protection against unauthorised use of memory or access to memory by checking the subject access rights in a hierarchical protection system, e.g. privilege levels, memory rings
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1032Reliability improvement, data loss prevention, degraded operation etc
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1041Resource optimization
    • G06F2212/1044Space efficiency improvement

Definitions

  • the priority of the Chinese patent application for "computer-readable storage medium” requires the priority of the Chinese patent application with the application number 202011385387.9 submitted to the State Intellectual Property Office of China on December 1, 2020, and the name of the invention is "anonymous page management method, Device, Electronic Equipment, Media and Program Products", the priority of the Chinese patent application filed on December 23, 2020 with the China State Intellectual Property Office, application number 202011540521.8, the name of the invention is "One The priority of the Chinese patent application for a UFS device lifetime management and control method based on lifetime prediction" requires the priority of the Chinese patent application submitted to the State Intellectual Property Office of China on October 31, 2020 with the application number 202011197410.1, and the name of the invention is " The priority of the Chinese patent application for a memory management method and electronic device” requires the
  • the embodiments of the present application relate to the field of computer technologies, and in particular, to a memory management method, an apparatus, an electronic device, and a computer-readable storage medium.
  • terminal equipment has become an indispensable item in people's daily life.
  • more and more processes are running and more and more memory is occupied, which will reduce the available memory of the system and cause insufficient memory. problem, which in turn causes the terminal device to freeze.
  • Embodiments of the present application provide a memory management method, apparatus, electronic device, and computer-readable storage medium, which are used to manage the memory of the electronic device, which can improve memory recovery efficiency, reduce system freezes, and improve user experience.
  • embodiments of the present application provide a memory management method, where the memory management method includes:
  • an application-level memory control group of the first application is created; the anonymous page of the first application is added to the least recently used linked list of the application-level memory control group, and according to the least recently used
  • the linked list reclaims anonymous pages; the file pages of the first application are added to the global least recently used linked list of the memory node, and the file pages are reclaimed according to the global least recently used linked list.
  • the memory management method further includes: managing the anonymous page of the first application according to the application-level memory control group; and/or according to the state of the first application Controlling the reclamation sequence of the anonymous pages; and/or controlling the reclamation ratio of the anonymous pages according to the application-level memory control group, wherein the reclamation ratio of the anonymous pages is the number of anonymous pages to be reclaimed in the first application and the total number of anonymous pages in the first application; and/or controlling the memory usage of the first application managed by the application-level memory control group.
  • the embodiments of the present application can manage anonymous pages of applications according to the application-level memory control group, for example, can manage the recycling and release of memory, etc., to improve user experience.
  • the memory management method further includes: determining the anonymous page of the first application according to the frozen state and/or active state and/or foreground state of the first application. recycling order.
  • the embodiments of the present application can manage anonymous pages of applications according to the application-level memory control group, for example, can manage the recycling and release of memory, etc., to improve user experience.
  • creating an application-level memory control group of the first application further includes: when the first process of the first application is started, according to the The application identifier corresponding to the first process creates an application-level memory control group corresponding to the first application.
  • each application has an application identifier, which can be used to uniquely identify the application. Therefore, when the first application is started, a corresponding application-level memory control group can be created according to the application identifier, thereby creating a corresponding application-level memory control group in the dimension of the application, thereby improving the efficiency of memory recycling.
  • creating an application-level memory control group corresponding to the first application according to the application identifier corresponding to the first process also includes: if a memory control group corresponding to the application identifier corresponding to the first process does not exist, creating an application-level memory control group corresponding to the first application. Based on this design, the system can be reduced and the user experience can be improved.
  • the first process is added to the application-level memory control group, and the application-level memory control group is managed according to the application-level memory control group.
  • first process when the first process of the application starts, the anonymous page applied by the first process can be added to the application-level memory control group, and the file page applied by the first process can be added to the global least recently used linked list middle. Therefore, the above-mentioned design can recycle memory in a targeted manner, thereby improving the efficiency of memory recycling.
  • the memory management method further includes: when the electronic device starts, creating a corresponding memory control group according to the white list; when starting the system process, judging whether it is a Whitelist process; if it is a whitelist process, add the whitelist process to the memory control group.
  • the memory management method further includes: adding anonymous pages of the whitelisted process to the least recently used linked list of the memory control group; according to the least recently used linked list The anonymous pages of the whitelist process are reclaimed.
  • the memory management method further includes: adding the file page of the whitelist process to the global least recently used linked list of the memory node; according to the global least recently used linked list, pair The file pages of the whitelist process are recycled.
  • the memory management method further includes: when the second process of the first application starts, adding an anonymous page of the second process to the application-level memory control group and adding the file page of the second process to the global least recently used linked list. Therefore, the above-mentioned design can recycle memory in a targeted manner to improve the efficiency of memory recycling.
  • the memory management method further includes: when the first process and/or the second process is destroyed, removing the first process and/or the second process from the Removed from the application-level memory control group. Based on this design, when the process is destroyed, the process is deleted from the memory control group, thereby releasing the anonymous pages and file pages of the process, improving the fluency of the operating system, and preventing the electronic device from stalling.
  • the memory management method further includes: when the first application is destroyed, deleting the application-level memory control group. Based on this design, the anonymous pages of the process can be deleted and released from the least recently used linked list of the application-level memory control group, and the file pages of the process can be deleted and released from the global least recently used linked list, thereby improving the fluency of the operating system. , to avoid jamming of electronic equipment.
  • the memory management method further includes: when the first application applies for the anonymous page, adding the anonymous page to the active least recently used linked list of the application-level memory control group in; when the first application applies for the file page, the file page is added to the global active least recently used linked list. Therefore, the above-mentioned design can recycle memory in a targeted manner to improve the efficiency of memory recycling.
  • an embodiment of the present application further provides a memory management device, where the memory management device includes:
  • a creation module configured to create an application-level memory control group of the first application when the first application is started
  • a control module configured to add the anonymous page of the first application to the least recently used linked list of the memory control group, and recycle the anonymous page according to the least recently used linked list, and the control module is further configured to add the first A file page of an application is added to the global least recently used linked list, and the file page is reclaimed according to the global least recently used linked list.
  • a corresponding application-level memory control group is created for the first application through the creation module, and the anonymous page of the first application is added to the corresponding application-level memory control group through the control module, and
  • the memory management apparatus further includes a management module, and the management module is further configured to: manage the anonymous page of the first application according to the application-level memory control group; and /or controlling the reclamation sequence of the anonymous pages according to the state of the first application; and/or controlling the reclamation ratio of the anonymous pages according to the application-level memory control group, wherein the reclamation ratio of the anonymous pages is the The number of anonymous pages to be reclaimed in the first application and the total number of anonymous pages in the first application; and/or controlling the memory usage of the application-level memory control group.
  • the efficiency of memory recycling can be improved, which in turn can reduce system lag and improve user experience.
  • the creation module may be further configured to create the first process according to the application identifier corresponding to the first process when the first process of the first application is started
  • the application-level memory control group corresponding to the application Based on such a design, each application has an application identifier, which can be used to uniquely identify the application. Therefore, the creation module may create a corresponding application-level memory control group according to the application identifier when the first application is started, thereby creating a corresponding application-level memory control group in the dimension of the application, thereby improving the efficiency of memory recycling.
  • the creation module is further configured to create an application corresponding to the first application when the memory control group corresponding to the application identifier corresponding to the first process does not exist level memory control group. Therefore, the above-mentioned design can recycle memory in a targeted manner, thereby improving the efficiency of memory recycling.
  • control module is configured to add the first process to the application-level memory control group when a memory control group exists in the application identifier; the management module It is also used for managing the first process according to the application-level memory control group. Based on this design, the efficiency of memory recycling can be improved, which in turn can reduce system lag and improve user experience.
  • the management module is configured to delete the first process from the application-level memory control group when the first process is destroyed. Based on this design, when the process is destroyed, the process is deleted from the memory control group, thereby releasing the anonymous pages and file pages of the process, improving the fluency of the operating system, and preventing the electronic device from stalling.
  • the management module is further configured to delete the application-level memory control group when the first application is destroyed. Based on this design, the anonymous pages of the process are deleted and released from the least recently used linked list of the first memory control group, and the file pages of the process are deleted and released from the global least recently used linked list, thereby improving the fluency of the operating system. Avoid stuttering of electronic equipment.
  • the control module when the first application applies for the anonymous page, the control module is configured to add the anonymous page to the active least recently used linked list of the application-level memory control group; when When the first application applies to the file page, the control module is configured to add the file page to the global active least recently used linked list. Therefore, the above-mentioned design can recycle memory in a targeted manner to improve the efficiency of memory recycling.
  • embodiments of the present application further provide an electronic device, the electronic device comprising:
  • a processor configured to execute the computer program stored in the memory, when the computer program is executed, the processor is configured to execute the memory management method described above.
  • embodiments of the present application further provide a computer-readable storage medium, where the computer-readable storage medium includes computer instructions, and when the computer instructions are executed on an electronic device, the electronic device is made to execute the above-mentioned The described memory management method.
  • the anonymous page of the first application is added to the corresponding application-level memory control group, and the file page of the first application is added to the global recent memory control group.
  • the least use of the linked list can not only perform refined management of anonymous pages, but also will not affect the efficiency of memory recycling, thereby reducing system lag and improving user experience.
  • Embodiments of the present application provide a memory management method, an electronic device, and a computer-readable storage medium, which are used to manage the memory of the electronic device, which can improve the recovery efficiency of the memory, expand the equivalent memory, thereby improve the fluency of the operating system, and avoid the The electronic device is stuck, which improves the user experience.
  • an embodiment of the present application provides a memory management method, where the memory management method includes:
  • the important score values of the tenth memory control group and the eleventh memory control group can be updated according to the status of the tenth application and the eleventh application, and the memory control group linked list can be based on the memory control group.
  • the tenth memory control group and the eleventh memory control group are ranked by the important score value of the control group. Therefore, the recycling mechanism performs memory recycling on the tenth memory control group and the eleventh memory control group according to the order of the tenth memory control group and the eleventh memory control group in the memory control group linked list.
  • the embodiments of the present application can adjust the recycling sequence of the memory control group of the tenth application and the eleventh memory control group of the eleventh application according to the running state of the application, so as to improve the recycling efficiency of the memory, expand the equivalent memory, and further It can improve the fluency of the operating system, prevent the electronic device from being stuck, and improve the user experience.
  • the important score value of the tenth memory control group is set according to the state of the tenth application, and the eleventh memory is set according to the state of the eleventh application.
  • Significant score values for the control group are set. Based on the above design, the important scoring system corresponding to the memory control group can be adjusted according to the running state of the application to improve the user experience.
  • memory compression is performed on the tenth memory control group according to the compression ratio, and the compressed data is put into the swap area.
  • the memory control group can be compressed according to the preset compression ratio, so that the memory recycling is more targeted and accurate, and the memory recycling efficiency can be improved.
  • the data in the tenth memory control group is swapped out from the swap area to the external storage according to the swap-out ratio;
  • the data in the eleventh memory control group is swapped out from the swap area to the external storage according to the swap-out ratio.
  • the compression ratio and/or the swap-out ratio of the tenth memory control group is set according to the state of the tenth application;
  • the compression ratio and/or the swap-out ratio of the eleventh memory control group when the state of the tenth application changes, the important score value, compression ratio and swap-out ratio of the tenth memory control group change accordingly.
  • Adjust the recycling sequence of the memory to improve the efficiency of memory recycling, which can improve the fluency of the operating system, prevent the electronic device from stalling, and improve the user experience.
  • the tenth memory control group and the eleventh memory control group are controlled according to the order of the tenth memory control group and the eleventh memory control group in the memory control group linked list. Compression order and swapout order of eleven memory control groups.
  • the order of the importance score values of the memory control group is the order of compression and swapping out of the application, which improves the efficiency of memory recycling, which in turn can improve the fluency of the operating system and avoid jamming of electronic devices. phenomenon to enhance the user experience.
  • the compression ratio of the tenth application reaches the compression ratio, the compression of the tenth application is terminated, and the memory in the memory control group linked list is continued to be controlled according to the memory.
  • the ordering of control groups is compressed. Based on such a design, the efficiency of memory recycling can be improved, thereby improving the fluency of the operating system, preventing the electronic device from being stuck, and improving the user experience.
  • the swap-out ratio of the tenth application reaches the swap-out ratio, the swap-out of the tenth application is terminated, and the memory control group continues to be executed according to the memory control group.
  • the ordering of memory control groups in the linked list is swapped out. Based on this design, the equivalent memory is expanded and the user experience is improved.
  • a tenth memory control group of the tenth application is created, and the important score value of the tenth memory control group is set as the tenth pre-determination value. set value. Based on the above design, the efficiency of memory recovery can be improved, thereby improving the fluency of the operating system, avoiding the jam phenomenon of the electronic device, and improving the user experience.
  • an eleventh memory control group of the eleventh application is created. Based on the above design, the efficiency of memory recovery can be improved, thereby improving the fluency of the operating system, avoiding the jam phenomenon of the electronic device, and improving the user experience.
  • the important score value of the tenth memory control group when the tenth application is running in the foreground, the important score value of the tenth memory control group is set as the foreground default value; when the tenth application is in a thawed state , the important score value of the tenth memory control group is set as the important score value when the tenth application is in the frozen state; when the tenth application is in the active state, according to the active time of the tenth application The important score value of the tenth memory control group is adjusted according to the proportion and frequency of use; when the tenth application is in a frozen state, the tenth memory control group is adjusted according to the number of times of freezing and thawing and the memory occupancy size of the tenth application.
  • the compression ratio of the tenth application reaches the tenth compression ratio, the compression of the tenth application is terminated, and the memory control group linked list is selected. Compression is performed in the next application.
  • an embodiment of the present application further provides a memory management device, where the memory management device includes;
  • a creation module is used to create the tenth memory control group of the tenth application and the eleventh memory control group of the eleventh application;
  • control module is used to set the important score value of the tenth memory control group and the important score value of the eleventh memory control group;
  • the control module is further configured to control the memory control group linked list to control the tenth memory control group and the eleventh memory control group according to the important score values of the tenth memory control group and the eleventh memory control group. group to sort;
  • a recycling module which is used for sorting the tenth memory control group and the eleventh memory control group according to the order of the tenth memory control group and the eleventh memory control group in the memory control group linked list. Group for memory reclamation.
  • the control module can set the important score value of the tenth memory control group and the important score value of the eleventh memory control group, and the memory control group linked list can be based on the important score of the memory control group.
  • the value sorts multiple memory control groups. Therefore, the recycling module may perform the sorting of the tenth memory control group and the eleventh memory control group on the tenth memory control group and the eleventh memory control group according to the order of the tenth memory control group and the eleventh memory control group in the memory control group linked list. Memory reclamation.
  • the embodiments of the present application can adjust the recycling sequence of the memory control group of the application according to the running state of the application, improve the efficiency of memory recycling, and expand the equivalent memory, thereby improving the fluency of the operating system and preventing the electronic device from being stuck. phenomenon to enhance the user experience.
  • control module is further configured to set an important score value of the tenth memory control group according to the state of the tenth application.
  • the control module is further configured to set the important score value of the eleventh memory control group according to the state of the eleventh application. Based on such a design, the important scoring system corresponding to the memory control group can be adjusted according to the running state of the application to improve the user experience.
  • the recycling module is further configured to perform memory compression on the tenth memory control group according to the compression ratio, and put the compressed data into the swap area; the recycling module It is also used to perform memory compression on the eleventh memory control group according to the compression ratio, and put the compressed data into the swap area.
  • the recycling mechanism can compress the memory control group according to the compression ratio, making memory recycling more targeted and accurate, and improving the efficiency of memory recycling.
  • the recycling module is further configured to swap the data of the tenth memory control group from the swap area according to the swap-out ratio when the data in the swap area reaches a preset waterline.
  • the recycling module is further configured to swap out the data of the eleventh memory control group from the swap area to the external storage according to the swap-out ratio when the data in the swap area reaches a preset waterline.
  • the recycling mechanism can swap out data from the swap area to external storage according to the preset swap-out ratio, which makes memory recycling more targeted and accurate, and can improve the efficiency of memory recycling.
  • the recycling module is further configured to control the first memory control group according to the order of the tenth memory control group and the eleventh memory control group in the memory control group linked list. Compression order and swap out order for the tenth memory control group and the eleventh memory control group. Based on the above design, the efficiency of memory recovery can be improved, thereby improving the fluency of the operating system, avoiding the jam phenomenon of the electronic device, and improving the user experience.
  • the control module updates the important score value and/or the compression ratio and/or the tenth memory control group of the tenth application. Or swap out the scale.
  • the important score value, compression ratio and swap-out ratio of the memory control group change accordingly.
  • the control module when the tenth application is in the foreground, the control module sets the important score value of the tenth memory control group of the tenth application as the foreground default value; when the tenth application is in the foreground When the application is in the thawed state, the control module sets the important score value of the tenth memory control group of the tenth application as the important score value when the application is active before the tenth application is in the frozen state; when the tenth application is in the frozen state When in the active state, the control module adjusts the important score value of the tenth memory control group of the tenth application according to the active time ratio and the frequency of use of the tenth application; when the tenth application is in the frozen state , the control module adjusts the important score value of the tenth memory control group of the tenth application according to the number of times of freezing and thawing of the tenth application and the memory occupancy size.
  • the important score value, compression ratio and swap-out ratio of the tenth memory control group change accordingly. Adjust the recycling sequence of the memory to improve the efficiency of memory recycling, which can improve the fluency of the operating system, prevent the electronic device from stalling, and improve the user experience.
  • the recycling module terminates the compression of the tenth application, and continues according to the The ordering of memory control groups in the memory control group linked list is compressed.
  • the creation module is further configured to create a tenth memory control group of the tenth application when the tenth application is started. Based on such a design, the efficiency of memory recycling can be improved, thereby improving the fluency of the operating system, preventing the electronic device from being stuck, and improving the user experience.
  • the creation module is further configured to create an eleventh memory control group of the eleventh application when the eleventh application is started. Based on the above design, the efficiency of memory recovery can be improved, thereby improving the fluency of the operating system, avoiding the jam phenomenon of the electronic device, and improving the user experience.
  • an embodiment of the present application further provides an electronic device, the electronic device comprising:
  • a processor configured to execute the computer program stored in the memory, when the computer program is executed, the processor is configured to execute the memory management method described above.
  • the electronic device can update the important score value of the memory control group according to the state of the application, and the memory control group linked list can sort the tenth memory control group according to the important score value of the memory control group. Therefore, the recycling mechanism performs memory recycling on the multiple memory control groups according to the order of the multiple memory control groups in the memory control group linked list.
  • the electronic device provided by the embodiments of the present application can adjust the recycling sequence of multiple memory control groups according to the running state of the application, so as to improve the recycling efficiency of the memory, thereby improving the fluency of the operating system and avoiding the stall phenomenon of the electronic device. , to improve the user experience.
  • an embodiment of the present application further provides a computer-readable storage medium, where the computer-readable storage medium includes computer instructions, and when the computer instructions are executed on an electronic device, the electronic device is made to execute the above-mentioned described memory management methods.
  • the important score value of the memory control group can be updated according to the state of the application, and the memory control group linked list can sort multiple memory control groups according to the important score value of the memory control group. Therefore, the recycling mechanism performs memory recycling on the multiple memory control groups according to the order of the multiple memory control groups in the memory control group linked list.
  • the embodiments of the present application can adjust the recycling sequence of the memory control group of the tenth application according to the running state of the application, improve the memory recycling efficiency, thereby improve the fluency of the operating system, avoid the stall phenomenon of the electronic device, and improve the user experience.
  • the important score values of the tenth memory control group and the eleventh memory control group are respectively updated according to the states of the tenth application and the eleventh application. Sorting the tenth memory control group and the eleventh memory control group in the memory control group linked list, and performing memory recycling on the tenth memory control group and the eleventh memory control group. Therefore, the memory management method, electronic device, and computer-readable storage medium disclosed in the embodiments of the present application can improve memory recovery efficiency, expand equivalent memory, reduce stalls, and improve user experience.
  • Embodiments of the present application provide a memory management method, apparatus, electronic device, and computer-readable storage medium, so as to solve the problems of low memory management efficiency, untimely memory supply, and low number of applications kept alive.
  • the present application provides a memory management method, which is applied to an electronic device.
  • the memory management method includes creating a memory statistic value, the memory statistic value being used to represent the remaining available memory in the electronic device system memory, and the available memory includes a thirty-first memory and a thirty-second memory.
  • the thirty-first memory is free memory, and the free memory is memory that has not been used by the system.
  • the thirty-second memory is the memory that is occupied but can be converted into the thirty-first memory by recycling.
  • the memory statistics value includes a thirty-first memory statistics value and a thirty-second memory statistics value, and the thirty-first memory statistics value is greater than the thirty-second memory statistics value.
  • the setting of multi-level memory statistics value can maintain a high memory statistics value when the memory pressure is small; when the memory pressure is large, it can avoid inefficient recycling or idling caused by frequent anonymous page compression, and finally achieve high efficiency according to memory pressure. Maintain long-term stability of memory statistics and increase application keep-alive.
  • the memory statistical value further includes a thirty-third memory statistical value, and the thirty-third memory statistical value is smaller than the thirty-second memory statistical value
  • the method further includes: when When the memory statistics value is lowered and the current memory statistics value of the system is lower than the thirty-third memory statistics value, the thirty-second memory is recovered by killing the process to convert the thirty-second memory It is the thirty-first memory, until the current memory statistics value of the system is not lower than the thirty-third memory statistics value. Therefore, different memory recycling methods are adopted in different scenarios, thereby effectively improving the efficiency of memory recycling and supplying memory in time.
  • the method further includes: monitoring the space usage rate of the swap area; when the current space usage rate of the swap area reaches a preset ratio, reclaiming the thirty-second process by killing the process memory to convert the thirty-second memory into the thirty-first memory.
  • the space usage rate of the swap area reaches the preset ratio, it will be difficult for the memory statistics to continue to reclaim memory through anonymous page compression.
  • memory can be reclaimed directly by killing the process. Therefore, different memory recycling methods are adopted in different scenarios, thereby effectively improving the efficiency of memory recycling and supplying memory in time.
  • the enabling anonymous page compression to reclaim the thirty-second memory to convert the thirty-second memory to the thirty-first memory includes: confirming the current system The memory pressure level is the 31st level, and is reported as a 31st level pressure event; according to the 31st level pressure event, anonymous page compression is started to reclaim the 32nd memory, so that the The thirty-second memory is converted to the thirty-first memory.
  • lowering the memory statistic value includes confirming that the current memory pressure level of the system is the thirty-second level, and reporting is a level 32 stress event; the memory statistics value is adjusted down according to the level 32 stress event.
  • the thirty-second memory is recovered by killing the process, so as to convert the thirty-second memory into the thirty-first memory, including Confirm that the current memory pressure level of the system is the 33rd level, and report it as the 33rd level pressure event; according to the 33rd level pressure event, recover the 32nd memory by killing the process to Converting the thirty-second memory into a thirty-first memory.
  • the memory pressure of the thirty-third level is higher than the memory pressure of the thirty-second level, and the memory pressure of the thirty-second level is higher than the memory pressure of the thirty-first level.
  • the memory statistical value further includes a thirty-fourth memory statistical value
  • the method further includes: when the current pressure stall information (PSI) value of the system is greater than a preset threshold, reporting the PSI pressure value ;
  • PSI current pressure stall information
  • the thirty-second memory is recovered by killing the process, so that the third Twelve memory is converted to thirty-first memory.
  • a large memory application such as a camera
  • the memory statistics value will be lowered. At this time, memory recovery will be performed through anonymous page compression.
  • the process of downgrading the memory statistic value to the thirty-third memory statistic value may be slow for the camera to start, so in addition to the killing process triggered by the startup of large-memory applications, the PSI pressure report will be a good
  • the memory statistics value has a downward trend, the memory will be reclaimed by killing the process in time.
  • the method further includes: monitoring whether a preset application is started; when it is monitored that a preset application is started and the current memory statistic value of the system is less than the thirty-first memory statistic value, The thirty-second memory is reclaimed by killing the process to convert the thirty-second memory to the thirty-first memory.
  • the application memory demand is too fast and there is still a delay in reporting the PSI pressure, the memory cannot be recovered by killing the process in time. Therefore, in application startup scenarios with large memory requirements, such as camera startup, when a startup message is received, it will immediately trigger to kill the process to reclaim memory.
  • the thirty-first memory statistic value, the thirty-second memory statistic value, and the thirty-third memory statistic value are respectively lower than when the system is in a screen-on state.
  • the memory statistics can be calculated in the off-screen scenario and the bright-screen scenario. They are set to two different values, and the memory statistics in the off-screen scenario are lower than those in the bright-screen scenario.
  • the method further includes: sorting the processes according to the importance of the applications, the priority of the processes and/or the size and distribution of the anonymous pages of the applications, so as to kill the processes according to the sorted processes.
  • sorting the processes according to the importance of the applications, the priority of the processes and/or the size and distribution of the anonymous pages of the applications so as to kill the processes according to the sorted processes.
  • the method further includes: configuring a reclamation parameter; and compressing the anonymous page according to the reclamation parameter to reclaim the thirty-second memory.
  • the reclamation parameters include the number of target memory pages, the reclamation priority of the target memory pages, and/or the memory reclamation ratio. Therefore, in this design, the anonymous page compression can be guided to be performed faster and more efficiently through the setting of the recycling parameter.
  • the embodiments of the present application further provide a memory management apparatus.
  • the memory management device includes: a creation module for creating a memory statistical value, the memory statistical value is used to represent the remaining available memory in the memory of the electronic device system, the available memory includes the thirty-first memory and the thirty-second memory RAM.
  • the thirty-first memory is the free memory of the system, and the free memory is the memory that has not been used by the system.
  • the thirty-second memory is the memory that is occupied but can be converted into the thirty-first memory by recycling.
  • the memory statistics value includes a thirty-first memory statistics value and a thirty-second memory statistics value, and the thirty-first memory statistics value is greater than the thirty-second memory statistics value.
  • the memory management device further includes a memory recycling module for starting anonymous page compression when the current memory statistic value of the system is lower than the thirty-second memory statistic value, so as to reclaim the thirty-second memory so as to recycle all the memory.
  • the thirty-second memory is converted into the thirty-first memory.
  • the memory management device further includes a memory adjustment module, which is configured to down-regulate the memory statistics value when the current memory statistics value of the system is lower than the thirty-first memory statistics value after the anonymous page compression.
  • the memory statistical value further includes a thirty-third memory statistical value, and the thirty-third memory statistical value is smaller than the thirty-second memory statistical value, and the memory recycling module further uses So when the memory statistics value is lowered and the current memory statistics value of the system is lower than the thirty-third memory statistics value, the thirty-second memory is recovered by killing the process, so that the thirty-second memory is recovered. The memory is converted to the thirty-first memory.
  • the memory management device further includes a reporting module, and the reporting module is further used to monitor the space usage rate of the swap area, and the memory recycling module is also used to monitor the current space usage of the swap area.
  • the rate reaches a preset ratio
  • the thirty-second memory is reclaimed by killing the process, so as to convert the thirty-second memory into the thirty-first memory.
  • the reporting module is further configured to confirm that the current memory pressure level of the system is the thirty-first level when the current memory statistical value of the system is lower than the thirty-second memory statistical value, and It is reported as the 31st level pressure event, and the memory recycling module starts anonymous page compression according to the 31st level pressure event to reclaim the 32nd memory, so as to recycle the 32nd memory Convert into the thirty-first memory; the reporting module is also used to confirm that the current memory pressure level of the system is The 32nd level is reported as a 32nd level stress event, and the memory adjustment module further reduces the memory statistics value according to the 32nd level stress event; the reporting module is also used to When the space utilization rate of the swap area reaches the preset ratio, confirm that the current memory pressure level of the system is the thirty-third level, and report it as a thirty-third level pressure event.
  • the thirty-second memory is reclaimed by killing the process to convert the thirty-second memory into the thirty-first memory; the memory pressure of the thirty-third level is higher than the The memory pressure of the thirty-second level, the memory pressure of the thirty-second level is higher than the memory pressure of the thirty-first level.
  • the memory statistical value further includes a thirty-fourth memory statistical value
  • the reporting module is further configured to report the PSI pressure value when the current pressure stall information (PSI) value of the system is greater than a preset threshold value
  • the memory recycling module is also used to recycle the thirty-second by killing the process when the PSI pressure value is received, and when the current memory statistical value of the system is less than the thirty-fourth memory statistical value memory to convert the thirty-second memory into the thirty-first memory.
  • the memory recycling module is also used to monitor whether a preset application is started. When a preset application is monitored and the current memory statistic value of the system is less than the thirty-first memory statistic value , the memory reclaiming module reclaims the thirty-second memory by killing the process, so as to convert the thirty-second memory into the thirty-first memory.
  • the thirty-first memory statistic value, the thirty-second memory statistic value, and the thirty-third memory statistic value are respectively lower than when the system is in a screen-on state.
  • the memory reclaiming module is used to sort the processes according to the importance of the application, the priority of the process and/or the size and distribution of the anonymous pages of the application, and kill the processes according to the sorted processes.
  • the memory recycling module is further configured to configure recycling parameters, and compress anonymous pages according to the recycling parameters to recycle the thirty-second memory; the recycling parameters include the number of target memory pages , the priority of target memory page reclamation, and/or the ratio of memory reclamation.
  • the embodiments of the present application further provide an electronic device, including:
  • a storage unit for storing a computer program
  • a processor configured to execute the computer program stored in the storage unit, and when the computer program is executed, the processor is configured to execute the memory in the above ninth aspect and any possible designs of the embodiments of the present application management method.
  • an embodiment of the present application provides a computer-readable storage medium, including computer instructions, when the computer instruction is executed on an electronic device, the electronic device is made to execute the above ninth aspect and any one of the above-mentioned embodiments of the present application. Memory management methods in possible designs.
  • Embodiments of the present application provide an anonymous page management method, apparatus, electronic device, medium and program product for managing the memory of the electronic device, which can improve the memory recovery efficiency, thereby improving the fluency of the operating system and improving the user experience.
  • an embodiment of the present application provides an anonymous page management method, including:
  • the time parameter of the swap-out time and the time parameter of the swap-in time obtain the time interval information from the swap-in to the swap-out;
  • the anonymous page is swapped into the inactive linked list of the memory.
  • the non-thrash anonymous page can be swapped out prior to the thrash anonymous page, and the swap out of the thrash anonymous page can be reduced.
  • This will reduce the data thrashing of anonymous pages, thereby reducing invalid anonymous page recycling under high-pressure system memory, improving the efficiency of anonymous page memory recycling, improving memory recycling efficiency, thereby improving the fluency of the operating system and improving user experience. experience.
  • the data of the anonymous page is swapped out from the memory to the external storage space
  • the time parameter for recording the swap-out moment includes: when the data of the anonymous page is swapped out from the memory to the external storage space, according to The number of moving pages in the inactive linked list to which the anonymous page belongs is obtained as a time parameter of the swap-out time.
  • the time parameter of the swap-out time is recorded, which reduces the probability of the bumpy anonymous page being swapped out, thereby reducing the data bumping of the anonymous page, thereby reducing the invalidity in the high-pressure state of the system memory.
  • the anonymous page recycling can improve the anonymous page memory recycling efficiency, improve the memory recycling efficiency, and then improve the fluency of the operating system and improve the user experience.
  • the data of the anonymous page is swapped out from the memory to the external storage space
  • the time parameter for recording the swap-out moment further includes: when the data of the anonymous page is swapped out from the memory to the external storage space, The time parameter of the swap-out time is stored in the page table entry corresponding to the anonymous page.
  • the page table entry is stored in the memory, and the time parameter of the swap-out time is recorded in the page table entry, so as to facilitate the subsequent operation of swapping anonymous pages into the inactive linked list and reduce the probability of bumping anonymous pages being swapped out.
  • This further reduces the data thrashing of anonymous pages, thereby reducing invalid anonymous page recycling under high system memory conditions, improving anonymous page memory recycling efficiency, and improving memory recycling efficiency, thereby improving the fluency of the operating system and improving user experience.
  • the anonymous page management method provided by the embodiment of the present application further includes: recording the number of pages moved in the inactive linked list to which the anonymous page belongs according to the page movement of the inactive linked list to which the anonymous page belongs.
  • the number of pages moved in the inactive linked list is recorded according to the page movement of the inactive linked list to which the anonymous page belongs, so as to facilitate the subsequent operation of swapping anonymous pages into the inactive linked list, reducing the probability of bumpy anonymous pages being swapped out, thereby reducing the
  • the data of anonymous pages is thrashed, thereby reducing invalid anonymous page recycling in the high-pressure state of the system memory, improving the recycling efficiency of anonymous page memory, and improving the efficiency of memory recycling, thereby improving the fluency of the operating system and improving the user experience.
  • the page movement of the inactive linked list to which the anonymous page belongs includes:
  • the page of the inactive linked list to which the anonymous page belongs is removed from the tail of the inactive linked list, or the page of the inactive linked list to which the anonymous page belongs is moved to the active linked list.
  • the number of pages moved in the inactive linked list to which the anonymous page belongs is recorded according to the page movement of the inactive linked list to which the anonymous page belongs, so as to facilitate the subsequent operation of swapping anonymous pages into the inactive linked list and reduce bumpy anonymous pages being swapped out.
  • This will reduce the data thrashing of anonymous pages, thereby reducing invalid anonymous page recycling under high-pressure system memory, improving the efficiency of anonymous page memory recycling, improving memory recycling efficiency, thereby improving the fluency of the operating system and improving user experience. experience.
  • the swapping out data of the anonymous page from the external storage space into the memory, and the time parameter for recording the swap-in moment includes: when the anonymous page is swapped out When the data is swapped into the memory from the external storage space, the time parameter of the swap-in moment is obtained according to the number of pages moved in the inactive linked list to which the anonymous page belongs.
  • the time parameter of the swap-in time is recorded, which reduces the probability of the bumpy anonymous page being swapped out, thereby reducing the data bumping of the anonymous page, thereby reducing the invalidity in the high-pressure state of the system memory.
  • the anonymous page recycling can improve the anonymous page memory recycling efficiency, improve the memory recycling efficiency, and then improve the fluency of the operating system and improve the user experience.
  • the method further includes: when the anonymous page is interrupted by a page fault, and it is detected that the storage location of the data swapped out of the anonymous page is in the external storage space, the anonymous page is swapped out.
  • the data is swapped into the internal memory from the external storage space.
  • the anonymous page when the anonymous page is interrupted by a page fault, the anonymous page is swapped into the memory. Improve the fluency of the operating system and enhance the user experience.
  • embodiments of the present application further provide an apparatus for managing anonymous pages, including:
  • the fortieth record unit is used to swap out the anonymous page data from the memory to the external storage space, record the swap
  • the forty-first recording unit used for swapping in the data swapped out of the anonymous page from the external storage space
  • an obtaining unit configured to obtain the time interval information from the swap-in to the swap-out according to the time parameter of the swap-out moment and the time parameter of the swap-in moment;
  • the swap-in unit is configured to swap the anonymous page into the inactive linked list of the memory when the value corresponding to the time interval information is larger than the preset fixed value.
  • the anonymous page management device provided by the embodiment of the present application, by swapping the non-thrash anonymous pages into the inactive linked list of the memory, the non-thrash anonymous pages can be swapped out in preference to the thrash anonymous pages, and the thrash anonymous pages can be reduced.
  • the probability of being swapped out thereby reducing the data thrashing of anonymous pages, thereby reducing invalid anonymous page recycling in the high-pressure state of the system memory, improving the recycling efficiency of anonymous page memory, and improving the efficiency of memory recycling, thereby improving the fluency of the operating system.
  • Improve user experience by swapping the non-thrash anonymous pages into the inactive linked list of the memory, the non-thrash anonymous pages can be swapped out in preference to the thrash anonymous pages, and the thrash anonymous pages can be reduced.
  • the embodiments of the present application further provide an electronic device, including:
  • a memory for storing a computer program
  • a processor configured to execute the computer program stored in the memory, when the computer program is executed, the processor is configured to execute the anonymous page management method described above. Therefore, by swapping the non-thrash anonymous pages into the inactive linked list, the non-thrash anonymous pages can be swapped out in preference to the thrash anonymous pages, reducing the probability of the thrash anonymous pages being swapped out, thereby reducing the data thrashing of the anonymous pages. , so as to reduce invalid anonymous page recycling in the high-pressure state of system memory, improve anonymous page memory recycling efficiency, and improve memory recycling efficiency, thereby improving the fluency of the operating system and improving the user experience.
  • embodiments of the present application further provide a computer-readable storage medium, where the computer-readable storage medium includes computer instructions, and when the computer instructions are executed on an electronic device, the electronic device causes the electronic device to execute the following:
  • the anonymous page management method described above Therefore, by swapping the non-thrash anonymous pages into the inactive linked list, the non-thrash anonymous pages can be swapped out in preference to the thrash anonymous pages, reducing the probability of the thrash anonymous pages being swapped out, thereby reducing the data thrashing of the anonymous pages. , so as to reduce invalid anonymous page recycling in the high-pressure state of system memory, improve anonymous page memory recycling efficiency, and improve memory recycling efficiency, thereby improving the fluency of the operating system and improving the user experience.
  • embodiments of the present application further provide a computer program product
  • the computer program product includes computer program code
  • the computer program code when executed by a computer, the computer program code can cause the The computer executes the anonymous page management method as described above. Therefore, by swapping the non-thrash anonymous pages into the inactive linked list, the non-thrash anonymous pages can be swapped out in preference to the thrash anonymous pages, reducing the probability of the thrash anonymous pages being swapped out, thereby reducing the data thrashing of the anonymous pages. , so as to reduce invalid anonymous page recycling in the high-pressure state of system memory, improve anonymous page memory recycling efficiency, and improve memory recycling efficiency, thereby improving the fluency of the operating system and improving the user experience.
  • the time interval information from the swap in to the swap out is obtained, and when the value corresponding to the time interval information is larger than the preset fixed value, the non-thrash anonymous page is swapped in to the inactive linked list , then the non-thrash anonymous pages can be swapped out prior to the bumpy anonymous pages, reducing the probability of the bumpy anonymous pages being swapped out, thereby reducing the data thrashing of the anonymous pages, thereby reducing invalid anonymous page recycling in the high-pressure state of the system memory.
  • Embodiments of the present application provide a storage life management method, an electronic device, and a computer storage medium to manage and control the amount of data written into the storage device and ensure that the storage device has an expected lifespan.
  • the present application provides a method for managing the lifespan of a memory, which is applied in an electronic device, the method comprising: acquiring a first cycle to be swapped out from the memory of the electronic device to the memory of the electronic device in the first cycle.
  • the status information includes: erasing and/or total service life and/or service life and/or capacity and/or device write amplification factor and/or use time.
  • the present application can subtract the preset user data usage of the storage from the total data quota to obtain the swapped-out data quota of the first period, and calculate the amount of data swapped out from the memory to the storage according to the swapped-out data quota Limit, thereby reducing the number of times of erasing and writing the memory, improving the service life of the memory, and ensuring that the service life of the memory reaches the expected design life.
  • deducting the preset user data usage of the memory from the total data quota to obtain the swap-out data quota of the first cycle includes: acquiring the erased data of the memory in the first cycle. The number of times of writing; according to the number of erasing and writing of the memory in the first cycle and the first cycle, the growth rate of the number of erasing and writing of the memory in the first cycle is calculated; according to the number of times of erasing and writing of the memory in the first cycle; The growth rate of the number of erasing and writing in one cycle determines the preset user data usage; subtracting the preset user data usage from the total data quota obtains the swap-out data quota of the memory in the first cycle .
  • the swapped-out data quota of the memory in the first cycle is calculated according to the number of times of erasing and writing of the memory, so as to control the amount of data swapped out from the memory to the memory in the first cycle.
  • the determining the preset user data usage amount according to the growth rate of the erasing and writing times of the memory in the first cycle includes: erasing and rewriting the memory in the first cycle.
  • the growth rate of the number of times is input into the disk life prediction model, and the preset user data usage is output after being processed by the disk life prediction model, wherein the disk life prediction model is to learn the growth rate of the erasing and writing times of the memory. and the neural network model of the relationship between the preset user data usage.
  • swapping out the first data from the memory to the memory according to the swapped-out data quota includes: judging whether the first period ends; if the first period does not end, obtaining the The data that has been swapped out to the storage in the first cycle, and the remaining data quota is obtained by subtracting the swapped-out data quota of the first cycle and the data swapped out to the storage in the first cycle; Determine whether the first data is less than the remaining data quota; if the first data is less than or equal to the remaining data quota, swap out all the first data from the memory to the storage; if the first data is less than or equal to the remaining data quota The data is greater than or equal to the remaining data quota, select target data with the same amount of data as the remaining data quota from the first data, swap the target data from the memory to the memory, and close the memory write function.
  • the first data when the first data is less than the remaining data quota, all the first data is swapped out from the memory to the storage, and when the first data is greater than or equal to the remaining data quota, the first data is selected from the Data with the same amount of data as the remaining data quota is swapped out from the memory to the memory, and the write function of the memory is turned off, which can improve the service life of the memory and ensure that the service life of the memory reaches the expected design life.
  • the method further includes: if it is determined that the first period ends, recalculating the swap-out data quota of the memory in the second period to obtain an updated swap-out data quota, and performing the swap-out data quota in the second period.
  • write control is performed on the second data expected to be swapped out to the memory in the second cycle according to the updated swap data quota.
  • the determining the swap-out data quota of the memory in the second cycle according to the state information of the memory includes: acquiring the erasing and writing of the memory in a preset time period in the second cycle. number of times; calculate the growth rate of the number of times of erasing and writing of the memory within the preset time period according to the growth rate of the number of times of erasing and writing of the memory within the preset time period; The growth rate is input into the disk life prediction model, and after being processed by the disk life prediction model, the total data quota of the memory in the second cycle is output; the total data quota of the memory in the second cycle is decremented.
  • the disk life prediction model is used to learn the growth rate of the erasing and writing times of the storage and the neural network model of the relationship between the total data quota of the memory.
  • the swap data of the memory in the first cycle can be determined according to the total service life of the memory, the service life of the memory, the capacity of the memory, the target usage time of the memory, the device write amplification factor of the memory, and the first cycle. quota.
  • the swapping out the first data from the memory to the memory according to the swapped-out data quota includes: timing based on a preset timing mode, and acquiring the data in the preset timing mode. Timing time; judging whether the timing time is within the first period: if the timing time is within the first period, obtain the start time of the first period and accumulatively swap out to the timing before the timing time The accumulated data of the storage; the remaining data quota is obtained by subtracting the swapped-out data quota of the storage in the first cycle from the accumulated data; if the first data is less than the remaining data quota, the first The data is swapped out from the memory to the memory; otherwise, if the first data is not less than the remaining data quota, select the target data with the same amount of data as the remaining data quota from the first data, and convert the The target data is swapped out from the memory to the memory, and the write function of the memory is turned off.
  • timing can be performed based on a preset timing method to determine whether the first period ends, and when the first period does not end and the first data is less than the remaining data quota, all the first data is swapped out from the memory to the memory.
  • the method further includes: if a shutdown instruction of the electronic device is obtained, accumulatively swapping out the timing time and the start time of the first cycle to the memory before the timing time.
  • the accumulated data is stored in the memory, wherein the memory is a non-volatile memory.
  • the method further includes: if a power-on command of the electronic device is obtained, reading the timing time and the accumulated data from the memory, and according to the timing time and the accumulated data The data controls the first data to be swapped out to the memory in the first cycle.
  • the method further includes: setting a detection period; acquiring the service life of the memory and the total service life of the memory in each detection period; calculating the The ratio of the service life of the memory to the total service life of the memory obtains a first ratio value; if the first ratio value is less than a preset ratio value in each detection cycle, the first data is transferred from the The memory is swapped out to the storage; if the first ratio is greater than or equal to a preset ratio in each detection period, the first data is not swapped out from the memory to the storage, and is turned off the write function of the memory.
  • the first ratio of the service life of the memory to the total service life of the memory is used as the writing condition of the memory, so as to control the first data to be swapped out from the memory to the memory, ensuring that The memory has reached the end of its designed life.
  • the amount of stored data in GB units should be subtracted from the swapped-out data quota of the memory in the first cycle, and d is the data limit; subtract the data limit from the swapped-out data quota of the first cycle The difference is used as the swap-out data quota of the memory in the first cycle.
  • the difference between the swapped-out data quota in the first cycle minus the data limit is used as the swapped-out data quota of the memory in the first cycle, so that the data written into the memory is corrected in the first cycle, which can prolong the The service life of the memory to reach the expected life.
  • the determining the target usage time of the memory includes: obtaining the target service life of the memory and the total service life of the memory; calculating the service life of the memory and the total service life of the memory.
  • the allocation factor is 1 GB.
  • the swap-out data quota in the first cycle can be corrected through a configuration factor of 1GB, so as to correct the data swapped out from the memory to the memory in the first cycle to achieve the expected lifespan.
  • the preset user data usage amount is the amount of data written into the memory by the non-system software in the previous cycle.
  • the preset user data usage amount is set as the data amount written into the memory by the non-system software in the previous cycle.
  • an embodiment of the present application provides another method for managing the lifespan of a memory, which is applied in an electronic device.
  • the method includes: acquiring a memory to be swapped out from the memory of the electronic device to the electronic device for a first cycle. obtaining the first data of the storage; acquiring the swapped-out data quota of the storage in the first cycle; and swapping out the first data from the storage to the storage according to the swapped-out data quota.
  • the present application can limit the amount of data swapped out from the memory to the memory according to the acquired swap data quota, thereby reducing the number of times of erasing and writing the memory, improving the service life of the memory, and ensuring that the service life of the memory reaches the expected design life.
  • an embodiment of the present application provides an electronic device, the electronic device includes a memory and a processor: wherein the memory is used to store program instructions; the processor is used to read and execute the The program instructions stored in the memory, when the program instructions are executed by the processor, cause the electronic device to execute the memory life management methods of the eighteenth and nineteenth aspects.
  • an embodiment of the present application provides a computer storage medium, where the computer storage medium stores program instructions, and when the program instructions are executed on an electronic device, the electronic device enables the electronic device to execute the eighteenth aspect and the first aspect of the embodiment of the present application.
  • the nineteenth aspect of the invention provides a life management method for a memory.
  • Embodiments of the present application provide a memory management method and an electronic device, which can improve the performance of memory swapping out and memory swapping in.
  • an embodiment of the present application provides a memory management method, the method may include: detecting that the fiftieth application is switched to the foreground, and loading the fiftieth anonymous page data belonging to the fiftieth application from an external storage to In the fiftieth memory area (for example, a cache block of memory); if the fiftieth process of the fiftieth application is called, the fifty-first anonymous page of the fiftieth process is not in the memory area of the fiftieth process. If there is (ie, a memory page shortage occurs), the fifty-first anonymous page data is read from the fiftieth memory region; wherein, the fifty-first anonymous page data includes the fifty-first anonymous page data.
  • the fiftieth anonymous page data is stored in an external storage as at least one data block of a preset size; the storage address of the at least one data block satisfies a preset condition.
  • the preset conditions include: the storage addresses are continuous; or, the maximum jump interval of the storage addresses is less than the fiftieth value.
  • One storage block in the virtual memory can store multiple anonymous pages, and the anonymous pages are grouped into data blocks, which are stored in the virtual memory in a space with consecutive storage addresses in units of data blocks.
  • all data blocks of the application in the virtual memory may be loaded into the fiftieth memory area.
  • one or more data blocks are loaded from the virtual memory to the fiftieth memory area. In this way, it may occur that the storage addresses of multiple data blocks of an application are discontinuous in the virtual memory.
  • the application's data blocks can be read at skip intervals. In this way, all anonymous page data of the application in the virtual memory can be loaded into the fiftieth memory area.
  • the method further includes: moving the fifty-second anonymous page data belonging to the fiftieth application in the fiftieth memory area to an external storage with consecutive storage addresses Fiftieth space.
  • the anonymous page data belonging to the same application is moved into the space with consecutive storage addresses in the external storage; in this way, when the memory is swapped in, the anonymous page data of the application can be sequentially read from the space with consecutive storage addresses. Improved data reading efficiency.
  • the anonymous page data belonging to the fiftieth application in the fiftyth memory area is sorted according to hot and cold, and the number of pages belonging to the fiftieth application in the fiftyth memory area is sorted.
  • Moving the fifty-second anonymous page data to the fiftieth space with continuous storage addresses in the external storage includes: moving the fifty-second anonymous page data belonging to the fiftieth application from the fiftieth memory area in order from cold to hot , and store the fifty-second anonymous page data in the fiftieth space with continuous storage addresses in the external storage.
  • the 52nd anonymous page data belonging to the 50th application is removed from the 50th memory area in the order from cold to hot; in this way, the anonymous page data in the external storage can be sorted according to hot and cold.
  • loading a plurality of fiftieth anonymous page data belonging to the fiftieth application from the external storage to the fiftieth memory area of the memory includes: In the cold sequence, the data of the fiftieth anonymous page belonging to the fiftieth application is loaded from the external storage into the fiftieth memory area of the memory.
  • Loading the data blocks of an application from the virtual memory to the fiftieth memory area in the order from hot to cold can improve the probability that the fiftyth memory area includes the anonymous pages of the fiftieth process when the fiftieth process is called. , that is, to increase the probability of reading from the fiftieth memory area to the fiftieth process anonymous page. Reading anonymous page data from the fiftieth memory area is faster than reading anonymous page data from virtual memory, which improves data reading efficiency and effectively avoids system freezes.
  • the method further includes: moving the least recently used anonymous page in the memory to the fiftieth memory area; wherein, the anonymous page first moved to the fiftieth memory area Page data is cooler than anonymous page data moved later to the fiftieth memory region.
  • Moving anonymous pages from the memory into the fiftieth memory area according to hot and cold can make anonymous pages in the fiftieth memory area distinguish between hot and cold.
  • moving the fifty-second anonymous page data belonging to the fiftieth application in the fiftieth memory area to the fiftieth space with continuous storage addresses in the external storage includes: : Pack the 52nd anonymous page data group belonging to the 50th application in the 50th memory area into one or more data blocks; move one or more data blocks to the 50th consecutive storage address in the external storage space; wherein, one data block includes a plurality of fifty-second anonymous page data.
  • packaging the fifty-second anonymous page data group belonging to the fiftieth application in the fiftieth memory area into one or more data blocks includes:
  • the compressed fifty-second anonymous page data group belonging to the fiftieth application in the tenth memory area is one or more data blocks.
  • Compressing anonymous pages and storing them in the fiftieth memory area can save memory space and improve memory utilization.
  • the data size of one fifty-second anonymous page is 4k, and the size of one data block is 32k.
  • loading the fiftieth anonymous page data belonging to the fiftieth application from the external storage to the fiftieth memory area of the memory includes: loading the data belonging to the fiftieth application in the external storage The fiftyth anonymous page data of the fiftyth application is unpacked and loaded into the fiftyth memory area of the memory.
  • loading the fiftieth anonymous page data belonging to the fiftieth application from the external storage to the fiftieth memory area of the memory includes: loading the data belonging to the fiftieth application in the external storage The fiftyth anonymous page data of the fiftyth application is unpacked and decompressed and loaded into the fiftyth memory area of the memory.
  • the method further includes: if the 50th continuous storage address space in the external storage is smaller than the space occupied by the data of the fifty-second anonymous page, releasing the storage space in the external storage.
  • Anonymous page data belonging to the fifty-first application wherein, the fifty-first application is the application in the external storage that occupies the largest continuous storage address space.
  • the fiftieth space with consecutive storage addresses in the external storage is pre-allocated.
  • the free fiftieth space in the external storage is smaller than the space occupied by the fifty-second anonymous page data, stop the fifty-second anonymous page data from the fifty-second anonymous page.
  • the memory area is moved to external storage.
  • the present application provides an electronic device, which can implement the memory management method described in the twenty-second aspect and its possible design methods, and can execute the corresponding memory management method through software, hardware, or through hardware.
  • the software implements the above method.
  • the electronic device may include a processor and memory; wherein the memory includes memory and external storage.
  • the processor is configured to support the electronic device to perform the corresponding functions in the above twenty-second aspect and possible design manners thereof.
  • the memory is for coupling with the processor, which holds the necessary program instructions and data for the electronic device.
  • an embodiment of the present application provides a computer-readable storage medium, where the computer-readable storage medium includes computer instructions, when the computer instructions are executed on an electronic device, the electronic device is made to execute the above twentieth The memory management method described in the second aspect and its possible design.
  • an embodiment of the present application provides a computer program product, which, when the computer program product is run on a computer, causes the computer to execute as described in the twenty-second aspect and possible design methods thereof. method of memory management.
  • the embodiments of the present application provide a memory management method and device, which can reduce the application and release of memory to the kernel system, reduce the memory exchange delay, and improve the memory exchange performance.
  • an embodiment of the present application provides a memory management method, the method may include: detecting that the sixtieth application switches to the foreground, applying for the sixtieth memory from the memory swap memory pool; A data block of a preset size is loaded from an external storage into a cache block of the memory; wherein, the memory swap memory pool is used to store the sixtieth memory; one data block includes one or more anonymous pages of the sixtieth application.
  • the memory swap process when the memory swap process needs to load the data block from the external storage to the cache block of the memory, it first applies for the sixtieth memory from the memory swap memory pool, instead of directly requesting the kernel system to allocate new memory. In this way, it is possible to reduce the application and release of memory to the kernel system, and reduce the memory exchange delay.
  • the method further includes: applying for the sixtieth memory from the memory swap memory pool; Cache blocks are moved to external storage.
  • the memory swap process when the memory swap process needs to move the data block from the memory cache block to the external storage, it first applies for the sixtieth memory from the memory swap memory pool, instead of directly requesting the kernel system to allocate new memory. In this way, it is possible to reduce the application and release of memory to the kernel system, and reduce the memory exchange delay.
  • the method further includes: releasing the sixtieth memory to the memory swap memory pool, so that a sixtieth memory is added to the memory swap memory pool.
  • the sixtieth memory is first released back to the memory swap memory pool instead of being directly released back to the kernel system.
  • the memory swap process can use the sixtieth memory to move other data blocks, avoiding frequent application and release of memory to the kernel system.
  • the method further includes: when the sixtieth set condition is satisfied, the memory swap memory pool releases all the sixtieth memory in the memory swap memory pool to the kernel system.
  • the sixtieth setting condition includes: no data block to be loaded into the cache block of the memory exists in the external storage; and no data block to be moved to the external storage exists in the cache block of the internal memory.
  • the method further includes: when the sixty-first set condition is satisfied, the memory swap memory pool releases part of the sixtieth memory in the memory swap memory pool to the kernel system.
  • the sixty-first setting condition includes: the sixtieth memory in the memory swap memory pool is greater than the set threshold.
  • releasing part of the sixtieth memory in the memory swap memory pool to the kernel system from the memory swap memory pool includes: releasing the part of the memory swap memory pool that exceeds the set threshold; or Release part of the sixtieth memory in the memory swap memory pool according to the set range.
  • the kernel system is a Linux kernel.
  • the present application provides an electronic device, which can implement the memory management method described in the twenty-sixth aspect and its possible design methods, and can execute the corresponding memory management method through software, hardware, or through hardware.
  • the software implements the above method.
  • the electronic device may include a processor and memory; wherein the memory includes memory and external storage.
  • the processor is configured to support the electronic device to perform the corresponding functions in the above twenty-sixth aspect and possible design manners thereof.
  • the memory is for coupling with the processor, which holds the necessary program instructions and data for the electronic device.
  • an embodiment of the present application provides a computer-readable storage medium, where the computer-readable storage medium includes computer instructions, when the computer instructions are executed on an electronic device, the electronic device is made to execute the above twentieth
  • the memory management methods described in the six aspects and their possible design approaches are described in the six aspects and their possible design approaches.
  • an embodiment of the present application provides a computer program product, which, when the computer program product runs on a computer, causes the computer to execute as described in the twenty-sixth aspect and its possible design manners above. method of memory management.
  • 1-1 is a schematic structural diagram of an electronic device to which the memory management method provided by the embodiment of the application is applied;
  • FIGS. 1-2 are schematic structural diagrams of an operating system according to an embodiment of the present application.
  • FIG. 1-3 are schematic flowcharts of a memory management method according to an embodiment of the present application.
  • 1-4 are schematic flowcharts of another memory management method provided by an embodiment of the present application.
  • FIGS. 1-5 are schematic flowcharts of another memory management method provided by an embodiment of the present application.
  • 1-6 are schematic diagrams of a memory management method provided by an embodiment of the present application.
  • FIGS. 1-7 are schematic diagrams of another memory management method provided by an embodiment of the present application.
  • FIGS. 1-8 are schematic diagrams of another memory management method provided by an embodiment of the present application.
  • FIGS. 1-9 are schematic structural diagrams of a memory management device according to an embodiment of the present application.
  • FIG. 2-1 is a schematic structural diagram of an electronic device to which the memory management method provided by the embodiment of the application is applied;
  • FIG. 2-2 is a schematic structural diagram of an operating system according to an embodiment of the present application.
  • 2-3 are schematic flowcharts of a memory management method provided by an embodiment of the present application.
  • FIGS. 2-5 are schematic diagrams of data swapping out from the swap area to external storage according to an embodiment of the present application
  • FIGS. 2-6 are schematic diagrams of a memory control group linked list provided by an embodiment of the present application.
  • FIGS. 2-7 are schematic diagrams of a memory control group linked list when an application state changes according to an embodiment of the present application
  • FIGS. 2-8 are schematic diagrams of memory reclamation provided by an embodiment of the present application.
  • 2-9 are schematic flowcharts of a memory compression method provided by an embodiment of the present application.
  • FIGS. 2-10 are schematic flowcharts of a memory swapping method provided by an embodiment of the present application.
  • FIGS. 2-11 are schematic structural diagrams of a memory management apparatus according to an embodiment of the present application.
  • 3-1 is a schematic structural diagram of an electronic device to which the memory management method provided by the embodiment of the application is applied;
  • 3-2a is a schematic flowchart of a memory management method provided by an embodiment of the present application.
  • FIG. 3-2b is a schematic diagram of three memory statistics values corresponding to different memory management strategies provided in an embodiment of the present application.
  • 3-3 is a schematic flowchart of another memory management method provided by an embodiment of the present application.
  • 3-4 are schematic flowcharts of another memory management method provided by an embodiment of the present application.
  • 3-5 are schematic flowcharts of another memory management method provided by an embodiment of the present application.
  • FIG. 3-6 are schematic structural diagrams of a memory management apparatus according to an embodiment of the present application.
  • 3-7 are schematic framework diagrams of another memory management apparatus provided by an embodiment of the present application.
  • 3-8 are schematic flowcharts when a preset application is started in an embodiment of the present application.
  • FIGS. 3-9 are schematic structural diagrams of another electronic device provided by an embodiment of the present application.
  • 4-1 is a schematic structural diagram of a page table mapping provided by an embodiment of the present application.
  • FIG. 4-2 is a schematic diagram of the relationship between a memory node, a memory management area, and a page structure provided by an embodiment of the present application;
  • 4-3 is a schematic diagram of a linked list management structure provided by an embodiment of the present application.
  • 4-4 is a schematic diagram of another linked list management structure provided by an embodiment of the present application.
  • 4-6 are block diagrams of the software structure of the electronic device in the embodiment of the application.
  • FIGS. 4-7 are schematic diagrams of an anonymous page life cycle provided by an embodiment of the present application.
  • FIGS. 4-8 are schematic structural diagrams of a page table index provided by an embodiment of the present application.
  • FIGS. 4-9 are schematic flowcharts of an anonymous page management method provided by an embodiment of the present application.
  • FIGS. 4-10 are schematic diagrams of an anonymous page swap out process provided by an embodiment of the present application.
  • 4-11 is a schematic flowchart of a method for swapping out anonymous pages according to an embodiment of the present application
  • FIGS. 4-12 are schematic diagrams of an anonymous page swap-in process provided by an embodiment of the present application.
  • 4-13 is a schematic flowchart of an anonymous page swap-in method provided by an embodiment of the present application.
  • FIGS. 4-15 are schematic block diagrams of another anonymous page management method provided by an embodiment of the present application.
  • FIGS. 4-16 are schematic flowcharts of another anonymous page management method provided by an embodiment of the present application.
  • FIGS. 4-17 are schematic diagrams of modules of an anonymous page management apparatus provided by an embodiment of the present application.
  • 4-18 are schematic diagrams of a fortieth recording unit module provided by an embodiment of the present application.
  • FIGS. 4-19 are schematic diagrams of modules of another anonymous page management apparatus provided by an embodiment of the present application.
  • 5-1 is a system architecture diagram of a method for managing the lifespan of a memory according to an embodiment of the application
  • 5-2 is a flowchart of a method for managing the lifespan of a memory according to an embodiment of the application
  • 5-3 is a flow chart of a method for obtaining a swap-out data quota of a memory according to an embodiment of the present application
  • 5-4 is a flowchart of a method for swapping out first data from a memory to a memory according to the swapped-out data quota according to an embodiment of the application;
  • 5-5 are flowcharts of a method for obtaining a swap-out data quota of a memory in another embodiment of the present application.
  • 5-6 are flowcharts of a method for swapping out the first data to the memory according to the swapped-out data quota according to an embodiment of the application;
  • 5-7A is a schematic diagram of writing statistical information by a storage management and control module according to an embodiment of the present application.
  • 5-7B are schematic diagrams of statistics information read by a storage management and control module according to an embodiment of the present application.
  • 6-1 is a schematic diagram of a hardware structure of an electronic device provided by an embodiment of the present application.
  • Figure 6-2 is a schematic diagram of the process of memory swap out and memory swap in;
  • Figure 6-3 is a schematic diagram of a memory management method
  • 6-4 is a schematic diagram of a scenario example of a memory management method provided by an embodiment of the present application.
  • 6-5 are schematic flowcharts of a memory management method provided by an embodiment of the present application.
  • FIG. 6-6 are schematic diagrams of a scenario example of a memory management method provided by an embodiment of the present application.
  • 6-7 are schematic diagrams of scene examples of the memory management method provided by the embodiments of the present application.
  • FIGS. 6-8 are schematic diagrams of scene examples of the memory management method provided by the embodiments of the present application.
  • FIGS. 6-9 are schematic diagrams of scenario examples of the memory management method provided by the embodiments of the present application.
  • FIGS. 6-10 are schematic diagrams of scene examples of the memory management method provided by the embodiments of the present application.
  • FIGS. 6-11 are schematic diagrams of scenario examples of the memory management method provided by the embodiments of the present application.
  • FIGS. 6-12 are schematic diagrams of scenario examples of the memory management method provided by the embodiments of the present application.
  • FIG. 6-13 are schematic diagrams of scenario examples of the memory management method provided by the embodiments of the present application.
  • FIGS. 6-14 are schematic structural diagrams of an electronic device according to an embodiment of the present application.
  • FIG. 7-1 is a schematic diagram of a hardware structure of an electronic device provided by an embodiment of the present application.
  • Figure 7-2 is a schematic diagram of the process of memory swapping out and memory swapping in;
  • Figure 7-3 is a schematic diagram of a memory swap out and memory swap in method
  • Figure 7-4 is a schematic diagram of the working principle of memory swap processing in the process of memory swap out and memory swap in;
  • Figure 7-5 is a schematic diagram of a scene instance of a memory management method
  • FIGS. 7-6 are schematic diagrams of scene examples of the memory management method provided by the embodiments of the present application.
  • FIG. 7-7 are schematic structural diagrams of an electronic device according to an embodiment of the present application.
  • Wireless communication module 3-160 Audio module 3-170 Speaker 3-170A Receiver 3-170B
  • the 40th record unit 4-10 The 40th record unit 4-10
  • the forty-first record unit 4-20 The forty-first record unit 4-20
  • references in this specification to "one embodiment” or “some embodiments” and the like mean that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application.
  • appearances of the phrases “in one embodiment,” “in some embodiments,” “in other embodiments,” “in other embodiments,” etc. in various places in this specification are not necessarily All refer to the same embodiment, but mean “one or more but not all embodiments” unless specifically emphasized otherwise.
  • the terms “including”, “including”, “having” and their variants mean “including but not limited to” unless specifically emphasized otherwise.
  • the term “connected” includes both direct and indirect connections unless otherwise specified.
  • At least one refers to one or more, and multiple refers to two or more.
  • at least one of a, b or c can represent: a, b, c, a and b, a and c, b and c,
  • words such as “first” and “second” are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order.
  • the first application, the second application, etc. are used to distinguish different applications, rather than to describe the specific order of the applications, and the features defined with “first” and “second” may expressly or implicitly include one or more of this feature.
  • words such as “exemplary” or “for example” are used to mean serving as an example, illustration or illustration. Any embodiments or designs described in the embodiments of the present application as “exemplary” or “such as” should not be construed as advantageous over other embodiments or designs. Rather, the use of words such as “exemplary” or “such as” is intended to present the related concepts in a specific manner.
  • Embodiments of the present application disclose a memory management method, an electronic device, and a computer-readable storage medium, which can improve the stability of an operating system, avoid a stuck phenomenon in an electronic device, and improve user experience.
  • the memory management method provided by the embodiments of the present application can be applied to electronic equipment, and the electronic equipment may also be referred to as user equipment (User Equipment, UE), mobile station (Mobile Station, MS), mobile terminal (Mobile Terminal), etc. .
  • the electronic device may be capable of communicating with a radio access network (Radio Access Network, RAN) and one or more core networks, for example, the electronic device may be a mobile phone (or referred to as a "cellular" phone) , or a mobile computer, etc.
  • RAN Radio Access Network
  • 1-1 shows a schematic structural diagram of an electronic device 1-100.
  • the electronic device 1-100 may be a cell phone, tablet computer, desktop computer, laptop computer, handheld computer, notebook computer, ultra-mobile personal computer (UMPC), netbook, as well as cellular telephones, personal digital assistants (personal digital assistant, PDA), augmented reality (AR) devices, virtual reality (VR) devices, artificial intelligence (artificial intelligence, AI) devices, wearable devices, in-vehicle devices, smart home devices and /or smart city equipment, the embodiments of the present application do not specifically limit the specific type of the electronic equipment.
  • PDA personal digital assistant
  • AR augmented reality
  • VR virtual reality
  • AI artificial intelligence
  • wearable devices wearable devices
  • in-vehicle devices smart home devices and /or smart city equipment
  • smart city equipment the embodiments of the present application do not specifically limit the specific type of the electronic equipment.
  • the electronic device 1-100 may include a processor 1-110, an external memory interface 1-201-120, an internal memory 1-121, a universal serial bus (USB) interface 1-130, and a charge management module 1-140 , Power Management Module 1-141, Battery 1-142, Antenna 1-1, Antenna 1-2, Mobile Communication Module 1-150, Wireless Communication Module 1-160, Audio Module 1-170, Speaker 1-170A, Receiver 1 -170B, Microphone 1-170C, Headphone Jack 1-170D, Sensor Module 1-180, Key 1-190, Motor 1-191, Indicator 1-192, Camera 1-193, Display 1-194, and User ID Module (subscriber identification module, SIM) card interface 1-195 and so on.
  • SIM subscriber identification module
  • the sensor module 1-180 may include a pressure sensor 1-180A, a gyroscope sensor 1-180B, an air pressure sensor 1-180C, a magnetic sensor 1-180D, an acceleration sensor 1-180E, a distance sensor 1-180F, a proximity light sensor 1- 180G, fingerprint sensor 1-180H, temperature sensor 1-180J, touch sensor 1-180K, ambient light sensor 1-180L, bone conduction sensor 1-180M, etc.
  • the structures illustrated in the embodiments of the present application do not constitute a specific limitation on the electronic device 1-100.
  • the electronic device 1-100 may include more or less components than shown, or combine some components, or separate some components, or arrange different components.
  • the illustrated components may be implemented in hardware, software, or a combination of software and hardware.
  • the processor 1-110 may include one or more processing units, for example, the processor 1-110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), image signal processor (ISP), controller, video codec, digital signal processor (DSP), baseband processor, and/or neural-network processing unit (neural-network processing unit, NPU), etc. Wherein, different processing units may be independent devices, or may be integrated in one or more processors.
  • application processor application processor
  • AP application processor
  • modem processor graphics processor
  • ISP image signal processor
  • DSP digital signal processor
  • NPU neural-network processing unit
  • different processing units may be independent devices, or may be integrated in one or more processors.
  • the controller can generate an operation control signal according to the instruction operation code and timing signal, and complete the control of fetching and executing instructions.
  • Memory may also be provided in processor 1-110 for storing instructions and data.
  • the memory in processor 1-110 is a cache memory. This memory may hold instructions or data that have just been used or recycled by processors 1-110. If the processor 1-110 needs to use the instruction or data again, it can be called directly from the memory. Repeated access is avoided, and the waiting time of the processors 1-110 is reduced, thereby improving the efficiency of the system.
  • processor 1-110 may include one or more interfaces.
  • the interface may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous transceiver (universal asynchronous transmitter) receiver/transmitter, UART) interface, mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, subscriber identity module (SIM) interface, and / or universal serial bus (universal serial bus, USB) interface, etc.
  • I2C integrated circuit
  • I2S integrated circuit built-in audio
  • PCM pulse code modulation
  • PCM pulse code modulation
  • UART universal asynchronous transceiver
  • MIPI mobile industry processor interface
  • GPIO general-purpose input/output
  • SIM subscriber identity module
  • USB universal serial bus
  • the I2C interface is a bidirectional synchronous serial bus that includes a serial data line (SDA) and a serial clock line (SCL).
  • processors 1-110 may contain multiple sets of I2C buses.
  • the processor 1-110 can be respectively coupled to the touch sensor 1-180K, charger, flash, camera 1-193, etc. through different I2C bus interfaces.
  • the processor 1-110 can couple the touch sensor 1-180K through the I2C interface, so that the processor 1-110 and the touch sensor 1-180K communicate with the touch sensor 1-180K through the I2C bus interface, so as to realize the touch function of the electronic device 1-100.
  • the I2S interface can be used for audio communication.
  • processors 1-110 may contain multiple sets of I2S buses.
  • the processor 1-110 can be coupled with the audio module 1-170 through the I2S bus to implement communication between the processor 1-110 and the audio module 1-170.
  • the audio module 1-170 can transmit audio signals to the wireless communication module 1-160 through the I2S interface, so as to realize the function of answering calls through a Bluetooth headset.
  • the PCM interface can also be used for audio communications, sampling, quantizing and encoding analog signals.
  • the audio module 1-170 and the wireless communication module 1-160 may be coupled through a PCM bus interface.
  • the audio module 1-170 can also transmit audio signals to the wireless communication module 1-160 through the PCM interface, so as to realize the function of answering calls through a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
  • the UART interface is a universal serial data bus used for asynchronous communication.
  • the bus may be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication.
  • a UART interface is typically used to connect the processor 1-110 with the wireless communication module 1-160.
  • the processor 1-110 communicates with the Bluetooth module in the wireless communication module 1-160 through the UART interface to realize the Bluetooth function.
  • the audio module 1-170 can transmit audio signals to the wireless communication module 1-160 through the UART interface, so as to realize the function of playing music through the Bluetooth headset.
  • the MIPI interface can be used to connect the processor 1-110 with the display screen 1-194, the camera 1-193 and other peripheral devices.
  • MIPI interfaces include camera serial interface (CSI), display serial interface (DSI), etc.
  • the processor 1-110 communicates with the camera 1-193 through the CSI interface, so as to realize the shooting function of the electronic device 1-100.
  • the processor 1-110 communicates with the display screen 1-194 through the DSI interface to realize the display function of the electronic device 1-100.
  • the GPIO interface can be configured by software.
  • the GPIO interface can be configured as a control signal or as a data signal.
  • the GPIO interface can be used to connect the processor 1-110 with the camera 1-193, the display screen 1-194, the wireless communication module 1-160, the audio module 1-170, the sensor module 1-180, and so on.
  • the GPIO interface can also be configured as I2C interface, I2S interface, UART interface, MIPI interface, etc.
  • the USB interface 1-130 is an interface that conforms to the USB standard specification, which can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc.
  • the USB interface 1-130 can be used to connect a charger to charge the electronic device 1-100, and can also be used to transmit data between the electronic device 1-100 and peripheral devices. It can also be used to connect headphones to play audio through the headphones.
  • the interface can also be used to connect other electronic devices, such as AR devices.
  • the interface connection relationship between the modules illustrated in the embodiments of the present application is only a schematic illustration, and does not constitute a structural limitation of the electronic device 1-100.
  • the electronic device 1-100 may also adopt different interface connection manners in the foregoing embodiments, or a combination of multiple interface connection manners.
  • the charging management module 1-140 is used to receive charging input from the charger.
  • the charger may be a wireless charger or a wired charger.
  • the charging management module 1-140 may receive charging input from the wired charger through the USB interface 1-130.
  • the charging management module 1-140 may receive wireless charging input through the wireless charging coil of the electronic device 1-100.
  • the charging management module 1-140 charges the battery 1-142, it can also supply power to the electronic device through the power management module 1-141.
  • the power management module 1-141 is used to connect the battery 1-142, the charging management module 1-140 and the processor 1-110.
  • Power management module 1-141 receives input from battery 1-142 and/or charge management module 1-140, for processor 1-110, internal memory 1-121, display screen 1-194, camera 1-193, and wireless communication Modules 1-160 etc. supply power.
  • the power management module 1-141 can also be used to monitor parameters such as battery capacity, battery cycle times, battery health status (leakage, impedance).
  • the power management module 1-141 may also be provided in the processor 1-110.
  • the power management module 1-141 and the charging management module 1-140 may also be provided in the same device.
  • the wireless communication function of the electronic device 1-100 can be realized by the antenna 1-1, the antenna 1-2, the mobile communication module 1-150, the wireless communication module 1-160, the modulation and demodulation processor, the baseband processor, and the like.
  • the antenna 1-1 and the antenna 1-2 are used for transmitting and receiving electromagnetic wave signals.
  • Each antenna in electronic device 1-100 may be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antennas.
  • the antenna 1-1 can be multiplexed as the diversity antenna of the wireless local area network. In other embodiments, the antenna may be used in conjunction with a tuning switch.
  • the mobile communication module 1-150 can provide a wireless communication solution including 2G/3G/4G/5G etc. applied on the electronic device 1-100.
  • the mobile communication module 1-150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA) and the like.
  • the mobile communication module 1-150 can receive electromagnetic waves from the antenna 1-1, filter and amplify the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation.
  • the mobile communication module 1-150 can also amplify the signal modulated by the modulation and demodulation processor, and then convert it into electromagnetic waves for radiation through the antenna 1-1.
  • at least part of the functional modules of the mobile communication module 1-150 may be provided in the processor 1-110.
  • at least part of the functional modules of the mobile communication module 1-150 may be provided in the same device as at least part of the modules of the processor 1-110.
  • the modem processor may include a modulator and a demodulator.
  • the modulator is used to modulate the low frequency baseband signal to be sent into a medium and high frequency signal.
  • the demodulator is used to demodulate the received electromagnetic wave signal into a low frequency baseband signal. Then the demodulator transmits the demodulated low-frequency baseband signal to the baseband processor for processing.
  • the low frequency baseband signal is processed by the baseband processor and passed to the application processor.
  • the application processor outputs sound signals through audio devices (not limited to the speaker 1-170A, the receiver 1-170B, etc.), or displays images or videos through the display screen 1-194.
  • the modem processor may be a stand-alone device.
  • the modem processor may be independent of the processor 1-110, and be provided in the same device as the mobile communication module 1-150 or other functional modules.
  • the wireless communication module 1-160 can provide applications on the electronic device 1-100 including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (bluetooth, BT) , Global Navigation Satellite System (GNSS), Frequency Modulation (FM), Near Field Communication (NFC), Infrared (IR) and other wireless communication solutions.
  • WLAN wireless local area networks
  • BT Bluetooth
  • GNSS Global Navigation Satellite System
  • FM Frequency Modulation
  • NFC Near Field Communication
  • IR Infrared
  • the wireless communication module 1-160 may be one or more devices integrating at least one communication processing module.
  • the wireless communication module 1-160 receives electromagnetic waves via the antenna 1-2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 1-110.
  • the wireless communication module 1-160 can also receive the signal to be sent from the processor 1-110, perform frequency modulation on it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 1-2.
  • the antenna 1-1 of the electronic device 1-100 is coupled with the mobile communication module 1-150, and the antenna 1-2 is coupled with the wireless communication module 1-160, so that the electronic device 1-100 can communicate with network and other device communication.
  • the wireless communication technologies may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), broadband Code Division Multiple Access (WCDMA), Time Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC , FM, and/or IR technology, etc.
  • the GNSS may include a global positioning system (global positioning system, GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (quasi -zenith satellite system, QZSS) and/or satellite based augmentation systems (SBAS).
  • GPS global positioning system
  • GLONASS global navigation satellite system
  • BDS Beidou navigation satellite system
  • QZSS quasi-zenith satellite system
  • SBAS satellite based augmentation systems
  • the electronic device 1-100 realizes the display function through the GPU, the display screen 1-194, and the application processor.
  • the GPU is a microprocessor for image processing, which is connected to the display screen 1-194 and the application processor.
  • the GPU is used to perform mathematical and geometric calculations for graphics rendering.
  • Processors 1-110 may include one or more GPUs that execute program instructions to generate or alter display information.
  • Display 1-194 is used to display images, videos, etc.
  • Display 1-194 includes a display panel.
  • the display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (active-matrix organic light).
  • LCD liquid crystal display
  • OLED organic light-emitting diode
  • active-matrix organic light-emitting diode active-matrix organic light-emitting diode
  • active-matrix organic light active-matrix organic light.
  • AMOLED organic light-emitting diode
  • FLED flexible light-emitting diode
  • Miniled MicroLed
  • the electronic device 1-100 may include 1 or N display screens 1-194, where N is a positive integer greater than 1.
  • the electronic device 1-100 can realize the shooting function through the ISP, the camera 1-193, the video codec, the GPU, the display screen 1-194, and the application processor.
  • ISP is used to process the data fed back by camera 1-193. For example, when taking a photo, the shutter is opened, the light is transmitted to the camera photosensitive element through the lens, the light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing, and converts it into an image visible to the naked eye.
  • ISP can also perform algorithm optimization on image noise, brightness, and skin tone. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene.
  • the ISP may be located in camera 1-193.
  • Camera 1-193 is used to capture still images or video.
  • the object is projected through the lens to generate an optical image onto the photosensitive element.
  • the photosensitive element may be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor.
  • CMOS complementary metal-oxide-semiconductor
  • the photosensitive element converts the optical signal into an electrical signal, and then transmits the electrical signal to the ISP to convert it into a digital image signal.
  • the ISP outputs the digital image signal to the DSP for processing.
  • DSP converts digital image signals into standard RGB, YUV and other formats of image signals.
  • the electronic device 1-100 may include 1 or N cameras 1-193, where N is a positive integer greater than 1.
  • a digital signal processor is used to process digital signals, in addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 1-100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy, and the like.
  • Video codecs are used to compress or decompress digital video.
  • the electronic device 1-100 may support one or more video codecs. In this way, the electronic device 1-100 can play or record videos in various encoding formats, such as: Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4 and so on.
  • MPEG Moving Picture Experts Group
  • MPEG2 MPEG2, MPEG3, MPEG4 and so on.
  • the NPU is a neural-network (NN) computing processor.
  • NN neural-network
  • Applications such as intelligent cognition of electronic devices 1-100 can be realized through the NPU, such as image recognition, face recognition, speech recognition, text understanding, etc.
  • the internal memory 1-121 may include one or more random access memory (RAM) and one or more non-volatile memory (NVM).
  • RAM random access memory
  • NVM non-volatile memory
  • Random access memory can include static random-access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronization Dynamic random access memory (double data rate synchronous dynamic random access memory, DDR SDRAM, such as the fifth generation DDR SDRAM is generally called DDR5 SDRAM), etc.;
  • SRAM static random-access memory
  • DRAM dynamic random access memory
  • SDRAM synchronous dynamic random access memory
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • DDR5 SDRAM double data rate synchronous dynamic random access memory
  • Non-volatile memory may include magnetic disk storage devices, flash memory.
  • Flash memory can be divided into NOR FLASH, NAND FLASH, 3D NAND FLASH, etc. according to the operating principle, and can include single-level memory cell (SLC), multi-level memory cell (multi-level memory cell, SLC) according to the level of storage cell potential.
  • cell, MLC multi-level memory cell
  • TLC triple-level cell
  • QLC quad-level cell
  • UFS universal flash storage
  • eMMC embedded multimedia memory card
  • the random access memory can be directly read and written by the processors 1-110, and can be used to store executable programs (such as machine instructions) of the operating system or other running programs, and can also be used to store user and application data. Wait.
  • the non-volatile memory can also store executable programs and store data of users and application programs, etc., and can be loaded into the random access memory in advance for the processors 1-110 to directly read and write.
  • the external memory interface 1-120 can be used to connect an external non-volatile memory, so as to expand the storage capacity of the electronic device 1-100.
  • the external non-volatile memory communicates with the processor 1-110 through the external memory interface 1-120 to realize the data storage function. For example, save music, video, etc. files in external non-volatile memory.
  • the electronic device 1-100 can implement audio functions through an audio module 1-170, a speaker 1-170A, a receiver 1-170B, a microphone 1-170C, an earphone interface 1-170D, and an application processor. Such as music playback, recording, etc.
  • the audio module 1-170 is used for converting digital audio information into analog audio signal output, and also for converting analog audio input into digital audio signal. Audio module 1-170 may also be used to encode and decode audio signals. In some embodiments, the audio module 1-170 may be provided in the processor 1-110, or some functional modules of the audio module 1-170 may be provided in the processor 1-110.
  • Speaker 1-170A also known as "horn" is used to convert audio electrical signals into sound signals.
  • the electronic device 1-100 can listen to music through the speaker 1-170A, or listen to a hands-free call.
  • the receiver 1-170B also called “earpiece” is used to convert audio electrical signals into sound signals.
  • the electronic device 1-100 answers a call or a voice message, it can answer the voice by placing the receiver 1-170B close to the human ear.
  • Microphone 1-170C also known as “microphone”, “microphone”, is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can make a sound by approaching the microphone 1-170C through the human mouth, and input the sound signal into the microphone 1-170C.
  • the electronic device 1-100 may be provided with at least one microphone 1-170C. In other embodiments, the electronic device 1-100 may be provided with two microphones 1-170C, which can implement a noise reduction function in addition to collecting sound signals. In other embodiments, the electronic device 1-100 may further be provided with three, four or more microphones 1-170C to collect sound signals, reduce noise, identify sound sources, and implement directional recording functions.
  • the headphone jack 1-170D is used to connect wired headphones.
  • the headphone interface 1-170D can be a USB interface 1-130, or a 3, 5mm open mobile terminal platform (OMTP) standard interface, the cellular telecommunications industry association of the USA, CTIA) standard interface.
  • OMTP open mobile terminal platform
  • the pressure sensor 1-180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal.
  • the pressure sensor 1-180A may be positioned on the display screen 1-194.
  • the capacitive pressure sensor may be comprised of at least two parallel plates of conductive material. When a force is applied to the pressure sensor 1-180A, the capacitance between the electrodes changes.
  • the electronic device 1-100 determines the intensity of the pressure based on the change in capacitance. When a touch operation acts on the display screen 1-194, the electronic device 1-100 detects the intensity of the touch operation according to the pressure sensor 1-180A.
  • the electronic device 1-100 can also calculate the touched position according to the detection signal of the pressure sensor 1-180A.
  • touch operations acting on the same touch position but with different touch operation intensities may correspond to different operation instructions. For example, when a touch operation whose intensity is less than the first pressure threshold acts on the short message application icon, the instruction for viewing the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, the instruction to create a new short message is executed.
  • the gyro sensor 1-180B can be used to determine the motion attitude of the electronic device 1-100.
  • the angular velocity of the electronic device 1-100 about three axes may be determined by the gyro sensor 1-180B.
  • Gyro sensor 1-180B can be used for image stabilization.
  • the gyroscope sensor 1-180B detects the shaking angle of the electronic device 1-100, calculates the distance to be compensated by the lens module according to the angle, and allows the lens to offset the vibration of the electronic device 1-100 through reverse motion. Shake, achieve anti-shake.
  • the gyroscope sensor 1-180B can also be used for navigation and somatosensory game scenes.
  • Air pressure sensor 1-180C is used to measure air pressure.
  • the electronic device 1-100 calculates the altitude through the air pressure value measured by the air pressure sensor 1-180C to assist in positioning and navigation.
  • Magnetic sensor 1-180D includes a Hall sensor.
  • the electronic device 1-100 can detect the opening and closing of the flip holster using the magnetic sensor 1-180D.
  • the electronic device 1-100 when the electronic device 1-100 is a flip machine, the electronic device 1-100 can detect the opening and closing of the flip according to the magnetic sensor 1-180D. Then, according to the detected opening and closing state of the holster or the opening and closing state of the flip cover, characteristics such as unlocking the flip cover are set.
  • the acceleration sensor 1-180E can detect the magnitude of the acceleration of the electronic device 1-100 in various directions (generally three axes).
  • the magnitude and direction of gravity can be detected when the electronic device 1-100 is stationary. It can also be used to identify the posture of electronic devices, and can be used in applications such as horizontal and vertical screen switching, pedometers, etc.
  • Distance sensor 1-180F for measuring distance.
  • Electronic device 1-100 can measure distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device 1-100 can use the distance sensor 1-180F to measure the distance to achieve fast focusing.
  • Proximity light sensors 1-180G may include, for example, light emitting diodes (LEDs) and light detectors, such as photodiodes.
  • the light emitting diodes may be infrared light emitting diodes.
  • the electronic device 1-100 emits infrared light outward through light emitting diodes.
  • Electronic device 1-100 uses photodiodes to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device 1-100. When insufficient reflected light is detected, the electronic device 1-100 may determine that there is no object near the electronic device 1-100.
  • the electronic device 1-100 can use the proximity light sensor 1-180G to detect that the user holds the electronic device 1-100 close to the ear to talk, so as to turn off the screen to save power.
  • Proximity light sensor 1-180G can also be used in holster mode, pocket mode unlock and lock screen.
  • Ambient light sensor 1-180L is used to sense ambient light brightness.
  • the electronic device 1-100 can adaptively adjust the brightness of the display screen 1-194 according to the perceived ambient light brightness.
  • the ambient light sensor 1-180L can also be used to adjust the white balance when taking pictures.
  • the ambient light sensor 1-180L can also cooperate with the proximity light sensor 1-180G to detect whether the electronic device 1-100 is in the pocket to prevent accidental touch.
  • the fingerprint sensor 1-180H is used to acquire fingerprints.
  • the electronic device 1-100 can use the acquired fingerprint characteristics to realize fingerprint unlocking, accessing application locks, taking photos with fingerprints, answering incoming calls with fingerprints, and the like.
  • Temperature sensor 1-180J is used to detect temperature.
  • the electronic device 1-100 utilizes the temperature detected by the temperature sensor 1-180J to execute a temperature handling strategy. For example, when the temperature reported by the temperature sensor 1-180J exceeds a threshold, the electronic device 1-100 performs a performance reduction of a processor located near the temperature sensor 1-180J in order to reduce power consumption and implement thermal protection.
  • the electronic device 1-100 when the temperature is lower than another threshold, the electronic device 1-100 heats the battery 1-142 to avoid abnormal shutdown of the electronic device 1-100 due to low temperature.
  • the electronic device 1-100 when the temperature is lower than yet another threshold, the electronic device 1-100 performs boosting on the output voltage of the battery 1-142 to avoid abnormal shutdown caused by low temperature.
  • Touch sensor 1-180K also known as "touch device”.
  • the touch sensor 1-180K can be arranged on the display screen 1-194, and a touch screen is formed by the touch sensor 1-180K and the display screen 1-194, also called “touch screen”.
  • the touch sensor 1-180K is used to detect touch operations on or near it.
  • the touch sensor can pass the detected touch operation to the application processor to determine the type of touch event.
  • Visual output related to touch operations may be provided through display screen 1-194.
  • the touch sensor 1-180K may also be disposed on the surface of the electronic device 1-100, which is different from the location where the display screen 1-194 is located.
  • Bone conduction sensor 1-180M can acquire vibration signal.
  • the bone conduction sensor 1-180M can acquire the vibration signal of the vibrating bone mass of the human voice.
  • the bone conduction sensor 1-180M can also contact the human pulse and receive the blood pressure beating signal.
  • the bone conduction sensor 1-180M can also be disposed in the earphone, combined with the bone conduction earphone.
  • the audio module 1-170 can analyze the voice signal based on the vibration signal of the vocal vibration bone mass obtained by the bone conduction sensor 1-180M, so as to realize the voice function.
  • the application processor can analyze the heart rate information based on the blood pressure beat signal obtained by the bone conduction sensor 1-180M, and realize the function of heart rate detection.
  • Buttons 1-190 include power button, volume button, etc. Keys 1-190 may be mechanical keys. It can also be a touch key.
  • the electronic device 1-100 may receive key input and generate key signal input related to user settings and function control of the electronic device 1-100.
  • Motor 1-191 can generate vibration cues.
  • Motor 1-191 can be used for incoming call vibration alerts, and can also be used for touch vibration feedback.
  • touch operations acting on different applications can correspond to different vibration feedback effects.
  • Acting on the touch operation in different areas of the display screen 1-194, the motor 1-191 can also correspond to different vibration feedback effects.
  • Different application scenarios for example: time reminder, receiving information, alarm clock, games, etc.
  • the touch vibration feedback effect can also support customization.
  • Indicator 1-192 can be an indicator light, which can be used to indicate charging status, battery change, and can also be used to indicate messages, missed calls, notifications, and the like.
  • the SIM card interface 1-195 is used to connect the SIM card.
  • the SIM card can be inserted into the SIM card interface 1-195 or pulled out from the SIM card interface 1-195 to achieve contact and separation with the electronic device 1-100.
  • the electronic device 1-100 may support 1 or N SIM card interfaces, where N is a positive integer greater than 1.
  • SIM card interface 1-195 can support Nano SIM card, Micro SIM card, SIM card, etc.
  • the same SIM card interface 1-195 can insert multiple cards at the same time.
  • the types of the plurality of cards may be the same or different.
  • the SIM card interface 1-195 is also compatible with different types of SIM cards.
  • the SIM card interface 1-195 is also compatible with external memory cards.
  • the electronic device 1-100 interacts with the network through the SIM card to realize functions such as call and data communication.
  • the electronic device 1-100 employs an eSIM, ie: an embedded SIM card.
  • the eSIM card can be embedded in the electronic device 1-100 and cannot be separated from the electronic device 1-100.
  • the software system of the electronic device 1-100 may adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture.
  • the embodiments of the present application take an Android system with a layered architecture as an example to exemplarily describe the software structure of the electronic device 1-100.
  • 1-2 is a block diagram of a software structure of an electronic device 1-100 according to an embodiment of the present application.
  • the layered architecture divides the software into several layers, and each layer has a clear role and division of labor. Layers communicate with each other through software interfaces.
  • the Android system is divided into four layers, which are, from top to bottom, an application layer, an application framework layer, an Android runtime (Android runtime) and a system library, and a kernel layer.
  • the application layer can include a series of application packages.
  • the application package can include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, SMS, etc.
  • the application framework layer provides an application programming interface (application programming interface, API) and a programming framework for applications in the application layer.
  • the application framework layer includes some predefined functions.
  • the application framework layer can include window managers, content providers, view systems, telephony managers, resource managers, notification managers, and so on.
  • a window manager is used to manage window programs.
  • the window manager can get the size of the display screen, determine whether there is a status bar, lock the screen, take screenshots, etc.
  • Content providers are used to store and retrieve data and make these data accessible to applications.
  • the data may include video, images, audio, calls made and received, browsing history and bookmarks, phone book, etc.
  • the view system includes visual controls, such as controls for displaying text, controls for displaying pictures, and so on. View systems can be used to build applications.
  • a display interface can consist of one or more views.
  • the display interface including the short message notification icon may include a view for displaying text and a view for displaying pictures.
  • the phone manager is used to provide the communication function of the electronic device 1-100. For example, the management of call status (including connecting, hanging up, etc.).
  • the resource manager provides various resources for the application, such as localization strings, icons, pictures, layout files, video files and so on.
  • the notification manager enables applications to display notification information in the status bar, which can be used to convey notification-type messages, and can disappear after a brief pause without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc.
  • the notification manager can also display notifications in the status bar at the top of the system in the form of graphs or scroll bar text, such as notifications of applications running in the background, and notifications on the screen in the form of dialog windows. For example, text information is prompted in the status bar, a prompt sound is issued, the electronic device vibrates, and the indicator light flashes.
  • Android Runtime includes core libraries and a virtual machine. Android runtime is responsible for scheduling and management of the Android system.
  • the core library consists of two parts: one is the function functions that the java language needs to call, and the other is the core library of Android.
  • the application layer and the application framework layer run in virtual machines.
  • 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 lifecycle management, stack management, thread management, safety and exception management, and garbage collection.
  • a system library can include multiple functional modules. For example: surface manager (surface manager), media library (Media Libraries), 3D graphics processing library (eg: OpenGL ES), 2D graphics engine (eg: SGL), etc.
  • surface manager surface manager
  • media library Media Libraries
  • 3D graphics processing library eg: OpenGL ES
  • 2D graphics engine eg: SGL
  • the Surface Manager is used to manage the display subsystem and provides a fusion of 2D and 3D layers for multiple applications.
  • the media library supports playback and recording of a variety of commonly used audio and video formats, as well as still image files.
  • the media library can support a variety of audio and video encoding formats, such as: MPEG4, H, 264, MP3, AAC, AMR, JPG, PNG, etc.
  • the 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
  • 2D graphics engine is a drawing engine for 2D drawing.
  • the kernel layer is the layer between hardware and software.
  • the kernel layer contains at least display drivers, camera drivers, audio drivers, and sensor drivers.
  • the corresponding hardware interrupt is sent to the kernel layer.
  • the kernel layer processes touch operations into raw input events (including touch coordinates, timestamps of touch operations, etc.). Raw input events are stored at the kernel layer.
  • the application framework layer obtains the original input event from the kernel layer, and identifies the control corresponding to the input event. Taking the touch operation as a touch click operation, and the control corresponding to the click operation is the control of the camera application icon, for example, the camera application calls the interface of the application framework layer to start the camera application, and then starts the camera driver by calling the kernel layer.
  • Camera 1-193 captures still images or video.
  • the present application provides a memory management method.
  • FIG. 1-3 is a flowchart of a memory management method provided by an embodiment of the present application.
  • the execution subject of the memory management method is the electronic device 1-100, and the memory management method may include but not limited to the following steps:
  • step S1-31 when the application starts, the electronic device creates an application-level memory control group of the application.
  • the memory control group can be used to manage the memory unit corresponding to the application, and can be created in the memory in the form of an object, including the method for managing the memory unit (such as controlling the recycling parameters of the memory unit, etc.) and the related information describing the memory resources .
  • the relevant information may include physical memory occupation of the current memory control group, memory active state of the current memory control group, etc.
  • the memory unit may be in pages, and the size of a page may be 4KB bytes.
  • This application proposes a memory control group based on the application level, which can be created when the application starts, can include the memory information of the process of the application, and manage the process of the application according to the memory information, which can make the memory management more targeted , which can reduce the overhead of the memory management structure, improve the user experience, and improve the efficiency of memory recycling.
  • An application is the smallest unit in the electronic device 1-100 that interacts with a user.
  • the electronic device 1-100 can implement a service on demand of a user through an application. For example, users can play games through game applications, watch videos through video applications, and play music through music applications.
  • the electronic device 1-100 may include one or more applications, and the multiple refers to two or more.
  • applications such as browsers, shopping applications, game applications, and music applications can be installed on the electronic device 1-100, and each application needs to apply for memory to start and run.
  • the electronic device 1-100 may create an application-level memory control group corresponding to the application when the application is started.
  • the first application in the embodiment of the present application may be one of the system applications in the electronic device, and may also be one of the third-party applications in the electronic device. Specifically, it may be determined according to actual usage requirements, which is not limited in the embodiments of the present application.
  • the application can be a browser
  • the electronic device 1-100 can create an application-level memory control group memcg1 corresponding to the browser when the browser is started, so the kernel will manage the application-level memory control group memcg1 according to the application-level memory control group memcg1.
  • the relative memory of the browser may also be a game application, and the electronic device 1-100 may create an application-level memory control group memcg2 corresponding to the game application when starting the game application, and then the kernel may manage the game according to the application-level memory control group memcg2 The memory associated with the application.
  • the user mode can create a folder (ie, a memory control group) under the directory of a control group (control group, cgroup), and the folder is created in units of applications, that is, the application's All processes can be added to the folder, so that multiple applications of the electronic device 1-100 can create an application-level memory control group when they are started. Therefore, in the embodiment of the present application, multiple applications in the electronic device 1-100 can create their corresponding application-level memory control groups when they are started, that is, create application-level memory control groups by using the application dimension.
  • Step S1-32 adding the anonymous page applied for by the application to the least recently used linked list of the application-level memory control group.
  • the file page (File-backed Page) can be the cache of the data on the disk in the memory, and the data stored in the file page can be found on the disk.
  • Anonymous pages can be memory pages dynamically allocated by applications without corresponding disk files.
  • the application When the application is started, the application applies to the system for memory resources, and the kernel can add the anonymous page applied for by the application to the Least Recently Used (LRU) linked list of the application-level memory control group.
  • LRU Least Recently Used
  • an application may add an anonymous page to the application-level memory control group corresponding to the application when immediately applying for the anonymous page.
  • the least recently used may be a memory management algorithm, which is used for memory management and reclamation control, and is used to select the most recently unused page for reclamation.
  • the electronic device 1-100 can add the applied anonymous page to the LRU linked list in the application-level memory control group memcg3 for management.
  • the embodiment of the present application can manage anonymous pages of applications according to the application-level memory control group, and/or control the recycle sequence of the anonymous pages according to the state of the application, and/or according to the application-level memory control group Controlling the recycling ratio of the anonymous page, and/or controlling the memory usage of the applications managed by the application-level memory control group.
  • the recycling sequence of the anonymous pages can be controlled according to the state of the application, that is, the application that is recycled first can be controlled according to the state of the application.
  • the order of recycling anonymous pages of the application may be determined according to the frozen state and/or the active state and/or the foreground state of the application. For example, if application 1 is in a frozen state and application 2 is in an active state, at this time, according to the frozen state of application 1, the anonymous page of application 1 can be recycled first, and then the anonymous page of application 2 can be recycled, that is, the more the state is, the more The more active the application, the more anonymous pages will be recycled later.
  • the recycling ratio of the anonymous page may be controlled according to the application-level memory control group.
  • application 1 creates a corresponding application-level memory control group memcg1 at startup
  • application 2 creates a corresponding application-level memory control group memcg2 at startup. If the recovery ratio of anonymous pages controlled in the application-level memory control group memcg1 is 60%, and the LRU linked list 1 in application 1 includes 1-100 anonymous pages, only 60 anonymous pages can be recovered sequentially from the tail of the LRU linked list 1 during memory recovery. Page.
  • the recovery ratio of anonymous pages controlled in the application-level memory control group memcg2 is 70%, and the LRU linked list 2 in application 2 includes 1-100 anonymous pages, only 70 anonymous pages can be recovered sequentially from the tail of the LRU linked list 2 during memory recovery. Page. It can be understood that, in an embodiment, the more active the application is, the lower the recycling rate of its anonymous pages is.
  • Step S1-33 adding the file page applied for by the application to the global least recently used linked list.
  • the electronic device 1-100 when the application starts, it will apply for memory resources from the system, and the electronic device 1-100 will add the anonymous page to the application-level memory control group corresponding to the application.
  • the electronic device 1-100 -100 also adds the file page applied for by the application to the global LRU linked list. For example, the application may add the file page to the global LRU linked list when the file page is just applied for.
  • the user may open a shopping application in the electronic device 1-100, and the electronic device 1-100 creates a corresponding application-level memory control group memcg3 for the shopping application.
  • the shopping application can load library files such as so and lib from the disk, and the file page applied for can be added to the global LRU linked list.
  • the user can open the gallery application in the electronic device 1-100, and the electronic device 1-100 creates a corresponding application-level memory control group memcg4 for the gallery application.
  • the gallery application can load photos from the disk, etc.
  • the file page applied for can be added to the global LRU linked list.
  • the system can recycle the library file and the photo file according to the location of the global LRU linked list.
  • the LRU linked list can be divided into an active (active) linked list and an inactive (inactive) linked list, and the pages of memory reclamation are obtained from the inactive linked list. That is to say, the memory control group corresponding to the first application uses two LRU linked lists to manage anonymous pages, and the file page uses two global LRU linked lists to manage.
  • the applied anonymous page is added to the active linked list of the application-level memory control group corresponding to the application, and the applied-for anonymous page is added to the active linked list of the application-level memory control group corresponding to the application.
  • the file page is added to the global active list.
  • the anonymous page of the inactive linked list is referenced for a preset number of times, the anonymous page can be extracted from the inactive linked list and placed in the active linked list.
  • the system can continue to scan the active linked list and migrate some anonymous pages to the inactive linked list.
  • a memory control group can be created according to a process identifier (pid), and each process id manages its own LRU linked list, that is, a memory control group is created according to the process dimension.
  • pid process identifier
  • the problem of wasting power consumption will be brought to the electronic device 1-100, thereby affecting the user experience.
  • an application is the smallest unit that interacts with the user in the electronic device 1-100. From the user's point of view, the application is an operation object; from the demand point of view, the application is a carrier of resource requirements. Therefore, in the technical solution of the present application, an application-level memory control group is created according to the application dimension. That is, each application creates an application-level memory control group.
  • each process may correspond to a memory control group, but this will consume huge system resources.
  • the file page is the cache or buffer area of the disk file, sharing is its main feature. Therefore, the management of file pages according to the memory control group will lead to uneven distribution of hot and cold file pages. In addition, when the memory is insufficient, the memory will be obtained through recycling. The uneven distribution of hot and cold file pages will lead to frequent recycling of hot file pages, which is prone to system freezes and seriously affects the user experience.
  • the embodiments of the present application by creating a corresponding application-level memory control group for an application, the anonymous page applied for by the application is added to the LRU linked list of the application-level memory control group, and the application application The accessed file pages are added to a global LRU list.
  • the embodiments of the present application can manage anonymous pages in the application dimension, and control the memory, power consumption, and performance, and at the same time, improve memory recycling efficiency, reduce system freezes, and improve user experience.
  • FIG. 1-4 is another schematic flowchart of a memory management method provided by an embodiment of the present application. The method may include, but is not limited to, the following steps:
  • step S1-41 when the process of the application is started, an application-level memory control group corresponding to the application is created according to the application identifier corresponding to the process.
  • a process is an application running in memory and is the basic unit of resource allocation and scheduling in the system. Each process has its own independent piece of memory space.
  • each application has an application identifier (for example, a package name), which can be used to uniquely identify the application.
  • application identifier for example, a package name
  • the application identifier of the application can be determined by querying the configuration information of the application.
  • the application identifier of the application can be determined according to the process identifier of the application. .
  • an application may include multiple processes. That is, the application may include multiple processes, and when the process of the application is started, an application-level memory control group corresponding to the first application is created according to the application identifier corresponding to the process.
  • the electronic device 1-100 may create an application-level memory control group corresponding to the application according to the package name corresponding to the process.
  • the browser is created.
  • the process 1 is added to the application-level memory control group memcg1 of the browser, and the process 1 is managed according to the application-level memory control group memcg1, wherein the memory resources of the process 1 can be added to In the LRU linked list of the application-level memory control group memcg1.
  • the process 2 of the browser since the browser includes process 1 and process 2, the process 2 and the process 1 belong to the same application identifier APP1, and the application corresponding to the process 2 at this time. Identifies that APP1 has created an application-level memory control group memcg1. Therefore, when the process 2 starts, the process 2 is directly added to the application-level memory control group memcg1 corresponding to the browser, and the memory of the process 2 The resource is added to the LRU list of the application-level memory control group memcg2.
  • Step S1-42 adding the anonymous page of the process to the least recently used linked list of the memory control group, reclaiming the anonymous page according to the least recently used linked list, and adding the file page of the process to the memory node.
  • the file pages are reclaimed according to the global least recently used linked list.
  • the anonymous page applied for by the first process may be added to the LRU of the memory control group
  • the linked list is added, and the file page applied for by the first process is added to the global LRU linked list of the memory node.
  • the process 2 of the browser is started, since the process 2 and the process 1 belong to the same application identifier APP1, the application identifier APP1 corresponding to the process 2 has already created an application-level memory control group memcg1 , therefore, when the process 2 starts, the anonymous page applied for by the process 2 is directly added to the application-level memory control group memcg1 of the browser, so process 1 and process 2 can be compared according to the least recently used linked list.
  • the anonymous pages of the process 2 are recycled, and the file pages applied for by the process 2 are added to the global LRU linked list, and the file pages of the process 1 and the process 2 can be recycled according to the global least recently used linked list.
  • Step S1-43 if the process is destroyed, delete the process from the application-level memory control group.
  • the process of the application may be deleted from the application-level memory control group of the application.
  • the system can choose to kill the process 1 and the process 2, and simultaneously remove the process 1 and all the The process 2 is deleted from the memory control group corresponding to the application, so that some anonymous pages and file pages of the application can be released to meet the memory requirements of the system.
  • Step S1-44 if the application is destroyed, delete the application-level memory control group.
  • the memory control group corresponding to the application is deleted. For example, if all the processes in the memory control group of the application are destroyed, the anonymous pages of the process can be deleted and released from the least recently used linked list of the application-level memory control group, and the file pages of the process can be deleted from the global memory control group. Deleted and released from the least recently used list.
  • the user creates 3 processes after starting the browser, that is, the browser may include process 1, process 2 and process 3, and the process 1, the process 2 and the process 3 are all added to the In the browser's application-level memory control group memcg1.
  • process 1, process 2 and process 3 in the memory control group of the first application are destroyed, and the kernel will delete the application-level memory control group memcg1 of the browser.
  • the memory occupied by the browser can also be released.
  • FIG. 1-5 is another schematic flowchart of a memory management method provided by an embodiment of the present application.
  • the memory management method may include, but is not limited to, the following steps:
  • Step S1-51 create a memory control group according to the whitelist.
  • a memory control group can be created according to the whitelist, so the key system processes in the whitelist can be added to the memory control group.
  • Step S1-52 when the system process is started, it is judged whether it is a whitelist process according to the process name of the system process.
  • the system process may include: the system manages the computer individual and processes necessary to complete various operations, such as additional program processes started and executed by the user. Among these processes, some system processes are the processes that the system needs to call. If these processes are lacking, the operation of the entire system will be affected, such as key system services and frequently used system services.
  • the whitelist may include process name 1 of system process 1, process 2 of system process 2, and process name 3 of system process 3. If, when the system process 1 is started, it is determined that the process name 1 of the system process 1 is in the white list, it can be determined that the system process 1 is a white list process. If, when the system process 2 is started, it is determined that the process name 2 of the system process 2 is in the white list, it can be determined that the system process 2 is a white list process. If it is determined that the process name 4 of the system process 4 is not in the whitelist when the system process 4 is started, it can be determined that the system process 4 is not a whitelist process.
  • Step S1-53 adding a system process to the memory control group.
  • the whitelisted process is added to the memory control group, that is, some key system services and frequently used system services are added to the whitelist , to prevent the system from recycling these system processes by mistake and affecting the user experience.
  • the anonymous page of the whitelisted process can be added to the least recently used linked list of the memory control group, and the least recently used linked list can be The anonymous pages of the whitelisted process are reclaimed.
  • the file pages of the whitelisted process can also be added to the global least recently used linked list of the memory node, so that the whitelist can be updated according to the global least recently used linked list. The process's file pages are reclaimed.
  • FIG. 1-6 is a scene diagram of the memory management disclosed in the embodiment of the present application.
  • an application-level memory control group of the application may be created according to the package name of the application. Therefore, in some embodiments of the present application, each application creates an application-level memory control group. For example, each application will manage memory according to the corresponding application-level memory control group.
  • the application-level memory control group corresponding to the package name of the application may be deleted, and the memory corresponding to the application-level memory control group of the application may be released .
  • FIG. 1-7 is a more specific scene diagram of the memory management disclosed in the embodiment of the present application.
  • the electronic device 1-100 When the process 1 of the news application is created, the electronic device 1-100 will create an application-level memory control group memcg1 according to the package name of the news application. Next, the kernel adds the anonymous page applied for by the news application to the application-level memory control group memcg1, and adds the file page applied for by the news application to the global LRU linked list. It can be understood that, in one embodiment, other applications in the electronic device, such as a music application, can also create a corresponding application-level memory control group memcg2 at startup, and add the anonymous page applied for by the music application to the application-level memory control group memcg2. Memory control group memcg2, and add the file page applied by the music application to the global LRU linked list.
  • process 2 of the news application is created, the process 2 is added to the application-level memory control group memcg1 of the news application, the anonymous page applied for by the process 2 is added to the application-level memory control group memcg1, and the The file page applied for by process 2 is added to the global LRU linked list.
  • anonymous pages can be managed according to the dimension of the application, and memory, power consumption, and performance consumption can be controlled, so that refined memory management can be realized.
  • FIG. 1-8 is a scene diagram of the memory management disclosed in the embodiment of the present application.
  • the embodiment of the present application customizes various parameter setting interfaces for the application-level memory control group of each application. Therefore, the user mode can set the recycling priority of the application, the maximum memory usage of the application, and the recycling parameter of the application through parameter settings. Wait.
  • the user mode can correspondingly control the recycling sequence of the application-level memory control group in the kernel space by setting the parameters of the application-level memory control group of the application. For example, the user mode can set the corresponding recycling priority according to the importance of the application. Therefore, when memory recycling is required, the recycling sequence of the application-level memory control group in the kernel space is controlled according to the recycling priority of the application. Specifically, the user mode can also control the recycling ratio of the application-level memory control group in the kernel space according to the parameters of the application-level memory control group.
  • the operating system is independent of ordinary applications, and can access the protected memory space, as well as the permission to access the underlying hardware device.
  • the operating system divides the addressing space (the addressing space can be a part of the memory of the computing device or a virtual storage space) into two parts, one part is The kernel space, which is a protected memory space, is used to store the code and data of the kernel; the other part is the user space, which is used to store the code and data of the application.
  • the kernel space which is a protected memory space
  • the user space which is used to store the code and data of the application.
  • the user mode can control the behavior of the application-level memory control group in the kernel mode by setting parameters of the application-level memory control group of the application.
  • the user mode may control the memory usage of the application, such as the maximum memory usage of the application, according to the parameters of the application-level memory control group of the application.
  • the user mode can set the maximum memory usage of the browser through the interface, that is, the memory size of each application can be limited. Assuming that the maximum memory usage of the browser is 800Mb, but the memory used by the browser is 900Mb, at this time, since the browser's file pages have been backed up to disk, the system kernel will The file page is cleaned up, and the anonymous page of the browser is compressed to meet the memory requirement.
  • the parameters of the application-level memory control group can be set by providing the following interface:
  • Waterline setting interface User mode can set the standard waterline of system memory through the waterline setting interface, and the kernel will try to satisfy this waterline by recycling to ensure that the system memory is in a healthy state.
  • Proportion setting interface User mode can set the recycling and swapping ratio of each application through the proportional setting interface according to user habits and application characteristics, to control the amount of recycling and swapping, reduce invalid recycling of applications, and enhance user experience.
  • Important score value setting interface User mode can set the priority and importance of each application through the important score value setting interface according to user habits and application characteristics, determine their recycling order in recycling, and enhance user experience.
  • Application memory usage upper limit setting interface User mode sets the memory usage upper limit of each application through the application memory usage upper limit setting interface to ensure that each application uses memory benignly.
  • Active compression interface When the application is in a frozen state, the user mode actively compresses and reclaims the anonymous pages of the application through the active compression interface to increase the system memory and ensure the health of the memory.
  • Application memory usage interface uses the application memory usage interface to query the anonymous page occupancy of each application in the system, which is used as a reference when cleaning and recycling.
  • System status interface The user mode queries the real-time status of the system through the system status interface, such as the system memory status, CPU status, IO status, and the running status of some key processes.
  • the system can recycle the file pages according to the hot and cold conditions of the global LRU linked list according to the importance of the application, the maximum memory usage of the application, and the reclamation parameters of the application, etc. , the anonymous page is recycled according to the parameters set by the user. Therefore, with the technical solutions of the embodiments of the present application, memory recovery is more targeted, and the recovery efficiency can be further improved.
  • FIG. 1-9 is a schematic structural diagram of a memory management apparatus disclosed in an embodiment of the present application.
  • the memory management device can be used to execute the steps of the memory management method described in FIGS. 1-3 to 1-8 .
  • the memory management apparatus 1-200 may include: a creation module 1-201, a control module 1-202, and a management module 1-203.
  • the creation module 1-201 is configured to create an application-level memory control group of the first application when the first application is started;
  • the control module 1-202 is configured to add the anonymous page applied for by the application to the least recently used linked list of the memory control group, and the control module 1-202 is further configured to add the file applied for by the application The page is added to the global least recently used list.
  • the creating module 1-201 may also be configured to create an application-level memory control group corresponding to the application according to the application identifier corresponding to the process when the process of the application is started.
  • the creation module 1-201 creates an application-level memory control group corresponding to the application.
  • the control module 1-202 adds the process to the application-level memory control group, and adds the anonymous page of the process to the application-level memory control group. Add to the least recently used linked list of the application-level memory control group, and add the file page of the process to the global least recently used linked list.
  • the management module 1-203 is configured to delete the process from the application-level memory control group when the process is destroyed.
  • the management module 1-203 is further configured to delete the application-level memory control group when all processes in the application-level memory control group of the application are destroyed.
  • the management module 1-203 can also be used for:
  • control module 1-202 is also used for:
  • control module 1-202 is configured to add the anonymous page to the active least recently used linked list of the first memory control group;
  • the management module 1-203 is configured to add the file page to the global active least recently used linked list.
  • the management module 1-203 is configured to control the reclamation sequence of the memory control group in the kernel space according to the first parameter of the memory control group.
  • the management module 1-203 is configured to control the reclamation ratio of the memory control group in the kernel space according to the second parameter of the memory control group.
  • the management module 1-203 is further configured to control the memory usage amount of the memory control group in the kernel space according to the third parameter of the memory control group. It can be understood that the division of each module in the above-mentioned memory management apparatus is only for illustration, and in other embodiments, the memory management apparatus may be divided into different modules as required to complete the functions of the above-mentioned memory management apparatus.
  • each module in the memory management apparatus may be in the form of a computer program.
  • the computer program can run on an electronic device or server.
  • the specific implementation of each module in the embodiments of the present application may also refer to the corresponding descriptions of the method embodiments shown in FIGS. 1-3 to 1-8 .
  • anonymous pages can be managed in a refined manner, and recycling pertinence and recycling efficiency can be improved, thereby avoiding application freezes and improving user experience.
  • Embodiments of the present application also provide a computer-readable storage medium.
  • the readable storage medium stores computer instructions, and when the instructions run on the computing device, can cause the computing device to execute the memory management method provided by the foregoing embodiments.
  • the embodiments of the present application disclose a memory management method, an electronic device, and a computer-readable storage medium, which can improve the fluency of an operating system, avoid a stuck phenomenon in an electronic device, and improve user experience.
  • the memory management method provided by the embodiments of the present application can be applied to electronic equipment, and the electronic equipment may also be referred to as user equipment (User Equipment, UE), mobile station (Mobile Station, MS), mobile terminal (Mobile Terminal), etc. .
  • the electronic device may be capable of communicating with a radio access network (Radio Access Network, RAN) and one or more core networks, for example, the electronic device may be a mobile phone (or referred to as a "cellular" phone) , or a mobile computer, etc.
  • RAN Radio Access Network
  • FIG. 2-1 shows a schematic structural diagram of an electronic device 2-100.
  • the electronic device 2-100 may be a cell phone, tablet computer, desktop computer, laptop computer, handheld computer, notebook computer, ultra-mobile personal computer (UMPC), netbook, as well as cellular telephones, personal digital assistants (personal digital assistant, PDA), augmented reality (AR) devices, virtual reality (VR) devices, artificial intelligence (artificial intelligence, AI) devices, wearable devices, in-vehicle devices, smart home devices and /or smart city equipment, the embodiments of the present application do not specifically limit the specific type of the electronic equipment.
  • PDA personal digital assistant
  • AR augmented reality
  • VR virtual reality
  • AI artificial intelligence
  • wearable devices wearable devices
  • in-vehicle devices smart home devices and /or smart city equipment
  • smart city equipment the embodiments of the present application do not specifically limit the specific type of the electronic equipment.
  • the electronic device 2-100 may include a processor 2-110, an external memory interface 2-120, an internal memory 2-121, a universal serial bus (USB) interface 2-130, a charge management module 2-140, a power supply Management module 2-141, battery 2-142, antenna 2-1, antenna 2-2, mobile communication module 2-150, wireless communication module 2-160, audio module 2-170, speaker 2-170A, receiver 2-170B , Microphone 2-170C, Headphone Jack 2-170D, Sensor Module 2-180, Key 2-190, Motor 2-191, Indicator 2-192, Camera 2-193, Display 2-194, and User Identification Module ( subscriber identification module, SIM) card interface 2-195, etc.
  • a processor 2-110 an external memory interface 2-120, an internal memory 2-121, a universal serial bus (USB) interface 2-130, a charge management module 2-140, a power supply Management module 2-141, battery 2-142, antenna 2-1, antenna 2-2, mobile communication module 2-150, wireless communication module 2-160, audio module 2-170, speaker 2-170A, receiver 2-170B
  • the sensor module 2-180 may include a pressure sensor 2-180A, a gyroscope sensor 2-180B, an air pressure sensor 2-180C, a magnetic sensor 2-180D, an acceleration sensor 2-180E, a distance sensor 2-180F, a proximity light sensor 2- 180G, fingerprint sensor 2-180H, temperature sensor 2-180J, touch sensor 2-180K, ambient light sensor 2-180L, bone conduction sensor 2-180M, etc.
  • the structures illustrated in the embodiments of the present application do not constitute a specific limitation on the electronic device 2-100.
  • the electronic device 2-100 may include more or less components than shown, or some components may be combined, or some components may be separated, or different component arrangements.
  • the illustrated components may be implemented in hardware, software, or a combination of software and hardware.
  • the processor 2-110 may include one or more processing units, for example, the processor 2-110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), image signal processor (ISP), controller, video codec, digital signal processor (DSP), baseband processor, and/or neural-network processing unit, NPU), etc. Wherein, different processing units may be independent devices, or may be integrated in one or more processors.
  • application processor application processor, AP
  • modem processor graphics processor
  • ISP image signal processor
  • DSP digital signal processor
  • NPU neural-network processing unit
  • different processing units may be independent devices, or may be integrated in one or more processors.
  • the controller can generate an operation control signal according to the instruction operation code and timing signal, and complete the control of fetching and executing instructions.
  • Memory may also be provided in the processor 2-110 for storing instructions and data.
  • the memory in processor 2-110 is a cache memory. This memory may hold instructions or data that have just been used or recycled by the processor 2-110. If the processor 2-110 needs to use the instruction or data again, it can be called directly from the memory. Repeated accesses are avoided and the latency of the processor 2-110 is reduced, thereby increasing the efficiency of the system.
  • the processor 2-110 may include one or more interfaces.
  • the interface may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous transceiver (universal asynchronous transmitter) receiver/transmitter, UART) interface, mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, subscriber identity module (SIM) interface, and / or universal serial bus (universal serial bus, USB) interface, etc.
  • I2C integrated circuit
  • I2S integrated circuit built-in audio
  • PCM pulse code modulation
  • PCM pulse code modulation
  • UART universal asynchronous transceiver
  • MIPI mobile industry processor interface
  • GPIO general-purpose input/output
  • SIM subscriber identity module
  • USB universal serial bus
  • the I2C interface is a bidirectional synchronous serial bus that includes a serial data line (SDA) and a serial clock line (SCL).
  • processor 2-110 may contain multiple sets of I2C buses.
  • the processor 2-110 can respectively couple the touch sensor 2-180K, charger, flash, camera 2-193, etc. through different I2C bus interfaces.
  • the processor 2-110 can couple the touch sensor 2-180K through the I2C interface, so that the processor 2-110 communicates with the touch sensor 2-180K through the I2C bus interface, so as to realize the touch function of the electronic device 2-100.
  • the I2S interface can be used for audio communication.
  • processor 2-110 may contain multiple sets of I2S buses.
  • the processor 2-110 can be coupled with the audio module 2-170 through the I2S bus to implement communication between the processor 2-110 and the audio module 2-170.
  • the audio module 2-170 can transmit audio signals to the wireless communication module 2-160 through the I2S interface, so as to realize the function of answering calls through a Bluetooth headset.
  • the PCM interface can also be used for audio communications, sampling, quantizing and encoding analog signals.
  • the audio module 2-170 and the wireless communication module 2-160 may be coupled through a PCM bus interface.
  • the audio module 2-170 can also transmit audio signals to the wireless communication module 2-160 through the PCM interface, so as to realize the function of answering calls through a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
  • the UART interface is a universal serial data bus used for asynchronous communication.
  • the bus may be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication.
  • a UART interface is typically used to connect the processor 2-110 with the wireless communication module 2-160.
  • the processor 2-110 communicates with the Bluetooth module in the wireless communication module 2-160 through the UART interface to realize the Bluetooth function.
  • the audio module 2-170 can transmit audio signals to the wireless communication module 2-160 through the UART interface, so as to realize the function of playing music through the Bluetooth headset.
  • the MIPI interface can be used to connect the processor 2-110 with the display screen 2-194, the camera 2-193 and other peripheral devices.
  • MIPI interfaces include camera serial interface (CSI), display serial interface (DSI), etc.
  • the processor 2-110 communicates with the camera 2-193 through the CSI interface, so as to realize the shooting function of the electronic device 2-100.
  • the processor 2-110 communicates with the display screen 2-194 through the DSI interface to realize the display function of the electronic device 2-100.
  • the GPIO interface can be configured by software.
  • the GPIO interface can be configured as a control signal or as a data signal.
  • the GPIO interface can be used to connect the processor 2-110 with the camera 2-193, the display screen 2-194, the wireless communication module 2-160, the audio module 2-170, the sensor module 2-180, and so on.
  • the GPIO interface can also be configured as I2C interface, I2S interface, UART interface, MIPI interface, etc.
  • the USB interface 2-130 is an interface that conforms to the USB standard specification, which can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc.
  • the USB interface 2-130 can be used to connect a charger to charge the electronic device 2-100, and can also be used to transmit data between the electronic device 2-100 and peripheral devices. It can also be used to connect headphones to play audio through the headphones.
  • the interface can also be used to connect other electronic devices, such as AR devices.
  • the interface connection relationship between the modules illustrated in the embodiments of the present application is a schematic illustration, and does not constitute a structural limitation of the electronic device 2-100.
  • the electronic device 2-100 may also adopt different interface connection manners in the foregoing embodiments, or a combination of multiple interface connection manners.
  • the charging management module 2-140 is used to receive charging input from the charger.
  • the charger may be a wireless charger or a wired charger.
  • the charging management module 2-140 may receive charging input from the wired charger through the USB interface 2-130.
  • the charging management module 2-140 may receive wireless charging input through the wireless charging coil of the electronic device 2-100. While the charging management module 2-140 charges the battery 2-142, it can also supply power to the electronic device through the power management module 2-141.
  • the power management module 2-141 is used to connect the battery 2-142, the charging management module 2-140 and the processor 2-110. Power management module 2-141 receives input from battery 2-142 and/or charge management module 2-140 for processor 2-110, internal memory 2-121, display screen 2-194, camera 2-193, and wireless communication Modules 2-160 etc. supply power. The power management module 2-141 can also be used to monitor parameters such as battery capacity, battery cycle times, battery health status (leakage, impedance). In some other embodiments, the power management module 2-141 may also be provided in the processor 2-110. In other embodiments, the power management module 2-141 and the charging management module 2-140 may also be provided in the same device.
  • the wireless communication function of the electronic device 2-100 can be realized by the antenna 2-1, the antenna 2-2, the mobile communication module 2-150, the wireless communication module 2-160, the modulation and demodulation processor and the baseband processor.
  • the antenna 2-1 and the antenna 2-2 are used to transmit and receive electromagnetic wave signals.
  • Each antenna in electronic device 2-100 may be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization.
  • the antenna 2-1 can be multiplexed as a diversity antenna of the wireless local area network. In other embodiments, the antenna may be used in conjunction with a tuning switch.
  • the mobile communication module 2-150 can provide a wireless communication solution including 2G/3G/4G/5G etc. applied on the electronic device 2-100.
  • the mobile communication module 2-150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), and the like.
  • the mobile communication module 2-150 can receive electromagnetic waves from the antenna 2-1, filter and amplify the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation.
  • the mobile communication module 2-150 can also amplify the signal modulated by the modulation and demodulation processor, and then convert it into electromagnetic waves for radiation through the antenna 2-1.
  • at least part of the functional modules of the mobile communication module 2-150 may be provided in the processor 2-110.
  • at least part of the functional modules of the mobile communication module 2-150 may be provided in the same device as at least part of the modules of the processor 2-110.
  • the modem processor may include a modulator and a demodulator.
  • the modulator is used to modulate the low frequency baseband signal to be sent into a medium and high frequency signal.
  • the demodulator is used to demodulate the received electromagnetic wave signal into a low frequency baseband signal. Then the demodulator transmits the demodulated low-frequency baseband signal to the baseband processor for processing.
  • the low frequency baseband signal is processed by the baseband processor and passed to the application processor.
  • the application processor outputs sound signals through audio devices (not limited to the speaker 2-170A, the receiver 2-170B, etc.), or displays images or videos through the display screen 2-194.
  • the modem processor may be a stand-alone device.
  • the modem processor may be independent of the processor 2-110, and be provided in the same device as the mobile communication module 2-150 or other functional modules.
  • the wireless communication module 2-160 can provide applications on the electronic device 2-100 including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (bluetooth, BT) , Global Navigation Satellite System (GNSS), Frequency Modulation (FM), Near Field Communication (NFC), Infrared (IR) and other wireless communication solutions.
  • the wireless communication module 2-160 may be one or more devices integrating at least one communication processing module.
  • the wireless communication module 2-160 receives electromagnetic waves via the antenna 2-2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 2-110.
  • the wireless communication module 2-160 can also receive the signal to be sent from the processor 2-110, perform frequency modulation on it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2-2.
  • the antenna 2-1 of the electronic device 2-100 is coupled with the mobile communication module 2-150, and the antenna 2-2 is coupled with the wireless communication module 2-160, so that the electronic device 2-100 can communicate with network and other device communication.
  • the wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), broadband Code Division Multiple Access (WCDMA), Time Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC , FM, and/or IR technology, etc.
  • the GNSS may include global positioning system (global positioning system, GPS), global navigation satellite system (global navigation satellite system, GLONASS), Beidou navigation satellite system (beidou navigation satellite system, BDS), quasi-zenith satellite system (quasi -zenith satellite system, QZSS) and/or satellite based augmentation systems (SBAS).
  • global positioning system global positioning system, GPS
  • global navigation satellite system global navigation satellite system, GLONASS
  • Beidou navigation satellite system beidou navigation satellite system, BDS
  • quasi-zenith satellite system quadsi -zenith satellite system, QZSS
  • SBAS satellite based augmentation systems
  • the electronic device 2-100 realizes the display function through the GPU, the display screen 2-194, and the application processor.
  • the GPU is a microprocessor for image processing, and connects the display screen 2-194 and the application processor.
  • the GPU is used to perform mathematical and geometric calculations for graphics rendering.
  • Processor 2-110 may include one or more GPUs that execute program instructions to generate or alter display information.
  • Display 2-194 is used to display images, videos, etc.
  • Display 2-194 includes a display panel.
  • the display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (active-matrix organic light).
  • emitting diode AMOLED
  • flexible light-emitting diode flex light-emitting diode, FLED
  • Miniled MicroLed, Micro-oLed, quantum dot light-emitting diode (quantum dot light emitting diodes, QLED) and so on.
  • the electronic device 2-100 may include 1 or N display screens 2-194, where N is a positive integer greater than 1.
  • the electronic device 2-100 can realize the shooting function through the ISP, the camera 2-193, the video codec, the GPU, the display screen 2-194, and the application processor.
  • ISP is used to process the data fed back by camera 2-193.
  • the shutter is opened, the light is transmitted to the camera photosensitive element through the lens, the light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing, and converts it into an image visible to the naked eye.
  • ISP can also perform algorithm optimization on image noise, brightness, and skin tone. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene.
  • the ISP may be located in the camera 2-193.
  • Camera 2-193 is used to capture still images or video.
  • the object is projected through the lens to generate an optical image onto the photosensitive element.
  • the photosensitive element may be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor.
  • CMOS complementary metal-oxide-semiconductor
  • the photosensitive element converts the optical signal into an electrical signal, and then transmits the electrical signal to the ISP to convert it into a digital image signal.
  • the ISP outputs the digital image signal to the DSP for processing.
  • DSP converts digital image signals into standard RGB, YUV and other formats of image signals.
  • the electronic device 2-100 may include 1 or N cameras 2-193, where N is a positive integer greater than 1.
  • a digital signal processor is used to process digital signals, in addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 2-100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy, and the like.
  • Video codecs are used to compress or decompress digital video.
  • Electronic device 2-100 may support one or more video codecs. In this way, the electronic device 2-100 can play or record videos in various encoding formats, such as: moving picture experts group (moving picture experts group, MPEG) 1, MPEG2, MPEG3, MPEG4 and so on.
  • MPEG moving picture experts group
  • the NPU is a neural-network (NN) computing processor.
  • NN neural-network
  • Applications such as intelligent cognition of electronic devices 2-100 can be realized through the NPU, such as image recognition, face recognition, speech recognition, text understanding, etc.
  • the internal memory 2-121 may include one or more random access memories (RAM) and one or more non-volatile memories (NVM).
  • RAM random access memories
  • NVM non-volatile memories
  • Random access memory can include static random-access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronization Dynamic random access memory (double data rate synchronous dynamic random access memory, DDR SDRAM, such as fifth-generation DDR SDRAM is generally called DDR5 SDRAM), etc.;
  • SRAM static random-access memory
  • DRAM dynamic random access memory
  • SDRAM synchronous dynamic random access memory
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • fifth-generation DDR SDRAM is generally called DDR5 SDRAM
  • Non-volatile memory may include magnetic disk storage devices, flash memory.
  • Flash memory can be divided into NOR FLASH, NAND FLASH, 3D NAND FLASH, etc. according to the operating principle, and can include single-level memory cells (single-level cells, SLC), multi-level memory cells (multi-level memory cells) according to the level of storage cell potential cell, MLC), triple-level cell (TLC), quad-level cell (QLC), etc., according to the storage specification can include universal flash storage (English: universal flash storage, UFS) , embedded multimedia memory card (embedded multi media Card, eMMC) and so on.
  • SLC single-level memory cells
  • multi-level memory cells multi-level memory cells
  • MLC multi-level memory cells
  • TLC triple-level cell
  • QLC quad-level cell
  • UFS universal flash storage
  • eMMC embedded multimedia memory card
  • the random access memory can be directly read and written by the processor 2-110, and can be used to store executable programs (such as machine instructions) of the operating system or other running programs, and can also be used to store user and application data. Wait.
  • the non-volatile memory can also store executable programs and store data of user and application programs, etc., and can be loaded into the random access memory in advance for the processor 2-110 to directly read and write.
  • the external memory interface 2-120 can be used to connect an external non-volatile memory, so as to expand the storage capacity of the electronic device 2-100.
  • the external non-volatile memory communicates with the processor 2-110 through the external memory interface 2-120 to realize the data storage function. For example, save music, video, etc. files in external non-volatile memory.
  • the electronic device 2-100 can implement audio functions through an audio module 2-170, a speaker 2-170A, a receiver 2-170B, a microphone 2-170C, an earphone interface 2-170D, and an application processor. Such as music playback, recording, etc.
  • the audio module 2-170 is used to convert digital audio information to analog audio signal output, and is also used to convert analog audio input to digital audio signal. Audio module 2-170 may also be used to encode and decode audio signals. In some embodiments, the audio module 2-170 may be provided in the processor 2-110, or some functional modules of the audio module 2-170 may be provided in the processor 2-110.
  • Speaker 2-170A also known as "horn" is used to convert audio electrical signals into sound signals.
  • Electronic device 2-100 can listen to music through speaker 2-170A, or listen to hands-free calls.
  • the receiver 2-170B also referred to as the "earpiece" is used to convert audio electrical signals into sound signals.
  • the electronic device 2-100 answers a call or a voice message, the voice can be answered by placing the receiver 2-170B close to the human ear.
  • Microphone 2-170C also known as “microphone”, “microphone”, is used to convert sound signals into electrical signals.
  • the user can make a sound by approaching the microphone 2-170C through the human mouth, and input the sound signal into the microphone 2-170C.
  • the electronic device 2-100 may be provided with at least one microphone 2-170C.
  • the electronic device 2-100 may be provided with two microphones 2-170C, which can implement a noise reduction function in addition to acquiring sound signals.
  • the electronic device 2-100 may further be provided with three, four or more microphones 2-170C to achieve sound signal acquisition, noise reduction, identification of sound sources, and directional recording functions.
  • the headphone jack 2-170D is used to connect wired headphones.
  • the headphone interface 2-170D can be a USB interface 2-130, or a 3, 5mm open mobile terminal platform (OMTP) standard interface, the cellular telecommunications industry association of the USA, CTIA) standard interface.
  • OMTP open mobile terminal platform
  • the pressure sensor 2-180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal.
  • the pressure sensor 2-180A may be provided on the display screen 2-194.
  • the capacitive pressure sensor may be comprised of at least two parallel plates of conductive material. When a force is applied to the pressure sensor 2-180A, the capacitance between the electrodes changes.
  • the electronic device 2-100 determines the intensity of the pressure from the change in capacitance. When a touch operation acts on the display screen 2-194, the electronic device 2-100 detects the intensity of the touch operation according to the pressure sensor 2-180A.
  • the electronic device 2-100 can also calculate the touched position according to the detection signal of the pressure sensor 2-180A.
  • touch operations acting on the same touch position but with different touch operation intensities may correspond to different operation instructions. For example, when a touch operation whose intensity is less than the tenth pressure threshold acts on the short message application icon, the instruction for viewing the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the tenth pressure threshold acts on the short message application icon, the instruction to create a new short message is executed.
  • the gyro sensor 2-180B can be used to determine the motion attitude of the electronic device 2-100.
  • the angular velocity of electronic device 2-100 about three axes may be determined by gyro sensor 2-180B.
  • Gyro sensor 2-180B can be used for image stabilization.
  • the gyroscope sensor 2-180B detects the shaking angle of the electronic device 2-100, calculates the distance to be compensated by the lens module according to the angle, and allows the lens to offset the electronic device 2-100 through reverse motion. Shake, achieve anti-shake.
  • the gyroscope sensor 2-180B can also be used for navigation and somatosensory game scenes.
  • Air pressure sensor 2-180C is used to measure air pressure.
  • the electronic device 2-100 calculates altitude from the air pressure value measured by the air pressure sensor 2-180C to assist in positioning and navigation.
  • Magnetic sensor 2-180D includes a Hall sensor.
  • the electronic device 2-100 can detect the opening and closing of the flip holster using the magnetic sensor 2-180D.
  • the electronic device 2-100 can detect the opening and closing of the flip according to the magnetic sensor 2-180D. Further, according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, characteristics such as unlocking the flip cover are set.
  • the acceleration sensor 2-180E can detect the magnitude of the acceleration of the electronic device 2-100 in various directions (generally three axes).
  • the magnitude and direction of gravity can be detected when the electronic device 2-100 is stationary. It can also be used to identify the posture of electronic devices, and can be used in applications such as horizontal and vertical screen switching, pedometers, etc.
  • Distance sensor 2-180F for measuring distance.
  • Electronic device 2-100 can measure distance by infrared or laser. In some embodiments, to capture a scene, the electronic device 2-100 can use the distance sensor 2-180F to measure the distance to achieve fast focusing.
  • Proximity light sensor 2-180G may include, for example, light emitting diodes (LEDs) and light detectors, such as photodiodes.
  • the light emitting diodes may be infrared light emitting diodes.
  • the electronic device 2-100 emits infrared light outward through light emitting diodes.
  • Electronic device 2-100 uses photodiodes to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object in the vicinity of the electronic device 2-100. When insufficient reflected light is detected, the electronic device 2-100 may determine that there is no object in the vicinity of the electronic device 2-100.
  • the electronic device 2-100 can use the proximity light sensor 2-180G to detect that the user holds the electronic device 2-100 close to the ear to talk, so as to turn off the screen to save power.
  • Proximity light sensor 2-180G can also be used in holster mode, pocket mode unlock and lock screen.
  • the ambient light sensor 2-180L is used to sense ambient light brightness.
  • the electronic device 2-100 can adaptively adjust the brightness of the display screen 2-194 according to the perceived ambient light brightness.
  • the ambient light sensor 2-180L can also be used to adjust the white balance when taking pictures.
  • the ambient light sensor 2-180L can also cooperate with the proximity light sensor 2-180G to detect whether the electronic device 2-100 is in the pocket to prevent accidental touch.
  • the fingerprint sensor 2-180H is used to acquire fingerprints.
  • the electronic device 2-100 can use the acquired fingerprint characteristics to realize fingerprint unlocking, accessing application lock, taking photos with fingerprints, answering incoming calls with fingerprints, and the like.
  • Temperature sensor 2-180J is used to detect temperature.
  • the electronic device 2-100 utilizes the temperature detected by the temperature sensor 2-180J to implement a temperature handling strategy. For example, when the temperature reported by the temperature sensor 2-180J exceeds a threshold, the electronic device 2-100 performs a performance reduction of the processor located near the temperature sensor 2-180J in order to reduce power consumption and implement thermal protection.
  • the electronic device 2-100 when the temperature is lower than another threshold, the electronic device 2-100 heats the battery 2-142 to avoid abnormal shutdown of the electronic device 2-100 due to the low temperature.
  • the electronic device 2-100 when the temperature is lower than yet another threshold, the electronic device 2-100 performs a boost to the output voltage of the battery 2-142 to avoid abnormal shutdown due to low temperature.
  • Touch sensor 2-180K also known as "touch device”.
  • the touch sensor 2-180K can be arranged on the display screen 2-194, and a touch screen is formed by the touch sensor 2-180K and the display screen 2-194, also called “touch screen”.
  • the touch sensor 2-180K is used to detect touch operations on or near it.
  • the touch sensor can pass the detected touch operation to the application processor to determine the type of touch event.
  • Visual output related to touch operations may be provided through display screen 2-194.
  • the touch sensor 2-180K may also be disposed on the surface of the electronic device 2-100, which is different from the location where the display screen 2-194 is located.
  • Bone conduction sensor 2-180M can acquire vibration signals.
  • the bone conduction sensor 2-180M can acquire the vibration signal of the vibrating bone mass of the human voice.
  • the bone conduction sensor 2-180M can also contact the human pulse and receive the blood pressure beating signal.
  • the bone conduction sensor 2-180M can also be disposed in the earphone, combined with the bone conduction earphone.
  • the audio module 2-170 can analyze the voice signal based on the vibration signal of the vocal vibration bone mass obtained by the bone conduction sensor 2-180M, so as to realize the voice function.
  • the application processor can analyze the heart rate information based on the blood pressure beat signal obtained by the bone conduction sensor 2-180M, and realize the function of heart rate detection.
  • Buttons 2-190 include the power button, volume button, etc. Keys 2-190 may be mechanical keys. It can also be a touch key.
  • the electronic device 2-100 may receive key input and generate key signal input related to user settings and function control of the electronic device 2-100.
  • Motor 2-191 can generate vibration cues.
  • Motor 2-191 can be used for incoming call vibration alerts, and can also be used for touch vibration feedback.
  • touch operations acting on different applications can correspond to different vibration feedback effects.
  • Acting on the touch operation in different areas of the display screen 2-194, the motor 2-191 can also correspond to different vibration feedback effects.
  • Different application scenarios for example: time reminder, receiving information, alarm clock, games, etc.
  • the touch vibration feedback effect can also support customization.
  • the indicator 2-192 can be an indicator light, which can be used to indicate charging status, power change, and can also be used to indicate messages, missed calls, notifications, and the like.
  • SIM card interface 2-195 is used to connect SIM card.
  • the SIM card can be inserted into the SIM card interface 2-195 or pulled out from the SIM card interface 2-195 to achieve contact and separation with the electronic device 2-100.
  • the electronic device 2-100 may support 1 or N SIM card interfaces, where N is a positive integer greater than 1.
  • SIM card interface 2-195 can support Nano SIM card, Micro SIM card, SIM card, etc.
  • the same SIM card interface 2-195 can insert multiple cards at the same time.
  • the types of the plurality of cards may be the same or different.
  • the SIM card interface 2-195 is also compatible with different types of SIM cards.
  • the SIM card interface 2-195 is also compatible with external memory cards.
  • the electronic device 2-100 interacts with the network through the SIM card to realize functions such as call and data communication.
  • the electronic device 2-100 employs an eSIM, ie: an embedded SIM card.
  • the eSIM card can be embedded in the electronic device 2-100 and cannot be separated from the electronic device 2-100.
  • the software system of the electronic device 2-100 may adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture.
  • the embodiments of the present application take an Android system with a layered architecture as an example to exemplarily describe the software structure of the electronic device 2-100.
  • FIG. 2-2 is a block diagram of a software structure of an electronic device 2-100 according to an embodiment of the present application.
  • the layered architecture divides the software into several layers, and each layer has a clear role and division of labor. Layers communicate with each other through software interfaces.
  • the Android system is divided into four layers, which are, from top to bottom, an application layer, an application framework layer, an Android runtime (Android runtime) and a system library, and a kernel layer.
  • the application layer can include a series of application packages.
  • the application package can include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, SMS, etc.
  • the application framework layer provides an application programming interface (application programming interface, API) and a programming framework for applications in the application layer.
  • the application framework layer includes some predefined functions.
  • the application framework layer can include window managers, content providers, view systems, telephony managers, resource managers, notification managers, and so on.
  • a window manager is used to manage window programs.
  • the window manager can get the size of the display screen, determine whether there is a status bar, lock the screen, take screenshots, etc.
  • Content providers are used to store and retrieve data and make these data accessible to applications.
  • the data may include video, images, audio, calls made and received, browsing history and bookmarks, phone book, etc.
  • the view system includes visual controls, such as controls for displaying text, controls for displaying pictures, and so on. View systems can be used to build applications.
  • a display interface can consist of one or more views.
  • the display interface including the short message notification icon may include a view for displaying text and a view for displaying pictures.
  • the phone manager is used to provide the communication functions of the electronic device 2-100. For example, the management of call status (including connecting, hanging up, etc.).
  • the resource manager provides various resources for the application, such as localization strings, icons, pictures, layout files, video files and so on.
  • the notification manager enables applications to display notification information in the status bar, which can be used to convey notification-type messages, and can disappear after a brief pause without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc.
  • the notification manager can also display notifications in the status bar at the top of the system in the form of graphs or scroll bar text, such as notifications from applications running in the background, and notifications on the screen in the form of dialog windows. For example, text information is prompted in the status bar, a prompt sound is issued, the electronic device vibrates, and the indicator light flashes.
  • Android Runtime includes core libraries and a virtual machine. Android runtime is responsible for scheduling and management of the Android system.
  • the core library consists of two parts: one is the function functions that the java language needs to call, and the other is the core library of Android.
  • the application layer and the application framework layer run in virtual machines.
  • 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 lifecycle management, stack management, thread management, safety and exception management, and garbage collection.
  • a system library can include multiple functional modules. For example: surface manager (surface manager), media library (Media Libraries), 3D graphics processing library (eg: OpenGL ES), 2D graphics engine (eg: SGL), etc.
  • surface manager surface manager
  • media library Media Libraries
  • 3D graphics processing library eg: OpenGL ES
  • 2D graphics engine eg: SGL
  • the Surface Manager is used to manage the display subsystem and provides a fusion of 2D and 3D layers for multiple applications.
  • the media library supports playback and recording of a variety of commonly used audio and video formats, as well as still image files.
  • the media library can support a variety of audio and video encoding formats, such as: MPEG4, H, 264, MP3, AAC, AMR, JPG, PNG, etc.
  • the 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
  • 2D graphics engine is a drawing engine for 2D drawing.
  • the kernel layer is the layer between hardware and software.
  • the kernel layer contains at least display drivers, camera drivers, audio drivers, and sensor drivers.
  • the following describes the workflow of the software and hardware of the electronic device 2-100 by way of example in conjunction with capturing a photographing scene.
  • the corresponding hardware interrupt is sent to the kernel layer.
  • the kernel layer processes touch operations into raw input events (including touch coordinates, timestamps of touch operations, etc.). Raw input events are stored at the kernel layer.
  • the application framework layer obtains the original input event from the kernel layer, and identifies the control corresponding to the input event. Taking the touch operation as a touch click operation, and the control corresponding to the click operation is the control of the camera application icon, for example, the camera application calls the interface of the application framework layer to start the camera application, and then starts the camera driver by calling the kernel layer.
  • Camera 2-193 captures still images or video.
  • the present application provides a memory management method.
  • FIG. 2-3 is a flowchart of a memory management method provided by an embodiment of the present application.
  • the execution subject of the memory management method may be the electronic device 2-100, and the memory management method may include but not limited to the following steps:
  • step S2-31 when the application is started, the electronic device creates a memory control group of the application, and sets the important score value of the memory control group to a preset important score value.
  • the memory control group is used to manage the memory unit corresponding to the application and can be created in the memory in the form of an object, including methods for managing the memory unit (for example, controlling the recycling parameters of the memory unit, etc.) and related information describing the memory resources.
  • the relevant information may include physical memory occupation of the current memory control group, memory active state of the current memory control group, etc.
  • the memory unit may be in pages, and the size of a page may be 4KB bytes.
  • This application proposes a memory control group based on the application level, which can be created when the application starts, can include the memory information of the process of the application, and manage the process of the application according to the memory information, which can make the memory management more targeted , reduce the overhead of memory management structures, improve user experience, and improve memory recycling efficiency.
  • the electronic device 2-100 may create a memory control group for an application when the application is launched.
  • the electronic device 2-100 can realize the demand service for the user through the application.
  • users can play games through game applications, watch videos through video applications, and play music through music applications.
  • the application can be a browser, and the electronic device 2-100 can create a memory control group 1 of the browser when the browser is started, so the kernel can manage the relevant memory of the browser according to the memory control group 1 .
  • the application may also be a game application, the electronic device 2-100 creates a memory control group 2 corresponding to the game application when the electronic device 2-100 starts the game application, and then the kernel can manage the relevant memory of the game application according to the memory control group 2 .
  • a plurality of applications of the electronic device 2-100 can create respective corresponding memory control groups when they are activated.
  • the user mode can create a folder (ie, a memory control group) under the directory of a control group (control group, cgroup), and the folder is created in units of applications, that is, the application's All processes can be added to this folder, so that multiple applications of the electronic device 2-100 can create a memory control group when started.
  • the application in the embodiment of the present application may be one of the system applications in the electronic device 2-100, or may be one of the third-party applications in the electronic device. Specifically, it may be determined according to actual usage requirements, which is not limited in the embodiments of the present application. It can be understood that the enumeration of the above applications is an exemplary enumeration, which can be specifically determined according to the actual use situation, which is not limited in this embodiment of the present application.
  • the system when the tenth application of the electronic device 2-100 is started, the system sets the important score of the tenth memory control group to a tenth preset value.
  • multiple applications have their respective preset important score values, and the multiple applications are assigned corresponding preset important score values when the applications are started.
  • the important score value can be used to represent the user's attention degree of the application. The smaller the important rating value, the higher the user attention of the application. For example, if the important rating value of application 1 is higher than the important rating value of application 2, it can be determined that the user attention degree of application 2 is higher than that of application 1.
  • the kernel mode may provide a tenth interface of a memory control group, where the tenth interface may be used to configure an important score value of each memory control group.
  • the kernel mode process runs in the kernel space.
  • the process executes a system call and falls into the execution of the kernel code, the process is in the kernel mode.
  • the system will create a memory control group for the chat application, and set the initial important score value of the memory control group.
  • the chat software will be in an active state after being started, so the electronic device 2-100 can update the important score value of the chat software correspondingly according to the active time ratio of the chat software and the frequency of application usage.
  • the chat application has different states, and the memory control group may have different important score values. Therefore, the electronic device 2-100 can correspondingly update the important score value of each memory control group according to the state of each application.
  • the setting of the memory control group can be implemented in the following specific ways:
  • the system can set the important score value of the application's memory control group as the foreground default value.
  • the foreground default value may be 0, or may be other values. It can be understood that the application is in the foreground state, that is, the state of the application that is visible to the user and can interact with the user.
  • the system can set the important score value of the application's memory control group as the background default value.
  • the background default value may be 300, or may be other values. Understandably, an application in the background state is invisible to the user and the application is still running.
  • the important score value of the memory control group of the application can be adjusted according to the active time ratio of the application and the frequency of use. It can be understood that the active state of the application may be a foreground active state and a background active state.
  • the important score value of the memory control group of the application can be adjusted by the number of freeze-thaw times and the memory occupied size of the application. It can be understood that the frozen state of the application may be a state in which the application is in the background and is invisible to the user, and the process of the application cannot apply for memory and cannot perform activities.
  • step S2-32 the memory control group linked list sorts the plurality of memory control groups according to the important score values of the plurality of memory control groups.
  • the memory control group linked list is used to manage at least one memory control group, that is, the plurality of memory control groups can be sorted according to the important score values of the plurality of memory control groups.
  • the memory control group linked list can sort the memory control groups of the application in descending order according to the level of the important score value, that is, the memory control group with a higher important score value is positioned higher in the memory control group linked list.
  • the electronic device 2-100 can start application 1 and application 2, application 1 creates a memory control group 1 when it is started, and application 2 creates a memory control group 2 when it is started.
  • the initial important score values of memory control group 1 and memory control group 2 are both 2-200, as the state of application 1 and application 2 changes, the important score values of memory control group 1 and memory control group 2 will change accordingly.
  • the user switches application 1 to the foreground and switches application 2 to the background.
  • the important score value of memory control group 1 can be updated to 0, and the important score value of memory control group 2 can be updated to 300. Therefore, the memory control group linked list is sorted according to the important score values of memory control group 1 and memory control group 2.
  • the important score value of the memory control group can be updated correspondingly, and after the important score value of the memory control group is updated, the memory control group linked list can update the memory control group sort.
  • FIG. 2-6 it is a schematic diagram of sorting multiple memory control groups according to the importance scoring system for the memory control group linked list.
  • the important score value of memory control group 2 is 500
  • the important score value of memory control group 3 is 2-200
  • the important score value of memory control group 4 is 0, then the memory control group linked list will put the memory control group 1 At the head position, the following sequences are respectively memory control group 2 and memory control group 3, and the memory control group 4 is placed at the end position.
  • the reclamation mechanism may perform memory reclamation according to the order of the multiple memory control groups in the memory control group linked list, and according to the order of the multiple memory control groups.
  • the system has judgment conditions for memory recycling, that is, to determine when to perform memory recycling. It can be passively recycled when the system state enters low memory, that is, the recycling mechanism set by the system can be used, or the user can call the interface to actively recycle, that is, it can be recycled. is a user-created recycling mechanism.
  • the reclamation mechanism may be based on the order of multiple memory control groups in the memory control group linked list, that is, according to the level of the important score values of the multiple memory control groups in the memory control group linked list, for the multiple memory control groups.
  • the control group performs memory reclamation.
  • the recycling mechanism can use the kswapd recycling mechanism or the direct-reclaim recycling mechanism, or it can be any other mechanism for memory recycling.
  • the recycling mechanism can be that the kernel reclaims memory when the system's free memory is lower than the threshold.
  • the existing mechanism on the kernel can include kswapd recycling mechanism, direct-reclaim recycling mechanism, etc.
  • the anonymous page may be a page without a file background, such as a heap, a stack, a data segment, etc., which does not exist in the form of a file.
  • the target reclamation amount may be set according to the memory requirement of the system.
  • the reclamation mechanism performs memory reclamation according to the target reclamation amount. If the memory resources of the system are insufficient, when memory reclamation is triggered, the reclamation mechanism will compress anonymous pages in multiple memory control groups according to the compression ratio according to the important score values of multiple memory control groups in the memory control group linked list. , and put the compressed data into the swap area, and release the space occupied by these data in the swap area. If the data in the swap area reaches the preset waterline, the recycling mechanism will swap out the data from the swap area to the external storage according to the swap-out ratio, so as to realize memory recycling.
  • the preset waterline may be the ratio of the amount of compressed data in the swap area to the size of the swap space, and the preset waterline may be the upper limit of the capacity of the control swap area.
  • the memory resources of the system are insufficient to set a target recovery amount (for example, it can be 50Mb)
  • three applications are opened when the electronic device 2-100 is running, specifically the application 1, the application 2 and the application 3, and the memory of the application 1
  • Control group 1 includes compression ratio 1 and swap-out ratio 1
  • memory control group 2 of application 2 includes compression ratio 2 and swap-out ratio 2
  • memory control group 3 of application 3 includes compression ratio 3 and swap-out ratio 3.
  • the recycling mechanism compresses anonymous page 1 in memory control group 1 according to compression ratio 1
  • the recycling mechanism compresses anonymous page 2 in memory control group 2 according to compression ratio 2.
  • the recycling mechanism also compresses anonymous page 2 according to compression ratio 3 Compress anonymous page 3 in memory control group 3.
  • a total of tenth compression amount (for example, 30 Mb) is compressed.
  • the recycling mechanism also puts the compressed data into the swap area until the data volume in the swap area reaches a preset waterline, where the data may be some data segments and stacks in the process.
  • the recycling mechanism can swap out the data from the swap area to the external storage according to the swap-out ratio, and the tenth swap-out amount is swapped out in total (for example, it can be 20Mb). Therefore, the memory reclaimed by the reclamation mechanism can meet the memory requirements of the system.
  • the system may reclaim anonymous pages from the memory control group in sequence.
  • the memory control groups are sorted according to the creation time, that is, the earlier the memory control group is created, the more likely it is to be reclaimed. It is unreasonable to recycle in this order.
  • Some memory control groups in the front order may be used by the application corresponding to the memory control group immediately after being reclaimed, which makes anonymous pages switch between being recycled and used in a short time. cause volatility.
  • the thrash rate is high, the system memory recovery efficiency is low, and it is easy to enter a low memory state, resulting in freezes. Therefore, in the memory management method provided by the embodiments of the present application, the memory is recovered when the system memory resources are insufficient, and the fluency of the system is improved.
  • the degree of hot and cold of its anonymous pages is not the same, so the proportion of the reclaimable part of the anonymous pages is not equal.
  • some applications do nothing in the background, and their anonymous pages can be completely reclaimed, while some applications process messages in the background, and only part of the anonymous pages can be reclaimed. If they are reclaimed, they will immediately re-apply for memory , which makes anonymous pages switch between being recycled and used in a short period of time, causing fluctuations, which will increase the thrashing rate of anonymous pages.
  • the above-mentioned implementations may have the following problems: on the one hand, since the cold start sequence of the application does not represent the user's attention to the application, if the anonymous pages are recycled in this order, the thrashing rate is high and the recycling efficiency is low; on the other hand On the one hand, in the case of the same application attention, sorting according to the anonymous page size of the memory control group can indeed make the recycling process exit early and reduce the over-recycling rate. However, user attention is usually not related to the anonymous page size of the memory control group, so this ordering will also increase the anonymous page thrash rate.
  • the important score value of the memory control group can be set by the system to a preset value, and the important score value of the memory control group can be updated according to the state of the application.
  • the memory control group linked list can sort the multiple memory control groups according to the important score values of the multiple memory control groups.
  • the reclamation mechanism performs memory reclamation on the multiple tenth memory control groups according to the order of the multiple memory control groups in the memory control group linked list.
  • the embodiments of the present application can adjust the recycling sequence of the memory control group of the application according to the running state of the application, improve the recycling efficiency of the memory, and expand the equivalent memory, thereby improving the fluency of the operating system and preventing the electronic device from being stuck. phenomenon to enhance the user experience.
  • step S2-33 that is, the recycling mechanism recycles the multiple memory control groups according to the sorting of the multiple memory control groups in the memory control group linked list.
  • Memory reclamation can include the following specific steps:
  • Step S2-41 the recycling mechanism performs memory compression on the memory control group according to the compression ratio, and puts the compressed data into the swap area.
  • the electronic device 2-100 will set a compression ratio for the memory control group of the application, and set the compression ratio as a preset compression ratio when the application is started.
  • the compression ratio is used to represent the ratio between the sum of the data volume of the swap area and the external storage and the sum of the data volume of the memory, the swap area and the external storage.
  • the upper limit of compression can be controlled by the compression ratio.
  • the electronic device 2-100 may update the compression ratio of the memory control group according to the state of the application.
  • the upper layer may provide an eleventh interface of a memory control group, where the eleventh interface may be used to configure the compression ratio of each memory control group.
  • the recycling mechanism starts to recycle memory. That is, the recycling mechanism traverses the memory control group linked list, scans the memory data of the memory control group, performs memory compression on the memory control group according to the compression ratio, puts the compressed data in the swap area, and releases the The space occupied by these data in the swap area.
  • the upper limit of compression is controlled by the compression ratio.
  • Step S2-42 if the data in the swap area reaches a preset waterline, the recycling mechanism swaps out the data from the swap area to external storage according to the swap-out ratio.
  • the recycling mechanism will swap out the data from the swap area to external storage according to the swap-out ratio (such as disk).
  • the swap-out ratio is used to represent the ratio between the amount of data that has been swapped out and the sum of the amount of data in the swap area and the external storage.
  • the swap-out upper limit is controlled by the swap-out ratio.
  • each memory control group has different memory activity levels in different states. For example, when some applications process network messages in the background or are in a dormant state, the memory of these applications is cold. The heat ratios are not the same. However, the above implementation manner may have the following problems: if the memory is recovered according to a fixed ratio, the recovery efficiency of the memory is low, and the power consumption is also very large.
  • the important score value, compression ratio and swap-out ratio of the memory control group corresponding to the application will be adjusted accordingly, and the memory control group linked list will also be modified.
  • the order of memory control groups Therefore, in the memory management method provided by the embodiments of the present application, the problem of insufficient accuracy of memory recycling caused by improper memory control group sorting and recycling ratio can be avoided, thereby further improving user experience.
  • the effective compression ratio is improved, and the memory thrashing caused by wrong compression and over-compression can be reduced.
  • the memory can include the normal use area and the swap area.
  • the recycling mechanism starts to recycle the memory.
  • the recycling mechanism starts to compress the data in the normal usage area and put the compressed data into the swap area. If the amount of data in the swap area reaches the watermark, the data in the swap area is swapped out to the external storage.
  • FIG. 2-6 is a schematic structural diagram of a memory control group linked list disclosed in an embodiment of the present application. As shown in Figure 2-6, the memory control group linked list can include multiple memory control groups in sequence.
  • the upper layer (ie, the application layer) can update the important score value, the compression ratio and the swap-out ratio of the memory control group corresponding to the application according to the state of the application.
  • the upper layer can update the important score value 1, compression ratio 1 and swap-out ratio 1 of memory control group 1 in real time according to the state of application 1, and the upper layer can also update the important score value of memory control group 2 in real time according to the state of application 2 2.
  • Compression ratio 2 and swap-out ratio 2 the upper layer can also update the important score value 3, compression ratio 3 and swap-out ratio 3 of the memory control group 3 in real time according to the state of the application 3.
  • the recycling mechanism can preferentially reclaim anonymous page 1 in memory control group 1, then reclaim anonymous page 2 in memory control group 2, and then reclaim anonymous page in memory control group 3.
  • Page 3 Specifically, the recycling mechanism may preferentially compress anonymous page 1 in memory control group 1, then compress anonymous page 2 in memory control group 2, and then compress anonymous page 3 in memory control group 3.
  • the recycling mechanism preferentially swaps the data in memory control group 1 from the swap area to external storage, then swaps the data in memory control group 2 from the swap area to external storage, and then swaps the data in memory control group 3 from the swap area. Swap out to external storage in the swap area.
  • the reclamation mechanism may perform memory reclamation for multiple memory control groups according to the level of the important score values of the multiple memory control groups in the memory control group linked list. That is, the recycling mechanism can control the compression sequence and swap-out sequence of the memory control group of the application according to the sequence of the important score value of the application in the memory control group linked list.
  • the recycling mechanism can compress anonymous page 1 in memory control group 1 according to compression ratio 1, the recycling mechanism compresses anonymous page 2 in memory control group 2 according to compression ratio 2, and the recycling mechanism also compresses memory control group 2 according to compression ratio 3. Anonymous page 3 in 3 is compressed.
  • the recycling mechanism can also put the compressed data into the swap area until the data volume in the swap area reaches a preset waterline, and the recycling mechanism can swap out the data from the swap area to the external storage according to the swap-out ratio. For example, when the amount of data in the swap area reaches the preset waterline, the recycling mechanism can swap out the data in the memory control group 1 from the swap area to external storage according to the swap-out ratio 1, and the recycling mechanism can also swap out the data in the swap-out ratio. 2 Swap out the data of memory control group 2 from the swap area to external storage.
  • FIG. 2-7 is a schematic diagram of the ordering change of the memory control groups in the memory control group linked list when the application in the electronic device 2-100 is started.
  • the application started by the electronic device 2-100 is described by taking news software as an example.
  • the descending order in the memory control group linked list is memory control group 1, memory control group 2, memory control group 3, memory control group 4, memory control group 5, memory control group Group 6.
  • the important score value of the memory control group in the news software is 300, and its compression ratio is 30.
  • the important score value of the memory control group 3 of the application 3 in the electronic device is 900
  • the memory control group of the application 4 is 900.
  • the important score value of group 3 is 2-200. Therefore, according to the important score value of the memory control group of the news software, the memory control group of the news software is sorted in the memory control group 3 and the memory control group. between 4.
  • the upper layer updates the important score value and compression ratio of the memory control group of the news software in time, and the important score value of the memory control group of the news software is updated to 2-200, and its compression Scale updated to 20.
  • the important score value of memory control group 4 of application 4 is 2-200
  • the important score value of memory control group 5 of application 5 is 2-100. Since the news software is active at this time, the memory control group 5 is in an active state.
  • the group linked list sorts the memory control groups of the news software between the memory control group 4 and the memory control group 5 according to the important score values of the memory control groups of the news software.
  • the upper layer will update the important score value and compression ratio of the memory control group of the news software in time.
  • the important score value of the memory control group of the news software is updated to 900, and its compression ratio Update to 90.
  • the important score value of memory control group 3 of application 3 is 900, and the important score value of memory control group 4 of application 4 is 2-200. Therefore, the memory control group linked list is based on the memory control group of the news software.
  • the important score value, the memory control group of the news software is sorted between memory control group 3 and memory control group 4.
  • the upper layer will update the important score value and compression ratio of the memory control group of the news software in time.
  • the important score value of the memory control group of the news software is updated to 2-1000, and its compression Scale updated to 2-100.
  • the important score value of memory control group 2 of application 2 is 2-1000, and the important score value of memory control group 4 of application 3 is 900. Therefore, the memory control group linked list is based on the memory control group of the news software.
  • the important score value, the memory control group of the news software is sorted between memory control group 2 and memory control group 3.
  • the memory control group linked list of the news software sorts the memory control group of the news software in the memory control group according to the important score value of the memory control group of the news software. Back of group 6.
  • a corresponding memory control group is created accordingly, and an initial important score value, a compression ratio, and a swap-out ratio can be set through the system.
  • the important score value, compression ratio and swap-out ratio are adjusted according to its active time ratio and frequency of use.
  • the important score value, compression ratio and swap-out ratio can be adjusted according to the background time ratio and the background event strategy.
  • the app is frozen in the background, adjust the important score value, compression ratio and swap-out ratio through factors such as the number of freeze-thaw times and memory usage.
  • the important score value is lowered, and the compression ratio and swap out ratio can be adjusted synchronously.
  • the important score value, compression ratio and swap-out ratio of the memory control group corresponding to the application will be adjusted accordingly, and the memory control group linked list will also adjust the ordering of multiple memory control groups.
  • Figure 2-8 is a schematic diagram of memory reclamation for multiple memory control groups in the memory control group linked list.
  • the tenth application activated by the electronic device is described by taking news software as an example.
  • the news software is switched to run in the foreground, the important score value of the memory control group of the news software is 0, and the order in the memory control group linked list in descending order is memory control group 1, memory control group 2, memory control group 3.
  • Memory control group 4 memory control group 5, memory control group 6 and memory control group of news software.
  • the important score value of memory control group 1 is 2-1000, and its compression ratio is 2-100.
  • Memory control group 2 has an important score value of 2-1000, and its compression ratio is 2-100.
  • the memory control group 3 important score value is 900, and its compression ratio is 90.
  • Memory control group 4 has an important score of 2-200, and its compression ratio is 20.
  • the memory control group 5 has an important score of 2-100, and its compression ratio is 10.
  • the important score value of memory control group 6 is 0, and its compression ratio is 0.
  • the reclamation mechanism can traverse multiple memory control groups in the order of multiple memory control groups in the memory control group linked list. , memory control group 2 and memory control group 3 memory.
  • the recycling mechanism can preferentially compress and swap out the memory control group. That is, the recovery of memory control group 1 stops when it reaches 2-100%, the recovery of memory control group 2 stops when it reaches 2-100%, the recovery of memory control group 3 stops when it reaches 90%, and the recovery of memory control group 4 reaches 20%. stop. Since scanning stops when enough pages are scanned, memory control group 5 is not reclaimed. If the important score values of memory control group 5 and memory control group 6 are both 0, the memory of memory control group 5 and memory control group 6 will not be reclaimed.
  • FIG. 2-9 is a flowchart of a memory compression method disclosed by an embodiment of the present application. The method includes the following steps:
  • Step S2-91 calculating the tenth compression amount.
  • the tenth compression amount is the target compression amount of this memory reclamation.
  • Step S2-92 it is determined whether the eleventh compression amount is smaller than the tenth compression amount. If the eleventh compression amount is less than the tenth compression amount, go to step S2-93, otherwise end.
  • the eleventh compression amount is the compressed amount of the memory control group of each application by the recycling mechanism, and the compressed amount is compared with the target compression amount to determine whether the compressed amount meets the requirements.
  • Step S2-93 it is determined that there are still untraversed applications on the memory control group linked list. If there are still untraversed applications on the memory control group linked list, go to step S2-94, otherwise end.
  • the eleventh compression amount when the eleventh compression amount is less than the tenth compression amount, it indicates that the compressed memory has not yet met the requirements. Therefore, it is necessary to confirm again whether there are any untraversed applications on the memory control group linked list.
  • Step S2-94 select the next application.
  • the eleventh compression amount is less than the tenth compression amount, that is, the compressed memory has not reached the target compression amount, and the next application that is not traversed can be selected.
  • step S2-95 the compression amount is calculated according to the applied compression ratio.
  • the anonymous pages of the memory control group of the application are compressed according to the compression ratio of the memory control group of the application.
  • Step S2-96 compress the data into the swap area.
  • the data may include related data segments and stacks in the process.
  • Step S2-97 count the compression amount again.
  • FIG. 2-10 is a flowchart of a memory swapping method disclosed in an embodiment of the present application. The method includes the following steps:
  • Step S2-101 input the tenth swap-out amount.
  • the tenth swap-out amount is the target swap-out amount for this memory recycling.
  • Step S2-102 setting the eleventh swap-out amount to 0.
  • Step S2-103 confirming whether the tenth swap-out amount is greater than the eleventh swap-out amount. If yes, go to step S2-104, otherwise end.
  • the eleventh swap-out amount is the compressed amount of the memory control group of each application by the recycling mechanism, and the swap-out amount is compared with the target swap-out amount to determine whether the swap-out amount is not. Achieving the target swap volume.
  • Step S2-104 confirming that there are still applications that have not been traversed. If there are still untraversed applications, go to step S2-105, otherwise end.
  • Step S2-105 select the next application according to the sorting result in the memory control group linked list.
  • the next application will be selected according to the sorting result in the memory control group linked list
  • step S2-106 the swap-out amount is calculated according to the application swap-out ratio.
  • Step S2-107 swap out data according to the least recently used linked list.
  • the data may include related data segments and stacks in the process.
  • Step S2-108 count the eleventh swap-out amount.
  • external storage can be used to expand the internal storage space, which effectively increases the size of the equivalent memory.
  • the swapped out amount may be accumulated, and then the swapped out amount may be counted into the eleventh swapped out amount.
  • the data of the inactive application is selected as much as possible to be swapped out, and the least recently used (Least Recently Used, LRU)
  • LRU least recently used
  • the algorithm separates the data in the swap area from hot and cold, and the frequently accessed data is placed at the head of the LRU linked list, and the infrequent data is placed at the tail of the LRU linked list.
  • the IO efficiency is improved, the amount and number of IO data are reduced, so as to achieve more efficient memory exchange, and at the same time reduce the lifespan of the memory exchange to the storage device loss.
  • the memory control group can be managed according to the order in which the applications are started by the user, but this approach will result in a high anonymous page thrashing rate and low recycling efficiency.
  • the recycling sequence of the memory control group of each application can be adjusted, so that the memory recycling is more accurate and efficient, and the power consumption and performance consumption are controllable at the same time.
  • FIG. 2-11 is a schematic structural diagram of a memory management apparatus disclosed in an embodiment of the present application.
  • the memory recycling device can be used to execute the steps of the memory management method described in FIGS. 2-3 to 2-10.
  • the memory management apparatus 2-200 may include: a creation module 2-201, a control module 2-202, and a recycling module 2-203.
  • control module 2-202 may adjust the important score value of the tenth memory control group and the important score value of the eleventh memory control group according to the states of the tenth application and the eleventh application, respectively.
  • the memory control group linked list may sort the tenth memory control group and the eleventh memory control group according to the important score values of the tenth memory control group and the eleventh memory control group.
  • the control module 2-202 may also be configured to update the important score value of the memory control group according to the state of the application.
  • the reclamation module 2-203 may sort the tenth memory control group and the eleventh memory control group according to the order of the tenth memory control group and the eleventh memory control group in the memory control group linked list. and the eleventh memory control group for memory reclamation.
  • the creation module 2-201 may be configured to create a memory control group of the application when the application is started.
  • the creation module 2-201 may create a tenth memory control group of the tenth application when the tenth application is started.
  • the creation module 2-201 may also create an eleventh memory control group of the eleventh application when the eleventh application is started.
  • the control module 2-202 may also be configured to set the important score value of the memory control group to a preset value.
  • the recycling module 2-203 may be further configured to perform memory compression on the tenth memory control group according to the compression ratio, and put the compressed data into the swap area.
  • the recycling module 2-203 may also be configured to perform memory compression on the eleventh memory control group according to the compression ratio, and put the compressed data into the swap area.
  • the recycling module 2-203 is further configured to control the tenth memory control group and the eleventh memory control group according to the order of the tenth memory control group and the eleventh memory control group in the memory control group linked list Controls the order in which groups are compressed and swapped out.
  • the recycling module 2-203 may perform memory compression on the memory control group according to the compression ratio, and put the compressed data into the swap area.
  • the recycling module 2-203 may swap out the data from the swap area to external storage according to the swap-out ratio.
  • the recycling module 2-203 terminates the compression of the application, and continues to control the memory in the memory control group list according to the memory control.
  • the sorting of the control groups is performed for compression, that is, the next application in the memory control group linked list may be selected for compression.
  • the recycling module 2-203 terminates the swap-out of the application, and continues to control the group according to the memory control group.
  • the ordering of memory control groups in the linked list is swapped out.
  • control module 2-202 may update the important score value and/or the compression ratio and/or the swap-out ratio of the memory control group of the application.
  • the control module 2-202 may set the important score value of the memory control group of the application as the foreground default value. It can be understood that, in a possible implementation manner, the foreground default value may be set to 0, or may be other values.
  • control module 2-202 may set the important score value of the memory control group of the application as the important score value when the application was active before freezing.
  • control module 2-202 may adjust the important score value of the memory control group of the application according to the active time ratio and the usage frequency of the application.
  • control module 2-202 may adjust the important score value of the memory control group of the application according to the number of times of freezing and thawing of the application and the size of the memory occupied.
  • each module in the above-mentioned memory management apparatus is only for illustration, and in other embodiments, the memory management apparatus may be divided into different modules as required to complete the functions of the above-mentioned memory management apparatus.
  • each module in the memory management apparatus may be in the form of a computer program.
  • the computer program can run on an electronic device or server.
  • the specific implementation of each module in the embodiments of the present application may also correspond to the corresponding descriptions of the method embodiments shown in FIG. 2-3 to FIG. 2-10 .
  • the problem of insufficient memory reclamation accuracy caused by improper memory control group sorting and reclamation ratio can be avoided, thereby improving user experience.
  • Embodiments of the present application also provide a computer-readable storage medium.
  • the readable storage medium stores computer instructions, and when the instructions run on the computing device, causes the computing device to execute the memory management method provided by the foregoing embodiments.
  • MemFree refers to the number of free memory, indicating the capacity of the remaining memory space in the free state that has not been allocated in the entire memory space of the system.
  • MemUsed MemTotal-MemFree, MemUsed represents the memory that has been used.
  • MemTotal refers to the total amount of memory. From the start of power-on to the completion of booting, the BIOS needs to reserve some memory, the kernel needs to reserve some memory, and finally the remaining memory for the system is MemTotal. This value is generally fixed during system operation.
  • MemAvailble there is also a memory management method based on MemAvailble.
  • the method is mainly to maintain the waterline by killing.
  • the waterline setting is lower, and the same problem as MemFree waterline control will still exist when the memory pressure is too high.
  • MemAvailble waterline setting is more sensitive, and different devices have different memory requirements, so it is difficult to unify the waterline.
  • MemAvailable refers to the number of available memory. Although some memory in the system has been used, it can be recycled. For example, some of the cache/buffer and slab can be recycled. Therefore, MemFree cannot represent all the available memory. MemFree is the memory available to the system, namely: MemAvailable ⁇ MemFree+Buffers+Cached, which is calculated by the kernel using a specific algorithm and is an estimated value.
  • Embodiments of the present application provide a memory management method, apparatus, electronic device, and computer-readable storage medium, to solve the problems of low memory management efficiency, untimely memory supply, and low number of applications kept alive.
  • the execution body of the memory management method provided by the embodiment of the present application may be the memory management apparatus provided by the embodiment of the present application, or an electronic device integrating the memory management apparatus.
  • the memory management apparatus may be implemented by means of hardware or software.
  • the electronic equipment may also be referred to as user equipment (User Equipment, UE), mobile station (Mobile Station, MS), mobile terminal (Mobile Terminal), and the like.
  • the electronic device may be capable of communicating with a radio access network (Radio Access Network, RAN) and one or more core networks, for example, the electronic device may be a mobile phone (or referred to as a "cellular" phone), tablet, PDA, laptop, or desktop computer.
  • Radio Access Network Radio Access Network
  • the operating system of the electronic device may include, but is not limited to, Linux system, Android (Android) system, IOS operating system, Symbian (Symbian) operating system, BlackBerry (Blackberry) operating system, Windows Phone 8 operating system, etc. . It can be understood that the memory management method provided by the embodiment of the present application is mainly applied to an electronic device having an Android operating system.
  • FIG. 3-1 shows a schematic structural diagram of the electronic device 3-100.
  • the electronic device 3-100 may include a processor 3-110, an external memory interface 3-120, an internal memory 3-121, a universal serial bus (USB) interface 3-130, Charge Management Module 3-140, Power Management Module 3-141, Battery 3-142, Antenna 3-1, Antenna 3-2, Mobile Communication Module 3-150, Wireless Communication Module 3-160, Audio Module 3-170, Speaker 3-170A, receiver 3-170B, microphone 3-170C, headphone jack 3-170D, sensor module 3-180, button 3-190, motor 3-191, indicator 3-192, camera 3-193, display 3 -194, and user identification module (subscriber identification module, SIM) card interface 3-195 and so on.
  • SIM subscriber identification module
  • the sensor module 3-180 may include a pressure sensor 3-180A, a gyroscope sensor 3-180B, an air pressure sensor 3-180C, a magnetic sensor 3-180D, an acceleration sensor 3-180E, a distance sensor 3-180F, a proximity light sensor 3- 180G, fingerprint sensor 3-180H, temperature sensor 3-180J, touch sensor 3-180K, ambient light sensor 3-180L, bone conduction sensor 3-180M, etc.
  • the structures illustrated in the embodiments of the present application do not constitute a specific limitation on the electronic device 3-100.
  • the electronic device 3-100 may include more or less components than shown, or combine some components, or separate some components, or arrange different components.
  • the illustrated components may be implemented in hardware, software, or a combination of software and hardware.
  • the processor 3-110 may include one or more processing units, for example, the processor 3-110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), image signal processor (ISP), controller, video codec, digital signal processor (DSP), baseband processor, and/or neural-network processing unit, NPU), etc. Wherein, different processing units may be independent devices, or may be integrated in one or more processors.
  • application processor application processor, AP
  • modem processor graphics processor
  • GPU graphics processor
  • ISP image signal processor
  • DSP digital signal processor
  • NPU neural-network processing unit
  • different processing units may be independent devices, or may be integrated in one or more processors.
  • the controller can generate an operation control signal according to the instruction operation code and timing signal, and complete the control of fetching and executing instructions.
  • Memory may also be provided in the processor 3-110 for storing instructions and data.
  • the memory in the processor 3-110 is a cache memory. This memory may hold instructions or data that have just been used or recycled by the processor 3-110. If the processor 3-110 needs to use the instruction or data again, it can be called directly from the memory. Repeated access is avoided, and the waiting time of the processor 3-110 is reduced, thereby increasing the efficiency of the system.
  • the processor 3-110 may include one or more interfaces.
  • the interface may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous transceiver (universal asynchronous transmitter) receiver/transmitter, UART) interface, mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, subscriber identity module (SIM) interface, and / or universal serial bus (universal serial bus, USB) interface, etc.
  • I2C integrated circuit
  • I2S integrated circuit built-in audio
  • PCM pulse code modulation
  • PCM pulse code modulation
  • UART universal asynchronous transceiver
  • MIPI mobile industry processor interface
  • GPIO general-purpose input/output
  • SIM subscriber identity module
  • USB universal serial bus
  • the I2C interface is a bidirectional synchronous serial bus that includes a serial data line (SDA) and a serial clock line (SCL).
  • processor 3-110 may contain multiple sets of I2C buses.
  • the processor 3-110 can respectively couple the touch sensor 3-180K, charger, flash, camera 3-193, etc. through different I2C bus interfaces.
  • the processor 3-110 can couple the touch sensor 3-180K through the I2C interface, so that the processor 3-110 communicates with the touch sensor 3-180K through the I2C bus interface, so as to realize the touch function of the electronic device 3-100.
  • the I2S interface can be used for audio communication.
  • processor 3-110 may contain multiple sets of I2S buses.
  • the processor 3-110 can be coupled with the audio module 3-170 through the I2S bus to implement communication between the processor 3-110 and the audio module 3-170.
  • the audio module 3-170 can transmit audio signals to the wireless communication module 3-160 through the I2S interface, so as to realize the function of answering calls through a Bluetooth headset.
  • the PCM interface can also be used for audio communications, sampling, quantizing and encoding analog signals.
  • the audio module 3-170 and the wireless communication module 3-160 may be coupled through a PCM bus interface.
  • the audio module 3-170 can also transmit audio signals to the wireless communication module 3-160 through the PCM interface, so as to realize the function of answering calls through a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
  • the UART interface is a universal serial data bus used for asynchronous communication.
  • the bus may be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication.
  • a UART interface is typically used to connect the processor 3-110 with the wireless communication module 3-160.
  • the processor 3-110 communicates with the Bluetooth module in the wireless communication module 3-160 through the UART interface to realize the Bluetooth function.
  • the audio module 3-170 can transmit audio signals to the wireless communication module 3-160 through the UART interface, so as to realize the function of playing music through the Bluetooth headset.
  • the MIPI interface can be used to connect the processor 3-110 with the display screen 3-194, the camera 3-193 and other peripheral devices.
  • MIPI interfaces include camera serial interface (CSI), display serial interface (DSI), etc.
  • the processor 3-110 communicates with the camera 3-193 through the CSI interface, so as to realize the shooting function of the electronic device 3-100.
  • the processor 3-110 communicates with the display screen 3-194 through the DSI interface to realize the display function of the electronic device 3-100.
  • the GPIO interface can be configured by software.
  • the GPIO interface can be configured as a control signal or as a data signal.
  • the GPIO interface can be used to connect the processor 3-110 with the camera 3-193, the display screen 3-194, the wireless communication module 3-160, the audio module 3-170, the sensor module 3-180, and so on.
  • the GPIO interface can also be configured as I2C interface, I2S interface, UART interface, MIPI interface, etc.
  • the USB interface 3-130 is an interface that conforms to the USB standard specification, which can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc.
  • the USB interface 3-130 can be used to connect a charger to charge the electronic device 3-100, and can also be used to transmit data between the electronic device 3-100 and peripheral devices. It can also be used to connect headphones to play audio through the headphones.
  • the interface can also be used to connect other electronic devices, such as AR devices.
  • the interface connection relationship between the modules illustrated in the embodiments of the present application is only a schematic illustration, and does not constitute a structural limitation of the electronic device 3-100.
  • the electronic device 3-100 may also adopt different interface connection manners in the foregoing embodiments, or a combination of multiple interface connection manners.
  • the charging management module 3-140 is used to receive charging input from the charger.
  • the charger may be a wireless charger or a wired charger.
  • the charging management module 3-140 may receive charging input from the wired charger through the USB interface 3-130.
  • the charging management module 3-140 may receive wireless charging input through the wireless charging coil of the electronic device 3-100. While the charging management module 3-140 charges the battery 3-142, it can also supply power to the electronic device through the power management module 3-141.
  • the power management module 3-141 is used for connecting the battery 3-142, the charging management module 3-140 and the processor 3-110.
  • Power management module 3-141 receives input from battery 3-142 and/or charge management module 3-140 for processor 3-110, internal memory 3-121, display screen 3-194, camera 3-193, and wireless communication Modules 3-160 etc. supply power.
  • the power management module 3-141 can also be used to monitor battery capacity, battery cycle times, battery health status (leakage, impedance) and other parameters.
  • the power management module 3-141 may also be provided in the processor 3-110.
  • the power management module 3-141 and the charging management module 3-140 may also be provided in the same device.
  • the wireless communication function of the electronic device 3-100 can be realized by the antenna 3-1, the antenna 3-2, the mobile communication module 3-150, the wireless communication module 3-160, the modem processor and the baseband processor.
  • the antenna 3-1 and the antenna 3-2 are used for transmitting and receiving electromagnetic wave signals.
  • Each antenna in electronic device 3-100 may be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization.
  • the antenna 3-1 can be multiplexed as a diversity antenna of the wireless local area network. In other embodiments, the antenna may be used in conjunction with a tuning switch.
  • the mobile communication module 3-150 can provide wireless communication solutions including 2G/3G/4G/5G etc. applied to the electronic device 3-100.
  • the mobile communication module 3-150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), and the like.
  • the mobile communication module 3-150 can receive electromagnetic waves from the antenna 3-1, filter and amplify the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation.
  • the mobile communication module 3-150 can also amplify the signal modulated by the modulation and demodulation processor, and then convert it into electromagnetic waves for radiation through the antenna 3-1.
  • at least part of the functional modules of the mobile communication module 3-150 may be provided in the processor 3-110.
  • at least part of the functional modules of the mobile communication module 3-150 may be provided in the same device as at least part of the modules of the processor 3-110.
  • the modem processor may include a modulator and a demodulator.
  • the modulator is used to modulate the low frequency baseband signal to be sent into a medium and high frequency signal.
  • the demodulator is used to demodulate the received electromagnetic wave signal into a low frequency baseband signal. Then the demodulator transmits the demodulated low-frequency baseband signal to the baseband processor for processing.
  • the low frequency baseband signal is processed by the baseband processor and passed to the application processor.
  • the application processor outputs sound signals through audio devices (not limited to the speaker 3-170A, the receiver 3-170B, etc.), or displays images or videos through the display screen 3-194.
  • the modem processor may be a stand-alone device.
  • the modem processor may be independent of the processor 3-110, and be provided in the same device as the mobile communication module 3-150 or other functional modules.
  • the wireless communication module 3-160 can provide applications on the electronic device 3-100 including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (bluetooth, BT) , Global Navigation Satellite System (GNSS), Frequency Modulation (FM), Near Field Communication (NFC), Infrared (IR) and other wireless communication solutions.
  • WLAN wireless local area networks
  • BT Bluetooth
  • GNSS Global Navigation Satellite System
  • FM Frequency Modulation
  • NFC Near Field Communication
  • IR Infrared
  • the wireless communication module 3-160 may be one or more devices integrating at least one communication processing module.
  • the wireless communication module 3-160 receives the electromagnetic wave via the antenna 3-2, frequency modulates and filters the electromagnetic wave signal, and sends the processed signal to the processor 3-110.
  • the wireless communication module 3-160 can also receive the signal to be sent from the processor 3-110, perform frequency modulation on it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 3-2.
  • the antenna 3-1 of the electronic device 3-100 is coupled with the mobile communication module 3-150, and the antenna 3-2 is coupled with the wireless communication module 3-160, so that the electronic device 3-100 can communicate with network and other device communication.
  • the wireless communication technologies may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), broadband Code Division Multiple Access (WCDMA), Time Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC , FM, and/or IR technology, etc.
  • the GNSS may include a global positioning system (global positioning system, GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (quasi -zenith satellite system, QZSS) and/or satellite based augmentation systems (SBAS).
  • GPS global positioning system
  • GLONASS global navigation satellite system
  • BDS Beidou navigation satellite system
  • QZSS quasi-zenith satellite system
  • SBAS satellite based augmentation systems
  • the electronic device 3-100 realizes the display function through the GPU, the display screen 3-194, and the application processor.
  • the GPU is a microprocessor for image processing, which connects the display screen 3-194 and the application processor.
  • the GPU is used to perform mathematical and geometric calculations for graphics rendering.
  • the processor 3-110 may include one or more GPUs that execute program instructions to generate or alter display information.
  • Display 3-194 is used to display images, videos, etc.
  • Display screen 3-194 includes a display panel.
  • the display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (active-matrix organic light).
  • LED diode AMOLED
  • flexible light-emitting diode flexible light-emitting diode (flex light-emitting diode, FLED), Miniled, MicroLed, Micro-oLed, quantum dot light-emitting diode (quantum dot light emitting diodes, QLED) and so on.
  • the electronic device 3-100 may include 1 or N display screens 3-194, where N is a positive integer greater than 1.
  • the electronic device 3-100 can realize the shooting function through the ISP, the camera 3-193, the video codec, the GPU, the display screen 3-194, and the application processor.
  • ISP is used to process the data fed back by camera 3-193. For example, when taking a photo, the shutter is opened, the light is transmitted to the camera photosensitive element through the lens, the light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing, and converts it into an image visible to the naked eye.
  • ISP can also perform algorithm optimization on image noise, brightness, and skin tone. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene.
  • the ISP may be located in the camera 3-193.
  • Camera 3-193 is used to capture still images or video.
  • the object is projected through the lens to generate an optical image onto the photosensitive element.
  • the photosensitive element may be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor.
  • CMOS complementary metal-oxide-semiconductor
  • the photosensitive element converts the optical signal into an electrical signal, and then transmits the electrical signal to the ISP to convert it into a digital image signal.
  • the ISP outputs the digital image signal to the DSP for processing.
  • DSP converts digital image signals into standard RGB, YUV and other formats of image signals.
  • the electronic device 3-100 may include 1 or N cameras 3-193, where N is a positive integer greater than 1.
  • a digital signal processor is used to process digital signals, in addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 3-100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the energy of the frequency point, and so on.
  • Video codecs are used to compress or decompress digital video.
  • the electronic device 3-100 may support one or more video codecs. In this way, the electronic device 3-100 can play or record videos in various encoding formats, such as: Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4 and so on.
  • MPEG Moving Picture Experts Group
  • the NPU is a neural-network (NN) computing processor.
  • NN neural-network
  • Applications such as intelligent cognition of electronic devices 3-100 can be realized through the NPU, such as image recognition, face recognition, speech recognition, text understanding, etc.
  • the internal memory 3-121 may include one or more random access memories (RAM) and one or more non-volatile memories (NVM).
  • RAM random access memories
  • NVM non-volatile memories
  • Random access memory can include static random-access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronization Dynamic random access memory (double data rate synchronous dynamic random access memory, DDR SDRAM, such as the fifth generation DDR SDRAM is generally called DDR5 SDRAM) and so on.
  • SRAM static random-access memory
  • DRAM dynamic random access memory
  • SDRAM synchronous dynamic random access memory
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • DDR5 SDRAM double data rate synchronous dynamic random access memory
  • Non-volatile memory may include magnetic disk storage devices, flash memory.
  • Flash memory can be divided into NOR FLASH, NAND FLASH, 3D NAND FLASH, etc. according to the operating principle, and can include single-level memory cells (single-level cells, SLC), multi-level memory cells (multi-level memory cells) according to the level of storage cell potential cell, MLC), triple-level cell (TLC), quad-level cell (QLC), etc., according to storage specifications, it can include universal flash storage (UFS), embedded Multimedia memory card (embedded multi-media Card, eMMC) and so on.
  • SLC single-level memory cells
  • multi-level memory cells multi-level memory cells
  • MLC multi-level memory cells
  • TLC triple-level cell
  • QLC quad-level cell
  • UFS universal flash storage
  • eMMC embedded Multimedia memory card
  • the random access memory can be directly read and written by the processor 3-110, and can be used to store executable programs (such as machine instructions) of the operating system or other running programs, and can also be used to store user and application data. Wait.
  • the non-volatile memory can also store executable programs and store user and application data, etc., and can be loaded into the random access memory in advance for the processor 3-110 to directly read and write.
  • the external memory interface 3-120 can be used to connect an external non-volatile memory, so as to expand the storage capacity of the electronic device 3-100.
  • the external non-volatile memory communicates with the processor 3-110 through the external memory interface 3-120 to realize the data storage function. For example, save music, video, etc. files in external non-volatile memory.
  • the electronic device 3-100 can implement audio functions through an audio module 3-170, a speaker 3-170A, a receiver 3-170B, a microphone 3-170C, an earphone interface 3-170D, and an application processor. Such as music playback, recording, etc.
  • the audio module 3-170 is used to convert digital audio information to analog audio signal output, and also to convert analog audio input to digital audio signal.
  • the audio module 3-170 may also be used to encode and decode audio signals.
  • the audio module 3-170 may be provided in the processor 3-110, or some functional modules of the audio module 3-170 may be provided in the processor 3-110.
  • Speaker 3-170A also known as "horn" is used to convert audio electrical signals into sound signals.
  • the electronic device 3-100 can listen to music through the speaker 3-170A, or listen to a hands-free call.
  • the receiver 3-170B also called “earpiece” is used to convert audio electrical signals into sound signals.
  • the electronic device 3-100 answers a call or a voice message, the voice can be answered by placing the receiver 3-170B close to the human ear.
  • Microphone 3-170C also known as “microphone”, “microphone”, is used to convert sound signals into electrical signals.
  • the user can make a sound by approaching the microphone 3-170C through the human mouth, and input the sound signal into the microphone 3-170C.
  • the electronic device 3-100 may be provided with at least one microphone 3-170C. In other embodiments, the electronic device 3-100 may be provided with two microphones 3-170C, which can implement a noise reduction function in addition to collecting sound signals. In other embodiments, the electronic device 3-100 may further be provided with three, four or more microphones 3-170C to collect sound signals, reduce noise, identify sound sources, and implement directional recording functions.
  • the headphone jack 3-170D is used to connect wired headphones.
  • the headphone interface 3-170D can be a USB interface 3-130, or a 3, 5mm open mobile terminal platform (OMTP) standard interface, the cellular telecommunications industry association of the USA, CTIA) standard interface.
  • OMTP open mobile terminal platform
  • the pressure sensor 3-180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal.
  • the pressure sensor 3-180A may be positioned on the display screen 3-194.
  • the capacitive pressure sensor may be comprised of at least two parallel plates of conductive material. When a force is applied to the pressure sensor 3-180A, the capacitance between the electrodes changes.
  • the electronic device 3-100 determines the intensity of the pressure from the change in capacitance. When a touch operation acts on the display screen 3-194, the electronic device 3-100 detects the intensity of the touch operation according to the pressure sensor 3-180A.
  • the electronic device 3-100 can also calculate the touched position according to the detection signal of the pressure sensor 3-180A.
  • touch operations acting on the same touch position but with different touch operation intensities may correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the thirty-first pressure threshold acts on the short message application icon, the instruction to view the short message is executed. When a touch operation whose intensity is greater than or equal to the thirty-first pressure threshold acts on the short message application icon, the instruction to create a new short message is executed.
  • the gyro sensor 3-180B can be used to determine the motion attitude of the electronic device 3-100.
  • the angular velocity of the electronic device 3-100 about three axes may be determined by the gyro sensor 3-180B.
  • Gyro sensor 3-180B can be used for image stabilization.
  • the gyroscope sensor 3-180B detects the shaking angle of the electronic device 3-100, calculates the distance to be compensated by the lens module according to the angle, and allows the lens to offset the electronic device 3-100 through reverse motion. Shake, achieve anti-shake.
  • the gyroscope sensor 3-180B can also be used for navigation and somatosensory game scenes.
  • Air pressure sensor 3-180C is used to measure air pressure.
  • the electronic device 3-100 calculates the altitude from the air pressure value measured by the air pressure sensor 3-180C to assist in positioning and navigation.
  • Magnetic sensor 3-180D includes a Hall sensor.
  • the electronic device 3-100 can detect the opening and closing of the flip holster using the magnetic sensor 3-180D.
  • the electronic device 3-100 can detect the opening and closing of the flip according to the magnetic sensor 3-180D. Further, according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, characteristics such as automatic unlocking of the flip cover are set.
  • the acceleration sensor 3-180E can detect the magnitude of the acceleration of the electronic device 3-100 in various directions (generally three axes).
  • the magnitude and direction of gravity can be detected when the electronic device 3-100 is stationary. It can also be used to identify the posture of electronic devices, and can be used in applications such as horizontal and vertical screen switching, pedometers, etc.
  • Distance sensor 3-180F for measuring distance.
  • Electronic device 3-100 can measure distance by infrared or laser. In some embodiments, to capture a scene, the electronic device 3-100 can use the distance sensor 3-180F to measure distances to achieve fast focusing.
  • Proximity light sensor 3-180G may include, for example, light emitting diodes (LEDs) and light detectors, such as photodiodes.
  • the light emitting diodes may be infrared light emitting diodes.
  • the electronic device 3-100 emits infrared light outward through light emitting diodes.
  • Electronic device 3-100 uses photodiodes to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object in the vicinity of the electronic device 3-100. When insufficient reflected light is detected, the electronic device 3-100 may determine that there is no object in the vicinity of the electronic device 3-100.
  • the electronic device 3-100 can use the proximity light sensor 3-180G to detect that the user holds the electronic device 3-100 close to the ear to talk, so as to automatically turn off the screen to save power.
  • Proximity light sensor 3-180G can also be used in holster mode, pocket mode automatically unlock and lock screen.
  • the ambient light sensor 3-180L is used to sense ambient light brightness.
  • the electronic device 3-100 can adaptively adjust the brightness of the display screen 3-194 according to the perceived ambient light brightness.
  • the ambient light sensor 3-180L can also be used to automatically adjust the white balance when taking pictures.
  • the ambient light sensor 3-180L can also cooperate with the proximity light sensor 3-180G to detect whether the electronic device 3-100 is in the pocket to prevent accidental touch.
  • the fingerprint sensor 3-180H is used to collect fingerprints.
  • the electronic device 3-100 can use the collected fingerprint characteristics to realize fingerprint unlocking, accessing application locks, taking photos with fingerprints, answering incoming calls with fingerprints, and the like.
  • Temperature sensor 3-180J is used to detect temperature.
  • the electronic device 3-100 utilizes the temperature detected by the temperature sensor 3-180J to implement a temperature handling strategy. For example, when the temperature reported by the temperature sensor 3-180J exceeds a threshold, the electronic device 3-100 performs performance reduction of the processor located near the temperature sensor 3-180J in order to reduce power consumption and implement thermal protection. In other embodiments, when the temperature is lower than another threshold, the electronic device 3-100 heats the battery 3-142 to avoid abnormal shutdown of the electronic device 3-100 due to low temperature. In some other embodiments, when the temperature is lower than another threshold, the electronic device 3-100 performs a boost to the output voltage of the battery 3-142 to avoid abnormal shutdown caused by low temperature.
  • Touch sensor 3-180K also known as "touch device”.
  • the touch sensor 3-180K can be arranged on the display screen 3-194, and the touch screen is composed of the touch sensor 3-180K and the display screen 3-194, also called “touch screen”.
  • the touch sensor 3-180K is used to detect touch operations on or near it.
  • the touch sensor can pass the detected touch operation to the application processor to determine the type of touch event.
  • Visual output related to touch operations may be provided through display screen 3-194.
  • the touch sensor 3-180K may also be disposed on the surface of the electronic device 3-100, which is different from the location where the display screen 3-194 is located.
  • Bone conduction sensor 3-180M can acquire vibration signals.
  • the bone conduction sensor 3-180M can acquire the vibration signal of the vibrating bone mass of the human voice.
  • the bone conduction sensor 3-180M can also contact the human pulse and receive the blood pressure beating signal.
  • the bone conduction sensor 3-180M can also be disposed in the earphone, combined with the bone conduction earphone.
  • the audio module 3-170 can analyze the voice signal based on the vibration signal of the vocal vibration bone mass obtained by the bone conduction sensor 3-180M, so as to realize the voice function.
  • the application processor can analyze the heart rate information based on the blood pressure beat signal obtained by the bone conduction sensor 3-180M, and realize the function of heart rate detection.
  • Buttons 3-190 include the power button, the volume button and so on. Keys 3-190 may be mechanical keys. It can also be a touch key.
  • the electronic device 3-100 may receive key input and generate key signal input related to user settings and function control of the electronic device 3-100.
  • Motor 3-191 can generate vibration cues.
  • Motor 3-191 can be used for incoming call vibration alerts, and can also be used for touch vibration feedback.
  • touch operations acting on different applications can correspond to different vibration feedback effects.
  • Acting on the touch operation in different areas of the display screen 3-194, the motor 3-191 can also correspond to different vibration feedback effects.
  • Different application scenarios for example: time reminder, receiving information, alarm clock, games, etc.
  • the touch vibration feedback effect can also support customization.
  • the indicator 3-192 can be an indicator light, which can be used to indicate charging status, battery change, and can also be used to indicate messages, missed calls, notifications, and the like.
  • the SIM card interface 3-195 is used to connect the SIM card.
  • the SIM card can be inserted into the SIM card interface 3-195 or pulled out from the SIM card interface 3-195 to achieve contact and separation with the electronic device 3-100.
  • the electronic device 3-100 may support 1 or N SIM card interfaces, where N is a positive integer greater than 1.
  • SIM card interface 3-195 can support Nano SIM card, Micro SIM card, SIM card, etc.
  • the same SIM card interface 3-195 can insert multiple cards at the same time.
  • the types of the plurality of cards may be the same or different.
  • the SIM card interface 3-195 is also compatible with different types of SIM cards.
  • the SIM card interface 3-195 is also compatible with external memory cards.
  • the electronic device 3-100 interacts with the network through the SIM card to realize functions such as call and data communication.
  • the electronic device 3-100 employs an eSIM, ie: an embedded SIM card.
  • the eSIM card can be embedded in the electronic device 3-100 and cannot be separated from the electronic device 3-100.
  • the memory management method may include S3-20-S3-211:
  • Step S3-20 creating a memory statistical value and a memory pressure level.
  • the memory statistics are used to characterize the remaining available memory in the system memory of the electronic device, which is typically characterized by a watermark parameter. For example, a lower memory watermark indicates less available system memory remaining.
  • a watermark is an array in the memory management area, and the memory watermark usually includes three watermark values, namely WMARK_HIGH (high watermark), WMARK_LOW (low watermark), and WMARK_MIN (minimum watermark). Among them, WMARK_HIGH>WMARK_LOW>WMARK_MIN. Usually, the watermark needs to be checked before allocating a page.
  • WMARK_HIGH when the free page is greater than WMARK_HIGH, it indicates that the system memory state of the electronic device is ideal, and memory reclamation is not needed for the time being.
  • WMARK_LOW when the free page is lower than WMARK_LOW, it means that the system memory of the electronic device is insufficient, and memory recovery needs to be performed.
  • WMARK_MIN when the free page is lower than WMARK_MIN, it means that the system memory of the electronic device is seriously insufficient. For example, there are very few free pages in the memory domain, and memory reclamation must be accelerated.
  • the available memory in this embodiment of the present application includes two parts, for example, a thirty-first memory and a thirty-second memory.
  • the thirty-first memory refers to the free memory of the system.
  • the free memory refers to the memory that has not been used by the system, that is, MemFree.
  • the thirty-second memory is the memory that is occupied but can be converted into the thirty-first memory by recycling.
  • the occupied memory mainly refers to the memory occupied by the currently running process and service and the memory occupied by the kernel running.
  • Buffer is the number of buffer memory, also known as write-buffer, which is generally used for write operations.
  • Cache is the number of cache memory, also known as read-cache, which is generally used for read operations.
  • the parameter buffer is the memory waterline.
  • the parameter freemem is the free memory in the thirty-first memory.
  • the parameter inactive_file is the inactive file memory.
  • the parameter active_file is the active file memory.
  • the parameter ion_cache is the available memory (cache) of the ION memory manager. Among them, the cache (cache) is to save the read data. When re-reading, if it hits (find the required data), don't read the hard disk. If there is no hit, read the hard disk.
  • the parameters inactive_file, active_file and ion_cache together constitute the memory that is occupied but can be supplied by recycling in the thirty-second memory.
  • Parameters ⁇ and ⁇ are adjustable parameters. Specifically, the parameters ⁇ and ⁇ can be adjusted correspondingly according to the specifications of different products, that is, different ratios or discounts can be selected.
  • the thirty-first memory and the thirty-second memory are not limited.
  • the thirty-second memory may also be other memory that is occupied but can be supplied or reclaimed, and is not limited to inactive file memory and/or active file memory.
  • the creation of the memory statistics value comprehensively considers the supply of rapidly reclaimable memory, and provides adjustable parameters for the supply of file pages, so that the memory statistics value setting is more reasonable. . That is, the memory statistics value can more effectively reflect the available memory supply capability and more effectively reflect the memory pressure situation.
  • the memory statistics value includes a thirty-first memory statistics value, a thirty-second memory statistics value, and a thirty-third memory statistics value.
  • the thirty-first memory statistic value corresponds to WMARK_HIGH in the above watermark, and is collectively referred to as high_buffer hereinafter.
  • the thirty-second memory statistic value may correspond to WMARK_LOW in the above-mentioned watermark, and is collectively referred to as low_buffer hereinafter.
  • the thirty-third memory statistic value corresponds to WMARK_MIN in the above watermark, and is collectively referred to as min_buffer hereinafter.
  • the thirty-second memory statistic value is smaller than the thirty-first memory statistic value.
  • the thirty-third memory statistic value is smaller than the thirty-second memory statistic value.
  • the memory pressure levels include the thirty-first level, the thirty-second level, and the thirty-third level.
  • the electronic device may also preset the memory pressure level, for example, the thirty-first level corresponds to a low level, the thirty-second level corresponds to an intermediate level, and the thirty-third level corresponds to a high level.
  • the high level (critical_level_press) indicates that the memory pressure is relatively large.
  • Medium (medium_level_press) indicates moderate memory pressure
  • low_level_press) indicates less memory pressure. That is, the memory pressure of the thirty-third level is higher than the memory pressure of the thirty-second level, and the memory pressure of the thirty-second level is higher than the memory pressure of the thirty-first level.
  • the memory pressure level may be determined according to the current memory statistics value of the system. For example, if the current memory statistic value of the system is less than the thirty-second memory statistic value, it may be determined that the current memory pressure level of the system is the thirty-first level (eg, low level). After the system memory is reclaimed, if the current memory statistic value of the system is less than the 31st memory statistic value, it can be determined that the current memory pressure level of the system is the 32nd level (for example, the intermediate level). When the current system memory statistic value is less than At the thirty-third memory statistics value, it can be determined that the current memory pressure level of the system is the thirty-third level (for example, advanced).
  • the memory statistics value may be statically preset. Specifically, there are the following situations:
  • the available memory of the system is different, and the corresponding memory statistics are also different.
  • the memory statistics value can be configured to be 600MB, and for 4GRAM products, the memory statistics value can be configured to be 700MB.
  • the memory statistics can be calculated separately in the off-screen scenario and the bright-screen scenario.
  • the memory statistics in the off-screen scenario are lower than those in the bright-screen scenario.
  • the thirty-first memory statistic value in the screen-off scenario is lower than the thirty-first memory statistic value in the bright-screen scenario.
  • the thirty-second memory statistic value in the screen-off scenario is lower than the thirty-second memory statistic value in the bright-screen scenario.
  • the thirty-third memory statistic value in the screen-off scenario is lower than the thirty-third memory statistic value in the bright-screen scenario.
  • each user has its own characteristics, after the terminal is used for a long time, the applications installed and running on the terminal are inconsistent.
  • the cloud server can collect the memory information occupied by all applications running on the terminal in each scenario according to the terminal's identification, and form a form with the names of the applications whose memory is larger than the preset value (such as 300MB) and the running scene of the application at that time. , push the form to the terminal periodically (such as monthly), after the terminal receives the form, it traverses the application information in this form and the local application list, and determines the maximum memory usage information of the applications installed on the terminal, and further, Compare the maximum occupied memory with the current system's memory statistics. If the maximum occupied memory is greater than the current system's memory statistics, the maximum occupied memory is selected as the system's new memory statistics.
  • the preset value such as 300MB
  • the memory statistic value may also be dynamically configured.
  • the user behavior analysis algorithm can be used to predict the applications that are most likely to run next according to the user's usage habits, application usage history, usage frequency, usage duration and other information, according to the prediction algorithm, and form an application list to obtain the application list.
  • the maximum memory that needs to be used by the application in and compare the maximum memory with the memory statistics value of the current system. If the maximum memory is greater than the memory statistics value of the current system, the maximum memory is selected as the new memory statistics value of the system.
  • Step S3-21 monitoring the current memory statistics of the system.
  • Step S3-22 determining whether the current memory statistic value of the system is lower than the thirty-second memory statistic value low_buffer.
  • step S3-23 is performed. If it is determined that the current memory statistic value of the system is not lower than the thirty-second memory statistic value low_buffer, return to step S3-21, that is, continue to monitor the current memory statistic value of the system.
  • Step S3-23 when it is determined that the current memory statistic value of the system is lower than the thirty-second memory statistic value low_buffer, wake up the anonymous page compression thread to prepare to reclaim memory.
  • the anonymous page is the memory page of the heap memory dynamically allocated by the application. Since anonymous pages are likely to be accessed again and cannot be directly reclaimed, these memory cannot be released directly. Therefore, the memory space occupied by them is indirectly released by means of memory compression. For example, first determine the anonymous pages in the allocated memory pages, select a certain number of memory pages from all the anonymous pages as the target memory pages, and compress them to achieve the purpose of increasing the free memory.
  • Step S3-24 determine that the current memory pressure level of the system is level 31, and report it as a level 31 pressure event (eg, a low-level pressure (low_level_press) event) to the upper layer.
  • a level 31 pressure event eg, a low-level pressure (low_level_press) event
  • step S3-25 the upper layer receives the low-level pressure (low_level_press) event, and configures and delivers reclamation parameters to the anonymous page compression thread according to the application characteristics, so as to instruct the anonymous page compression thread to reclaim memory.
  • low_level_press low-level pressure
  • Step S3-26 Receive the recycling parameter, and start the compression process through the anonymous page compression thread according to the recycling parameter, so as to perform memory recycling. That is, the thirty-second memory is reclaimed to convert the thirty-second memory into the thirty-first memory.
  • the upper layer may be a native layer or an application framework layer (FWK).
  • FWK application framework layer
  • the reclamation parameters include, but are not limited to, the number of target memory pages, the reclamation priority of the target memory pages, and/or the memory reclamation ratio (ratio), and the like.
  • the number of target memory pages may be determined according to the current size of the memory statistic value of the system and the thirty-second memory statistic value low_buffer.
  • the amount of memory to be recycled is determined according to the difference between the thirty-second memory statistical value low_buffer and the current memory statistical value of the system, and then the required target memory page is calculated according to the amount of memory to be recycled and the expected compression rate quantity.
  • the anonymous page compression thread can start the compression process according to the above-mentioned recycling parameter.
  • the target memory pages are compressed, and the compressed memory pages are written into the memory compression space in the memory space, so as to release a part of the memory space occupied by these target memory pages. Later, when the system needs to use these memory pages again, it finds the compressed memory pages from the memory compression space, decompresses them and uses them.
  • the current size of the memory statistic value of the system is 10M
  • the thirty-second memory statistic value low_buffer is 20M. Therefore, it can be concluded that the memory space to be released is 10M.
  • the expected compression rate is 50%
  • the compression ratio is the ratio between the size of the compressed memory page and the size of the original memory page.
  • the desired compression ratio can be a preset empirical value.
  • Step S3-27 after completing one memory recovery through anonymous compression, determine whether the current memory statistic value of the system is lower than the thirty-first memory statistic value high_buffer.
  • step S3-28 is performed. If it is determined that the current memory statistic value of the system is not lower than the thirty-first memory statistic value high_buffer, return to step S3-21, that is, continue to monitor the current memory statistic value of the system.
  • Step S3-28 when it is determined that the current memory statistical value of the system is lower than the thirty-first memory statistical value high_buffer, confirm that the current memory pressure level of the system is the thirty-second level, and compress the anonymous page through the anonymous page.
  • the thread reports a thirty-second level stress event (eg, a medium_level_press event) to the upper layer.
  • Step S3-29 the upper layer receives the medium_level_press event, and adjusts (eg, lowers) the memory statistics value.
  • the anonymous page compression thread can generally reach the thirty-first memory statistic value high_buffer at the end of the reclamation, so that the system has enough free resources for subsequent application startups, such as camera startup to maintain a higher value. memory statistics.
  • the anonymous page compression thread performs memory reclamation, so that the memory statistic value reaches the thirty-first memory statistic value high_buffer, that is, the memory statistic value reaches a higher level. In this way, it can also effectively prevent the power consumption problem caused by the frequent start of recycling, the recycling efficiency problem caused by the recycling idling, and the refault problem caused by excessive recycling.
  • Step S3-210 determining whether the current memory statistic value of the system is lower than the thirty-third memory statistic value min_buffer.
  • step S3-211 If it is determined that the current memory statistic value of the system is lower than the thirty-third memory statistic value min_buffer, step S3-211 is performed. If it is determined that the current memory statistic value of the system is not lower than the thirty-third memory statistic value min_buffer, return to step S3-26, that is, continue to start the anonymous page compression thread to perform memory reclamation.
  • Step S3-211 when it is determined that the current memory statistic value of the system is lower than the thirty-third memory statistic value min_buffer, it is reported again as a medium_level_press event, and the third process is recovered by killing the dead process. Twelve memory, and return to step S3-21, that is, continue to monitor the current memory statistics of the system.
  • the memory statistical value is gradually lowered to the third Thirteen memory stats min_buffer.
  • the lowering of the memory statistic value by the upper layer means that when the upper layer receives a medium_level_press event, it adjusts the thirty-second memory statistic value low_buffer and the The thirty-first memory statistic value high_buffer is simultaneously lowered, and the lowered value is the difference between the thirty-first memory statistic value high_buffer and the current memory statistic value of the system.
  • the thirty-third memory statistic value min_buffer cannot be maintained after the memory reclamation of the anonymous page compression process, that is, the current memory statistic value of the system is still lower than the thirty-third memory statistic value min_buffer, the The thirty-second memory is recovered by killing the dead process when reporting the medium_level_press event.
  • the thirty-third memory statistic value min_buffer can be further based on the And the current memory statistics value of the system determines the amount to be killed and the target process to be killed, that is, to determine which process or processes to kill. That is to say, when it is determined that the triggering condition for killing a process is satisfied, a list of killing processes can be created, and then the processes are killed according to the sequence execution of the processes in the list of killing processes, until the current memory statistics value of the system reaches the first Thirty-three memory stats min_buffer.
  • the killing process list is a dynamic two-dimensional table sorted according to the importance of applications, process priority and/or other factors (such as size and distribution of anonymous pages of applications), including processes of one or more applications. That is, the kill process list may include one or more applications, and one application may include one or more processes.
  • the killing process list is a list sorted according to the importance of the application, the priority of the process and/or other factors.
  • the method of creating the killing process list specifically includes, but is not limited to, the following steps:
  • the key factors include one or more of the following: process priority, user usage habits, system resources occupied by the process, and application relationship.
  • each application running in the background of the terminal may include one or more processes, and the key factors of each application include one or more of the following: process priority, user usage habits, and process occupation of system resources and application associations.
  • Each key factor has a corresponding score.
  • Create a kill process list based on key factors of the application (process priority, user usage habits, system resource occupied by the process, and application relationship), and then the process to be processed can be determined from the kill process list according to memory requirements. In this way, the killable process queue can be accurately selected, reducing the probability of wrongly killing/overkilling/underkilling processes.
  • the system will evaluate the importance of each process, and the importance of the process also represents the process priority.
  • the importance is expressed by the value of oom_adj (out of memory adjust) and assigned to each process, and the system will judge which processes need to be terminated according to oom_adj.
  • the score of oom_adj is provided by the system, and the system can assign it according to the current running state of the application.
  • the higher the score of oom_adj the higher the possibility of the process being selected by the system to terminate, and the lower the priority of the process.
  • the user's usage habits may include, but not limited to, the usage time record of the application, the accumulated usage times of the application, the duration of each usage, and the accumulated usage duration. According to the user's usage habits, it can be determined which processes are the processes of the applications frequently used by the user, or which processes are the processes of the applications that the user has used for a long time, or which processes are the processes of the applications recently used by the user, and other related process information .
  • the application importance model can be obtained through model learning such as random forest, and the killing process list can be obtained in combination with application usage frequency, application anonymous page size and distribution, and/or other factors.
  • the application to be killed is obtained according to the anonymous page situation of the application in the killing process list and the amount to be killed.
  • the memory statistics value includes the thirty-first memory statistics value, the thirty-second memory statistics value, and the thirty-third memory statistics value.
  • the thirty-second memory statistic value is smaller than the thirty-first memory statistic value.
  • the thirty-third memory statistic value is smaller than the thirty-second memory statistic value.
  • anonymous page compression can be started to reclaim the thirty-second memory, so that the The thirty-second memory is converted into the thirty-first memory.
  • the memory statistic value may be lowered.
  • the thirty-second memory may be reclaimed by killing the process, so as to convert the thirty-second memory into the thirty-second memory a memory, until the current memory statistic value of the system is not lower than the thirty-third memory statistic value.
  • FIG. 3-3 shows a schematic flowchart of another memory management method provided according to an embodiment of the present application. As shown in Fig. 3-3, the memory management method may further include steps S3-30-S3-33 on the basis of Fig. 3-2a.
  • step S3-30 the space usage rate of the swap partition is monitored.
  • the swap partition is the swap area.
  • the memory can include the normal use area and the swap area.
  • the recycling mechanism starts to recycle the memory.
  • the recycling mechanism starts to compress the data in the normal usage area and puts the compressed data into the swap area. If the amount of data in the swap area reaches the watermark, the data in the swap area is swapped out to the external storage.
  • Step S3-31 it is determined whether the space usage rate of the current swap partition reaches a preset ratio. If it is determined that the space usage rate of the current swap partition reaches the preset ratio, step S3-32 is performed. If it is determined that the space usage rate of the current swap partition does not reach the preset ratio, then return to step S3-30, that is, continue to monitor the space usage rate of the swap partition.
  • Step S3-32 when it is determined that the space usage rate of the current swap partition reaches the preset ratio, confirm that the current memory pressure level of the system is the 33rd level, and report it as a 33rd level pressure event (eg high level pressure (critical_level_press event) to the upper level.
  • a 33rd level pressure event eg high level pressure (critical_level_press event) to the upper level.
  • Step S3-33 according to the high-level pressure (critical_level_press) event, the upper layer reclaims the thirty-second memory by killing the process.
  • the anonymous page compression thread when the anonymous page compression thread is started, causing the space usage rate of the swap partition to reach the preset ratio, it will be difficult for the memory statistics to continue to reclaim memory through anonymous page compression. At that time, the anonymous page compression thread will report the high-level pressure (critical_level_press) event to trigger the upper layer to reclaim the thirty-second memory by killing the process.
  • critical_level_press high-level pressure
  • the anonymous page compression thread will report a high-level pressure (critical_level_press) event at the end of the current round of reclamation, which directly triggers the upper layer
  • critical_level_press high-level pressure
  • FIG. 3-4 show schematic flowcharts of another memory management method provided according to an embodiment of the present application. As shown in Fig. 3-4, the memory management method may further include steps S3-40-S3-44 based on Fig. 3-2a and/or Fig. 3-3.
  • step S3-40 the system resource pressure is monitored through a pressure stall information (Pressure Stall Information, PSI) thread.
  • PSI Pressure Stall Information
  • System resources can include CPU resources, IO resources, etc.
  • delays may increase and users experience lag.
  • An accurate detection method can help resource users determine the appropriate workload, and can also help the system to formulate efficient resource scheduling strategies, maximize the use of system resources, and maximize user experience.
  • PSI is an important resource measurement tool to provide a real-time method to detect the competition degree of system resources, so as to improve the competitiveness of the system resources.
  • the waiting time is presented, which can judge the current system pressure more comprehensively, and provide users and resource schedulers to make decisions simply and accurately.
  • the PSI is used to aggregate the delays of each task into resource pressure indicators, and these indicators reflect problems in terms of workload operation status and resource utilization. It can be understood that, in this embodiment of the present application, the indicator considered by the PSI thread is usually the speed of supplying applications.
  • PSI thread can be used to trigger the detection of system resource pressure.
  • PSI statistics i.e. PSI values
  • Step S3-41 determining whether the current PSI value of the system is greater than a preset threshold. If it is determined that the current PSI value of the system is greater than the preset threshold, step S3-42 is performed. If it is determined that the current PSI value of the system is not greater than the preset threshold, return to step S3-40, that is, continue to monitor the system resource pressure.
  • Step S3-42 when it is determined that the current PSI value of the system is greater than the preset threshold, the PSI thread reports the PSI pressure value to the upper layer.
  • Step S3-43 the upper layer receives the PSI pressure value, and determines whether the current memory statistic value of the system is less than the thirty-fourth memory statistic value psi_buffer.
  • step S3-44 is performed. If it is determined that the current memory statistic value of the system is not less than the thirty-fourth memory statistic value psi_buffer, return to step S3-40.
  • Step S3-44 When it is determined that the current memory statistical value of the system is less than the thirty-fourth memory statistical value psi_buffer, the thirty-second memory is recovered by killing the process.
  • the PSI thread report indicates that the speed of the system memory fast supplying the application is relatively slow
  • the current memory statistic value of the system is not lower than the thirty-fourth memory statistic value psi_buffer, it means that the current system can still provide available memory for the application, but the supply speed is slow.
  • the current memory statistic value of the system is lower than the thirty-fourth memory statistic value psi_buffer, it means that the available memory that the system can provide for the application is insufficient and the supply speed is slow. At this point, the thirty-second memory will be reclaimed directly by killing the process.
  • the thirty-fourth memory statistic value psi_buffer is smaller than the thirty-third memory statistic value min_buffer.
  • reclaiming the thirty-second memory by killing the process in step S3-44 is the same as reclaiming the thirty-second memory by killing the process in step S3-211 in Fig. 3-2a, Fig. 3
  • the process of reclaiming the thirty-second memory by killing the process in step S3-33 in -3 is similar, and the corresponding concept is also similar, and will not be repeated here.
  • the memory management method may further include steps S3-50-S3-52 based on Fig. 3-2a, Fig. 3-3 and/or Fig. 3-4.
  • Step S3-50 monitoring whether a preset application is started. If the startup of the preset application is monitored, step S3-51 is performed, and if the startup of the default application is not monitored, step S3-50 is continued.
  • the preset application refers to an application that consumes a large amount of memory during startup, for example, an application that consumes a large amount of memory in a short period of time once the preset is used for startup.
  • the preset application can be preset and stored.
  • Step S3-51 when a preset application startup is monitored, it is further determined whether the current memory statistic value of the system is greater than the thirty-first memory statistic value high_buffer. If it is determined that the current memory statistic value of the system is less than the thirty-first memory statistic value high_buffer, step S3-52 is performed. If it is determined that the current memory statistic value of the system is not less than the thirty-first memory statistic value high_buffer, return to step S3-50.
  • Step S3-52 when it is determined that the current memory statistical value of the system is less than the thirty-first memory statistical value high_buffer, the thirty-second memory is recovered by killing the process.
  • the thirty-second memory cannot be recovered by killing the process in time. Therefore, in an application startup scenario with large memory requirements, such as camera startup, when a startup message is received, the thirty-second memory is immediately triggered to be reclaimed by killing the process.
  • FIG. 3-2a to FIG. 3-5 Please refer to FIG. 3-2a to FIG. 3-5 again.
  • this embodiment of the present application there are at least the following four situations in which the thirty-second memory is recovered by killing a process.
  • the first case when the memory statistic value is gradually lowered to the minimum value of the thirty-third memory statistic value min_buffer, if the current memory statistic value of the system still fails to reach the thirty-third memory statistic value min_buffer, Then, the thirty-second memory is recovered by killing the process, and the memory statistics value is maintained to the thirty-third memory statistics value min_buffer (refer to step S3-211 in FIG. 3-2a).
  • PSI pressure reporting strategy that is, directly triggering the detection of the thirty-fourth memory statistic value psi_buffer according to the PSI pressure state and triggering the recovery of the thirty-second memory by killing the process (see Figure 3-4 in step S3-44).
  • the fourth situation the default application startup, that is, if the application memory demand is too fast, there is still a delay in PSI reporting, and the thirty-second memory cannot be recovered by killing the process in time. Therefore, in an application startup scenario with large memory requirements, such as camera startup, when a startup message is received, the thirty-second memory will be reclaimed by killing the process immediately (refer to step S3-52 in Figure 3-5) .
  • the time or order of killing the process corresponding to the above four situations is not limited, and as long as it satisfies any one of them, it can trigger the recovery of the thirtieth process by killing the process.
  • Second memory Second memory.
  • FIG. 3-6 is a schematic structural diagram of a memory management apparatus provided by an embodiment of the present application.
  • the memory management apparatus 3-200 may be used to execute some or all of the steps of the memory management method described in FIG. 3-2a to FIG. 3-5.
  • the memory management apparatus 3-200 may include:
  • a thread module 3-21 the thread module 3-21 at least includes an anonymous page compression thread 3-211 and a PSI thread 3-212.
  • the anonymous page compression thread 3-211 is used to compress the anonymous page to reclaim the thirty-second memory.
  • the PSI thread 3-212 is used to monitor system resource pressure.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Mathematical Physics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)
  • Stored Programmes (AREA)

Abstract

本申请实施例公开一种内存管理方法、装置、电子设备及计算机可读存储介质,本申请的实施例可以通过在第一应用启动时,创建所述第一应用的应用级内存控制组,并将所述第一应用的匿名页添加至所述应用级内存控制组的最近最少使用链表中,将所述第一应用的文件页添加至全局最近最少使用链表中。采用本申请的实施例,通过以应用的维度创建应用级内存控制组,精细化管理应用的匿名页,同时应用级内存控制组的文件页可以按照全局最近最少使用链表管理,因此,可以提升操作系统的稳定性,避免电子设备出现卡顿现象,提升用户的体验度。

Description

内存管理方法、装置、电子设备以及计算机可读存储介质
本申请要求在2020年11月30日提交中国国家知识产权局、申请号为202011381363.6的中国专利申请的优先权,发明名称为“内存管理方法、装置、电子设备以及计算机可读存储介质”的中国专利申请的优先权,要求在2020年11月30日提交中国国家知识产权局、申请号为202011381379.7的中国专利申请的优先权,发明名称为“内存管理方法、装置、电子设备以及计算机可读存储介质”的中国专利申请的优先权,要求在2020年11月30日提交中国国家知识产权局、申请号为202011381223.9的中国专利申请的优先权,发明名称为“内存管理方法、装置、电子设备以及计算机可读存储介质”的中国专利申请的优先权,要求在2020年12月1日提交中国国家知识产权局、申请号为202011385387.9的中国专利申请的优先权,发明名称为“匿名页管理方法、装置、电子设备、介质及程序产品”的中国专利申请的优先权,要求在2020年12月23日提交中国国家知识产权局、申请号为202011540521.8的中国专利申请的优先权,发明名称为“一种基于寿命预测的UFS器件寿命管控方法”的中国专利申请的优先权,要求在2020年10月31日提交中国国家知识产权局、申请号为202011197410.1的中国专利申请的优先权,发明名称为“一种内存管理方法及电子设备”的中国专利申请的优先权,要求在2020年10月31日提交中国国家知识产权局、申请号为202011197416.9的中国专利申请的优先权,发明名称为“一种内存管理方法及设备”的中国专利申请的优先权,要求在2020年12月30日提交中国国家知识产权局、申请号为202011628747.3的中国专利申请的优先权,发明名称为“内存管理方法、装置、电子设备以及计算机可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及计算机技术领域,尤其涉及一种内存管理方法、装置、电子设备及计算机可读存储介质。
背景技术
随着终端技术的发展,终端设备成为人们日常生活中必不可缺的物品。然而终端设备在使用过程中,随着应用打开数量的增加,其中运行的进程越来越多,占用的内存也会越来越多,这样将会使得系统的可用内存变少,出现内存不足的问题,进而导致终端设备出现卡顿现象。
发明内容
本申请实施例提供一种内存管理方法、装置、电子设备及计算机可读存储介质,用于管理电子设备的内存,可以提升内存回收效率,能够减少系统卡顿,并提升用户的体验度。
第一方面,本申请的实施例提供一种内存管理方法,所述内存管理方法包括:
第一应用启动时,创建所述第一应用的应用级内存控制组;将所述第一应用的匿名页添加至所述应用级内存控制组的最近最少使用链表中,根据所述最近最少使用链表对匿名页进行回收;将所述第一应用的文件页添加至内存节点的全局最近最少使用链表中,根据所述全局最近最少使用链表对文件页进行回收。采用本申请实施例所提供的内存管理方法,通过为第一应用创建对应的应用级内存控制组,将第一应用的匿名页添加到对应的应用级内存控制组,并将第一应用的文件页添加到全局最近最少使用链表中,由此不仅可以对匿名页进行精细化管理,同时还不会影响内存的回收效率,进而可以减少系统卡顿,提升用户的体验。
结合第一方面,在一种可能的设计中,所述内存管理方法还包括:根据所述应用级内存控制组管理所述第一应用的匿名页;和/或根据所述第一应用的状态控制所述匿名页的回收顺序;和/或根据所述应用级内存控制组控制所述匿名页的回收比例,其中所述匿名页的回收比例为所述第一应用中待回收的匿名页数量与所述第一应用中匿名页的总数;和/或控制所述应用级内存控制组所管理的第一应用的内存使用量。基于上述设计,由此,本申请实施例能够根据所述应用级内存控制组管理应用的匿名页,例如可以管理内存的回收及释放等,提升用户的体验。
结合第一方面,在一种可能的设计中,所述内存管理方法还包括:根据所述第一应用的冻结状态和/或活跃状态和/或前台状态决定所述第一应用的匿名页的回收顺序。由此,本申请实施例能够根据所述应用级内存控制组管理应用的匿名页,例如可以管理内存的回收及释放等,提升用户的体验。
结合第一方面,在一种可能的设计中,所述第一应用启动时,创建所述第一应用的应用级内存控制组还包括:所述第一应用的第一进程启动时,按照所述第一进程所对应的应用标识创建所述第一应用对应的应用级内存控制组。基于这样的设计,每个应用具有一个应用标识,可以用于唯一标识该应用。因此,第一应用在启动时可以按照应用标识来创建对应的应用级内存控制组,由此以应用的维度来创建对应的应用级内存控制组,提升内存的回收效率。
结合第一方面,在一种可能的设计中,所述第一应用的第一进程启动时,按照所述第一进程所对应的应用标识创建所述第一应用对应的应用级内存控制组还包括:若所述第一进程对应的所述应用标识对应的内存控制组不存在,则创建所述第一应用对应的应用级内存控制组。基于这样的设计,可以减少系统卡顿,提升用户的体验。
结合第一方面,在一种可能的设计中,若所述应用标识存在内存控制组,将所述第一进程添加到所述应用级内存控制组,根据所述应用级内存控制组管理所 述第一进程。基于这样的设计,在应用的第一进程启动时,可以将第一进程申请到的匿名页添加至应用级内存控制组中,并将第一进程申请到的文件页添加至全局最近最少使用链表中。由此,上述设计可以具有针对性对内存进行回收,提升内存回收的效率。
结合第一方面,在一种可能的设计中,所述内存管理方法还包括:电子设备启动时,按照白名单创建对应的内存控制组;系统进程启动时,按照系统进程的进程名判断是否为白名单进程;若是白名单进程,则将该白名单进程添加至所述内存控制组。采用这样的设计,可以避免系统误回收这些系统进程,影响用户的体验。
结合第一方面,在一种可能的设计中,所述内存管理方法还包括:将所述白名单进程的匿名页添加至所述内存控制组的最近最少使用链表;根据所述最近最少使用链表对所述白名单进程的匿名页进行回收。采用这样的设计,可以避免系统误回收这些系统进程,影响用户的体验。
结合第一方面,在一种可能的设计中,所述内存管理方法还包括:将所述白名单进程的文件页添加至内存节点的全局最近最少使用链表;根据所述全局最近最少使用链表对所述白名单进程的文件页进行回收。采用这样的设计,可以避免系统误回收这些系统进程,影响用户的体验。
在一种可能的设计中,所述内存管理方法还包括:当所述第一应用的第二进程启动时,将所述第二进程的匿名页添加到所述应用级内存控制组的所述最近最少使用链表中,并将所述第二进程的文件页添加到全局最近最少使用链表中。因此,上述设计可以具有针对性对内存进行回收,提升内存回收的效率。
在一种可能的设计中,所述内存管理方法还包括:当所述第一进程和/或所述第二进程销毁时,将所述第一进程和/或所述第二进程从所述应用级内存控制组中删除。基于这样的设计,当进程销毁时,进程从内存控制组中删除,从而将该进程的匿名页及文件页释放,提升操作系统的流畅性,避免电子设备出现卡顿现象。
在一种可能的设计中,所述内存管理方法还包括:当所述第一应用销毁时,删除所述应用级内存控制组。基于这样的设计,该进程的匿名页可以从应用级内存控制组的最近最少使用链表中删除并释放,该进程的文件页从全局最近最少使用链表中删除并释放,从而提升操作系统的流畅性,避免电子设备出现卡顿现象。
在一种可能的设计中,所述内存管理方法还包括:当所述第一应用申请到所述匿名页时,将所述匿名页添加至所述应用级内存控制组的活跃最近最少使用链表中;当所述第一应用申请到所述文件页时,将所述文件页添加至全局活跃最近最少使用链表中。因此,上述设计可以具有针对性对内存进行回收,提升内存回收的效率。
第二方面,本申请的实施例还提供一种内存管理装置,所述内存管理装置包括:
创建模块,用于在第一应用启动时,创建所述第一应用的应用级内存控制组;
控制模块,用于将第一应用的匿名页添加至所述内存控制组的最近最少使用链表中,根据所述最近最少使用链表对匿名页进行回收,所述控制模块还用于将所述第一应用的文件页添加至全局最近最少使用链表中,根据所述全局最近最少使用链表对文件页进行回收。采用本申请实施例所提供的内存管理装置,通过创建模块为第一应用创建对应的应用级内存控制组,并通过控制模块将第一应用的匿名页添加到对应的应用级内存控制组,并将第一应用的文件页添加到全局最近最少使用链表中,由此不仅可以对匿名页进行精细化管理,同时还不会影响内存的回收效率,进而可以减少系统卡顿,提升用户的体验。
结合第二方面,在一种可能的设计中,所述内存管理装置还包括管理模块,所述管理模块还用于:根据所述应用级内存控制组管理所述第一应用的匿名页;和/或根据所述第一应用的状态控制所述匿名页的回收顺序;和/或根据所述应用级内存控制组控制所述匿名页的回收比例,其中所述匿名页的回收比例为所述第一应用中待回收的匿名页数量与所述第一应用中匿名页的总数;和/或控制所述应用级内存控制组的内存使用量。基于这样的设计,可以提升内存的回收效率,进而可以减少系统卡顿,提升用户的体验。
结合第二方面,在一种可能的设计中,所述创建模块还可以用于在所述第一应用的第一进程启动时,按照所述第一进程所对应的应用标识创建所述第一应用对应的应用级内存控制组。基于这样的设计,每个应用具有一个应用标识,可以用于唯一标识该应用。因此,所述创建模块可以在第一应用启动时按照应用标识来创建对应的应用级内存控制组,由此以应用的维度来创建对应的应用级内存控制组,提升内存的回收效率。
结合第二方面,在一种可能的设计中,所述创建模块还用于在所述第一进程对应的所述应用标识对应的内存控制组不存在时,创建所述第一应用对应的应用级内存控制组。由此,上述设计可以具有针对性对内存进行回收,提升内存回收的效率。
结合第二方面,在一种可能的设计中,所述控制模块用于在所述应用标识存在内存控制组时,将所述第一进程添加到所述应用级内存控制组;所述管理模块还用于根据所述应用级内存控制组管理所述第一进程。基于这样的设计,可以提升内存的回收效率,进而可以减少系统卡顿,提升用户的体验。
在一种可能的设计中,所述管理模块用于在所述第一进程销毁时将所述第一进程从所述应用级内存控制组中删除。基于这样的设计,当进程销毁时,进程从内存控制组中删除,从而将该进程的匿名页及文件页释放,提升操作系统的流畅性,避免电子设备出现卡顿现象。
在一种可能的设计中,所述管理模块还用于在所述第一应用销毁时,删除所述应用级内存控制组。基于这样的设计,该进程的匿名页从第一内存控制组的最近最少使用链表中删除并释放,该进程的文件页从全局最近最少使用链表中删除并释放,从而提升操作系统的流畅性,避免电子设备出现卡顿现象。
在一些可能的设计中,当所述第一应用申请到所述匿名页时,所述控制模 块用于将所述匿名页添加至所述应用级内存控制组的活跃最近最少使用链表中;当所述第一应用申请到所述文件页时,所述控制模块用于将所述文件页添加至全局活跃最近最少使用链表中。因此,上述设计可以具有针对性对内存进行回收,提升内存回收的效率。
第三方面,本申请的实施例还提供一种电子设备,所述电子设备包括:
存储器,用于存储有及计算机程序;
处理器,用于执行所述存储器存储的所述计算机程序,当所述计算机程序被执行时,所述处理器用于执行如上述所述的内存管理方法。
基于上述的设计,通过为第一应用创建对应的内存控制组,将第一应用的匿名页添加到对应的内存控制组,并将第一应用的文件页添加到全局最近最少使用链表中,由此不仅可以对匿名页进行精细化管理,同时还不会影响内存的回收效率,进而可以减少系统卡顿,提升用户的体验。
第四方面,本申请的实施例还提供一种计算机可读存储介质,所述计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如上述所述的内存管理方法。
本申请上述实施例中,通过为第一应用创建对应的应用级内存控制组,将第一应用的匿名页添加到对应的应用级内存控制组,并将第一应用的文件页添加到全局最近最少使用链表中,由此不仅可以对匿名页进行精细化管理,同时还不会影响内存的回收效率,进而可以减少系统卡顿,提升用户的体验。
本申请实施例提供一种内存管理方法、装置电子设备和计算机可读存储介质,用于管理电子设备的内存,可以提升内存的回收效率,扩大等效内存,进而提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
第五方面,本申请实施例提供一种内存管理方法,所述内存管理方法包括:
创建第十应用的第十内存控制组和第十一应用的第十一内存控制组;设置第十内存控制组的重要评分值,设置第十一内存控制组的重要评分值;内存控制组链表按照所述第十内存控制组及所述第十一内存控制组的重要评分值,对所述第十内存控制组及所述第十一内存控制组进行排序;根据所述内存控制组链表中所述第十内存控制组及所述第十一内存控制组的排序,对所述第十内存控制组及所述第十一内存控制组进行内存回收。
采用本申请实施例提供的内存管理方法,可以根据第十应用及第十一应用的状态更新第十内存控制组及第十一内存控制组的重要评分值,内存控制组链表可以根据所述内存控制组的重要评分值对第十内存控制组及第十一内存控制组进行排序。因此,回收机制根据所述内存控制组链表中所述第十内存控制组及第十一内存控制组的排序,对所述第十内存控制组及第十一内存控制组进行内存回收。本申请的实施例能够根据应用的运行状态,对第十应用的内存控制组及第十一应用的第十一内存控制组的回收顺序进行调整,提升内存的回收效率,扩大等效内存,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第五方面,在一种可能的设计中,根据所述第十应用的状态设置所述第十内存控制组的重要评分值,根据所述第十一应用的状态设置所述第十一内存控制组的重要评分值。基于上述设计,可以根据应用的运行状态调整对应内存控制组的重要评分制,提升用户的体验。
结合第五方面,在一种可能的设计中,当进行内存回收时,按照压缩比例对所述第十内存控制组进行内存压缩,并将压缩后的数据放入交换区中;按照压缩比例对所述第十一内存控制组进行内存压缩,并将压缩后的数据放入交换区中。基于这样的设计,可以提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第五方面,在一种可能的设计中,按照压缩比例对所述第十内存控制组进行内存压缩,并将压缩后的数据放入交换区中。基于这样的设计,可以按照预设的压缩比例来对内存控制组进行内存压缩,使得内存回收更加具有针对性及精确性,可以提升内存的回收效率。
结合第五方面,在一种可能的设计中,若交换区的数据达到预设水线,按照换出比例将所述第十内存控制组的数据从交换区中换出至外部存储;若交换区的数据达到预设水线,按照换出比例将所述第十一内存控制组的数据从交换区中换出至外部存储。基于这样的设计,可以按照预设的换出比例将数据从交换区换出到外部存储,由此使得内存回收更加具有针对性及精确性,可以提升内存的回收效率。
结合第五方面,在一种可能的设计中,根据所述第十应用的状态设置所述第十内存控制组的压缩比例和/或换出比例;根据所述第十一应用的状态设置所述第十一内存控制组的压缩比例和/或换出比例。本申请的实施例中,第十应用的状态变化时,第十内存控制组的重要评分值、压缩比例和换出比例随之变化,可以根据第十应用的运行状态,对应用的内存控制组的回收顺序进行调整,提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第五方面,在一种可能的设计中,根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,控制所述第十内存控制组和第十一内存控制组的压缩顺序和换出顺序。基于这样的设计,在内存回收过程中,内存控制组的重要性评分值顺序为应用的压缩和换出顺序,提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第五方面,在一种可能的设计中,若所述第十应用的压缩量占比达到压缩比例,则终止对所述第十应用的压缩,并继续按照所述内存控制组链表中内存控制组的排序进行压缩。基于这样的设计,可以提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第五方面,在一种可能的设计中,若所述第十应用的换出量占比达到换出比例,则终止对所述第十应用的换出,并继续按照所述内存控制组链表中内存控制组的排序进行换出。基于这样的设计,扩大等效内存,提升用户的体验。
结合第五方面,在一种可能的设计中,第十应用启动时,创建所述第十应用的第十内存控制组,并设定所述第十内存控制组的重要评分值为第十预设值。基于上述设计,可以提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第五方面,在一种可能的设计中,第十一应用启动时,创建所述第十一应用的第十一内存控制组。基于上述设计,可以提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第五方面,在一种可能的设计中,当所述第十应用处于前台运行时,所述第十内存控制组的重要评分值设置为前台默认值;当所述第十应用处于解冻状态时,所述第十内存控制组的重要评分值设为所述第十应用处于冻结状态之前时的重要评分值;当所述第十应用处于活跃状态时,按照所述第十应用的活跃时间比例和使用频繁程度调整所述第十内存控制组的重要评分值;当所述第十应用处于冻结状态时,按照所述第十应用的冻结解冻次数和内存占用大小调整所述第十内存控制组的重要评分值。本申请的实施例中,第十应用的状态变化时,第十内存控制组的重要评分值、压缩比例和换出比例随之变化,可以根据第十应用的运行状态,对应用的内存控制组的回收顺序进行调整,提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第五方面,在一种可能的设计中,若所述第十应用的压缩量占比达到所述第十压缩比例,则终止对所述第十应用的压缩,选择所述内存控制组链表中下一个应用进行压缩。通过上述设计,通过对每个应用设置合理的压缩量,可以有效地提升内存回收效率。
第六方面,本申请实施例还提供一种内存管理装置,所述内存管理装置包括;
创建模块,所述创建模块用于创建第十应用的第十内存控制组和第十一应用的第十一内存控制组;
控制模块,所述控制模块用于设置第十内存控制组的重要评分值和第十一内存控制组的重要评分值;
所述控制模块还用于控制内存控制组链表按照所述第十内存控制组和所述第十一内存控制组的重要评分值,对所述第十内存控制组及所述第十一内存控制组进行排序;
回收模块,所述回收模块用于根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,对所述第十内存控制组及第十一内存控制组进行内存回收。
采用本申请实施例提供的内存管理装置,所述控制模块可以设置第十内存控制组的重要评分值和第十一内存控制组的重要评分值,内存控制组链表可以根据内存控制组的重要评分值对多个内存控制组进行排序。因此,回收模块可以根据所述内存控制组链表中所述第十内存控制组及所述第十一内存控制组的排序,对所述第十内存控制组及所述第十一内存控制组进行内存回收。本 申请的实施例能够根据应用的运行状态,对应用的内存控制组的回收顺序进行调整,提升内存的回收效率,扩大等效内存,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第六方面,在一些可能的设计中,所述控制模块还用于根据所述第十应用的状态设置所述第十内存控制组的重要评分值。所述控制模块还用于根据所述第十一应用的状态设置所述第十一内存控制组的重要评分值。基于这样的设计,可以根据应用的运行状态调整对应内存控制组的重要评分制,提升用户的体验。
结合第六方面,在一些可能的设计中,所述回收模块还用于按照压缩比例对所述第十内存控制组进行内存压缩,并将压缩后的数据放入交换区中;所述回收模块还用于按照压缩比例对所述第十一内存控制组进行内存压缩,并将压缩后的数据放入交换区中。基于这样的设计,回收机制可以按照压缩比例来对内存控制组进行内存压缩,使得内存回收更加具有针对性及精确性,可以提升内存的回收效率。
结合第六方面,在一些可能的设计中,所述回收模块还用于在交换区的数据达到预设水线时,按照换出比例将所述第十内存控制组的数据从交换区中换出至外部存储;所述回收模块还用于在交换区的数据达到预设水线时,按照换出比例将所述第十一内存控制组的数据从交换区中换出至外部存储。基于这样的设计,回收机制可以按照预设的换出比例将数据从交换区换出到外部存储,由此使得内存回收更加具有针对性及精确性,可以提升内存的回收效率。
结合第六方面,在一些可能的设计中,所述回收模块还用于根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,控制所述第十内存控制组和第十一内存控制组的压缩顺序和换出顺序。基于上述设计,可以提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第六方面,在一些可能的设计中,当所述第十应用的状态变化时,所述控制模块更新所述第十应用的第十内存控制组的重要评分值和/或压缩比例和/或换出比例。本申请的实施例中,应用的状态变化时,内存控制组的重要评分值、压缩比例和换出比例随之变化,可以根据应用的运行状态,对应用的内存控制组的回收顺序进行调整,提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第六方面,在一些可能的设计中,当第十应用处于前台时,所述控制模块将该第十应用的第十内存控制组的重要评分值设置为前台默认值;当所述第十应用处于解冻状态时,所述控制模块将该第十应用的第十内存控制组的重要评分值设为所述第十应用处于冻结状态之前应用活跃时的重要评分值;当所述第十应用处于活跃状态时,所述控制模块根据所述第十应用的活跃时间比例、使用频繁程度,来调整该第十应用的第十内存控制组的重要评分值;当所述第十应用处于冻结状态时,所述控制模块根据所述第十应用的冻结解冻次数和内存占用大小调整该第十应用的第十内存控制组的重要评 分值。本申请的实施例中,第十应用的状态变化时,第十内存控制组的重要评分值、压缩比例和换出比例随之变化,可以根据第十应用的运行状态,对应用的内存控制组的回收顺序进行调整,提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第六方面,在一些可能的设计中,若所述第十应用的压缩量占比达到所述第十压缩比例,所述回收模块终止对所述第十应用的压缩,并继续按照所述内存控制组链表中内存控制组的排序进行压缩。通过上述设计,通过对每个应用设置合理的压缩量,可以有效地提升内存回收效率。
结合第六方面,在一些可能的设计中,所述创建模块还用于在第十应用启动时,创建所述第十应用的第十内存控制组。基于这样的设计,可以提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
结合第六方面,在一些可能的设计中,所述创建模块还用于在第十一应用启动时,创建所述第十一应用的第十一内存控制组。基于上述设计,可以提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
第七方面,本申请实施例还提供一种电子设备,所述电子设备包括:
存储器,用于存储计算机程序;
处理器,用于执行所述存储器存储的所述计算机程序,当所述计算机程序被执行时,所述处理器用于执行如上述所述的内存管理方法。
采用本申请实施例,电子设备可以根据应用的状态更新内存控制组的重要评分值,内存控制组链表可以根据所述内存控制组的重要评分值对第十内存控制组进行排序。因此,回收机制根据所述内存控制组链表中多个内存控制组的排序,对多个内存控制组进行内存回收。本申请的实施例提供的电子设备可以根据应用的运行状态,对多个内存控制组的回收顺序进行调整,提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
第八方面,本申请实施例还提供一种计算机可读存储介质,所述计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如上述所述的内存管理方法。
采用本申请实施例,可以根据应用的状态更新内存控制组的重要评分值,内存控制组链表可以根据所述内存控制组的重要评分值对多个内存控制组进行排序。因此,回收机制根据所述内存控制组链表中多个内存控制组的排序,对多个内存控制组进行内存回收。本申请的实施例能够根据应用的运行状态,对第十应用的内存控制组的回收顺序进行调整,提升内存的回收效率,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
本申请实施例中,根据所述第十应用及第十一应用的状态分别更新第十内存 控制组及第十一内存控制组的重要评分值,当需要进行内存回收时,回收机制根据所述内存控制组链表中第十内存控制组及第十一内存控制组的排序,对所述第十内存控制组及所述第十一内存控制组进行内存回收。因此,本申请实施例公开的内存管理方法、电子设备以及计算机可读存储介质,可以提高内存的回收效率,扩大等效内存,能够减少卡顿,并提升用户体验。
本申请实施例提供一种内存管理方法、装置、电子设备及计算机可读存储介质,以解决内存管理效率低,造成内存供给不及时,应用保活数量低的问题。
第九方面,本申请提供一种内存管理方法,应用于电子设备。所述内存管理方法包括创建内存统计值,所述内存统计值用以表征电子设备系统内存中剩余的可用内存,所述可用内存包括第三十一内存和第三十二内存。所述第三十一内存为空闲内存,所述空闲内存为系统尚未使用的内存。所述第三十二内存为被占用但是可通过回收来转换为第三十一内存的内存。所述内存统计值包括第三十一内存统计值及第三十二内存统计值,所述第三十一内存统计值大于所述第三十二内存统计值。当系统当前的内存统计值低于所述第三十二内存统计值时,启动匿名页压缩,以回收所述第三十二内存。当通过匿名页压缩后系统当前的内存统计值低于所述第三十一内存统计值时,下调所述内存统计值。本申请实施例提供的方法创建了一种新的可用内存,所述可用内存能够更有效体现可用内存供给能力,更有效的体现内存压力情况。再者,基于多级内存统计值,可通过匿名页压缩实现多级内存统计值的维持。多级内存统计值的设定,在内存压力较小时,可维持较高的内存统计值;内存压力较大时,可避免频繁进行匿名页压缩导致低效回收或者空转,最终达到根据内存压力高效维持内存统计值的长稳及应用保活的增加。
在一种可能的设计中,所述内存统计值还包括第三十三内存统计值,所述第三十三内存统计值小于所述第三十二内存统计值,所述方法还包括:当下调所述内存统计值且系统当前的内存统计值低于所述第三十三内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存,直至系统当前的内存统计值不低于所述第三十三内存统计值。因此,通过不同场景采用不同的内存回收方式,进而有效提高内存回收效率,以及时供应内存。
在一种可能的设计中,所述方法还包括:监控交换区的空间使用率;当当前所述交换区的空间使用率达到预设比例时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。本设计中,当启动匿名页压缩,导致所述交换区的空间使用率到达所述预设比例时,此时会导致所述内存统计值难以继续通过匿名页压缩的方式回收内存,此时所述可直接通过杀死进程来回收内存。因此,通过不同场景采用不同的内存回收方式,进而有效提高内存回收效率,以及时供应内存。
在一种可能的设计中,所述启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存,包括:确认系统当前的内 存压力等级为第三十一等级,并上报为第三十一级压力事件;根据所述第三十一级压力事件启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存。所述当通过匿名页压缩后系统当前的内存统计值低于所述第三十一内存统计值时,下调所述内存统计值,包括确认系统当前的内存压力等级为第三十二等级,上报为第三十二级压力事件;根据所述第三十二级压力事件下调所述内存统计值。所述当当前所述交换区的空间使用率达到预设比例时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存,包括确认系统当前的内存压力等级为第三十三等级,上报为第三十三级压力事件;根据所述第三十三级压力事件,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。所述第三十三等级的内存压力高于所述第三十二等级的内存压力,所述第三十二等级的内存压力高于所述第三十一等级的内存压力。显然,本设计中,可通过确认系统当前的内存等级上报不同的压力事件,并根据不同的压力事件采取不同的内存回收策略。即通过不同场景采用不同的内存回收方式,进而有效提高内存回收效率,以及时供应内存。
在一种可能的设计中,所述内存统计值还包括第三十四内存统计值,所述方法还包括:当系统当前的压力失速信息(PSI)值大于预设阈值时,上报PSI压力值;当接收到所述PSI压力值,且确认系统当前的内存统计值小于所述第三十四内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。本设计中,通常当大内存应用(例如相机)启动时,会在短时间内消耗大量内存,拉低内存统计值,此时会通过匿名页压缩来进行内存回收。但是从所述内存统计值下调到所述第三十三内存统计值的过程对于相机启动来说可能是缓慢的,所以除了大内存应用启动触发的杀进程,PSI压力上报将会是一个很好的补充,在所述内存统计值具有下降趋势的时候,也会及时通过杀死进程来回收内存。
在一种可能的设计中,所述方法还包括:监控是否有预设应用启动;当监控到有预设应用启动,且系统当前的内存统计值小于所述第三十一内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。本设计中,如果应用内存需求过快,PSI压力上报仍然存在延迟,则无法及时通过杀死进程来回收内存。因此在大内存需求的应用启动场景下,例如相机启动,会在收到启动消息时,立刻触发通过杀死进程来回收内存。
在一种可能的设计中,当系统处于灭屏状态时,所述第三十一内存统计值、第三十二内存统计值、第三十三内存统计值分别低于当系统处于亮屏状态时的第三十一内存统计值、第三十二内存统计值、第三十三内存统计值。本设计中,考虑到在灭屏场景下要降低灭屏后台功耗,以及要解决亮屏瞬间应用集中唤醒带来的内存冲击场景,可将所述内存统计值在灭屏场景和亮屏场景分别设置为两个不同的值,且处于灭屏场景时的内存统计值均低于亮屏场景下的内 存统计值。
在一种可能的设计中,所述方法还包括:根据应用的重要程度,进程优先级和/或应用匿名页大小及分布对进程进行排序,以根据排序后的进程来杀死进程。本设计中,通过创建杀进程列表,并根据所述杀进程列表中进程的顺序来杀死进程,可实现内存的快速高效回收。
在一种可能的设计中,所述方法还包括:配置回收参数;根据所述回收参数压缩匿名页,以回收所述第三十二内存。所述回收参数包括目标内存页的数量,目标内存页回收的优先级,和/或内存回收比例(ratio)。因此,本设计中,通过所述回收参数的设置,可指导匿名页压缩更快更高效地进行。
第十方面,本申请的实施例还提供一种内存管理装置。所述内存管理装置包括:创建模块,用以创建内存统计值,所述内存统计值用以表征电子设备系统内存中剩余的可用内存,所述可用内存包括第三十一内存和第三十二内存。所述第三十一内存为系统的空闲内存,所述空闲内存为系统尚未使用的内存。所述第三十二内存为被占用但是可通过回收来转换为第三十一内存的内存。所述内存统计值包括第三十一内存统计值及第三十二内存统计值,所述第三十一内存统计值大于所述第三十二内存统计值。所述内存管理装置还包括内存回收模块,用以当系统当前的内存统计值低于所述第三十二内存统计值时启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存。所述内存管理装置还包括内存调整模块,用以当通过匿名页压缩后系统当前的内存统计值低于所述第三十一内存统计值时下调所述内存统计值。
在一种可能的设计中,所述内存统计值还包括第三十三内存统计值,所述第三十三内存统计值小于所述第三十二内存统计值,所述内存回收模块还用以当下调所述内存统计值且系统当前的内存统计值低于所述第三十三内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
在一种可能的设计中,所述内存管理装置还包括上报模块,所述上报模块还用以监控交换区的空间使用率,所述内存回收模块还用以当当前所述交换区的空间使用率达到预设比例时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
在一种可能的设计中,所述上报模块还用以当系统当前的内存统计值低于所述第三十二内存统计值时,确认系统当前的内存压力等级为第三十一等级,并上报为第三十一级压力事件,所述内存回收模块再根据所述第三十一级压力事件启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存;所述上报模块还用以当通过匿名页压缩后系统当前的内存统计值低于所述第三十一内存统计值时,确认系统当前的内存压力等级为第三十二等级,并上报为第三十二级压力事件,所述内存调整模块再根据所述第三十二级压力事件下调所述内存统计值;所述上报模块还用以当 当前所述交换区的空间使用率达到预设比例时,确认系统当前的内存压力等级为第三十三等级,并上报为第三十三级压力事件,所述内存回收模块再根据所述第三十三级压力事件,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存;所述第三十三等级的内存压力高于所述第三十二等级的内存压力,所述第三十二等级的内存压力高于所述第三十一等级的内存压力。
在一种可能的设计中,所述内存统计值还包括第三十四内存统计值,所述上报模块还用以当系统当前的压力失速信息(PSI)值大于预设阈值时上报PSI压力值;所述内存回收模块还用以当接收到所述PSI压力值,且当系统当前的内存统计值小于所述第三十四内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
在一种可能的设计中,所述内存回收模块还用以监控是否有预设应用启动,当监控到有预设应用启动,且系统当前的内存统计值小于所述第三十一内存统计值时,所述内存回收模块通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
在一种可能的设计中,当系统处于灭屏状态时,所述第三十一内存统计值、第三十二内存统计值、第三十三内存统计值分别低于当系统处于亮屏状态时的第三十一内存统计值、第三十二内存统计值、第三十三内存统计值。
在一种可能的设计中,所述内存回收模块用以根据应用的重要程度,进程优先级和/或应用匿名页大小及分布对进程进行排序,并根据排序后的进程来杀死进程。
在一种可能的设计中,所述内存回收模块还用以配置回收参数,并根据所述回收参数压缩匿名页,以回收所述第三十二内存;所述回收参数包括目标内存页的数量,目标内存页回收的优先级,和/或内存回收比例(ratio)。
第十一方面,本申请的实施例还提供一种电子设备,包括:
存储单元,用于存储有计算机程序;
处理器,用于执行所述存储单元存储的所述计算机程序,当所述计算机程序被执行时,所述处理器用于执行本申请实施例上述第九方面及其任一可能的设计中的内存管理方法。
第十二方面,本申请实施例提供一种计算机可读存储介质,包括计算机指令,当所述计算机指令在电子设备上运行时,使得电子设备执行本申请实施例上述第九方面及其任一可能的设计中的内存管理方法。
另外,第十方面,第十一方面及第十二方面所带来的技术效果可参见上述方法部分各设计的方法相关的描述,此处不再赘述。
本申请实施例提供一种匿名页管理方法、装置、电子设备、介质及程序产品,用于管理电子设备的内存,可以提升内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
第十三方面,本申请的实施例提供一种匿名页管理方法,包括:
将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数;
将所述匿名页换出的数据从所述外部存储空间换入到所述内存中,记录换入
时刻的时间
参数;
根据所述换出时刻的时间参数和所述换入时刻的时间参数,获取所述换入到所述换出的时间间隔信息;
当所述时间间隔信息对应的数值比预设固定值大时,将匿名页换入所述内存的不活跃链表。
采用本申请实施例提供的匿名页管理方法,通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
在其中一种可能的设计中,所述将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数包括:当匿名页的数据从内存换出到外部存储空间时,根据所述匿名页所属不活跃链表移动页面个数得到换出时刻的时间参数。
基于这样的设计,根据匿名页所属不活跃链表移动页面个数记录换出时刻时间参数,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
在其中一种可能的设计中,所述将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数还包括:当匿名页的数据从内存换出到外部存储空间时,将所述换出时刻的时间参数存储至该匿名页对应的页表项。
基于这样的设计,页表项存储至内存中,将换出时刻的时间参数记录至页表项,以便于后续进行匿名页换入不活跃链表的操作,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
在其中一种可能的设计中,本申请实施例提供的匿名页管理方法还包括:根据所述匿名页所属不活跃链表的页面移动,记录所述匿名页所属不活跃链表移动页面个数。
基于这样的设计,根据匿名页所属不活跃链表的页面移动记录不活跃链表移动页面个数,以便于后续进行匿名页换入不活跃链表的操作,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
在其中一种可能的设计中,所述匿名页所属不活跃链表的页面移动包括:
所述匿名页所属不活跃链表的页面从不活跃链表尾部移除,或,所述匿名页 所属不活跃链表的页面移动到活跃链表。
基于这样的设计,根据匿名页所属不活跃链表的页面移动记录所述匿名页所属不活跃链表移动页面个数,以便于后续进行匿名页换入不活跃链表的操作,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
在其中一种可能的设计中,所述将所述匿名页换出的数据从所述外部存储空间换入到所述内存中,记录换入时刻的时间参数包括:当所述匿名页换出的数据从所述外部存储空间换入到内存中时,根据所述匿名页所属不活跃链表移动页面个数得到所述换入时刻的时间参数。
基于这样的设计,根据匿名页所属不活跃链表移动页面个数记录换入时刻时间参数,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
在其中一种可能的设计中,还包括:当所述匿名页发生缺页中断,且检测到所述匿名页换出的数据的存储位置在所述外部存储空间,将所述匿名页换出的数据从所述外部存储空间换入到所述内存。
基于这样的设计,当所述匿名页发生缺页中断时,将匿名页换入至内存中。提高操作系统的流畅性,提升用户的体验。
第十四方面,本申请的实施例还提供一种匿名页管理装置,包括:
第四十记录单元,用于将匿名页的数据从内存换出到外部存储空间,记录换
出时刻的时间参数;
第四十一记录单元,用于将所述匿名页换出的数据从所述外部存储空间换入
到所述内存中,记录换入时刻的时间参数;
获取单元,用于根据所述换出时刻的时间参数和所述换入时刻的时间参数,获取所述换入到所述换出的时间间隔信息;
换入单元,用于当所述时间间隔信息对应的数值比预设固定值大时,将匿名页换入所述内存的不活跃链表。在本申请实施例提供的匿名页管理装置中,通过将不颠簸的匿名页换入至内存的不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
第十五方面,本申请的实施例还提供一种电子设备,包括:
存储器,用于存储有计算机程序;
处理器,用于执行所述存储器存储的所述计算机程序,当所述计算机程序被执行时,所述处理器用于执行如上述所述的匿名页管理方法。因此,通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内 存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
第十六方面,本申请的实施例还提供一种计算机可读存储介质,所述计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如上述所述的匿名页管理方法。因此,通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
第十七方面,本申请的实施例还提供一种计算机程序产品,所述计算机程序产品包括计算机程序代码,当所述计算机程序代码被一个计算机执行的时候,所述计算机程序代码可以使得所述计算机执行如上述所述的匿名页管理方法。因此,通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
本申请实施例中,获取所述换入到所述换出的时间间隔信息,当所述时间间隔信息对应的数值比预设固定值大时,将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
本申请的实施例提供一种存储器的寿命管理方法、电子设备及计算机存储介质以对写入存储设备中的写入数据量进行管控,并保障存储设备使用寿命达到预期的使用寿命。
第十八方面,本申请提供一种存储器的寿命管理方法,应用在电子设备中,所述方法包括:获取第一周期由所述电子设备的内存待换出到所述电子设备的存储器的第一数据;获取所述存储器在所述第一周期的总数据配额,从所述总数据配额减去所述存储器的预设用户数据使用量得到所述第一周期的换出数据配额;根据所述换出数据配额将所述第一数据从内存换出到所述存储器;获取所述存储器的状态信息,并根据所述存储器的状态信息确定所述存储器在第二周期的换出数据配额,其中所述状态信息包括:擦写次数和/或总使用寿命和/或已使用寿命和/或容量和/或器件写入放大系数和/或已使用时间。本申请能够从所述总数据配额减去所述存储器的预设用户数据使用量得到所述第一周期的换出数据配额,并根据换出数据配额对从内存换出到存储器中的数据量进行限制,从而减少存储器的擦写次数,提升存储器的使用寿命,并保障存储器的使用寿命达到预期设计的寿命。
在一可能的设计中,从所述总数据配额减去所述存储器的预设用户数据使用量得到所述第一周期的换出数据配额包括:获取所述存储器在所述第一周期的擦写次数;根据所述存储器在所述第一周期的擦写次数及所述第一周期计算出所述存储器在所述第一周期的擦写次数的增长速度;根据所述存储器在所述第一周期的擦写次数的增长速度确定所述预设用户数据使用量;从所述总数据配额减去所述预设用户数据使用量得到所述存储器在所述第一周期的换出数据配额。通过上述技术方案,根据存储器的擦写次数计算出所述存储器在所述第一周期的换出数据配额,以实现对第一周期内从内存换出到存储器中的数据量的控制。
在一可能的设计中,所述根据所述存储器在所述第一周期的擦写次数的增长速度确定所述预设用户数据使用量包括:将所述存储器在所述第一周期的擦写次数的增长速度输入到磁盘寿命预测模型,并经过所述磁盘寿命预测模型处理后输出所述预设用户数据使用量,其中,所述磁盘寿命预测模型为学习所述存储器的擦写次数增长速度及所述预设用户数据使用量之间的关系的神经网络模型。上述技术方案通过磁盘寿命预测模型预测预设用户数据使用量,从而可以快速计算出存储器在第一周期的总数据配额。
在一可能的设计中,根据所述换出数据配额将所述第一数据从内存换出到所述存储器包括:判断所述第一周期是否结束;若所述第一周期没有结束,获取在所述第一周期已换出到所述存储器的数据,并将所述第一周期的换出数据配额与在所述第一周期已换出到所述存储器的数据相减得到剩余数据配额;判断所述第一数据是否小于所述剩余数据配额;若所述第一数据小于或等于所述剩余数据配额,将所有所述第一数据从内存换出到所述存储器;若所述第一数据大于或等于所述剩余数据配额,从所述第一数据中选出与所述剩余数据配额相同数据量的目标数据,将所述目标数据从内存换出到所述存储器,并关闭所述存储器的写入功能。通过上述技术方案,在第一数据小于剩余数据配额时将所有第一数据从内存换出到所述存储器,及在第一数据大于或等于所述剩余数据配额将所述第一数据中选出与所述剩余数据配额相同数据量的数据从内存换出到所述存储器,并关闭所述存储器的写入功能,能够提升存储器的使用寿命,并保障存储器的使用寿命达到预期设计的寿命。
在一可能的设计中,该方法还包括:若确定所述第一周期结束,在所述第二周期重新计算所述存储器的换出数据配额得到更新的换出数据配额,并在所述第二周期依据更新的换出数据配额对所述第二周期待换出到所述存储器的第二数据进行写入管控。通过上述技术方案,在第一周期结束后根据第二周期的换出数据配额对第二周期的从内存换出到存储器中的数据量进行管控。
在一可能的设计中,所述根据所述存储器的状态信息确定所述存储器在第二周期的换出数据配额包括:获取所述存储器在所述第二周期内预设时间段内的擦写次数;根据所述存储器在所述预设时间段内的擦写次数的增长速 度计算所述存储器在所述预设时间段内的擦写次数的增长速度;将所述存储器的擦写次数的增长速度输入到磁盘寿命预测模型中,并经过所述磁盘寿命预测模型处理后输出所述存储器在所述第二周期的总数据配额;将所述存储器在所述第二周期的总数据配额减去所述第二周期的预设用户数据使用量得到所述存储器在所述第二周期的换出数据配额,其中,所述磁盘寿命预测模型为用于学习所述存储器的擦写次数增长速度及所述存储器的总数据配额之间的关系的神经网络模型。上述技术方案通过磁盘寿命预测模型预测预设用户数据使用量,从而可以快速计算出存储器在第二周期的总数据配额。
在一可能的设计中,所述获取所述存储器在所述第一周期的换出数据配额包括:设定所述存储器的目标使用时间;获取所述存储器的已使用寿命及所述存储器的总使用寿命;获取所述存储器的器件写入放大系数及所述存储器的容量;根据公式p=(e-b)*q/((c/t)*w)计算得到所述存储器在所述第一周期的换出数据配额,其中,e为所述存储器的总使用寿命,b为所述存储器的已使用寿命,q为所述存储器的容量,c为存储器的目标使用时间,w为所述存储器的器件写入放大系数,t为所述第一周期,p为换出数据配额。通过上述技术方案,能够根据存储器的总使用寿命、存储器的已使用寿命、存储器的容量、存储器的目标使用时间、存储器的器件写入放大系数、第一周期确定存储器在第一周期的换出数据配额。
在一可能的设计中,所述根据所述换出数据配额将所述第一数据从内存换出到所述存储器包括:基于预设计时方式进行计时,并获取所述预设计时方式下的计时时间;判断所述计时时间是否在所述第一周期内:若所述计时时间在所述第一周期内,获取所述第一周期开始时间到所述计时时间前累计换出到所述存储器的累加数据;将所述存储器在所述第一周期的换出数据配额与所述累加数据相减得到剩余数据配额;若所述第一数据小于所述剩余数据配额,将所述第一数据从内存换出到所述存储器;否则若所述第一数据不小于所述剩余数据配额,从所述第一数据中选出与所述剩余数据配额相同数据量的目标数据,并将所述目标数据从内存换出到所述存储器,并关闭所述存储器的写入功能。通过上述技术方案,可以基于预设计时方式进行计时以确定所述第一周期是否结束,并在所述第一周期未结束且第一数据小于剩余数据配额时将所有第一数据从内存换出到所述存储器。
在一可能的设计中,所述存储器的状态信息确定所述存储器在第二周期的换出数据配额包括:获取所述存储器的已使用时间;根据公式p=(e-b)*q/((c-c1)*w/t)计算得到所述存储器在所述第二周期的换出数据配额,其中,c1为所述存储器的已使用时间。通过上述技术方案,能够实现根据存储器的总使用寿命、存储器的已使用寿命、存储器的容量、存储器的目标使用时间、存储器的器件写入放大系数、第一周期及存储器的已使用时间确定存储器在第二周期的换出数据配额。
在一可能的设计中,该方法还包括:若获取到所述电子设备的关机指令, 将所述计时时间及所述第一周期开始时间到所述计时时间前累计换出到所述存储器的所述累加数据存储到所述存储器中,其中,所述存储器为非易失性存储器。通过上述技术方案,电子设备在关机前能够将存储器在第一周期内的计时时间及累加数据存储到存储器中。
在一可能的设计中,该方法还包括:若获取到所述电子设备的开机指令,从所述存储器中读取所述计时时间及所述累加数据,并根据所述计时时间及所述累加数据对所述第一周期内待换出到所述存储器的第一数据进行管控。通过上述技术方案,电子设备在开机后能够根据电子设备在关机前的计时时间及累加数据继续对第一周期内从内存待换出到存储器的数据量进行管控。
在一可能的设计中,该方法还包括:设置检测周期;在每一所述检测周期获取所述存储器的已使用寿命及所述存储器的总使用寿命;在每一所述检测周期计算所述存储器的已使用寿命与所述存储器的总使用寿命的比值得到第一占比值;若在每一所述检测周期所述第一占比值小于预设占比值,将所述第一数据从所述内存换出到所述存储器;若在每一所述检测周期所述第一占比值大于或等于预设占比值,不将所述第一数据从所述内存换出到所述存储器,并关闭所述存储器的写入功能。通过上述技术方案,将存储器的已使用寿命占存储器的总使用寿命的第一占比值作为存储器的写入条件,从而对从所述内存待换出到所述存储器的第一数据进行管控,保障存储器到达设计的使用寿命。
在一可能的设计中,该方法还包括:确定所述存储器的目标使用时间;获取所述存储器的已使用寿命;若所述存储器的已使用寿命大于或等于所述存储器的目标使用时间,将所述第一数据从所述内存换出到所述存储器;若所述存储器的已使用寿命小于所述存储器的目标使用时间,根据公式d=k1*(c-b)*100/b计算得到数据限制量,其中,c为所述存储器的目标使用时间,b为所述存储器的已使用寿命,k1为用户设定的配置系数,所述配置系数表示相比较所述存储器的目标使用时间每少1%应对所述存储器在所述第一周期的换出数据配额减去多少GB单位的存储数据,d为数据限制量;将所述第一周期的换出数据配额减去所述数据限制量的差值作为所述存储器在所述第一周期的换出数据配额。通过上述技术方案,将在第一周期的换出数据配额减去数据限量的差值作为存储器在第一周期的换出数据配额,如此在第一周期对写入存储器的数据进行纠偏,可以延长存储器的使用寿命,以达到预期寿命。
在一可能的设计中,所述确定所述存储器的目标使用时间包括:获取所述存储器的目标使用寿命及所述存储器的总使用寿命;计算所述存储器的已使用寿命与所述存储器的总使用寿命的比例得到第二占比值;根据公式c=k2*a计算得到所述存储器的目标使用时间,其中a为存储器的目标使用寿命,k2为所述第二占比值。通过上述技术方案,能够存储器的目标使用寿命、已使用寿命、总使用寿命计算得到存储器的目标使用时间。
在一可能的设计中,所述配置系数为1GB。通过1GB的配置系数可以对第一周期的换出数据配额进行修正,以在第一周期对从内存换出到存储器的数据进行纠偏,以达到预期寿命。
在一可能的设计中,所述预设用户数据使用量为上周期的非系统软件写入所述存储器的数据量。通过上述技术方案,将预设用户数据使用量设定为上周期的非系统软件写入所述存储器的数据量。
第十九方面,本申请实施例提供另一种存储器的寿命管理方法,应用在电子设备中,所述方法包括:获取第一周期由所述电子设备的内存待换出到所述电子设备的存储器的第一数据;获取所述存储器在所述第一周期的换出数据配额;根据所述换出数据配额将所述第一数据从内存换出到所述存储器。本申请能够根据获取的换出数据配额对从内存换出到存储器中的数据量进行限制,从而减少存储器的擦写次数,提升存储器的使用寿命,并保障存储器的使用寿命达到预期设计的寿命。
第二十方面,本申请实施例提供一种电子设备,所述电子设备包括存储器和处理器:其中,所述存储器,用于存储程序指令;所述处理器,用于读取并执行所述存储器中存储的所述程序指令,当所述程序指令被所述处理器执行时,使得所述电子设备执行上述第十八方面、第十九方面的存储器的寿命管理方法。
第二十一方面,本申请实施例提供一种计算机存储介质,计算机存储介质存储有程序指令,当程序指令在电子设备上运行时,使得电子设备执行本申请实施例上述第十八方面、第十九方面的存储器的寿命管理方法。
另外,第二十方面至第二十一方面所带来的技术效果可参见上述方法部分各设计的方法相关的描述,此处不再赘述。
本申请实施例提供一种内存管理方法及电子设备,能够提高内存换出和内存换入的性能。
第二十二方面,本申请实施例提供一种内存管理方法,该方法可以包括:检测到第五十应用切换至前台,将属于第五十应用的第五十匿名页数据从外部存储加载至第五十内存区域(比如,内存的缓存块)中;如果第五十应用的第五十进程被调用时,第五十进程的第五十一匿名页在第五十进程的内存区域中不存在(即产生了内存缺页),从第五十内存区域读取第五十一匿名页数据;其中,第五十匿名页数据包括第五十一匿名页数据。
在该方法中,在应用切换至前台时,该应用的全部或大部分匿名页已经加载至第五十内存区域。产生内存缺页时,直接从第五十内存区域中读取需要访问的匿名页,访问的是内存中的数据,读取数据的性能不受外部存储读性能制约,提高了数据读取效率,有效避免产生系统卡顿。
结合第二十二方面,在一种可能的设计方式中,第五十匿名页数据在外部存储中存储为至少一个预设大小的数据块;该至少一个数据块的存储地址满足预设条件。其中,预设条件包括:存储地址连续;或者,存储地址最大跳跃间隔小于 第五十数值。
虚拟内存中一个存储块可以存储多个匿名页,将匿名页组包为数据块,以数据块为单位存储于虚拟内存中存储地址连续的空间。在应用切换至前台时,一种实现方式中,可以将虚拟内存中该应用的全部数据块加载至第五十内存区域。另一种实现方式中,由于进程可能被后台唤醒,将一个或多个数据块从虚拟内存加载至第五十内存区域。这样,可能出现某个应用的多个数据块在虚拟内存中存储地址不连续的情况。从虚拟内存中加载数据块时,可以跳跃间隔读取该应用的数据块。这样就可以将虚拟内存中该应用的全部匿名页数据加载至第五十内存区域中。
结合第二十二方面,在一种可能的设计方式中,该方法还包括:将第五十内存区域中属于第五十应用的第五十二匿名页数据移至外部存储中存储地址连续的第五十空间。
在内存换出时,将属于同一应用的匿名页数据移入外部存储中存储地址连续的空间;这样,内存换入时,就可以从存储地址连续的空间顺序读取该应用的匿名页数据。提高了数据读取效率。
结合第二十二方面,在一种可能的设计方式中,第五十内存区域中属于第五十应用的匿名页数据根据冷热排序,将第五十内存区域中属于第五十应用的第五十二匿名页数据移至外部存储中存储地址连续的第五十空间包括:按照从冷到热的顺序将属于第五十应用的第五十二匿名页数据从第五十内存区域中移出,并将第五十二匿名页数据存储至外部存储中存储地址连续的第五十空间。
内存换出时,按照从冷到热的顺序将属于第五十应用的第五十二匿名页数据从第五十内存区域中移出;这样外部存储中的匿名页数据可以按照冷热排序。
结合第二十二方面,在一种可能的设计方式中,将属于第五十应用的多个第五十匿名页数据从外部存储加载至内存的第五十内存区域中包括:按照从热到冷的顺序,将属于第五十应用的第五十匿名页数据从外部存储加载至内存的第五十内存区域中。
按照从热到冷的顺序将一个应用的数据块从虚拟内存加载至第五十内存区域,可以提高第五十进程被调用时,第五十内存区域中包括第五十进程的匿名页的几率,即提高从第五十内存区域读取到第五十进程匿名页的几率。从第五十内存区域读取匿名页数据比从虚拟内存读取匿名页数据的速度更快,提高了数据读取效率,有效避免产生系统卡顿。
结合第二十二方面,在一种可能的设计方式中,该方法还包括:将内存中最近最少使用的匿名页移至第五十内存区域;其中,先移至第五十内存区域的匿名页数据比后移至第五十内存区域的匿名页数据更冷。
按照冷热将匿名页从内存中移入第五十内存区域,可以使得第五十内存区域中匿名页区分冷热。
结合第二十二方面,在一种可能的设计方式中,将第五十内存区域中属于第五十应用的第五十二匿名页数据移至外部存储中存储地址连续的第五十空间包 括:将第五十内存区域中属于第五十应用的第五十二匿名页数据组包为一个或多个数据块;将一个或多个数据块移至外部存储中存储地址连续的第五十空间;其中,一个数据块包括多个第五十二匿名页数据。
结合第二十二方面,在一种可能的设计方式中,将第五十内存区域中属于第五十应用的第五十二匿名页数据组包为一个或多个数据块包括:将第五十内存区域中属于第五十应用的压缩后的第五十二匿名页数据组包为一个或多个数据块。
将匿名页压缩后存入第五十内存区域可以节省内存空间,提高内存利用率。
结合第二十二方面,在一种可能的设计方式中,一个第五十二匿名页数据大小为4k,一个数据块大小为32k。
结合第二十二方面,在一种可能的设计方式中,将属于第五十应用的第五十匿名页数据从外部存储加载至内存的第五十内存区域中包括:将外部存储中属于第五十应用的第五十匿名页数据解包后加载至内存的第五十内存区域中。
结合第二十二方面,在一种可能的设计方式中,将属于第五十应用的第五十匿名页数据从外部存储加载至内存的第五十内存区域中包括:将外部存储中属于第五十应用的第五十匿名页数据解包并解压缩后加载至内存的第五十内存区域中。
结合第二十二方面,在一种可能的设计方式中,该方法还包括:若外部存储中空余的存储地址连续的第五十空间小于第五十二匿名页数据占用空间,释放外部存储中属于第五十一应用的匿名页数据;其中,第五十一应用为外部存储中占用存储地址连续的空间最大的应用。
结合第二十二方面,在一种可能的设计方式中,外部存储中存储地址连续的第五十空间是预分配的。
结合第二十二方面,在一种可能的设计方式中,若外部存储中空余的第五十空间小于第五十二匿名页数据占用空间,停止将第五十二匿名页数据从第五十内存区域移至外部存储。
第二十三方面,本申请提供一种电子设备,该电子设备可以实现第二十二方面及其可能的设计方式中所述的内存管理方法,其可以通过软件、硬件、或者通过硬件执行相应的软件实现上述方法。在一种可能的设计中,该电子设备可以包括处理器和存储器;其中,存储器包括内存和外部存储。该处理器被配置为支持该电子设备执行上述第二十二方面及其可能的设计方式中相应的功能。存储器用于与处理器耦合,其保存该电子设备必要的程序指令和数据。
第二十四方面,本申请实施例提供一种计算机可读存储介质,该计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得电子设备执行如上述第二十二方面及其可能的设计方式中所述的内存管理方法。
第二十五方面,本申请实施例提供一种计算机程序产品,当所述计算机程序产品在计算机上运行时,使得所述计算机执行如上述第二十二方面及其可能的设计方式中所述的内存管理方法。
第二十三方面所述的电子设备,第二十四方面所述的计算机可读存储介质以 及第二十五方面所述的计算机程序产品所带来的技术效果可参见上述对应的方法所带来的技术效果,此处不再赘述。
本申请实施例提供一种内存管理方法及设备,能够减少向内核系统申请以及释放内存,降低内存交换时延,提高内存交换性能。
第二十六方面,本申请实施例提供一种内存管理方法,该方法可以包括:检测到第六十应用切换至前台,向内存交换内存池申请第六十内存;使用第六十内存将一个预设大小的数据块从外部存储加载至内存的缓存块中;其中,内存交换内存池用于存放第六十内存;一个数据块包括第六十应用的一个或多个匿名页。
在该方法中,内存交换处理需要将数据块从外部存储加载至内存的缓存块时,先向内存交换内存池申请第六十内存,而不是直接请求内核系统新分配内存。这样,可以减少向内核系统申请以及释放内存,降低内存交换时延。
结合第二十六方面,在一种可能的设计方式中,若向内存交换内存池申请第六十内存失败,向内核系统申请分配第六十内存;使用内核系统分配的第六十内存将一个预设大小的数据块从外部存储加载至内存的缓存块中。也就是说,如果内存交换内存池中不存在第六十内存,则请求内核系统新分配内存。
结合第二十六方面,在一种可能的设计方式中,该方法还包括:向内存交换内存池申请第六十内存;内存交换处理使用第六十内存将一个预设大小的数据块从内存的缓存块移至外部存储中。
在该方法中,内存交换处理需要将数据块从内存的缓存块移至外部存储时,先向内存交换内存池申请第六十内存,而不是直接请求内核系统新分配内存。这样,可以减少向内核系统申请以及释放内存,降低内存交换时延。
结合第二十六方面,在一种可能的设计方式中,若向内存交换内存池申请第六十内存失败,向内核系统申请分配第六十内存;使用内核系统分配的第六十内存将一个预设大小的数据块从内存的缓存块移至外部存储中。也就是说,如果内存交换内存池中不存在第六十内存,则请求内核系统新分配内存。
结合第二十六方面,在一种可能的设计方式中,该方法还包括:将第六十内存释放至内存交换内存池,使得内存交换内存池中增加一个第六十内存。
在该方法中,使用第六十内存移动完数据块后,先将第六十内存释放回内存交换内存池,而不是直接释放回内核系统。这样,内存交换处理可以使用这些第六十内存移动其他的数据块,避免频繁的向内核系统申请和释放内存。
结合第二十六方面,在一种可能的设计方式中,该方法还包括:满足第六十设定条件时,内存交换内存池向内核系统释放内存交换内存池中全部的第六十内存。其中,第六十设定条件包括:外部存储中不存在待加载至内存的缓存块中的数据块;并且,内存的缓存块中不存在待移至外部存储中的数据块。
也就是说,一次内存交换过程结束后,将内核系统分配的内存全部释放回内核系统。
结合第二十六方面,在一种可能的设计方式中,该方法还包括:满足第六十一设定条件时,内存交换内存池向内核系统释放内存交换内存池中部分第六十内 存。其中,第六十一设定条件包括:内存交换内存池中第六十内存大于设定阈值。
结合第二十六方面,在一种可能的设计方式中,内存交换内存池向内核系统释放内存交换内存池中部分第六十内存包括:释放内存交换内存池中超过设定阈值的部分;或者根据设定范围释放内存交换内存池中部分第六十内存。
结合第二十六方面,在一种可能的设计方式中,该内核系统为Linux内核。
第二十七方面,本申请提供一种电子设备,该电子设备可以实现第二十六方面及其可能的设计方式中所述的内存管理方法,其可以通过软件、硬件、或者通过硬件执行相应的软件实现上述方法。在一种可能的设计中,该电子设备可以包括处理器和存储器;其中,存储器包括内存和外部存储。该处理器被配置为支持该电子设备执行上述第二十六方面及其可能的设计方式中相应的功能。存储器用于与处理器耦合,其保存该电子设备必要的程序指令和数据。
第二十八方面,本申请实施例提供一种计算机可读存储介质,该计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得电子设备执行如上述第二十六方面及其可能的设计方式中所述的内存管理方法。
第二十九方面,本申请实施例提供一种计算机程序产品,当所述计算机程序产品在计算机上运行时,使得所述计算机执行如上述第二十六方面及其可能的设计方式中所述的内存管理方法。
第二十七方面所述的电子设备,第二十八方面所述的计算机可读存储介质以及第二十九方面所述的计算机程序产品所带来的技术效果可参见上述对应的方法所带来的技术效果,此处不再赘述。
附图说明
图1-1为本申请实施例提供的内存管理方法所适用的一种电子设备的结构示意图;
图1-2为本申请实施例提供的一种操作系统的结构示意图;
图1-3为本申请实施例提供的一种内存管理方法的流程示意图;
图1-4为本申请实施例提供的另一种内存管理方法的流程示意图;
图1-5为本申请实施例提供的另一种内存管理方法的流程示意图;
图1-6为本申请实施例提供的一种内存管理方法的示意图;
图1-7为本申请实施例提供的另一种内存管理方法的示意图;
图1-8为本申请实施例提供的另一种内存管理方法的示意图;
图1-9为本申请实施例提供的一种内存管理装置的结构示意图;
图2-1为本申请实施例提供的内存管理方法所适用的一种电子设备的结构示意图;
图2-2为本申请实施例提供的一种操作系统的结构示意图;
图2-3为本申请实施例提供的一种内存管理方法的流程示意图;
图2-4为本申请实施例提供的另一种内存管理方法的流程示意图;
图2-5为本申请实施例提供的数据从交换区换出到外部存储的示意图;
图2-6为本申请实施例提供的内存控制组链表的示意图;
图2-7为本申请实施例提供的应用状态变化时内存控制组链表的示意图;
图2-8为本申请实施例提供的内存回收的示意图;
图2-9为本申请实施例提供的一种内存压缩方法的流程示意图;
图2-10为本申请实施例提供的一种内存换出方法的流程示意图;
图2-11为本申请实施例提供的一种内存管理装置的结构示意图;
图3-1为本申请实施例提供的内存管理方法所适用的一种电子设备的结构示意图;
图3-2a为本申请实施例提供的一种内存管理方法的流程示意图;
图3-2b为本申请实施例提供的三种内存统计值对应不同的内存管理策略示意图;
图3-3为本申请实施例提供的另一种内存管理方法的流程示意图;
图3-4为本申请实施例提供的另一种内存管理方法的流程示意图;
图3-5为本申请实施例提供的另一种内存管理方法的流程示意图;
图3-6为本申请实施例提供的一种内存管理装置的结构示意图;
图3-7为本申请实施例提供的另一种内存管理装置的框架示意图;
图3-8为本申请实施例中预设应用启动时的流程示意图;
图3-9为本申请实施例提供的另一种电子设备的结构示意图;
图4-1为本申请实施例提供的页表映射的结构示意图;
图4-2为本申请实施例提供的内存节点、内存管理区域及页结构关系示意图;
图4-3为本申请实施例提供的一种链表管理结构示意图;
图4-4为本申请实施例提供的另一种链表管理结构示意图;
图4-5为本申请实施例中电子设备结构示意图;
图4-6为本申请实施例中电子设备的软件结构框图;
图4-7为本申请实施例提供的匿名页生命周期的示意图;
图4-8为本申请实施例提供的页表索引的结构示意图;
图4-9为本申请实施例提供的匿名页管理方法流程示意图;
图4-10为本申请实施例提供的匿名页换出流程示意图;
图4-11为本申请实施例提供的匿名页换出方法流程示意图;
图4-12为本申请实施例提供的匿名页换入流程示意图;
图4-13为本申请实施例提供的匿名页换入方法流程示意图;
图4-14为本申请实施例提供的匿名页颠簸判断示意图;
图4-15为本申请实施例提供的另一种匿名页管理方法方框示意图;
图4-16为本申请实施例提供的另一种匿名页管理方法流程示意图;
图4-17为本申请实施例提供的一种匿名页管理装置模块示意图;
图4-18为本申请实施例提供的一种第四十记录单元模块示意图;
图4-19为本申请实施例提供的另一种匿名页管理装置模块示意图;
图5-1为本申请一实施例中存储器的寿命管理方法的系统架构图;
图5-2为本申请一实施例中存储器的寿命管理方法的流程图;
图5-3为本申请一个实施例中获取存储器的换出数据配额的方法流程图;
图5-4为本申请一实施例中根据换出数据配额将第一数据从内存换出到存储器的方法流程图;
图5-5为本申请另一实施例中获取存储器的换出数据配额的方法流程图;
图5-6为本申请一实施例中根据换出数据配额将第一数据换出到存储器的方法流程图;
图5-7A为本申请一实施例中存储管控模块写入统计信息的示意图;
图5-7B为本申请一实施例中存储管控模块读入统计信息的示意图;
图5-8为本申请一实施例中将第一数据换出到存储器的方法流程图;
图6-1为本申请实施例提供的电子设备的硬件结构示意图;
图6-2为内存换出和内存换入过程的示意图;
图6-3为一种内存管理方法的示意图;
图6-4为本申请实施例提供的内存管理方法的场景实例示意图;
图6-5为本申请实施例提供的内存管理方法的流程示意图;
图6-6为本申请实施例提供的内存管理方法的场景实例示意图;
图6-7为本申请实施例提供的内存管理方法的场景实例示意图;
图6-8为本申请实施例提供的内存管理方法的场景实例示意图;
图6-9为本申请实施例提供的内存管理方法的场景实例示意图;
图6-10为本申请实施例提供的内存管理方法的场景实例示意图;
图6-11为本申请实施例提供的内存管理方法的场景实例示意图;
图6-12为本申请实施例提供的内存管理方法的场景实例示意图;
图6-13为本申请实施例提供的内存管理方法的场景实例示意图;
图6-14为本申请实施例提供的一种电子设备的结构组成示意图;
图7-1为本申请实施例提供的电子设备的硬件结构示意图;
图7-2为内存换出和内存换入过程的示意图;
图7-3为一种内存换出和内存换入方法的示意图;
图7-4为内存换出和内存换入过程中内存交换处理工作原理示意图;
图7-5为一种内存管理方法的场景实例示意图;
图7-6为本申请实施例提供的内存管理方法的场景实例示意图;
图7-7为本申请实施例提供的一种电子设备的结构组成示意图。
主要元件符号说明
电子设备                         1-100
处理器                           1-110
外部存储器接口                   1-120
内部存储器                       1-121
USB接口                          1-130
充电管理模块                     1-140
电源管理模块                    1-141
电池                            1-142
天线                            1-1、1-2
移动通信模块                    1-150
无线通信模块                    1-160
音频模块                        1-170
扬声器                          1-170A
受话器                          1-170B
麦克风                          1-170C
耳机接口                        1-170D
传感器模块                      1-180
压力传感器                      1-180A
陀螺仪传感器                    1-180B
气压传感器                      1-180C
磁传感器                        1-180D
加速度传感器                    1-180E
距离传感器                      1-180F
接近光传感器                    1-180G
指纹传感器                      1-180H
温度传感器                      1-180J
触摸传感器                      1-180K
环境光传感器                    1-180L
骨传导传感器                    1-180M
按键                            1-190
马达                            1-191
指示器                          1-192
摄像头                          1-193
显示屏                          1-194
SIM卡接口                       1-195
内存管理装置                    1-200
创建模块                        1-201
控制模块                        1-202
管理模块                        1-203
电子设备                        2-100
处理器                          2-110
外部存储器接口                  2-120
内部存储器                      2-121
USB接口                         2-130
充电管理模块                    2-140
电源管理模块                    2-141
电池                            2-142
天线                            2-1、2-2
移动通信模块                    2-150
无线通信模块                    2-160
音频模块                        2-170
扬声器                          2-170A
受话器                          2-170B
麦克风                          2-170C
耳机接口                        2-170D
传感器模块                      2-180
压力传感器                      2-180A
陀螺仪传感器                    2-180B
气压传感器                      2-180C
磁传感器                        2-180D
加速度传感器                    2-180E
距离传感器                      2-180F
接近光传感器                    2-180G
指纹传感器                      2-180H
温度传感器                      2-180J
触摸传感器                      2-180K
环境光传感器                    2-180L
骨传导传感器                    2-180M
按键                            2-190
马达                            2-191
指示器                          2-192
摄像头                          2-193
显示屏                          2-194
SIM卡接口                       2-195
内存管理装置                    2-200
创建模块                        2-201
控制模块                        2-202
回收模块                        2-203
电子设备3-100、3-300 处理器3-110 外部存储器接口3-120
内部存储器3-121 USB接口3-130 充电管理模块3-140
电源管理模块3-141 电池3-142 天线3-1、3-2 移动通信模块3-150
无线通信模块3-160 音频模块3-170 扬声器3-170A 受话器3-170B
麦克风3-170C 耳机接口3-170D 传感器模块3-180 压力传感器3-180A
陀螺仪传感器3-180B 气压传感器3-180C 磁传感器3-180D
加速度传感器3-180E 距离传感器3-180F 接近光传感器3-180G
指纹传感器3-180H 温度传感器3-180J 触摸传感器3-180K
环境光传感器3-180L 骨传导传感器3-180M 按键3-190 马达3-191
指示器3-192 摄像头3-193 显示屏3-194 SIM卡接口3-195
内存管理装置3-200 线程模块3-21 匿名页压缩线程3-211 PSI线程3-212
创建模块3-22 上报模块3-23 内存回收模块3-24 内存调整模块3-25
处理单元3-301 存储单元3-302
电子设备                        4-100
处理器                          4-110
外部存储器接口                  4-120
内部存储器                      4-121
USB接口                         4-130
充电管理模块                    4-140
电源管理模块                    4-141
电池                            4-142
天线                            4-1、4-2
移动通信模块                    4-150
无线通信模块                    4-160
音频模块                        4-170
扬声器                          4-170A
受话器                          4-170B
麦克风                          4-170C
耳机接口                        4-170D
传感器模块                      4-180
压力传感器                      4-180A
陀螺仪传感器                     4-180B
气压传感器                       4-180C
磁传感器                         4-180D
加速度传感器                     4-180E
距离传感器                       4-180F
接近光传感器                     4-180G
指纹传感器                       4-180H
温度传感器                       4-180J
触摸传感器                       4-180K
环境光传感器                     4-180L
骨传导传感器                     4-180M
按键                             4-190
马达                             4-191
指示器                           4-192
摄像头                           4-193
显示屏                           4-194
SIM卡接口                        4-195
匿名页管理装置                   4-200
第四十记录单元                   4-10
第四十一记录单元                 4-20
获取单元                         4-30
换入单元                         4-40
参数获取单元                     4-182
存储单元                         4-183
页面记录单元                     4-181
中断单元                         4-50
如下具体实施方式将结合上述附图进一步说明本申请。
具体实施方式
为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
以下实施例中所使用的术语只是为了描述特定实施例的目的,而并非旨在作为对本申请的限制。如在本申请的说明书和所附权利要求书中所使用的那样,单数表达形式“一个”、“一种”、“所述”、“上述”、“该”和“这一”旨在也包括例 如“一个或多个”这种表达形式,除非其上下文中明确地有相反指示。还应当理解,在本申请以下各实施例中,“至少一个”、“一个或多个”是指一个或两个以上(包含两个)。术语“和/或”,用于描述关联对象的关联关系,表示可以存在三种关系;例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B的情况,其中A、B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。
在本说明书中描述的参考“一个实施例”或“一些实施例”等意味着在本申请的一个或多个实施例中包括结合该实施例描述的特定特征、结构或特点。由此,在本说明书中的不同之处出现的语句“在一个实施例中”、“在一些实施例中”、“在其他一些实施例中”、“在另外一些实施例中”等不是必然都参考相同的实施例,而是意味着“一个或多个但不是所有的实施例”,除非是以其他方式另外特别强调。术语“包括”、“包含”、“具有”及它们的变形都意味着“包括但不限于”,除非是以其他方式另外特别强调。术语“连接”包括直接连接和间接连接,除非另外说明。
本申请实施例中“至少一个”是指一个或者多个,多个是指两个或两个以上。例如,a、b或c中的至少一个,可以表示:a,b,c,a和b,a和c,b和c,
a、b和c七种情况。除非另有定义,本文所使用的所有的技术和科学术语与属于本申请中的技术领域的技术人员通常理解的含义相同。本申请的说明书中所使用的术语只是为了描述具体的实施例的目的,不是旨在于限制本申请。应理解,本申请中除非另有说明,“/”表示或的意思。例如,A/B可以表示A或B。本申请中的术语“和/或”,是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。本文中符号“/”表示关联对象是或者的关系,例如A/B表示A或者B。
本申请实施例中,“第一”、“第二”等词汇,仅用于区别不同的对象,不能理解为指示或暗示相对重要性,也不能理解为指示或暗示顺序。例如,第一应用、第二应用等是用于区别不同的应用,而不是用于描述应用的特定顺序,限定有“第一”、“第二”的特征可以明示或者隐含地包括一个或者更多个该特征。
本申请实施例中,“第十”、“第十一”等词汇,仅用于区别不同的对象,不能理解为指示或暗示相对重要性,也不能理解为指示或暗示顺序。例如,第十应用、第十一应用等是用于区别不同的应用,而不是用于描述应用的特定顺序,限定有“第十”、“第十一”的特征可以明示或者隐含地包括一个或者更多个该特征。
以下,术语”第五十”、”第五十一”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有”第五十”、”第五十一”的特征可以明示或者隐含地包括一个或者更多个该特征。
以下,术语“第六十”、“第六十一”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第六十”、 “第六十一”的特征可以明示或者隐含地包括一个或者更多个该特征。
在本申请实施例的描述中,“示例性的”或者“例如”等词用于表示作例子、例证或说明。本申请实施例中被描述为“示例性的”或者“例如”的任何实施例或设计方案不应被解释为比其它实施例或设计方案更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。
本申请实施例公开一种内存管理的方法、电子设备及计算机可读存储介质,可以提升操作系统的稳定性,避免电子设备出现卡顿现象,提升用户的体验。
本申请实施例提供的内存管理的方法可以应用于电子设备,所述电子设备也可称之为用户设备(User Equipment,UE)、移动台(Mobile Station,MS)、移动终端(Mobile Terminal)等。可选地,所述电子设备可以具备无线接入网(Radio Access Nework,RAN)与一个或多个核心网进行通信的能力,例如,电子设备可以是移动电话(或称为“蜂窝”电话)、或具有移动性质的计算机等。
图1-1示出了电子设备1-100的结构示意图。
电子设备1-100可以是手机、平板电脑、桌面型计算机、膝上型计算机、手持计算机、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本,以及蜂窝电话、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)设备、虚拟现实(virtual reality,VR)设备、人工智能(artificial intelligence,AI)设备、可穿戴式设备、车载设备、智能家居设备和/或智慧城市设备,本申请实施例对该电子设备的具体类型不作特殊限制。
电子设备1-100可以包括处理器1-110,外部存储器接口1-201-120,内部存储器1-121,通用串行总线(universal serial bus,USB)接口1-130,充电管理模块1-140,电源管理模块1-141,电池1-142,天线1-1,天线1-2,移动通信模块1-150,无线通信模块1-160,音频模块1-170,扬声器1-170A,受话器1-170B,麦克风1-170C,耳机接口1-170D,传感器模块1-180,按键1-190,马达1-191,指示器1-192,摄像头1-193,显示屏1-194,以及用户标识模块(subscriber identification module,SIM)卡接口1-195等。其中传感器模块1-180可以包括压力传感器1-180A,陀螺仪传感器1-180B,气压传感器1-180C,磁传感器1-180D,加速度传感器1-180E,距离传感器1-180F,接近光传感器1-180G,指纹传感器1-180H,温度传感器1-180J,触摸传感器1-180K,环境光传感器1-180L,骨传导传感器1-180M等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备1-100的具体限定。在本申请另一些实施例中,电子设备1-100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器1-110可以包括一个或多个处理单元,例如:处理器1-110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP), 控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器1-110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器1-110中的存储器为高速缓冲存储器。该存储器可以保存处理器1-110刚用过或循环使用的指令或数据。如果处理器1-110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器1-110的等待时间,因而提升了系统的效率。
在一些实施例中,处理器1-110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
I2C接口是一种双向同步串行总线,包括一根串行数据线(serial data line,SDA)和一根串行时钟线(derail clock line,SCL)。在一些实施例中,处理器1-110可以包含多组I2C总线。处理器1-110可以通过不同的I2C总线接口分别耦合触摸传感器1-180K,充电器,闪光灯,摄像头1-193等。例如:处理器1-110可以通过I2C接口耦合触摸传感器1-180K,使处理器1-110与触摸传感器1-180K通过I2C总线接口通信,实现电子设备1-100的触摸功能。
I2S接口可以用于音频通信。在一些实施例中,处理器1-110可以包含多组I2S总线。处理器1-110可以通过I2S总线与音频模块1-170耦合,实现处理器1-110与音频模块1-170之间的通信。在一些实施例中,音频模块1-170可以通过I2S接口向无线通信模块1-160传递音频信号,实现通过蓝牙耳机接听电话的功能。
PCM接口也可以用于音频通信,将模拟信号抽样,量化和编码。在一些实施例中,音频模块1-170与无线通信模块1-160可以通过PCM总线接口耦合。在一些实施例中,音频模块1-170也可以通过PCM接口向无线通信模块1-160传递音频信号,实现通过蓝牙耳机接听电话的功能。所述I2S接口和所述PCM接口都可以用于音频通信。
UART接口是一种通用串行数据总线,用于异步通信。该总线可以为双向通信总线。它将要传输的数据在串行通信与并行通信之间转换。在一些实施例中,UART接口通常被用于连接处理器1-110与无线通信模块1-160。例 如:处理器1-110通过UART接口与无线通信模块1-160中的蓝牙模块通信,实现蓝牙功能。在一些实施例中,音频模块1-170可以通过UART接口向无线通信模块1-160传递音频信号,实现通过蓝牙耳机播放音乐的功能。
MIPI接口可以被用于连接处理器1-110与显示屏1-194,摄像头1-193等外围器件。MIPI接口包括摄像头串行接口(camera serial interface,CSI),显示屏串行接口(display serial interface,DSI)等。在一些实施例中,处理器1-110和摄像头1-193通过CSI接口通信,实现电子设备1-100的拍摄功能。处理器1-110和显示屏1-194通过DSI接口通信,实现电子设备1-100的显示功能。
GPIO接口可以通过软件配置。GPIO接口可以被配置为控制信号,也可被配置为数据信号。在一些实施例中,GPIO接口可以用于连接处理器1-110与摄像头1-193,显示屏1-194,无线通信模块1-160,音频模块1-170,传感器模块1-180等。GPIO接口还可以被配置为I2C接口,I2S接口,UART接口,MIPI接口等。
USB接口1-130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口1-130可以用于连接充电器为电子设备1-100充电,也可以用于电子设备1-100与外围设备之间传输数据。也可以用于连接耳机,通过耳机播放音频。该接口还可以用于连接其他电子设备,例如AR设备等。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备1-100的结构限定。在本申请另一些实施例中,电子设备1-100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块1-140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块1-140可以通过USB接口1-130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块1-140可以通过电子设备1-100的无线充电线圈接收无线充电输入。充电管理模块1-140为电池1-142充电的同时,还可以通过电源管理模块1-141为电子设备供电。
电源管理模块1-141用于连接电池1-142,充电管理模块1-140与处理器1-110。电源管理模块1-141接收电池1-142和/或充电管理模块1-140的输入,为处理器1-110,内部存储器1-121,显示屏1-194,摄像头1-193,和无线通信模块1-160等供电。电源管理模块1-141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块1-141也可以设置于处理器1-110中。在另一些实施例中,电源管理模块1-141和充电管理模块1-140也可以设置于同一个器件中。
电子设备1-100的无线通信功能可以通过天线1-1,天线1-2,移动通信模块1-150,无线通信模块1-160,调制解调处理器以及基带处理器等实现。
天线1-1和天线1-2用于发射和接收电磁波信号。电子设备1-100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提升天线的利用率。例如:可以将天线1-1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块1-150可以提供应用在电子设备1-100上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块1-150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块1-150可以由天线1-1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块1-150还可以对经调制解调处理器调制后的信号放大,经天线1-1转为电磁波辐射出去。在一些实施例中,移动通信模块1-150的至少部分功能模块可以被设置于处理器1-110中。在一些实施例中,移动通信模块1-150的至少部分功能模块可以与处理器1-110的至少部分模块被设置在同一个器件中。
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器1-170A,受话器1-170B等)输出声音信号,或通过显示屏1-194显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器1-110,与移动通信模块1-150或其他功能模块设置在同一个器件中。
无线通信模块1-160可以提供应用在电子设备1-100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块1-160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块1-160经由天线1-2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器1-110。无线通信模块1-160还可以从处理器1-110接收待发送的信号,对其进行调频,放大,经天线1-2转为电磁波辐射出去。
在一些实施例中,电子设备1-100的天线1-1和移动通信模块1-150耦合,天线1-2和无线通信模块1-160耦合,使得电子设备1-100可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access, TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。
电子设备1-100通过GPU,显示屏1-194,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏1-194和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器1-110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏1-194用于显示图像,视频等。显示屏1-194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,
Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备1-100可以包括1个或N个显示屏1-194,N为大于1的正整数。
电子设备1-100可以通过ISP,摄像头1-193,视频编解码器,GPU,显示屏1-194以及应用处理器等实现拍摄功能。
ISP用于处理摄像头1-193反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头1-193中。
摄像头1-193用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备1-100可以包括1个或N个摄像头1-193,N为大于1的正整数。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备1-100在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。电子设备1-100可以支持一种或多种视频编解码器。这样,电子设备1-100可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1, MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备1-100的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。
内部存储器1-121可以包括一个或多个随机存取存储器(random access memory,RAM)和一个或多个非易失性存储器(non-volatile memory,NVM)。
随机存取存储器可以包括静态随机存储器(static random-access memory,SRAM)、动态随机存储器(dynamic random access memory,DRAM)、同步动态随机存储器(synchronous dynamic random access memory,SDRAM)、双倍资料率同步动态随机存取存储器(double data rate synchronous dynamic random access memory,DDR SDRAM,例如第五代DDR SDRAM一般称为DDR5SDRAM)等;
非易失性存储器可以包括磁盘存储器件、快闪存储器(flash memory)。
快闪存储器按照运作原理划分可以包括NOR FLASH、NAND FLASH、3D NAND FLASH等,按照存储单元电位阶数划分可以包括单阶存储单元(single-level cell,SLC)、多阶存储单元(multi-level cell,MLC)、三阶储存单元(triple-level cell,TLC)、四阶储存单元(quad-level cell,QLC)等,按照存储规范划分可以包括通用闪存存储(英文:universal flash storage,UFS)、嵌入式多媒体存储卡(embedded multi media Card,eMMC)等。
随机存取存储器可以由处理器1-110直接进行读写,可以用于存储操作系统或其他正在运行中的程序的可执行程序(例如机器指令),还可以用于存储用户及应用程序的数据等。
非易失性存储器也可以存储可执行程序和存储用户及应用程序的数据等,可以提前加载到随机存取存储器中,用于处理器1-110直接进行读写。
外部存储器接口1-120可以用于连接外部的非易失性存储器,实现扩展电子设备1-100的存储能力。外部的非易失性存储器通过外部存储器接口1-120与处理器1-110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部的非易失性存储器中。
电子设备1-100可以通过音频模块1-170,扬声器1-170A,受话器1-170B,麦克风1-170C,耳机接口1-170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块1-170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块1-170还可以用于对音频信号编码和解码。在一些实施例中,音频模块1-170可以设置于处理器1-110中,或将音频模块1-170的部分功能模块设置于处理器1-110中。
扬声器1-170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备1-100可以通过扬声器1-170A收听音乐,或收听免提通话。
受话器1-170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备1-100接听电话或语音信息时,可以通过将受话器1-170B靠近人耳接听语音。
麦克风1-170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风1-170C发声,将声音信号输入到麦克风1-170C。电子设备1-100可以设置至少一个麦克风1-170C。在另一些实施例中,电子设备1-100可以设置两个麦克风1-170C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备1-100还可以设置三个,四个或更多麦克风1-170C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。
耳机接口1-170D用于连接有线耳机。耳机接口1-170D可以是USB接口1-130,也可以是3、5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。
压力传感器1-180A用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器1-180A可以设置于显示屏1-194。压力传感器1-180A的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器1-180A,电极之间的电容改变。电子设备1-100根据电容的变化确定压力的强度。当有触摸操作作用于显示屏1-194,电子设备1-100根据压力传感器1-180A检测所述触摸操作强度。电子设备1-100也可以根据压力传感器1-180A的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。
陀螺仪传感器1-180B可以用于确定电子设备1-100的运动姿态。在一些实施例中,可以通过陀螺仪传感器1-180B确定电子设备1-100围绕三个轴(即,x,y和z轴)的角速度。陀螺仪传感器1-180B可以用于拍摄防抖。示例性的,当按下快门,陀螺仪传感器1-180B检测电子设备1-100抖动的角度,根据角度计算出镜头模组需要补偿的距离,让镜头通过反向运动抵消电子设备1-100的抖动,实现防抖。陀螺仪传感器1-180B还可以用于导航,体感游戏场景。
气压传感器1-180C用于测量气压。在一些实施例中,电子设备1-100通过气压传感器1-180C测得的气压值计算海拔高度,辅助定位和导航。
磁传感器1-180D包括霍尔传感器。电子设备1-100可以利用磁传感器1-180D检测翻盖皮套的开合。在一些实施例中,当电子设备1-100是翻盖机时,电子设备1-100可以根据磁传感器1-180D检测翻盖的开合。进而根据检 测到的皮套的开合状态或翻盖的开合状态,设置翻盖解锁等特性。
加速度传感器1-180E可检测电子设备1-100在各个方向上(一般为三轴)加速度的大小。当电子设备1-100静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。
距离传感器1-180F,用于测量距离。电子设备1-100可以通过红外或激光测量距离。在一些实施例中,拍摄场景,电子设备1-100可以利用距离传感器1-180F测距以实现快速对焦。
接近光传感器1-180G可以包括例如发光二极管(LED)和光检测器,例如光电二极管。发光二极管可以是红外发光二极管。电子设备1-100通过发光二极管向外发射红外光。电子设备1-100使用光电二极管检测来自附近物体的红外反射光。当检测到充分的反射光时,可以确定电子设备1-100附近有物体。当检测到不充分的反射光时,电子设备1-100可以确定电子设备1-100附近没有物体。电子设备1-100可以利用接近光传感器1-180G检测用户手持电子设备1-100贴近耳朵通话,以便熄灭屏幕达到省电的目的。接近光传感器1-180G也可用于皮套模式,口袋模式解锁与锁屏。
环境光传感器1-180L用于感知环境光亮度。电子设备1-100可以根据感知的环境光亮度自适应调节显示屏1-194亮度。环境光传感器1-180L也可用于拍照时调节白平衡。环境光传感器1-180L还可以与接近光传感器1-180G配合,检测电子设备1-100是否在口袋里,以防误触。
指纹传感器1-180H用于获取指纹。电子设备1-100可以利用获取的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。
温度传感器1-180J用于检测温度。在一些实施例中,电子设备1-100利用温度传感器1-180J检测的温度,执行温度处理策略。例如,当温度传感器1-180J上报的温度超过阈值,电子设备1-100执行降低位于温度传感器1-180J附近的处理器的性能,以便降低功耗实施热保护。在另一些实施例中,当温度低于另一阈值时,电子设备1-100对电池1-142加热,以避免低温导致电子设备1-100异常关机。在其他一些实施例中,当温度低于又一阈值时,电子设备1-100对电池1-142的输出电压执行升压,以避免低温导致的异常关机。
触摸传感器1-180K,也称“触控器件”。触摸传感器1-180K可以设置于显示屏1-194,由触摸传感器1-180K与显示屏1-194组成触摸屏,也称“触控屏”。触摸传感器1-180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏1-194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器1-180K也可以设置于电子设备1-100的表面,与显示屏1-194所处的位置不同。
骨传导传感器1-180M可以获取振动信号。在一些实施例中,骨传导传感器1-180M可以获取人体声部振动骨块的振动信号。骨传导传感器1-180M 也可以接触人体脉搏,接收血压跳动信号。在一些实施例中,骨传导传感器1-180M也可以设置于耳机中,结合成骨传导耳机。音频模块1-170可以基于所述骨传导传感器1-180M获取的声部振动骨块的振动信号,解析出语音信号,实现语音功能。应用处理器可以基于所述骨传导传感器1-180M获取的血压跳动信号解析心率信息,实现心率检测功能。
按键1-190包括开机键,音量键等。按键1-190可以是机械按键。也可以是触摸式按键。电子设备1-100可以接收按键输入,产生与电子设备1-100的用户设置以及功能控制有关的键信号输入。
马达1-191可以产生振动提示。马达1-191可以用于来电振动提示,也可以用于触摸振动反馈。例如,作用于不同应用(例如拍照,音频播放等)的触摸操作,可以对应不同的振动反馈效果。作用于显示屏1-194不同区域的触摸操作,马达1-191也可对应不同的振动反馈效果。不同的应用场景(例如:时间提醒,接收信息,闹钟,游戏等)也可以对应不同的振动反馈效果。触摸振动反馈效果还可以支持自定义。
指示器1-192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。
SIM卡接口1-195用于连接SIM卡。SIM卡可以通过插入SIM卡接口1-195,或从SIM卡接口1-195拔出,实现和电子设备1-100的接触和分离。电子设备1-100可以支持1个或N个SIM卡接口,N为大于1的正整数。SIM卡接口1-195可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM卡接口1-195可以同时插入多张卡。所述多张卡的类型可以相同,也可以不同。SIM卡接口1-195也可以兼容不同类型的SIM卡。SIM卡接口1-195也可以兼容外部存储卡。电子设备1-100通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备1-100采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备1-100中,不能和电子设备1-100分离。电子设备1-100的软件系统可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。本申请实施例以分层架构的Android系统为例,示例性说明电子设备1-100的软件结构。
图1-2是本申请实施例的电子设备1-100的软件结构框图。
分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将Android系统分为四层,从上至下分别为应用程序层,应用程序框架层,安卓运行时(Android runtime)和系统库,以及内核层。
应用程序层可以包括一系列应用程序包。
如图1-2所示,应用程序包可以包括相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息等应用程序。
应用程序框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架。应用程序框架层包括一些预先定义 的函数。
如图1-2所示,应用程序框架层可以包括窗口管理器,内容提供器,视图系统,电话管理器,资源管理器,通知管理器等。
窗口管理器用于管理窗口程序。窗口管理器可以获取显示屏大小,判断是否有状态栏,锁定屏幕,截取屏幕等。
内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。
视图系统包括可视控件,例如显示文字的控件,显示图片的控件等。视图系统可用于构建应用程序。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。
电话管理器用于提供电子设备1-100的通信功能。例如通话状态的管理(包括接通,挂断等)。
资源管理器为应用程序提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。
通知管理器使应用程序可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在系统顶部状态栏的通知,例如后台运行的应用程序的通知,还可以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息,发出提示音,电子设备振动,指示灯闪烁等。
Android Runtime包括核心库和虚拟机。Android runtime负责安卓系统的调度和管理。
核心库包含两部分:一部分是java语言需要调用的功能函数,另一部分是安卓的核心库。
应用程序层和应用程序框架层运行在虚拟机中。虚拟机将应用程序层和应用程序框架层的java文件执行为二进制文件。虚拟机用于执行对象生命周期的管理,堆栈管理,线程管理,安全和异常的管理,以及垃圾回收等功能。
系统库可以包括多个功能模块。例如:表面管理器(surface manager),媒体库(Media Libraries),三维图形处理库(例如:OpenGL ES),2D图形引擎(例如:SGL)等。
表面管理器用于对显示子系统进行管理,并且为多个应用程序提供了2D和3D图层的融合。
媒体库支持多种常用的音频,视频格式回放和录制,以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:MPEG4,H、264,MP3,AAC,AMR,JPG,PNG等。
三维图形处理库用于实现三维图形绘图,图像渲染,合成,和图层处理等。
2D图形引擎是2D绘图的绘图引擎。
内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。
下面结合捕获拍照场景,示例性说明电子设备1-100软件以及硬件的工作流程。
当触摸传感器1-180K接收到触摸操作,相应的硬件中断被发给内核层。内核层将触摸操作加工成原始输入事件(包括触摸坐标,触摸操作的时间戳等信息)。原始输入事件被存储在内核层。应用程序框架层从内核层获取原始输入事件,识别该输入事件所对应的控件。以该触摸操作是触摸单击操作,该单击操作所对应的控件为相机应用图标的控件为例,相机应用调用应用框架层的接口,启动相机应用,进而通过调用内核层启动摄像头驱动,通过摄像头1-193捕获静态图像或视频。
基于上述电子设备的硬件结构,提出本申请内存管理方法的各个实施例。
本申请提供一种内存管理方法。
请参阅图1-3,图1-3是本申请实施例提供的内存管理方法的流程图。所述内存管理方法的执行主体为电子设备1-100,所述内存管理方法可以包括但不限于以下步骤:
步骤S1-31,电子设备在应用启动时,创建该应用的应用级内存控制组。
其中,内存控制组可以用于管理应用对应的内存单元,可以以对象的形式创建在内存中,包括用于管理内存单元的方法(例如控制内存单元的回收参数等)以及描述内存资源的相关信息。例如,所述相关信息可以包括当前内存控制组的物理内存占用情况,和当前内存控制组的内存活跃状态等,内存单元可以以页为单位,一页的大小可以是4KB字节。本申请提出一种基于应用级别的内存控制组,可以在应用启动时创建,可以包括所属应用的进程的内存信息,并根据内存信息对所属应用的进程进行管理,可以使得内存管理更加具有针对性,可以减少内存管理结构的开销,提升用户的体验,并提升内存回收效率。
应用是电子设备1-100中与用户进行交互的最小单位,具体地,电子设备1-100可以通过应用来实现对用户的需求服务。例如,用户可以通过游戏类应用玩游戏,也可以通过视频类应用看视频,还可以通过音乐类应用播放音乐。
电子设备1-100可以包括一个或多个应用,该多个即指两个或两个以上。例如,该电子设备1-100上可以安装浏览器、购物应用、游戏应用、音乐应用等应用,并且每个应用的启动以及运行都需要申请内存。在一个实施例中,电子设备1-100在应用启动时可以创建该应用对应的应用级内存控制组。
其中,本申请实施例中的第一应用可以为电子设备中的系统应用之一, 也可以为电子设备中的第三方应用之一。具体地,可以根据实际使用需求确定,本申请实施例不作限定。
举例来说,若该应用可以为浏览器,电子设备1-100可以在浏览器启动时创建浏览器所对应的应用级内存控制组memcg1,因此内核会按照该应用级内存控制组memcg1来管理该浏览器的相关内存。例如,该应用也可以为游戏应用,电子设备1-100可以在启动游戏应用时创建所述游戏应用对应的应用级内存控制组memcg2,接着内核可以按照该应用级内存控制组memcg2来管理该游戏应用的相关内存。
在一种实施方式中,用户态可以通过在控制组群(control group,cgroup)的目录下创建一个文件夹(即内存控制组),并且该文件夹以应用为单位进行创建,即该应用的进程均可以添加到该文件夹中,由此,电子设备1-100的多个应用在启动时均可以去创建一个应用级内存控制组。因此,本申请实施例中,电子设备1-100中的多个应用在启动时可以创建各自对应的应用级内存控制组,即通过以应用维度来创建应用级内存控制组。
可以理解,上述应用的列举是示例性的列举,具体可以根据实际使用情况确定,本申请实施例不作限定。
步骤S1-32,将所述应用申请到的匿名页添加至所述应用级内存控制组的最近最少使用链表中。
其中,文件页(File-backed Page)可以是磁盘上的数据在内存上的缓存,文件页所存储的数据可以在磁盘中找到。匿名页(Anonymous Page)可以是应用程序动态分配的内存页,没有对应的磁盘文件。
在启动该应用时,该应用向系统申请内存资源,内核可以将该应用申请到的匿名页添加到应用级内存控制组的最近最少使用(Least Recently Used,LRU)链表中。例如,应用可以在立即申请到匿名页时将匿名页添加到该应用对应的应用级内存控制组中。其中,最近最少使用可以是一种内存管理算法,其用于内存管理和回收控制,并用于选择最近最久未使用的页面进行回收。
以该应用是购物应用为例,若用户开启电子设备1-100中的购物应用,将为该购物应用创建对应的应用级内存控制组memcg3,并且该购物应用还将向系统申请内存资源,此时,电子设备1-100可以在该购物应用立即申请到匿名页时,将申请到的匿名页添加到应用级内存控制组memcg3中的LRU链表中进行管理。
因此,通过为所述应用(此处可以为该购物应用)创建对应的应用级内存控制组,将所述应用申请到的匿名页添加到所述应用对应的应用级内存控制组中,由此,本申请实施例可以根据所述应用级内存控制组来管理应用的匿名页,和/或根据所述应用的状态控制所述匿名页的回收顺序,和/或根据所述应用级内存控制组控制所述匿名页的回收比例,和/或控制所述应用级内存控制组所管理的应用的内存使用量。
在一个实施例中,可以根据所述应用的状态控制所述匿名页的回收顺序,即可以根据应用的状态来控制先回收的应用。具体地,本申请实施例可以根据应用的冻结状态和/或活跃状态和/或前台状态决定应用的匿名页的回收顺序。举例说明,若应用1处于冻结状态,应用2处于活跃状态,此时,可以根据应用1的冻结状态先回收所述应用1的匿名页,然后再回收所述应用2的匿名页,即状态越活越的应用,其匿名页将越后被回收。
在一个实施例中,可以根据所述应用级内存控制组控制所述匿名页的回收比例。例如,应用1在启动时创建了对应的应用级内存控制组memcg1,且应用2在启动时创建了对应的应用级内存控制组memcg2。若应用级内存控制组memcg1中控制匿名页的回收比例为60%,并且应用1中的LRU链表1包括1-100个匿名页,内存回收时只能对LRU链表1的尾部依次回收60个匿名页。若应用级内存控制组memcg2中控制匿名页的回收比例为70%,并且应用2中的LRU链表2包括1-100个匿名页,内存回收时只能对LRU链表2的尾部依次回收70个匿名页。可以理解,在一个实施例中,状态越活跃的应用,其匿名页的回收比例越低。
步骤S1-33,将所述应用申请到的文件页添加至全局最近最少使用链表中。
如上所述,该应用启动时会向系统申请内存资源,并且电子设备1-100会将申请到匿名页添加到该应用对应的应用级内存控制组中,本申请的实施例中,电子设备1-100还将所述应用申请到的文件页添加到全局LRU链表中。例如,所述应用可以在刚申请到文件页时就将该文件页添加到全局LRU链表中。
举例说明,在第一时间,用户可以打开电子设备1-100中的购物应用,电子设备1-100为该购物应用创建对应的应用级内存控制组memcg3。此时,该购物应用可以从磁盘加载so,lib等库文件,其申请到的文件页可以添加到全局的LRU链表中。在第二时间,用户可以打开电子设备1-100中的图库应用,电子设备1-100为该图库应用创建对应的应用级内存控制组memcg4,用户浏览照片时,图库应用可以从磁盘加载照片等文件,其申请到的文件页可以添加到全局的LRU链表中,在使用该应用一段时间之后,系统可以根据库文件和照片文件在该全局的LRU链表中的位置进行回收。
可以理解的是,LRU链表可以分为活跃(active)链表和非活跃(inactive)链表,内存回收的页都从非活跃链表中得到。也就是说,第一应用所对应的内存控制组中使用两个LRU链表对匿名页进行管理,文件页使用全局的两个LRU链表进行管理。
具体地,本申请的实施例中,当所述应用申请到匿名页及文件页时,将申请到的匿名页添加至所述应用对应的应用级内存控制组的活跃链表中,并将申请到的文件页添加至全局的活跃链表中。其中,当对内存控制组中的内存进行回收时,会先从非活跃链表尾部的冷数据进行回收。当非活跃链表的匿名页被引用到预设次数时,可以将匿名页从非活跃链表中摘出,放到活跃链表中。当非活跃链 表中的匿名页不足时,系统可以继续扫描活跃链表,并将一些匿名页迁移到非活跃链表中。
在一种可能实现的方式中,可以按照进程标识符(process identifier,pid)来创建内存控制组,并且每个进程id各自管理自己的LRU链表,即按照进程维度去创建内存控制组。然而,若按照进程id来创建内存控制组,将给电子设备1-100带来功耗浪费问题,从而影响用户体验。可以理解,应用是电子设备1-100中与用户交互的最小单位,从用户的角度看,应用是一个操作对象;从需求角度来看,应用是一个资源需求的承载体。因此,本申请的技术方案中,按照应用维度创建应用级内存控制组。即每个应用创建一个应用级内存控制组。采用本申请的技术方案,既可以按照应用来管理匿名页,又能实现内存、功耗及性能消耗可控,且提升了回收效率。
在一种可能实现的实施例中,每一个进程可以对应一个内存控制组,然而这样会消耗巨大的系统资源。并且文件页是磁盘文件的缓存或缓冲区域,共享性是其主要特征。所以文件页按照内存控制组来管理将会导致文件页冷热分布不均。此外,内存不足时会通过回收来获取内存,文件页冷热分布不均会导致经常回收较热的文件页,容易出现系统卡顿,严重影响用户体验。由此,本申请实施例提供的技术方案中,通过为应用创建对应的应用级内存控制组,将所述应用申请到的匿名页添加至应用级内存控制组的LRU链表中,并将应用申请到的文件页添加到一个全局LRU链表中。由此,本申请实施例能够以应用维度来管理匿名页,且内存、功耗和性能可控,同时还可以提升内存回收效率,能够减少系统卡顿,并且提升用户的体验度。
下面将在上述实施例描述的方法基础上,对本申请的存管理方法进一步详细介绍。请参阅图1-4,图1-4为本申请实施例提供的内存管理方法的另一流程示意图,该方法可以包括,但不限于以下步骤:
步骤S1-41,所述应用的进程启动时,按照所述进程所对应的应用标识创建所述应用对应的应用级内存控制组。
可以理解,进程是一个在内存中运行的应用程序,是系统进行资源分配和调度的基本单位。每个进程都有自己独立的一块内存空间。
可以理解,每个应用具有一个应用标识(例如包名),可以用于唯一标识该应用。其中应用的应用标识的获取方式可以有很多种,例如,可以通过查询应用的配置信息,用于确定该应用的应用标识,又如,可以根据应用的进程标识,用于确定该应用的应用标识。
在一个实施例中,一个应用可能包括多个进程。即所述应用可能包括多个进程,所述应用的进程启动时,会按照所述进程所对应的应用标识来创建所述第一应用对应的应用级内存控制组。例如,在一个实施例中,电子设备1-100可以按照进程所对应的包名来创建所述应用对应的应用级内存控制组。
举例说明,以所述应用为浏览器为例,假设该浏览器的进程1开始启动,若所述进程1对应的应用标识APP1对应的应用级内存控制组memcg1不存在, 则创建所述浏览器对应的应用级内存控制组memcg1。若所述进程1对应的应用标识APP1已经存在应用级内存控制组memcg1,则所述浏览器不需要重新创建所述应用级内存控制组memcg1。此时,将所述进程1添加到所述浏览器的应用级内存控制组memcg1中,并根据所述应用级内存控制组memcg1管理所述进程1,其中,可以将进程1的内存资源添加到应用级内存控制组memcg1的LRU链表中。接着,若所述浏览器的进程2启动,由于该浏览器包括进程1及进程2,因此所述进程2与所述进程1属于同一个应用标识APP1,此时所述进程2所对应的应用标识APP1已经创建了应用级内存控制组memcg1,因此,在所述进程2启动时,直接将所述进程2添加到所述浏览器对应的应用级内存控制组memcg1中,并将进程2的内存资源添加到应用级内存控制组memcg2的LRU链表中。
步骤S1-42,将所述进程的匿名页添加至所述内存控制组的最近最少使用链表中,根据最近最少使用链表对匿名页进行回收,并将所述进程的文件页添加至内存节点的全局最近最少使用链表中,根据全局最近最少使用链表对文件页进行回收。
在一个实施例中,若所述进程对应的应用标识已经创建所述应用对应的应用级内存控制组,可以将所述第一进程申请到的匿名页添加至所述内存控制组的所述LRU链表中,并将所述第一进程申请到的文件页添加至内存节点的全局LRU链表中。
举例说明,以所述第一应用为浏览器为例,假设该浏览器的进程1开始启动,由于所述网页1对应的应用标识APP1已经创建应用级内存控制组memcg1,此时,将所述进程1申请到的匿名页添加到所述浏览器的应用级内存控制组memcg1中,并将所述进程1申请到的文件页添加到所述全局的LRU链表中。接着,若所述浏览器的进程2启动,由于所述进程2与所述进程1属于同一个应用标识APP1,此时所述进程2所对应的应用标识APP1已经创建了应用级内存控制组memcg1,因此,在所述进程2启动时,直接将所述进程2申请到的匿名页添加到所述浏览器的应用级内存控制组memcg1中,因此可以根据最近最少使用链表对进程1和进程2的匿名页进行回收,并将所述进程2申请到的文件页添加到所述全局的LRU链表中,可以根据全局最近最少使用链表对进程1和进程2的文件页进行回收。
步骤S1-43,若所述进程销毁,将所述进程从所述应用级内存控制组中删除。
本申请的实施例中,若所述应用的进程销毁,可以将所述进程从所述应用的应用级内存控制组中删除。
假设所述应用包括进程1、进程2和进程3,当系统的内存资源不足而需要回收内存时,系统可以选择杀掉所述进程1和所述进程2,并同时将所述进程1和所述进程2从所述应用对应的内存控制组中删除,从而可以释放所述应用的部分匿名页及文件页,以满足系统的内存需求。
步骤S1-44,若所述应用销毁,删除所述应用级内存控制组。
本申请的实施例中,若应用销毁时,则删除该应用对应的内存控制组。举例说明,若所述应用的所述内存控制组中的全部进程销毁,则该进程的匿名页可以从应用级内存控制组的最近最少使用链表中删除并释放,该进程的文件页可以从全局最近最少使用链表中删除并释放。
例如,用户在启动浏览器后创建了3个进程,即所述浏览器可以包括进程1、进程2和进程3,并且所述进程1、所述进程2和所述进程3均添加到所述浏览器的应用级内存控制组memcg1中。当用户选择退出所述浏览器时,所述第一应用的内存控制组中的进程1、进程2和进程3销毁,并且内核将会删除所述浏览器的应用级内存控制组memcg1。此时,所述浏览器所占用的内存也可以得到释放。
请参阅图1-5,图1-5为本申请实施例提供的内存管理方法的另一流程示意图,所述内存管理方法可以包括,但不限于以下步骤:
步骤S1-51,按照白名单创建内存控制组。
本申请的实施例中,电子设备1-100启动时,可以按照白名单去创建内存控制组,因此,在白名单中的关键系统进程可以添加到该内存控制组中。
步骤S1-52,系统进程启动时,按照系统进程的进程名判断是否是白名单进程。
系统进程中可以包括:系统管理计算机个体和完成各种操作所必需的进程,例如用户开启、执行的额外程序进程。在这些进程中,有些系统进程是系统运行所需要调用的进程,如果缺少这些进程,将会影响整个系统的运行,例如关键系统服务及频繁使用的系统服务。
本申请的实施例中,系统进程或者系统服务启动时,可以按照系统的进程名来判断是否为白名单进程。举例说明,白名单中可以包括系统进程1的进程名1、系统进程2的进程2和系统进程3的进程名3。若系统进程1启动时,判断系统进程1的进程名1在白名单内,则可以确定系统进程1是白名单进程。若系统进程2启动时,判断系统进程2的进程名2在白名单内,则可以确定系统进程2是白名单进程。若系统进程4启动时,判断系统进程4的进程名4不在白名单内,则可以确定系统进程4不是白名单进程。
步骤S1-53,将系统进程添加至该内存控制组。
本申请的实施例中,若根据系统进程的进程名确定是白名单进程,则将该白名单进程添加到内存控制组中,即将一些关键的系统服务及频繁使用的系统服务添加到白名单内,避免系统误回收这些系统进程,影响用户的体验。
在一个实施例中,若确定系统进程为白名单进程,则可以将所述白名单进程的匿名页添加至内存控制组的最近最少使用链表中,并可以根据所述最近最少使用链表对所述白名单进程的匿名页进行回收,此外,还可以将所述白名单进程的文件页添加至内存节点的全局最近最少使用链表中,由此可以根据所述全局最近最少使用链表对所述白名单进程的文件页进行回收。
请参阅图1-6,图1-6是本申请实施例公开的内存管理的一个场景图。
本申请的实施例中,当电子设备1-100的应用启动时,可以按照所述应用的包名来创建所述应用的应用级内存控制组。因此,在本申请的一些实施例中,每个应用创建一个应用级内存控制组。例如,每个应用会按照对应的应用级内存控制组来进行内存的管理。
本申请的实施例中,当电子设备1-100的应用删除时,可以将所述应用的包名所对应的应用级内存控制组删除,并将所述应用的应用级内存控制组对应的内存释放。
请一并参阅图1-7,图1-7是本申请实施例公开的内存管理的一个更为具体的场景图。
下面将以应用为新闻应用为例,并结合图1-7对本申请公开的内存管理方案进行说明。
当新闻应用的进程1创建时,电子设备1-100会按照所述新闻应用的包名创建应用级内存控制组memcg1。接着,内核会将新闻应用申请到的匿名页添加到应用级内存控制组memcg1,并将所述新闻应用申请到的文件页添加到全局的LRU链表中。可以理解的是,在一个实施例中,电子设备中的其他应用,如音乐应用,也可在启动时创建对应的应用级内存控制组memcg2,并将音乐应用申请到的匿名页添加到应用级内存控制组memcg2,并将音乐应用申请到的文件页添加到全局的LRU链表中。
若新闻应用的进程2创建,将所述进程2添加到所述新闻应用的应用级内存控制组memcg1中,所述进程2申请到的匿名页添加到应用级内存控制组memcg1中,把所述进程2申请到的文件页添加到全局的LRU链表中。
若所述新闻应用的进程2销毁,将所述进程2从所述新闻应用的应用级内存控制组memcg1中删除,其中所述进程2的匿名页从所述新闻应用的应用级内存控制组memcg2中删除,同时所述进程2的文件页也从全局LRU链表中删除。
当所述新闻应用退出时,即所述新闻应用的应用级内存控制组memcg1中的这些进程销毁,并且内核将会删除所述新闻应用的应用级内存控制组memcg1。此时,所述新闻应用对应的文件页和匿名页也会被释放。
由此,采用本申请的实施例,既可以按照应用的维度来管理匿名页,又可以实现内存、功耗和性能消耗可控,以能够实现内存的精细化管理。
请参阅图1-8,图1-8是本申请实施例公开的内存管理的一个场景图。
本申请的实施例针对每个应用的应用级内存控制组定制多种参数设置接口,因此用户态可以通过参数设置,来设定应用的回收优先级、应用的最大内存使用量、应用的回收参数等。
具体来说,用户态可以通过设置应用的应用级内存控制组的参数,来对应地控制所述应用级内存控制组在内核空间中的回收顺序。例如,用户态可以根据应用的重要程度来设置对应的回收优先级,因此,当需要进行内存回收时,根据应用的回收优先级,控制所述应用级内存控制组在内核空间中的回收顺序。 具体地,用户态还可以根据应用级内存控制组的参数,控制所述应用级内存控制组在内核空间中的回收比例。
可以理解,操作系统作为计算设备的内核,独立于普通的应用程序,可以访问受保护的内存空间,也有访问底层硬件设备的权限。为了保证用户进程不直接操作内核,保证内核的安全,操作系统将寻址空间(该寻址空间可以是计算设备的内存中的一部分空间,也可以是虚拟存储空间)划分为两部分,一部分为内核空间,该内核空间是受保护的内存空间,用于存放内核的代码和数据;另一部分为用户空间,用于存放应用程序的代码和数据。当进程执行用户程序的代码时,此时进程处于用户态。对应的,当进程执行系统调用而陷入内核代码中执行时,此时进程处于内核态。用户态的进程运行于用户空间中,内核态的进程运行于内核空间中。
在一个实施例中,用户态可以通过设置应用的应用级内存控制组的参数,来控制所述应用级内存控制组在内核态的行为。例如,用户态可以根据所述应用的应用级内存控制组的参数,控制所述应用的内存使用量,如应用的最大内存使用量。
举例说明,以应用为浏览器为例,用户态可以通过接口设置所述浏览器的最大内存使用量,即可以限制每个应用的内存大小。假设所述浏览器的最大内存使用量为800Mb,但所述浏览器所使用的内存为900Mb,此时,由于所述浏览器的文件页已经磁盘备份,因此系统内核会将所述浏览器的文件页进行清理,并将所述浏览器的匿名页进行压缩,由此来满足内存需求。
作为一种可能的实现方式,在一个实施例中,可以通过提供以下的接口来对应用级内存控制组的参数进行设置:
水线设置接口:用户态可以通过水线设置接口来设定系统内存的标准水线,内核再通过回收来尽力满足这条水线,保证系统内存处于健康状态。
比例设置接口:用户态可以根据用户习惯和应用特点,通过比例设置接口设置各个应用的回收和换出比例,来控制回收和换出的量,减少应用的无效回收,增强用户体验。
重要评分值设置接口:用户态可以根据用户习惯和应用特点,通过重要评分值设置接口来设定各个应用的优先级和重要程度,决定他们在回收中的回收顺序,增强用户体验。
应用内存使用上限设置接口:用户态通过应用内存使用上限设置接口,来设置每个应用的内存使用上限,保证各个应用良性使用内存。
主动压缩接口:应用处于冻结状态时,用户态通过主动压缩接口,对应用的匿名页进行主动压缩回收,来增加系统内存,保证内存的健康。
应用内存使用状况接口:用户态通过应用内存使用状况接口,来查询系统各个应用的匿名页占用量,在执行清理和回收时作为参考。
系统状况接口:用户态通过所述系统状况接口,来查询系统的实时状态,比如系统的内存状态、CPU状态、IO状态和一些关键进程的运行状态等。
采用本申请实施例中的技术方案,当需要内存回收时,系统可以根据应用的重要程度、应用的最大内存使用量和应用的回收参数等,让文件页按照全局LRU链表的冷热情况进行回收,匿名页按照用户设定的参数回收。因此采用本申请实施例的技术方案,内存回收更加具有针对性,可以进一步地提升回收效率。
请参阅图1-9,图1-9是本申请实施例公开的一种内存管理装置的结构示意图。其中,该内存管理装置可以用于执行图1-3至图1-8中所描述的内存管理方法的步骤,具体请参见图1-3至图1-8中的相关描述,在此不再赘述。如图1-9所示,所述内存管理装置1-200可以包括:创建模块1-201、控制模块1-202及管理模块1-203。
本申请的实施例中,所述创建模块1-201用于在第一应用启动时创建所述第一应用的应用级内存控制组;
所述控制模块1-202用于将所述应用申请到的匿名页添加至所述内存控制组的最近最少使用链表中,所述控制模块1-202还用于将所述应用申请到的文件页添加至全局最近最少使用链表中。
所述创建模块1-201还可以用于在所述应用的进程启动时,按照所述进程所对应的应用标识创建所述应用对应的应用级内存控制组。
具体地,若所述进程对应的所述应用标识对应的内存控制组不存在,所述创建模块1-201创建所述应用对应的应用级内存控制组。
若所述创建模块1-201已经创建所述应用标识对应的应用级内存控制组,所述控制模块1-202将所述进程添加到所述应用级内存控制组,将所述进程的匿名页添加至所述应用级内存控制组的所述最近最少使用链表中,并将所述进程的文件页添加至所述全局最近最少使用链表中。
所述管理模块1-203用于在所述进程销毁时将所述进程从所述应用级内存控制组中删除。所述管理模块1-203还用于在所述应用的所述应用级内存控制组中的全部进程销毁时,删除所述应用级内存控制组。
在一种可能的实现方式中,所述管理模块1-203还可以用于:
根据所述应用级内存控制组管理应用的匿名页;
和/或根据所述应用的状态控制所述匿名页的回收顺序;
和/或根据所述内存控制组控制所述匿名页的回收比例;
和/或控制所述内存控制组的内存使用量。
在一些可能的实现方式中,所述控制模块1-202还用于:
当所述应用申请到所述匿名页时,所述控制模块1-202用于将所述匿名页添加至所述第一内存控制组的活跃最近最少使用链表中;
当所述应用申请到所述文件页时,所述管理模块1-203用于将所述文件页添加至全局活跃最近最少使用链表中。
当需要进行内存回收时,所述管理模块1-203用于根据所述内存控制组的第一参数,控制所述内存控制组在内核空间中的回收顺序。
当需要进行内存回收时,所述管理模块1-203用于根据所述内存控制组的第 二参数,控制所述内存控制组在内核空间中的回收比例。
所述管理模块1-203还用于根据所述内存控制组的第三参数,控制所述内存控制组在内核空间中的内存使用量。可以理解的是,上述内存管理装置中各个模块的划分仅用于举例说明,在其他的实施例中,可将内存管理装置按照需要划分为不同的模块,以完成上述内存管理装置的功能。
本申请实施例中提供的内存管理装置中的各个模块的实现,可为计算机程序的形式。该计算机程序可在电子设备或服务器上运行。在本申请实施例中各个模块的具体实现还可以对应参照图1-3至图1-8所示的方法实施例的相应描述。在图1-9所描述的内存管理装置中,可以能够以精细化地管理匿名页,并且还可以提升回收针对性,提升回收效率,从而可以避免应用卡顿,提升用户体验。具体内容可以参见上述内存管理方法的具体实施例,在此不再详述。
本申请实施例还提供了一种计算机可读存储介质。所述可读存储介质中存储有计算机指令,所述指令在计算设备上运行时,可以使得计算设备执行前述实施例提供的内存管理方法。
对于本领域的技术人员而言,显然本申请不限于上述示范性实施例的细节,而且在不背离本申请的精神或基本特征的情况下,能够以其他具体形式实现本申请。因此,只要在本申请的实质精神范围之内,对以上实施例所作的适当改变和变化都应该落在本申请要求保护的范围之内。
本申请实施例公开一种内存管理的方法、电子设备及计算机可读存储介质,可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
本申请实施例提供的内存管理的方法可以应用于电子设备,所述电子设备也可称之为用户设备(User Equipment,UE)、移动台(Mobile Station,MS)、移动终端(Mobile Terminal)等。可选地,所述电子设备可以具备无线接入网(Radio Access Nework,RAN)与一个或多个核心网进行通信的能力,例如,电子设备可以是移动电话(或称为“蜂窝”电话)、或具有移动性质的计算机等。
图2-1示出了电子设备2-100的结构示意图。
电子设备2-100可以是手机、平板电脑、桌面型计算机、膝上型计算机、手持计算机、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本,以及蜂窝电话、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)设备、虚拟现实(virtual reality,VR)设备、人工智能(artificial intelligence,AI)设备、可穿戴式设备、车载设备、智能家居设备和/或智慧城市设备,本申请实施例对该电子设备的具体类型不作特殊限制。
电子设备2-100可以包括处理器2-110,外部存储器接口2-120,内部存储器2-121,通用串行总线(universal serial bus,USB)接口2-130,充电管理模块2-140,电源管理模块2-141,电池2-142,天线2-1,天线2-2,移动通信模块2-150,无线通信模块2-160,音频模块2-170,扬声器2-170A,受话器2-170B,麦克风2-170C,耳机接口2-170D,传感器模块2-180,按键2-190,马达2-191,指示器2-192,摄像头2-193,显示屏2-194,以及用户标识模块(subscriber identification module,SIM)卡接口2-195等。其中传感器模块2-180可以包括压力传感器2-180A,陀螺仪传感器2-180B,气压传感器2-180C,磁传感器2-180D,加速度传感器2-180E,距离传感器2-180F,接近光传感器2-180G,指纹传感器2-180H,温度传感器2-180J,触摸传感器2-180K,环境光传感器2-180L,骨传导传感器2-180M等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备2-100的具体限定。在本申请另一些实施例中,电子设备2-100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器2-110可以包括一个或多个处理单元,例如:处理器2-110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器2-110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器2-110中的存储器为高速缓冲存储器。该存储器可以保存处理器2-110刚用过或循环使用的指令或数据。如果处理器2-110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器2-110的等待时间,因而提高了系统的效率。
在一些实施例中,处理器2-110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传送器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
I2C接口是一种双向同步串行总线,包括一根串行数据线(serial data line, SDA)和一根串行时钟线(derail clock line,SCL)。在一些实施例中,处理器2-110可以包含多组I2C总线。处理器2-110可以通过不同的I2C总线接口分别耦合触摸传感器2-180K,充电器,闪光灯,摄像头2-193等。例如:处理器2-110可以通过I2C接口耦合触摸传感器2-180K,使处理器2-110与触摸传感器2-180K通过I2C总线接口通信,实现电子设备2-100的触摸功能。
I2S接口可以用于音频通信。在一些实施例中,处理器2-110可以包含多组I2S总线。处理器2-110可以通过I2S总线与音频模块2-170耦合,实现处理器2-110与音频模块2-170之间的通信。在一些实施例中,音频模块2-170可以通过I2S接口向无线通信模块2-160传递音频信号,实现通过蓝牙耳机接听电话的功能。
PCM接口也可以用于音频通信,将模拟信号抽样,量化和编码。在一些实施例中,音频模块2-170与无线通信模块2-160可以通过PCM总线接口耦合。在一些实施例中,音频模块2-170也可以通过PCM接口向无线通信模块2-160传递音频信号,实现通过蓝牙耳机接听电话的功能。所述I2S接口和所述PCM接口都可以用于音频通信。
UART接口是一种通用串行数据总线,用于异步通信。该总线可以为双向通信总线。它将要传送的数据在串行通信与并行通信之间转换。在一些实施例中,UART接口通常被用于连接处理器2-110与无线通信模块2-160。例如:处理器2-110通过UART接口与无线通信模块2-160中的蓝牙模块通信,实现蓝牙功能。在一些实施例中,音频模块2-170可以通过UART接口向无线通信模块2-160传递音频信号,实现通过蓝牙耳机播放音乐的功能。
MIPI接口可以被用于连接处理器2-110与显示屏2-194,摄像头2-193等外围器件。MIPI接口包括摄像头串行接口(camera serial interface,CSI),显示屏串行接口(display serial interface,DSI)等。在一些实施例中,处理器2-110和摄像头2-193通过CSI接口通信,实现电子设备2-100的拍摄功能。处理器2-110和显示屏2-194通过DSI接口通信,实现电子设备2-100的显示功能。
GPIO接口可以通过软件配置。GPIO接口可以被配置为控制信号,也可被配置为数据信号。在一些实施例中,GPIO接口可以用于连接处理器2-110与摄像头2-193,显示屏2-194,无线通信模块2-160,音频模块2-170,传感器模块2-180等。GPIO接口还可以被配置为I2C接口,I2S接口,UART接口,MIPI接口等。
USB接口2-130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口2-130可以用于连接充电器为电子设备2-100充电,也可以用于电子设备2-100与外围设备之间传送数据。也可以用于连接耳机,通过耳机播放音频。该接口还可以用于连接其他电子设备,例如AR设备等。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,是示意 性说明,并不构成对电子设备2-100的结构限定。在本申请另一些实施例中,电子设备2-100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块2-140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块2-140可以通过USB接口2-130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块2-140可以通过电子设备2-100的无线充电线圈接收无线充电输入。充电管理模块2-140为电池2-142充电的同时,还可以通过电源管理模块2-141为电子设备供电。
电源管理模块2-141用于连接电池2-142,充电管理模块2-140与处理器2-110。电源管理模块2-141接收电池2-142和/或充电管理模块2-140的输入,为处理器2-110,内部存储器2-121,显示屏2-194,摄像头2-193,和无线通信模块2-160等供电。电源管理模块2-141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块2-141也可以设置于处理器2-110中。在另一些实施例中,电源管理模块2-141和充电管理模块2-140也可以设置于同一个器件中。
电子设备2-100的无线通信功能可以通过天线2-1,天线2-2,移动通信模块2-150,无线通信模块2-160,调制解调处理器以及基带处理器等实现。
天线2-1和天线2-2用于发射和接收电磁波信号。电子设备2-100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线2-1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块2-150可以提供应用在电子设备2-100上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块2-150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块2-150可以由天线2-1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块2-150还可以对经调制解调处理器调制后的信号放大,经天线2-1转为电磁波辐射出去。在一些实施例中,移动通信模块2-150的至少部分功能模块可以被设置于处理器2-110中。在一些实施例中,移动通信模块2-150的至少部分功能模块可以与处理器2-110的至少部分模块被设置在同一个器件中。
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器2-170A,受话器2-170B等)输出声音信号,或通过显示屏2-194显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器2-110, 与移动通信模块2-150或其他功能模块设置在同一个器件中。
无线通信模块2-160可以提供应用在电子设备2-100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块2-160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块2-160经由天线2-2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器2-110。无线通信模块2-160还可以从处理器2-110接收待发送的信号,对其进行调频,放大,经天线2-2转为电磁波辐射出去。
在一些实施例中,电子设备2-100的天线2-1和移动通信模块2-150耦合,天线2-2和无线通信模块2-160耦合,使得电子设备2-100可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。
电子设备2-100通过GPU,显示屏2-194,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏2-194和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器2-110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏2-194用于显示图像,视频等。显示屏2-194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备2-100可以包括1个或N个显示屏2-194,N为大于1的正整数。
电子设备2-100可以通过ISP,摄像头2-193,视频编解码器,GPU,显示屏2-194以及应用处理器等实现拍摄功能。
ISP用于处理摄像头2-193反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头2-193中。
摄像头2-193用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备2-100可以包括1个或N个摄像头2-193,N为大于1的正整数。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备2-100在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。电子设备2-100可以支持一种或多种视频编解码器。这样,电子设备2-100可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备2-100的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。
内部存储器2-121可以包括一个或多个随机存取存储器(random access memory,RAM)和一个或多个非易失性存储器(non-volatile memory,NVM)。
随机存取存储器可以包括静态随机存储器(static random-access memory,SRAM)、动态随机存储器(dynamic random access memory,DRAM)、同步动态随机存储器(synchronous dynamic random access memory,SDRAM)、双倍资料率同步动态随机存取存储器(double data rate synchronous dynamic random access memory,DDR SDRAM,例如第五代DDR SDRAM一般称为DDR5SDRAM)等;
非易失性存储器可以包括磁盘存储器件、快闪存储器(flash memory)。
快闪存储器按照运作原理划分可以包括NOR FLASH、NAND FLASH、3D NAND FLASH等,按照存储单元电位阶数划分可以包括单阶存储单元(single-level cell,SLC)、多阶存储单元(multi-level cell,MLC)、三阶储存单元(triple-level cell,TLC)、四阶储存单元(quad-level cell,QLC)等,按照存储规范划分可以包括通用闪存存储(英文:universal flash storage,UFS)、嵌入式多媒体存储卡(embedded multi media Card,eMMC)等。
随机存取存储器可以由处理器2-110直接进行读写,可以用于存储操作系统或其他正在运行中的程序的可执行程序(例如机器指令),还可以用于存储用户及应用程序的数据等。
非易失性存储器也可以存储可执行程序和存储用户及应用程序的数据等,可以提前加载到随机存取存储器中,用于处理器2-110直接进行读写。
外部存储器接口2-120可以用于连接外部的非易失性存储器,实现扩展电子设备2-100的存储能力。外部的非易失性存储器通过外部存储器接口2-120与处理器2-110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部的非易失性存储器中。
电子设备2-100可以通过音频模块2-170,扬声器2-170A,受话器2-170B,麦克风2-170C,耳机接口2-170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块2-170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块2-170还可以用于对音频信号编码和解码。在一些实施例中,音频模块2-170可以设置于处理器2-110中,或将音频模块2-170的部分功能模块设置于处理器2-110中。
扬声器2-170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备2-100可以通过扬声器2-170A收听音乐,或收听免提通话。
受话器2-170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备2-100接听电话或语音信息时,可以通过将受话器2-170B靠近人耳接听语音。
麦克风2-170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风2-170C发声,将声音信号输入到麦克风2-170C。电子设备2-100可以设置至少一个麦克风2-170C。在另一些实施例中,电子设备2-100可以设置两个麦克风2-170C,除了获取声音信号,还可以实现降噪功能。在另一些实施例中,电子设备2-100还可以设置三个,四个或更多麦克风2-170C,实现获取声音信号,降噪,还可以识别声音来源,实现定向录音功能等。
耳机接口2-170D用于连接有线耳机。耳机接口2-170D可以是USB接口2-130,也可以是3、5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。
压力传感器2-180A用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器2-180A可以设置于显示屏2-194。压力传感器2-180A的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器2-180A,电极之间的电容改变。电子设备2-100根据电容的变化确定压力的强度。当有触摸操作作用于显示屏2-194,电子设 备2-100根据压力传感器2-180A检测所述触摸操作强度。电子设备2-100也可以根据压力传感器2-180A的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第十压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第十压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。
陀螺仪传感器2-180B可以用于确定电子设备2-100的运动姿态。在一些实施例中,可以通过陀螺仪传感器2-180B确定电子设备2-100围绕三个轴(即,x,y和z轴)的角速度。陀螺仪传感器2-180B可以用于拍摄防抖。示例性的,当按下快门,陀螺仪传感器2-180B检测电子设备2-100抖动的角度,根据角度计算出镜头模组需要补偿的距离,让镜头通过反向运动抵消电子设备2-100的抖动,实现防抖。陀螺仪传感器2-180B还可以用于导航,体感游戏场景。
气压传感器2-180C用于测量气压。在一些实施例中,电子设备2-100通过气压传感器2-180C测得的气压值计算海拔高度,辅助定位和导航。
磁传感器2-180D包括霍尔传感器。电子设备2-100可以利用磁传感器2-180D检测翻盖皮套的开合。在一些实施例中,当电子设备2-100是翻盖机时,电子设备2-100可以根据磁传感器2-180D检测翻盖的开合。进而根据检测到的皮套的开合状态或翻盖的开合状态,设置翻盖解锁等特性。
加速度传感器2-180E可检测电子设备2-100在各个方向上(一般为三轴)加速度的大小。当电子设备2-100静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。
距离传感器2-180F,用于测量距离。电子设备2-100可以通过红外或激光测量距离。在一些实施例中,拍摄场景,电子设备2-100可以利用距离传感器2-180F测距以实现快速对焦。
接近光传感器2-180G可以包括例如发光二极管(LED)和光检测器,例如光电二极管。发光二极管可以是红外发光二极管。电子设备2-100通过发光二极管向外发射红外光。电子设备2-100使用光电二极管检测来自附近物体的红外反射光。当检测到充分的反射光时,可以确定电子设备2-100附近有物体。当检测到不充分的反射光时,电子设备2-100可以确定电子设备2-100附近没有物体。电子设备2-100可以利用接近光传感器2-180G检测用户手持电子设备2-100贴近耳朵通话,以便熄灭屏幕达到省电的目的。接近光传感器2-180G也可用于皮套模式,口袋模式解锁与锁屏。
环境光传感器2-180L用于感知环境光亮度。电子设备2-100可以根据感知的环境光亮度自适应调节显示屏2-194亮度。环境光传感器2-180L也可用于拍照时调节白平衡。环境光传感器2-180L还可以与接近光传感器2-180G配合,检测电子设备2-100是否在口袋里,以防误触。
指纹传感器2-180H用于获取指纹。电子设备2-100可以利用获取的指纹 特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。
温度传感器2-180J用于检测温度。在一些实施例中,电子设备2-100利用温度传感器2-180J检测的温度,执行温度处理策略。例如,当温度传感器2-180J上报的温度超过阈值,电子设备2-100执行降低位于温度传感器2-180J附近的处理器的性能,以便降低功耗实施热保护。在另一些实施例中,当温度低于另一阈值时,电子设备2-100对电池2-142加热,以避免低温导致电子设备2-100异常关机。在其他一些实施例中,当温度低于又一阈值时,电子设备2-100对电池2-142的输出电压执行升压,以避免低温导致的异常关机。
触摸传感器2-180K,也称“触控器件”。触摸传感器2-180K可以设置于显示屏2-194,由触摸传感器2-180K与显示屏2-194组成触摸屏,也称“触控屏”。触摸传感器2-180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏2-194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器2-180K也可以设置于电子设备2-100的表面,与显示屏2-194所处的位置不同。
骨传导传感器2-180M可以获取振动信号。在一些实施例中,骨传导传感器2-180M可以获取人体声部振动骨块的振动信号。骨传导传感器2-180M也可以接触人体脉搏,接收血压跳动信号。在一些实施例中,骨传导传感器2-180M也可以设置于耳机中,结合成骨传导耳机。音频模块2-170可以基于所述骨传导传感器2-180M获取的声部振动骨块的振动信号,解析出语音信号,实现语音功能。应用处理器可以基于所述骨传导传感器2-180M获取的血压跳动信号解析心率信息,实现心率检测功能。
按键2-190包括开机键,音量键等。按键2-190可以是机械按键。也可以是触摸式按键。电子设备2-100可以接收按键输入,产生与电子设备2-100的用户设置以及功能控制有关的键信号输入。
马达2-191可以产生振动提示。马达2-191可以用于来电振动提示,也可以用于触摸振动反馈。例如,作用于不同应用(例如拍照,音频播放等)的触摸操作,可以对应不同的振动反馈效果。作用于显示屏2-194不同区域的触摸操作,马达2-191也可对应不同的振动反馈效果。不同的应用场景(例如:时间提醒,接收信息,闹钟,游戏等)也可以对应不同的振动反馈效果。触摸振动反馈效果还可以支持自定义。
指示器2-192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。
SIM卡接口2-195用于连接SIM卡。SIM卡可以通过插入SIM卡接口2-195,或从SIM卡接口2-195拔出,实现和电子设备2-100的接触和分离。电子设备2-100可以支持1个或N个SIM卡接口,N为大于1的正整数。SIM卡接口2-195可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM 卡接口2-195可以同时插入多张卡。所述多张卡的类型可以相同,也可以不同。SIM卡接口2-195也可以兼容不同类型的SIM卡。SIM卡接口2-195也可以兼容外部存储卡。电子设备2-100通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备2-100采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备2-100中,不能和电子设备2-100分离。电子设备2-100的软件系统可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。本申请实施例以分层架构的Android系统为例,示例性说明电子设备2-100的软件结构。
图2-2是本申请实施例的电子设备2-100的软件结构框图。
分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将Android系统分为四层,从上至下分别为应用程序层,应用程序框架层,安卓运行时(Android runtime)和系统库,以及内核层。
应用程序层可以包括一系列应用程序包。
如图2-2所示,应用程序包可以包括相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息等应用程序。
应用程序框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架。应用程序框架层包括一些预先定义的函数。
如图2-2所示,应用程序框架层可以包括窗口管理器,内容提供器,视图系统,电话管理器,资源管理器,通知管理器等。
窗口管理器用于管理窗口程序。窗口管理器可以获取显示屏大小,判断是否有状态栏,锁定屏幕,截取屏幕等。
内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。
视图系统包括可视控件,例如显示文字的控件,显示图片的控件等。视图系统可用于构建应用程序。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。
电话管理器用于提供电子设备2-100的通信功能。例如通话状态的管理(包括接通,挂断等)。
资源管理器为应用程序提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。
通知管理器使应用程序可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在系统顶部状态栏的通知,例如后台运行的应用程序的通知,还可 以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息,发出提示音,电子设备振动,指示灯闪烁等。
Android Runtime包括核心库和虚拟机。Android runtime负责安卓系统的调度和管理。
核心库包含两部分:一部分是java语言需要调用的功能函数,另一部分是安卓的核心库。
应用程序层和应用程序框架层运行在虚拟机中。虚拟机将应用程序层和应用程序框架层的java文件执行为二进制文件。虚拟机用于执行对象生命周期的管理,堆栈管理,线程管理,安全和异常的管理,以及垃圾回收等功能。
系统库可以包括多个功能模块。例如:表面管理器(surface manager),媒体库(Media Libraries),三维图形处理库(例如:OpenGL ES),2D图形引擎(例如:SGL)等。
表面管理器用于对显示子系统进行管理,并且为多个应用程序提供了2D和3D图层的融合。
媒体库支持多种常用的音频,视频格式回放和录制,以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:MPEG4,H、264,MP3,AAC,AMR,JPG,PNG等。
三维图形处理库用于实现三维图形绘图,图像渲染,合成,和图层处理等。
2D图形引擎是2D绘图的绘图引擎。
内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。
下面结合捕获拍照场景,示例性说明电子设备2-100软件以及硬件的工作流程。
当触摸传感器2-180K接收到触摸操作,相应的硬件中断被发给内核层。内核层将触摸操作加工成原始输入事件(包括触摸坐标,触摸操作的时间戳等信息)。原始输入事件被存储在内核层。应用程序框架层从内核层获取原始输入事件,识别该输入事件所对应的控件。以该触摸操作是触摸单击操作,该单击操作所对应的控件为相机应用图标的控件为例,相机应用调用应用框架层的接口,启动相机应用,进而通过调用内核层启动摄像头驱动,通过摄像头2-193捕获静态图像或视频。
基于上述电子设备2-100的硬件结构,提出本申请内存管理方法的各个实施例。
本申请提供一种内存管理方法。
请参阅图2-3,图2-3是本申请实施例提供的内存管理方法的流程图。所述内存管理方法的执行主体可以为电子设备2-100,所述内存管理方法可以包括但不限于以下步骤:
步骤S2-31,电子设备在应用启动时,创建所述应用的内存控制组,设 置所述内存控制组的重要评分值为预设重要评分值。
其中,内存控制组用于管理应用对应的内存单元,可以以对象的形式创建在内存中,包括用于管理内存单元的方法(例如控制内存单元的回收参数等)以及描述内存资源的相关信息。例如,所述相关信息可以包括当前内存控制组的物理内存占用情况,和当前内存控制组的内存活跃状态等,内存单元可以以页为单位,一页的大小可以是4KB字节。本申请提出一种基于应用级别的内存控制组,可以在应用启动时创建,可以包括所属应用的进程的内存信息,并根据内存信息对所属应用的进程进行管理,可以使得内存管理更具有针对性,减少内存管理结构的开销,提升用户的体验,并提升内存回收效率。
电子设备2-100可以在应用启动时创建所述应用的内存控制组。电子设备2-100可以通过应用来实现对用户的需求服务。例如,用户可以通过游戏类应用玩游戏,也可以通过视频类应用看视频,还可以通过音乐类应用播放音乐。举例来说,所述应用可以为浏览器,电子设备2-100可以在浏览器启动时创建浏览器的内存控制组1,因此内核可以按照该内存控制组1来管理该浏览器的相关内存。例如,所述应用也可以为游戏应用,电子设备2-100在启动游戏应用时创建所述游戏应用对应的内存控制组2,接着内核可以按照该内存控制组2来管理该游戏应用的相关内存。
因此,电子设备2-100的多个应用在启动时可以创建各自对应的内存控制组。在一种实施方式中,用户态可以通过在控制组群(control group,cgroup)的目录下创建一个文件夹(即内存控制组),并且该文件夹以应用为单位进行创建,即该应用的所有进程均可以添加到该文件夹中,由此,电子设备2-100的多个应用在启动时均可以去创建一个内存控制组。其中,本申请实施例中的应用可以为电子设备2-100中的系统应用之一,也可以为电子设备中的第三方应用之一。具体地,可以根据实际使用需求确定,本申请实施例不作限定。可以理解,上述应用的列举是示例性的列举,具体可以根据实际使用情况确定,本申请实施例对此不作限定。
在一种实施方式中,电子设备2-100的第十应用启动时,系统将所述第十内存控制组的重要评分值(important score)设置第十预设值。
作为一种实现方式,多个应用具有其各自的预设重要评分值,在应用启动时赋予了多个应用相应的预设重要评分值。其中,重要评分值可以用于表征应用的用户关注程度。重要评分值越小,应用的用户关注程度越高。例如,应用1的重要评分值高于应用2的重要评分值,则可以确定应用2的用户关注程度高于应用1。
在具体的实现过程中,内核态可以提供一个内存控制组的第十接口,其中该第十接口可以用于配置每个内存控制组的重要评分值。其中,内核态进程运行于内核空间中,对应的,当进程执行系统调用而陷入内核代码中执行时,进程处于内核态。
作为本申请的一种示例,假设用户启动电子设备2-100的聊天应用,系统将为该聊天应用创建内存控制组,并设置内存控制组初始的重要评分值。聊天软件在启动后会处于活跃状态,因此电子设备2-100可以根据该聊天软件的活跃时间比例和应用使用的频繁程度等,来对应更新该聊天软件的重要评分值。可以理解,在不同的场景中,所述聊天应用具有不同的状态,所述内存控制组可以具有不同的重要评分值。因此,电子设备2-100可以根据各个应用的状态对应更新各自内存控制组的重要评分值。
在一种可能的设计中,内存控制组的设置可以通过如下的具体实现方式:
1、当应用处于前台时,系统可以将该应用的内存控制组的重要评分值设置为前台默认值。其中,作为示例,所述前台默认值可以为0,也可以为其它值。可以理解,应用处于前台状态即可以为用户可见的且可以与用户交互的应用的状态。
2、当应用处于后台时,系统可以将该应用的内存控制组的重要评分值设置为后台默认值。其中,作为示例,所述后台默认值可以为300,也可以为其它值。可以理解,应用处于后台状态即可以为用户不可见且应用仍处于运行状态。
3、当应用处于活跃状态时,可以通过该应用的活跃时间比例和使用频繁程度调整该应用的内存控制组的重要评分值。可以理解,应用的活跃状态可以为前台活跃状态和后台活跃状态。
4、当应用处于冻结状态时,可以通过该应用的冻结解冻次数和内存占用大小来调整该应用的内存控制组的重要评分值。可以理解,应用的冻结状态可以为应用处于后台且用户不可见状态,应用的进程不能申请内存且不能进行活动的状态。
步骤S2-32,内存控制组链表按照多个内存控制组的重要评分值,对多个内存控制组进行排序。
可以理解,所述内存控制组链表用于管理至少一个内存控制组,即可以根据多个内存控制组的重要评分值对多个内存控制组进行排序。所述内存控制组链表根据重要评分值的高低可以对应用的内存控制组进行递减排序,即重要评分值越高的内存控制组,在所述内存控制组链表中的位置越靠前。
举例说明,电子设备2-100可以开启应用1和应用2,应用1在开启时创建了内存控制组1,应用2在开启时创建了内存控制组2。假设内存控制组1和内存控制组2初始的重要评分值均为2-200,随着应用1和应用2的状态变化,内存控制组1和内存控制组2的重要评分值均会对应变化。例如,用户在某一时刻将应用1切换到了前台运行,而将应用2切换到了后台运行。此时,内存控制组1的重要评分值可以更新为0,并且内存控制组2的重要评分值可以更新为300。因此,内存控制组链表按照内存控制组1和内存控制组2的重要评分值进行排序。
在一个实施例中,当应用的状态发生变化时,内存控制组的重要评分值 可以对应进行更新,并且在内存控制组的重要评分值更新后,所述内存控制组链表可以更新内存控制组的排序。
如图2-6中所示,为内存控制组链表根据重要评分制对多个内存控制组进行排序的示意图。
下面以应用1的内存控制组1、应用2的内存控制组2、应用3的内存控制组3和应用4的内存控制组4为例进行说明,假设内存控制组1的重要评分值为900,内存控制组2的重要评分值为500,内存控制组3的重要评分值为2-200,内存控制组4的重要评分值为0,则所述内存控制组链表将所述内存控制组1放在头部位置,接着后面的排序分别为内存控制组2、内存控制组3,并将所述内存控制组4放在尾端位置。
步骤S2-33,当需要进行内存回收时,回收机制可以根据所述内存控制组链表中多个内存控制组的排序,根据多个内存控制组的排序进行内存回收。
首先,系统对内存回收的具有判断条件,即确定何时进行内存回收,可以在系统状态进入低内存时被动回收,即可以采用系统设定的回收机制,也可以用户调用接口主动回收,即可以是用户创建的回收机制。
当触发内存回收时,回收机制则可以根据所述内存控制组链表中的多个内存控制组的排序,即按照内存控制组链表中多个内存控制组的重要评分值的高低,对多个内存控制组进行内存回收。可以理解,回收机制可以采用kswapd回收机制或者direct-reclaim回收机制,也可以是其他任何形式存在的针对内存回收的机制,其中,回收机制可以是内核在系统的空闲内存低于阈值时进行回收内存的一种机制,内核上已有的机制可以包括kswapd回收机制、direct-reclaim回收机制等。
内存回收时可以将应用所占的内存进行释放,即可以将内存控制组链表中内存控制组的匿名页(anonymous page)进行回收,尽量减少内存的占用,并将占用内存的数据换出到外部存储中,以此来进行内存回收。其中匿名页可以是没有文件背景的页,如堆,栈,数据段等,其并不是以文件形式存在的。
在一个实施方式中,在内存回收之前,可以根据系统的内存需求设定目标回收量。接着,回收机制根据目标回收量进行内存回收。若系统的内存资源不足,当触发内存回收时,回收机制将会按照内存控制组链表中多个内存控制组的重要评分值的高低,对多个内存控制组中的匿名页按照压缩比例进行压缩,并将压缩后的数据放入交换区中,并释放交换区中这些数据所占的空间。若所述交换区的数据达到预设水线,回收机制将按照换出比例将所述数据从所述交换区换出到外部存储中,以此来实现内存回收。其中,所述预设水线可以是所述交换区中已压缩的数据量与交换空间大小的比值,所述预设水线可以是控制交换区的容量上限。
举例说明,若系统的内存资源不足设定一个目标回收量(例如可以为50Mb),电子设备2-100运行时开启了3个应用,具体为应用1、应用2和 应用3,应用1的内存控制组1包括压缩比例1及换出比例1,应用2的内存控制组2包括压缩比例2及换出比例2,应用3的内存控制组3包括压缩比例3及换出比例3。当需要内存回收时,回收机制根据压缩比例1对内存控制组1中的匿名页1进行压缩,回收机制根据压缩比例2对内存控制组2中的匿名页2进行压缩,回收机制还根据压缩比例3对内存控制组3中的匿名页3进行压缩。由此,通过对内存控制组1、内存控制组2、内存控制组3的匿名页进行压缩,共压缩第十压缩量(例如可以为30Mb)。回收机制还将压缩后的数据放入交换区中,直至交换区的数据量达到预设水线,其中所述数据可以是进程中的一些数据段及堆栈等。回收机制可以根据换出比例将数据从所述交换区换出到外部存储中,共换出第十换出量(例如可以为20Mb)。因此,回收机制回收的内存可以满足系统的内存需求。
在一种可能实施例中,当需要内存回收时,系统可以按顺序从内存控制组中回收匿名页。内存控制组是按照创建时间来进行排序,即越先被创建的内存控制组越有可能被回收。按照这个顺序回收并不合理,有些顺序靠前的内存控制组,其被回收后可能会立刻被内存控制组对应的应用使用,这使得匿名页在短时间内会被回收和被使用之间切换而造成波动。然而当颠簸率较高时,系统内存回收效率低下,容易进入低内存状态,造成卡顿。由此,本申请实施例提供的内存管理方法中,在系统内存资源不足时实现内存的回收,提升系统的流畅性。
可以理解的是,在一种可能实现的方式中,内存控制组在每一状态下,其匿名页的冷热程度不相同,因此匿名页可被回收部分的比例并不相等。例如,有些应用在后台时无任何操作,其匿名页可以完全被回收,而有一些应用则会在后台处理消息,仅有部分匿名页可被回收,如果其被回收,则会马上重新申请内存,这使得匿名页短时间内在被回收和被使用之间切换,造成波动,由此会抬高匿名页的颠簸率。
然而上述的实现方式中可能存在如下问题:一方面,由于应用的冷启动顺序并不能代表用户对应用的关注度,如若按照这种顺序回收匿名页,颠簸率较高且回收效率低;另一方面,在应用关注度相同的情况下,按照内存控制组的匿名页大小排序确实能够使得回收流程提前退出,降低过回收率。然而,通常情况下的用户关注度与内存控制组的匿名页大小并不相关,所以这种排序同样会抬高匿名页颠簸率。
因此,本申请实施例提供的一种内存管理方法,可以通过系统设置内存控制组的重要评分值为预设值,并根据应用的状态更新内存控制组的重要评分值,该重要评分值越小,该应用的用户关注度越高,由此内存控制组链表可以根据多个内存控制组的重要评分值对多个内存控制组进行排序。当需要进行内存回收时,回收机制根据所述内存控制组链表中多个内存控制组的排序,对多个第十内存控制组进行内存回收。本申请的实施例能够根据应用的运行状态,对应用的内存控制组的回收顺序进行调整,提升内存的回收效率, 扩大等效内存,进而可以提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
请参阅图2-4,在本申请的一些实施例中,在上述步骤S2-33中,即回收机制根据所述内存控制组链表中的多个内存控制组的排序,对多个内存控制组进行内存回收,可以包括如下的具体步骤:
步骤S2-41,回收机制按照压缩比例对所述内存控制组进行内存压缩,并将压缩后的数据放入交换区中。
作为一种实现方式,电子设备2-100将为应用的内存控制组设置了一个压缩比例,并且在应用启动时将所述压缩比例设为预设压缩比例。其中,所述压缩比例用于表征交换区和外部存储的数据量总和与内存、交换区和外部存储的数据量的总和之间的比值。可以理解,压缩上限可以由所述压缩比例控制。在一些实施方式中,电子设备2-100可以根据应用的状态更新内存控制组的压缩比例。在具体的实现过程中,上层可以提供一个内存控制组的第十一接口,其中该第十一接口可以用于配置每个内存控制组的压缩比例。
因此,在系统内存资源不足时,回收机制开始进行内存回收。即,回收机制遍历所述内存控制组链表,对内存控制组的内存数据进行扫描,并将按照压缩比例对所述内存控制组进行内存压缩,将压缩后的数据放入交换区中,并释放交换区中这些数据所占的空间。其中压缩上限由所述压缩比例控制。
步骤S2-42,若所述交换区的数据达到预设水线,回收机制按照换出比例将所述数据从所述交换区换出到外部存储。
若交换区的数据量达到预设水线,例如,交换区的数据量达到总的内存量的30%,回收机制将会按照换出比例将数据从所述交换区换出到外部存储(比如磁盘)。其中,所述换出比例用于表征已换出的数据量与交换区和外部存储的数据量的总和之间的比值。换出上限由所述换出比例控制。
可以理解的是,在一些可能实现的方式中,每一内存控制组在不同状态下,其内存活跃程度并不一样,例如有些应用在后台处理网络消息或者处于休眠状态时,这些应用的内存冷热比例是不一样的。然而上述的实现方式中可能存在如下问题:若按照固定的比例来回收内存,内存的回收效率较低,并且功耗消耗也非常大。
因此,本申请实施例提供的内存管理方法,当应用的状态发生改变时,应用所对应内存控制组的重要评分值、压缩比例和换出比例会进行对应的调整,内存控制组链表也会修改内存控制组的顺序。因此本申请实施例提供的内存管理方法中,可以避免因内存控制组排序及回收比例不当而导致的内存回收的准确性不足问题,从而进一步提升用户体验。
采用本申请的实施例,与现有的内存压缩技术相比,提高了有效压缩比,可以减少错误压缩和过压缩带来的内存颠簸。
如图2-5所示,内存可以包括正常使用区及交换区,当系统内存资源不足时,回收机制开始进行内存回收。回收机制开始对正常使用区中的数据进 行压缩,并将压缩后的数据放入交换区中。若交换区中的数据量达到水线,则将交换区中的数据换出到外部存储中。
由此,本申请实施例提供的内存管理方法中,在系统内存资源不足时可以实现内存的回收,提升系统的流畅性。
请参阅图2-6,图2-6是本申请实施例公开的内存控制组链表的一个结构示意图。如图2-6所示,内存控制组链表中可以包括多个依次排序的内存控制组。
举例来说,电子设备运行时开启了4个应用,具体为应用1、应用2、应用3和应用4。应用1、应用2、应用3和应用4启动时会向系统申请内存资源,由此电子设备可以将申请到匿名页添加到应用对应的内存控制组中。即应用1启动时创建内存控制组1,并将申请到的匿名页1添加到内存控制组1,应用2启动时创建内存控制组2,并将申请到的匿名页2添加到内存控制组2,应用3启动时创建内存控制组3,并将申请到的匿名页3添加到内存控制组3,应用4启动时创建内存控制组4,并将申请到的匿名页4添加到内存控制组4。
其中,上层(即应用层)可以根据应用的状态更新应用所对应内存控制组的重要评分值、压缩比例和换出比例。例如,上层可以根据应用1的状态实时地更新内存控制组1的重要评分值1、压缩比例1和换出比例1,上层也可以根据应用2的状态实时地更新内存控制组2的重要评分值2、压缩比例2和换出比例2,上层还可以根据应用3的状态实时地更新内存控制组3的重要评分值3、压缩比例3和换出比例3。
如上所述,重要评分值1大于重要评分值2,重要评分值2大于重要评分值3。因此,根据内存控制组链表中内存控制组的排序,回收机制可以优先回收内存控制组1中的匿名页1,接着回收内存控制组2中的匿名页2,再回收内存控制组3中的匿名页3。具体地,回收机制可以优先压缩内存控制组1中的匿名页1,接着压缩内存控制组2中的匿名页2,再压缩内存控制组3中的匿名页3。回收机制优先将内存控制组1中的数据从交换区中换出至外部存储,接着再将内存控制组2的数据从交换区中换出至外部存储,再将内存控制组3中的数据从交换区中换出至外部存储。
当需要内存回收时,回收机制可以按照内存控制组链表中多个内存控制组的重要评分值的高低,对多个内存控制组进行内存回收。即,回收机制可以根据应用的重要评分值在内存控制组链表中的顺序,控制应用的内存控制组的压缩顺序和换出顺序。回收机制可以根据压缩比例1对内存控制组1中的匿名页1进行压缩,回收机制根据压缩比例2对内存控制组2中的匿名页2进行压缩,回收机制还根据压缩比例3对内存控制组3中的匿名页3进行压缩。回收机制还可以将压缩后的数据放入交换区中,直至交换区的数据量达到预设水线,回收机制可以根据换出比例将数据从所述交换区换出到外部存储中。举例说明,当交换区的数据量达到预设水线时,回收机制可以按照 换出比例1将内存控制组1中的数据从交换区中换出至外部存储,回收机制还可以按照换出比例2将内存控制组2的数据从交换区中换出至外部存储。
请参阅图2-7,图2-7为电子设备2-100中的应用启动时,内存控制组链表中的内存控制组的排序变化示意图。
本申请实施例中,电子设备2-100启动的应用以新闻软件为例进行说明。
可以看出,在新闻软件启动之前,在所述内存控制组链表中依次递减的排序为内存控制组1、内存控制组2、内存控制组3、内存控制组4、内存控制组5、内存控制组6。
新闻软件启动时,新闻软件中内存控制组的重要评分值为300,其压缩比例为30,此时,电子设备中的应用3的内存控制组3的重要评分值为900,应用4的内存控制组3的重要评分值为2-200,因此,所述内存控制组链表根据该新闻软件的内存控制组的重要评分值,将该新闻软件的内存控制组排序在内存控制组3与内存控制组4之间。
当新闻软件为活跃状态时,此时,上层及时地更新所述新闻软件的内存控制组的重要评分值及压缩比例,该新闻软件的内存控制组的重要评分值更新为2-200,其压缩比例更新为20。此时,应用4的内存控制组4的重要评分值为2-200,应用5的内存控制组5的重要评分值为2-100,由于此时新闻软件为活跃状态,因此,所述内存控制组链表根据该新闻软件的内存控制组的重要评分值,将该新闻软件的内存控制组排序在内存控制组4与内存控制组5之间。
当新闻软件切到后台时,此时,上层会及时地更新所述新闻软件的内存控制组的重要评分值及压缩比例,该新闻软件的内存控制组的重要评分值更新为900,其压缩比例更新为90。此时,应用3的内存控制组3的重要评分值为900,应用4的内存控制组4的重要评分值为2-200,因此,所述内存控制组链表根据该新闻软件的内存控制组的重要评分值,将该新闻软件的内存控制组排序在内存控制组3与内存控制组4之间。
当新闻软件被冻结时,此时,上层会及时地更新所述新闻软件的内存控制组的重要评分值及压缩比例,该新闻软件的内存控制组的重要评分值更新为2-1000,其压缩比例更新为2-100。此时,应用2的内存控制组2的重要评分值为2-1000,应用3的内存控制组4的重要评分值为900,因此,所述内存控制组链表根据该新闻软件的内存控制组的重要评分值,将该新闻软件的内存控制组排序在内存控制组2与内存控制组3之间。
当新闻软件再次切到前台时,此时,上层会及时地更新所述新闻软件的内存控制组的重要评分值及压缩比例,该新闻软件的内存控制组的重要评分值更新为0,其压缩比例更新为0。此时,应用6的内存控制组6的重要评分值为0,因此,所述内存控制组链表根据该新闻软件的内存控制组的重要评分值,将该新闻软件的内存控制组排序在内存控制组6的后面。
本申请实施例的技术方案中,应用启动时,对应内存控制组随之创建, 可以通过系统设置初始的重要评分值、压缩比例及换出比例。应用启动后处于活跃状态,根据其活跃时间比例、使用频繁程度调整重要评分值、压缩比例及换出比例。当应用切到后台时,可以按照后台时间比例及后台事件策略调整重要评分值、压缩比例及换出比例。当应用在后台被冻结时,通过冻结解冻次数、内存占用大小等因素调整重要评分值、压缩比例及换出比例。当应用再次被切到前台,重要评分值调低,压缩比例及换出比例可以同步调整。
当应用状态发生改变时,应用所对应内存控制组的重要评分值、压缩比例和换出比例会对应调整,所述内存控制组链表亦将会调整多个内存控制组的排序。
请参阅图2-8,图2-8为对内存控制组链表中的多个内存控制组进行内存回收的示意图。
本申请实施例中,电子设备启动的第十应用以新闻软件为例进行说明。
所述新闻软件切换到前台运行,所述新闻软件的内存控制组的重要评分值为0,在所述内存控制组链表中依次递减的排序为内存控制组1、内存控制组2、内存控制组3、内存控制组4、内存控制组5、内存控制组6和新闻软件的内存控制组。
其中,内存控制组1重要评分值为2-1000,其压缩比例为2-100。内存控制组2重要评分值为2-1000,其压缩比例为2-100。内存控制组3重要评分值为900,其压缩比例为90。内存控制组4重要评分值为2-200,其压缩比例为20。内存控制组5重要评分值为2-100,其压缩比例为10。内存控制组6重要评分值为0,其压缩比例为0。
因此,在需要内存回收时,回收机制可以按照内存控制组链表中多个内存控制组的顺序遍历多个内存控制组,重要评分值高的内存控制组优先被扫描,即优先回收内存控制组1、内存控制组2和内存控制组3的内存。例如,对于重要评分值高的内存控制组,回收机制可以优先对该内存控制组进行压缩和换出。即,内存控制组1的回收到2-100%停止,内存控制组2的回收到2-100%即停止,内存控制组3的回收到90%停止,内存控制组4的回收到20%即停止。由于扫描到足够页数时停止扫描,因此,内存控制组5没有被回收。内存控制组5和内存控制组6的重要评分值均为0,则不回收内存控制组5和内存控制组6的内存。
请参阅图2-9,图2-9为本申请实施例公开的一种内存压缩方法的流程图。所述方法包括以下步骤:
步骤S2-91,计算第十压缩量。
在一种实施方式中,所述第十压缩量即为此次内存回收的目标压缩量。
步骤S2-92,确定第十一压缩量是否小于第十压缩量。若第十一压缩量小于第十压缩量,则进入步骤S2-93,否则结束。
其中,第十一压缩量即为回收机制对各个应用的内存控制组的已压缩量,并将已压缩量与目标压缩量进行比较,以确定已压缩量是否满足要求。
步骤S2-93,确定内存控制组链表上还有未遍历应用。若内存控制组链表上还有未遍历应用,则进入步骤S2-94,否则结束。
在一种实施方式中,当第十一压缩量小于第十压缩量时,即表明已压缩的内存还没有达到要求,因此,需要再次确认内存控制组链表上是否还有未遍历的应用。
步骤S2-94,选择下一个应用。
当第十一压缩量小于第十压缩量时,即已压缩的内存还没有达到目标压缩量,可以选择下一个没有遍历的应用。
步骤S2-95,按照应用的压缩比例来计算压缩量。
本申请的实施例中,根据该应用的内存控制组的压缩比例,以对该应用的内存控制组的匿名页进行压缩。
步骤S2-96,将数据压缩到交换区中。
在一种实施方式中,所述数据可以包括进程中的相关数据段及堆栈等。
步骤S2-97,再次统计压缩量。
采用本申请的实施例,内存压缩时,按照内存控制组链表中的内存控制组的顺序,优先遍历回收率高的应用,当压缩总量达到目标压缩量时,退出遍历。对于被遍历的到的应用,若其单应用压缩量占比达到其压缩比例,则终止对该应用的压缩,转而压缩内存控制组链表中的下一个应用。与现有的内存压缩技术相比,本申请实施例的技术方案提高了有效压缩比,有效减少了错误压缩和过压缩带来的内存颠簸。
请参阅图2-10,图2-10为本申请实施例公开的一种内存换出方法的流程图。所述方法包括以下步骤:
步骤S2-101,输入第十换出量。
本申请实施例中,所述第十换出量即为此次内存回收的目标换出量。
步骤S2-102,将第十一换出量设置为0。步骤S2-103,确认第十换出量是否大于第十一换出量。若是,则进入步骤S2-104,否则结束。
本申请的实施例中,第十一换出量即为回收机制对各个应用的内存控制组的已压缩量,并将已换出量与目标换出量进行比较,以确定已换出量是否达到目标换出量。
步骤S2-104,确认还有未遍历应用。若还有未遍历应用,则进入步骤S2-105,否则结束。
步骤S2-105,按照内存控制组链表中的排序结果选择下一个应用。
在一个实施方式中,当已换出量没有达到目标换出量时,此时,将会按照内存控制组链表中的排序结果,来选择下一个应用
步骤S2-106,按应用换出比例计算换出量。
步骤S2-107,按最近最少使用链表进行换出数据。
可以理解,在一种实施方式中,所述数据可以包括进程中的相关数据段及堆栈等。
步骤S2-108,统计第十一换出量。
本申请的实施例中,可以采用外部存储来扩展内部存储空间,有效提高了等效内存的大小。
本申请的实施例中,可以将已换出量进行累加,进而可以将已换出量统计到第十一换出量中。
本申请的实施例中,内存换出时,按照所述内存控制组链表中内存控制组的排序,尽可能地选择非活跃应用的数据进行换出,使用最近最少使用(Least Recently Used,LRU)算法对交换区中数据进行冷热分离,访问较频繁的数据放在LRU链表的头部,不频繁的数据放在LRU链表的尾部。换出时,从LRU链表的尾部开始,选择较冷数据换出,使得热数据尽可能保留在交换区中,保证应用性能的同时提高内存使用效率。其中,最近最少使用(Least Recently Used,LRU)可以是内存管理的一种算法,是内核用于内存管理和回收控制的重要链表,每个LRU链表可能属于不同的内存控制组。
本申请的实施例中,当应用被使用时进行批量换入,将应用在外部存储的数据按访问频度由高到低读入交换区中,避免应用运行过程中需要使用交换区中的数据而产生频繁的IO,提高应用的流畅性。
因此,采用本申请实施例的技术方案,与现有内存交换技术相比,提高了IO效率,减少了IO数据量和次数,从而实现更高效的内存交换,同时降低内存交换对存储设备的寿命损耗。
在一些可能实现的方式中,可以按照用户启动应用的顺序去管理内存控制组,但是这种做法会导致匿名页颠簸率过高,回收效率较低。采用本申请实施例提供的技术方案,可以对每个应用的内存控制组的回收顺序作出调整,使得内存回收更加精准和高效,同时做到功耗和性能消耗可控。
请参阅图2-11,图2-11是本申请实施例公开的一种内存管理装置的结构示意图。其中,该内存回收装置可以用于执行图2-3至图2-10中所描述的内存管理方法的步骤,具体请参见图2-3至图2-10中的相关描述,在此不再赘述。如图2-11所示,所述内存管理装置2-200可以包括:创建模块2-201、控制模块2-202、回收模块2-203。
本申请的实施例中,所述控制模块2-202可以根据第十应用及第十一应用的状态分别调整第十内存控制组的重要评分值和第十一内存控制组的重要评分值。
因此,内存控制组链表可以按照所述第十内存控制组和所述第十一内存控制组的重要评分值,对所述第十内存控制组及所述第十一内存控制组进行排序。
所述控制模块2-202还可以用于根据应用的状态更新所述内存控制组的所述重要评分值。
当需要内存回收时,所述回收模块2-203可以根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,以对所述第十内存控制组及第十一内存控制组进行内存回收。
在一些可能实现的实施例中,所述创建模块2-201可以用于在应用启动时创 建所述应用的内存控制组。
举例说明,所述创建模块2-201可以在第十应用启动时,创建所述第十应用的第十内存控制组。所述创建模块2-201还可以在第十一应用启动时,创建所述第十一应用的第十一内存控制组。所述控制模块2-202还可以用于设定所述内存控制组的重要评分值为预设值。
在一个实施例中,所述回收模块2-203还可以用于按照压缩比例对所述第十内存控制组进行内存压缩,并将压缩后的数据放入交换区中。所述回收模块2-203还可以用于按照压缩比例对所述第十一内存控制组进行内存压缩,并将压缩后的数据放入交换区中。
所述回收模块2-203还用于根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,控制所述第十内存控制组和第十一内存控制组的压缩顺序和换出顺序。
具体地,在一种可能实现的方式中,所述回收模块2-203可以按照压缩比例对所述内存控制组进行内存压缩,并将压缩后的数据放入交换区中。
若所述交换区的数据达到预设水线,所述回收模块2-203可以按照所述换出比例将所述数据从所述交换区换出到外部存储。
在一种可能的实现方式中,若所述应用的压缩量占比达到所述压缩比例,所述回收模块2-203终止对所述应用的压缩,并继续按照所述内存控制组链表中内存控制组的排序进行压缩,即可以选择所述内存控制组链表中下一个应用进行压缩。
在一种可能的实现方式中,若所述应用的换出量占比达到所述换出比例,所述回收模块2-203终止对所述应用的换出,并继续按照所述内存控制组链表中内存控制组的排序进行换出。
当所述应用的状态变化时,所述控制模块2-202可以更新所述应用的内存控制组的重要评分值和/或压缩比例和/或换出比例。
举例来说,当应用处于前台时,所述控制模块2-202可以将该应用的内存控制组的重要评分值设置为前台默认值。可以理解的是,在一种可能的实现方式中,所述前台默认值可以设置为0,也可以为其它值。
当所述应用处于解冻状态时,所述控制模块2-202可以将该应用的内存控制组的重要评分值设为冻结之前应用活跃时的重要评分值。
当所述应用处于活跃状态时,所述控制模块2-202可以根据所述应用的活跃时间比例、使用频繁程度,来调整该应用的内存控制组的重要评分值。
当所述应用处于冻结状态时,所述控制模块2-202可以根据所述应用的冻结解冻次数、内存占用大小,来调整该应用的内存控制组的重要评分值。
可以理解的是,上述内存管理装置中各个模块的划分仅用于举例说明,在其他的实施例中,可将内存管理装置按照需要划分为不同的模块,以完成上述内存管理装置的功能。
本申请实施例中提供的内存管理装置中的各个模块的实现,可为计算机 程序的形式。该计算机程序可在电子设备或服务器上运行。在本申请实施例中各个模块的具体实现还可以对应参照图2-3至图2-10所示的方法实施例的相应描述。在图2-11所描述的内存管理装置中,可以避免因内存控制组排序及回收比例不当而导致的内存回收的准确性不足问题,从而提升用户体验。具体内容可以参见上述内存管理方法的具体实施例,在此不再详述。
本申请实施例还提供了一种计算机可读存储介质。所述可读存储介质中存储有计算机指令,所述指令在计算设备上运行时,使得计算设备执行前述实施例提供的内存管理方法。
对于本领域的技术人员而言,显然本申请不限于上述示范性实施例的细节,而且在不背离本申请的精神或基本特征的情况下,能够以其他具体形式实现本申请。因此,只要在本申请的实质精神范围之内,对以上实施例所作的适当改变和变化都应该落在本申请要求保护的范围之内。
随着终端技术的发展,终端设备成为人们日常生活中必不可缺的物品。内存管理是终端设备系统的核心技术之一,对提高系统的用户体验和系统运行的稳定性具有关键作用。然而终端设备在使用过程中,随着应用打开数量的增加,其中运行的进程越来越多,占用的内存也会越来越多,这样将会使得系统的可用内存变少。而当内存紧张时,系统会出现卡顿、运行出错、崩溃等一系列问题。因此,如何高效管理内存,以及时回收内存,提高用户使用体验,是研发人员关注的一个重要课题。
可以理解,当前移动终端等嵌入式设备的内存状况与固定终端或服务器的内存状况区别越来越大。一方面,适用于服务器的内存管控策略可能在移动终端设备上不能很好的工作。另一方面,移动终端新的用户体验也对内存管控提出了新的需求,比如相机设备配置的升级对内存的需求越来越大。对此,安卓(Android)已经针对移动终端的内存需求特点做了很多调整工作。目前,Android的内存管理方法主要是基于MemFree的内存水线管控。该种方案中,所述内存水线不包含能够通过快速回收获得的内存,当MemFree较低时,内存压力已经非常大,触发回收以及kill时机滞后,不仅影响应用保活,甚至可能因为内存不足(Out Of Memory,OOM)出现Panic,影响用户体验。其中,MemFree是指空闲内存数,表示系统的整个内存空间中还未分配的、处于空闲状态的剩余内存空间的容量。其中,MemUsed=MemTotal-MemFree,MemUsed表示已被使用过的内存。例如,电子设备的内存空间总大小为4G,其中有3G已经分配给一个或者多个运行中的进程使用,另外1G处于空闲状态,则所述电子设备当前的空闲内存数为1G。MemTotal是指内存总数,系统从加电开始到引导完成,BIOS等要保留一些内存,内核要保留一些内存,最后剩下可供系统支配的内存就是MemTotal。这个值在系统运行期间一般是固定不变的。
另外,还存在一种基于MemAvailble的内存管理方法。所述方法主要是通过kill来进行水线维持。然而,水线设置过高,在内存压力较小时容易造成过杀, 影响保活。水线设置较低,在内存压力过大时仍然会存在和MemFree水线管控同样的问题。例如,在内存需求量较大较快的场景,如相机、游戏这类场景下,会出现内存不足造成过杀,甚至出现内存分配速度慢导致应用无响应,严重影响用户体验。而且MemAvailble水线设置比较敏感,不同的设备内存需求不同,很难统一水线。再者,第二种方法中除了kill也有伴随一些内存回收的动作,但是仅仅通过上层单向指导内存回收,无法形成上下统一的闭环,内存回收的效率、效果都无法保证。容易造成回收频繁启动引入功耗问题、回收空转造成回收效率问题、过度回收造成的refault问题,最终不能有效维持内存水线,反而给系统造成更大压力。其中,MemAvailable是指可用内存数,系统中有些内存虽然已被使用但是可以回收的,比如cache/buffer、slab都有一部分可以回收,所以MemFree不能代表全部可用的内存,这部分可回收的内存加上MemFree才是系统可用的内存,即:MemAvailable≈MemFree+Buffers+Cached,它是内核使用特定的算法计算出来的,是一个估计值。
本申请实施例提供一种内存管理方法、装置、电子设备及计算机可读存储介质,用以解决内存管理效率低,造成内存供给不及时,应用保活数量低的问题。
可以理解,本申请实施例提供的内存管理方法的执行主体可以是本申请实施例提供的内存管理装置,或者集成了所述内存管理装置的电子设备。其中,所述内存管理装置可以采用硬件或者软件的方式实现。所述电子设备也可称为用户设备(User Equipment,UE)、移动台(Mobile Station,MS)、移动终端(Mobile Terminal)等。可选地,所述电子设备可以具备无线接入网(Radio Access Nework,RAN)与一个或多个核心网进行通信的能力,例如,所述电子设备可以是移动电话(或称为“蜂窝”电话)、平板电脑、掌上电脑、笔记本电脑、或者台式电脑等设备。所述电子设备的操作系统可以包括,但不限于,Linux系统、Android(安卓)系统、IOS操作系统、Symbian(塞班)操作系统、Black Berry(黑莓)操作系统、Windows Phone 8操作系统等等。可以理解,本申请实施例提供的内存管理方法主要应用于具有Android操作系统的电子设备。
以手机为上述电子设备举例,图3-1示出了电子设备3-100的结构示意图。
如图3-1所示,电子设备3-100可以包括处理器3-110,外部存储器接口3-120,内部存储器3-121,通用串行总线(universal serial bus,USB)接口3-130,充电管理模块3-140,电源管理模块3-141,电池3-142,天线3-1,天线3-2,移动通信模块3-150,无线通信模块3-160,音频模块3-170,扬声器3-170A,受话器3-170B,麦克风3-170C,耳机接口3-170D,传感器模块3-180,按键3-190,马达3-191,指示器3-192,摄像头3-193,显示屏3-194,以及用户标识模块(subscriber identification module,SIM)卡接口3-195等。其中传感器模块3-180可以包括压力传感器3-180A,陀螺仪传感器3-180B,气压传感器3-180C,磁传感器3-180D,加速度传感器3-180E,距离传感器3-180F,接近光传感器3-180G,指纹传感器3-180H,温度传感器3-180J,触摸传感器3-180K,环境光传感器3-180L,骨传导传感器3-180M等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备3-100的具体限定。在本申请另一些实施例中,电子设备3-100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器3-110可以包括一个或多个处理单元,例如:处理器3-110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器3-110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器3-110中的存储器为高速缓冲存储器。该存储器可以保存处理器3-110刚用过或循环使用的指令或数据。如果处理器3-110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器3-110的等待时间,因而提升了系统的效率。
在一些实施例中,处理器3-110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
I2C接口是一种双向同步串行总线,包括一根串行数据线(serial data line,SDA)和一根串行时钟线(derail clock line,SCL)。在一些实施例中,处理器3-110可以包含多组I2C总线。处理器3-110可以通过不同的I2C总线接口分别耦合触摸传感器3-180K,充电器,闪光灯,摄像头3-193等。例如:处理器3-110可以通过I2C接口耦合触摸传感器3-180K,使处理器3-110与触摸传感器3-180K通过I2C总线接口通信,实现电子设备3-100的触摸功能。
I2S接口可以用于音频通信。在一些实施例中,处理器3-110可以包含多组I2S总线。处理器3-110可以通过I2S总线与音频模块3-170耦合,实现处理器3-110与音频模块3-170之间的通信。在一些实施例中,音频模块3-170可以通过I2S接口向无线通信模块3-160传递音频信号,实现通过蓝牙耳机接听电话的功能。
PCM接口也可以用于音频通信,将模拟信号抽样,量化和编码。在一些 实施例中,音频模块3-170与无线通信模块3-160可以通过PCM总线接口耦合。在一些实施例中,音频模块3-170也可以通过PCM接口向无线通信模块3-160传递音频信号,实现通过蓝牙耳机接听电话的功能。所述I2S接口和所述PCM接口都可以用于音频通信。
UART接口是一种通用串行数据总线,用于异步通信。该总线可以为双向通信总线。它将要传输的数据在串行通信与并行通信之间转换。在一些实施例中,UART接口通常被用于连接处理器3-110与无线通信模块3-160。例如:处理器3-110通过UART接口与无线通信模块3-160中的蓝牙模块通信,实现蓝牙功能。在一些实施例中,音频模块3-170可以通过UART接口向无线通信模块3-160传递音频信号,实现通过蓝牙耳机播放音乐的功能。
MIPI接口可以被用于连接处理器3-110与显示屏3-194,摄像头3-193等外围器件。MIPI接口包括摄像头串行接口(camera serial interface,CSI),显示屏串行接口(display serial interface,DSI)等。在一些实施例中,处理器3-110和摄像头3-193通过CSI接口通信,实现电子设备3-100的拍摄功能。处理器3-110和显示屏3-194通过DSI接口通信,实现电子设备3-100的显示功能。
GPIO接口可以通过软件配置。GPIO接口可以被配置为控制信号,也可被配置为数据信号。在一些实施例中,GPIO接口可以用于连接处理器3-110与摄像头3-193,显示屏3-194,无线通信模块3-160,音频模块3-170,传感器模块3-180等。GPIO接口还可以被配置为I2C接口,I2S接口,UART接口,MIPI接口等。
USB接口3-130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口3-130可以用于连接充电器为电子设备3-100充电,也可以用于电子设备3-100与外围设备之间传输数据。也可以用于连接耳机,通过耳机播放音频。该接口还可以用于连接其他电子设备,例如AR设备等。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备3-100的结构限定。在本申请另一些实施例中,电子设备3-100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块3-140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块3-140可以通过USB接口3-130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块3-140可以通过电子设备3-100的无线充电线圈接收无线充电输入。充电管理模块3-140为电池3-142充电的同时,还可以通过电源管理模块3-141为电子设备供电。
电源管理模块3-141用于连接电池3-142,充电管理模块3-140与处理器3-110。电源管理模块3-141接收电池3-142和/或充电管理模块3-140的输入, 为处理器3-110,内部存储器3-121,显示屏3-194,摄像头3-193,和无线通信模块3-160等供电。电源管理模块3-141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块3-141也可以设置于处理器3-110中。在另一些实施例中,电源管理模块3-141和充电管理模块3-140也可以设置于同一个器件中。
电子设备3-100的无线通信功能可以通过天线3-1,天线3-2,移动通信模块3-150,无线通信模块3-160,调制解调处理器以及基带处理器等实现。
天线3-1和天线3-2用于发射和接收电磁波信号。电子设备3-100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线3-1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块3-150可以提供应用在电子设备3-100上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块3-150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块3-150可以由天线3-1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块3-150还可以对经调制解调处理器调制后的信号放大,经天线3-1转为电磁波辐射出去。在一些实施例中,移动通信模块3-150的至少部分功能模块可以被设置于处理器3-110中。在一些实施例中,移动通信模块3-150的至少部分功能模块可以与处理器3-110的至少部分模块被设置在同一个器件中。
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器3-170A,受话器3-170B等)输出声音信号,或通过显示屏3-194显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器3-110,与移动通信模块3-150或其他功能模块设置在同一个器件中。
无线通信模块3-160可以提供应用在电子设备3-100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块3-160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块3-160经由天线3-2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器3-110。无线通信模块3-160还可以从处理器3-110接收待发送的信号,对其进行调频,放大,经天线3-2转为电磁波辐射出去。
在一些实施例中,电子设备3-100的天线3-1和移动通信模块3-150耦合,天线3-2和无线通信模块3-160耦合,使得电子设备3-100可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。
电子设备3-100通过GPU,显示屏3-194,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏3-194和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器3-110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏3-194用于显示图像,视频等。显示屏3-194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备3-100可以包括1个或N个显示屏3-194,N为大于1的正整数。
电子设备3-100可以通过ISP,摄像头3-193,视频编解码器,GPU,显示屏3-194以及应用处理器等实现拍摄功能。
ISP用于处理摄像头3-193反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头3-193中。
摄像头3-193用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备3-100可以包括1个或N个摄像头3-193,N为大于1的正整数。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备3-100在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。电子设备3-100可以支持一种或多种视频编解码器。这样,电子设备3-100可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备3-100的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。
内部存储器3-121可以包括一个或多个随机存取存储器(random access memory,RAM)和一个或多个非易失性存储器(non-volatile memory,NVM)。
随机存取存储器可以包括静态随机存储器(static random-access memory,SRAM)、动态随机存储器(dynamic random access memory,DRAM)、同步动态随机存储器(synchronous dynamic random access memory,SDRAM)、双倍资料率同步动态随机存取存储器(double data rate synchronous dynamic random access memory,DDR SDRAM,例如第五代DDR SDRAM一般称为DDR5SDRAM)等。
非易失性存储器可以包括磁盘存储器件、快闪存储器(flash memory)。
快闪存储器按照运作原理划分可以包括NOR FLASH、NAND FLASH、3D NAND FLASH等,按照存储单元电位阶数划分可以包括单阶存储单元(single-level cell,SLC)、多阶存储单元(multi-level cell,MLC)、三阶储存单元(triple-level cell,TLC)、四阶储存单元(quad-level cell,QLC)等,按照存储规范划分可以包括通用闪存存储(universal flash storage,UFS)、嵌入式多媒体存储卡(embedded multi-media Card,eMMC)等。
随机存取存储器可以由处理器3-110直接进行读写,可以用于存储操作系统或其他正在运行中的程序的可执行程序(例如机器指令),还可以用于存储用户及应用程序的数据等。
非易失性存储器也可以存储可执行程序和存储用户及应用程序的数据等,可以提前加载到随机存取存储器中,用于处理器3-110直接进行读写。
外部存储器接口3-120可以用于连接外部的非易失性存储器,实现扩展电子设备3-100的存储能力。外部的非易失性存储器通过外部存储器接口3-120与处理器3-110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部的非易失性存储器中。
电子设备3-100可以通过音频模块3-170,扬声器3-170A,受话器3-170B,麦克风3-170C,耳机接口3-170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块3-170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块3-170还可以用于对音频信号编码和解码。在一些实施例中,音频模块3-170可以设置于处理器3-110中,或将音频模块3-170的部分功能模块设置于处理器3-110中。
扬声器3-170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备3-100可以通过扬声器3-170A收听音乐,或收听免提通话。
受话器3-170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备3-100接听电话或语音信息时,可以通过将受话器3-170B靠近人耳接听语音。
麦克风3-170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风3-170C发声,将声音信号输入到麦克风3-170C。电子设备3-100可以设置至少一个麦克风3-170C。在另一些实施例中,电子设备3-100可以设置两个麦克风3-170C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备3-100还可以设置三个,四个或更多麦克风3-170C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。
耳机接口3-170D用于连接有线耳机。耳机接口3-170D可以是USB接口3-130,也可以是3、5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。
压力传感器3-180A用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器3-180A可以设置于显示屏3-194。压力传感器3-180A的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器3-180A,电极之间的电容改变。电子设备3-100根据电容的变化确定压力的强度。当有触摸操作作用于显示屏3-194,电子设备3-100根据压力传感器3-180A检测所述触摸操作强度。电子设备3-100也可以根据压力传感器3-180A的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第三十一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第三十一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。
陀螺仪传感器3-180B可以用于确定电子设备3-100的运动姿态。在一些实施例中,可以通过陀螺仪传感器3-180B确定电子设备3-100围绕三个轴(即,x,y和z轴)的角速度。陀螺仪传感器3-180B可以用于拍摄防抖。示例性的,当按下快门,陀螺仪传感器3-180B检测电子设备3-100抖动的角度,根据角度计算出镜头模组需要补偿的距离,让镜头通过反向运动抵消电子设备 3-100的抖动,实现防抖。陀螺仪传感器3-180B还可以用于导航,体感游戏场景。
气压传感器3-180C用于测量气压。在一些实施例中,电子设备3-100通过气压传感器3-180C测得的气压值计算海拔高度,辅助定位和导航。
磁传感器3-180D包括霍尔传感器。电子设备3-100可以利用磁传感器3-180D检测翻盖皮套的开合。在一些实施例中,当电子设备3-100是翻盖机时,电子设备3-100可以根据磁传感器3-180D检测翻盖的开合。进而根据检测到的皮套的开合状态或翻盖的开合状态,设置翻盖自动解锁等特性。
加速度传感器3-180E可检测电子设备3-100在各个方向上(一般为三轴)加速度的大小。当电子设备3-100静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。
距离传感器3-180F,用于测量距离。电子设备3-100可以通过红外或激光测量距离。在一些实施例中,拍摄场景,电子设备3-100可以利用距离传感器3-180F测距以实现快速对焦。
接近光传感器3-180G可以包括例如发光二极管(LED)和光检测器,例如光电二极管。发光二极管可以是红外发光二极管。电子设备3-100通过发光二极管向外发射红外光。电子设备3-100使用光电二极管检测来自附近物体的红外反射光。当检测到充分的反射光时,可以确定电子设备3-100附近有物体。当检测到不充分的反射光时,电子设备3-100可以确定电子设备3-100附近没有物体。电子设备3-100可以利用接近光传感器3-180G检测用户手持电子设备3-100贴近耳朵通话,以便自动熄灭屏幕达到省电的目的。接近光传感器3-180G也可用于皮套模式,口袋模式自动解锁与锁屏。
环境光传感器3-180L用于感知环境光亮度。电子设备3-100可以根据感知的环境光亮度自适应调节显示屏3-194亮度。环境光传感器3-180L也可用于拍照时自动调节白平衡。环境光传感器3-180L还可以与接近光传感器3-180G配合,检测电子设备3-100是否在口袋里,以防误触。
指纹传感器3-180H用于采集指纹。电子设备3-100可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。
温度传感器3-180J用于检测温度。在一些实施例中,电子设备3-100利用温度传感器3-180J检测的温度,执行温度处理策略。例如,当温度传感器3-180J上报的温度超过阈值,电子设备3-100执行降低位于温度传感器3-180J附近的处理器的性能,以便降低功耗实施热保护。在另一些实施例中,当温度低于另一阈值时,电子设备3-100对电池3-142加热,以避免低温导致电子设备3-100异常关机。在其他一些实施例中,当温度低于又一阈值时,电子设备3-100对电池3-142的输出电压执行升压,以避免低温导致的异常关机。
触摸传感器3-180K,也称“触控器件”。触摸传感器3-180K可以设置于显示屏3-194,由触摸传感器3-180K与显示屏3-194组成触摸屏,也称“触控 屏”。触摸传感器3-180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏3-194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器3-180K也可以设置于电子设备3-100的表面,与显示屏3-194所处的位置不同。
骨传导传感器3-180M可以获取振动信号。在一些实施例中,骨传导传感器3-180M可以获取人体声部振动骨块的振动信号。骨传导传感器3-180M也可以接触人体脉搏,接收血压跳动信号。在一些实施例中,骨传导传感器3-180M也可以设置于耳机中,结合成骨传导耳机。音频模块3-170可以基于所述骨传导传感器3-180M获取的声部振动骨块的振动信号,解析出语音信号,实现语音功能。应用处理器可以基于所述骨传导传感器3-180M获取的血压跳动信号解析心率信息,实现心率检测功能。
按键3-190包括开机键,音量键等。按键3-190可以是机械按键。也可以是触摸式按键。电子设备3-100可以接收按键输入,产生与电子设备3-100的用户设置以及功能控制有关的键信号输入。
马达3-191可以产生振动提示。马达3-191可以用于来电振动提示,也可以用于触摸振动反馈。例如,作用于不同应用(例如拍照,音频播放等)的触摸操作,可以对应不同的振动反馈效果。作用于显示屏3-194不同区域的触摸操作,马达3-191也可对应不同的振动反馈效果。不同的应用场景(例如:时间提醒,接收信息,闹钟,游戏等)也可以对应不同的振动反馈效果。触摸振动反馈效果还可以支持自定义。
指示器3-192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。
SIM卡接口3-195用于连接SIM卡。SIM卡可以通过插入SIM卡接口3-195,或从SIM卡接口3-195拔出,实现和电子设备3-100的接触和分离。电子设备3-100可以支持1个或N个SIM卡接口,N为大于1的正整数。SIM卡接口3-195可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM卡接口3-195可以同时插入多张卡。所述多张卡的类型可以相同,也可以不同。SIM卡接口3-195也可以兼容不同类型的SIM卡。SIM卡接口3-195也可以兼容外部存储卡。电子设备3-100通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备3-100采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备3-100中,不能和电子设备3-100分离。
下面结合附图,以执行主体为电子设备3-100为例,对本申请实施例提供的内存管理方法进行详细介绍。
图3-2a示出根据本申请实施例提供的一种内存管理方法的流程示意图。如图3-2a所示,所述内存管理方法可以包括S3-20-S3-211:
步骤S3-20,创建内存统计值及内存压力等级。
可以理解,所述内存统计值用于表征电子设备的系统内存中剩余的可用 内存,其通常用水线(watermark)参数来表征。例如内存水线越低,表明剩余的可用系统内存越少。水线(watermark)为内存管理区中的一个数组,所述内存水线通常包括三个水线值,即WMARK_HIGH(高水线)、WMARK_LOW(低水线)、WMARK_MIN(最小水线)。其中,WMARK_HIGH>WMARK_LOW>WMARK_MIN。通常,在分配页(page)之前,需要先检查watermark。例如,当空闲页大于WMARK_HIGH时,说明电子设备的系统内存状态是理想的,暂不需要进行内存回收。当空闲页低于WMARK_LOW时,则说明电子设备的系统内存不足,需要进行内存回收。当空闲页低于WMARK_MIN时,则说明电子设备的系统内存严重不足,例如内存域中的可用空闲页已经很少了,必须加快进行内存回收。
可以理解,本申请实施例中的可用内存包括两部分,例如第三十一内存和第三十二内存。其中,所述第三十一内存是指系统的空闲内存。所述空闲内存是指系统尚未使用的内存,即MemFree。所述第三十二内存为被占用但是可通过回收来转换为第三十一内存的内存。所述被占用内存主要指当前正在运行的进程和服务所占用的内存以及内核运行所占用的内存。
可以理解,请一并参阅下述公式(1),本申请实施例中定义的所述内存水线可由所述公式(1)获得。
buffer=freemem+α*inactive_file+β*active_file+ion_cache(1)
其中,Buffer为缓冲区内存数,也被称write-buffer,一般用在写操作。Cache为缓存区内存数,也被称read-cache,一般用在读操作。
在本申请实施例中,参数buffer为所述内存水线。参数freemem为所述第三十一内存中的空闲内存。参数inactive_file为不活跃文件内存。参数active_file为活跃文件内存。参数ion_cache为ION内存管理器的可用内存(cache)。其中缓存(cache)是把读取过的数据保存起来,重新读取时若命中(找到需要的数据)就不要去读硬盘了,若没有命中就读硬盘。所述参数inactive_file,active_file和ion_cache共同构成所述第三十二内存中被占用但是可通过回收来供给的内存。参数α、β为可调参数。具体地,所述参数α、β可以根据不同产品的规格进行相应的调整,即选择不同的比例或折扣。
可以理解,在本申请实施例中,并不对所述第三十一内存和第三十二内存进行限定。例如所述第三十二内存还可以为其他被占用但是可供给或回收的内存,而不局限于不活跃文件内存和/或活跃文件内存。
可以理解,根据上述公式(1),所述内存统计值的创建综合考虑了可快速回收内存的供应,提供了针对文件页(file page)供应的可调参数,使得内存统计值设定更加合理。即所述内存统计值能够更有效地体现可用内存供给能力,更有效地体现内存压力情况。
可以理解,在本申请实施例中,所述内存统计值包括第三十一内存统计值,第三十二内存统计值及第三十三内存统计值。所述第三十一内存统计值对应上述水线(watermark)中的WMARK_HIGH,以下统称为high_buffer。 所述第三十二内存统计值可对应上述水线(watermark)中的WMARK_LOW,以下统称为low_buffer。所述第三十三内存统计值对应上述水线(watermark)中的WMARK_MIN,以下统称为min_buffer。其中,所述第三十二内存统计值小于所述第三十一内存统计值。所述第三十三内存统计值小于所述第三十二内存统计值。
可以理解,本申请实施例中,所述内存压力等级包括第三十一等级,第三十二等级,及第三十三等级。所述电子设备还可预先设定所述内存压力等级,例如所述第三十一等级对应低级,所述第三十二等级对应中级,所述第三十三等级对应高级。其中,高级(critical_level_press)表征内存压力较大。中级(medium_level_press)表征内存压力适中,低级(low_level_press)表征内存压力较小。即所述第三十三等级的内存压力高于所述第三十二等级的内存压力,所述第三十二等级的内存压力高于所述第三十一等级的内存压力。所述内存压力等级可以根据系统当前的内存统计值来确定。例如,若系统当前的内存统计值小于第三十二内存统计值,可以确定系统当前的内存压力等级为第三十一等级(例如低级)。当经过系统内存回收后,若系统当前的内存统计值小于第三十一内存统计值,可以确定系统当前的内存压力等级为第三十二等级(例如中级),当系统当前的内存统计值小于第三十三内存统计值时,可以确定系统当前的内存压力等级为第三十三等级(例如高级)。
可选的,所述内存统计值可以是静态预置的。具体的,有如下几种情况:
(1)根据产品规格配置内存统计值
针对2G/3G/4G/6G随机存取存储器(Random Access Memory,RAM)的产品,系统的可用内存不同,相应的,内存统计值也不同。比如:针对3G RAM的产品,可以配置内存统计值为600MB,针对4GRAM的产品,可以配置内存统计值为700MB。
(2)根据应用场景配置尽可能小的内存统计值
不同的应用及其不同的场景,对于内存的耗费是不同的。因此要想配置合理的内存统计值,采用方式(1)存在一些弊端,可能会因为没有考虑某个第三方应用而出现该应用启动时卡顿的现象。针对此类问题,可以通过离线分析应用市场中排名靠前的第三方应用,获取各类应用在各个场景中最大的内存占用信息,并设置内存统计值为该应用的最大占用内存。
又如,考虑到在灭屏场景下要降低灭屏后台功耗,以及要解决亮屏瞬间应用集中唤醒带来的内存冲击场景,可将所述内存统计值在灭屏场景和亮屏场景分别设置为两个不同的值,且处于灭屏场景时的内存统计值均低于亮屏场景下的内存统计值。例如,灭屏场景下的所述第三十一内存统计值低于亮屏场景下的所述第三十一内存统计值。灭屏场景下的所述第三十二内存统计值低于亮屏场景下的所述第三十二内存统计值。灭屏场景下的所述第三十三内存统计值低于亮屏场景下的所述第三十三内存统计值。
(3)根据系统运行进程历史占用内存进行配置
由于每个用户都有自己的特点,终端被长时间使用后,终端上安装和运行的应用并不一致,可以根据系统运行进程历史占用内存来配置内存统计值。具体的,可以在用户不使用终端的时候(比如半夜)查询每个进程运行时内存占用的历史状态信息(procstats),获取其中最大的内存占用信息(如应用程序名称、最大占用内存),进一步地,将最大占用内存和当前系统的内存统计值比较,若最大占用内存大于当前系统的内存统计值,则选取该最大占用内存作为系统新的内存统计值。
(4)通过云端下发配置内存统计值
云端服务器可以根据终端的标识收集在终端上运行的所有应用在各个场景占用的内存信息,将占用内存大于预设值(如300MB)的应用名及该应用当时的运行场景等信息形成一张表单,定期(如每月)将该表单推送给终端,终端接收到表单后,将此表单中的应用信息和本地应用列表进行遍历,并确定终端上安装的应用的最大内存占用信息,进一步地,将最大占用内存和当前系统的内存统计值进行比较,若最大占用内存大于当前系统的内存统计值,则选取该最大占用内存作为系统新的内存统计值。
可选的,该内存统计值还可以是动态配置的。
具体的,可以通过用户行为分析算法,根据用户使用习惯、应用使用历史、使用频率、使用时长等信息,根据预测算法,预测出接下来最有可能运行的应用,并形成应用列表,获取应用列表中的应用需要使用的最大内存,并将最大内存和当前系统的内存统计值相比,若最大内存大于当前系统的内存统计值,则选取该最大内存作为系统新的内存统计值。
步骤S3-21,监控系统当前的内存统计值。
步骤S3-22,确定系统当前的内存统计值是否低于所述第三十二内存统计值low_buffer。
其中,若确定系统当前的内存统计值低于所述第三十二内存统计值low_buffer,则执行步骤S3-23。若确定系统当前的内存统计值不低于所述第三十二内存统计值low_buffer,则返回步骤S3-21,即继续监控系统当前的内存统计值。
步骤S3-23,当确定系统当前的内存统计值低于所述第三十二内存统计值low_buffer,唤醒匿名页压缩线程,以准备回收内存。
可以理解,一般内核在进行内存压缩处理时,会选择匿名页作为内存压缩处理的对象。其中,匿名页为应用程序动态分配的堆内存的内存页。由于匿名页很可能还要再次被访问,不能直接回收,这些内存自然不能直接释放。因此,采用内存压缩的方式间接地释放他们所占的内存空间。例如,先确定已分配内存页中的匿名页,从全部匿名页中选择一定数量的内存页作为目标内存页,并进行压缩,以达到增大空闲内存的目的。
步骤S3-24,确定系统当前的内存压力等级为第三十一级,并上报为第三十一级压力事件(例如低级压力(low_level_press)事件)至上层。
步骤S3-25,所述上层接收所述低级压力(low_level_press)事件,并根据应用特征来配置并下发回收参数至所述匿名页压缩线程,以指导所述匿名页压缩线程回收内存。
步骤S3-26,接收所述回收参数,并根据所述回收参数通过匿名页压缩线程启动压缩处理,以进行内存回收。即回收第三十二内存,以将所述第三十二内存转换为所述第三十一内存。
可以理解,所述上层可以为native层或应用框架层(FWK)。
可以理解,所述回收参数包括,但不限于,目标内存页的数量,目标内存页回收的优先级,和/或内存回收比例(ratio)等。其中,目标内存页的数量可以根据系统当前的内存统计值大小和所述第三十二内存统计值low_buffer来确定。例如,根据所述第三十二内存统计值low_buffer与系统当前的内存统计值的大小的差值确定待回收的内存量,再根据待回收的内存量和期望压缩率,计算需要的目标内存页的数量。
如此,所述匿名页压缩线程可根据上述回收参数启动压缩处理。例如对目标内存页进行压缩,并将压缩后的内存页写入内存空间中的内存压缩空间中,以释放这些目标内存页占用的一部分内存空间。后续,当系统需要再使用这些内存页时,从内存压缩空间中找到压缩后的内存页,将其解压后使用。
例如,假设系统当前的内存统计值大小为10M,所述第三十二内存统计值low_buffer为20M。因此可得出需要释放的内存空间为10M,假设期望压缩率为50%,则可以计算得到需要进行压缩处理的内存大小为10M÷50%=20M。接着从匿名页中获取20M的目标内存页,对这些内存页进行压缩处理,可以得到10M的内存空间。其中,压缩率为压缩后的内存页的大小与原始内存页的大小之间的比例。期望压缩率可以为一个预设的经验值。
步骤S3-27,当通过匿名压缩完成一次内存回收后,确定系统当前的内存统计值是否低于所述第三十一内存统计值high_buffer。
若确定系统当前的内存统计值低于所述第三十一内存统计值high_buffer,则执行步骤S3-28。若确定系统当前的内存统计值不低于所述第三十一内存统计值high_buffer,则返回步骤S3-21,即继续监控系统当前的内存统计值。
步骤S3-28,当确定系统当前的内存统计值低于所述第三十一内存统计值high_buffer时,确认系统当前的内存压力等级为所述第三十二等级,并通过所述匿名页压缩线程上报为第三十二级压力事件(例如中级压力(medium_level_press)事件)至所述上层。
步骤S3-29,所述上层接收所述中级压力(medium_level_press)事件,并调整(例如下调)所述内存统计值。
可以理解,通常所述匿名页压缩线程在回收结束时一般可以达到所述第三十一内存统计值high_buffer,如此使得系统有足够的空闲资源,以为后续的应用启动,例如相机启动维护一个较高的内存统计值。
另外,通过所述匿名页压缩线程进行内存回收,使所述内存统计值达到 所述第三十一内存统计值high_buffer,即使得所述内存统计值达到一个较高的水平。如此,亦可有效防止造成回收频繁启动引入功耗问题、回收空转造成回收效率问题、过度回收造成的refault问题等。
可以理解,在本申请实施例中,当所述匿名页压缩线程在回收结束时,若系统当前的内存统计值仍达不到所设定的第三十一内存统计值high_buffer,则对所述内存统计值进行调整,例如下调所述内存统计值。
步骤S3-210,确定系统当前的内存统计值是否低于所述第三十三内存统计值min_buffer。
若确定系统当前的内存统计值低于所述第三十三内存统计值min_buffer,则执行步骤S3-211。若确定系统当前的内存统计值不低于所述第三十三内存统计值min_buffer,则返回步骤S3-26,即继续启动所述匿名页压缩线程进行内存回收。
步骤S3-211,当确定系统当前的内存统计值低于所述第三十三内存统计值min_buffer,再次上报为中级压力(medium_level_press)事件,并通过杀(kill)死进程来回收所述第三十二内存,并返回步骤S3-21,即继续监控系统当前的内存统计值。
可以理解,在本申请实施例中,当所述上层在时间窗口Δ内收到预设次数(例如n次)的中级压力(medium_level_press)事件时,所述内存统计值逐渐下调至所述第三十三内存统计值min_buffer。其中,所述上层下调所述内存统计值是指,当所述上层接收到中级压力(medium_level_press)事件时,其根据系统当前的内存统计值将所述第三十二内存统计值low_buffer及所述第三十一内存统计值high_buffer同时下调,其下调的值为所述第三十一内存统计值high_buffer与系统当前的内存统计值的差值。若经过所述匿名页压缩进程的内存回收,仍无法维护所述第三十三内存统计值min_buffer,即系统当前的内存统计值仍低于所述第三十三内存统计值min_buffer,则在再次上报中级压力(medium_level_press)事件时通过杀(kill)死进程来回收所述第三十二内存。
可以理解,在确定满足杀死进程的触发条件,例如当系统当前的内存统计值仍低于所述第三十三内存统计值min_buffer时,则可以进一步根据所述第三十三内存统计值min_buffer以及系统当前的内存统计值确定需要杀的量及需要杀的目标进程,即确定杀哪一个或哪些进程。也就是说,在确定满足杀死进程的触发条件时,可创建杀进程列表,再根据所述杀进程列表中进程的顺序执行来杀死进程,直至使得系统当前的内存统计值到达所述第三十三内存统计值min_buffer。
其中,所述杀进程列表为一个根据应用的重要程度,进程优先级和/或其他因素(例如应用匿名页大小及分布)进行排序的动态二维表,包括一个或多个应用的进程。即所述杀进程列表可以包括一个或多个应用,同时一个应用可以包括一个或多个进程。所述杀进程列表为根据应用的重要程度,进程 优先级和/或其他因素排序后的列表。
具体的,创建所述杀进程列表的方式具体包括,但不限于,以下步骤:
(1)确定当前在后台运行的每个应用的关键因素的分值,所述关键因素包括以下中的一个或多个:进程优先级、用户使用习惯、进程占用系统资源以及应用的关联关系。
(2)针对每个所述应用,将所有所述关键因素的分值进行加权计算,获得所述应用的重要程度。
(3)根据所有所述应用的重要程度,对所有所述应用进行排序。
(4)根据进程优先级,对排序后的每个所述应用包括的进程进行排序,以生成杀进程列表。
在本申请实施例中,在终端后台运行的每个应用可以包括一个或多个进程,每个应用的关键因素包括以下中的一个或多个:进程优先级、用户使用习惯、进程占用系统资源以及应用的关联关系。每个关键因素都有相应的分值。基于应用的关键因素(进程优先级、用户使用习惯、进程占用系统资源以及应用的关联关系)来创建杀进程列表,后续就可以根据内存的需求从所述杀进程列表中确定需要处理的进程,这样就可以精确地选择可杀进程队列,减少错杀/多杀/少杀进程的概率。
其中,系统会对每个进程的重要性进行评估,进程的重要性也代表了进程优先级。通常,将重要性以oom_adj(out of memory adjust)这个数值表示出来,赋予各个进程,系统会根据oom_adj来判断需要结束哪些进程。一般,oom_adj的分值由系统提供,系统可以根据应用当前的运行状态来分配。通常oom_adj的分值越大,所述进程被系统选中终止的可能就越高,进程优先级就越低。
其中,用户使用习惯可以包括但不限于应用的使用时间记录、应用的累计使用次数、每次被使用的时长以及累计使用时长。根据用户使用习惯可以确定哪些进程为用户经常使用的应用的进程,或者确定哪些进程为用户使用时间较长的应用的进程,或者确定哪些进程为用户最近使用的应用的进程等等相关进程的信息。
其中,可通过随机森林等模型学习得到应用重要程度模型,结合应用使用频率,应用匿名页大小及分布和/或其他因素,得到所述杀进程列表。在杀死进程时,根据所述杀进程列表中的应用匿名页情况以及所需杀的量,得到所需杀的应用。
显然,如图3-2a所述,所述内存统计值包括第三十一内存统计值,第三十二内存统计值及第三十三内存统计值。所述第三十二内存统计值小于所述第三十一内存统计值。所述第三十三内存统计值小于所述第三十二内存统计值。如此,通过将系统当前的内存统计值与预设的所述第三十一内存统计值,第三十二内存统计值,第三十三内存统计值进行比较,进而可根据其比较结果采用不同的内存管理策略。
例如,请一并参阅图3-2b,当确定系统当前的内存统计值低于所述第三十二内存统计值时,可启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存。
当通过匿名页压缩后确定系统当前的内存统计值低于所述第三十一内存统计值时,可下调所述内存统计值。
当确定系统当前的内存统计值低于所述第三十三内存统计值时,可通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存,直至系统当前的内存统计值不低于所述第三十三内存统计值。
图3-3示出根据本申请实施例提供的另一种内存管理方法的流程示意图。如图3-3所示,所述内存管理方法在图3-2a的基础上,还可以包括步骤S3-30-S3-33。
步骤S3-30,监控swap分区的空间使用率。
在本申请实施例中,swap分区即交换区。通常内存可以包括正常使用区及交换区,当系统内存资源不足时,回收机制开始进行内存回收。回收机制开始对正常使用区中的数据进行压缩,并将压缩后的数据放入交换区中。若交换区中的数据量达到水线,则将交换区中的数据换出到外部存储中。
步骤S3-31,确定当前swap分区的空间使用率是否达到预设比例。若确定当前swap分区的空间使用率达到所述预设比例,则执行步骤S3-32。若确定当前swap分区的空间使用率未达到所述预设比例,则返回步骤S3-30,即继续监控swap分区的空间使用率。
步骤S3-32,当确定当前swap分区的空间使用率达到所述预设比例时,确认系统当前的内存压力等级为所述第三十三等级,并上报为第三十三级压力事件(例如高级压力(critical_level_press)事件)至所述上层。
步骤S3-33,根据所述高级压力(critical_level_press)事件,所述上层通过杀死进程来回收所述第三十二内存。
可以理解,当启动所述匿名页压缩线程,导致所述swap分区的空间使用率到达所述预设比例时,此时会导致所述内存统计值难以继续通过匿名页压缩的方式回收内存,此时所述匿名页压缩线程将上报所述高级压力(critical_level_press)事件,以触发所述上层通过杀死进程来回收所述第三十二内存。
例如,如果在此前已经回收了大量应用的冷匿名页,swap分区的空间已满,则所述匿名页压缩线程在本轮回收结束时,上报为高级压力(critical_level_press)事件,直接触发所述上层通过杀死进程来回收所述第三十二内存。
可以理解,步骤S3-33中的通过杀死进程来回收第三十二内存与图3-2a中步骤S3-211中的通过杀死进程来回收所述第三十二内存类似,以及相应的概念也是类似,在此不再赘述。
图3-4示出根据本申请实施例提供的另一种内存管理方法的流程示意图。如图3-4所示,所述内存管理方法在图3-2a和/或图3-3的基础上,还可以包括步骤S3-40-S3-44。
步骤S3-40,通过压力失速信息(Pressure Stall Information,PSI)线程来监控系统资源压力。PSI提供一种评估系统资源压力的方法。系统资源可以包括CPU资源、IO资源等,一旦产生资源竞争,就有可能带来延迟增大,使用户体验到卡顿。如果没有一种相对准确的方法检测系统的资源压力程度,有两种后果。一种是资源使用者过度克制,没有充分使用系统资源;另一种是经常产生资源竞争,过度使用资源导致等待延迟过大。准确的检测方法可以帮忙资源使用者确定合适的工作量,同时也可以帮助系统制定高效的资源调度策略,最大化利用系统资源,最大化改善用户体验。对此,Facebook在2018年开源了一套解决重要计算集群管理问题的Linux内核组件和相关工具,PSI是其中重要的资源度量工具,用以提供一种实时检测系统资源竞争程度的方法,以竞争等待时间的方式呈现,可以更全面地判断当前系统压力,并简单而准确地供用户以及资源调度者进行决策。具体的,所述PSI用以将各个任务延迟汇总为资源压力指标,这些指标反映工作负载运行状况和资源利用率方面的问题。可以理解,在本申请实施例中,所述PSI线程考量的指标通常为供给应用的速度。在一种情况下,大内存消耗类应用,会在短时间内消耗大量内存,例如一下消耗到2G内存,但采用前面的方式(例如采用匿名压压缩的方式回收内存),其内存回收速度较慢,因此,可采用PSI线程触发系统资源压力的检测。PSI统计数据(即PSI值)可为即将发生的资源短缺提供早期预警,从而实现更积极主动、细致的响应。
步骤S3-41,确定系统当前的PSI值是否大于预设阈值。若确定系统当前的PSI值大于所述预设阈值时,执行步骤S3-42。若确定系统当前的PSI值不大于所述预设阈值时,返回步骤S3-40,即继续监控系统资源压力。
步骤S3-42,当确定系统当前的PSI值大于所述预设阈值时,所述PSI线程上报PSI压力值至所述上层。
步骤S3-43,所述上层接收所述PSI压力值,并确定系统当前的内存统计值是否小于第三十四内存统计值psi_buffer。
若确定系统当前的内存统计值小于所述第三十四内存统计值psi_buffer,则执行步骤S3-44。若确定系统当前的内存统计值不小于所述第三十四内存统计值psi_buffer,则返回步骤S3-40。
步骤S3-44:当确定系统当前的内存统计值小于所述第三十四内存统计值psi_buffer时,通过杀死进程来回收所述第三十二内存。
可以理解,在本申请实施例中,当PSI线程上报表明系统内存快速供给应用的速度较慢时,还需判断系统当前的内存统计值是否小于所述第三十四内存统计值psi_buffer。当系统当前的内存统计值不低于所述第三十四内存统计值psi_buffer时,说明当前系统还是可以为应用提供可用内存,只是其供给速度较慢。当系统当前的内存统计值低于所述第三十四内存统计值psi_buffer时,说明系统能为应用提供的可用内存不足,且供给速度较慢。此时,将直接通过杀死进程来回收所述第三十二内存。
可以理解,所述第三十四内存统计值psi_buffer小于所述第三十三内存统计值min_buffer。
可以理解,步骤S3-44中的通过杀死进程来回收所述第三十二内存与图3-2a中步骤S3-211中的通过杀死进程来回收所述第三十二内存、图3-3中步骤S3-33中的通过杀死进程来回收所述第三十二内存类似,以及相应的概念也是类似,在此不再赘述。
图3-5示出根据本申请实施例提供的另一种内存管理方法的流程示意图。如图3-5所示,所述内存管理方法在图3-2a,图3-3和/或图3-4的基础上,还可以包括步骤S3-50-S3-52。
步骤S3-50,监控是否有预设应用启动。若监控到有预设应用启动,则执行步骤S3-51,若没有监控到预设应用的启动,则继续执行步骤S3-50。
可以理解,所述预设应用是指启动时会消耗大量内存的应用,例如一旦所述预设用以启动,将在短时间内消耗大量内存的应用。所述预设应用可以预先设置,并进行存储。
步骤S3-51,当监控到有预设应用启动时,进一步确定系统当前的内存统计值是否大于所述第三十一内存统计值high_buffer。若确定系统当前的内存统计值小于所述第三十一内存统计值high_buffer,则执行步骤S3-52。若确定系统当前的内存统计值不小于所述第三十一内存统计值high_buffer,则返回步骤S3-50。
步骤S3-52,当确定系统当前的内存统计值小于所述第三十一内存统计值high_buffer,通过杀死进程来回收所述第三十二内存。
可以理解,在本申请实施例中,如果应用内存需求过快,PSI压力上报仍然存在延迟,则无法及时通过杀死进程来回收第三十二内存。因此在大内存需求的应用启动场景下,例如相机启动,会在收到启动消息时,立刻触发通过杀死进程来回收所述第三十二内存。
可以理解,通常当大内存应用(例如相机)启动时,会在短时间内消耗大量内存,拉低内存统计值,所述匿名页压缩线程会被唤醒进行内存回收。但是从所述内存统计值下调到所述第三十三内存统计值min_buffer的过程对于相机启动来说可能是缓慢的,所以除了大内存应用启动触发的杀进程,PSI压力上报将会是一个很好的补充,在所述内存统计值具有下降趋势的时候,也会及时通过杀死进程来回收所述第三十二内存。
可以理解,步骤S3-52中的通过杀死进程来回收第三十二内存与图3-2a中步骤S3-211中的通过杀死进程来回收第三十二内存,图3-3中步骤S3-33中的通过杀死进程来回收第三十二内存,图3-4中步骤S3-44中的通过杀死进程来回收第三十二内存类似,以及相应的概念也是类似,在此不再赘述。
请再次参阅图3-2a至图3-5,显然,在本申请实施例中,通过杀死进程来回收所述第三十二内存至少存在以下四种情况。
第一种情况:当所述内存统计值逐步下调最低至所述第三十三内存统计 值min_buffer时,此后若系统当前的内存统计值仍未能达到所述第三十三内存统计值min_buffer,则通过杀死进程来回收所述第三十二内存,进而将所述内存统计值维持至所述第三十三内存统计值min_buffer(参图3-2a中步骤S3-211)。
第二种情况:当监控到所述匿名页压缩进程压缩内存导致swap分区的空间使用率达到所述预设比例,此时会导致所述内存统计值难以继续通过匿名页压缩的方式回收内存,则上报为高级压力(critical-level-press)事件,同步通过杀死进程来回收所述第三十二内存(参图3-3中步骤S3-33)。
第三种情况:PSI压力上报策略,即根据PSI压力状态直接触发所述第三十四内存统计值psi_buffer的检测并触发通过杀死进程来回收所述第三十二内存(参图3-4中步骤S3-44)。
第四种情况:预设应用启动,即若应用内存需求过快,PSI上报仍然存在延迟,无法及时通过杀死进程来回收所述第三十二内存。因此在大内存需求的应用启动场景下,例如相机启动,会在收到启动消息时,立刻触发通过杀死进程来回收所述第三十二内存(参图3-5中步骤S3-52)。
可以理解,在本申请实施例中,并不对上述四种情况对应的杀死进程的时间或顺序进行限制,只要其满足其中任何之一,均可以触发通过杀死进程来回收所述第三十二内存。
请参阅图3-6,图3-6是本申请实施例提供的一种内存管理装置的结构示意图。其中,所述内存管理装置3-200可以用于执行图3-2a至图3-5中所描述的内存管理方法的部分或全部步骤。如图3-6所示,所述内存管理装置3-200可以包括:
线程模块3-21,所述线程模块3-21至少包括匿名页压缩线程3-211和PSI线程3-212。所述匿名页压缩线程3-211用以对匿名页进行压缩,以回收所述第三十二内存。所述PSI线程3-212用以监控系统资源压力。
创建模块3-22,所述创建模块3-22用以创建内存统计值及内存压力等级。
所述内存统计值用以表征系统内存中剩余的可用内存。所述第三十一内存为系统的空闲内存,所述第三十二内存为被占用但是可通过回收来转换为第三十一内存的内存。
所述内存统计值包括第三十一内存统计值,第三十二内存统计值及第三十三内存统计值。所述第三十二内存统计值小于所述第三十一内存统计值。所述第三十三内存统计值小于所述第三十二内存统计值。
所述内存压力等级包括第三十一等级,第三十二等级及第三十三等级。所述第三十三等级的内存压力高于所述第三十二等级的内存压力,所述第三十二等级的内存压力高于所述第三十一等级的内存压力。
上报模块3-23,所述上报模块3-23用以当系统当前的内存统计值低于所述第三十二内存统计值时,确认系统当前的内存压力等级为所述第三十一等级,并上报为第三十一级压力事件。所述上报模块3-23还用以当系统当前的 内存统计值低于所述第三十一内存统计值时,确认系统当前的内存压力等级为所述第三十二等级,并上报为第三十二级压力事件。
内存回收模块3-24,所述内存回收模块3-24用以根据所述第三十一级压力事件,启动所述匿名页压缩线程3-211,以进行匿名页压缩,进而回收所述第三十二内存。
可以理解,在本申请实施例中,所述上报模块3-23可通过匿名页压缩线程3-211来进行压力事件上报。
内存调整模块3-25,所述内存调整模块3-25用以根据所述第三十二级压力事件调整所述内存统计值。例如,当通过所述匿名页压缩线程3-211进行内存回收后,若系统当前的内存统计值未达到所述第三十一内存统计值high_buffer,则接收所述中级压力(mediuam-level-press)事件,并动态调整(例如下调)所述内存统计值。
所述内存回收模块3-24还用以当所述内存统计值逐步下调最低至所述第三十三内存统计值min_buffer,且系统当前的内存统计值仍未能达到所述第三十三内存统计值min_buffer时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
可以理解,所述上报模块3-23还用以监控交换区的空间使用率,且当当前所述交换区的空间使用率达到预设比例时,确认系统当前的内存压力等级为所述第三十三等级,并上报为第三十三级压力事件。所述内存回收模块3-24还用以根据所述第三十三级压力事件,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
可以理解,所述内存统计值还包括第三十四内存统计值,所述上报模块3-23还用以通过所述PSI线程3-212监控系统资源压力,且当系统当前的PSI值大于预设阈值时上报PSI压力值。所述内存回收模块3-24还用以当接收所述PSI压力值,且当系统当前的内存统计值小于所述第三十四内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
可以理解,所述内存回收模块3-24还用以监控是否有预设应用启动。当监控到有预设应用启动,且系统当前的内存统计值小于所述第三十一内存统计值时,所述内存回收模块3-24通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
可以理解,所述内存回收模块3-24可通过输出相应的kill命令,并根据所述kill命令来杀死进程。例如,每一个进程都有一个pid号作为唯一标识。所述kill命令中可包含相应的pid,如此所述内存回收模块3-24可根据所述进程号(pid)来杀死对应的进程。
可以理解的是,上述内存管理装置3-200中各个模块的划分仅用于举例说明,在其他的实施例中,可将所述内存管理装置3-200按照需要划分为不同的模块,以完成上述内存管理装置3-200的全部或部分功能。
本申请实施例中提供的内存管理装置中的各个模块的实现,可为计算机程序的形式。该计算机程序可在电子设备或服务器上运行。该计算机程序构成的程序模块可存储在终端或服务器的存储器上。该计算机程序被处理器执行时,实现本申请实施例中所描述的步骤。在本申请实施例中各个模块的具体实现还可以对应参照图3-2a至图3-5所示的方法实施例的相应描述。在图3-6所描述的内存管理装置中,可以有效改善内存管理效率低,造成内存供给不及时,应用保活数量低等问题。具体内容可以参见上述内存管理方法的具体实施例,在此不再详述。
请参阅图3-7,图3-7是本申请实施例中内存管理装置3-200的部分系统框架示意图。
可以理解,在本申请实施例中,以所述上报模块3-23通过匿名页压缩线程3-211来进行压力上报,并通过PSI线程3-212监控系统资源压力,且当系统当前的PSI值大于预设阈值时上报PSI压力值为例加以说明。
其中,所述匿名页压缩线程3-211和PSI线程3-212设置于下层,例如内核层。所述内存回收模块3-24,内存调整模块3-25设置于上层。所述上层为native层或应用框架(FWK)层。
可以理解,当系统当前的内存统计值低于所述第三十二内存统计值low_buffer时,所述上报模块3-23通过所述匿名页压缩线程3-211上报为低级压力(low-level-press)事件。所述上层在接收到所述低级压力(low-level-press)事件时,所述内存回收模块3-24可下发相应的回收参数至所述匿名页压缩线程3-211,以指导所述匿名页压缩线程3-211启动压缩处理,以进行内存回收。
当所述内存回收模块3-24通过所述匿名页压缩线程3-211经过一轮回收后,若系统当前的内存统计值未达到设定的所述第三十一内存统计值high_buffer,则所述上报模块3-23通过所述匿名页压缩线程3-211上报为中级压力(medium_level_press)事件。所述上层接收到所述中级压力(medium_level_press)事件时,通过所述内存调整模块3-25动态调整所述内存统计值。
当所述上层在时间窗口Δ内收到预设次数(例如n次)的所述中级压力(medium_level_press)事件,且所述内存统计值已调整至最低,即已调整至所述第三十三内存统计值min_buffer时,若再次监控到系统当前的内存统计值仍达不到所述第三十三内存统计值min_buffer,则所述上报模块3-23通过所述匿名页压缩线程3-211再次上报为中级压力(medium_level_press)事件。所述上层再通过所述内存回收模块3-24输出相应的kill命令,以通过杀死进程来回收第三十二内存,进而调整所述内存统计值至所述第三十三内存统计值min_buffer。
另外,在一些实施例中,所述上报模块3-23还可通过所述匿名页压缩线程3-211监控swap分区的空间使用率。当监控到当前swap分分区的空间使用率已达到一定比例,此时会导致所述内存统计值难以继续通过匿名页压缩的方式回收内存时,此时所述上报模块3-23通过所述匿名页压缩线程3-211上报为高级压力(critical_level_press)事件。当所述上层接收到所述高级压力 (medium_level_press)事件时,通过所述内存回收模块3-24输出相应的kill命令,以通过杀死进程来回收所述第三十二内存。
另外,在一些实施例中,所述上报模块3-23还可通过所述PSI线程3-212监控系统资源压力。当监控到当前的PSI压力值大于预设阈值时,进行PSI压力上报。所述上层接收到所述PSI压力上报事件,并确认系统当前的内存统计值是否低于所述第三十四内存统计值psi_buffer。当确定系统当前的内存统计值低于所述第三十四内存统计值psi_buffer时,通过所述内存回收模块3-24输出相应的kill命令,以通过杀死进程来回收所述第三十二内存。
另外,在一些实施例中,还可以监控是否有预设应用启动。当监控到有预设应用启动时,其进一步确定系统当前的内存统计值是否低于所述第三十一内存统计值high_buffer。当确定系统当前的内存统计值低于所述第三十一内存统计值high_buffer时,通过所述内存回收模块3-24输出相应的kill命令,以通过杀死进程来回收所述第三十二内存。
显然,上述三级内存压力场景,即低级压力(low-level-press)场景、中级压力(medium_level_press)场景及高级压力(critical_level_press)场景各自闭环,且总的内存水线管控又形成更高一级的闭环,最终实现内存水线的常稳管理。
可以理解,上述内存管理方法中,所述匿名页压缩线程基于多级内存统计值初步维持水线,并根据其工作状态分级(低级压力(low-level-press)场景、中级压力(medium_level_press),高级压力(critical_level_press)场景)上报内存压力,不同级别的内存压力下,所述上层将介入调整,例如调整内存回收参数,动态调整内存统计值,直接触发杀死进程,进而高效的维持内存统计值,提升应用保活。
可以理解,本申请实施例提供了一种基于用户行为模型及应用模型的kill方法,可有效提高kill的效率及准确性,维持了内存统计值,提高了应用保活情况。
在本申请一实施例中,为了更好的描述本申请,请参阅图3-8,如下将以一较大内存需求场景,例如相机应用启动为例,详细说明本申请的具体实施过程。
首先,在相机应用启动前,系统当前的内存统计值处于监控状态。如果当前后台存在内存消耗或者正在使用其他应用,则系统当前的内存统计值有可能已经低于所述第三十二内存统计值low_buffer,则唤醒所述匿名页压缩线程。
在唤醒所述匿名页压缩线程时,所述匿名页压缩线程上报为低级压力(low_level_press)事件。收到所述低级压力(low_level_press)事件时,所述上层根据应用特征下发回收参数,以指导所述匿名页压缩线程工作,即压缩匿名页以回收内存。通常所述匿名页压缩线程在回收结束时一般可以达到第三十一内存统计值high_buffer,为后续的相机启动维护一个较高的内存水线。
当启动相机应用时,将识别到所述应用是大内存消耗类应用。当收到相机启动消息时,确定系统当前的内存统计值是否满足所述第三十一内存统计值 high_buffer,即确定系统当前的内存统计值是否小于所述第三十一内存统计值high_buffer。当确定系统当前的内存统计值小于所述第三十一内存统计值high_buffer时,通过杀死进程来回收所述第三十二内存。
如果此时用户使用相机录像一段时间,即所述相机应用启动一段时间,在所述匿名页压缩线程回收结束时,若确定系统当前的内存统计值仍然达不到所设定的所述第三十一内存统计值high_buffer时,所述匿名页压缩线程将上报为中级压力(medium_level_press)事件。如此,当所述上层接收到中级压力(medium_level_press)事件时,会根据内存需求下调内存统计值,直至下调内存统计值至所述第三十三内存统计值min_buffer。
可以理解,如果所述内存统计值下调至所述第三十三内存统计值min_buffer后,所述匿名页压缩线程仍然无法维护,则会再次上报中级压力(medium_level_press)事件,以触发kill,进而上层根据所述第三十三内存阈值min_buffer以及系统当前的内存统计值,计算出需要kill的量,并根据可杀列表中的顺序kill到所述第三十三内存统计值min_buffer。
最后,当相机应用退出切回桌面,所述上层将下调的内存统计值重新抬高至所述第三十二内存统计值low_buffer,以进行一种常稳态的内存管理。
可以理解,在一些实施例中,当启动相机应用时,相机在短时间内消耗大量内存,以拉低内存统计值,虽然所述匿名页压缩线程会被唤醒进行内存回收,但是从内存统计值下调到所述第三十三内存统计值min_buffer的过程对于相机启动来说可能是缓慢的,所以除了大内存应用启动触发的kill,PSI压力上报kill将会是一个很好的补充。即当在内存统计值具有下降趋势的时候,也会及时触发kill。
可以理解,在一些实施例中,在上述过程中,如果在此前已经回收了大量应用的冷匿名页,swap分区的空间已满,则所述内核中的所述匿名页压缩线程将上报为高级压力(critical_level_press)事件。如此,当所述上层接收到高级压力(critical_level_press)事件时,亦直接触发kill。
显然,本申请实施例中的所述内存管理方法及装置至少具有以下优点:
(1)创建了一种新的内存统计值,根据公式(1),所述内存统计值计算对文件页活跃和不活跃部分的比例提供了可调参数,并添加了ION的可用内存部分。新定义的内存统计值能够更有效体现可用内存供给能力,更有效的体现内存压力情况。
(2)基于多级内存统计值,通过匿名页的并行压缩,实现多级内存统计值维持。多级内存统计值的设定,在内存压力较小时,可维持较高的内存统计值;内存压力较大时,避免匿名页压缩线程频繁唤起做低效回收或者空转,最终达到根据内存压力高效维持内存统计值长稳。
(3)采用多级内存压力上报机制以及多维kill机制。其中,内存压力基于匿名页压缩线程对内存统计值的维持情况,上报后根据不同级别的上报事件,选择调整内存回收参数、动态调整内存统计值、以及kill,形成内存统计值管理的 闭环,不仅达到回收效率最优,而且为内存轻载、重载全场景提供了必要的内存供应手段,最终达到应用保活的增加。
(4)基于用户行为模型及应用模型的kill方法,在内存压力不同的情况下选择了不同的kill方法,快速有效准确地维持了对应场景所需求的目标内存统计值,完成内存管理的闭环。
可以理解的是,上述电子设备为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请实施例能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请实施例的范围。
本申请实施例可以根据上述方法示例对上述电子设备进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
在采用集成的单元的情况下,图3-9示出了上述实施例中所涉及的电子设备的一种可能的结构示意图。该电子设备300包括处理单元3-301和存储单元3-302。
其中,处理单元3-301,用于对所述电子设备300的动作进行控制管理。
存储单元3-302,用于保存所述电子设备300的指令和数据,上述指令可以用于执行如图3-2a至图3-5及相应实施例中的各个步骤。
本申请实施例还可提供一种计算机存储介质,所述计算机存储介质中存储有计算机程序代码,当上述电子设备执行所述计算机程序代码时,所述电子设备可执行图3-2a至图3-5中的相关方法步骤,以实现上述实施例中的方法。
本申请实施例还可提供一种计算机程序产品,当所述计算机程序产品在计算机上运行时,使得计算机执行图3-2a至图3-5中的相关方法步骤,以实现上述实施例中的方法。
可以理解,本申请实施例提供的电子设备、计算机存储介质或者计算机程序产品均可用于执行上述所提供的对应的方法,因此,其所能达到的有益效果可参考上述所提供的对应的方法中的有益效果,在此不再赘述。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
在本申请所提供的几个实施例中,应所述理解到,所揭露的系统和方法,可以通过其它的方式实现。例如,以上所描述的系统实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划 分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以使用硬件的形式实现,也可以使用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者所述技术方案的全部或部分可以以软件产品的形式体现出来,所述软件产品存储在一个存储介质中,包括若干指令用以使得一个设备(可以是单片机,芯片等)或处理器(processor)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、ROM、磁碟或者光盘等各种可以存储程序代码的介质。
可以理解,当前移动终端等嵌入式设备的内存状况与固定终端或服务器的内存状况区别越来越大。一方面,适用于服务器的内存管控策略可能在移动终端设备上不能很好的工作。另一方面,移动终端新的用户体验也对内存管控提出了新的需求,比如相机设备配置的升级对内存的需求越来越大。对此,安卓(Android)已经针对移动终端的内存需求特点做了很多调整工作。目前,Android的内存管理方法主要是基于MemFree的内存水线管控。该种方案中,所述内存水线不包含能够通过快速回收获得的内存,当MemFree较低时,内存压力已经非常大,触发回收以及kill时机滞后,不仅影响应用保活,甚至可能因为内存不足(Out Of Memory,OOM)出现Panic,影响用户体验。其中,MemFree是指空闲内存数,表示系统的整个内存空间中还未分配的、处于空闲状态的剩余内存空间的容量。其中,MemUsed=MemTotal-MemFree,MemUsed表示已被使用过的内存。例如,电子设备的内存空间总大小为4G,其中有3G已经分配给一个或者多个运行中的进程使用,另外1G处于空闲状态,则所述电子设备当前的空闲内存数为1G。MemTotal是指内存总数,系统从加电开始到引导完成,BIOS等要保留一些内存,内核要保留一些内存,最后剩下可供系统支配的内存就是MemTotal。这个值在系统运行期间一般是固定不变的。
另外,还存在一种基于MemAvailble的内存管理方法。所述方法主要是通过kill来进行水线维持。然而,水线设置过高,在内存压力较小时容易造成过杀,影响保活。水线设置较低,在内存压力过大时仍然会存在和MemFree水线管控同样的问题。例如,在内存需求量较大较快的场景,如相机、游戏这类场景下,会出现内存不足造成过杀,甚至出现内存分配速度慢导致应用无响应,严重影响用户体验。而且MemAvailble水线设置比较敏感,不同的设备内存需求不同,很难统一水线。再者,第二种方法中除了kill也有伴随一些内存回收的动作,但是 仅仅通过上层单向指导内存回收,无法形成上下统一的闭环,内存回收的效率、效果都无法保证。容易造成回收频繁启动引入功耗问题、回收空转造成回收效率问题、过度回收造成的refault问题,最终不能有效维持内存水线,反而给系统造成更大压力。其中,MemAvailable是指可用内存数,系统中有些内存虽然已被使用但是可以回收的,比如cache/buffer、slab都有一部分可以回收,所以MemFree不能代表全部可用的内存,这部分可回收的内存加上MemFree才是系统可用的内存,即:MemAvailable≈MemFree+Buffers+Cached,它是内核使用特定的算法计算出来的,是一个估计值。
本申请实施例提供一种内存管理方法、装置、电子设备及计算机可读存储介质,用以解决内存管理效率低,造成内存供给不及时,应用保活数量低的问题。
可以理解,本申请实施例提供的内存管理方法的执行主体可以是本申请实施例提供的内存管理装置,或者集成了所述内存管理装置的电子设备。其中,所述内存管理装置可以采用硬件或者软件的方式实现。所述电子设备也可称为用户设备(User Equipment,UE)、移动台(Mobile Station,MS)、移动终端(Mobile Terminal)等。可选地,所述电子设备可以具备无线接入网(Radio Access Nework,RAN)与一个或多个核心网进行通信的能力,例如,所述电子设备可以是移动电话(或称为“蜂窝”电话)、平板电脑、掌上电脑、笔记本电脑、或者台式电脑等设备。所述电子设备的操作系统可以包括,但不限于,Linux系统、Android(安卓)系统、IOS操作系统、Symbian(塞班)操作系统、Black Berry(黑莓)操作系统、Windows Phone 8操作系统等等。可以理解,本申请实施例提供的内存管理方法主要应用于具有Android操作系统的电子设备。
以手机为上述电子设备举例,图3-1示出了电子设备3-100的结构示意图。
如图3-1所示,电子设备3-100可以包括处理器3-110,外部存储器接口3-120,内部存储器3-121,通用串行总线(universal serial bus,USB)接口3-130,充电管理模块3-140,电源管理模块3-141,电池3-142,天线3-1,天线3-2,移动通信模块3-150,无线通信模块3-160,音频模块3-170,扬声器3-170A,受话器3-170B,麦克风3-170C,耳机接口3-170D,传感器模块3-180,按键3-190,马达3-191,指示器3-192,摄像头3-193,显示屏3-194,以及用户标识模块(subscriber identification module,SIM)卡接口3-195等。其中传感器模块3-180可以包括压力传感器3-180A,陀螺仪传感器3-180B,气压传感器3-180C,磁传感器3-180D,加速度传感器3-180E,距离传感器3-180F,接近光传感器3-180G,指纹传感器3-180H,温度传感器3-180J,触摸传感器3-180K,环境光传感器3-180L,骨传导传感器3-180M等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备3-100的具体限定。在本申请另一些实施例中,电子设备3-100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器3-110可以包括一个或多个处理单元,例如:处理器3-110可以 包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器3-110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器3-110中的存储器为高速缓冲存储器。该存储器可以保存处理器3-110刚用过或循环使用的指令或数据。如果处理器3-110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器3-110的等待时间,因而提升了系统的效率。
在一些实施例中,处理器3-110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
I2C接口是一种双向同步串行总线,包括一根串行数据线(serial data line,SDA)和一根串行时钟线(derail clock line,SCL)。在一些实施例中,处理器3-110可以包含多组I2C总线。处理器3-110可以通过不同的I2C总线接口分别耦合触摸传感器3-180K,充电器,闪光灯,摄像头3-193等。例如:处理器3-110可以通过I2C接口耦合触摸传感器3-180K,使处理器3-110与触摸传感器3-180K通过I2C总线接口通信,实现电子设备3-100的触摸功能。
I2S接口可以用于音频通信。在一些实施例中,处理器3-110可以包含多组I2S总线。处理器3-110可以通过I2S总线与音频模块3-170耦合,实现处理器3-110与音频模块3-170之间的通信。在一些实施例中,音频模块3-170可以通过I2S接口向无线通信模块3-160传递音频信号,实现通过蓝牙耳机接听电话的功能。
PCM接口也可以用于音频通信,将模拟信号抽样,量化和编码。在一些实施例中,音频模块3-170与无线通信模块3-160可以通过PCM总线接口耦合。在一些实施例中,音频模块3-170也可以通过PCM接口向无线通信模块3-160传递音频信号,实现通过蓝牙耳机接听电话的功能。所述I2S接口和所述PCM接口都可以用于音频通信。
UART接口是一种通用串行数据总线,用于异步通信。该总线可以为双 向通信总线。它将要传输的数据在串行通信与并行通信之间转换。在一些实施例中,UART接口通常被用于连接处理器3-110与无线通信模块3-160。例如:处理器3-110通过UART接口与无线通信模块3-160中的蓝牙模块通信,实现蓝牙功能。在一些实施例中,音频模块3-170可以通过UART接口向无线通信模块3-160传递音频信号,实现通过蓝牙耳机播放音乐的功能。
MIPI接口可以被用于连接处理器3-110与显示屏3-194,摄像头3-193等外围器件。MIPI接口包括摄像头串行接口(camera serial interface,CSI),显示屏串行接口(display serial interface,DSI)等。在一些实施例中,处理器3-110和摄像头3-193通过CSI接口通信,实现电子设备3-100的拍摄功能。处理器3-110和显示屏3-194通过DSI接口通信,实现电子设备3-100的显示功能。
GPIO接口可以通过软件配置。GPIO接口可以被配置为控制信号,也可被配置为数据信号。在一些实施例中,GPIO接口可以用于连接处理器3-110与摄像头3-193,显示屏3-194,无线通信模块3-160,音频模块3-170,传感器模块3-180等。GPIO接口还可以被配置为I2C接口,I2S接口,UART接口,MIPI接口等。
USB接口3-130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口3-130可以用于连接充电器为电子设备3-100充电,也可以用于电子设备3-100与外围设备之间传输数据。也可以用于连接耳机,通过耳机播放音频。该接口还可以用于连接其他电子设备,例如AR设备等。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备3-100的结构限定。在本申请另一些实施例中,电子设备3-100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块3-140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块3-140可以通过USB接口3-130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块3-140可以通过电子设备3-100的无线充电线圈接收无线充电输入。充电管理模块3-140为电池3-142充电的同时,还可以通过电源管理模块3-141为电子设备供电。
电源管理模块3-141用于连接电池3-142,充电管理模块3-140与处理器3-110。电源管理模块3-141接收电池3-142和/或充电管理模块3-140的输入,为处理器3-110,内部存储器3-121,显示屏3-194,摄像头3-193,和无线通信模块3-160等供电。电源管理模块3-141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块3-141也可以设置于处理器3-110中。在另一些实施例中,电源管理模块3-141和充电管理模块3-140也可以设置于同一个器件中。
电子设备3-100的无线通信功能可以通过天线3-1,天线3-2,移动通信模块3-150,无线通信模块3-160,调制解调处理器以及基带处理器等实现。
天线3-1和天线3-2用于发射和接收电磁波信号。电子设备3-100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线3-1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块3-150可以提供应用在电子设备3-100上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块3-150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块3-150可以由天线3-1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块3-150还可以对经调制解调处理器调制后的信号放大,经天线3-1转为电磁波辐射出去。在一些实施例中,移动通信模块3-150的至少部分功能模块可以被设置于处理器3-110中。在一些实施例中,移动通信模块3-150的至少部分功能模块可以与处理器3-110的至少部分模块被设置在同一个器件中。
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器3-170A,受话器3-170B等)输出声音信号,或通过显示屏3-194显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器3-110,与移动通信模块3-150或其他功能模块设置在同一个器件中。
无线通信模块3-160可以提供应用在电子设备3-100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块3-160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块3-160经由天线3-2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器3-110。无线通信模块3-160还可以从处理器3-110接收待发送的信号,对其进行调频,放大,经天线3-2转为电磁波辐射出去。
在一些实施例中,电子设备3-100的天线3-1和移动通信模块3-150耦合,天线3-2和无线通信模块3-160耦合,使得电子设备3-100可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple  access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。
电子设备3-100通过GPU,显示屏3-194,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏3-194和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器3-110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏3-194用于显示图像,视频等。显示屏3-194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备3-100可以包括1个或N个显示屏3-194,N为大于1的正整数。
电子设备3-100可以通过ISP,摄像头3-193,视频编解码器,GPU,显示屏3-194以及应用处理器等实现拍摄功能。
ISP用于处理摄像头3-193反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头3-193中。
摄像头3-193用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备3-100可以包括1个或N个摄像头3-193,N为大于1的正整数。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备3-100在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。电子设备3-100可以支持一种或多种视频编解码器。这样,电子设备3-100可以播放或录制多种编码 格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备3-100的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。
内部存储器3-121可以包括一个或多个随机存取存储器(random access memory,RAM)和一个或多个非易失性存储器(non-volatile memory,NVM)。
随机存取存储器可以包括静态随机存储器(static random-access memory,SRAM)、动态随机存储器(dynamic random access memory,DRAM)、同步动态随机存储器(synchronous dynamic random access memory,SDRAM)、双倍资料率同步动态随机存取存储器(double data rate synchronous dynamic random access memory,DDR SDRAM,例如第五代DDR SDRAM一般称为DDR5SDRAM)等。
非易失性存储器可以包括磁盘存储器件、快闪存储器(flash memory)。
快闪存储器按照运作原理划分可以包括NOR FLASH、NAND FLASH、3D NAND FLASH等,按照存储单元电位阶数划分可以包括单阶存储单元(single-level cell,SLC)、多阶存储单元(multi-level cell,MLC)、三阶储存单元(triple-level cell,TLC)、四阶储存单元(quad-level cell,QLC)等,按照存储规范划分可以包括通用闪存存储(universal flash storage,UFS)、嵌入式多媒体存储卡(embedded multi-media Card,eMMC)等。
随机存取存储器可以由处理器3-110直接进行读写,可以用于存储操作系统或其他正在运行中的程序的可执行程序(例如机器指令),还可以用于存储用户及应用程序的数据等。
非易失性存储器也可以存储可执行程序和存储用户及应用程序的数据等,可以提前加载到随机存取存储器中,用于处理器3-110直接进行读写。
外部存储器接口3-120可以用于连接外部的非易失性存储器,实现扩展电子设备3-100的存储能力。外部的非易失性存储器通过外部存储器接口3-120与处理器3-110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部的非易失性存储器中。
电子设备3-100可以通过音频模块3-170,扬声器3-170A,受话器3-170B,麦克风3-170C,耳机接口3-170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块3-170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块3-170还可以用于对音频信号编码和解码。在一些实施例中,音频模块3-170可以设置于处理器3-110中,或将音频模块3-170的部分功能模块设置于处理器3-110中。
扬声器3-170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子 设备3-100可以通过扬声器3-170A收听音乐,或收听免提通话。
受话器3-170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备3-100接听电话或语音信息时,可以通过将受话器3-170B靠近人耳接听语音。
麦克风3-170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风3-170C发声,将声音信号输入到麦克风3-170C。电子设备3-100可以设置至少一个麦克风3-170C。在另一些实施例中,电子设备3-100可以设置两个麦克风3-170C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备3-100还可以设置三个,四个或更多麦克风3-170C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。
耳机接口3-170D用于连接有线耳机。耳机接口3-170D可以是USB接口3-130,也可以是3、5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。
压力传感器3-180A用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器3-180A可以设置于显示屏3-194。压力传感器3-180A的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器3-180A,电极之间的电容改变。电子设备3-100根据电容的变化确定压力的强度。当有触摸操作作用于显示屏3-194,电子设备3-100根据压力传感器3-180A检测所述触摸操作强度。电子设备3-100也可以根据压力传感器3-180A的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第三十一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第三十一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。
陀螺仪传感器3-180B可以用于确定电子设备3-100的运动姿态。在一些实施例中,可以通过陀螺仪传感器3-180B确定电子设备3-100围绕三个轴(即,x,y和z轴)的角速度。陀螺仪传感器3-180B可以用于拍摄防抖。示例性的,当按下快门,陀螺仪传感器3-180B检测电子设备3-100抖动的角度,根据角度计算出镜头模组需要补偿的距离,让镜头通过反向运动抵消电子设备3-100的抖动,实现防抖。陀螺仪传感器3-180B还可以用于导航,体感游戏场景。
气压传感器3-180C用于测量气压。在一些实施例中,电子设备3-100通过气压传感器3-180C测得的气压值计算海拔高度,辅助定位和导航。
磁传感器3-180D包括霍尔传感器。电子设备3-100可以利用磁传感器 3-180D检测翻盖皮套的开合。在一些实施例中,当电子设备3-100是翻盖机时,电子设备3-100可以根据磁传感器3-180D检测翻盖的开合。进而根据检测到的皮套的开合状态或翻盖的开合状态,设置翻盖自动解锁等特性。
加速度传感器3-180E可检测电子设备3-100在各个方向上(一般为三轴)加速度的大小。当电子设备3-100静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。
距离传感器3-180F,用于测量距离。电子设备3-100可以通过红外或激光测量距离。在一些实施例中,拍摄场景,电子设备3-100可以利用距离传感器3-180F测距以实现快速对焦。
接近光传感器3-180G可以包括例如发光二极管(LED)和光检测器,例如光电二极管。发光二极管可以是红外发光二极管。电子设备3-100通过发光二极管向外发射红外光。电子设备3-100使用光电二极管检测来自附近物体的红外反射光。当检测到充分的反射光时,可以确定电子设备3-100附近有物体。当检测到不充分的反射光时,电子设备3-100可以确定电子设备3-100附近没有物体。电子设备3-100可以利用接近光传感器3-180G检测用户手持电子设备3-100贴近耳朵通话,以便自动熄灭屏幕达到省电的目的。接近光传感器3-180G也可用于皮套模式,口袋模式自动解锁与锁屏。
环境光传感器3-180L用于感知环境光亮度。电子设备3-100可以根据感知的环境光亮度自适应调节显示屏3-194亮度。环境光传感器3-180L也可用于拍照时自动调节白平衡。环境光传感器3-180L还可以与接近光传感器3-180G配合,检测电子设备3-100是否在口袋里,以防误触。
指纹传感器3-180H用于采集指纹。电子设备3-100可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。
温度传感器3-180J用于检测温度。在一些实施例中,电子设备3-100利用温度传感器3-180J检测的温度,执行温度处理策略。例如,当温度传感器3-180J上报的温度超过阈值,电子设备3-100执行降低位于温度传感器3-180J附近的处理器的性能,以便降低功耗实施热保护。在另一些实施例中,当温度低于另一阈值时,电子设备3-100对电池3-142加热,以避免低温导致电子设备3-100异常关机。在其他一些实施例中,当温度低于又一阈值时,电子设备3-100对电池3-142的输出电压执行升压,以避免低温导致的异常关机。
触摸传感器3-180K,也称“触控器件”。触摸传感器3-180K可以设置于显示屏3-194,由触摸传感器3-180K与显示屏3-194组成触摸屏,也称“触控屏”。触摸传感器3-180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏3-194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器3-180K也可以设置于电子设备3-100的表面,与显示屏3-194所处的位置不同。
骨传导传感器3-180M可以获取振动信号。在一些实施例中,骨传导传感器3-180M可以获取人体声部振动骨块的振动信号。骨传导传感器3-180M也可以接触人体脉搏,接收血压跳动信号。在一些实施例中,骨传导传感器3-180M也可以设置于耳机中,结合成骨传导耳机。音频模块3-170可以基于所述骨传导传感器3-180M获取的声部振动骨块的振动信号,解析出语音信号,实现语音功能。应用处理器可以基于所述骨传导传感器3-180M获取的血压跳动信号解析心率信息,实现心率检测功能。
按键3-190包括开机键,音量键等。按键3-190可以是机械按键。也可以是触摸式按键。电子设备3-100可以接收按键输入,产生与电子设备3-100的用户设置以及功能控制有关的键信号输入。
马达3-191可以产生振动提示。马达3-191可以用于来电振动提示,也可以用于触摸振动反馈。例如,作用于不同应用(例如拍照,音频播放等)的触摸操作,可以对应不同的振动反馈效果。作用于显示屏3-194不同区域的触摸操作,马达3-191也可对应不同的振动反馈效果。不同的应用场景(例如:时间提醒,接收信息,闹钟,游戏等)也可以对应不同的振动反馈效果。触摸振动反馈效果还可以支持自定义。
指示器3-192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。
SIM卡接口3-195用于连接SIM卡。SIM卡可以通过插入SIM卡接口3-195,或从SIM卡接口3-195拔出,实现和电子设备3-100的接触和分离。电子设备3-100可以支持1个或N个SIM卡接口,N为大于1的正整数。SIM卡接口3-195可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM卡接口3-195可以同时插入多张卡。所述多张卡的类型可以相同,也可以不同。SIM卡接口3-195也可以兼容不同类型的SIM卡。SIM卡接口3-195也可以兼容外部存储卡。电子设备3-100通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备3-100采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备3-100中,不能和电子设备3-100分离。
下面结合附图,以执行主体为电子设备3-100为例,对本申请实施例提供的内存管理方法进行详细介绍。
图3-2a示出根据本申请实施例提供的一种内存管理方法的流程示意图。如图3-2a所示,所述内存管理方法可以包括S3-20-S3-211:
步骤S3-20,创建内存统计值及内存压力等级。
可以理解,所述内存统计值用于表征电子设备的系统内存中剩余的可用内存,其通常用水线(watermark)参数来表征。例如内存水线越低,表明剩余的可用系统内存越少。水线(watermark)为内存管理区中的一个数组,所述内存水线通常包括三个水线值,即WMARK_HIGH(高水线)、WMARK_LOW(低水线)、WMARK_MIN(最小水线)。其中,WMARK_HIGH>WMARK_LOW>WMARK_MIN。通常,在分配页(page) 之前,需要先检查watermark。例如,当空闲页大于WMARK_HIGH时,说明电子设备的系统内存状态是理想的,暂不需要进行内存回收。当空闲页低于WMARK_LOW时,则说明电子设备的系统内存不足,需要进行内存回收。当空闲页低于WMARK_MIN时,则说明电子设备的系统内存严重不足,例如内存域中的可用空闲页已经很少了,必须加快进行内存回收。
可以理解,本申请实施例中的可用内存包括两部分,例如第三十一内存和第三十二内存。其中,所述第三十一内存是指系统的空闲内存。所述空闲内存是指系统尚未使用的内存,即MemFree。所述第三十二内存为被占用但是可通过回收来转换为第三十一内存的内存。所述被占用内存主要指当前正在运行的进程和服务所占用的内存以及内核运行所占用的内存。
可以理解,请一并参阅下述公式(1),本申请实施例中定义的所述内存水线可由所述公式(1)获得。
buffer=freemem+α*inactive_file+β*active_file+ion_cache  (1)
其中,Buffer为缓冲区内存数,也被称write-buffer,一般用在写操作。Cache为缓存区内存数,也被称read-cache,一般用在读操作。
在本申请实施例中,参数buffer为所述内存水线。参数freemem为所述第三十一内存中的空闲内存。参数inactive_file为不活跃文件内存。参数active_file为活跃文件内存。参数ion_cache为ION内存管理器的可用内存(cache)。其中缓存(cache)是把读取过的数据保存起来,重新读取时若命中(找到需要的数据)就不要去读硬盘了,若没有命中就读硬盘。所述参数inactive_file,active_file和ion_cache共同构成所述第三十二内存中被占用但是可通过回收来供给的内存。参数α、β为可调参数。具体地,所述参数α、β可以根据不同产品的规格进行相应的调整,即选择不同的比例或折扣。
可以理解,在本申请实施例中,并不对所述第三十一内存和第三十二内存进行限定。例如所述第三十二内存还可以为其他被占用但是可供给或回收的内存,而不局限于不活跃文件内存和/或活跃文件内存。
可以理解,根据上述公式(1),所述内存统计值的创建综合考虑了可快速回收内存的供应,提供了针对文件页(file page)供应的可调参数,使得内存统计值设定更加合理。即所述内存统计值能够更有效地体现可用内存供给能力,更有效地体现内存压力情况。
可以理解,在本申请实施例中,所述内存统计值包括第三十一内存统计值,第三十二内存统计值及第三十三内存统计值。所述第三十一内存统计值对应上述水线(watermark)中的WMARK_HIGH,以下统称为high_buffer。所述第三十二内存统计值可对应上述水线(watermark)中的WMARK_LOW,以下统称为low_buffer。所述第三十三内存统计值对应上述水线(watermark)中的WMARK_MIN,以下统称为min_buffer。其中,所述第三十二内存统计值小于所述第三十一内存统计值。所述第三十三内存统计值小于所述第三十二内存统计值。
可以理解,本申请实施例中,所述内存压力等级包括第三十一等级,第三十二等级,及第三十三等级。所述电子设备还可预先设定所述内存压力等级,例如所述第三十一等级对应低级,所述第三十二等级对应中级,所述第三十三等级对应高级。其中,高级(critical_level_press)表征内存压力较大。中级(medium_level_press)表征内存压力适中,低级(low_level_press)表征内存压力较小。即所述第三十三等级的内存压力高于所述第三十二等级的内存压力,所述第三十二等级的内存压力高于所述第三十一等级的内存压力。所述内存压力等级可以根据系统当前的内存统计值来确定。例如,若系统当前的内存统计值小于第三十二内存统计值,可以确定系统当前的内存压力等级为第三十一等级(例如低级)。当经过系统内存回收后,若系统当前的内存统计值小于第三十一内存统计值,可以确定系统当前的内存压力等级为第三十二等级(例如中级),当系统当前的内存统计值小于第三十三内存统计值时,可以确定系统当前的内存压力等级为第三十三等级(例如高级)。
可选的,所述内存统计值可以是静态预置的。具体的,有如下几种情况:
(1)根据产品规格配置内存统计值
针对2G/3G/4G/6G随机存取存储器(Random Access Memory,RAM)的产品,系统的可用内存不同,相应的,内存统计值也不同。比如:针对3G RAM的产品,可以配置内存统计值为600MB,针对4GRAM的产品,可以配置内存统计值为700MB。
(2)根据应用场景配置尽可能小的内存统计值
不同的应用及其不同的场景,对于内存的耗费是不同的。因此要想配置合理的内存统计值,采用方式(1)存在一些弊端,可能会因为没有考虑某个第三方应用而出现该应用启动时卡顿的现象。针对此类问题,可以通过离线分析应用市场中排名靠前的第三方应用,获取各类应用在各个场景中最大的内存占用信息,并设置内存统计值为该应用的最大占用内存。
又如,考虑到在灭屏场景下要降低灭屏后台功耗,以及要解决亮屏瞬间应用集中唤醒带来的内存冲击场景,可将所述内存统计值在灭屏场景和亮屏场景分别设置为两个不同的值,且处于灭屏场景时的内存统计值均低于亮屏场景下的内存统计值。例如,灭屏场景下的所述第三十一内存统计值低于亮屏场景下的所述第三十一内存统计值。灭屏场景下的所述第三十二内存统计值低于亮屏场景下的所述第三十二内存统计值。灭屏场景下的所述第三十三内存统计值低于亮屏场景下的所述第三十三内存统计值。
(3)根据系统运行进程历史占用内存进行配置
由于每个用户都有自己的特点,终端被长时间使用后,终端上安装和运行的应用并不一致,可以根据系统运行进程历史占用内存来配置内存统计值。具体的,可以在用户不使用终端的时候(比如半夜)查询每个进程运行时内存占用的历史状态信息(procstats),获取其中最大的内存占用信息(如应用程序名称、最大占用内存),进一步地,将最大占用内存和当前系统的内 存统计值比较,若最大占用内存大于当前系统的内存统计值,则选取该最大占用内存作为系统新的内存统计值。
(4)通过云端下发配置内存统计值
云端服务器可以根据终端的标识收集在终端上运行的所有应用在各个场景占用的内存信息,将占用内存大于预设值(如300MB)的应用名及该应用当时的运行场景等信息形成一张表单,定期(如每月)将该表单推送给终端,终端接收到表单后,将此表单中的应用信息和本地应用列表进行遍历,并确定终端上安装的应用的最大内存占用信息,进一步地,将最大占用内存和当前系统的内存统计值进行比较,若最大占用内存大于当前系统的内存统计值,则选取该最大占用内存作为系统新的内存统计值。
可选的,该内存统计值还可以是动态配置的。
具体的,可以通过用户行为分析算法,根据用户使用习惯、应用使用历史、使用频率、使用时长等信息,根据预测算法,预测出接下来最有可能运行的应用,并形成应用列表,获取应用列表中的应用需要使用的最大内存,并将最大内存和当前系统的内存统计值相比,若最大内存大于当前系统的内存统计值,则选取该最大内存作为系统新的内存统计值。
步骤S3-21,监控系统当前的内存统计值。
步骤S3-22,确定系统当前的内存统计值是否低于所述第三十二内存统计值low_buffer。
其中,若确定系统当前的内存统计值低于所述第三十二内存统计值low_buffer,则执行步骤S3-23。若确定系统当前的内存统计值不低于所述第三十二内存统计值low_buffer,则返回步骤S3-21,即继续监控系统当前的内存统计值。
步骤S3-23,当确定系统当前的内存统计值低于所述第三十二内存统计值low_buffer,唤醒匿名页压缩线程,以准备回收内存。
可以理解,一般内核在进行内存压缩处理时,会选择匿名页作为内存压缩处理的对象。其中,匿名页为应用程序动态分配的堆内存的内存页。由于匿名页很可能还要再次被访问,不能直接回收,这些内存自然不能直接释放。因此,采用内存压缩的方式间接地释放他们所占的内存空间。例如,先确定已分配内存页中的匿名页,从全部匿名页中选择一定数量的内存页作为目标内存页,并进行压缩,以达到增大空闲内存的目的。
步骤S3-24,确定系统当前的内存压力等级为第三十一级,并上报为第三十一级压力事件(例如低级压力(low_level_press)事件)至上层。
步骤S3-25,所述上层接收所述低级压力(low_level_press)事件,并根据应用特征来配置并下发回收参数至所述匿名页压缩线程,以指导所述匿名页压缩线程回收内存。
步骤S3-26,接收所述回收参数,并根据所述回收参数通过匿名页压缩线程启动压缩处理,以进行内存回收。即回收第三十二内存,以将所述第三 十二内存转换为所述第三十一内存。
可以理解,所述上层可以为native层或应用框架层(FWK)。
可以理解,所述回收参数包括,但不限于,目标内存页的数量,目标内存页回收的优先级,和/或内存回收比例(ratio)等。其中,目标内存页的数量可以根据系统当前的内存统计值大小和所述第三十二内存统计值low_buffer来确定。例如,根据所述第三十二内存统计值low_buffer与系统当前的内存统计值的大小的差值确定待回收的内存量,再根据待回收的内存量和期望压缩率,计算需要的目标内存页的数量。
如此,所述匿名页压缩线程可根据上述回收参数启动压缩处理。例如对目标内存页进行压缩,并将压缩后的内存页写入内存空间中的内存压缩空间中,以释放这些目标内存页占用的一部分内存空间。后续,当系统需要再使用这些内存页时,从内存压缩空间中找到压缩后的内存页,将其解压后使用。
例如,假设系统当前的内存统计值大小为10M,所述第三十二内存统计值low_buffer为20M。因此可得出需要释放的内存空间为10M,假设期望压缩率为50%,则可以计算得到需要进行压缩处理的内存大小为10M÷50%=20M。接着从匿名页中获取20M的目标内存页,对这些内存页进行压缩处理,可以得到10M的内存空间。其中,压缩率为压缩后的内存页的大小与原始内存页的大小之间的比例。期望压缩率可以为一个预设的经验值。
步骤S3-27,当通过匿名压缩完成一次内存回收后,确定系统当前的内存统计值是否低于所述第三十一内存统计值high_buffer。
若确定系统当前的内存统计值低于所述第三十一内存统计值high_buffer,则执行步骤S3-28。若确定系统当前的内存统计值不低于所述第三十一内存统计值high_buffer,则返回步骤S3-21,即继续监控系统当前的内存统计值。
步骤S3-28,当确定系统当前的内存统计值低于所述第三十一内存统计值high_buffer时,确认系统当前的内存压力等级为所述第三十二等级,并通过所述匿名页压缩线程上报为第三十二级压力事件(例如中级压力(medium_level_press)事件)至所述上层。
步骤S3-29,所述上层接收所述中级压力(medium_level_press)事件,并调整(例如下调)所述内存统计值。
可以理解,通常所述匿名页压缩线程在回收结束时一般可以达到所述第三十一内存统计值high_buffer,如此使得系统有足够的空闲资源,以为后续的应用启动,例如相机启动维护一个较高的内存统计值。
另外,通过所述匿名页压缩线程进行内存回收,使所述内存统计值达到所述第三十一内存统计值high_buffer,即使得所述内存统计值达到一个较高的水平。如此,亦可有效防止造成回收频繁启动引入功耗问题、回收空转造成回收效率问题、过度回收造成的refault问题等。
可以理解,在本申请实施例中,当所述匿名页压缩线程在回收结束时,若系统当前的内存统计值仍达不到所设定的第三十一内存统计值high_buffer, 则对所述内存统计值进行调整,例如下调所述内存统计值。
步骤S3-210,确定系统当前的内存统计值是否低于所述第三十三内存统计值min_buffer。
若确定系统当前的内存统计值低于所述第三十三内存统计值min_buffer,则执行步骤S3-211。若确定系统当前的内存统计值不低于所述第三十三内存统计值min_buffer,则返回步骤S3-26,即继续启动所述匿名页压缩线程进行内存回收。
步骤S3-211,当确定系统当前的内存统计值低于所述第三十三内存统计值min_buffer,再次上报为中级压力(medium_level_press)事件,并通过杀(kill)死进程来回收所述第三十二内存,并返回步骤S3-21,即继续监控系统当前的内存统计值。
可以理解,在本申请实施例中,当所述上层在时间窗口Δ内收到预设次数(例如n次)的中级压力(medium_level_press)事件时,所述内存统计值逐渐下调至所述第三十三内存统计值min_buffer。其中,所述上层下调所述内存统计值是指,当所述上层接收到中级压力(medium_level_press)事件时,其根据系统当前的内存统计值将所述第三十二内存统计值low_buffer及所述第三十一内存统计值high_buffer同时下调,其下调的值为所述第三十一内存统计值high_buffer与系统当前的内存统计值的差值。若经过所述匿名页压缩进程的内存回收,仍无法维护所述第三十三内存统计值min_buffer,即系统当前的内存统计值仍低于所述第三十三内存统计值min_buffer,则在再次上报中级压力(medium_level_press)事件时通过杀(kill)死进程来回收所述第三十二内存。
可以理解,在确定满足杀死进程的触发条件,例如当系统当前的内存统计值仍低于所述第三十三内存统计值min_buffer时,则可以进一步根据所述第三十三内存统计值min_buffer以及系统当前的内存统计值确定需要杀的量及需要杀的目标进程,即确定杀哪一个或哪些进程。也就是说,在确定满足杀死进程的触发条件时,可创建杀进程列表,再根据所述杀进程列表中进程的顺序执行来杀死进程,直至使得系统当前的内存统计值到达所述第三十三内存统计值min_buffer。
其中,所述杀进程列表为一个根据应用的重要程度,进程优先级和/或其他因素(例如应用匿名页大小及分布)进行排序的动态二维表,包括一个或多个应用的进程。即所述杀进程列表可以包括一个或多个应用,同时一个应用可以包括一个或多个进程。所述杀进程列表为根据应用的重要程度,进程优先级和/或其他因素排序后的列表。
具体的,创建所述杀进程列表的方式具体包括,但不限于,以下步骤:
(1)确定当前在后台运行的每个应用的关键因素的分值,所述关键因素包括以下中的一个或多个:进程优先级、用户使用习惯、进程占用系统资源以及应用的关联关系。
(2)针对每个所述应用,将所有所述关键因素的分值进行加权计算,获得所述应用的重要程度。
(3)根据所有所述应用的重要程度,对所有所述应用进行排序。
(4)根据进程优先级,对排序后的每个所述应用包括的进程进行排序,以生成杀进程列表。
在本申请实施例中,在终端后台运行的每个应用可以包括一个或多个进程,每个应用的关键因素包括以下中的一个或多个:进程优先级、用户使用习惯、进程占用系统资源以及应用的关联关系。每个关键因素都有相应的分值。基于应用的关键因素(进程优先级、用户使用习惯、进程占用系统资源以及应用的关联关系)来创建杀进程列表,后续就可以根据内存的需求从所述杀进程列表中确定需要处理的进程,这样就可以精确地选择可杀进程队列,减少错杀/多杀/少杀进程的概率。
其中,系统会对每个进程的重要性进行评估,进程的重要性也代表了进程优先级。通常,将重要性以oom_adj(out of memory adjust)这个数值表示出来,赋予各个进程,系统会根据oom_adj来判断需要结束哪些进程。一般,oom_adj的分值由系统提供,系统可以根据应用当前的运行状态来分配。通常oom_adj的分值越大,所述进程被系统选中终止的可能就越高,进程优先级就越低。
其中,用户使用习惯可以包括但不限于应用的使用时间记录、应用的累计使用次数、每次被使用的时长以及累计使用时长。根据用户使用习惯可以确定哪些进程为用户经常使用的应用的进程,或者确定哪些进程为用户使用时间较长的应用的进程,或者确定哪些进程为用户最近使用的应用的进程等等相关进程的信息。
其中,可通过随机森林等模型学习得到应用重要程度模型,结合应用使用频率,应用匿名页大小及分布和/或其他因素,得到所述杀进程列表。在杀死进程时,根据所述杀进程列表中的应用匿名页情况以及所需杀的量,得到所需杀的应用。
显然,如图3-2a所述,所述内存统计值包括第三十一内存统计值,第三十二内存统计值及第三十三内存统计值。所述第三十二内存统计值小于所述第三十一内存统计值。所述第三十三内存统计值小于所述第三十二内存统计值。如此,通过将系统当前的内存统计值与预设的所述第三十一内存统计值,第三十二内存统计值,第三十三内存统计值进行比较,进而可根据其比较结果采用不同的内存管理策略。
例如,请一并参阅图3-2b,当确定系统当前的内存统计值低于所述第三十二内存统计值时,可启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存。
当通过匿名页压缩后确定系统当前的内存统计值低于所述第三十一内存统计值时,可下调所述内存统计值。
当确定系统当前的内存统计值低于所述第三十三内存统计值时,可通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存,直至系统当前的内存统计值不低于所述第三十三内存统计值。
图3-3示出根据本申请实施例提供的另一种内存管理方法的流程示意图。如图3-3所示,所述内存管理方法在图3-2a的基础上,还可以包括步骤S3-30-S3-33。
步骤S3-30,监控swap分区的空间使用率。
在本申请实施例中,swap分区即交换区。通常内存可以包括正常使用区及交换区,当系统内存资源不足时,回收机制开始进行内存回收。回收机制开始对正常使用区中的数据进行压缩,并将压缩后的数据放入交换区中。若交换区中的数据量达到水线,则将交换区中的数据换出到外部存储中。
步骤S3-31,确定当前swap分区的空间使用率是否达到预设比例。若确定当前swap分区的空间使用率达到所述预设比例,则执行步骤S3-32。若确定当前swap分区的空间使用率未达到所述预设比例,则返回步骤S3-30,即继续监控swap分区的空间使用率。
步骤S3-32,当确定当前swap分区的空间使用率达到所述预设比例时,确认系统当前的内存压力等级为所述第三十三等级,并上报为第三十三级压力事件(例如高级压力(critical_level_press)事件)至所述上层。
步骤S3-33,根据所述高级压力(critical_level_press)事件,所述上层通过杀死进程来回收所述第三十二内存。
可以理解,当启动所述匿名页压缩线程,导致所述swap分区的空间使用率到达所述预设比例时,此时会导致所述内存统计值难以继续通过匿名页压缩的方式回收内存,此时所述匿名页压缩线程将上报所述高级压力(critical_level_press)事件,以触发所述上层通过杀死进程来回收所述第三十二内存。
例如,如果在此前已经回收了大量应用的冷匿名页,swap分区的空间已满,则所述匿名页压缩线程在本轮回收结束时,上报为高级压力(critical_level_press)事件,直接触发所述上层通过杀死进程来回收所述第三十二内存。
可以理解,步骤S3-33中的通过杀死进程来回收第三十二内存与图3-2a中步骤S3-211中的通过杀死进程来回收所述第三十二内存类似,以及相应的概念也是类似,在此不再赘述。
图3-4示出根据本申请实施例提供的另一种内存管理方法的流程示意图。如图3-4所示,所述内存管理方法在图3-2a和/或图3-3的基础上,还可以包括步骤S3-40-S3-44。
步骤S3-40,通过压力失速信息(Pressure Stall Information,PSI)线程来监控系统资源压力。PSI提供一种评估系统资源压力的方法。系统资源可以包括CPU资源、IO资源等,一旦产生资源竞争,就有可能带来延迟增大,使用户体验到卡顿。如果没有一种相对准确的方法检测系统的资源压力程度,有两种后果。一种是资源使用者过度克制,没有充分使用系统资源;另一种 是经常产生资源竞争,过度使用资源导致等待延迟过大。准确的检测方法可以帮忙资源使用者确定合适的工作量,同时也可以帮助系统制定高效的资源调度策略,最大化利用系统资源,最大化改善用户体验。对此,Facebook在2018年开源了一套解决重要计算集群管理问题的Linux内核组件和相关工具,PSI是其中重要的资源度量工具,用以提供一种实时检测系统资源竞争程度的方法,以竞争等待时间的方式呈现,可以更全面地判断当前系统压力,并简单而准确地供用户以及资源调度者进行决策。具体的,所述PSI用以将各个任务延迟汇总为资源压力指标,这些指标反映工作负载运行状况和资源利用率方面的问题。可以理解,在本申请实施例中,所述PSI线程考量的指标通常为供给应用的速度。在一种情况下,大内存消耗类应用,会在短时间内消耗大量内存,例如一下消耗到2G内存,但采用前面的方式(例如采用匿名压压缩的方式回收内存),其内存回收速度较慢,因此,可采用PSI线程触发系统资源压力的检测。PSI统计数据(即PSI值)可为即将发生的资源短缺提供早期预警,从而实现更积极主动、细致的响应。
步骤S3-41,确定系统当前的PSI值是否大于预设阈值。若确定系统当前的PSI值大于所述预设阈值时,执行步骤S3-42。若确定系统当前的PSI值不大于所述预设阈值时,返回步骤S3-40,即继续监控系统资源压力。
步骤S3-42,当确定系统当前的PSI值大于所述预设阈值时,所述PSI线程上报PSI压力值至所述上层。
步骤S3-43,所述上层接收所述PSI压力值,并确定系统当前的内存统计值是否小于第三十四内存统计值psi_buffer。
若确定系统当前的内存统计值小于所述第三十四内存统计值psi_buffer,则执行步骤S3-44。若确定系统当前的内存统计值不小于所述第三十四内存统计值psi_buffer,则返回步骤S3-40。
步骤S3-44:当确定系统当前的内存统计值小于所述第三十四内存统计值psi_buffer时,通过杀死进程来回收所述第三十二内存。
可以理解,在本申请实施例中,当PSI线程上报表明系统内存快速供给应用的速度较慢时,还需判断系统当前的内存统计值是否小于所述第三十四内存统计值psi_buffer。当系统当前的内存统计值不低于所述第三十四内存统计值psi_buffer时,说明当前系统还是可以为应用提供可用内存,只是其供给速度较慢。当系统当前的内存统计值低于所述第三十四内存统计值psi_buffer时,说明系统能为应用提供的可用内存不足,且供给速度较慢。此时,将直接通过杀死进程来回收所述第三十二内存。
可以理解,所述第三十四内存统计值psi_buffer小于所述第三十三内存统计值min_buffer。
可以理解,步骤S3-44中的通过杀死进程来回收所述第三十二内存与图3-2a中步骤S3-211中的通过杀死进程来回收所述第三十二内存、图3-3中步骤S3-33中的通过杀死进程来回收所述第三十二内存类似,以及相应的概念也 是类似,在此不再赘述。
图3-5示出根据本申请实施例提供的另一种内存管理方法的流程示意图。如图3-5所示,所述内存管理方法在图3-2a,图3-3和/或图3-4的基础上,还可以包括步骤S3-50-S3-52。
步骤S3-50,监控是否有预设应用启动。若监控到有预设应用启动,则执行步骤S3-51,若没有监控到预设应用的启动,则继续执行步骤S3-50。
可以理解,所述预设应用是指启动时会消耗大量内存的应用,例如一旦所述预设用以启动,将在短时间内消耗大量内存的应用。所述预设应用可以预先设置,并进行存储。
步骤S3-51,当监控到有预设应用启动时,进一步确定系统当前的内存统计值是否大于所述第三十一内存统计值high_buffer。若确定系统当前的内存统计值小于所述第三十一内存统计值high_buffer,则执行步骤S3-52。若确定系统当前的内存统计值不小于所述第三十一内存统计值high_buffer,则返回步骤S3-50。
步骤S3-52,当确定系统当前的内存统计值小于所述第三十一内存统计值high_buffer,通过杀死进程来回收所述第三十二内存。
可以理解,在本申请实施例中,如果应用内存需求过快,PSI压力上报仍然存在延迟,则无法及时通过杀死进程来回收第三十二内存。因此在大内存需求的应用启动场景下,例如相机启动,会在收到启动消息时,立刻触发通过杀死进程来回收所述第三十二内存。
可以理解,通常当大内存应用(例如相机)启动时,会在短时间内消耗大量内存,拉低内存统计值,所述匿名页压缩线程会被唤醒进行内存回收。但是从所述内存统计值下调到所述第三十三内存统计值min_buffer的过程对于相机启动来说可能是缓慢的,所以除了大内存应用启动触发的杀进程,PSI压力上报将会是一个很好的补充,在所述内存统计值具有下降趋势的时候,也会及时通过杀死进程来回收所述第三十二内存。
可以理解,步骤S3-52中的通过杀死进程来回收第三十二内存与图3-2a中步骤S3-211中的通过杀死进程来回收第三十二内存,图3-3中步骤S3-33中的通过杀死进程来回收第三十二内存,图3-4中步骤S3-44中的通过杀死进程来回收第三十二内存类似,以及相应的概念也是类似,在此不再赘述。
请再次参阅图3-2a至图3-5,显然,在本申请实施例中,通过杀死进程来回收所述第三十二内存至少存在以下四种情况。
第一种情况:当所述内存统计值逐步下调最低至所述第三十三内存统计值min_buffer时,此后若系统当前的内存统计值仍未能达到所述第三十三内存统计值min_buffer,则通过杀死进程来回收所述第三十二内存,进而将所述内存统计值维持至所述第三十三内存统计值min_buffer(参图3-2a中步骤S3-211)。
第二种情况:当监控到所述匿名页压缩进程压缩内存导致swap分区的 空间使用率达到所述预设比例,此时会导致所述内存统计值难以继续通过匿名页压缩的方式回收内存,则上报为高级压力(critical-level-press)事件,同步通过杀死进程来回收所述第三十二内存(参图3-3中步骤S3-33)。
第三种情况:PSI压力上报策略,即根据PSI压力状态直接触发所述第三十四内存统计值psi_buffer的检测并触发通过杀死进程来回收所述第三十二内存(参图3-4中步骤S3-44)。
第四种情况:预设应用启动,即若应用内存需求过快,PSI上报仍然存在延迟,无法及时通过杀死进程来回收所述第三十二内存。因此在大内存需求的应用启动场景下,例如相机启动,会在收到启动消息时,立刻触发通过杀死进程来回收所述第三十二内存(参图3-5中步骤S3-52)。
可以理解,在本申请实施例中,并不对上述四种情况对应的杀死进程的时间或顺序进行限制,只要其满足其中任何之一,均可以触发通过杀死进程来回收所述第三十二内存。
请参阅图3-6,图3-6是本申请实施例提供的一种内存管理装置的结构示意图。其中,所述内存管理装置3-200可以用于执行图3-2a至图3-5中所描述的内存管理方法的部分或全部步骤。如图3-6所示,所述内存管理装置3-200可以包括:
线程模块3-21,所述线程模块3-21至少包括匿名页压缩线程3-211和PSI线程3-212。所述匿名页压缩线程3-211用以对匿名页进行压缩,以回收所述第三十二内存。所述PSI线程3-212用以监控系统资源压力。
创建模块3-22,所述创建模块3-22用以创建内存统计值及内存压力等级。
所述内存统计值用以表征系统内存中剩余的可用内存。所述第三十一内存为系统的空闲内存,所述第三十二内存为被占用但是可通过回收来转换为第三十一内存的内存。
所述内存统计值包括第三十一内存统计值,第三十二内存统计值及第三十三内存统计值。所述第三十二内存统计值小于所述第三十一内存统计值。所述第三十三内存统计值小于所述第三十二内存统计值。
所述内存压力等级包括第三十一等级,第三十二等级及第三十三等级。所述第三十三等级的内存压力高于所述第三十二等级的内存压力,所述第三十二等级的内存压力高于所述第三十一等级的内存压力。
上报模块3-23,所述上报模块3-23用以当系统当前的内存统计值低于所述第三十二内存统计值时,确认系统当前的内存压力等级为所述第三十一等级,并上报为第三十一级压力事件。所述上报模块3-23还用以当系统当前的内存统计值低于所述第三十一内存统计值时,确认系统当前的内存压力等级为所述第三十二等级,并上报为第三十二级压力事件。
内存回收模块3-24,所述内存回收模块3-24用以根据所述第三十一级压力事件,启动所述匿名页压缩线程3-211,以进行匿名页压缩,进而回收所述第三十二内存。
可以理解,在本申请实施例中,所述上报模块3-23可通过匿名页压缩线程3-211来进行压力事件上报。
内存调整模块3-25,所述内存调整模块3-25用以根据所述第三十二级压力事件调整所述内存统计值。例如,当通过所述匿名页压缩线程3-211进行内存回收后,若系统当前的内存统计值未达到所述第三十一内存统计值high_buffer,则接收所述中级压力(mediuam-level-press)事件,并动态调整(例如下调)所述内存统计值。
所述内存回收模块3-24还用以当所述内存统计值逐步下调最低至所述第三十三内存统计值min_buffer,且系统当前的内存统计值仍未能达到所述第三十三内存统计值min_buffer时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
可以理解,所述上报模块3-23还用以监控交换区的空间使用率,且当当前所述交换区的空间使用率达到预设比例时,确认系统当前的内存压力等级为所述第三十三等级,并上报为第三十三级压力事件。所述内存回收模块3-24还用以根据所述第三十三级压力事件,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
可以理解,所述内存统计值还包括第三十四内存统计值,所述上报模块3-23还用以通过所述PSI线程3-212监控系统资源压力,且当系统当前的PSI值大于预设阈值时上报PSI压力值。所述内存回收模块3-24还用以当接收所述PSI压力值,且当系统当前的内存统计值小于所述第三十四内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
可以理解,所述内存回收模块3-24还用以监控是否有预设应用启动。当监控到有预设应用启动,且系统当前的内存统计值小于所述第三十一内存统计值时,所述内存回收模块3-24通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
可以理解,所述内存回收模块3-24可通过输出相应的kill命令,并根据所述kill命令来杀死进程。例如,每一个进程都有一个pid号作为唯一标识。所述kill命令中可包含相应的pid,如此所述内存回收模块3-24可根据所述进程号(pid)来杀死对应的进程。
可以理解的是,上述内存管理装置3-200中各个模块的划分仅用于举例说明,在其他的实施例中,可将所述内存管理装置3-200按照需要划分为不同的模块,以完成上述内存管理装置3-200的全部或部分功能。
本申请实施例中提供的内存管理装置中的各个模块的实现,可为计算机程序的形式。该计算机程序可在电子设备或服务器上运行。该计算机程序构成的程序模块可存储在终端或服务器的存储器上。该计算机程序被处理器执行时,实现本申请实施例中所描述的步骤。在本申请实施例中各个模块的具体实现还可以对应参照图3-2a至图3-5所示的方法实施例的相应描述。在图 3-6所描述的内存管理装置中,可以有效改善内存管理效率低,造成内存供给不及时,应用保活数量低等问题。具体内容可以参见上述内存管理方法的具体实施例,在此不再详述。
请参阅图3-7,图3-7是本申请实施例中内存管理装置3-200的部分系统框架示意图。
可以理解,在本申请实施例中,以所述上报模块3-23通过匿名页压缩线程3-211来进行压力上报,并通过PSI线程3-212监控系统资源压力,且当系统当前的PSI值大于预设阈值时上报PSI压力值为例加以说明。
其中,所述匿名页压缩线程3-211和PSI线程3-212设置于下层,例如内核层。所述内存回收模块3-24,内存调整模块3-25设置于上层。所述上层为native层或应用框架(FWK)层。
可以理解,当系统当前的内存统计值低于所述第三十二内存统计值low_buffer时,所述上报模块3-23通过所述匿名页压缩线程3-211上报为低级压力(low-level-press)事件。所述上层在接收到所述低级压力(low-level-press)事件时,所述内存回收模块3-24可下发相应的回收参数至所述匿名页压缩线程3-211,以指导所述匿名页压缩线程3-211启动压缩处理,以进行内存回收。
当所述内存回收模块3-24通过所述匿名页压缩线程3-211经过一轮回收后,若系统当前的内存统计值未达到设定的所述第三十一内存统计值high_buffer,则所述上报模块3-23通过所述匿名页压缩线程3-211上报为中级压力(medium_level_press)事件。所述上层接收到所述中级压力(medium_level_press)事件时,通过所述内存调整模块3-25动态调整所述内存统计值。
当所述上层在时间窗口Δ内收到预设次数(例如n次)的所述中级压力(medium_level_press)事件,且所述内存统计值已调整至最低,即已调整至所述第三十三内存统计值min_buffer时,若再次监控到系统当前的内存统计值仍达不到所述第三十三内存统计值min_buffer,则所述上报模块3-23通过所述匿名页压缩线程3-211再次上报为中级压力(medium_level_press)事件。所述上层再通过所述内存回收模块3-24输出相应的kill命令,以通过杀死进程来回收第三十二内存,进而调整所述内存统计值至所述第三十三内存统计值min_buffer。
另外,在一些实施例中,所述上报模块3-23还可通过所述匿名页压缩线程3-211监控swap分区的空间使用率。当监控到当前swap分分区的空间使用率已达到一定比例,此时会导致所述内存统计值难以继续通过匿名页压缩的方式回收内存时,此时所述上报模块3-23通过所述匿名页压缩线程3-211上报为高级压力(critical_level_press)事件。当所述上层接收到所述高级压力(medium_level_press)事件时,通过所述内存回收模块3-24输出相应的kill命令,以通过杀死进程来回收所述第三十二内存。
另外,在一些实施例中,所述上报模块3-23还可通过所述PSI线程3-212监控系统资源压力。当监控到当前的PSI压力值大于预设阈值时,进行PSI压力上报。所述上层接收到所述PSI压力上报事件,并确认系统当前的内存 统计值是否低于所述第三十四内存统计值psi_buffer。当确定系统当前的内存统计值低于所述第三十四内存统计值psi_buffer时,通过所述内存回收模块3-24输出相应的kill命令,以通过杀死进程来回收所述第三十二内存。
另外,在一些实施例中,还可以监控是否有预设应用启动。当监控到有预设应用启动时,其进一步确定系统当前的内存统计值是否低于所述第三十一内存统计值high_buffer。当确定系统当前的内存统计值低于所述第三十一内存统计值high_buffer时,通过所述内存回收模块3-24输出相应的kill命令,以通过杀死进程来回收所述第三十二内存。
显然,上述三级内存压力场景,即低级压力(low-level-press)场景、中级压力(medium_level_press)场景及高级压力(critical_level_press)场景各自闭环,且总的内存水线管控又形成更高一级的闭环,最终实现内存水线的常稳管理。
可以理解,上述内存管理方法中,所述匿名页压缩线程基于多级内存统计值初步维持水线,并根据其工作状态分级(低级压力(low-level-press)场景、中级压力(medium_level_press),高级压力(critical_level_press)场景)上报内存压力,不同级别的内存压力下,所述上层将介入调整,例如调整内存回收参数,动态调整内存统计值,直接触发杀死进程,进而高效的维持内存统计值,提升应用保活。
可以理解,本申请实施例提供了一种基于用户行为模型及应用模型的kill方法,可有效提高kill的效率及准确性,维持了内存统计值,提高了应用保活情况。
在本申请一实施例中,为了更好的描述本申请,请参阅图3-8,如下将以一较大内存需求场景,例如相机应用启动为例,详细说明本申请的具体实施过程。
首先,在相机应用启动前,系统当前的内存统计值处于监控状态。如果当前后台存在内存消耗或者正在使用其他应用,则系统当前的内存统计值有可能已经低于所述第三十二内存统计值low_buffer,则唤醒所述匿名页压缩线程。
在唤醒所述匿名页压缩线程时,所述匿名页压缩线程上报为低级压力(low_level_press)事件。收到所述低级压力(low_level_press)事件时,所述上层根据应用特征下发回收参数,以指导所述匿名页压缩线程工作,即压缩匿名页以回收内存。通常所述匿名页压缩线程在回收结束时一般可以达到第三十一内存统计值high_buffer,为后续的相机启动维护一个较高的内存水线。
当启动相机应用时,将识别到所述应用是大内存消耗类应用。当收到相机启动消息时,确定系统当前的内存统计值是否满足所述第三十一内存统计值high_buffer,即确定系统当前的内存统计值是否小于所述第三十一内存统计值high_buffer。当确定系统当前的内存统计值小于所述第三十一内存统计值high_buffer时,通过杀死进程来回收所述第三十二内存。
如果此时用户使用相机录像一段时间,即所述相机应用启动一段时间,在所述匿名页压缩线程回收结束时,若确定系统当前的内存统计值仍然达不到所设 定的所述第三十一内存统计值high_buffer时,所述匿名页压缩线程将上报为中级压力(medium_level_press)事件。如此,当所述上层接收到中级压力(medium_level_press)事件时,会根据内存需求下调内存统计值,直至下调内存统计值至所述第三十三内存统计值min_buffer。
可以理解,如果所述内存统计值下调至所述第三十三内存统计值min_buffer后,所述匿名页压缩线程仍然无法维护,则会再次上报中级压力(medium_level_press)事件,以触发kill,进而上层根据所述第三十三内存阈值min_buffer以及系统当前的内存统计值,计算出需要kill的量,并根据可杀列表中的顺序kill到所述第三十三内存统计值min_buffer。
最后,当相机应用退出切回桌面,所述上层将下调的内存统计值重新抬高至所述第三十二内存统计值low_buffer,以进行一种常稳态的内存管理。
可以理解,在一些实施例中,当启动相机应用时,相机在短时间内消耗大量内存,以拉低内存统计值,虽然所述匿名页压缩线程会被唤醒进行内存回收,但是从内存统计值下调到所述第三十三内存统计值min_buffer的过程对于相机启动来说可能是缓慢的,所以除了大内存应用启动触发的kill,PSI压力上报kill将会是一个很好的补充。即当在内存统计值具有下降趋势的时候,也会及时触发kill。
可以理解,在一些实施例中,在上述过程中,如果在此前已经回收了大量应用的冷匿名页,swap分区的空间已满,则所述内核中的所述匿名页压缩线程将上报为高级压力(critical_level_press)事件。如此,当所述上层接收到高级压力(critical_level_press)事件时,亦直接触发kill。
显然,本申请实施例中的所述内存管理方法及装置至少具有以下优点:
(1)创建了一种新的内存统计值,根据公式(1),所述内存统计值计算对文件页活跃和不活跃部分的比例提供了可调参数,并添加了ION的可用内存部分。新定义的内存统计值能够更有效体现可用内存供给能力,更有效的体现内存压力情况。
(2)基于多级内存统计值,通过匿名页的并行压缩,实现多级内存统计值维持。多级内存统计值的设定,在内存压力较小时,可维持较高的内存统计值;内存压力较大时,避免匿名页压缩线程频繁唤起做低效回收或者空转,最终达到根据内存压力高效维持内存统计值长稳。
(3)采用多级内存压力上报机制以及多维kill机制。其中,内存压力基于匿名页压缩线程对内存统计值的维持情况,上报后根据不同级别的上报事件,选择调整内存回收参数、动态调整内存统计值、以及kill,形成内存统计值管理的闭环,不仅达到回收效率最优,而且为内存轻载、重载全场景提供了必要的内存供应手段,最终达到应用保活的增加。
(4)基于用户行为模型及应用模型的kill方法,在内存压力不同的情况下选择了不同的kill方法,快速有效准确地维持了对应场景所需求的目标内存统计值,完成内存管理的闭环。
可以理解的是,上述电子设备为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请实施例能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请实施例的范围。
本申请实施例可以根据上述方法示例对上述电子设备进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
在采用集成的单元的情况下,图3-9示出了上述实施例中所涉及的电子设备的一种可能的结构示意图。该电子设备300包括处理单元3-301和存储单元3-302。
其中,处理单元3-301,用于对所述电子设备300的动作进行控制管理。
存储单元3-302,用于保存所述电子设备300的指令和数据,上述指令可以用于执行如图3-2a至图3-5及相应实施例中的各个步骤。
本申请实施例还可提供一种计算机存储介质,所述计算机存储介质中存储有计算机程序代码,当上述电子设备执行所述计算机程序代码时,所述电子设备可执行图3-2a至图3-5中的相关方法步骤,以实现上述实施例中的方法。
本申请实施例还可提供一种计算机程序产品,当所述计算机程序产品在计算机上运行时,使得计算机执行图3-2a至图3-5中的相关方法步骤,以实现上述实施例中的方法。
可以理解,本申请实施例提供的电子设备、计算机存储介质或者计算机程序产品均可用于执行上述所提供的对应的方法,因此,其所能达到的有益效果可参考上述所提供的对应的方法中的有益效果,在此不再赘述。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
在本申请所提供的几个实施例中,应所述理解到,所揭露的系统和方法,可以通过其它的方式实现。例如,以上所描述的系统实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也 可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以使用硬件的形式实现,也可以使用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者所述技术方案的全部或部分可以以软件产品的形式体现出来,所述软件产品存储在一个存储介质中,包括若干指令用以使得一个设备(可以是单片机,芯片等)或处理器(processor)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、ROM、磁碟或者光盘等各种可以存储程序代码的介质。
计算机中程序的运行都是在内存中进行的,同时内存还是用于暂时存放中央处理器(Central Processing Unit,简称CPU)中的运算数据、与外部磁盘等外部存储器交换数据的媒介。当运行程序时,需要将可执行的程序相关数据代码等加载到内存中,中央处理器从内存中读取相关数据。当运行程序较多,操作系统可使用内存不足,影响操作系统的流畅度。
计算机中的程序的运行都是在计算机的内存中进行的,因此内存的使用状况对计算机性能的影响非常大。在计算机中通常有多个进程在同时运行,而为了减少启动时间,操作系统会尽量保留该进程所占的内存空间,但由于内存大小的限制,操作系统无法保留进程所占的内存空间。在内存不足时,操作系统可以进行Swap Out(换出)。例如,系统空闲内存低于预定的低水线(watermark_low),系统进程主动触发内存回收动作,为后续的内存申请腾出内存空间,空闲内存回收到高水线(watermark_high)时停止回收。内存回收包括两个方面,一个方面是将一些页框释放,另一个方面是将页框上页面数据回写保存到外部存储空间,然后再释放页框。则内存回收时,会进行换出操作,换出即将物理内存中的数据移动至外部存储空间。当一个进程又需要这些被换出至外部存储空间的数据时可以进行Swap In(换入)。换入即把外部存储空间中的数据移动到物理内存。
示例性地,当加载一个文件或程序时,该文件被存储在内存中,如。由于随机存取存储器(Random Access Memory,RAM)是有限的,有些文件无法放进去。这些文件存储在外部存储空间,如硬盘驱动器的一个特殊部分,称为“交换分区”。交换是一种机制,在这种机制中,进程可以暂时从内存中交换到外部存储空间存储,此为换出。将交换到外部存储空间的数据交换回到内存中,此为换入。
示例性地,一个中央处理器同一时刻只能执行一条指令,执行某个进程时,其它进程是停止状态。那么,当中央处理器切换到进程B运行时,如果操作系统中已经没有空闲的物理内存页面了,内存空间不足,内核就会选择将某一进程物理内存页面数据移动到外部存储空间,将进程A物理内存页面的数据备份到外部存储空间上,这样就可以腾出原进程A所占用的物理内存并将腾出的物理 内存给当前正在运行的进程B使用,这个过程称为换出。当切换到进程A运行时,再重新分配一个物理内存页面,此时如果也没有空闲物理内存页面,同样执行换出操作,并且从外部存储空间上恢复进程A换出的数据,即将进程A换出至外部存储空间的数据交换到为进程A重新分配的物理内存页面,这个过程称为换入。外部存储空间可以包括云存储空间或者存储器件,在本申请实施例中以外部存储空间为磁盘进行说明,在系统的物理内存不够用的时候,把磁盘内存中的一部分空间释放出来,以供当前运行的程序使用,该释放出来的一部分空间即为磁盘Swap分区,也称磁盘交换区。将磁盘Swap分区的数据换入至内存对应磁盘读操作,将内存的数据换出至磁盘Swap分区对应磁盘写操作,对磁盘Swap分区进行读、写操作的速度较慢,因此频繁换入换出会影响计算机的性能。
如果给程序分配足够内存后,物理内存还有剩余空间,操作系统就会把这部分剩余内存空间再划分为交换缓存空间(Swap cache)及未分配内存空间(buffer)两部分加以利用。从磁盘读取到内存的数据在被相关应用程序读取后,如果内存中有剩余内存空间,则将从磁盘读取到内存的数据存入交换缓存空间。内核在将一个页面换入内存后,会增加一个交换缓存空间对这个页面的指向,当程序试图换入一个页面时,会首先从交换缓存空间中查找,如果找到了,则填写对应的页表项PTE,将对磁盘Swap分区的指向转化为对这个交换缓存空间的指向。如果在交换缓存空间中没有找到,说明还没有其他进程在此之前访问过该页面,那么就需要去磁盘Swap分区中寻找。当一个程序在内存中修改过数据后,因为磁盘写操作的速度相对较低,在有空闲内存空间的情况下,将这些修改过的数据先存入未分配内存空间buffer,在以后某个时间再将这些修改过的数据从未分配内存空间buffer写入磁盘,从而应用程序可以继续后面的操作,而不必等待这些修改后的数据进行磁盘写操作完成。如果在某个时刻,系统需要更多的内存,则会把交换缓存空间部分擦除,并把buffer中的内容写入磁盘,从而把这两部分内存释放给系统使用。
对于内存数据的换入换出,存在页式存储管理方法,请参阅图4-1,在操作系统,将进程的逻辑地址空间(在内存虚拟空间中的结构(软件层面))划分成为固定大小的页/页面(page),以页(page)为单位,大小为4KB。而物理内存空间也划分为同样大小的页框(frame),以页框(frame)为单位,大小为4KB。页和页框的大小相同。在运行进程时,可将任意一页面放入至物理内存中的任意一个页框,放入的页框不必连接,从而实现离散分配。通过页表(page table,简称PT)实现物理地址与逻辑地址之间的映射,进而能够以页面为单位进行换入换出。页表即页表项(page table entry,PTE)集合,页表项是页面与页框之间一一映射的关系对(pair),访问页面数据的时候,系统中拿到的是虚拟空间中的虚拟地址,需要通过页表记录的页面与页框关系,然后根据虚拟地址找到物理内存空间中真正存放数据的物理地址,再从物理地址中读取数据。
每个页面在PTE页表中都有一个对应的页表项,用来表示该页面在物理内存中的实际地址和相关信息。每个页表项又对应一个交换空间页表项(Swap  Entry),区别在于:页表项PTE用于寻找该页面在物理内存中的位置,交换空间页表项Swap Entry用于寻找该页面在磁盘Swap分区中的位置。
在本申请实施例中,交换空间页表项(Swap Entry)是匿名页的数据被置换到外部存储空间中后,为所述匿名页所分配的一个交换空间页表项,用于寻找该页面在外部存储空间中的位置。
物理内存地址包括高位段和低位段,高位段叫页框码,低位段叫页框偏移量。虚拟内存地址包括高位段和低位段,高位段叫页码,低位段叫页内偏移量。在把一个页面映射到某个页框上的同时,须把页码和存放该页映像的页框码填入页表的页表项中。示例性地,页表项中的起始12/47位即第12位到第47位,共36位,用于表示一个页框首位的物理地址。页面结构包括页框、页框属性和页数据。每个页框大小为4Kbytes,即2的12次方,因此只需要定位到一个页框位置,就可以从页框的第0个位置开始,根据虚拟地址最后12位的页内偏移量找到实际的物理地址。剩余的位数11/0,即第0位到第11位,就被用于表示页面本身的属性/控制信息,包括页面是否有效(该页面是否在物理内存中有映射)、是否被访问、是否为文件页脏页、是否写保护等。
为了支持非统一内存访问(Non Uniform Memory Access,NUMA)模型,中央处理器对不同内存单元的访问时间可能不同,因此将物理内存划分为几个内存节点,系统中每个内存节点(pg_data-t)被链接到一个以NULL结尾的pgdat_list链表中,而其中每个内存节点利用pg_data_tnode_next字段链接到下一内存节点。请参阅图4-2,每个内存节点又被划分为多个内存管理区域(node-zones),一个内存管理区域可通过struct zone_struct描述,用以表示该内存管理区域在内存的某个范围。通常一个内存节点分为三个内存管理区域,包括直接内存访问区域(direct memory access,DMA)、普通内存管理区域及高端内存管理区域。直接内存访问区域以ZONE-DMA描述,通常为物理内存的起始16M。普通内存管理区域以ZONE-NORMAL描述,通常为物理内存从16M到896M内存区。高端内存管理区域以ZONE-HIGHMEM描述,是896M以后的内存区,超出内核虚拟地址空间的物理内存段。每个内存管理区域包括大量的页框,内核以struct page来描述页框,页框有很多属性,这些属性描述了这个页框的状态、用途等。通过页框数组记录一个内存分区的页框的使用情况,页框数组可用zone_mem_map描述。
请参图4-3,在每个内存节点中对应一个lruvec链表结构,以lruvec描述,每个链表结构会维护五种类型的最近最少使用(Least Recently Used,LRU)链表,最近最少使用链表可以是内存管理的一种算法,是一种常用的页面置换算法,选择最近最久未使用的页面予以淘汰,是内核用于内存管理和回收控制的重要链表。LRU链表类型分别包括文件页的活跃链表(ACTIVE_FILE)、文件页的不活跃链表(INACTIVE_FILE)、匿名页的活跃链表(ACTIVE_ANON)、匿名页的不活跃链表(INACTIVE_ANON)以及不可回收链表(Unevictable)。链表包括一系列结点(链表中每一个元素称为结点),结点可以在运行时动态生成。每个结点包括 两个部分:一个是存储数据元素的数据域,另一个是存储下一个结点地址的指针域。
可以理解,在内存不足时,系统进行内存回收,即将一些页框回收,通过LRU链表能够让系统在可以回收的页框当中,选择到理想的回收页框。LRU链表存储于内存中的,在内存中申请一个内存空间用于保存LRU链表,则在内存中有相应的内存空间存储不活跃链表和活跃链表。
请一并参阅图4-4,每个LRU链表上挂载了多个页面页框,通过链表头的地址进行连接。每个页面页框包括页框属性和页数据。每个页有自己的页描述符,而内核主要是将对应的页的页描述符加入至这些链表中。文件页的活跃链表和文件页的不活跃链表,存放的都是文件页(File-backed Page)的页描述符,文件页是映射文件的页。文件页的活跃链表中可以保存此内存管理区域中所有最近被访问过的文件页的页描述符,此链表中的页描述符的PG_active可标志为1。文件页的不活跃链表中可以保存此内存管理区域中所有最近没被访问过的文件页的页描述符,此链表中的页描述符的PG_active可标志为0。匿名页的活跃链表和匿名页的不活跃链表,存放的都是匿名页(anonymous pages)的页描述符。匿名页是没有关联到文件的页,如进程的堆、栈、数据段等。匿名页的活跃链表可以保存此内存管理区域中所有最近被访问过的并且可以存放到外部存储空间的页描述符,此链表中的页描述符的PG_active可标志为1。匿名页的不活跃链表可以保存此内存管理区域中所有最近没被访问过的并且可以存放到外部存储空间的页描述符,此链表中的页描述符的PG_active可标志为0。不可回收链表中可以存放文件页或匿名页,此链表的页在任何情况下都不允许被回收,此链表中保存的是此内存管理区域中所有禁止换出的页的描述符。
可以理解,页面置换算法遵循先进先出(FIFO)原则包括:新分配的页面链接到不活跃或活跃链表头部。从活跃链表的尾部摘取页面链接到不活跃链表头部。从不活跃链表尾部摘取页表进行内存回收。内存回收为让页面在活跃链表、不活跃链表和内存管理之间流动,匿名页页面回收时,如果没有使用该匿名页的进程,该匿名页页面直接被释放,如果有进程使用该匿名页,先交换到磁盘交换分区,然后再释放。文件映射页面只能回写磁盘交换区,然后再被释放。
在Linux操作系统的内核中匿名页占比很高,其对内存的申请占据一部分,在内存压力较大的情况下,若匿名页存在数据颠簸的情况且无法得到有效处理,则可能会出现频繁回收内存空间却又重复换入,导致内存压力依旧没有减轻的情况。申请人发现,现有匿名页的换出与换入的机制中,在匿名页的数据从磁盘Swap分区换入至内存中时,默认将匿名页的数据换入至该匿名页所属的活跃链表中,默认匿名页会被频繁使用,没有充分考虑换入的匿名页的使用情况。在默认将匿名页均换入至活跃链表中时,不颠簸的匿名页也放入至活跃链表中,基于活跃链表中空间有限,相应的有些颠簸的匿名页会被移至不活跃链表,有可能导致颠簸的匿名页在被再次访问前被移除至磁盘Swap分区。
为此,本申请实施例公开一种匿名页管理方法,在匿名页的数据从内存换 出到外部存储空间后,再将该匿名页的数据从外部存储空间换入至内存时,对该匿名页的换入到换出的时间间隔信息进行处理,然后根据处理结果将该换入的匿名页放入合适的链表中。具体地,在匿名页换入到换出的时间间隔信息比预设固定值大时,认为该匿名页不颠簸,将该匿名页换入至不活跃链表,而不是换入至活跃链表。在匿名页换入到换出的时间间隔信息小于或等于预设固定值时,认为该匿名页颠簸,将该匿名页换入至活跃链表。通过将不颠簸的匿名页换入至不活跃链表,颠簸的匿名页换入至活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,避免电子设备出现卡顿现象,提升用户的体验。
本申请实施例提供的匿名页管理方法可以应用于电子设备,所述电子设备也可称之为用户设备(User Equipment,UE)、移动台(Mobile Station,MS)、移动终端(Mobile Terminal)等。可选地,所述电子设备可以具备无线接入网(Radio Access Nework,RAN)与一个或多个核心网进行通信的能力,例如,电子设备可以是移动电话(或称为“蜂窝”电话)、或具有移动性质的计算机等。所述电子设备的操作系统可以包括但不限于Linux系统、Android(安卓)系统、IOS操作系统、Symbian(塞班)操作系统、Black Berry(黑莓)操作系统、Windows Phone 8操作系统等等。可以理解,本申请实施例提供的匿名页管理方法可以应用于具有Linux操作系统的电子设备。
请参阅图4-5,图4-5为本申请实施例中电子设备4-100的结构示意图。
电子设备4-100可以是手机、平板电脑、桌面型计算机、膝上型计算机、手持计算机、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本,以及蜂窝电话、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)设备、虚拟现实(virtual reality,VR)设备、人工智能(artificial intelligence,AI)设备、可穿戴式设备、车载设备、智能家居设备和/或智慧城市设备,本申请实施例对该电子设备的具体类型不作特殊限制。
电子设备4-100可以包括处理器4-110,外部存储器接口4-120,内部存储器4-121,通用串行总线(universal serial bus,USB)接口4-130,充电管理模块4-140,电源管理模块4-141,电池4-142,天线4-1,天线4-2,移动通信模块4-150,无线通信模块4-160,音频模块4-170,扬声器4-170A,受话器4-170B,麦克风4-170C,耳机接口4-170D,传感器模块4-180,按键4-190,马达4-191,指示器4-192,摄像头4-193,显示屏4-194,以及用户标识模块(subscriber identification module,SIM)卡接口4-195等。其中传感器模块4-180可以包括压力传感器4-180A,陀螺仪传感器4-180B,气压传感器4-180C,磁传感器4-180D,加速度传感器4-180E,距离传感器4-180F,接近光传感器4-180G,指纹传感器4-180H,温度传感器4-180J,触摸传感器4-180K,环境光传感器4-180L,骨传导传感器4-180M等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备4-100的具体 限定。在本申请另一些实施例中,电子设备4-100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器4-110可以包括一个或多个处理单元,例如:处理器4-110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器4-110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器4-110中的存储器为高速缓冲存储器。该存储器可以保存处理器4-110刚用过或循环使用的指令或数据。如果处理器4-110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器4-110的等待时间,因而提高了系统的效率。
在一些实施例中,处理器4-110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
I2C接口是一种双向同步串行总线,包括一根串行数据线(serial data line,SDA)和一根串行时钟线(derail clock line,SCL)。在一些实施例中,处理器4-110可以包含多组I2C总线。处理器4-110可以通过不同的I2C总线接口分别耦合触摸传感器4-180K,充电器,闪光灯,摄像头4-193等。例如:处理器4-110可以通过I2C接口耦合触摸传感器4-180K,使处理器4-110与触摸传感器4-180K通过I2C总线接口通信,实现电子设备4-100的触摸功能。
I2S接口可以用于音频通信。在一些实施例中,处理器4-110可以包含多组I2S总线。处理器4-110可以通过I2S总线与音频模块4-170耦合,实现处理器4-110与音频模块4-170之间的通信。在一些实施例中,音频模块4-170可以通过I2S接口向无线通信模块4-160传递音频信号,实现通过蓝牙耳机接听电话的功能。
PCM接口也可以用于音频通信,将模拟信号抽样,量化和编码。在一些实施例中,音频模块4-170与无线通信模块4-160可以通过PCM总线接口耦合。在一些实施例中,音频模块4-170也可以通过PCM接口向无线通信模块4-160传递音频信号,实现通过蓝牙耳机接听电话的功能。所述I2S接口和 所述PCM接口都可以用于音频通信。
UART接口是一种通用串行数据总线,用于异步通信。该总线可以为双向通信总线。它将要传输的数据在串行通信与并行通信之间转换。在一些实施例中,UART接口通常被用于连接处理器4-110与无线通信模块4-160。例如:处理器4-110通过UART接口与无线通信模块4-160中的蓝牙模块通信,实现蓝牙功能。在一些实施例中,音频模块4-170可以通过UART接口向无线通信模块4-160传递音频信号,实现通过蓝牙耳机播放音乐的功能。
MIPI接口可以被用于连接处理器4-110与显示屏4-194,摄像头4-193等外围器件。MIPI接口包括摄像头串行接口(camera serial interface,CSI),显示屏串行接口(display serial interface,DSI)等。在一些实施例中,处理器4-110和摄像头4-193通过CSI接口通信,实现电子设备4-100的拍摄功能。处理器4-110和显示屏4-194通过DSI接口通信,实现电子设备4-100的显示功能。
GPIO接口可以通过软件配置。GPIO接口可以被配置为控制信号,也可被配置为数据信号。在一些实施例中,GPIO接口可以用于连接处理器4-110与摄像头4-193,显示屏4-194,无线通信模块4-160,音频模块4-170,传感器模块4-180等。GPIO接口还可以被配置为I2C接口,I2S接口,UART接口,MIPI接口等。
USB接口4-130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口4-130可以用于连接充电器为电子设备4-100充电,也可以用于电子设备4-100与外围设备之间传输数据。也可以用于连接耳机,通过耳机播放音频。该接口还可以用于连接其他电子设备,例如AR设备等。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备4-100的结构限定。在本申请另一些实施例中,电子设备4-100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块4-140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块4-140可以通过USB接口4-130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块4-140可以通过电子设备4-100的无线充电线圈接收无线充电输入。充电管理模块4-140为电池4-142充电的同时,还可以通过电源管理模块4-141为电子设备供电。
电源管理模块4-141用于连接电池4-142,充电管理模块4-140与处理器4-110。电源管理模块4-141接收电池4-142和/或充电管理模块4-140的输入,为处理器4-110,内部存储器4-121,显示屏4-194,摄像头4-193,和无线通信模块4-160等供电。电源管理模块4-141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源 管理模块4-141也可以设置于处理器4-110中。在另一些实施例中,电源管理模块4-141和充电管理模块4-140也可以设置于同一个器件中。
电子设备4-100的无线通信功能可以通过天线4-1,天线4-2,移动通信模块4-150,无线通信模块4-160,调制解调处理器以及基带处理器等实现。
天线4-1和天线4-2用于发射和接收电磁波信号。电子设备4-100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线4-1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块4-150可以提供应用在电子设备4-100上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块4-150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块4-150可以由天线4-1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块4-150还可以对经调制解调处理器调制后的信号放大,经天线4-1转为电磁波辐射出去。在一些实施例中,移动通信模块4-150的至少部分功能模块可以被设置于处理器4-110中。在一些实施例中,移动通信模块4-150的至少部分功能模块可以与处理器4-110的至少部分模块被设置在同一个器件中。
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器4-170A,受话器4-170B等)输出声音信号,或通过显示屏4-194显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器4-110,与移动通信模块4-150或其他功能模块设置在同一个器件中。
无线通信模块4-160可以提供应用在电子设备4-100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块4-160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块4-160经由天线4-2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器4-110。无线通信模块4-160还可以从处理器4-110接收待发送的信号,对其进行调频,放大,经天线4-2转为电磁波辐射出去。
在一些实施例中,电子设备4-100的天线4-1和移动通信模块4-150耦合,天线4-2和无线通信模块4-160耦合,使得电子设备4-100可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动 通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。
电子设备4-100通过GPU,显示屏4-194,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏4-194和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器4-110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏4-194用于显示图像,视频等。显示屏4-194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备4-100可以包括1个或N个显示屏4-194,N为大于1的正整数。
电子设备4-100可以通过ISP,摄像头4-193,视频编解码器,GPU,显示屏4-194以及应用处理器等实现拍摄功能。
ISP用于处理摄像头4-193反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头4-193中。
摄像头4-193用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备4-100可以包括1个或N个摄像头4-193,N为大于1的正整数。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备4-100在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。电子设备4-100可以支持一种或多种视频编解码器。这样,电子设备4-100可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备4-100的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。
内部存储器4-121可以包括一个或多个随机存取存储器(random access memory,RAM)和一个或多个非易失性存储器(non-volatile memory,NVM)。
随机存取存储器可以包括静态随机存储器(static random-access memory,SRAM)、动态随机存储器(dynamic random access memory,DRAM)、同步动态随机存储器(synchronous dynamic random access memory,SDRAM)、双倍资料率同步动态随机存取存储器(double data rate synchronous dynamic random access memory,DDR SDRAM,例如第五代DDR SDRAM一般称为DDR5SDRAM)等;
非易失性存储器可以包括磁盘存储器件、快闪存储器(flash memory)。
快闪存储器按照运作原理划分可以包括NOR FLASH、NAND FLASH、3D NAND FLASH等,按照存储单元电位阶数划分可以包括单阶存储单元(single-level cell,SLC)、多阶存储单元(multi-level cell,MLC)、三阶储存单元(triple-level cell,TLC)、四阶储存单元(quad-level cell,QLC)等,按照存储规范划分可以包括通用闪存存储(英文:universal flash storage,UFS)、嵌入式多媒体存储卡(embedded multi media Card,eMMC)等。
随机存取存储器可以由处理器4-110直接进行读写,可以用于存储操作系统或其他正在运行中的程序的可执行程序(例如机器指令),还可以用于存储用户及应用程序的数据等。
非易失性存储器也可以存储可执行程序和存储用户及应用程序的数据等,可以提前加载到随机存取存储器中,用于处理器4-110直接进行读写。
外部存储器接口4-120可以用于连接外部的非易失性存储器,实现扩展电子设备4-100的存储能力。外部的非易失性存储器通过外部存储器接口4-120与处理器4-110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部的非易失性存储器中。
电子设备4-100可以通过音频模块4-170,扬声器4-170A,受话器4-170B,麦克风4-170C,耳机接口4-170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块4-170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块4-170还可以用于对音频信 号编码和解码。在一些实施例中,音频模块4-170可以设置于处理器4-110中,或将音频模块4-170的部分功能模块设置于处理器4-110中。
扬声器4-170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备4-100可以通过扬声器4-170A收听音乐,或收听免提通话。
受话器4-170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备4-100接听电话或语音信息时,可以通过将受话器4-170B靠近人耳接听语音。
麦克风4-170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风4-170C发声,将声音信号输入到麦克风4-170C。电子设备4-100可以设置至少一个麦克风4-170C。在另一些实施例中,电子设备4-100可以设置两个麦克风4-170C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备4-100还可以设置三个,四个或更多麦克风4-170C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。
耳机接口4-170D用于连接有线耳机。耳机接口4-170D可以是USB接口4-130,也可以是3.5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。
压力传感器4-180A用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器4-180A可以设置于显示屏4-194。压力传感器4-180A的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器4-180A,电极之间的电容改变。电子设备4-100根据电容的变化确定压力的强度。当有触摸操作作用于显示屏4-194,电子设备4-100根据压力传感器4-180A检测所述触摸操作强度。电子设备4-100也可以根据压力传感器4-180A的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。
陀螺仪传感器4-180B可以用于确定电子设备4-100的运动姿态。在一些实施例中,可以通过陀螺仪传感器4-180B确定电子设备4-100围绕三个轴(即,x,y和z轴)的角速度。陀螺仪传感器4-180B可以用于拍摄防抖。示例性的,当按下快门,陀螺仪传感器4-180B检测电子设备4-100抖动的角度,根据角度计算出镜头模组需要补偿的距离,让镜头通过反向运动抵消电子设备4-100的抖动,实现防抖。陀螺仪传感器4-180B还可以用于导航,体感游戏场景。
气压传感器4-180C用于测量气压。在一些实施例中,电子设备4-100 通过气压传感器4-180C测得的气压值计算海拔高度,辅助定位和导航。
磁传感器4-180D包括霍尔传感器。电子设备4-100可以利用磁传感器4-180D检测翻盖皮套的开合。在一些实施例中,当电子设备4-100是翻盖机时,电子设备4-100可以根据磁传感器4-180D检测翻盖的开合。进而根据检测到的皮套的开合状态或翻盖的开合状态,设置翻盖自动解锁等特性。
加速度传感器4-180E可检测电子设备4-100在各个方向上(一般为三轴)加速度的大小。当电子设备4-100静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。
距离传感器4-180F,用于测量距离。电子设备4-100可以通过红外或激光测量距离。在一些实施例中,拍摄场景,电子设备4-100可以利用距离传感器4-180F测距以实现快速对焦。
接近光传感器4-180G可以包括例如发光二极管(LED)和光检测器,例如光电二极管。发光二极管可以是红外发光二极管。电子设备4-100通过发光二极管向外发射红外光。电子设备4-100使用光电二极管检测来自附近物体的红外反射光。当检测到充分的反射光时,可以确定电子设备4-100附近有物体。当检测到不充分的反射光时,电子设备4-100可以确定电子设备4-100附近没有物体。电子设备4-100可以利用接近光传感器4-180G检测用户手持电子设备4-100贴近耳朵通话,以便自动熄灭屏幕达到省电的目的。接近光传感器4-180G也可用于皮套模式,口袋模式自动解锁与锁屏。
环境光传感器4-180L用于感知环境光亮度。电子设备4-100可以根据感知的环境光亮度自适应调节显示屏4-194亮度。环境光传感器4-180L也可用于拍照时自动调节白平衡。环境光传感器4-180L还可以与接近光传感器4-180G配合,检测电子设备4-100是否在口袋里,以防误触。
指纹传感器4-180H用于采集指纹。电子设备4-100可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。
温度传感器4-180J用于检测温度。在一些实施例中,电子设备4-100利用温度传感器4-180J检测的温度,执行温度处理策略。例如,当温度传感器4-180J上报的温度超过阈值,电子设备4-100执行降低位于温度传感器4-180J附近的处理器的性能,以便降低功耗实施热保护。在另一些实施例中,当温度低于另一阈值时,电子设备4-100对电池4-142加热,以避免低温导致电子设备4-100异常关机。在其他一些实施例中,当温度低于又一阈值时,电子设备4-100对电池4-142的输出电压执行升压,以避免低温导致的异常关机。
触摸传感器4-180K,也称“触控器件”。触摸传感器4-180K可以设置于显示屏4-194,触摸屏包括触摸传感器4-180K与显示屏4-194,也称“触控屏”。触摸传感器4-180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏4-194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传 感器4-180K也可以设置于电子设备4-100的表面,与显示屏4-194所处的位置不同。
骨传导传感器4-180M可以获取振动信号。在一些实施例中,骨传导传感器4-180M可以获取人体声部振动骨块的振动信号。骨传导传感器4-180M也可以接触人体脉搏,接收血压跳动信号。在一些实施例中,骨传导传感器4-180M也可以设置于耳机中,结合成骨传导耳机。音频模块4-170可以基于所述骨传导传感器4-180M获取的声部振动骨块的振动信号,解析出语音信号,实现语音功能。应用处理器可以基于所述骨传导传感器4-180M获取的血压跳动信号解析心率信息,实现心率检测功能。
按键4-190包括开机键,音量键等。按键4-190可以是机械按键。也可以是触摸式按键。电子设备4-100可以接收按键输入,产生与电子设备4-100的用户设置以及功能控制有关的键信号输入。
马达4-191可以产生振动提示。马达4-191可以用于来电振动提示,也可以用于触摸振动反馈。例如,作用于不同应用(例如拍照,音频播放等)的触摸操作,可以对应不同的振动反馈效果。作用于显示屏4-194不同区域的触摸操作,马达4-191也可对应不同的振动反馈效果。不同的应用场景(例如:时间提醒,接收信息,闹钟,游戏等)也可以对应不同的振动反馈效果。触摸振动反馈效果还可以支持自定义。
指示器4-192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。
SIM卡接口4-195用于连接SIM卡。SIM卡可以通过插入SIM卡接口4-195,或从SIM卡接口4-195拔出,实现和电子设备4-100的接触和分离。电子设备4-100可以支持1个或N个SIM卡接口,N为大于1的正整数。SIM卡接口4-195可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM卡接口4-195可以同时插入多张卡。所述多张卡的类型可以相同,也可以不同。SIM卡接口4-195也可以兼容不同类型的SIM卡。SIM卡接口4-195也可以兼容外部存储卡。电子设备4-100通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备4-100采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备4-100中,不能和电子设备4-100分离。
电子设备4-100的软件系统可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。本申请实施例以分层架构的Android系统为例,示例性说明电子设备4-100的软件结构。
请参阅图4-6,图4-6为本申请实施例中电子设备4-100的软件结构框图。
分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将Android系统分为四层,从上至下分别为应用程序层,应用程序框架层,安卓运行时(Android runtime)和系统库,以及内核层。
应用程序层可以包括一系列应用程序包。
如图4-6所示,应用程序包可以包括相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息等应用程序。
应用程序框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架。应用程序框架层包括一些预先定义的函数。
如图4-6所示,应用程序框架层可以包括窗口管理器,内容提供器,视图系统,电话管理器,资源管理器,通知管理器等。
窗口管理器用于管理窗口程序。窗口管理器可以获取显示屏大小,判断是否有状态栏,锁定屏幕,截取屏幕等。
内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。
视图系统包括可视控件,例如显示文字的控件,显示图片的控件等。视图系统可用于构建应用程序。显示界面可以包括一个或多个视图。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。
电话管理器用于提供电子设备4-100的通信功能。例如通话状态的管理(包括接通,挂断等)。
资源管理器为应用程序提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。
通知管理器使应用程序可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后自动消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在系统顶部状态栏的通知,例如后台运行的应用程序的通知,还可以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息,发出提示音,电子设备4-100振动,指示灯闪烁等。
Android Runtime包括核心库和虚拟机。Android runtime负责安卓系统的调度和管理。
核心库包含两部分:一部分是java语言需要调用的功能函数,另一部分是安卓的核心库。
应用程序层和应用程序框架层运行在虚拟机中。虚拟机将应用程序层和应用程序框架层的java文件执行为二进制文件。虚拟机用于执行对象生命周期的管理,堆栈管理,线程管理,安全和异常的管理,以及垃圾回收等功能。
系统库可以包括多个功能模块。例如:表面管理器(surface manager),媒体库(Media Libraries),三维图形处理库(例如:OpenGL ES),2D图形引擎(例如:SGL)等。
表面管理器用于对显示子系统进行管理,并且为多个应用程序提供了2D和3D图层的融合。
媒体库支持多种常用的音频,视频格式回放和录制,以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:MPEG4,H.264,MP3,AAC,AMR,JPG,PNG等。
三维图形处理库用于实现三维图形绘图,图像渲染,合成,和图层处理等。
2D图形引擎是2D绘图的绘图引擎。
内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。
下面结合捕获拍照场景,示例性说明电子设备4-100软件以及硬件的工作流程。
当触摸传感器4-180K接收到触摸操作,相应的硬件中断被发给内核层。内核层将触摸操作加工成原始输入事件(包括触摸坐标,触摸操作的时间戳等信息)。原始输入事件被存储在内核层。应用程序框架层从内核层获取原始输入事件,识别该输入事件所对应的控件。以该触摸操作是触摸单击操作,该单击操作所对应的控件为相机应用图标的控件为例,相机应用调用应用框架层的接口,启动相机应用,进而通过调用内核层启动摄像头驱动,通过摄像头4-193捕获静态图像或视频。
需要说明的是,下文中说匿名页活跃链表指该匿名页所属的活跃链表,同理,匿名页不活跃链表指该匿名页所属的不活跃链表。
在本申请实施例中以外部存储空间为磁盘进行举例说明。
下面将结合本申请实施例中的附图,详细描述本申请实施例中的技术方案。
请参阅图4-7,图4-7为本申请实施例提供的匿名页生命周期的示意图。如图4-7所示,匿名页的生命周期包括五部分,分别为匿名页创建①、匿名页使用②、匿名页换出③、匿名页换入④及匿名页销毁⑤。
匿名页创建①,至少在以下情况会创建匿名页:(1)用户空间执行malloc/mmap接口函数来分配内存,在内核空间发生缺页中断时,执行do_anonymous_page()创建匿名页。(2)发生写时复制,当缺页中断出现写保护错误时,创建匿名页,可以通过执行do_wp_page()或do_cow_page()来创建匿名页。(3)执行do_swap_page()从磁盘Swap分区读回数据时会创建匿名页。(4)在迁移页面时也会创建匿名页。如图4-7,P0-PX是活跃链表下的页框,P10至PY是不活跃链表中的页框,Swap分区是磁盘Swap分区,其他分区是指磁盘的其他分区,包括根分区、/usr分区、/home分区等,匿名页创建后产生一个新的匿名页X,该新匿名页X将被放入页框中,本申请对匿名页的创建不作具体限定。
匿名页使用②,在创建了新的匿名页X后,就建立进程虚拟地址空间和物理地址页面的映射关系,进程访问虚拟地址即访问匿名页页面的数据。新匿名页在创建完成后会被发生缺页的进程所使用,将新创建的匿名页X放置在匿名页活跃链表的头部,以被相关进程访问匿名页的数据。匿名页X使用 完成后,若长时间不再被使用,会随着时间在匿名页的活跃链表中逐步后移,例如匿名页X从P0页框移动到P1页框,然后逐渐往后移动,当到达活跃链表的尾部时,内存回收过程中会执行shrink_active_list()函数将处于匿名页活跃链表尾部的匿名页移动到不活跃链表的头部,即匿名页X从页框PX移动到页框P10。若此匿名页X在移动到不活跃链表中后仍然未被使用,则会继续在不活跃链表中后移,例如匿名页X从P10页框移动到P11页框,逐渐被移动到不活跃链表的尾部,即匿名页X移动到页框PY。
匿名页换出③,在匿名页X移动到不活跃链表的尾部时,若内核执行内存回收动作,会执行对应的函数将该匿名页X的数据换出到磁盘Swap分区,即把页框PY内存储的数据换出至磁盘Swap分区,然后释放该匿名页X在内存中所占用的实际物理地址页面,即释放页框PY,则其他匿名页的数据可以存放到页框PY。具体地,在换出的时候分配交换空间页表项Swap Entry,交换空间页表项Swap Entry是匿名页被置换到磁盘Swap分区中之后用于记录其相关信息的数据结构。现有的交换空间页表项Swap Entry仅包括页表索引(val,无符号长整数),页表索引是匿名页的数据被置换到磁盘Swap分区后,作为该匿名页的“索引”,用于记录该匿名页在磁盘Swap分区中的“坐标”,由此可以根据该“坐标”从磁盘Swap分区找到匿名页被换出的数据。页表索引包括页表号以及页表内的偏移量(编号),在其中一种可能实现方式中,其在64位系统中的结构如图4-8,在图4-8中,第0-1位:最低两位保留不用,用于表示PAGE_PRESENT,其为0,第2-7位:页表号type,用于表示交换分区中的页表号,第8-57位为偏移量offset,用于表示在交换分区中编号为type的页表内的偏移量,即页号,第58位:用于表示页表项的有效性,置0(置1代表该索引无效),第59-63位:无数据内容。
在其中一种可能实现方式中,在生成交换空间页表项Swap Entry之后,将换出匿名页的数据放入交换缓存空间,如果在这个过程中,该匿名页又需要被访问时,就让需要访问该匿名页的进程直接从交换缓存空间里面读取该匿名页的数据,该匿名页对应的页面数据不换出,交换空间页表项Swap Entry被回收掉,重新变成PTE页表项。
匿名页换入④,在被换出的匿名页X被进程需要时,会发生缺页中断,在该匿名页的页表项(PTE)记录物理页面不在内存中,但页表项(PTE)不为空,说明该匿名页X被交换到外部存储空间,执行do_swap_page()函数重新读入该匿名页X的数据,将该匿名页X的数据写入至一新空页中,得到一个新匿名页,将该新匿名页换入至内存中,且默认将该新匿名页直接换入至该原匿名页X所属的活跃链表中。
在其中一种可能实现方式中,在将该新匿名页换入至内存中时,增加交换缓存空间对该新匿名页的指针指向,即在交换缓存空间和该匿名页对应的链表中均存储该新匿名页的指针,在现有技术中,均是默认将该新匿名页直接换入至原匿名页X所属的活跃链表中,则在该匿名页换入的活跃链表中存 储该新匿名页的指针。换入一个页面时,会首先从交换缓存空间中查找,如果找到了,则填写对应的页表项PTE,将对外部存储空间的指向转化为对这个交换缓存空间的指向。如果在交换缓存空间中没有找到,说明还没有其他进程在此之前访问过该页面,那么就需要去外部存储空间中寻找。
匿名页销毁⑤,当用户进程关闭或者退出时,会扫描这个用户进程的虚拟地址,并清除这些虚拟地址上的映射,将该匿名页X的实际物理地址释放,如图4-7中,匿名页X在被访问完成后,其对应的进程退出,则该匿名页X的数据将被换出,该匿名页X销毁,释放页框P0的内存地址。
请参阅图4-9,图4-9为本申请实施例提供的匿名页管理方法流程示意图。如图4-9中所示,该方法的执行主体为电子设备4-100,以Linux系统为例说明本申请的具体实施过程,但是本申请的应用场景不仅限于Linux系统,还可以为安卓系统,该电子设备4-100可以为手机、平板电脑等,所述方法可以包括但不限于以下步骤:
步骤S4-01:当匿名页换出的数据换入到内存中时,获取所述换入到所述换出的时间间隔信息。
在本申请实施例中,匿名页换出的数据指该匿名页的整个页面的数据从内存换出至外部存储空间。匿名页换出的数据从外部存储空间换入到内存,指匿名页换出到外部存储空间的整个页面的数据又被换入至内存。
在本申请实施例中,在匿名页的数据换出至外部存储空间后,若被换出的匿名页被进程需要时,发生缺页中断,调用相应的函数将该匿名页的数据从外部存储空间写入至内存中,在将匿名页的数据写入至内存中时,执行本申请的匿名页管理方法,以确定将匿名页写入该匿名页对应的不活跃链表还是写入该匿名页对应的活跃链表。
在本申请实施例中,时间间隔信息是记录匿名页的数据被换出至外部存储空间时为换出时刻,记录匿名页的数据从外部存储空间换入至内存中时为换入时刻,则在两次相邻的换出时刻至换入时刻之间的时间信息为时间间隔信息。即,当前时刻匿名页的数据被换出后需要被访问而重新被换入至内存,该次的换入与上一次换出两个时刻之间的时间距离定义为所述换入与所述换出的时间间隔信息。
在本申请实施例中,在发生缺页中断,调用相应的函数将该匿名页的数据从外部存储空间写入至内存时,获取所述换入到所述换出的时间间隔信息,通过使用该过程中不活跃链表移动页面的数量,来近似地表达页面被换出的总历时的逻辑时间,而不是以时间戳等方式记录真实的时间。
在本申请实施例中,匿名页不活跃链表移动页面数量(inactive_age),该值是每个内存管理区域(zone)内维护的一个统计值,以zone->inactive_age描述。该统计值是指该匿名页所属的内存管理区域zone内,该匿名页所属的不活跃链表中页面的移动数量。inactive_age归属于其所在的内存管理区域,不同的内存管理区域有不同的inactive_age。inactive_age是一个累加值,每次系统启动之后, 并且没有重新启动之前,inactive_age不会清零,inactive_age的数值根据所述匿名页所属不活跃链表的页面移动不断累加。匿名页所属的不活跃链表中页面移动指匿名页所属不活跃链表整体位置移动,包括在该匿名页所属的不活跃链表中,某一匿名页移除或升级。在匿名页所属的不活跃链表中有某一匿名页从不活跃链表尾部移除时,该统计值inactive_age加一;在匿名页所属的不活跃链表中的有某一匿名页再一次被访问(即除了第一次的访问)时,匿名页从不活跃链表升级到该匿名页所属的活跃链表,该统计值inactive_age加一。
在本申请实施例中,页面移除,即页面从不活跃链表的尾部离开,该页面的数据移动到外部存储空间,这个过程称为页面移除。
在本申请实施例中,页面升级,即页面从不活跃链表中离开,移动到活跃链表,这个过程称为页面升级。
在本申请实施例中,所述换入到所述换出的时间间隔信息包括匿名页在某一次换出至该次换出之后的第一次换入之间的时间间隔信息。
示例性地,在匿名页A将匿名页内的所有数据B换出到外部存储空间后,在进程需要访问匿名页A即需要读取数据B时,发生缺页中断,进而将换出的数据B换入至内存,匿名页A对应的数据B在内存中被修改为数据C,则该匿名页的数据为数据C,该匿名页A将其数据C再次换出到外部存储空间后,在进程需要访问匿名页A即读取数据C时,发生缺页中断,进而将数据C换入至所述内存,则所述换入到所述换出的时间间隔信息包括将匿名页A的数据B从外部存储空间换入到内存时,到将数据B从内存换出到外部存储空间时之间的时间间隔信息,或,所述换入到所述换出的时间间隔信息包括将匿名页A的数据C从外部存储空间换入到内存到将数据C从内存换出到外部存储空间之间的时间间隔信息。
示例性地,在T0时刻匿名页从不活跃链表的尾部被换出,在T1时刻发生缺页中断,基于T1时刻的缺页中断,在下一次时刻即T2时刻将该匿名页从外部存储空间换入至内存,则所述换入到所述换出的时间间隔信息包括T2时刻至T0时刻之间的时间间隔信息。
步骤S4-02:当所述时间间隔信息对应的数值比预设固定值大时,将匿名页换入不活跃链表。
在本申请实施例中,所述预设固定值为预先设置的数值,在执行本申请的匿名页管理方法时该预设固定值的数值不变。
可以理解,内存回收时,匿名页的换出至外部存储空间均是从不活跃链表的尾部换出,则在不活跃链表的匿名页相对于在活跃链表的匿名页被换出的概率大,活跃链表的长度固定。相对于现有技术中默认将颠簸或不颠簸的匿名页均换入至活跃链表,则相应的有些颠簸的匿名页就会被移动至不活跃链表。
在本申请实施例中,当所述时间间隔信息对应的数值比预设固定值大时,将匿名页换入不活跃链表,则该换入不活跃链表包括两种可能,一种可能是, 换入至不活跃链表的匿名页在该匿名页所属活跃链表中一直没有被访问,然后被移动至不活跃链表,然后从不活跃链表尾部被换出至外部存储空间,最后再从外部存储空间换入至内存时,则换入至不活跃链表。另一种可能是,刚创建的匿名页换入至内存中时,将该新创建的匿名页换入至不活跃链表。
在本申请实施例中,当所述时间间隔信息对应的数值比预设固定值大时,认为该匿名页为颠簸的,将该颠簸的匿名页换入不活跃链表。当所述时间间隔信息对应的数值比预设固定值小时,认为该匿名页为不颠簸的,将该不颠簸的匿名页换入活跃链表。
在本申请实施例中,根据时间间隔信息与预设固定值进行比较,以判断所述匿名页是否颠簸。当所述时间间隔信息对应的数值大于预设固定值时,判断所述匿名页为不颠簸,不能在每次换入时均将匿名页换入至活跃链表中,因此将该不颠簸的匿名页换入至不活跃链表,则从整个匿名页链表来看,减少了不颠簸匿名页对活跃链表的占用,可以让更多颠簸的匿名页换入至活跃链表,将不颠簸的匿名页优先于颠簸的匿名页换出至外部存储空间,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
请参阅图4-10,图4-10为本申请实施例提供的匿名页换出流程示意图,以外部存储空间为磁盘进行举例说明。
如图4-10所示,内存中有很多内存管理区域,包括内存管理区域4-1至内存管理区域4-N。以内存管理区域4-N进行说明,内存管理区域内包括文件页的活跃链表、文件页的不活跃链表、匿名页的活跃链表以及匿名页的不活跃链表。内存中还包括页表,页表包括页表项PTE,页表项PTE包括交换空间页表项。匿名页的活跃链表包括页框P0至PX,匿名页的不活跃链表包括页框P10至页框PY。其中,N、X及Y为大于1的正整数。磁盘分为磁盘Swap分区和其他分区,在磁盘Swap分区中,可以进行“分页”,以方便内存与磁盘之间进行数据交换。
针对内存管理区域4-N中的匿名页换出,匿名页被使用完成后,若长时间不再被使用,匿名页会随着时间在匿名页链表(匿名页的活跃链表和匿名页的不活跃链表)中逐步后移,当到达匿名页的活跃链表的尾部,即到达页框PX时,内存回收过程中的shrink_active_list()方法会将处于活跃链表尾部的匿名页移动到匿名页的不活跃链表的头部,即匿名页的数据从页框PX移动到页框P10。若此匿名页在移动到匿名页的不活跃链表中后仍然未被使用,则该匿名页会继续在匿名页不活跃链表中后移。
当匿名页移动到不活跃链表的尾部时,即匿名页移动到页框PY,若内核执行内存回收动作,执行shrink_inactive_list()方法将该匿名页的数据换出到外部存储空间,即将匿名页的整个页面数据换出至磁盘Swap分区,此时在该匿名页所 属内存管理区域维护的inactive_age统计值加1,基于该inactive_age值对应内存管理区域4-N的,该inactive_age值为zone->inactive_age,即内存管理区域4-N维护的zone->inactive_age数值加1。匿名页链表处于该内存管理区域zone内,该统计值(zone->inactive_age)是每个内存管理区域内维护的一个统计值,故可以直接读取其所属内存管理区域内的inactive_age值。inactive_age保存在内存管理区域中,用一个整数空间表示,通过执行代码zone->inactive_age即可读取到这个统计值。
执行shrink_inactive_list()方法将该匿名页的数据换出到磁盘Swap分区时,调用get_swap_page()函数在磁盘Swap分区中寻找能够容纳该匿名页的空余位置,为换出的匿名页分配交换空间页表项Swap Entry,申请两个内存空间,一个内存空间用于记录页表索引,另一个用于记录换出时刻的时间参数。在交换空间页表项Swap Entry的页表索引中记录寻找到的空余位置的具体编号,并读取换出时刻的inactive_age,将该inactive_age记录至交换空间页表项Swap Entry中的换出时刻的时间参数,以在换出时根据转换后得到的页表项Swap Entry中的页表索引中指定的位置标号,执行函数swap_writepage()将页框PY中匿名页的数据换入至磁盘Swap分区指定的位置标号,释放页框PY给发生内存缺页的进程使用。最后通过执行Swap_entry_to_pte()函数将分配的交换空间页表项Swap Entry保存至PTE页表项中,即将交换空间页表项Swap Entry通过Swap_entry_to_pte()函数转换为PTE页表项,并将转换得到的PTE页表项覆盖掉换出前的页表项,保存至PTE页表中。
在其中一种可能实现方式中,在匿名页换出时,匿名页的数据可以存储至交换缓存空间Swap cache,增加交换缓存空间Swap cache对准备换出的匿名页页面的指向,并标记这个匿名页页面的状态为"dirty"。在将匿名页的数据换入至外部存储空间Swap分区指定位置标号后,清除交换缓存空间对匿名页页面的指向。
在本申请实施例中,该交换空间页表项Swap Entry中相对于现有技术中的交换空间页表项,本申请的交换空间页表项Swap Entry还包括换出时刻的时间参数,换出时刻的时间参数记录的是换出时刻的inactive_age数值。本申请实施例中的交换空间页表项Swap Entry包括页表索引和换出时刻的时间参数。
示例性地,在匿名页从内存换出至外部存储空间之前,inactive_age为999,在匿名页从内存换出至外部存储空间时,该匿名页从不活跃链表的尾部移除,此时inactive_age加1,则inactive_age为1000,为匿名页分配交换空间页表项Swap Entry,在交换空间页表项Swap Entry中记录换出时刻的时间参数为1000。
采用本申请实施例提供的匿名页管理方法,在分配交换空间页表项Swap Entry申请一个新增加的空间,以记录换出时刻的时间参数。换入时读取换入时刻时间参数,通过换入至换出时的时间间隔信息判断匿名页换入的链表,并通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高 内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
请参阅图4-11,图4-11为本申请实施例提供的匿名页换出方法流程示意图。所述匿名页换出方法流程包括以下步骤:
步骤S4-10:在匿名页换出时,为所述匿名页分配交换空间页表项,以记录为所述匿名页分配的该匿名页数据在外部存储空间中的存储位置。
在其中一种可能实现方式中,在系统的内存紧张,或,操作系统检测内存低于内存水位标记时,需要回收一些页面来释放内存,而页面回收总是从不活跃链表的尾部开始回收,进而需要将处于不活跃链表尾部的匿名页释放,在释放匿名页时可将该匿名页的数据换出至外部存储空间。在本申请实施例中,匿名页从内存换出至外部存储空间中换出的是该匿名页的一整个匿名页的页面数据,数据大小为4K,如换出的数据经过压缩,则存放到外部存储空间中占用的空间小于4K。
在本申请实施例中,在基于其它原因需要释放匿名页,将该匿名页的整个4K的页面内容数据换出至外部存储空间时,需要为该匿名页分配页表项,分配的页表项为交换空间页表项Swap Entry,交换空间页表项Swap Entry用于记录为该匿名页寻找到的在外部存储空间中用于存储该匿名页页面数据的空余位置的具体编号及换出时刻的时间参数。
在本申请实施例中,在为匿名页分配交换空间页表项Swap Entry时,申请内存空间,请一并参阅图4-10,本申请所述交换空间页表项swp_entry_t包括了两个内存空间,一个内存空间用于记录所述页表索引,页表索引包括页表号和偏移量,页表索引用于记录匿名页相关信息的数据结构,包括为匿名页的数据寻找到的在外部存储空间中空余位置的具体编号。另一个内存空间是新增加申请的内存空间,该新增加申请的内存空间用于记录匿名页换出时刻的时间参数,如图4-10所示,该换出时刻的时间参数为匿名页换出时刻该匿名页所属的内存管理区域内维护的inactive_age数值。所述页表索引可保存为一个整数,所述换出时刻的时间参数可保存为一个整数,所述整数可为64位或32位。
步骤S4-20:记录换出时刻的时间参数。
在本申请实施例中,在匿名页的数据换出至外部存储空间中时,还记录其换出时刻的时间参数,以根据所述换出时刻的时间参数获取得到所述换入至换出的时间间隔信息。
在本申请实施例中,在匿名页的数据从内存换出至外部存储空间时,该匿名页所属的内存管理区域维护的inactive_age会更新,inactive_age数值加1,读取更新后的inactive_age值。在分配好交换空间页表项后,将该更新后的inactive_age记录至该交换空间页表项中。
在其中一种可能实现方式中,所述换出时刻的时间参数包括在匿名页的数据换出到外部存储空间时,匿名页所属不活跃链表移动页面个数,如图4-10中,在匿名页换出时刻读取内存管理区域4-N中对应的inactive_age。匿名页所属不活跃链表移动页面个数inactive_age,为每个内存管理区域维护的一个数值,直 接读取该统计值并将该统计值记录至交换空间页表项Swap Entry中,即将该统计数值保存至交换空间页表项Swap Entry中新增加申请的内存空间。
可以理解,以回收时不活跃链表的匿名页中的动作作为一个时间度量,在匿名页不活跃链表中的匿名页从链表中移除时,则记为一个“时刻”。在匿名页不活跃链表中的匿名页从不活跃链表升级至活跃链表中时,也记为一个“时刻”。即匿名页不活跃链表中的匿名页从链表中移除或升级时,该匿名页所属的内存管理器区域更新inactive_age数值。
步骤S4-30:根据交换空间页表项中记录的位置,将所述匿名页的数据写入至外部存储空间。
在本申请实施例中,根据所述页表项Swap Entry中记录的位置编号,在外部存储空间中找到对应的指定位置,执行相应的函数,将该匿名页的数据写入到外部存储空间的指定位置中,即换出后的数据通过序列化,转换为最简单最原始的数据流保存在外部存储空间的指定位置上,并释放该匿名页,将释放后得到的物理内存空间给发生内存缺页的进程使用。
步骤S4-40:将所述交换空间页表项转换为PTE页表项,并保存至PTE页表。
在本申请实施例中,在将匿名页的数据换出至外部存储空间后,将所述交换空间页表项Swap Entry转换为PTE页表项,并保存至PTE页表中。在所述交换空间页表项Swap Entry对应的匿名页的数据被换入至内存中时,所述交换空间页表项Swap Entry会销毁。
在其中一种可能实现方式中,在生成交换空间页表项Swap Entry之后,将换出匿名页的数据放入交换缓存空间,如果在这个过程中,该匿名页又需要被访问时,就让需要访问该匿名页的进程直接从交换缓存空间里面读取该匿名页的数据,该匿名页对应的页面数据不换出,增加交换缓存空间Swap cache对准备换出的匿名页页面的指向。交换空间页表项Swap Entry被回收掉,重新变成PTE页表项。
具体地,在执行shrink_inactive_list()方法将匿名页的数据换出到外部存储空间Swap分区时,首先执行add_to_swap()函数进行换出操作,请求把该匿名页换入至磁盘Swap分区,然后执行get_swap_page()函数,在磁盘Swap分区中寻找空余的能够容纳该匿名页数据的位置空间,并为换出的匿名页分配交换空间页表项swap_entry_t,并在交换空间页表项swp_entry_t中记录为所述匿名页寻找到的空余位置的具体编号以及换出时刻的时间参数即内存管理区域的inactive_age,可以调用free_swap_slot()将swp_entry_t写入到页表PTE中。最后,根据分配好的交换空间页表项swp_entry_t中页表项中指定的位置编号,执行swap_write page()函数将该匿名页的整个页面数据写入到外部存储空间Swap分区的指定位置中,并清空该匿名页,释放该匿名页占用的物理内存,即将该匿名页对应的页框给发生内存缺页的进程使用。通过执行Swap_entry_to_pte()函数将分配的页表项Swap Entry保存至页表项PTE中,即将 交换空间页表项Swap Entry通过Swap_entry_to_pte()函数转换为PTE页表项,并将转换得到的PTE页表项覆盖掉换出前的页表项,保存至PTE页表中。
在本申请实施例中,通过交换空间页表项swp_entry_t增加记录换出时刻匿名页所属不活跃链表移动页面个数,将执行一个动作(移除或升级)当做一个“时间度量”,以记录换出时刻的时间参数。在换出的时刻分配交换空间页表项swp_entry_t记录匿名页所属不活跃链表移动页面个数,在换入的时刻会将该交换空间页表项swp_entry_t销毁,则对匿名页的交换空间页表项swp_entry_t来说,其新增加的内存空间记录的均是在该匿名页换出时刻该匿名页所属不活跃链表移动页面个数。例如,在T1时刻该匿名页换出,该匿名页所属的内存管理区域维护的inactive_age值为1000,在T1时刻为匿名页分配的交换空间页表项swp_entry_t中记录的换出时刻的时间参数数值为1000。在T2时刻该匿名页换入至内存,则交换空间页表项swp_entry_t中记录的换出时刻的时间参数清零。在T3时刻该匿名页换出,该匿名页所属的内存管理区域维护的inactive_age值为2000,则在T3时刻为匿名页分配的交换空间页表项swp_entry_t中记录的换出时刻的时间参数数值为2000。
采用本申请实施例提供的匿名页管理方法,在分配交换空间页表项Swap Entry申请一个新增加的空间,以记录换出时刻的时间参数。换入时读取换入时刻时间参数,通过换入至换出时的时间间隔信息判断匿名页换入的链表,并通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
请参阅图4-12,图4-12为本申请实施例提供的匿名页换入流程示意图。
图4-12和图4-11的区别在于图4-11为匿名页的换出,图4-12为匿名页的换入。如图4-12所示,该匿名页的数据换出至磁盘后需要被换入时,将发生缺页异常,将该匿名页的数据从磁盘Swap分区中写入至内存。在发生缺页中断时,申请一个新的空页。从页表项PTE中获取交换空间页表项Swap Entry,从交换空间页表项Swap Entry中读取出换出时刻的时间参数,并根据页表索引记录的换出时为该匿名页分配的该匿名页数据存储在外部存储空间中的位置,在磁盘Swap分区中找到对应位置上的匿名页数据。将找到的匿名页数据写入至新的空页,得到一个新匿名页。记录换入时刻的时间参数,即读取换入时刻内存管理器区域维护的inactive_age,基于该inactive_age值对应内存管理区域的,可理解该inactive_age值即为zone->inactive_age,可以读取该inactive_age值。然后根据换入时刻的时间参数与换出时刻的时间参数得到该换入至换出的时间间隔信息,最后根据该时间间隔信息与一预设固定值判断将该新匿名页换入至该匿名页的活跃链表还是该匿名页的不活跃链表。具体地,根据换入时刻的inactive_age与换出时刻的inactive_age得到差值,将该差值与预设固定值进行比较,以在大于预设固定值时,将该新匿名页填入至匿名页的不活跃链表,即把该新匿名页的 指针放入匿名页的不活跃链表。在小于预设固定值时,将该新匿名页填入至匿名页的活跃链表,即把该新匿名页的指针放入匿名页的活跃链表。
在本申请实施例中,内核在将一个匿名页页面数据从外部存储空间换入内存后,增加一个交换缓存空间对这个新匿名页页面的指向,即在交换缓存空间和该匿名页对应的链表中均存储该新匿名页的指针,当进程试图换入一个页面时,会首先从交换缓存空间中查找,如果找到了,则填写对应的页表项PTE,将对外部存储空间Swap分区的指向转化为对这个内存页面的指向。
在本申请实施例中,在一个进程试图换入一个正在被换出的匿名页页面时,比如现在匿名页的数据正在被写入外部存储空间,此时进程B又试图访问这个匿名页页面,那么根据交换缓存空间对该页面的指向,找到其物理地址,填入进程B对应的页表项PTE中。
采用本申请实施例提供的匿名页管理方法,在分配交换空间页表项Swap Entry申请一个新增加的空间,以记录换出时刻的时间参数。换入时读取换入时刻时间参数,通过换入至换出时的时间间隔信息判断匿名页换入的链表,并通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
请参阅图4-13,图4-13为本申请实施例提供的匿名页换入方法流程示意图。所述匿名页换入方法流程包括以下步骤:
步骤S4-100:发生匿名页缺页中断时,申请新的空页。
在本申请实施例中,在匿名页的页面数据被换出至外部存储空间后,进程需要读写该匿名页的数据,发生缺页中断。因为PTE页表项显示该物理页面不在内存中,但PTE页表项不为空,说明该匿名页被交换到外部存储空间S,因此调用相应的函数重新读入该匿名页的数据。
具体地,当内存需要一个被换出的匿名页时,会去访问这个匿名页原本的PTE页表项,此时PTE页表项内存储的实际上是匿名页换出时生成的交换空间页表项Swap Entry,于是重新提取PTE页表项的内容转换为交换空间页表项Swap Entry,根据交换空间页表项Swap Entry找到存储在外部存储空间中的该匿名页的页面数据,以把该数据写入到为其新分配的新空页面中,得到新匿名页,此时PTE页表项映射的是新分配的匿名页面所对应的物理页面,保存的是这个新匿名页对应的物理地址信息。
在本申请实施例中,在发生匿名页缺页中断时,需要为该匿名页申请一个新的空页,即申请一个逻辑地址空间。
步骤S4-200:根据交换空间页表项中记录的位置从外部存储空间中获取该匿名页的数据。
在本申请实施例中,当内存需要被换出匿名页的数据时,会去访问这个匿名页原本的页表项PTE,此时页表项PTE内存储的实际上是匿名页换出时 生成的交换空间页表项Swap entry,于是重新提取PTE的内容转换为交换空间页表项Swap entry,即从页表项PTE中获取交换空间页表项Swap entry,然后根据交换空间页表项Swap entry中记录的位置找到保存在外部存储空间中的换出匿名页的页面数据,并从交换空间页表项Swap entry读取出换出时刻的时间参数。
步骤S4-300:将该匿名页的数据写入至新的空页,得到新匿名页。
在本申请实施例中,匿名页面数据中会有一个指针标记指向其所属的内存管理区域zone,这个指针存在4K的页面数据中,换出的匿名页数据重新换入时,将4K匿名页数据放入为其分配的新的空页后,得到一个新匿名页。根据4K的页面数据中记录的换出时的对应内存管理区域zone,再根据换入与换出的时间间隔信息,将该新匿名页重新放入对应内存管理区域zone的LRU链表中,此时页表项PTE映射的是新匿名页所对应的物理页面,保存的是这个新匿名页对应的物理地址信息。该新匿名页的数据与原换出的匿名页的数据相同,但该新匿名页的实际物理地址与原换出的匿名页的实际物理地址可能相同也可能不同。
步骤S4-400:记录换入时刻的时间参数,对该新匿名页进行颠簸评估。
如图4-12所示,可以直接读取换入时刻该匿名页所属的内存管理区域维护的inactive_age值,可以理解,换入时刻与换出时刻对应的inactive_age值的具体数值不一致,例如在T1时刻匿名页换出,记录T1换出时刻的时间参数inactive_age值为2000,在T2时刻,匿名页的数据又被换入至内存,记录T2换入时刻的时间参数inactive_age值为3500,该inactive_age是对应该匿名页所属的内存管理区域内,该匿名页不活跃链表中页面的移动数量,在T1至T2时刻,所述匿名页不活跃链表中有匿名页从不活跃链表中被移除,或有匿名页从不活跃链表升级到活跃链表中时,该inactive_age值均会加1。
在本申请实施例中,从交换空间页表项Swap entry中获取换出时刻的时间参数,再读取换入时刻的时间参数,然后根据换入时刻的时间参数与换出时刻的时间参数得到换入至换出时的时间间隔信息,最后根据时间间隔信息对换入后得到的新匿名页进行颠簸评估。
相对于现有技术默认将换入后得到的新匿名页换入至活跃链表,在本申请实施例中,在要将所述新的匿名页添加至对应的链表中前,根据换入至换出的时间间隔细信息对换入后得到的新匿名页进行颠簸评估,以确定将该新匿名页添加至活跃链表还是不活跃链表。
步骤S4-500:根据颠簸评估结果,将该新匿名页添加至对应的链表中。
在本申请实施例中,根据换入至换出的时间间隔细信息对匿名页进行颠簸评估,在匿名页为不颠簸时,将新匿名页换入至不活跃链表,而不是如现有技术统一默认放入至活跃链表。
具体地,在匿名页的数据被换出至磁盘Swap分区后,进程需要读写所述匿名页,会发生缺页中断,执行do_swap_page()方法,首先通过调用 pte_to_swp_entry()函数在PTE页表项中找到该匿名页换出时的交换空间页表项swp_entry_t,根据交换空间页表项swp_entry_t中记录的匿名页数据存放的位置找到该匿名页对应的数据,并从交换空间页表项swp_entry_t中读取换出时刻的时间参数,即换出时刻所述匿名页所属不活跃链表移动页面个数inactive_age。然后执行alloc_page_vma()函数,申请一个新的空页,将该匿名页的数据保存到该新的空页中,得到一个新的匿名页,该新匿名页的数据与原换出的匿名页的数据相同,但该新匿名页的实际物理地址与原换出的匿名页的实际物理地址不一定相同。
在内核调用add_page_to_lru_list()函数将新的匿名页重新放回链表中时,先进行颠簸评估,读取换入时刻的时间参数,即读取当前时刻该匿名页所属不活跃链表移动页面个数inactive_age,通过执行代码zone->inactive_age就可以得到该匿名页所属不活跃链表移动页面个数,然后根据换出时刻所述匿名页所属不活跃链表移动页面个数和换入时刻所述匿名页所属不活跃链表移动页面个数的差值得到时间间隔信息,即将换入时刻所述匿名页所属不活跃链表移动页面个数减去换出时刻所述匿名页所属不活跃链表移动页面个数得到所述换入至所述换出时刻的时间间隔信息。
最后,如图4-12所示,根据时间间隔信息与一预设固定值的比较结果,将该新匿名页添加至对应的链表中。在时间间隔信息小于或等于预设固定值时,则认为此匿名页为颠簸的,此时认为该匿名页在不久后将会被再次调用,因此不管匿名页此时是否被访问,都将调用函数SetPageActive()将此匿名页强制放置到活跃链表的头部。在所述时间间隔信息大于所述预设固定值时,则认为该匿名页不是颠簸的,允许其正常被换出,调用SetPageInactive()函数将该匿名页放入在不活跃链表的头部,不做处理,或在该匿名页被放入至不活跃链表后,等待下次被访问时再升级到活跃链表的头部。或,在所述时间间隔信息小于所述预设固定值时,则认为此匿名页为颠簸的,此时认为该匿名页在不久后将会被再次调用,因此不管匿名页此时是否被访问,都将调用SetPageActive()函数将此匿名页强制放置到活跃链表的头部。在所述时间间隔信息大于或等于所述预设固定值时,则认为该匿名页不是颠簸的,允许其正常被换出,调用SetPageInactive()函数将该匿名页放入在不活跃链表的头部,不做处理,或在该匿名页被放入至不活跃链表后,等待下次被访问时再升级到活跃链表的头部。
采用本申请实施例提供的匿名页管理方法,在分配交换空间页表项Swap Entry申请一个新增加的空间,以记录换出时刻的时间参数。换入时读取换入时刻时间参数,通过换入至换出时的时间间隔信息判断匿名页换入的链表,并通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
请参阅图4-14,图4-14为本申请实施例提供的匿名页颠簸判断示意图, 说明所述预设固定值的取值以及所述颠簸评估原理。
对于在链表中的每个内存页(文件页、匿名页),不管其处于哪个位置,只要被使用,就会被重新提到活跃链表的头部,此时链表中的其它内存页相应后移。
假设一个匿名页是颠簸的,则此匿名页应该永远留在内存中,若此匿名页刚刚被使用完,此时应处于活跃链表的头部,若此匿名页不能被换出,则此匿名页最晚应在不活跃链表的尾部时被再次使用,从而回到活跃链表的头部。若以此匿名页刚被访问,处于活跃链表头部作为起始时间,则从起始时间到此时匿名页位于不活跃链表尾部,该过程中从不活跃链表上移除的页面量的值应为活跃链表的长度加上不活跃链表的长度。
换句话说,对于不能被换出的匿名页,其两次被使用之间的最大等待距离应该为LRU链表的总长(NR_TOTAL),即活跃链表的长度与不活跃链表的长度之和(NR_ACTIVE_ANON+NR_INACTIVE_ANON)。
对于实际情况中的一个匿名页,其判定如图4-14所示,若此匿名页是刚刚被换入的页,则应处于不活跃链表的头部,若此匿名页一直未被使用,则会逐渐后移到不活跃链表的尾部,随后被逐出链表并换入到外部存储空间,在此匿名页被换出后未被换入的过程中,还会有更多的匿名页页被从被换出的匿名页所属的不活跃链表的尾部被逐出至外部存储空间,或被升级到被换出的匿名页所属的活跃链表,当此匿名页页归属的进程需要访问所述匿名页时,此匿名页再次被换入,将此匿名页换出和换入之间的时间距离定义为时间间隔信息,即此过程中从所述匿名页所属的不活跃链表中移动页面的总量,用于近似地表达页面被换出的总历时的逻辑时间,实际情况下很难以时间戳等方式记录真实的时间,因此使用该过程中不活跃链表移除页面的数量,来近似地表达页面被换出的总历时的逻辑时间。
可以发现,该匿名页第一次被读与第二次被读之间的距离(Read Distance),即为不活跃链表长度与所述换入至所述换出的时间间隔信息的总和(Refault Distance+NR_INACTIVE_ANON);
若实际情况中此匿名页是一个颠簸的页,则两次被读间的距离不应该超过最大等待距离,即“两次被读间不活跃链表移除的页面总量,不应超过两次被访问时间”。
因此有:
Read Distance<=NR_TOTAL
即Refault Distance+NR_INACTIVE_ANON<=NR_ACTIVE_ANON+NR_INACTIVE_ANON
即Refault Distance<=NR_ACTIVE_ANON
因此,得到该预设固定值为所述匿名页所属的活跃链表的长度。
在本申请实施例中,将匿名页换入至换出的时间间隔信息与匿名页所属的活跃链表的长度进行比较,根据比较结果将匿名页换入至对应的链表。具 体地,在该时间间隔信息的数值大于或等于匿名页所属的活跃链表的长度数值时,将此匿名页强制放置到不活跃链表的头部。在该时间间隔信息的数值小于匿名页所属的活跃链表的长度数值时,将此匿名页放置到活跃链表的头部。或,在该时间间隔信息的数值小于或等于匿名页所属的活跃链表的长度数值时,将此匿名页放置到活跃链表的头部。在该时间间隔信息的数值大于匿名页所属的活跃链表的长度数值时,将此匿名页强制放置到不活跃链表的头部。
请参阅图4-15,图4-15为本申请实施例提供的另一种匿名页管理方法方框示意图。
在内存回收过程中,为了提高回收速度,在内存极度紧张的情况下,会将不活跃链表尾部的连续多个内存页一起换出到外部存储空间,这个动作被称为整出,相对应地,每次换出单内存页的动作被称为零出。当进程需要访问这些内存页时,又会对这块连续的外部存储空间整体换入,这个动作被称为整入,相对应的单内存页换入则被称为零入。
在匿名页是整出整入场景中,所述匿名页整出部分与单匿名页换出一致,本申请对此不作具体限定。在所述匿名页整入部分,其相对于单匿名页零入,多了一个遍历步骤,即对整入中的每个匿名页单独执行颠簸评估。
由于整入的内存块中实际可能只有部分页是进程真正需要访问的,因此只需要遍历整入的内存块,对其中的每个内存页执行零入的颠簸评估动作。换句话说,整入的内存页进入到链表中后就不再作为一个整体进行处理了,而是重新作为每个独立的匿名页,各自进行相应的匿名页管理方法。
采用本申请实施例提供的匿名页管理方法,对于整入整出的匿名页,均进行单独匿名页管理,通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
请参阅图4-16,图4-16为本申请实施例提供的一种匿名页管理方法示意图。如图4-16中所示,该方法的执行主体为电子设备4-100,以Linux系统为例说明本申请的具体实施过程,但是本申请的应用场景不仅限于Linux系统,还可以为安卓系统等,该电子设备4-100可以为手机、平板电脑等,所述方法可以包括但不限于以下步骤:
步骤S4-001:将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数。
步骤S4-002:将所述匿名页换出的数据从所述外部存储空间换入到所述内存中,记录换入时刻的时间参数。
步骤S4-003:根据所述换出时刻的时间参数和所述换入时刻的时间参数,获取所述换入到所述换出的时间间隔信息。
步骤S4-004:当所述时间间隔信息对应的数值比预设固定值大时,将匿 名页换入所述内存的不活跃链表。
在其中一种可能实现方式中,所述将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数包括但不限于以下步骤:
当匿名页的数据换出到外部存储空间时,根据所述匿名页所属不活跃链表移动页面个数得到换出时刻的时间参数。
在其中一种可能实现方式中,所述将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数包括但不限于以下步骤:
当匿名页的数据换出到外部存储空间时,将所述换出时刻的时间参数存储至该匿名页对应的页表项。
在其中一种可能实现方式中,所述匿名页管理方法还包括:
根据所述匿名页所属不活跃链表的页面移动,记录所述匿名页所属不活跃链表移动页面个数。
在其中一种可能实现方式中,所述匿名页管理方法还包括:
当所述匿名页所属不活跃链表的页面从不活跃链表尾部移除时,记录所述匿名页所属不活跃链表移动页面个数,当所述匿名页所属不活跃链表的页面移动到活跃链表时,记录所述匿名页所属不活跃链表移动页面个数。
在其中一种可能实现方式中,所述将匿名页换出的数据从外部存储空间换入到内存中,记录换入时刻的时间参数包括但不限于以下步骤:
当所述匿名页换出的数据换入到内存中时,根据所述匿名页所属不活跃链表移动页面个数得到所述换入时刻的时间参数。
请参阅图4-17,图4-17为本申请实施例提供的一种匿名页管理装置示意图。其中,该匿名页管理装置4-200可以用于执行图4-7至图4-16中所描述的方法的部分或全部步骤,具体请参见图4-7至图4-16中的相关描述,在此不再赘述。如图4-17所示,所述匿名页管理装置4-200可以包括:
第四十记录单元4-10,用于将匿名页的数据从内存换出到外部存储空间,记
录换出时刻的时间参数。
第四十一记录单元4-20,用于将所述匿名页换出的数据从所述外部存储空间换入到所述内存中,记录换入时刻的时间参数。
获取单元4-30,用于根据所述换出时刻的时间参数和所述换入时刻的时间参数,获取所述换入到所述换出的时间间隔信息。
换入单元4-40,用于当所述时间间隔信息对应的数值比预设固定值大时,将匿名页换入所述内存的不活跃链表。
请一并参阅图4-18,所述第四十记录单元4-10包括:
参数获取单元4-182,用于当匿名页的数据从内存换出到外部存储空间时,根据所述匿名页所属不活跃链表移动页面个数得到换出时刻的时间参数。
存储单元4-183,用于当匿名页的数据从内存换出到外部存储空间时,将所述换出时刻的时间参数存储至该匿名页对应的页表项。
在其中一种可能实现方式中,请一并参阅图4-18,该匿名页管理装置4-200还包括:
页面记录单元4-181,用于根据所述匿名页所属不活跃链表的页面移动,记录所述匿名页所属不活跃链表移动页面个数。
在其中一种可能实现方式中,所述匿名页所属不活跃链表的页面移动包括:
所述匿名页所属不活跃链表的页面从不活跃链表尾部移除,或,所述匿名页所属不活跃链表的页面移动到活跃链表。
在其中一种可能实现方式中,第四十一记录单元4-20包括:
当所述匿名页换出的数据换入到内存中时,根据所述匿名页所属不活跃链表移动页面个数得到所述换入时刻的时间参数。
在其中一种可能实现方式中,请一并参阅图4-19,所述匿名页管理装置4-200还包括:
中断单元4-50,用于当所述匿名页发生缺页中断,且检测到所述匿名页换出的数据的存储位置在所述外部存储空间,将所述匿名页换出的数据从所述外部存储空间换入到所述内存。
采用本申请实施例提供的匿名页管理方法,通过将不颠簸的匿名页换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率,提高内存的回收效率,进而提高操作系统的流畅性,提升用户的体验。
可以理解的是,上述匿名页管理装置中各个模块的划分仅用于举例说明,在其他的实施例中,可将匿名页管理装置按照需要划分为不同的模块,以完成上述匿名页管理装置的全部或部分功能。
本申请实施例中提供的匿名页管理装置4-200中的各个模块的实现,可为计算机程序的形式。该计算机程序可在电子设备4-100或服务器上运行。该计算机程序构成的程序模块可存储在终端或服务器的存储器上。该计算机程序被处理器执行时,实现本申请实施例中所描述的步骤。在本申请实施例中各个模块的具体实现还可以对应参照图4-7至图4-16所示的方法实施例的相应描述。在图4-17所描述的匿名页管理装置4-200中,图4-18描述的第四十记录单元4-10及图4-19描述的中断单元4-50中,可以提前回收低使用率内存,从而可以避免应用卡顿,提升用户体验。具体内容可以参见上述匿名页管理方法的具体实施例,在此不再详述。
本申请实施例还提供了一种计算机可读存储介质。所述可读存储介质中存储有计算机指令,所述指令在计算设备上运行时,使得计算设备执行前述实施例提供的匿名页管理方法。
本申请的实施例还提供一种计算机程序产品,所述计算机程序产品包括计算机程序代码,当所述计算机程序代码被一个计算机执行的时候,所述计算机程序代码可以使得所述计算机执行如上述所述的方法。因此,通过将不颠簸的匿名页 换入至不活跃链表,则可以把不颠簸的匿名页优先于颠簸的匿名页换出,减少颠簸匿名页被换出的概率,进而减少匿名页的数据颠簸,从而在系统内存高压状态下减少无效的匿名页回收,提高匿名页内存的回收效率。
对于本领域的技术人员而言,显然本申请不限于上述示范性实施例的细节,而且在不背离本申请的精神或基本特征的情况下,能够以其他具体形式实现本申请。因此,只要在本申请的实质精神范围之内,对以上实施例所作的适当改变和变化都应该落在本申请要求保护的范围之内。
智能手机、平板电脑等智能设备行业飞速发展,对存储设备的需求也变得越来越大,在众多的存储设备中,基于Flash的存储器由于优异的读写性能,较大的存储空间,低廉的价格,优良的数据可靠性等优势占据了移动智能设备,特别是智能手机产品的绝大部分市场份额。然而,由于Flash存储器本身的物理属性,其可擦写次数是有限的(器件寿命有限),当擦写次数达到使用上限时,Flash存储器内部保存的数据的可靠性将会降低,从而导致器件数据丢失,最终使得器件失效。所以对Flash存储器的频繁编程操作会缩短Flash存储器的可使用寿命。
参考图5-1所示,为本申请一实施例中存储器的寿命管理方法的系统架构图。所述存储器的寿命管理方法应用在电子设备5-1中。所述电子设备5-1用于对从内存换出到所述电子设备5-1的存储器中的数据进行管控以保障存储器使用寿命达到预期的使用寿命。电子设备5-1可以是手机、平板电脑、桌面型计算机、膝上型计算机、手持计算机、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本,以及蜂窝电话、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)设备、虚拟现实(virtual reality,VR)设备、人工智能(artificial intelligence,AI)设备、可穿戴式设备、车载设备、智能家居设备和/或智慧城市设备,本申请实施例对该电子设备的具体类型不作特殊限制。
电子设备5-1可以包括处理器5-110,外部存储器接口5-120,存储器5-121,通用串行总线(universal serial bus,USB)接口5-130,充电管理模块5-140,电源管理模块5-141,电池5-142,天线1,天线2,移动通信模块5-150,无线通信模块5-160,音频模块5-170,扬声器5-170A,受话器5-170B,麦克风5-170C,耳机接口5-170D,传感器模块5-180,按键5-190,马达5-191,指示器5-192,摄像头5-193,显示屏5-194,以及用户标识模块(subscriber identification module,SIM)卡接口5-195等。其中传感器模块5-180可以包括压力传感器5-180A,陀螺仪传感器5-180B,气压传感器5-180C,磁传感器5-180D,加速度传感器5-180E,距离传感器5-180F,接近光传感器5-180G,指纹传感器5-180H,温度传感器5-180J,触摸传感器5-180K,环境光传感器5-180L,骨传导传感器5-180M等。
可以理解的是,本发明实施例示意的结构并不构成对电子设备5-1的具体限定。在本申请另一些实施例中,电子设备5-1可以包括比图示更多或更 少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器5-110可以包括一个或多个处理单元,例如:处理器5-110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器5-110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器5-110中的存储器为高速缓冲存储器。该存储器可以保存处理器5-110刚用过或循环使用的指令或数据。如果处理器5-110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器5-110的等待时间,因而提高了系统的效率。
在一些实施例中,处理器5-110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
I2C接口是一种双向同步串行总线,包括一根串行数据线(serial data line,SDA)和一根串行时钟线(derail clock line,SCL)。在一些实施例中,处理器5-110可以包含多组I2C总线。处理器5-110可以通过不同的I2C总线接口分别耦合触摸传感器5-180K,充电器,闪光灯,摄像头5-193等。例如:处理器5-110可以通过I2C接口耦合触摸传感器5-180K,使处理器5-110与触摸传感器5-180K通过I2C总线接口通信,实现电子设备5-1的触摸功能。
I2S接口可以用于音频通信。在一些实施例中,处理器5-110可以包含多组I2S总线。处理器5-110可以通过I2S总线与音频模块5-170耦合,实现处理器5-110与音频模块5-170之间的通信。在一些实施例中,音频模块5-170可以通过I2S接口向无线通信模块5-160传递音频信号,实现通过蓝牙耳机接听电话的功能。
PCM接口也可以用于音频通信,将模拟信号抽样,量化和编码。在一些实施例中,音频模块5-170与无线通信模块5-160可以通过PCM总线接口耦合。在一些实施例中,音频模块5-170也可以通过PCM接口向无线通信模块 5-160传递音频信号,实现通过蓝牙耳机接听电话的功能。所述I2S接口和所述PCM接口都可以用于音频通信。
UART接口是一种通用串行数据总线,用于异步通信。该总线可以为双向通信总线。它将要传输的数据在串行通信与并行通信之间转换。在一些实施例中,UART接口通常被用于连接处理器5-110与无线通信模块5-160。例如:处理器5-110通过UART接口与无线通信模块5-160中的蓝牙模块通信,实现蓝牙功能。在一些实施例中,音频模块5-170可以通过UART接口向无线通信模块5-160传递音频信号,实现通过蓝牙耳机播放音乐的功能。
MIPI接口可以被用于连接处理器5-110与显示屏5-194,摄像头5-193等外围器件。MIPI接口包括摄像头串行接口(camera serial interface,CSI),显示屏串行接口(display serial interface,DSI)等。在一些实施例中,处理器5-110和摄像头5-193通过CSI接口通信,实现电子设备5-1的拍摄功能。处理器5-110和显示屏5-194通过DSI接口通信,实现电子设备5-1的显示功能。
GPIO接口可以通过软件配置。GPIO接口可以被配置为控制信号,也可被配置为数据信号。在一些实施例中,GPIO接口可以用于连接处理器5-110与摄像头5-193,显示屏5-194,无线通信模块5-160,音频模块5-170,传感器模块5-180等。GPIO接口还可以被配置为I2C接口,I2S接口,UART接口,MIPI接口等。
USB接口5-130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口5-130可以用于连接充电器为电子设备5-1充电,也可以用于电子设备5-1与外围设备之间传输数据。也可以用于连接耳机,通过耳机播放音频。该接口还可以用于连接其他电子设备,例如AR设备等。
可以理解的是,本发明实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备5-1的结构限定。在本申请另一些实施例中,电子设备5-1也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块5-140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块5-140可以通过USB接口5-130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块5-140可以通过电子设备5-1的无线充电线圈接收无线充电输入。充电管理模块5-140为电池5-142充电的同时,还可以通过电源管理模块5-141为电子设备供电。
电源管理模块5-141用于连接电池5-142,充电管理模块5-140与处理器5-110。电源管理模块5-141接收电池5-142和/或充电管理模块5-140的输入,为处理器5-110,存储器5-121,显示屏5-194,摄像头5-193,和无线通信模块5-160等供电。电源管理模块5-141还可以用于监测电池容量,电池循环 次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块5-141也可以设置于处理器5-110中。在另一些实施例中,电源管理模块5-141和充电管理模块5-140也可以设置于同一个器件中。
电子设备5-1的无线通信功能可以通过天线1,天线2,移动通信模块5-150,无线通信模块5-160,调制解调处理器以及基带处理器等实现。
天线1和天线2用于发射和接收电磁波信号。电子设备5-1中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块5-150可以提供应用在电子设备5-1上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块5-150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块5-150可以由天线1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块5-150还可以对经调制解调处理器调制后的信号放大,经天线1转为电磁波辐射出去。在一些实施例中,移动通信模块5-150的至少部分功能模块可以被设置于处理器5-110中。在一些实施例中,移动通信模块5-150的至少部分功能模块可以与处理器5-110的至少部分模块被设置在同一个器件中。
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器5-170A,受话器5-170B等)输出声音信号,或通过显示屏5-194显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器5-110,与移动通信模块5-150或其他功能模块设置在同一个器件中。
无线通信模块5-160可以提供应用在电子设备5-1上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块5-160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块5-160经由天线2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器5-110。无线通信模块5-160还可以从处理器5-110接收待发送的信号,对其进行调频,放大,经天线2转为电磁波辐射出去。
在一些实施例中,电子设备5-1的天线1和移动通信模块5-150耦合,天线2和无线通信模块5-160耦合,使得电子设备5-1可以通过无线通信技 术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。
电子设备5-1通过GPU,显示屏5-194,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏5-194和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器5-110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏5-194用于显示图像,视频等。显示屏5-194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备5-1可以包括1个或N个显示屏5-194,N为大于1的正整数。
电子设备5-1可以通过ISP,摄像头5-193,视频编解码器,GPU,显示屏5-194以及应用处理器等实现拍摄功能。
ISP用于处理摄像头5-193反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头5-193中。
摄像头5-193用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备5-1可以包括1个或N个摄像头5-193,N为大于1的正整数。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可 以处理其他数字信号。例如,当电子设备5-1在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。电子设备5-1可以支持一种或多种视频编解码器。这样,电子设备5-1可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备5-1的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。
存储器5-121可以包括一个或多个随机存取存储器(random access memory,RAM)和一个或多个非易失性存储器(non-volatile memory,NVM)。
随机存取存储器可以包括静态随机存储器(static random-access memory,SRAM)、动态随机存储器(dynamic random access memory,DRAM)、同步动态随机存储器(synchronous dynamic random access memory,SDRAM)、双倍资料率同步动态随机存取存储器(double data rate synchronous dynamic random access memory,DDR SDRAM,例如第五代DDR SDRAM一般称为DDR5SDRAM)等;
非易失性存储器可以包括磁盘存储器、快闪存储器(flash memory)。
快闪存储器按照运作原理划分可以包括NOR FLASH、NAND FLASH、3D NAND FLASH等,按照存储单元电位阶数划分可以包括单阶存储单元(single-level cell,SLC)、多阶存储单元(multi-level cell,MLC)、三阶储存单元(triple-level cell,TLC)、四阶储存单元(quad-level cell,QLC)等,按照存储规范划分可以包括通用闪存存储(英文:universal flash storage,UFS)、嵌入式多媒体存储卡(embedded multi media Card,eMMC)等。
随机存取存储器可以由处理器5-110直接进行读写,可以用于存储操作系统或其他正在运行中的程序的可执行程序(例如机器指令),还可以用于存储用户及应用程序的数据等。
非易失性存储器也可以存储可执行程序和存储用户及应用程序的数据等,可以提前加载到随机存取存储器中,用于处理器5-110直接进行读写。
外部存储器接口5-120可以用于连接外部的非易失性存储器,实现扩展电子设备5-1的存储能力。外部的非易失性存储器通过外部存储器接口5-120与处理器5-110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部的非易失性存储器中。
本实施例中,所述系统软件5-122用于处理、写入或读取数据。例如,所述系统软件5-122从存储器5-121中读取数据并对数据进行处理,或所述系统软件5-122将数据写入到存储器5-121中。所述软件通道5-124用于将 数据分配到存储器5-121中。例如,所述系统软件5-122首先将数据传送到软件通道5-124中,然后由软件通道5-124将数据分配到存储器5-121中,或者所述系统软件5-122直接将数据写入到存储器5-121中。本实施例中,所述存储管控模块5-123用于获取系统软件5-122写入到所述存储器5-121中的数据,并存储管控模块5-123根据数据配额将数据写入到所述存储器5-121中存储管控模块5-123。
电子设备5-1可以通过音频模块5-170,扬声器5-170A,受话器5-170B,麦克风5-170C,耳机接口5-170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块5-170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块5-170还可以用于对音频信号编码和解码。在一些实施例中,音频模块5-170可以设置于处理器5-110中,或将音频模块5-170的部分功能模块设置于处理器5-110中。
扬声器5-170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备5-1可以通过扬声器5-170A收听音乐,或收听免提通话。
受话器5-170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备5-1接听电话或语音信息时,可以通过将受话器5-170B靠近人耳接听语音。
麦克风5-170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风5-170C发声,将声音信号输入到麦克风5-170C。电子设备5-1可以设置至少一个麦克风5-170C。在另一些实施例中,电子设备5-1可以设置两个麦克风5-170C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备5-1还可以设置三个,四个或更多麦克风5-170C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。
耳机接口5-170D用于连接有线耳机。耳机接口5-170D可以是USB接口5-130,也可以是3.5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。
压力传感器5-180A用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器5-180A可以设置于显示屏5-194。压力传感器5-180A的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器5-180A,电极之间的电容改变。电子设备5-1根据电容的变化确定压力的强度。当有触摸操作作用于显示屏5-194,电子设备5-1根据压力传感器5-180A检测所述触摸操作强度。电子设备5-1也可以根据压力传感器5-180A的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指 令。例如:当有触摸操作强度小于第一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。
陀螺仪传感器5-180B可以用于确定电子设备5-1的运动姿态。在一些实施例中,可以通过陀螺仪传感器5-180B确定电子设备5-1围绕三个轴(即,x,y和z轴)的角速度。陀螺仪传感器5-180B可以用于拍摄防抖。示例性的,当按下快门,陀螺仪传感器5-180B检测电子设备5-1抖动的角度,根据角度计算出镜头模组需要补偿的距离,让镜头通过反向运动抵消电子设备5-1的抖动,实现防抖。陀螺仪传感器5-180B还可以用于导航,体感游戏场景。
气压传感器5-180C用于测量气压。在一些实施例中,电子设备5-1通过气压传感器5-180C测得的气压值计算海拔高度,辅助定位和导航。
磁传感器5-180D包括霍尔传感器。电子设备5-1可以利用磁传感器5-180D检测翻盖皮套的开合。在一些实施例中,当电子设备5-1是翻盖机时,电子设备5-1可以根据磁传感器5-180D检测翻盖的开合。进而根据检测到的皮套的开合状态或翻盖的开合状态,设置翻盖自动解锁等特性。
加速度传感器5-180E可检测电子设备5-1在各个方向上(一般为三轴)加速度的大小。当电子设备5-1静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。
距离传感器5-180F,用于测量距离。电子设备5-1可以通过红外或激光测量距离。在一些实施例中,拍摄场景,电子设备5-1可以利用距离传感器5-180F测距以实现快速对焦。
接近光传感器5-180G可以包括例如发光二极管(LED)和光检测器,例如光电二极管。发光二极管可以是红外发光二极管。电子设备5-1通过发光二极管向外发射红外光。电子设备5-1使用光电二极管检测来自附近物体的红外反射光。当检测到充分的反射光时,可以确定电子设备5-1附近有物体。当检测到不充分的反射光时,电子设备5-1可以确定电子设备5-1附近没有物体。电子设备5-1可以利用接近光传感器5-180G检测用户手持电子设备5-1贴近耳朵通话,以便自动熄灭屏幕达到省电的目的。接近光传感器5-180G也可用于皮套模式,口袋模式自动解锁与锁屏。
环境光传感器5-180L用于感知环境光亮度。电子设备5-1可以根据感知的环境光亮度自适应调节显示屏5-194亮度。环境光传感器5-180L也可用于拍照时自动调节白平衡。环境光传感器5-180L还可以与接近光传感器5-180G配合,检测电子设备5-1是否在口袋里,以防误触。
指纹传感器5-180H用于采集指纹。电子设备5-1可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。
温度传感器5-180J用于检测温度。在一些实施例中,电子设备5-1利用温度传感器5-180J检测的温度,执行温度处理策略。例如,当温度传感器5-180J上报的温度超过阈值,电子设备5-1执行降低位于温度传感器5-180J 附近的处理器的性能,以便降低功耗实施热保护。在另一些实施例中,当温度低于另一阈值时,电子设备5-1对电池5-142加热,以避免低温导致电子设备5-1异常关机。在其他一些实施例中,当温度低于又一阈值时,电子设备5-1对电池5-142的输出电压执行升压,以避免低温导致的异常关机。
触摸传感器5-180K,也称“触控器件”。触摸传感器5-180K可以设置于显示屏5-194,由触摸传感器5-180K与显示屏5-194组成触摸屏,也称“触控屏”。触摸传感器5-180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏5-194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器5-180K也可以设置于电子设备5-1的表面,与显示屏5-194所处的位置不同。
骨传导传感器5-180M可以获取振动信号。在一些实施例中,骨传导传感器5-180M可以获取人体声部振动骨块的振动信号。骨传导传感器5-180M也可以接触人体脉搏,接收血压跳动信号。在一些实施例中,骨传导传感器5-180M也可以设置于耳机中,结合成骨传导耳机。音频模块5-170可以基于所述骨传导传感器5-180M获取的声部振动骨块的振动信号,解析出语音信号,实现语音功能。应用处理器可以基于所述骨传导传感器5-180M获取的血压跳动信号解析心率信息,实现心率检测功能。
按键5-190包括开机键,音量键等。按键5-190可以是机械按键。也可以是触摸式按键。电子设备5-1可以接收按键输入,产生与电子设备5-1的用户设置以及功能控制有关的键信号输入。
马达5-191可以产生振动提示。马达5-191可以用于来电振动提示,也可以用于触摸振动反馈。例如,作用于不同应用(例如拍照,音频播放等)的触摸操作,可以对应不同的振动反馈效果。作用于显示屏5-194不同区域的触摸操作,马达5-191也可对应不同的振动反馈效果。不同的应用场景(例如:时间提醒,接收信息,闹钟,游戏等)也可以对应不同的振动反馈效果。触摸振动反馈效果还可以支持自定义。
指示器5-192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。
SIM卡接口5-195用于连接SIM卡。SIM卡可以通过插入SIM卡接口5-195,或从SIM卡接口5-195拔出,实现和电子设备5-1的接触和分离。电子设备5-1可以支持1个或N个SIM卡接口,N为大于1的正整数。SIM卡接口5-195可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM卡接口5-195可以同时插入多张卡。所述多张卡的类型可以相同,也可以不同。SIM卡接口5-195也可以兼容不同类型的SIM卡。SIM卡接口5-195也可以兼容外部存储卡。电子设备5-1通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备5-1采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备5-1中,不能和电子设备5-1分离。
参考图5-2所示,为本申请一实施例中存储器5-121的寿命管理方法的流程图。具体可包括如下步骤。
步骤S5-201,获取第一周期由电子设备5-1的内存待换出到电子设备5-1的存储器5-121的第一数据。
本实施例中,电子设备5-1在第一周期获取系统软件5-122向存储器5-121写入数据的第一指令时,获取系统软件5-122由电子设备5-1的内存待换出到电子设备5-1的存储器5-121的第一数据。例如,在第一周期接收到第一指令时,电子设备5-1通过存储管控模块5-123获取系统软件5-122由电子设备5-1的内存待换出到电子设备5-1的存储器5-121的第一数据。本实施例中,第一数据为系统软件5-122待换出到存储器5-121的数据。
步骤S5-202,获取存储器5-121在第一周期的总数据配额,从总数据配额减去存储器的预设用户数据使用量得到第一周期的换出数据配额。
本实施例中,获取存储器5-121在第一周期的总数据配额的详细流程可参照图5-3、图5-5以及下文针对图5-3、图5-5的详细说明。
步骤S5-203,根据换出数据配额将第一数据从内存换出到存储器5-121。本实施例中,根据换出数据配额将第一数据从内存换出到存储器5-121的详细流程可参照图5-4、图5-6以及下文针对图5-4、图5-6的详细说明。
步骤S5-204,获取存储器5-121的状态信息,并根据存储器5-121的状态信息确定存储器5-121在第二周期的换出数据配额,其中状态信息包括状态信息包括擦写次数和/或总使用寿命和/或已使用寿命和/或容量和/或器件写入放大系数(Write Amplication,WA)和/或已使用时间。本实施例中,第二周期为第一周期之后的下一个第一周期。
本申请中,根据换出数据配额将待换出的第一数据换出到存储器5-121中,如此对系统软件5-122写入存储器5-121的数据进行限制,从而减少存储器5-121的擦写次数,提升存储器5-121的使用寿命,并保障存储器5-121的使用寿命达到预期设计的寿命。
本实施例中,电子设备5-1获取存储器5-121的擦写次数,并根据存储器5-121的擦写次数计算出第一周期的换出数据配额。参考图5-3所示,为本申请一个实施例中获取存储器5-121的换出数据配额的方法流程图,具体可包括如下步骤。
步骤S5-301,获取存储器5-121在第一周期的擦写次数。
本实施例中,第一周期可以根据用户需要进行设置,例如可将第一周期设置为1天、一周、一个月。
步骤S5-302,根据存储器5-121在第一周期的擦写次数及第一周期计算出存储器5-121在第一周期的擦写次数的增长速度。
步骤S5-303,根据存储器5-121在第一周期的擦写次数的增长速度确定在第一周期的预设用户数据使用量。
步骤S5-304,从总数据配额减去预设用户数据使用量得到存储器5-121 在第一周期的换出数据配额。
本实施例中,根据存储器5-121在第一周期的擦写次数的增长速度确定在第一周期的预设用户数据使用量包括:将存储器5-121在第一周期的擦写次数的增长速度输入到磁盘寿命预测模型中,并经过磁盘寿命预测模型处理后输出预设用户数据使用量。本实施例中,磁盘寿命预测模型为神经网络模型,磁盘寿命预测模型对存储器5-121的擦写次数增长速度及预设用户数据使用量进行深度学习后得到存储器5-121的擦写次数增长速度及预设用户数据使用量之间的关系。本实施例中,预设用户数据使用量为当前周期(例如第一周期或第二周期)的上周期的非系统软件写入存储器5-121的数据量。
在其他实施例中,存储管控模块5-123根据存储器5-121的擦写次数的增长速度查询第一关系表(图中未示),并根据第一关系表定义的多个擦写次数的增长速度与多个预设用户数据使用量的对应关系确定出与存储器5-121的擦写次数的增长速度对应的预设用户数据使用量,将存储器5-121的总数据配额减去预设用户数据使用量(电子设备5-1中非系统软件写入存储器的数据量)得到存储器5-121的换出数据配额。
本实施例中,在确定第一周期的换出数据配额后,电子设备5-1根据换出数据配额将第一数据从内存换出到存储器5-121。参考图5-4所示,为本申请一个实施例中根据换出数据配额将第一数据从内存换出到存储器5-121的方法流程图,具体可包括如下步骤。
步骤S5-401,判断第一周期是否结束;若确定第一周期没有结束,执行步骤S5-402,若确定第一周期结束,执行步骤S5-406。
步骤S5-402,获取在第一周期已换出到存储器5-121的数据,并将第一周期的换出数据配额与在第一周期已换出到存储器5-121的数据相减得到剩余数据配额。
步骤S5-403,判断待写入的第一数据是否小于剩余数据配额;若第一数据小于剩余数据配额,执行步骤S5-404,否则若第一数据大于或等于剩余数据配额,执行步骤S5-405。
步骤S5-404,将待换出的第一数据换出到存储器5-121。
步骤S5-405,从待换出的第一数据中选出与剩余数据配额相同数据量的目标数据,并将目标数据换出到存储器5-121,并在将目标数据换出到存储器5-121后关闭存储器5-121的写入功能。
步骤S5-406,在第二周期重新计算存储器5-121的换出数据配额得到更新的换出数据配额,并在第二周期依据更新的换出数据配额对第二周期待换出的第二数据进行写入管控。
本实施例中,根据存储器5-121的状态信息确定存储器5-121的第二周期的换出数据配额包括:获取存储器5-121在第二周期内预设时间段内的擦写次数;根据存储器5-121在预设时间段内的擦写次数的增长速度计算存储器5-121在预设时间段内的擦写次数的增长速度;将存储器5-121的擦写次 数的增长速度输入到磁盘寿命预测模型中,并经过磁盘寿命预测模型处理后输出存储器5-121在第二周期的总数据配额,将存储器5-121在第二周期的总数据配额减去第二周期的预设用户数据使用量得到存储器5-121在第二周期的换出数据配额。
本申请中的第一周期或第二周期可根据需求进行配置,例如,可以选择按天、周、月设置第一周期或第二周期以对存储器5-121的使用寿命进行管控,因而容易适配不同场景下对存储器5-121的管控需求。另外,由于各个第一周期所对应的存储器5-121的换出数据配额都会进行重新计算,使得在历史第一周期对存储器5-121的磁盘写入量的限制不会影响新的第一周期对存储器5-121的写入管控,尤其是对用户短期内的突发写入过量的行为,不会造成永久的写入限制,使得存储器5-121具备限制后的恢复能力。参考图5-5所示,为本申请另一实施例中获取存储器5-121的换出数据配额的方法流程图,具体可包括如下步骤。
步骤S5-501,设定存储器5-121的目标使用时间。
步骤S5-502,获取存储器5-121的已使用寿命及总使用寿命。
本实施例中,电子设备5-1从存储器5-121的第一寄存器中获取存储器5-121的已使用寿命。电子设备5-1从存储器5-121的第二寄存器中获取存储器5-121的总使用寿命。本实施例中,存储器5-121的总使用寿命为存储器5-121的所有擦写次数,存储器5-121的已使用寿命为存储器5-121已使用的擦写次数。
步骤S5-503,获取存储器5-121的器件写入放大系数及存储器5-121的容量。
步骤S5-504,根据存储器5-121的总使用寿命、存储器5-121的已使用寿命、存储器5-121的容量、存储器5-121的目标使用时间、存储器5-121的器件写入放大系数、第一周期确定存储器5-121在第一周期的换出数据配额。
本实施例中,电子设备5-1根据公式p=(e-b)*q/((c/t)*w)计算得到存储器5-121在第一周期的换出数据配额。其中,e为存储器5-121的总使用寿命,b为存储器5-121的已使用寿命,q为存储器5-121的容量,c为存储器5-121的目标使用时间,w为存储器5-121的器件写入放大系数,t为第一周期,p为换出数据配额。
本实施例中,在确定存储器5-121在第一周期的换出数据配额后,电子设备5-1根据换出数据配额将待换出的第一数据换出到存储器5-121中。参考图5-6所示,为本申请另一实施例中根据换出数据配额将第一数据换出到存储器5-121的方法流程图,具体可包括如下步骤。
步骤S5-601,基于预设计时方式进行计时,并获取预设计时方式下的计时时间。
本实施例中,电子设备5-1基于预设计时方式进行计时,并获取预设计 时方式下的计时时间。本实施例中,预设计时方式包括按照电子设备5-1的使用时间进行计时的方式、按照电子设备5-1的系统运行时间进行计时的方式、按照原子钟计时的方式。本实施方式中,按照电子设备5-1的使用时间进行计时的方式是指当电子设备5-1运行时进行计时,当电子设备5-1休眠时停止进行计时。按照电子设备5-1的系统运行时间进行计时的方式是指电子设备5-1上电时,电子设备5-1启动开机后电子设备5-1的系统时钟运转所计时的时间。
步骤S5-602,判断计时时间是否在第一周期内。若计时时间在第一周期内执行步骤S5-603,若计时时间不在第一周期内,执行步骤S5-608。
步骤S5-603,获取第一周期开始时间到计时时间前累计换出到存储器5-121的累加数据。
步骤S5-604,将存储器在第一周期的换出数据配额与累加数据相减得到剩余数据配额。
步骤S5-605,判断第一数据是否小于剩余数据配额。若第一数据小于剩余数据配额,执行步骤S5-606,否则若第一数据不小于剩余数据配额,执行步骤S5-607。
步骤S5-606,将第一数据从内存换出到存储器5-121。
步骤S5-607,从第一数据中选出与剩余数据配额相同数据量的目标数据,并将目标数据从内存换出到存储器5-121,并在将目标数据写入存储器5-121后关闭存储器5-121的写入功能。
步骤S5-608,在第二周期重新计算存储器5-121的换出数据配额得到更新的换出数据配额,并在第二周期依据更新的换出数据配额对第二周期待换出到存储器5-121的第二数据进行写入管控。
本实施例中,存储器5-121的状态信息包括存储器5-121的总使用寿命、存储器5-121的已使用寿命、存储器5-121的容量、存储器5-121的器件写入放大系数、存储器5-121的已使用时间。根据存储器的状态信息确定存储器在第二周期的换出数据配额包括:获取存储器5-121的总使用寿命、存储器5-121的已使用寿命、存储器5-121的容量、存储器5-121的器件写入放大系数、存储器5-121的已使用时间;获取预先设定的存储器5-121的目标使用时间;根据公式p=(e-b)*q/((c-c1)*w/t)计算得到存储器5-121在第二周期的换出数据配额。其中,e为存储器5-121的总使用寿命,b为存储器5-121的已使用寿命,q为存储器5-121的容量,c为存储器5-121的目标使用时间,c1为存储器5-121的已使用时间,w为存储器5-121的器件写入放大系数,t为第一周期,p为换出数据配额。
可选的,在本申请的一种可能的实施例中,若在第一周期内,电子设备5-1的存储管控模块5-123获取到电子设备5-1的关机指令时还用于将计时时间及第一周期开始时间到计时时间前累计换出到存储器5-121的所有累加数据作为统计信息写入到存储器5-121的统计信息文件5-141中。其中,存储 器5-121为非易失性存储器。参考图5-7A所示,为本申请一个实施例中存储管控模块5-123写入统计信息的示意图。本实施例中,存储管控模块5-123获取到电子设备5-1的关机指令后,将计时时间及累加数据写入到存储器5-121的统计信息文件5-141中,以便电子设备5-1下次开机后从统计信息文件5-141中读取计时时间及累加数据。存储管控模块5-123将计时时间、累加数据写入存储器5-121的统计信息文件5-141后控制电子设备5-1关机。
参考图5-7B所示,为本申请一个实施例中存储管控模块5-123读入统计信息的示意图。本实施例中,存储管控模块5-123获取到电子设备5-1的开机指令后,从存储器5-121的统计信息文件5-141中读取计时时间及累加数据,并根据计时时间及累加数据对第一周期内待换出到存储器5-121中的第一数据进行管控。存储管控模块5-123根据计时时间及累加数据对第一周期内待换出到存储器5-121中的第一数据进行管控的具体实现方法可参考图5-6的流程图,这里不再重复描述。
本申请可以在获取到电子设备5-1的系统的开机指令后,可从存储器5-121的统计信息文件5-141中读取未完成的第一管控周期的计时时间及累加数据,并根据未完成的第一周期的计时时间及累加数据继续对第一周期内待换出到存储器5-121中的第一数据进行管控,从而使得对存储器5-121的寿命管控效果可不受电子设备5-1的系统关机动作或系统开机动作的影响,电子设备5-1的系统在多次关机或开机后,仍然能基于时间轴对当前第一周期内写入到存储器5-121中的数据进行管控。
本实施例中,存储器5-121的状态信息包括存储器5-121的已使用寿命及存储器5-121的总使用寿命。本实施例中,方法还包括:获取存储器5-121的已使用寿命及存储器5-121的总使用寿命,计算存储器5-121的已使用寿命与存储器5-121的总使用寿命的比值得到第一占比值,并在第一占比值达到预设占比值时不将第一数据换出到存储器5-121中。参考图5-8所示,为本申请一个实施例中将第一数据换出到存储器5-121的方法流程图,具体可包括如下步骤。
步骤S5-801,设置检测周期。
步骤S5-802,在每一检测周期获取存储器5-121的已使用寿命及存储器5-121的总使用寿命。
本实施例中,电子设备5-1在每个检测周期从存储器5-121的第一寄存器中获取存储器5-121的已使用寿命。
本实施例中,电子设备5-1在每个检测周期从存储器5-121的第二寄存器中获取存储器5-121的总使用寿命。可选的,在本申请的实施例中,第一寄存器与第二寄存器可以是相同的寄存器,也可以是不同的寄存器。
步骤S5-803,在每一检测周期计算存储器5-121的已使用寿命与存储器5-121的总使用寿命的比值得到第一占比值。
步骤S5-804,在每一检测周期判断第一占比值是否小于预设占比值。若 在每一检测周期第一占比值小于预设占比值,执行步骤S5-805,否则若在每一检测周期第一占比值大于或等于预设占比值,执行步骤S5-806。
本实施例中,电子设备5-1获取预先设定的存储器5-12114的目标使用寿命,计算存储器5-121的目标使用寿命与存储器5-121的总使用寿命的比值得到预设占比值。
步骤S5-805,将第一数据从内存换出到存储器5-121。
步骤S5-806,不将第一数据从内存换出到存储器,并关闭存储器5-121的写入功能。
本申请通过在每一检测周期检测存储器5-121的已使用寿命占存储器5-121的总使用寿命的第一占比值将第一数据换出到存储器5-121的写入条件,从而对存储器5-121消耗的存储资源总量进行管控,保障存储器5-121到达设计的使用寿命。
本实施例中,方法还包括:确定存储器5-121的目标使用时间;获取存储器5-121的已使用寿命;将存储器5-121的已使用寿命与存储器5-121的目标使用时间进行比较;若存储器5-121的已使用寿命大于或等于存储器5-121的目标使用时间,将第一数据从内存换出到存储器5-121;若存储器5-121的已使用寿命小于存储器5-121的目标使用时间,根据公式d=k1*(c-b)*100/b计算得到数据限制量,其中,b为存储器5-121的已使用寿命,d为数据限制量,k1为用户设定的配置系数;将第一周期的换出数据配额减去数据限制量的差值作为存储器5-121在第一周期的换出数据配额。
本实施方式中,确定存储器5-121的目标使用时间包括:获取存储器5-121的目标使用寿命及存储器的总使用寿命;计算存储器5-121的已使用寿命与存储器5-121的总使用寿命的比例得到第二占比值;根据公式c=k2*a计算得到存储器5-121的目标使用时间,其中a为存储器5-121的目标使用寿命,k2为第二占比值,c为存储器5-121的目标使用时间。
本实施例中,配置系数表示相比较存储器5-121的目标使用时间每少1%应对换出数据配额减去多少GB单位的存储数据。本实施例中,配置系数为经验值1GB。
本申请中,若存储器5-121的已使用寿命小于存储器5-121的目标使用时间时,将在第一周期的换出数据配额减去数据限量的差值作为存储器5-121在第一周期的换出数据配额,如此在第一周期对写入存储器5-121的数据进行纠偏,可以延长存储器5-121的使用寿命,以达到预期寿命。
本实施例还提供一种计算机存储介质,该计算机存储介质中存储有计算机指令,当该计算机指令在电子设备上运行时,使得电子设备执行上述相关方法步骤实现上述实施例中的存储器5-121的寿命管理方法。
本实施例还提供了一种计算机程序产品,当该计算机程序产品在计算机上运行时,使得计算机执行上述相关步骤,以实现上述实施例中的内观管理方法。
另外,本申请的实施例还提供一种装置,这个装置具体可以是芯片,组件或模块,该装置可包括相连的处理器和存储器;其中,存储器用于存储计算机执行指令,当装置运行时,处理器可执行存储器存储的计算机执行指令,以使芯片执行上述各方法实施例中的存储器5-121的寿命管理方法。
其中,本实施例提供的电子设备、计算机存储介质、计算机程序产品或芯片均用于执行上文所提供的对应的方法,因此,其所能达到的有益效果可参考上文所提供的对应的方法中的有益效果,此处不再赘述。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,该模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
该作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是一个物理单元或多个物理单元,即可以位于一个地方,或者也可以分布到多个不同地方。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
该集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该软件产品存储在一个存储介质中,包括若干指令用以使得一个设备(可以是单片机,芯片等)或处理器(processor)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
最后应说明的是,以上实施例仅用以说明本申请的技术方案而非限制,尽管参照较佳实施例对本申请进行了详细说明,本领域的普通技术人员应当理解,可以对本申请的技术方案进行修改或等同替换,而不脱离本申请技术方案的精神和 范围。
在外部存储中设置虚拟内存是计算系统中一种常见的内存扩展方式。内存中应用动态分配的,没有文件背景的页面称为匿名页。将匿名页从内存移至外部存储称为内存换出,将匿名页从外部存储移至内存称为内存换入。内存换出和内存换入的性能直接影响系统性能。
受限于存储介质的演进,外部存储的单个读时延很难缩短。外部存储的读性能制约了内存换入的性能。内存换入性能不佳会导致系统卡顿。
本申请实施例提供的内存管理方法,可以应用于图6-1所示的电子设备6-100。电子设备6-100可以是手机、平板电脑、桌面型计算机、膝上型计算机、手持计算机、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本,以及蜂窝电话、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)设备、虚拟现实(virtual reality,VR)设备、人工智能(artificial intelligence,AI)设备、可穿戴式设备、车载设备、智能家居设备和/或智慧城市设备,本申请实施例对该电子设备的具体类型不作特殊限制。
电子设备6-100可以包括处理器6-110,外部存储器接口6-120,内部存储器6-121,通用串行总线(universal serial bus,USB)接口6-130,充电管理模块6-140,电源管理模块6-141,电池6-142,天线6-1,天线6-2,移动通信模块6-150,无线通信模块6-160,音频模块6-170,扬声器6-170A,受话器6-170B,麦克风6-170C,耳机接口6-170D,传感器模块6-180,摄像头6-191以及显示屏6-192等。其中传感器模块6-180可以包括压力传感器,陀螺仪传感器,气压传感器,磁传感器,加速度传感器,距离传感器,接近光传感器,指纹传感器,温度传感器,触摸传感器,环境光传感器,骨传导传感器等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备6-100的具体限定。在本申请另一些实施例中,电子设备6-100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器6-110可以包括一个或多个处理单元,例如:处理器6-110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器6-110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器6-110中的存储器为高速缓冲存储器。该存储器可以保存处理器6-110刚用过或循环使用的指令或数据。如果处理器6-110需要再次使用该指令或数据, 可从所述存储器中直接调用。避免了重复存取,减少了处理器6-110的等待时间,因而提高了系统的效率。
在一些实施例中,处理器6-110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
I2C接口是一种双向同步串行总线,包括一根串行数据线(serial data line,SDA)和一根串行时钟线(derail clock line,SCL)。在一些实施例中,处理器6-110可以包含多组I2C总线。
I2S接口可以用于音频通信。在一些实施例中,处理器6-110可以包含多组I2S总线。处理器6-110可以通过I2S总线与音频模块6-170耦合,实现处理器6-110与音频模块6-170之间的通信。在一些实施例中,音频模块6-170可以通过I2S接口向无线通信模块6-160传递音频信号,实现通过蓝牙耳机接听电话的功能。
PCM接口也可以用于音频通信,将模拟信号抽样,量化和编码。在一些实施例中,音频模块6-170与无线通信模块6-160可以通过PCM总线接口耦合。在一些实施例中,音频模块6-170也可以通过PCM接口向无线通信模块6-160传递音频信号,实现通过蓝牙耳机接听电话的功能。所述I2S接口和所述PCM接口都可以用于音频通信。
UART接口是一种通用串行数据总线,用于异步通信。该总线可以为双向通信总线。它将要传输的数据在串行通信与并行通信之间转换。在一些实施例中,UART接口通常被用于连接处理器6-110与无线通信模块6-160。例如:处理器6-110通过UART接口与无线通信模块6-160中的蓝牙模块通信,实现蓝牙功能。在一些实施例中,音频模块6-170可以通过UART接口向无线通信模块6-160传递音频信号,实现通过蓝牙耳机播放音乐的功能。
MIPI接口可以被用于连接处理器6-110与显示屏6-192,摄像头6-191等外围器件。MIPI接口包括摄像头串行接口(camera serial interface,CSI),显示屏串行接口(display serial interface,DSI)等。在一些实施例中,处理器6-110和摄像头6-191通过CSI接口通信,实现电子设备6-100的拍摄功能。处理器6-110和显示屏6-192通过DSI接口通信,实现电子设备6-100的显示功能。
GPIO接口可以通过软件配置。GPIO接口可以被配置为控制信号,也可被配置为数据信号。在一些实施例中,GPIO接口可以用于连接处理器6-110与摄像头6-191,显示屏6-192,无线通信模块6-160,音频模块6-170,传感器模块6-180等。GPIO接口还可以被配置为I2C接口,I2S接口,UART接口,MIPI接口等。
USB接口6-130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口6-130可以用于连接充电器为电子设备6-100充电,也可以用于电子设备6-100与外围设备之间传输数据。也可以用于连接耳机,通过耳机播放音频。该接口还可以用于连接其他电子设备,例如AR设备等。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备6-100的结构限定。在本申请另一些实施例中,电子设备6-100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块6-140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块6-140可以通过USB接口6-130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块6-140可以通过电子设备6-100的无线充电线圈接收无线充电输入。充电管理模块6-140为电池6-142充电的同时,还可以通过电源管理模块6-141为电子设备供电。
电源管理模块6-141用于连接电池6-142,充电管理模块6-140与处理器6-110。电源管理模块6-141接收电池6-142和/或充电管理模块6-140的输入,为处理器6-110,内部存储器6-121,显示屏6-192,摄像头6-191,和无线通信模块6-160等供电。电源管理模块6-141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块6-141也可以设置于处理器6-110中。在另一些实施例中,电源管理模块6-141和充电管理模块6-140也可以设置于同一个器件中。
电子设备6-100的无线通信功能可以通过天线6-1,天线6-2,移动通信模块6-150,无线通信模块6-160,调制解调处理器以及基带处理器等实现。
天线6-1和天线6-2用于发射和接收电磁波信号。电子设备6-100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线6-1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块6-150可以提供应用在电子设备6-100上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块6-150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块6-150可以由天线6-1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块6-150还可以对经调制解调处理器调制后的信号放大,经天线6-1转为电磁波辐射出去。在一些实施例中,移动通信模块6-150的至少部分功能模块可以被设置于处理器6-110中。在一些实施例中,移动通信模块6-150的至少部分功能模块可以与处理器6-110的至少部分模块被设置在同一个器件中。
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低 频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器6-170A,受话器6-170B等)输出声音信号,或通过显示屏6-192显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器6-110,与移动通信模块6-150或其他功能模块设置在同一个器件中。
无线通信模块6-160可以提供应用在电子设备6-100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块6-160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块6-160经由天线6-2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器6-110。无线通信模块6-160还可以从处理器6-110接收待发送的信号,对其进行调频,放大,经天线6-2转为电磁波辐射出去。
在一些实施例中,电子设备6-100的天线6-1和移动通信模块6-150耦合,天线6-2和无线通信模块6-160耦合,使得电子设备6-100可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。
电子设备6-100通过GPU,显示屏6-192,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏6-192和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器6-110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏6-192用于显示图像,视频等。显示屏6-192包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备6-100 可以包括1个或N个显示屏6-192,N为大于1的正整数。
电子设备6-100可以通过ISP,摄像头6-191,视频编解码器,GPU,显示屏6-192以及应用处理器等实现拍摄功能。
ISP用于处理摄像头6-191反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头6-191中。
摄像头6-191用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备6-100可以包括1个或N个摄像头6-191,N为大于1的正整数。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备6-100在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。电子设备6-100可以支持一种或多种视频编解码器。这样,电子设备6-100可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备6-100的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。
内部存储器6-121可以包括一个或多个随机存取存储器(random access memory,RAM)和一个或多个非易失性存储器(non-volatile memory,NVM)。
随机存取存储器可以包括静态随机存储器(static random-access memory,SRAM)、动态随机存储器(dynamic random access memory,DRAM)、同步动态随机存储器(synchronous dynamic random access memory,SDRAM)、双倍资料率同步动态随机存取存储器(double data rate synchronous dynamic random access memory,DDR SDRAM,例如第五代DDR SDRAM一般称为DDR5SDRAM)等。
非易失性存储器可以包括磁盘存储器件、快闪存储器(flash memory)。快闪存储器按照运作原理划分可以包括NOR FLASH、NAND FLASH、3D NAND FLASH等,按照存储单元电位阶数划分可以包括单阶存储单元(single-level cell,SLC)、多阶存储单元(multi-level cell,MLC)、三阶储存单元(triple-level cell,TLC)、四阶储存单元(quad-level cell,QLC)等,按照存储规范划分可以包括通 用闪存存储(英文:universal flash storage,UFS)、嵌入式多媒体存储卡(embedded multi media Card,eMMC)等。
本申请实施例中,随机存取存储器称之为内存,非易失性存储器称之为外部存储。
内存6-1211可以由处理器6-110直接进行读写,可以用于存储操作系统或其他正在运行中的程序的可执行程序(例如机器指令),还可以用于存储用户及应用程序的数据等。
外部存储6-1212也可以存储可执行程序和存储用户及应用程序的数据等,可以提前加载到内存中,用于处理器6-110直接进行读写。
外部存储器接口6-120可以用于连接外部的非易失性存储器,实现扩展电子设备6-100的存储能力。外部的非易失性存储器通过外部存储器接口6-120与处理器6-110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部的非易失性存储器中。
电子设备6-100可以通过音频模块6-170,扬声器6-170A,受话器6-170B,麦克风6-170C,耳机接口6-170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块6-170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块6-170还可以用于对音频信号编码和解码。在一些实施例中,音频模块6-170可以设置于处理器6-110中,或将音频模块6-170的部分功能模块设置于处理器6-110中。
扬声器6-170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备6-100可以通过扬声器6-170A收听音乐,或收听免提通话。
受话器6-170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备6-100接听电话或语音信息时,可以通过将受话器6-170B靠近人耳接听语音。
麦克风6-170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风6-170C发声,将声音信号输入到麦克风6-170C。电子设备6-100可以设置至少一个麦克风6-170C。在另一些实施例中,电子设备6-100可以设置两个麦克风6-170C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备6-100还可以设置三个,四个或更多麦克风6-170C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。
耳机接口6-170D用于连接有线耳机。耳机接口6-170D可以是USB接口6-130,也可以是3.5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。
内存中应用动态分配的,没有文件背景的页面称为匿名页(anonymous page)。比如堆,栈,数据段等。如图6-2所示,当内存6-1211剩余空间不足时,可以 将内存6-1211中一部分匿名页移至外部存储6-1212的虚拟内存中,进行内存回收;如果应用需要访问的匿名页在内存中不存在,即产生了内存缺页,则可以将匿名页从外部存储6-1212加载至内存6-1211。将匿名页从内存6-1211移至外部存储6-1212称为内存换出,将匿名页从外部存储6-1212加载至内存6-1211称为内存换入。内存换出和内存换入统称为内存交换。
在一种实现方式中,如图6-3所示,内存换出时,匿名页数据存储于虚拟内存中存储地址随机的空余空间。内存换入时,将应用需要访问的匿名页从虚拟内存中加载至内存。由于应用需要访问的匿名页是随机的,内存换入时,从虚拟内存加载至内存中的匿名页的存储地址也是随机的。这种从虚拟内存中随机读取匿名页的方式的速度较慢,内存交换的性能较低。
本申请实施例提供一种内存管理方法,如图6-4所示,内存6-1211中包括缓存块,该缓存块可以是一段指定的内存区域,或者动态分配的内存区域等。示例性的,缓存块为Linux中ZRAM。本申请中将缓存块称为第五十内存区域。内存6-1211中为每个应用的各个进程分别分配了对应的内存区域,用于运行该进程程序和相关变量。可以理解的,缓存块是独立于为应用的进程分配的内存区域的。
当内存6-1211中用于应用进程的内存区域剩余空间不足时(比如,内存6-1211剩余空间小于第五十设定值),进行内存回收,将进程的内存区域中一部分匿名页移至缓存块。当缓存块剩余空间不足时(比如,缓存块剩余空间小于第五十一设定值),进行回写存储,将缓存块中一部分或全部匿名页移至虚拟内存。其中,移至虚拟内存中的匿名页包括属于第五十应用的匿名页数据6-410。在一种实现方式中,属于第五十应用的匿名页数据6-410在虚拟内存中占用存储地址连续的一段空间。第五十应用被切换至前台时,将属于该第五十应用的全部(或部分)匿名页数据加载至缓存块,即内存预取。之后,该第五十应用的进程被调用,如果产生内存缺页(即第五十应用的该进程需要访问的数据在该进程的内存区域中不存在),直接从缓存块中读取需要访问的匿名页。由于在应用切换至前台时,该应用的全部或大部分匿名页已经加载至缓存块。产生内存缺页时,直接从缓存块中读取需要访问的匿名页,访问的是内存中的数据,读取数据的性能不受外部存储读性能制约,提高了数据读取效率,有效避免产生系统卡顿。
下面结合附图,对本申请实施例提供的内存管理方法进行详细介绍。
如图6-5所示,本申请实施例提供的内存管理方法可以包括:
S6-501、当内存中剩余空间不足时,将内存中满足第五十条件的匿名页移至缓存块。其中,满足第五十条件的匿名页包括第五十应用的多个匿名页。
内存中以应用为单位进行内存管理。每个应用对应一个内存管理链表,用于对该应用相关的匿名页进行内存管理。一个应用对应的内存管理链表包括该应用相关的所有匿名页。
内存中剩余空间小于第五十设定值(比如,60%),不能再为进程分配内存区域,即内存中剩余空间不足,将内存中满足第五十条件的匿名页移至缓存块。
在一种示例中,从在后台运行的应用中随机的选取一个或多个应用,将该一个或多个应用对应的内存管理链表中的匿名页移至缓存块。
在另一种示例中,按照应用启动的先后顺序,将在后台运行的应用中最先启动的一个或多个应用对应的内存管理链表中的匿名页移至缓存块。
在另一种示例中,按照应用的冷热,将在后台运行的应用中最冷的一个或多个应用的匿名页移至缓存块。其中,应用最近一次未被调用的时长越长,该应用越冷;应用最近一次未被调用的时长越短,该应用越热。比如,每个应用对应一个字段,用来记录该应用自上次被调用以来所经历的时间t(t>=0);t值越大,对应的应用越冷;t值越小,对应的应用越热。
在另一种示例中,每个应用对应的内存管理链表采用最近最少使用(least recently used,LRU)算法机制(该内存管理链表也称为LRU链表)。内存管理链表中,匿名页按照从热到冷或者从冷到热的顺序排列。匿名页最近一次未被调用的时长越长,该匿名页越冷;最近一次最久未被调用(最近最少使用)的匿名页是最冷的匿名页。内存中剩余空间不足时,将内存中最冷的p(p>2,可以根据用户设定)个匿名页移至缓存块。
在缓存块中,匿名页以应用为单位进行管理。每个应用对应一个缓存管理链表,用于对该应用相关的匿名页进行管理。一个应用对应的缓存管理链表包括缓存块中该应用相关的所有匿名页数据。
示例性的,缓存块包括第五十应用对应的第五十缓存管理链表,第五十缓存管理链表中包括第五十应用相关的匿名页数据。
S6-502、当缓存块中剩余空间不足时,将缓存块中满足第五十一条件的匿名页移至虚拟内存。移出的匿名页中包括第五十应用的匿名页数据。
缓存块中剩余空间小于第五十一设定值(比如,80%),即缓存块中剩余空间不足,将缓存块中满足第五十一条件的匿名页移至虚拟内存。
在一种示例中,随机的选取一个或多个应用,将该一个或多个应用对应的缓存管理链表中的匿名页数据移至虚拟内存。
在另一种示例中,按照缓存块中匿名页数据的冷热,将最冷的q(q>2,可以根据用户设定)个匿名页数据移至虚拟内存。其中,先移入缓存页的匿名页数据比后移入缓存页的匿名页数据冷;后移入缓存页的匿名页数据比先移入缓存页的匿名页数据热。
在一种实现方式中,属于同一应用的匿名页数据移至虚拟内存中存储地址连续的空间。示例性的,缓存块中属于同一应用的多个匿名页数据组包为一个数据块,将属于同一应用的多个数据块移至虚拟内存中存储地址连续的空间。
在一些示例中,按照虚拟地址从前往后的顺序,寻找虚拟内存中空余的、大于或等于从缓存块中移出的匿名页数据占用空间的、存储地址连续的空间;并将匿名页数据移入该存储地址连续的空间。
可选的,如果不存在空余的、大于或等于从缓存块中移出的匿名页数据占用空间的、存储地址连续的空间,释放虚拟内存中一个或多个第五十一应用占用的 存储空间(存储块);即后台杀死一个或多个第五十一应用,清除该一个或多个第五十一应用在虚拟内存中的数据。比如,该第五十一应用可以是在虚拟内存中占用存储块最多的一个或多个应用。示例性的,如图6-6所示,虚拟内存中多个应用的匿名页数据分别占用了存储地址连续的一段空间。其中,被一个应用的匿名页数据占用连续空间最大的为空间6-601。触发释放虚拟内存中一个应用占用的存储空间时,释放占用空间6-601的应用;这样空出了储存地址连续的空间6-602,供缓存块中移入虚拟内存中的匿名页数据占用。空间6-602被两个应用的匿名页数据占用后,再次触发释放虚拟内存中一个应用占用的存储空间。这时,被一个应用的匿名页数据占用连续空间最大的为空间6-603,释放占用空间6-603的应用;这样空出了储存地址连续的空间6-604,供后续从缓存块中移入虚拟内存中的匿名页数据占用。
可选的,如果不存在空余的、大于或等于从缓存块中移出的匿名页数据占用空间的、存储地址连续的空间;按照从前往后的顺序查找虚拟内存中占用的空间大于或等于从缓存块中移出的匿名页数据占用空间的应用,将该应用杀死,释放该应用占用的存储空间。
可选的,如果不存在空余的、大于或等于从缓存块中移出的匿名页数据占用空间的、存储地址连续的空间;将最早移入虚拟内存中的匿名页数据属于的应用杀死,释放该应用占用的存储空间。
可以理解的,如果不存在空余的、大于或等于从缓存块中移出的匿名页数据占用空间的、存储地址连续的空间;还可以采用其他规则确定虚拟内存中被杀死的应用,释放该应用占用的存储空间。本申请实施例对此并不进行限定。
可选的,如果不存在空余的、大于或等于从缓存块中移出的匿名页数据占用空间的、存储地址连续的空间;则停止将数据块移入虚拟内存。
在另一些示例中,为每个应用预分配对应的存储地址连续的存储空间。其中,各个存储地址连续的存储空间的大小可以相同也可以不同。
S6-503、检测到第五十应用被切换至前台,将属于第五十应用的匿名页数据从虚拟内存加载至缓存块。
应用被切换至前台可以是指:电子设备的显示屏显示该应用的界面。
应用被切换至前台还可以是指:应用对应的Activity从pauase状态进入到活动状态。
其中,电子设备的软件系统可以采用分层架构。分层架构可将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将电子设备的软件系统分为三层,从上至下分别为应用程序层(简称应用层),应用程序框架层(简称框架层),以及内核层(也称为驱动层)。
其中,应用层可以包括一系列应用程序包。如为相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息以及桌面启动(Launcher)等应用程序。框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架。应用程序框架层包括一些预先定义的 函数。该框架层可以包括窗口管理器(window manager service,WMS)和活动管理器AMS等。
窗口管理器WMS用于管理窗口程序。窗口管理器可以获取显示屏大小,判断是否有状态栏,锁定屏幕,截取屏幕等。活动管理器AMS用于负责管理Activity,负责系统中各组件的启动、切换、调度及应用程序的管理和调度等工作。内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。内核层是硬件和软件之间的层。
其中,用户对电子设备进行输入操作(如触发电子设备显示某个应用的操作),内核层可以根据输入操作产生相应的输入事件(如折叠屏展开事件),并向应用程序框架层上报该事件。由应用程序框架层的活动管理服务器AMS设置应用的窗口属性。应用程序框架层的窗口管理服务器WMS根据AMS的设置绘制窗口,然后将窗口数据发送给内核层的显示驱动,由显示驱动在折叠屏显示对应的应用界面。
其中,窗口的属性可以包括Activity窗口的位置和大小,以及Activity窗口的可见属性(即Activity窗口的状态)。Activity窗口的位置是该Activity窗口在显示屏的位置、Activity窗口的大小可以是应用启动config中的宽高等信息。Activity窗口的可见属性可以为true或者false。当Activity窗口的可见属性是true时,表示该Activity窗口处于活动状态,该Activity窗口对用户可见,即显示驱动会显示该Activity窗口的内容。当Activity窗口的Activity的可见属性是false时,表示该Activity窗口处于pauase状态,该Activity窗口对用户不可见,即显示驱动会不显示该Activity窗口的内容。
其中,应用(如应用1或应用2)可调用启动Activity接口以启动对应的Activity。活动管理器AMS响应于应用的调用,可请求窗口管理器WMS绘制Activity对应的窗口,并调用显示驱动实现界面的显示。
其中,进入活动状态的应用会进行以下处理:(1)创建Application对象、Context对象;(2)调用Activity.attach()来创建Activity对应的窗口;(3)调用用户的onCreate方法,里面的setContentView方法创建activity的视图DecorView;(4)对Activity视图进行计算和绘制。完成了上述的步骤,应用的画面会被显示出来,该应用是前台应用。
需要说明的是,前台应用的画面内容不仅可以包括用户看的见的画面,还可以包括无用户界面的内容、透明图层的内容或者被其他应用界面遮挡对用户不可见的内容。
S6-504、在第五十应用的第五十进程被调用时,从缓存块读取第五十进程的匿名页数据。
在第五十应用的第五十进程被调用时,如果第五十进程的匿名页在内存中不存在,即产生了内存缺页;直接从缓存块读取第五十进程的匿名页数据。其中,第五十进程的匿名页数据是S6-503中加载至缓存中的属于第五十应用的匿名页数据的一部分。
由于在第五十应用切换至前台时,该应用的匿名页数据已经加载至缓存块。产生内存缺页时,直接从缓存块中读取需要访问的匿名页,读取数据的性能不受外部存储读性能制约,提高了数据读取效率,有效避免产生系统卡顿。并且,第五十应用的匿名页数据在外部存储中存储地址连续。匿名页数据从外部存储加载至缓存块时,从存储地址连续的空间读取数据,提高了读取效率。
在一些实施例中,请参考图6-7,内存中满足第五十条件的匿名页移至缓存块6-710。缓存块6-710中,以应用为单位管理匿名页。每个应用分别对应一个缓存管理链表。示例性的,应用1对应的缓存管理链表为应用1链表,包括属于应用1的匿名页;应用i对应的缓存管理链表为应用i链表,包括属于应用i的匿名页;应用n对应的缓存管理链表为应用n链表,包括属于应用n的匿名页。缓存块6-710中剩余空间不足时,将属于应用i的匿名页移至虚拟内存6-720。在一种实现方式中,将属于应用i的多个匿名页组包为一个数据块,将组包形成的多个数据块存储至虚拟内存6-720中存储地址连续的空间。比如,一个匿名页的大小为4k,一个数据块为32k,将8个匿名页组包为一个数据块。可以理解的,如果待组包的匿名页数量小于一个数据块最大允许的匿名页数量,可以将这些待组包的匿名页组包为一个数据块。虚拟内存6-720中包括多个存储块6-721,每个存储块6-721可以存储一个数据块。属于应用i的匿名页组包形成的多个数据块占用的存储块6-721的地址连续。可以理解的,一个数据块内的匿名页的存储地址可以连续,也可以不连续。
请参考图6-8,应用i被启动时,将属于应用i的匿名页数据从虚拟内存6-720加载至缓存块6-710。在一种实现方式中,在虚拟内存6-720中,应用i的匿名页数据以数据块的形式存储。数据块解包为多个匿名页后移入缓存块6-710。由于应用i的匿名页数据存储在虚拟内存6-720中存储地址连续的空间,提高了匿名页数据从虚拟内存6-720加载至缓存块6-710中的速率。应用i的第五十进程被调用时,直接从缓存块6-710中应用i链表包括的多个匿名页中读取第五十进程的匿名页。从缓存块6-710读取匿名页,是内存内部的数据交互,数据读取效率高;数据读取速率不受外部存储读性能制约,提高了数据读取效率,有效避免产生系统卡顿。
在一些实施例中,请参考图6-9,内存中满足第五十条件的匿名页移至缓存块6-710时,采用压缩算法压缩匿名页,将压缩后的匿名页(压缩对象)移入缓存块6-710。缓存块6-710中,每个应用对应的缓存管理链表中包括属于该应用的所有压缩的匿名页(压缩对象)。示例性的,应用1对应的缓存管理链表为应用1链表,包括属于应用1的压缩对象;应用i对应的缓存管理链表为应用i链表,包括属于应用i的压缩对象;应用n对应的缓存管理链表为应用n链表,包括属于应用n的压缩对象。缓存块6-710中剩余空间不足时,将属于应用i的压缩对象移至虚拟内存6-720。在一种实现方式中,将属于应用i的多个压缩对象组包为一个数据块,将组包形成的多个数据块存储至虚拟内存6-720中存储地址连续的空间。比如,一个匿名页的大小为4k,一个压缩对象的大小小于4k,一 个数据块最大为32k,将多个压缩对象组包为一个数据块。虚拟内存6-720中包括多个存储块6-721,每个存储块6-721可以存储一个数据块。属于应用i的压缩对象组包形成的多个数据块占用的存储块6-721的地址连续。可以理解的,一个数据块内的压缩对象的存储地址可以连续,也可以不连续。
请参考图6-10,应用i被启动时,将属于应用i的匿名页数据从虚拟内存6-720加载至缓存块6-710。在一种实现方式中,在虚拟内存6-720中,应用i的匿名页数据以数据块的形式存储。数据块解包为多个压缩对象后移入缓存块6-710。由于应用i的匿名页数据存储在虚拟内存6-720中存储地址连续的空间,提高了匿名页数据从虚拟内存6-720加载至缓存块6-710中的速率。应用i的第五十进程被调用时,直接从缓存块6-710中应用i链表包括的多个压缩对象中获取第五十进程的压缩对象,解压缩后获取到第五十进程的匿名页。从缓存块6-710读取压缩对象,是内存内部的数据交互,数据读取效率高;数据读取速率不受外部存储读性能制约,提高了数据读取效率,有效避免产生系统卡顿。在缓存块中存储压缩的匿名页可以节省内存空间,提高内存利用率。
在一些实施例中,请参考图6-11,内存中满足第五十条件的匿名页按照从冷到热的顺序移入缓存块。先移入缓存块的匿名页比后移入缓存块的匿名页冷。缓存管理链表中匿名页(或压缩对象)按照冷热排序。缓存块6-710中剩余空间不足时,按照从热到冷的顺序将匿名页(或压缩对象)组包形成多个数据块;这样,数据块按照从热到冷的顺序移入虚拟内存6-720中存储地址连续的空间。
请参考图6-12,应用i被启动时,按照从热到冷的顺序将应用i的数据块从虚拟内存6-720中加载至缓存块6-710。应用i的第五十进程被调用时,从缓存块6-710中应用i链表包括的多个匿名页(或压缩对象)中获取第五十进程的匿名页(或压缩对象)。在一种示例中,应用i的第五十进程被调用时,属于应用i的匿名页仅有部分加载至缓存块6-710。按照从热到冷的顺序将应用i的数据块从虚拟内存6-720加载至缓存块6-710,可以提高第五十进程被调用时,缓存块中包括第五十进程的匿名页的几率,即提高从缓存块读取到第五十进程匿名页的几率。从缓存块读取匿名页数据比从虚拟内存读取匿名页数据的速度更快,提高了数据读取效率,有效避免产生系统卡顿。
在一些实施例中,应用在后台被唤醒,需要访问某匿名页。该匿名页在内存中不存在,产生内存缺页。请参考图6-13,在一种实现方式中,将该匿名页所属的数据块从虚拟内存中加载至缓存块,获取到多个匿名页(或压缩对象);并从多个匿名页(或压缩对象)中读取需要访问的匿名页。可选的,也可以将更多的数据块从虚拟内存中加载至缓存块;或者将数据块的一部分加载至缓存块;本申请实施例对此并不进行限定。
这样,可能出现应用i的多个数据块在虚拟内存中存储地址不连续的情况。在一种实现方式中,从虚拟内存6-720中提取应用i的数据块时,可以跳过不存在数据块的存储块。示例性的,跳过的存储块数(跳跃间隔)小于设定的第五十数值(比如,第五十数值为1、2等)。
本申请实施例提供一种内存管理方法。内存中以应用的进程为单位进行内存管理。每个进程对应一个内存管理链表,用于对该进程相关的匿名页进行内存管理。一个进程对应的内存管理链表包括该进程相关的所有匿名页。当内存中剩余空间小于第五十设定值(比如,60%),即内存中剩余空间不足,将内存中满足第五十条件的匿名页移至缓存块。比如,可以随机选取一个或多个进程对应的内存管理链表中的匿名页移至缓存块。比如,按照进程的冷热,将最冷的进程(即最近最少被调用的进程)相关的匿名页移至缓存块。比如,按照匿名页的冷热,将最冷的多个匿名页移至缓存块。
在缓存块中,匿名页以进程为单位进行管理。每个进程对应一个缓存管理链表,用于对该进程相关的匿名页进行管理。一个进程对应的缓存管理链表包括缓存块中该进程相关的所有匿名页数据。
缓存块中剩余空间小于第五十一设定值(比如,80%),即缓存块中剩余空间不足,将缓存块中满足第五十一条件的匿名页移至虚拟内存中虚拟地址连续的空间。比如,可以随机选取一个或多个进程对应的缓存管理链表中的匿名页移至虚拟内存。比如,按照缓存块中匿名页数据的冷热,将最冷的q(q>2,可以根据用户设定)个匿名页数据移至虚拟内存。
检测到第五十应用被启动,将属于第五十应用的匿名页数据从虚拟内存加载至缓存块。在第五十应用的第五十进程被调用时,从缓存块读取第五十进程的匿名页数据。
由于在第五十应用切换至前台时,该应用的匿名页数据已经加载至缓存块。产生内存缺页时,直接从缓存块中读取需要访问的匿名页,读取数据的性能不受外部存储读性能制约,提高了数据读取效率,有效避免产生系统卡顿。
可以理解的是,上述电子设备为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请实施例能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。本领域技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请实施例的范围。
本申请实施例可以根据上述方法示例对上述电子设备进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
如图6-14所示,本申请实施例公开了一种电子设备6-1400,该电子设备6-1400具体可以包括:一个或多个处理器6-1401;存储器6-1402;一个或多个应用程序(未示出);一个或多个计算机程序6-1403;以及通信接口6-1404;上述各器件可以通过一个或多个通信总线6-1405连接。其中,上述一个或多个计 算机程序6-1403被存储在上述存储器6-1402中并被配置为被该一个或多个处理器6-1401执行,该一个或多个计算机程序6-1403包括指令,该指令可以用于执行上述实施例中的相关步骤。在一种示例中,该电子设备6-1400可以为图6-1中电子设备6-100。
本申请实施例还提供一种计算机可读存储介质,该计算机可读存储介质中存储有计算机程序代码,当处理器执行该计算机程序代码时,电子设备执行上述实施例中的方法。
本申请实施例还提供了一种计算机程序产品,当该计算机程序产品在计算机上运行时,使得计算机执行上述实施例中的方法。
其中,本申请实施例提供的电子设备6-1400、计算机可读存储介质或者计算机程序产品均用于执行上文所提供的对应的方法,因此,其所能达到的有益效果可参考上文所提供的对应的方法中的有益效果,此处不再赘述。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以使用硬件的形式实现,也可以使用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该软件产品存储在一个存储介质中,包括若干指令用以使得一个设备(可以是单片机,芯片等)或处理器(processor)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、ROM、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何在本申请揭露的技术范围内的变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。
在外部存储中设置虚拟内存是计算系统中一种常见的内存扩展方式。内存中应用动态分配的,没有文件背景的页面称为匿名页。将匿名页从内存移至外部存储称为内存换出,将匿名页从外部存储移至内存称为内存换入。内存换出和内存换入称为内存交换。内存交换的性能直接影响系统性能。
内存交换时,需要向内核系统申请以及释放大量的内存,用于匿名页数据在内存和外部存储中交换。一般来说,发生内存交换时,内核系统非常繁忙,内存资源非常紧张;大量的申请和释放内存带来内存交换的时延,会导致系统卡顿。
本申请实施例提供的内存管理方法,可以应用于图7-1所示的电子设备7-100。电子设备7-100可以是手机、平板电脑、桌面型计算机、膝上型计算机、手持计算机、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本,以及蜂窝电话、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)设备、虚拟现实(virtual reality,VR)设备、人工智能(artificial intelligence,AI)设备、可穿戴式设备、车载设备、智能家居设备和/或智慧城市设备,本申请实施例对该电子设备的具体类型不作特殊限制。
电子设备7-100可以包括处理器7-110,外部存储器接口7-120,内部存储器7-121,通用串行总线(universal serial bus,USB)接口7-130,充电管理模块7-140,电源管理模块7-141,电池7-142,天线7-1,天线7-2,移动通信模块7-150,无线通信模块7-160,音频模块7-170,扬声器7-170A,受话器7-170B,麦克风7-170C,耳机接口7-170D,传感器模块7-180,摄像头7-191以及显示屏7-192等。其中传感器模块7-180可以包括压力传感器,陀螺仪传感器,气压传感器,磁传感器,加速度传感器,距离传感器,接近光传感器,指纹传感器,温度传感器,触摸传感器,环境光传感器,骨传导传感器等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备7-100的具体限定。在本申请另一些实施例中,电子设备7-100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器7-110可以包括一个或多个处理单元,例如:处理器7-110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器7-110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器7-110中的存储器为高速缓冲存储器。该存储器可以保存处理器7-110刚用过或循环使用的指令或数据。如果处理器7-110需要再次使用该指令或数据, 可从所述存储器中直接调用。避免了重复存取,减少了处理器7-110的等待时间,因而提高了系统的效率。
在一些实施例中,处理器7-110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
I2C接口是一种双向同步串行总线,包括一根串行数据线(serial data line,SDA)和一根串行时钟线(derail clock line,SCL)。在一些实施例中,处理器7-110可以包含多组I2C总线。
I2S接口可以用于音频通信。在一些实施例中,处理器7-110可以包含多组I2S总线。处理器7-110可以通过I2S总线与音频模块7-170耦合,实现处理器7-110与音频模块7-170之间的通信。在一些实施例中,音频模块7-170可以通过I2S接口向无线通信模块7-160传递音频信号,实现通过蓝牙耳机接听电话的功能。
PCM接口也可以用于音频通信,将模拟信号抽样,量化和编码。在一些实施例中,音频模块7-170与无线通信模块7-160可以通过PCM总线接口耦合。在一些实施例中,音频模块7-170也可以通过PCM接口向无线通信模块7-160传递音频信号,实现通过蓝牙耳机接听电话的功能。所述I2S接口和所述PCM接口都可以用于音频通信。
UART接口是一种通用串行数据总线,用于异步通信。该总线可以为双向通信总线。它将要传输的数据在串行通信与并行通信之间转换。在一些实施例中,UART接口通常被用于连接处理器7-110与无线通信模块7-160。例如:处理器7-110通过UART接口与无线通信模块7-160中的蓝牙模块通信,实现蓝牙功能。在一些实施例中,音频模块7-170可以通过UART接口向无线通信模块7-160传递音频信号,实现通过蓝牙耳机播放音乐的功能。
MIPI接口可以被用于连接处理器7-110与显示屏7-192,摄像头7-191等外围器件。MIPI接口包括摄像头串行接口(camera serial interface,CSI),显示屏串行接口(display serial interface,DSI)等。在一些实施例中,处理器7-110和摄像头7-191通过CSI接口通信,实现电子设备7-100的拍摄功能。处理器7-110和显示屏7-192通过DSI接口通信,实现电子设备7-100的显示功能。
GPIO接口可以通过软件配置。GPIO接口可以被配置为控制信号,也可被配置为数据信号。在一些实施例中,GPIO接口可以用于连接处理器7-110与摄像头7-191,显示屏7-192,无线通信模块7-160,音频模块7-170,传感器模块7-180等。GPIO接口还可以被配置为I2C接口,I2S接口,UART接口,MIPI接口等。
USB接口7-130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口7-130可以用于连接充电器为电子设备7-100充电,也可以用于电子设备7-100与外围设备之间传输数据。也可以用于连接耳机,通过耳机播放音频。该接口还可以用于连接其他电子设备,例如AR设备等。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备7-100的结构限定。在本申请另一些实施例中,电子设备7-100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块7-140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块7-140可以通过USB接口7-130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块7-140可以通过电子设备7-100的无线充电线圈接收无线充电输入。充电管理模块7-140为电池7-142充电的同时,还可以通过电源管理模块7-141为电子设备供电。
电源管理模块7-141用于连接电池7-142,充电管理模块7-140与处理器7-110。电源管理模块7-141接收电池7-142和/或充电管理模块7-140的输入,为处理器7-110,内部存储器7-121,显示屏7-192,摄像头7-191,和无线通信模块7-160等供电。电源管理模块7-141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块7-141也可以设置于处理器7-110中。在另一些实施例中,电源管理模块7-141和充电管理模块7-140也可以设置于同一个器件中。
电子设备7-100的无线通信功能可以通过天线7-1,天线7-2,移动通信模块7-150,无线通信模块7-160,调制解调处理器以及基带处理器等实现。
天线7-1和天线7-2用于发射和接收电磁波信号。电子设备7-100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线7-1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块7-150可以提供应用在电子设备7-100上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块7-150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块7-150可以由天线7-1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块7-150还可以对经调制解调处理器调制后的信号放大,经天线7-1转为电磁波辐射出去。在一些实施例中,移动通信模块7-150的至少部分功能模块可以被设置于处理器7-110中。在一些实施例中,移动通信模块7-150的至少部分功能模块可以与处理器7-110的至少部分模块被设置在同一个器件中。
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低 频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器7-170A,受话器7-170B等)输出声音信号,或通过显示屏7-192显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器7-110,与移动通信模块7-150或其他功能模块设置在同一个器件中。
无线通信模块7-160可以提供应用在电子设备7-100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块7-160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块7-160经由天线7-2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器7-110。无线通信模块7-160还可以从处理器7-110接收待发送的信号,对其进行调频,放大,经天线7-2转为电磁波辐射出去。
在一些实施例中,电子设备7-100的天线7-1和移动通信模块7-150耦合,天线7-2和无线通信模块7-160耦合,使得电子设备7-100可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。
电子设备7-100通过GPU,显示屏7-192,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏7-192和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器7-110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏7-192用于显示图像,视频等。显示屏7-192包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备7-100 可以包括1个或N个显示屏7-192,N为大于1的正整数。
电子设备7-100可以通过ISP,摄像头7-191,视频编解码器,GPU,显示屏7-192以及应用处理器等实现拍摄功能。
ISP用于处理摄像头7-191反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头7-191中。
摄像头7-191用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备7-100可以包括1个或N个摄像头7-191,N为大于1的正整数。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备7-100在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。电子设备7-100可以支持一种或多种视频编解码器。这样,电子设备7-100可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备7-100的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。
内部存储器7-121可以包括一个或多个随机存取存储器(random access memory,RAM)和一个或多个非易失性存储器(non-volatile memory,NVM)。
随机存取存储器可以包括静态随机存储器(static random-access memory,SRAM)、动态随机存储器(dynamic random access memory,DRAM)、同步动态随机存储器(synchronous dynamic random access memory,SDRAM)、双倍资料率同步动态随机存取存储器(double data rate synchronous dynamic random access memory,DDR SDRAM,例如第五代DDR SDRAM一般称为DDR5SDRAM)等。
非易失性存储器可以包括磁盘存储器件、快闪存储器(flash memory)。快闪存储器按照运作原理划分可以包括NOR FLASH、NAND FLASH、3D NAND FLASH等,按照存储单元电位阶数划分可以包括单阶存储单元(single-level cell,SLC)、多阶存储单元(multi-level cell,MLC)、三阶储存单元(triple-level cell,TLC)、四阶储存单元(quad-level cell,QLC)等,按照存储规范划分可以包括通 用闪存存储(英文:universal flash storage,UFS)、嵌入式多媒体存储卡(embedded multi media Card,eMMC)等。
本申请实施例中,随机存取存储器称之为内存,非易失性存储器称之为外部存储。
内存7-1211可以由处理器7-110直接进行读写,可以用于存储操作系统或其他正在运行中的程序的可执行程序(例如机器指令),还可以用于存储用户及应用程序的数据等。
外部存储7-1212也可以存储可执行程序和存储用户及应用程序的数据等,可以提前加载到内存中,用于处理器7-110直接进行读写。
外部存储器接口7-120可以用于连接外部的非易失性存储器,实现扩展电子设备7-100的存储能力。外部的非易失性存储器通过外部存储器接口7-120与处理器7-110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部的非易失性存储器中。
电子设备7-100可以通过音频模块7-170,扬声器7-170A,受话器7-170B,麦克风7-170C,耳机接口7-170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块7-170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块7-170还可以用于对音频信号编码和解码。在一些实施例中,音频模块7-170可以设置于处理器7-110中,或将音频模块7-170的部分功能模块设置于处理器7-110中。
扬声器7-170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备7-100可以通过扬声器7-170A收听音乐,或收听免提通话。
受话器7-170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备7-100接听电话或语音信息时,可以通过将受话器7-170B靠近人耳接听语音。
麦克风7-170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风7-170C发声,将声音信号输入到麦克风7-170C。电子设备7-100可以设置至少一个麦克风7-170C。在另一些实施例中,电子设备7-100可以设置两个麦克风7-170C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备7-100还可以设置三个,四个或更多麦克风7-170C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。
耳机接口7-170D用于连接有线耳机。耳机接口7-170D可以是USB接口7-130,也可以是3.5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。
内存中应用动态分配的,没有文件背景的页面称为匿名页(anonymous page)。比如堆,栈,数据段等。如图7-2所示,当内存7-1211剩余空间不足时,可以 将内存7-1211中在后台运行的应用的一部分匿名页移至外部存储7-1212的虚拟内存中,进行内存回收;如果在后台运行的应用切换至前台后,该应用的进程需要访问的匿名页在内存中不存在,即产生了内存缺页,则可以将匿名页从外部存储7-1212加载至内存7-1211。将匿名页从内存7-1211移至外部存储7-1212称为内存换出,将匿名页从外部存储7-1212加载至内存7-1211称为内存换入。内存换出和内存换入统称为内存交换。
下面对本申请实施例中应用切换至前台进行介绍。
应用被切换至前台可以是指:电子设备的显示屏显示该应用的界面。
应用被切换至前台还可以是指:应用对应的Activity从pauase状态进入到活动状态。
其中,电子设备的软件系统可以采用分层架构。分层架构可将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将电子设备的软件系统分为三层,从上至下分别为应用程序层(简称应用层),应用程序框架层(简称框架层),以及内核层(也称为驱动层)。
其中,应用层可以包括一系列应用程序包。如为相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息以及桌面启动(Launcher)等应用程序。框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架。应用程序框架层包括一些预先定义的函数。该框架层可以包括窗口管理器(window manager service,WMS)和活动管理器AMS等。
窗口管理器WMS用于管理窗口程序。窗口管理器可以获取显示屏大小,判断是否有状态栏,锁定屏幕,截取屏幕等。活动管理器AMS用于负责管理Activity,负责系统中各组件的启动、切换、调度及应用程序的管理和调度等工作。内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。内核层是硬件和软件之间的层。
其中,用户对电子设备进行输入操作(如触发电子设备显示某个应用的操作),内核层可以根据输入操作产生相应的输入事件(如折叠屏展开事件),并向应用程序框架层上报该事件。由应用程序框架层的活动管理服务器AMS设置应用的窗口属性。应用程序框架层的窗口管理服务器WMS根据AMS的设置绘制窗口,然后将窗口数据发送给内核层的显示驱动,由显示驱动在折叠屏显示对应的应用界面。
其中,窗口的属性可以包括Activity窗口的位置和大小,以及Activity窗口的可见属性(即Activity窗口的状态)。Activity窗口的位置是该Activity窗口在显示屏的位置、Activity窗口的大小可以是应用启动config中的宽高等信息。Activity窗口的可见属性可以为true或者false。当Activity窗口的可见属性是true时,表示该Activity窗口处于活动状态,该Activity窗口对用户可见,即显示驱动会显示该Activity窗口的内容。当Activity窗口的Activity的可见属性是false时,表示该Activity窗口处于pauase状态,该Activity窗口对用户不可见,即显 示驱动会不显示该Activity窗口的内容。
其中,应用(如应用1或应用2)可调用启动Activity接口以启动对应的Activity。活动管理器AMS响应于应用的调用,可请求窗口管理器WMS绘制Activity对应的窗口,并调用显示驱动实现界面的显示。
其中,进入活动状态的应用会进行以下处理:(1)创建Application对象、Context对象;(2)调用Activity.attach()来创建Activity对应的窗口;(3)调用用户的onCreate方法,里面的setContentView方法创建activity的视图DecorView;(4)对Activity视图进行计算和绘制。完成了上述的步骤,应用的画面会被显示出来,该应用是前台应用。
需要说明的是,前台应用的画面内容不仅可以包括用户看的见的画面,还可以包括无用户界面的内容、透明图层的内容或者被其他应用界面遮挡对用户不可见的内容。
请参考图7-3,本申请实施例提供的内存管理方法,内存7-1211中包括缓存块,该缓存块可以是一段指定的内存区域,或者动态分配的内存区域等。示例性的,缓存块为Linux中ZRAM。当内存7-1211剩余空间不足时(比如,内存7-1211剩余空间小于第六十设定值),进行内存回收,将内存中一部分匿名页移至缓存块。在缓存块中,匿名页以应用为单位进行管理。每个应用对应一个缓存管理链表,用于对该应用相关的匿名页进行管理。一个应用对应的缓存管理链表包括缓存块中该应用相关的所有匿名页数据。示例性的,如图7-3所示,应用1对应的缓存管理链表为应用1链表,包括属于应用1的匿名页;应用i对应的缓存管理链表为应用i链表,包括属于应用i的匿名页;应用j对应的缓存管理链表为应用j链表,包括属于应用j的匿名页。
当缓存块剩余空间不足时(比如,缓存块剩余空间小于第六十一设定值),将缓存块中一部分或全部匿名页移至虚拟内存。在一种实现方式中,将多个匿名页组包为一个数据块,属于应用i的全部匿名页组包形成一个或多个数据块。比如,一个匿名页的大小为4k,一个数据块为32k,可以将8个匿名页组包为一个数据块。虚拟内存中包括多个存储块,每个存储块可以存储一个数据块。在一种实现方式中,属于应用i的匿名页组包形成的多个数据块占用的存储块的地址连续。可以理解的,一个数据块内的匿名页的存储地址可以连续,也可以不连续。
可选的,内存中匿名页可以压缩后移入缓存块,这样缓存块中每个缓存管理链表包括缓存块中该应用相关的所有压缩后的匿名页(压缩对象)。将缓存块中一部分或全部匿名页移至虚拟内存时,将多个压缩对象组包为一个数据块。移入虚拟内存中的每个数据块包括多个压缩对象。
当应用被切换至前台时,将属于该应用的全部(或部分)匿名页数据加载至缓存块。在一种示例中,虚拟内存中的匿名页数据以数据块的形式存储。从虚拟内存中提取应用j的匿名页数据,即提取应用j的多个数据块;将数据块解包为多个匿名页(或压缩对象)后移入缓存块。之后,该应用j的一个进程被调用,如果产生内存缺页(即应用j的该进程需要访问的数据在内存中不存在),直接 从缓存块中读取需要访问的匿名页。
在上述内存换出和内存换入过程中,匿名页数据以数据块形式从缓存块移至虚拟内存,并以数据块形式从虚拟内存加载至缓存块。内存交换过程包括大量的数据块移动。请参考图7-4,缓存块和虚拟内存间的内存交换由内存交换处理进行管理。一个内存交换处理管理多个数据块的移动。示例性的,一个内存交换处理支持最大1M的数据交换。一个数据块最大32k,一个内存交换处理最多可以管理32个数据块。缓存块和虚拟内存间可以包括多个并行的内存交换处理。
在一些实施例中,如图7-5所示,缓存块和虚拟内存间包括n个内存交换处理,该n个内存交换处理并行处理数据块的移动。每个内存交换处理管理多个数据块的移动。
当发生内存交换(内存换出或内存换入)时,每个内存交换处理为其管理的每个数据块分别向Linux内核申请一个内存。一个数据块移动(数据块由缓存块移至虚拟内存,或从虚拟内存加载至缓存块)完毕,就将该数据块对应的内存释放回Linux内核。这样,当发生内存交换时,会产生大量的向Linux内核申请内存和释放内存。大量的向Linux内核申请和释放内存会带来内存交换的时延,导致系统卡顿。
本申请实施例提供一种内存管理方法,如图7-6所示,当缓存块剩余空间不足,存在待从缓存块移入虚拟内存中的数据块时;或者检测到应用被切换至前台,存在待从虚拟内存加载至缓存块中的数据块时;内存交换处理需要为其管理的每个数据块申请对应的第六十内存。
本申请实施例中,内核系统用于分配内存,将分配的内存供调用者使用;还用于回收内存,停止将分配的内存供调用者使用。示例性的,内核系统为Linux内核。内存调用者可以向内核系统申请为其分配内存;或将分配的内存释放回内核系统,进行回收。
内存中包括内存交换内存池,用于存放内存中空闲的第六十内存。比如,可以将空闲的第六十内存在内存中的虚拟地址记录在内存交换内存池。内存交换内存池可以是一段指定的内存区域,或者动态分配的内存区域等。内存交换处理使用第六十内存将数据块从缓存块移入虚拟内存中之后,或者使用第六十内存将数据块从虚拟内存加载至缓存块中之后,该第六十内存即为空闲的第六十内存。空闲的第六十内存放入内存交换内存池,而不被内核系统回收,就可以继续供内存交换处理使用。
在一些示例中,内存交换处理需要为其管理的每个数据块申请对应的第六十内存时,先向内存交换内存池申请第六十内存。如果申请第六十内存成功,内存交换处理使用该第六十内存移动数据块(将数据块从缓存块移入虚拟内存中,或者将数据块从虚拟内存加载至缓存块中)。如果向内存交换内存池申请第六十内存失败(内存交换内存池中不存在空闲的第六十内存),内存交换处理向内核系统申请分配第六十内存。内存交换处理使用分配的第六十内存将一个预设大小的数据块从内存的缓存块移至外部存储中,或者从外部存储加载至内存的缓存块中。
内存交换处理使用第六十内存将数据块从缓存块移入虚拟内存中之后,或者使用第六十内存将数据块从虚拟内存加载至缓存块中之后,将第六十内存释放至内存交换内存池,使得内存交换内存池中增加一个第六十内存。这样,内存交换内存池中可以包括一个或多个第六十内存。内存交换处理可以再次向内存交换内存池申请第六十内存。
在一种实现方式中,当外部存储中不存在待加载至内存的缓存块中的数据块,并且内存的缓存块中不存在待移至外部存储中的数据块时,内存交换内存池向内核系统释放内存交换内存池中全部的第六十内存;即内核系统回收将分配的所有第六十内存回收。
在一种实现方式中,如果内存交换内存池中第六十内存大于设定阈值(示例性的,设定阈值为百分比,比如80%;示例性的,设定阈值为数据量大小,比如2M),内存交换内存池向内核系统释放内存交换内存池中部分的第六十内存。在一种示例中,将内存交换内存池中超过设定阈值的部分第六十内存释放回内核系统。在另一种示例中,将内存交换内存池中设定范围(比如,40%)的第六十内存释放回内核系统。
本申请实施例提供的内存管理方法,在内存交换过程中,内存交换处理使用内核系统分配的内存移动数据块后,将内存临时放入内存交换内存池,供内存交换处理再次使用。内存交换过程完成后,再将内核系统分配的内存释放回内核系统。这样,有效的减少向内核系统申请以及释放内存,降低了内存交换时延,提高内存交换性能。
可以理解的是,上述电子设备为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请实施例能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。本领域技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请实施例的范围。
本申请实施例可以根据上述方法示例对上述电子设备进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
如图7-7所示,本申请实施例公开了一种电子设备7-1400,该电子设备7-1400具体可以包括:一个或多个处理器7-1401;存储器7-1402;一个或多个应用程序(未示出);一个或多个计算机程序7-1403;以及通信接口7-1404;上述各器件可以通过一个或多个通信总线7-1405连接。其中,上述一个或多个计算机程序7-1403被存储在上述存储器7-1402中并被配置为被该一个或多个处理器7-1401执行,该一个或多个计算机程序7-1403包括指令,该指令可以用于执行 上述实施例中的相关步骤。在一种示例中,该电子设备7-1400可以为图7-1中电子设备7-100。
本申请实施例还提供一种计算机可读存储介质,该计算机可读存储介质中存储有计算机程序代码,当处理器执行该计算机程序代码时,电子设备执行上述实施例中的方法。
本申请实施例还提供了一种计算机程序产品,当该计算机程序产品在计算机上运行时,使得计算机执行上述实施例中的方法。
其中,本申请实施例提供的电子设备7-1400、计算机可读存储介质或者计算机程序产品均用于执行上文所提供的对应的方法,因此,其所能达到的有益效果可参考上文所提供的对应的方法中的有益效果,此处不再赘述。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以使用硬件的形式实现,也可以使用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该软件产品存储在一个存储介质中,包括若干指令用以使得一个设备(可以是单片机,芯片等)或处理器(processor)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、ROM、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何在本申请揭露的技术范围内的变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。

Claims (136)

  1. 一种内存管理方法,应用于电子设备,其特征在于,所述内存管理方法包括:
    第一应用启动时,创建所述第一应用的应用级内存控制组;
    将所述第一应用的匿名页添加至所述应用级内存控制组的最近最少使用链表中,根据所述最近最少使用链表对匿名页进行回收;
    将所述第一应用的文件页添加至内存节点的全局最近最少使用链表中,根据所述全局最近最少使用链表对文件页进行回收。
  2. 如权利要求1所述的内存管理方法,其特征在于,所述内存管理方法还包括:
    根据所述应用级内存控制组管理所述第一应用的匿名页;
    和/或根据所述第一应用的状态控制所述匿名页的回收顺序;
    和/或根据所述应用级内存控制组控制所述匿名页的回收比例,其中所述匿名页的回收比例为所述第一应用中待回收的匿名页数量与所述第一应用中匿名页的总数;
    和/或控制所述应用级内存控制组所管理的第一应用的内存使用量。
  3. 如权利要求2所述的内存管理方法,其特征在于,所述根据所述第一应用的状态控制所述匿名页的回收顺序还包括:
    根据所述第一应用的冻结状态和/或活跃状态和/或前台状态决定所述第一应用的匿名页的回收顺序。
  4. 如权利要求1至3任意一项所述的内存管理方法,其特征在于,所述第一应用启动时,创建所述第一应用的应用级内存控制组还包括:
    所述第一应用的第一进程启动时,按照所述第一进程所对应的应用标识创建所述第一应用对应的应用级内存控制组。
  5. 如权利要求4所述的内存管理方法,其特征在于,所述第一应用的第一进程启动时,按照所述第一进程所对应的应用标识创建所述第一应用对应的应用级内存控制组还包括:
    若所述第一进程对应的所述应用标识对应的内存控制组不存在,则创建所述第一应用对应的应用级内存控制组。
  6. 如权利要求2至5任意一项所述的内存管理方法,其特征在于,所述第一应用的第一进程启动时,按照所述第一进程所对应的应用标识创建所述第一应用对应的应用级内存控制组还包括:
    若所述应用标识存在内存控制组,则将所述第一进程添加到所述应用级内存控制组,根据所述应用级内存控制组管理所述第一进程。
  7. 如权利要求1至6任意一项所述的内存管理方法,其特征在于,所述内存管理方法还包括:
    电子设备启动时,按照白名单创建对应的内存控制组;
    系统进程启动时,按照系统进程的进程名判断是否为白名单进程;若是白名单进程,则将该白名单进程添加至所述内存控制组。
  8. 如权利要求7所述的内存管理方法,其特征在于,所述内存管理方法还包括:
    将所述白名单进程的匿名页添加至所述内存控制组的最近最少使用链表;
    根据所述最近最少使用链表对所述白名单进程的匿名页进行回收。
  9. 如权利要求7所述的内存管理方法,其特征在于,所述内存管理方法还包括:
    将所述白名单进程的文件页添加至内存节点的全局最近最少使用链表;
    根据所述全局最近最少使用链表对所述白名单进程的文件页进行回收。
  10. 如权利要求1至6任意一项所述的内存管理方法,其特征在于,所述内存管理方法还包括:
    当所述第一应用的第二进程启动时,将所述第二进程的匿名页添加到所述第一内存控制组的所述最近最少使用链表中,并将所述第二进程的文件页添加到全局最近最少使用链表中。
  11. 如权利要求10所述的内存管理方法,其特征在于,所述内存管理方法还包括:
    当所述第一进程和/或所述第二进程销毁时,将所述第一进程和/或所述第二进程从所述应用级内存控制组中删除。
  12. 如权利要求10所述的内存管理方法,其特征在于,所述内存管理方法还包括:
    当所述第一应用销毁时,删除所述应用级内存控制组。
  13. 如权利要求1至10任意一项所述的内存管理方法,其特征在于,所述内存管理方法还包括:
    当所述第一应用申请到所述匿名页时,将所述匿名页添加至所述应用级内存控制组的活跃最近最少使用链表中;
    当所述第一应用申请到所述文件页时,将所述文件页添加至全局活跃最近最少使用链表中。
  14. 一种内存管理装置,其特征在于,包括:
    创建模块,所述创建模块用于在第一应用启动时,创建所述第一应用的应用级内存控制组;
    控制模块,所述控制模块用于将所述第一应用的匿名页添加至所述应用级内存控制组的最近最少使用链表中,根据所述最近最少使用链表对匿名页进行回收;
    所述控制模块还用于将所述第一应用的文件页添加至内存节点的全局最近最少使用链表中,根据所述全局最近最少使用链表对文件页进行回收。
  15. 如权利要求14所述的内存管理装置,其特征在于,还包括
    管理模块,所述管理模块用于:
    根据所述应用级内存控制组管理所述第一应用的匿名页;
    和/或根据所述第一应用的状态控制所述匿名页的回收顺序;
    和/或根据所述应用级内存控制组控制所述匿名页的回收比例;
    和/或控制所述应用级内存控制组所管理的第一应用的内存使用量。
  16. 如权利要求14或15所述的内存管理装置,其特征在于,
    所述创建模块还用于在所述第一应用的第一进程启动时,按照所述第一进程所对应的应用标识创建所述第一应用对应的应用级内存控制组。
  17. 如权利要求16所述的内存管理装置,其特征在于,
    所述创建模块还用于在所述第一进程对应的所述应用标识对应的内存控制组不存在时,创建所述第一应用对应的应用级内存控制组。
  18. 如权利要求17所述的内存管理装置,其特征在于,
    所述控制模块用于在所述应用标识存在内存控制组时,将所述第一进程添加到所述应用级内存控制组;
    所述管理模块还用于根据所述应用级内存控制组管理所述第一进程。
  19. 一种电子设备,其特征在于,包括:
    存储器,用于存储有及计算机程序;
    处理器,用于执行所述存储器存储的所述计算机程序,当所述计算机程序被执行时,所述处理器用于执行如权利要求1至13任意一项所述的内存管理方法。
  20. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如权利要求1至13任意一项所述的内存管理方法。
  21. 一种内存管理方法,其特征在于,所述内存管理方法包括:
    创建第十应用的第十内存控制组和第十一应用的第十一内存控制组;
    设置第十内存控制组的重要评分值;
    设置第十一内存控制组的重要评分值;
    内存控制组链表按照所述第十内存控制组和所述第十一内存控制组的重要评分值,对所述第十内存控制组及所述第十一内存控制组进行排序;
    根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,对所述第十内存控制组及第十一内存控制组进行内存回收。
  22. 如权利要求21所述的内存管理方法,其特征在于,所述设置第十内存控制组的重要评分值还包括:
    根据所述第十应用的状态设置所述第十内存控制组的重要评分值;
    根据所述第十一应用的状态设置所述第十一内存控制组的重要评分值。
  23. 如权利要求21或22所述的内存管理方法,其特征在于,根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,对所述第十内存控制组及所述第十一内存控制组进行内存回收还包括:
    按照压缩比例对所述第十内存控制组进行内存压缩,并将压缩后的数据放入 交换区中;
    按照压缩比例对所述第十一内存控制组进行内存压缩,并将压缩后的数据放入交换区中。
  24. 如权利要求21至23任意一项所述的内存管理方法,其特征在于根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,对所述第十内存控制组及所述第十一内存控制组进行内存回收还包括:
    若交换区的数据达到预设水线,按照换出比例将所述第十内存控制组的数据从交换区中换出至外部存储;
    若交换区的数据达到预设水线,按照换出比例将所述第十一内存控制组的数据从交换区中换出至外部存储。
  25. 如权利要求21至24任意一项所述的内存管理方法,其特征在于,
    根据所述第十应用的状态设置所述第十内存控制组的压缩比例和/或换出比例;
    根据所述第十一应用的状态设置所述第十一内存控制组的压缩比例和/或换出比例。
  26. 如权利要求21至25任意一项所述的内存管理方法,其特征在于,
    根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,控制所述第十内存控制组和第十一内存控制组的压缩顺序和换出顺序。
  27. 如权利要求21至26任意一项所述的内存管理方法,其特征在于,
    若所述第十应用的压缩量占比达到压缩比例,则终止对所述第十应用的压缩,并继续按照所述内存控制组链表中内存控制组的排序进行压缩。
  28. 如权利要求21至27任意一项所述的内存管理方法,其特征在于,
    若所述第十应用的换出量占比达到换出比例,则终止对所述第十应用的换出,并继续按照所述内存控制组链表中内存控制组的排序进行换出。
  29. 如权利要求21至28任意一项所述的内存管理方法,其特征在于,所述创建第十应用的第十内存控制组和第十一应用的第十一内存控制组还包括:
    第十应用启动时,创建所述第十应用的第十内存控制组,并设定所述第十内存控制组的重要评分值为第十预设值。
  30. 如权利要求21至29任意一项所述的内存管理方法,其特征在于,所述创建第十应用的第十内存控制组和第十一应用的第十一内存控制组还包括:
    第十一应用启动时,创建所述第十一应用的第十一内存控制组,并设定所述第十内存控制组的重要评分值为第十预设值。
  31. 一种内存管理装置,其特征在于,包括;
    创建模块,所述创建模块用于创建第十应用的第十内存控制组和第十一应用的第十一内存控制组;
    控制模块,所述控制模块用于设置第十内存控制组的重要评分值和第十一内存控制组的重要评分值;
    所述控制模块还用于控制内存控制组链表按照所述第十内存控制组和所述 第十一内存控制组的重要评分值,对所述第十内存控制组及所述第十一内存控制组进行排序;
    回收模块,所述回收模块用于根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,对所述第十内存控制组及第十一内存控制组进行内存回收。
  32. 如权利要求11所述的内存管理装置,其特征在于,还包括:
    所述控制模块还用于根据所述第十应用的状态设置所述第十内存控制组的重要评分值和或压缩比例和/或换出比例;
    所述控制模块还用于根据所述第十一应用的状态设置所述第十一内存控制组的重要评分值和或压缩比例和/或换出比例。
  33. 如权利要求31或32所述的内存管理装置,其特征在于,
    所述回收模块还用于按照压缩比例对所述第十内存控制组进行内存压缩,并将压缩后的数据放入交换区中;
    所述回收模块还用于按照压缩比例对所述第十一内存控制组进行内存压缩,并将压缩后的数据放入交换区中。
  34. 如权利要求31至33任意一项所述的内存管理装置,其特征在于,
    所述回收模块还用于在交换区的数据达到预设水线时,按照换出比例将所述第十内存控制组的数据从交换区中换出至外部存储;
    所述回收模块还用于在交换区的数据达到预设水线时,按照换出比例将所述第十一内存控制组的数据从交换区中换出至外部存储。
  35. 如权利要求31至34任意一项所述的内存管理装置,其特征在于,还包括:
    所述回收模块还用于根据所述内存控制组链表中所述第十内存控制组和所述第十一内存控制组的排序,控制所述第十内存控制组和第十一内存控制组的压缩顺序和换出顺序。
  36. 如权利要求31至35任意一项所述的内存管理装置,其特征在于,还包括:
    所述创建模块用于在所述第十应用启动时,创建所述第十应用的第十内存控制组。
  37. 如权利要求31至36任意一项所述的内存管理装置,其特征在于,
    所述创建模块还用于在所述第十应用启动时,创建所述第十应用的第十内存控制组。
  38. 如权利要求31或37所述的内存管理装置,其特征在于,
    所述创建模块还用于在所述第十一应用启动时,创建所述第十一应用的第十一内存控制组。
  39. 一种电子设备,其特征在于,包括:
    存储器,用于存储计算机程序;
    处理器,用于执行所述存储器存储的所述计算机程序,当所述计算机程序被 执行时,所述处理器用于执行如权利要求21至30任意一项所述的内存管理方法。
  40. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如权利要求21至30任意一项所述的内存管理方法。
  41. 一种内存管理方法,应用于电子设备,其特征在于,所述内存管理方法包括:
    创建内存统计值,所述内存统计值用以表征电子设备系统内存中剩余的可用内存,所述可用内存包括第三十一内存和第三十二内存,
    所述第三十一内存为空闲内存,所述空闲内存为系统尚未使用的内存,
    所述第三十二内存为被占用但是可通过回收来转换为第三十一内存的内存;
    所述内存统计值包括第三十一内存统计值及第三十二内存统计值,
    所述第三十一内存统计值大于所述第三十二内存统计值,
    当系统当前的内存统计值低于所述第三十二内存统计值时,
    启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存;
    当通过匿名页压缩后系统当前的内存统计值低于所述第三十一内存统计值时,下调所述内存统计值。
  42. 如权利要求41所述的内存管理方法,其特征在于,所述内存统计值还包括第三十三内存统计值,所述第三十三内存统计值小于所述第三十二内存统计值,所述方法还包括:
    当下调所述内存统计值且系统当前的内存统计值低于所述第三十三内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存,直至系统当前的内存统计值不低于所述第三十三内存统计值。
  43. 如权利要求41或42所述的内存管理方法,其特征在于,所述方法还包括:
    监控交换区的空间使用率;
    当当前所述交换区的空间使用率达到预设比例时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
  44. 如权利要求43所述的内存管理方法,其特征在于,
    所述启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存,包括:
    确认系统当前的内存压力等级为第三十一等级,并上报为第三十一级压力事件;
    根据所述第三十一级压力事件启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存;
    所述当通过匿名页压缩后系统当前的内存统计值低于所述第三十一内存统计值时,下调所述内存统计值,包括:
    确认系统当前的内存压力等级为第三十二等级,上报为第三十二级压力事件;
    根据所述第三十二级压力事件下调所述内存统计值;
    所述当当前所述交换区的空间使用率达到预设比例时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存,包括:
    确认系统当前的内存压力等级为第三十三等级,上报为第三十三级压力事件;
    根据所述第三十三级压力事件,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存;
    所述第三十三等级的内存压力高于所述第三十二等级的内存压力,所述第三十二等级的内存压力高于所述第三十一等级的内存压力。
  45. 如权利要求41至44任意一项所述的内存管理方法,其特征在于,
    所述内存统计值还包括第三十四内存统计值,所述方法还包括:
    当系统当前的压力失速信息(PSI)值大于预设阈值时,上报PSI压力值;
    当接收到所述PSI压力值,且确认系统当前的内存统计值小于所述第三十四内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
  46. 如权利要求41至45任意一项所述的内存管理方法,其特征在于,所述方法还包括:
    监控是否有预设应用启动;
    当监控到有预设应用启动,且系统当前的内存统计值小于所述第三十一内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
  47. 如权利要求42所述的内存管理方法,其特征在于,当系统处于灭屏状态时,所述第三十一内存统计值、第三十二内存统计值、第三十三内存统计值分别低于当系统处于亮屏状态时的第三十一内存统计值、第三十二内存统计值、第三十三内存统计值。
  48. 如权利要求42至47任意一项所述的内存管理方法,其特征在于,所述方法还包括:
    根据应用的重要程度,进程优先级和/或应用匿名页大小及分布对进程进行排序,以根据排序后的进程来杀死进程。
  49. 如权利要求41至48任意一项的内存管理方法,其特征在于,所述方法还包括:
    配置回收参数;
    根据所述回收参数压缩匿名页,以回收所述第三十二内存;
    所述回收参数包括目标内存页的数量,目标内存页回收的优先级,和/ 或内存回收比例(ratio)。
  50. 一种内存管理装置,其特征在于,所述内存管理装置包括:
    创建模块,用以创建内存统计值,所述内存统计值用以表征电子设备系统内存中剩余的可用内存,所述可用内存包括第三十一内存和第三十二内存,所述第三十一内存为空闲内存,所述空闲内存为系统尚未使用的内存,所述第三十二内存为被占用但是可通过回收来转换为第三十一内存的内存;所述内存统计值包括第三十一内存统计值及第三十二内存统计值,所述第三十一内存统计值大于所述第三十二内存统计值;
    内存回收模块,用以当系统当前的内存统计值低于所述第三十二内存统计值时启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存;
    内存调整模块,用以当通过匿名页压缩后系统当前的内存统计值低于所述第三十一内存统计值时下调所述内存统计值。
  51. 如权利要求50所述的内存管理装置,其特征在于,所述内存统计值还包括第三十三内存统计值,所述第三十三内存统计值小于所述第三十二内存统计值,所述内存回收模块还用以当下调所述内存统计值且系统当前的内存统计值低于所述第三十三内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
  52. 如权利要求50或51所述的内存管理装置,其特征在于,所述内存管理装置还包括上报模块,所述上报模块用以监控交换区的空间使用率,所述内存回收模块还用以当当前所述交换区的空间使用率达到预设比例时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
  53. 如权利要求52所述的内存管理装置,其特征在于,所述上报模块还用以当系统当前的内存统计值低于所述第三十二内存统计值时,确认系统当前的内存压力等级为第三十一等级,并上报为第三十一级压力事件,所述内存回收模块再根据所述第三十一级压力事件启动匿名页压缩,以回收所述第三十二内存,以将所述第三十二内存转换为所述第三十一内存;
    所述上报模块还用以当通过匿名页压缩后系统当前的内存统计值低于所述第三十一内存统计值时,确认系统当前的内存压力等级为第三十二等级,并上报为第三十二级压力事件,所述内存调整模块再根据所述第三十二级压力事件下调所述内存统计值;
    所述上报模块还用以当当前所述交换区的空间使用率达到预设比例时,确认系统当前的内存压力等级为第三十三等级,并上报为第三十三级压力事件,所述内存回收模块再根据所述第三十三级压力事件,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存;
    所述第三十三等级的内存压力高于所述第三十二等级的内存压力,所述第三十二等级的内存压力高于所述第三十一等级的内存压力。
  54. 如权利要求52或53所述的内存管理装置,其特征在于,所述内存统计值还包括第三十四内存统计值,所述上报模块还用以当系统当前的压力失速信息(PSI)值大于预设阈值时上报PSI压力值;
    所述内存回收模块还用以当接收到所述PSI压力值,且当系统当前的内存统计值小于所述第三十四内存统计值时,通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
  55. 如权利要求50至54任意一项所述的内存管理装置,其特征在于,所述内存回收模块还用以监控是否有预设应用启动,当监控到有预设应用启动,且系统当前的内存统计值小于所述第三十一内存统计值时,所述内存回收模块通过杀死进程来回收所述第三十二内存,以将所述第三十二内存转换为第三十一内存。
  56. 如权利要求51任意一项所述的内存管理装置,其特征在于,当系统处于灭屏状态时,所述第三十一内存统计值、第三十二内存统计值、第三十三内存统计值分别低于当系统处于亮屏状态时的第三十一内存统计值、第三十二内存统计值、第三十三内存统计值。
  57. 如权利要求50至56任意一项所述的内存管理装置,其特征在于,所述内存回收模块用以根据应用的重要程度,进程优先级和/或应用匿名页大小及分布对进程进行排序,并根据排序后的进程来杀死进程。
  58. 如权利要求50至57任意一项所述的内存管理装置,其特征在于,所述内存回收模块还用以配置回收参数,并根据所述回收参数压缩匿名页,以回收所述第三十二内存;
    所述回收参数包括目标内存页的数量,目标内存页回收的优先级,和/或内存回收比例(ratio)。
  59. 一种电子设备,其特征在于,包括:
    存储单元,用于存储有计算机程序;
    处理器,用于执行所述存储器存储的所述计算机程序,当所述计算机程序被执行时,所述处理器用于执行如权利要求41至49任意一项所述的方法。
  60. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如权利要求41至49任意一项所述的方法。
  61. 一种匿名页管理方法,其特征在于,所述方法包括:
    将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数;
    将所述匿名页换出的数据从所述外部存储空间换入到所述内存中,记录换入时刻的时间参数;
    根据所述换出时刻的时间参数和所述换入时刻的时间参数,获取所述换入到所述换出的时间间隔信息;
    当所述时间间隔信息对应的数值比预设固定值大时,将匿名页换入所述内存的不活跃链表。
  62. 如权利要求61所述的匿名页管理方法,其特征在于,所述将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数包括:
    当匿名页的数据从内存换出到外部存储空间时,根据所述匿名页所属不活跃链表移动页面个数得到换出时刻的时间参数。
  63. 如权利要求62所述的匿名页管理方法,其特征在于,所述将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数还包括:
    当匿名页的数据从内存换出到外部存储空间时,将所述换出时刻的时间参数存储至该匿名页对应的页表项。
  64. 如权利要求62或63所述的匿名页管理方法,其特征在于,所述方法还包括:
    根据所述匿名页所属不活跃链表的页面移动,记录所述匿名页所属不活跃链表移动页面个数。
  65. 如权利要求64所述的匿名页管理方法,其特征在于,所述匿名页所属不活跃链表的页面移动包括:
    所述匿名页所属不活跃链表的页面从不活跃链表尾部移除,或,所述匿名页所属不活跃链表的页面移动到活跃链表。
  66. 如权利要求61至65任一项所述的匿名页管理方法,其特征在于,所述将所述匿名页换出的数据从所述外部存储空间换入到所述内存中,记录换入时刻的时间参数包括:
    当所述匿名页换出的数据从所述外部存储空间换入到内存中时,根据所述匿名页所属不活跃链表移动页面个数得到所述换入时刻的时间参数。
  67. 如权利要求61至66任一项所述的匿名页管理方法,其特征在于,还包括:
    当所述匿名页发生缺页中断,且检测到所述匿名页换出的数据的存储位置在所述外部存储空间,将所述匿名页换出的数据从所述外部存储空间换入到所述内存。
  68. 一种匿名页管理装置,其特征在于,包括:
    第四十记录单元,用于将匿名页的数据从内存换出到外部存储空间,记录换出时刻的时间参数;
    第四十一记录单元,用于将所述匿名页换出的数据从所述外部存储空间换入到所述内存中,记录换入时刻的时间参数;
    获取单元,用于根据所述换出时刻的时间参数和所述换入时刻的时间参数,获取所述换入到所述换出的时间间隔信息;
    换入单元,用于当所述时间间隔信息对应的数值比预设固定值大时,将匿名页换入所述内存的不活跃链表。
  69. 如权利要求68所述的匿名页管理装置,其特征在于,所述第四十记录单元包括:
    参数获取单元,用于当匿名页的数据从内存换出到外部存储空间时,根据所述匿名页所属不活跃链表移动页面个数得到换出时刻的时间参数。
  70. 如权利要求69所述的匿名页管理装置,其特征在于,所述第四十记录单元还包括:
    存储单元,用于当匿名页的数据从内存换出到外部存储空间时,将所述换出时刻的时间参数存储至该匿名页对应的页表项。
  71. 如权利要求69或70所述的匿名页管理装置,其特征在于,所述匿名页管理装置还包括:
    页面记录单元,用于根据所述匿名页所属不活跃链表的页面移动,记录所述匿名页所属不活跃链表移动页面个数。
  72. 如权利要求71所述的匿名页管理装置,其特征在于,所述匿名页所属不活跃链表的页面移动包括:
    所述匿名页所属不活跃链表的页面从不活跃链表尾部移除,或,所述匿名页所属不活跃链表的页面移动到活跃链表。
  73. 如权利要求68至72任一项所述的匿名页管理装置,其特征在于,所述第四十一记录单元包括:
    当所述匿名页换出的数据从所述外部存储空间换入到内存中时,根据所述匿名页所属不活跃链表移动页面个数得到所述换入时刻的时间参数。
  74. 如权利要求68或69所述的匿名页管理装置,其特征在于,所述匿名页管理装置还包括:
    中断单元,用于当所述匿名页发生缺页中断,且检测到所述匿名页换出的数据的存储位置在所述外部存储空间,将所述匿名页换出的数据从所述外部存储空间换入到所述内存。
  75. 一种电子设备,其特征在于,包括:
    存储器,用于存储有计算机程序;
    处理器,用于执行所述存储器存储的所述计算机程序,当所述计算机程序被执行时,所述处理器用于执行如权利要求61至67任意一项所述的匿名页管理方法。
  76. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如权利要求61至67任意一项所述的方法。
  77. 一种计算机程序产品,其特征在于,所述计算机程序产品包括计算机程序代码,当所述计算机程序代码被一个计算机执行的时候,所述计算机程序代码可以使得所述计算机执行权利要求61至67项任意一项的匿名页管理方法。
  78. 一种存储器的寿命管理方法,应用在电子设备中,其特征在于,所述方法包括:
    获取第一周期由所述电子设备的内存待换出到所述电子设备的存储器的第一数据;
    获取所述存储器在所述第一周期的总数据配额,从所述总数据配额减去所述存储器的预设用户数据使用量得到所述第一周期的换出数据配额;
    根据所述换出数据配额将所述第一数据从内存换出到所述存储器;
    获取所述存储器的状态信息,并根据所述存储器的状态信息确定所述存储器在第二周期的换出数据配额,其中所述状态信息包括:
    擦写次数
    和/或
    总使用寿命
    和/或
    已使用寿命
    和/或
    容量
    和/或
    器件写入放大系数
    和/或
    已使用时间。
  79. 如权利要求78所述的存储器的寿命管理方法,其特征在于,从所述总数据配额减去所述存储器的预设用户数据使用量得到所述第一周期的换出数据配额包括:
    获取所述存储器在所述第一周期的擦写次数;
    根据所述存储器在所述第一周期的擦写次数及所述第一周期计算出所述存储器在所述第一周期的擦写次数的增长速度;
    根据所述存储器在所述第一周期的擦写次数的增长速度确定所述预设用户数据使用量;
    从所述总数据配额减去所述预设用户数据使用量得到所述存储器在所述第一周期的换出数据配额。
  80. 如权利要求79所述的存储器的寿命管理方法,其特征在于,所述根据所述存储器在所述第一周期的擦写次数的增长速度确定所述预设用户数据使用量包括:
    将所述存储器在所述第一周期的擦写次数的增长速度输入到磁盘寿命预测模型,并经过所述磁盘寿命预测模型处理后输出所述预设用户数据使用量,其中,所述磁盘寿命预测模型为学习所述存储器的擦写次数增长速度及所述预设用户数据使用量之间的关系的神经网络模型。
  81. 如权利要求78所述的存储器的寿命管理方法,其特征在于,根据 所述换出数据配额将所述第一数据从内存换出到所述存储器包括:
    判断所述第一周期是否结束;
    若所述第一周期没有结束,获取在所述第一周期已换出到所述存储器的数据,并将所述第一周期的换出数据配额与在所述第一周期已换出到所述存储器的数据相减得到剩余数据配额;
    判断所述第一数据是否小于所述剩余数据配额;
    若所述第一数据小于或等于所述剩余数据配额,将所有所述第一数据从内存换出到所述存储器;
    若所述第一数据大于或等于所述剩余数据配额,从所述第一数据中选出与所述剩余数据配额相同数据量的目标数据,将所述目标数据从内存换出到所述存储器,并关闭所述存储器的写入功能。
  82. 如权利要求81所述的存储器的寿命管理方法,其特征在于,所述方法还包括:
    若确定所述第一周期结束,在所述第二周期重新计算所述存储器的换出数据配额得到更新的换出数据配额,并在所述第二周期依据更新的换出数据配额对所述第二周期待换出到所述存储器的第二数据进行写入管控。
  83. 如权利要求78所述的存储器的寿命管理方法,其特征在于,所述根据所述存储器的状态信息确定所述存储器在第二周期的换出数据配额包括:
    获取所述存储器在所述第二周期内预设时间段内的擦写次数;
    根据所述存储器在所述预设时间段内的擦写次数的增长速度计算所述存储器在所述预设时间段内的擦写次数的增长速度;
    将所述存储器的擦写次数的增长速度输入到磁盘寿命预测模型中,并经过所述磁盘寿命预测模型处理后输出所述存储器在所述第二周期的总数据配额;
    将所述存储器在所述第二周期的总数据配额减去所述第二周期的预设用户数据使用量得到所述存储器在所述第二周期的换出数据配额,其中,所述磁盘寿命预测模型为用于学习所述存储器的擦写次数增长速度及所述存储器的总数据配额之间的关系的神经网络模型。
  84. 如权利要求78所述的存储器的寿命管理方法,其特征在于,所述获取所述存储器在所述第一周期的换出数据配额包括:
    设定所述存储器的目标使用时间;
    获取所述存储器的已使用寿命及所述存储器的总使用寿命;
    获取所述存储器的器件写入放大系数及所述存储器的容量;
    根据公式p=(e-b)*q/((c/t)*w)计算得到所述存储器在所述第一周期的换出数据配额,其中,e为所述存储器的总使用寿命,b为所述存储器的已使用寿命,q为所述存储器的容量,c为存储器的目标使用时间,w为所述存储器的器件写入放大系数,t为所述第一周期,p为换出数据配额。
  85. 如权利要求84所述的存储器的寿命管理方法,其特征在于,所述根据所述换出数据配额将所述第一数据从内存换出到所述存储器包括:
    基于预设计时方式进行计时,并获取所述预设计时方式下的计时时间;
    判断所述计时时间是否在所述第一周期内:
    若所述计时时间在所述第一周期内,获取所述第一周期开始时间到所述计时时间前累计换出到所述存储器的累加数据;
    将所述存储器在所述第一周期的换出数据配额与所述累加数据相减得到剩余数据配额;
    若所述第一数据小于所述剩余数据配额,将所述第一数据从内存换出到所述存储器;
    若所述第一数据不小于所述剩余数据配额,从所述第一数据中选出与所述剩余数据配额相同数据量的目标数据,并将所述目标数据从内存换出到所述存储器,并关闭所述存储器的写入功能。
  86. 如权利要求84所述的存储器的寿命管理方法,其特征在于,所述根据所述存储器的状态信息确定所述存储器在第二周期的换出数据配额包括:
    获取所述存储器的已使用时间;
    根据公式p=(e-b)*q/((c-c1)*w/t)计算得到所述存储器在所述第二周期的换出数据配额,其中,c1为所述存储器的已使用时间。
  87. 如权利要求85所述的存储器的寿命管理方法,其特征在于,所述方法还包括:
    若获取到所述电子设备的关机指令,将所述计时时间及所述第一周期开始时间到所述计时时间前累计换出到所述存储器的所述累加数据存储到所述存储器中,其中,所述存储器为非易失性存储器。
  88. 如权利要求87所述的存储器的寿命管理方法,其特征在于,所述方法还包括:
    若获取到所述电子设备的开机指令,从所述存储器中读取所述计时时间及所述累加数据,并根据所述计时时间及所述累加数据对所述第一周期内待换出到所述存储器的第一数据进行管控。
  89. 如权利要求78所述的存储器的寿命管理方法,其特征在于,所述方法还包括:
    设置检测周期;
    在每一所述检测周期获取所述存储器的已使用寿命及所述存储器的总使用寿命;
    在每一所述检测周期计算所述存储器的已使用寿命与所述存储器的总使用寿命的比值得到第一占比值;
    若在每一所述检测周期所述第一占比值小于预设占比值,将所述第一数据从所述内存换出到所述存储器;
    若在每一所述检测周期所述第一占比值大于或等于预设占比值,不将所述第一数据从所述内存换出到所述存储器,并关闭所述存储器的写入功能。
  90. 如权利要求78所述的存储器的寿命管理方法,其特征在于,所述方法还包括:
    确定所述存储器的目标使用时间;
    获取所述存储器的已使用寿命;
    若所述存储器的已使用寿命大于或等于所述存储器的目标使用时间,将所述第一数据从所述内存换出到所述存储器;
    若所述存储器的已使用寿命小于所述存储器的目标使用时间,根据公式d=k1*(c-b)*100/b计算得到数据限制量,其中,c为所述存储器的目标使用时间,b为所述存储器的已使用寿命,k1为用户设定的配置系数,所述配置系数表示相比较所述存储器的目标使用时间每少1%应对所述存储器在所述第一周期的换出数据配额减去多少GB单位的存储数据,d为数据限制量;
    将所述第一周期的换出数据配额减去所述数据限制量的差值作为所述存储器在所述第一周期的换出数据配额。
  91. 如权利要求90所述的存储器的寿命管理方法,其特征在于,所述确定所述存储器的目标使用时间包括:
    获取所述存储器的目标使用寿命及所述存储器的总使用寿命;
    计算所述存储器的已使用寿命与所述存储器的总使用寿命的比例得到第二占比值;
    根据公式c=k2*a计算得到所述存储器的目标使用时间,其中a为存储器的目标使用寿命,k2为所述第二占比值。
  92. 如权利要求90所述的存储器的寿命管理方法,其特征在于,所述配置系数为1GB。
  93. 如权利要求78所述的存储器的寿命管理方法,其特征在于,所述预设用户数据使用量为上周期的非系统软件写入所述存储器的数据量。
  94. 一种存储器的寿命管理方法,应用在电子设备中,其特征在于,所述方法包括:
    获取第一周期由所述电子设备的内存待换出到所述电子设备的存储器的第一数据;
    获取所述存储器在所述第一周期的换出数据配额;
    根据所述换出数据配额将所述第一数据从内存换出到所述存储器。
  95. 一种电子设备,其特征在于,所述电子设备包括存储器和处理器:
    其中,所述存储器,用于存储程序指令;
    所述处理器,用于读取并执行所述存储器中存储的所述程序指令,当所述程序指令被所述处理器执行时,使得所述电子设备执行如权利要求78至94中任一项所述的存储器的寿命管理方法。
  96. 一种计算机存储介质,其特征在于,所述计算机存储介质存储有程 序指令,当所述程序指令在电子设备上运行时,使得所述电子设备执行如权利要求78至94中任一项所述的存储器的寿命管理方法。
  97. 一种内存管理方法,其特征在于,包括:
    检测到第五十应用切换至前台,将属于所述第五十应用的第五十匿名页数据从外部存储加载至第五十内存区域中;
    如果所述第五十应用的第五十进程被调用时,所述第五十进程的第五十一匿名页在所述第五十进程的内存区域不存在,从所述第五十内存区域读取第五十一匿名页数据;所述第五十匿名页数据包括所述第五十一匿名页数据。
  98. 根据权利要求97所述的方法,其特征在于,
    所述第五十匿名页数据在所述外部存储中存储为至少一个预设大小的数据块;所述至少一个数据块的存储地址满足预设条件。
  99. 根据权利要求98所述的方法,其特征在于,所述预设条件包括:
    存储地址连续;或者,
    存储地址最大跳跃间隔小于第五十数值。
  100. 根据权利要求97-99任意一项所述的方法,其特征在于,所述方法还包括:
    将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据移至外部存储中存储地址连续的第五十空间。
  101. 根据权利要求100所述的方法,其特征在于,所述第五十内存区域中属于所述第五十应用的匿名页数据根据冷热排序,
    所述将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据移至外部存储中存储地址连续的第五十空间包括:
    按照从冷到热的顺序将属于所述第五十应用的第五十二匿名页数据从所述第五十内存区域中移出,并将所述第五十二匿名页数据存储至外部存储中存储地址连续的第五十空间。
  102. 根据权利要求101所述的方法,其特征在于,所述将属于所述第五十应用的第五十匿名页数据从外部存储加载至第五十内存区域中包括:
    按照从热到冷的顺序,将属于所述第五十应用的第五十匿名页数据从外部存储加载至第五十内存区域中。
  103. 根据权利要求101或102所述的方法,其特征在于,所述方法还包括:
    将内存中最近最少使用的匿名页移至所述第五十内存区域;其中,先移至所述第五十内存区域的匿名页数据比后移至所述第五十内存区域的匿名页数据更冷。
  104. 根据权利要求100-103任意一项所述的方法,其特征在于,所述将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据移至外部存储中存储地址连续的第五十空间包括:
    将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据组包为一个或多个数据块;
    将所述一个或多个数据块移至外部存储中存储地址连续的第五十空间;
    其中,一个所述数据块包括多个所述第五十二匿名页数据。
  105. 根据权利要求104所述的方法,其特征在于,所述将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据组包为一个或多个数据块包括:
    将所述第五十内存区域中属于所述第五十应用的压缩后的第五十二匿名页数据组包为一个或多个数据块。
  106. 根据权利要求100-105任意一项所述的方法,其特征在于,所述方法还包括:
    若外部存储中空余的存储地址连续的第五十空间小于所述第五十二匿名页数据占用空间,释放所述外部存储中属于第五十一应用的匿名页数据;所述第五十一应用为外部存储中占用存储地址连续的空间最大的应用。
  107. 一种电子设备,其特征在于,所述电子设备包括:
    存储器,所述存储器包括内存和外部存储;
    处理器,调用所述存储器中存储的一个或多个计算机程序,所述一个或多个计算机程序包括指令,当所述指令被所述处理器执行时,使得所述电子设备执行:
    检测到第五十应用切换至前台,将属于所述第五十应用的第五十匿名页数据从所述外部存储加载至所述内存的第五十内存区域中;
    如果所述第五十应用的第五十进程被调用时,所述第五十进程的第五十一匿名页在所述第五十进程的内存区域中不存在,从所述第五十内存区域读取第五十一匿名页数据;所述第五十匿名页数据包括所述第五十一匿名页数据。
  108. 根据权利要求107所述的电子设备,其特征在于,
    所述第五十匿名页数据在所述外部存储中存储为至少一个预设大小的数据块;所述至少一个数据块的存储地址满足预设条件。
  109. 根据权利要求108所述的电子设备,其特征在于,所述预设条件包括:
    存储地址连续;或者,
    存储地址最大跳跃间隔小于第五十数值。
  110. 根据权利要求107-109任意一项所述的电子设备,其特征在于,当所述指令被所述处理器执行时,还使得所述电子设备执行:
    将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据移至所述外部存储中存储地址连续的第五十空间。
  111. 根据权利要求110所述的电子设备,其特征在于,所述第五十内存区域中属于所述第五十应用的匿名页数据根据冷热排序,
    所述将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据移至所述外部存储中存储地址连续的第五十空间包括:
    按照从冷到热的顺序将属于所述第五十应用的第五十二匿名页数据从所述第五十内存区域中移出,并将所述第五十二匿名页数据存储至外部存储中存储地址连续的第五十空间。
  112. 根据权利要求111所述的电子设备,其特征在于,所述将属于所述第五十应用的第五十匿名页数据从所述外部存储加载至所述内存的第五十内存区域中包括:
    按照从热到冷的顺序,将属于所述第五十应用的第五十匿名页数据从所述外部存储加载至所述内存的第五十内存区域中。
  113. 根据权利要求111或112所述的电子设备,其特征在于,当所述指令被所述处理器执行时,还使得所述电子设备执行:
    将所述内存中最近最少使用的匿名页移至所述第五十内存区域;其中,先移至所述第五十内存区域的匿名页数据比后移至所述第五十内存区域的匿名页数据更冷。
  114. 根据权利要求110-113任意一项所述的电子设备,其特征在于,所述将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据移至所述外部存储中存储地址连续的第五十空间包括:
    将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据组包为一个或多个数据块;
    将所述一个或多个数据块移至所述外部存储中存储地址连续的第五十空间;
    其中,一个所述数据块包括多个所述第五十二匿名页数据。
  115. 根据权利要求114所述的电子设备,其特征在于,所述将所述第五十内存区域中属于所述第五十应用的第五十二匿名页数据组包为一个或多个数据块包括:
    将所述第五十内存区域中属于所述第五十应用的压缩后的第五十二匿名页数据组包为一个或多个数据块。
  116. 根据权利要求110-115任意一项所述的电子设备,其特征在于,当所述指令被所述处理器执行时,还使得所述电子设备执行:
    若所述外部存储中空余的存储地址连续的第五十空间小于所述第五十二匿名页数据占用空间,释放所述外部存储中属于第五十一应用的匿名页数据;所述第五十一应用为外部存储中占用存储地址连续的空间最大的应用。
  117. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如权利要求97-106任意一项所述的方法。
  118. 一种计算机程序产品,其特征在于,当所述计算机程序产品在计算机上运行时,使得所述计算机执行如权利要求97-106任意一项所述的方法。
  119. 一种内存管理方法,其特征在于,包括:
    检测到第六十应用切换至前台,向内存交换内存池申请第六十内存;所述内存交换内存池用于存放第六十内存;
    使用所述第六十内存将一个预设大小的数据块从外部存储加载至内存的缓存块中;一个所述数据块包括所述第六十应用的一个或多个匿名页。
  120. 根据权利要求119所述的方法,其特征在于,所述方法还包括:
    若向所述内存交换内存池申请第六十内存失败,向内核系统申请分配第六十内存;
    使用所述内核系统分配的第六十内存将一个所述预设大小的数据块从外部存储加载至内存的缓存块中。
  121. 根据权利要求119或120所述的方法,其特征在于,所述方法还包括:
    使用第六十内存将一个预设大小的数据块从内存的缓存块移至外部存储中。
  122. 根据权利要求119-121任意一项所述的方法,其特征在于,所述方法还包括:
    将第六十内存释放至所述内存交换内存池,使得所述内存交换内存池中增加一个第六十内存。
  123. 根据权利要求119-122任意一项所述的方法,其特征在于,所述方法还包括:
    满足第六十设定条件时,向内核系统释放所述内存交换内存池中全部的第六十内存。
  124. 根据权利要求123所述的方法,其特征在于,所述第六十设定条件包括:
    所述外部存储中不存在待加载至所述内存的缓存块中的数据块;并且,
    所述内存的缓存块中不存在待移至所述外部存储中的数据块。
  125. 根据权利要求119-124任意一项所述的方法,其特征在于,所述方法还包括:
    满足第六十一设定条件时,向内核系统释放所述内存交换内存池中部分第六十内存。
  126. 根据权利要求125所述的方法,其特征在于,所述第六十一设定条件包括:
    所述内存交换内存池中的第六十内存大于设定阈值。
  127. 一种电子设备,其特征在于,所述电子设备包括:
    存储器,所述存储器包括内存和外部存储;
    处理器,调用所述存储器中存储的一个或多个计算机程序,所述一个或多个计算机程序包括指令,当所述指令被所述处理器执行时,使得所述电子设备执行:
    检测到第六十应用切换至前台,向内存交换内存池申请第六十内存;所述内存交换内存池用于存放第六十内存;
    使用所述第六十内存将一个预设大小的数据块从外部存储加载至内存的缓存块中;一个所述数据块包括所述第六十应用的一个或多个匿名页。
  128. 根据权利要求127所述的电子设备,其特征在于,当所述指令被所述处理器执行时,还使得所述电子设备执行:
    若向所述内存交换内存池申请第六十内存失败,向内核系统申请分配第六十内存;
    使用所述内核系统分配的第六十内存将一个所述预设大小的数据块从外部存储加载至内存的缓存块中。
  129. 根据权利要求127或128所述的电子设备,其特征在于,当所述指令被所述处理器执行时,还使得所述电子设备执行:
    使用第六十内存将一个预设大小的数据块从内存的缓存块移至外部存储中。
  130. 根据权利要求127-129任意一项所述的电子设备,其特征在于,当所述指令被所述处理器执行时,还使得所述电子设备执行:
    将第六十内存释放至所述内存交换内存池,使得所述内存交换内存池中增加一个第六十内存。
  131. 根据权利要求127-130任意一项所述的电子设备,其特征在于,当所述指令被所述处理器执行时,还使得所述电子设备执行:
    满足第六十设定条件时,向内核系统释放所述内存交换内存池中全部的第六十内存。
  132. 根据权利要求131所述的电子设备,其特征在于,所述第六十设定条件包括:
    所述外部存储中不存在待加载至所述内存的缓存块中的数据块;并且,
    所述内存的缓存块中不存在待移至所述外部存储中的数据块。
  133. 根据权利要求127-132任意一项所述的电子设备,其特征在于,当所述指令被所述处理器执行时,还使得所述电子设备执行:
    满足第六十一设定条件时,向内核系统释放所述内存交换内存池中部分第六十内存。
  134. 根据权利要求133所述的电子设备,其特征在于,所述第六十一设定条件包括:
    所述内存交换内存池中的第六十内存大于设定阈值。
  135. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如权利要求119-126任意一项所述的方法。
  136. 一种计算机程序产品,其特征在于,当所述计算机程序产品在计算机上运行时,使得所述计算机执行如权利要求119-126任意一项所述的方法。
PCT/CN2021/126523 2020-10-31 2021-10-26 内存管理方法、装置、电子设备以及计算机可读存储介质 WO2022089452A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP21885179.8A EP4220400A4 (en) 2020-10-31 2021-10-26 MEMORY MANAGEMENT METHOD AND APPARATUS, ELECTRONIC DEVICE AND COMPUTER-READABLE STORAGE MEDIUM
US18/251,157 US20240054079A1 (en) 2020-10-31 2021-10-26 Memory Management Method and Apparatus, Electronic Device, and Computer-Readable Storage Medium

Applications Claiming Priority (16)

Application Number Priority Date Filing Date Title
CN202011197416 2020-10-31
CN202011197410 2020-10-31
CN202011197410.1 2020-10-31
CN202011197416.9 2020-10-31
CN202011381223.9 2020-11-30
CN202011381363.6 2020-11-30
CN202011381379 2020-11-30
CN202011381363 2020-11-30
CN202011381379.7 2020-11-30
CN202011381223 2020-11-30
CN202011385387.9 2020-12-01
CN202011385387 2020-12-01
CN202011540521.8 2020-12-23
CN202011540521 2020-12-23
CN202011628747.3A CN114443268A (zh) 2020-10-31 2020-12-30 内存管理方法、装置、电子设备以及计算机可读存储介质
CN202011628747.3 2020-12-30

Publications (1)

Publication Number Publication Date
WO2022089452A1 true WO2022089452A1 (zh) 2022-05-05

Family

ID=81361905

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/126523 WO2022089452A1 (zh) 2020-10-31 2021-10-26 内存管理方法、装置、电子设备以及计算机可读存储介质

Country Status (4)

Country Link
US (1) US20240054079A1 (zh)
EP (1) EP4220400A4 (zh)
CN (2) CN114443277A (zh)
WO (1) WO2022089452A1 (zh)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114741205A (zh) * 2022-06-02 2022-07-12 荣耀终端有限公司 一种匿名页回收方法及电子设备
CN116049024A (zh) * 2023-01-06 2023-05-02 广州匠芯创科技有限公司 内存页面回收优化方法及其系统、电子设备、存储介质
CN116048769A (zh) * 2022-08-11 2023-05-02 荣耀终端有限公司 内存回收方法、装置和终端设备
CN116680142A (zh) * 2022-11-15 2023-09-01 荣耀终端有限公司 内存资源监测方法、电子设备、程序产品及介质
WO2024037428A1 (zh) * 2022-08-17 2024-02-22 中移(苏州)软件技术有限公司 一种进程处理方法和设备

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114443277A (zh) * 2020-10-31 2022-05-06 华为终端有限公司 内存管理方法、装置、电子设备以及计算机可读存储介质
CN117112251B (zh) * 2022-05-27 2024-06-14 荣耀终端有限公司 一种通信方法及相关设备
CN115033378B (zh) * 2022-06-06 2023-01-06 北京熵核科技有限公司 一种关于易失性内存的管理方法
CN115328856B (zh) * 2022-07-05 2023-05-09 荣耀终端有限公司 一种文件页管理的方法、装置及电子设备
CN115061954B (zh) * 2022-08-18 2022-11-29 统信软件技术有限公司 一种缺页中断处理方法、计算设备及存储介质
CN116701238A (zh) * 2022-09-14 2023-09-05 荣耀终端有限公司 一种驱动文件处理方法及相关装置
WO2024076068A1 (ko) * 2022-10-06 2024-04-11 삼성전자주식회사 복수의 프로세스들의 릴리즈를 제어하기 위한 전자 장치 및 그 방법
CN117130947A (zh) * 2023-01-31 2023-11-28 荣耀终端有限公司 一种内存管理方法及电子设备
CN115858046B (zh) * 2023-02-28 2023-07-21 荣耀终端有限公司 一种预加载内存页的方法、电子设备及芯片系统
CN116126744B (zh) * 2023-04-04 2023-08-22 荣耀终端有限公司 一种内存回收方法、装置及终端设备
CN116185644A (zh) * 2023-04-26 2023-05-30 阿里云计算有限公司 内存回收控制方法、存储介质、处理器及终端设备
CN116225976B (zh) * 2023-05-05 2023-08-08 麒麟软件有限公司 一种Linux操作系统下的水位线自调整方法及系统
CN116776781B (zh) * 2023-08-17 2023-11-07 浪潮电子信息产业股份有限公司 一种寄存器参数的管理方法、系统、设备及存储介质

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140189267A1 (en) * 2012-12-31 2014-07-03 Emc Corporation Method and apparatus for managing memory space
CN104375899A (zh) * 2014-11-21 2015-02-25 北京应用物理与计算数学研究所 高性能计算机numa感知的线程和内存资源优化方法与系统
CN108205501A (zh) * 2017-06-26 2018-06-26 珠海市魅族科技有限公司 内存回收方法及装置、计算机装置及计算机可读存储介质
US20180307600A1 (en) * 2015-12-31 2018-10-25 Huawei Technologies Co., Ltd. Memory reclaim method and apparatus
US10228868B1 (en) * 2016-09-30 2019-03-12 EMC IP Holding Company LLC Managing lifespan of a flash memory
CN110532197A (zh) * 2019-08-30 2019-12-03 Oppo(重庆)智能科技有限公司 内存回收方法及装置、电子设备、存储介质
CN111831441A (zh) * 2020-07-01 2020-10-27 Oppo广东移动通信有限公司 内存回收方法、装置、存储介质及电子设备

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8719501B2 (en) * 2009-09-08 2014-05-06 Fusion-Io Apparatus, system, and method for caching data on a solid-state storage device
EP3504628B1 (en) * 2016-09-28 2020-09-09 Huawei Technologies Co., Ltd. Memory management method and device
US10824371B2 (en) * 2017-06-19 2020-11-03 Micron Technology, Inc. Managed NAND data compression
CN108287761B (zh) * 2017-08-09 2020-11-06 珠海市魅族科技有限公司 内存回收方法及装置、终端设备及计算机可读存储介质
CN108664411A (zh) * 2018-05-03 2018-10-16 晶晨半导体(上海)股份有限公司 一种内存链表及内存管理的优化方法
CN114443277A (zh) * 2020-10-31 2022-05-06 华为终端有限公司 内存管理方法、装置、电子设备以及计算机可读存储介质

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140189267A1 (en) * 2012-12-31 2014-07-03 Emc Corporation Method and apparatus for managing memory space
CN104375899A (zh) * 2014-11-21 2015-02-25 北京应用物理与计算数学研究所 高性能计算机numa感知的线程和内存资源优化方法与系统
US20180307600A1 (en) * 2015-12-31 2018-10-25 Huawei Technologies Co., Ltd. Memory reclaim method and apparatus
US10228868B1 (en) * 2016-09-30 2019-03-12 EMC IP Holding Company LLC Managing lifespan of a flash memory
CN108205501A (zh) * 2017-06-26 2018-06-26 珠海市魅族科技有限公司 内存回收方法及装置、计算机装置及计算机可读存储介质
CN110532197A (zh) * 2019-08-30 2019-12-03 Oppo(重庆)智能科技有限公司 内存回收方法及装置、电子设备、存储介质
CN111831441A (zh) * 2020-07-01 2020-10-27 Oppo广东移动通信有限公司 内存回收方法、装置、存储介质及电子设备

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP4220400A4

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114741205A (zh) * 2022-06-02 2022-07-12 荣耀终端有限公司 一种匿名页回收方法及电子设备
CN114741205B (zh) * 2022-06-02 2022-11-11 荣耀终端有限公司 一种匿名页回收方法及电子设备
CN116048769A (zh) * 2022-08-11 2023-05-02 荣耀终端有限公司 内存回收方法、装置和终端设备
CN116048769B (zh) * 2022-08-11 2023-11-21 荣耀终端有限公司 内存回收方法、装置和终端设备
WO2024037428A1 (zh) * 2022-08-17 2024-02-22 中移(苏州)软件技术有限公司 一种进程处理方法和设备
CN116680142A (zh) * 2022-11-15 2023-09-01 荣耀终端有限公司 内存资源监测方法、电子设备、程序产品及介质
CN116680142B (zh) * 2022-11-15 2024-05-07 荣耀终端有限公司 内存资源监测方法、电子设备、程序产品及介质
CN116049024A (zh) * 2023-01-06 2023-05-02 广州匠芯创科技有限公司 内存页面回收优化方法及其系统、电子设备、存储介质

Also Published As

Publication number Publication date
EP4220400A4 (en) 2024-01-17
CN114443277A (zh) 2022-05-06
EP4220400A1 (en) 2023-08-02
US20240054079A1 (en) 2024-02-15
CN114443268A (zh) 2022-05-06

Similar Documents

Publication Publication Date Title
WO2022089452A1 (zh) 内存管理方法、装置、电子设备以及计算机可读存储介质
US7571295B2 (en) Memory manager for heterogeneous memory control
EP3506106B1 (en) Method for processing application, electronic device, and computer-readable storage medium
WO2022257748A1 (zh) 虚拟内存管理方法和电子设备
US10956316B2 (en) Method and device for processing reclaimable memory pages, and storage medium
EP3506114B1 (en) Memory processing method and device and storage medium
WO2019128546A1 (zh) 应用程序处理方法、电子设备、计算机可读存储介质
WO2019137252A1 (zh) 内存处理方法、电子设备、计算机可读存储介质
WO2022078105A1 (zh) 内存管理方法、电子设备以及计算机可读存储介质
JP2024515462A (ja) アプリケーションによる描画操作を実行する方法及び電子装置
WO2021093626A1 (zh) 一种内存的管理方法及电子设备
CN112711387B (zh) 缓冲区容量的调整方法、装置、电子设备及可读存储介质
WO2019128542A1 (zh) 应用处理方法、电子设备、计算机可读存储介质
EP4328705A1 (en) Storage space arrangement method and electronic device
US20220058118A1 (en) Garbage Data Scrubbing Method, and Device
WO2023202429A1 (zh) 垃圾回收的方法及电子设备
CN116166573B (zh) 控制内存回收的方法、电子设备及存储介质
CN116701298B (zh) 一种文件系统管理方法及电子设备
WO2020133437A1 (zh) 应用程序的管理方法、装置、存储介质及电子设备
WO2023185684A1 (zh) 一种应用程序的进程查杀方法及电子设备
CN116225632A (zh) 线程调度方法、设备及相关装置
CN117130947A (zh) 一种内存管理方法及电子设备
CN114449094A (zh) 管控方法及电子设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21885179

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2021885179

Country of ref document: EP

Effective date: 20230427

NENP Non-entry into the national phase

Ref country code: DE