Memory management method, terminal equipment and computer readable storage medium

By allocating exclusive swap partitions to each user in the terminal device, the inefficient swap efficiency caused by random scattered storage of anonymous pages in a multi-user login environment is solved, and the user experience and performance are improved.

CN118915953APending Publication Date: 2024-11-08HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310506106.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-06
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

When multiple users log in to the terminal device, the anonymous pages are randomly stored in the swap partition, resulting in low swap efficiency of anonymous pages, poor user experience, and active users need to wait for memory to be released when there is insufficient memory, affecting performance.

Method used

When the terminal device detects preset trigger events (such as user login, logout, and switch), it stores the anonymous pages of each user to the user's exclusive exchange partition to ensure that the anonymous pages are stored in the exchange partition of the corresponding user and avoids the exchange of useless data. , improve the efficiency of swap.

Benefits of technology

Through user-specific swap partition management, the efficiency of anonymous page swap is improved, the user experience and the performance of active users is improved, and the reasonable allocation and rapid release of memory resources are ensured.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118915953A_ABST
    Figure CN118915953A_ABST
Patent Text Reader

Abstract

The invention is suitable for the technical field of terminals, and particularly relates to a memory management method, terminal equipment and a computer readable storage medium. In the method, when a preset trigger event is detected, terminal equipment can store target anonymous pages corresponding to all users to exchange partitions allocated to all the users. According to the method and the device, the exchange partitions can be set according to the users, so that the anonymous pages corresponding to the users can be uniformly stored in the exchange partitions corresponding to the users, and when the anonymous pages of the application of a certain user are exchanged subsequently, the anonymous pages can be exchanged only from the exchange partitions corresponding to the users; the method and the device have the advantages that the anonymous pages of other users cannot be swapped in, swap-in of useless data is reduced, swap-in efficiency is improved, user experience is improved, and the method and the device have high usability and practicability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of terminal technology, and in particular, relates to a memory management method, a terminal device, and a computer-readable storage medium. Background Art

[0002] At present, the terminal device can support multiple users to log in, for example, it can support user A, user B and user C to log in. When multiple users log in to the terminal device, there is generally only one active user (such as user A) at the same time, and the other users are inactive users (such as user B and user C). When the active user switches from user A to user B, all applications of user A will become background applications of user B. At this time, the applications that occupy memory in user A will still occupy the memory of the terminal device, resulting in less available memory for user B. When the available memory of user B is insufficient, the terminal device can release memory by swapping out anonymous pages, thereby increasing the available memory of user B, that is, the anonymous pages in the memory can be stored in the swap partition of the hard disk to release the memory occupied by the anonymous pages, but the swapped anonymous pages are generally randomly and scatteredly stored in the swap partition, that is, the anonymous pages of different users may be stored in the same data block, resulting in that when a user needs to swap in anonymous pages later (for example, load anonymous pages into memory), the anonymous pages of other users will be swapped in, that is, additional useless data will be swapped in, reducing the efficiency of data swapping in, resulting in a poor user experience. Summary of the invention

[0003] The embodiments of the present application provide a memory management method, a terminal device, and a computer-readable storage medium, which can solve the problem that when multiple users log in to the terminal device, the swapped-out anonymous pages are randomly and scatteredly stored in the swap partition, resulting in the anonymous pages of other users being swapped in when the anonymous pages are swapped in, causing low swap efficiency and poor user experience.

[0004] In a first aspect, an embodiment of the present application provides a memory management method, which is applied to a terminal device, wherein the terminal device supports multi-user login, and the method may include:

[0005] The terminal device detects a preset trigger event;

[0006] In response to the preset trigger event, the terminal device stores the target anonymous page corresponding to each user in a swap partition allocated to each user, and each user is a user who has logged into the terminal device.

[0007] In the above-mentioned memory management method, when a preset trigger event is detected, the terminal device can store the target anonymous page corresponding to each user to the swap partition allocated to each user, that is, the swap partition can be set according to the user, so that the anonymous page corresponding to each user can be uniformly stored in the swap partition corresponding to the user, so that when a user's application subsequently swaps in an anonymous page, the anonymous page can be swapped in only from the swap partition corresponding to the user, and the anonymous pages of other users will not be swapped in, thereby reducing the swapping of useless data, improving the swapping efficiency, and enhancing the user experience, with strong ease of use and practicality.

[0008] Exemplarily, the preset trigger event is a user login event, a user logout event, or a user switching event.

[0009] In the memory management method provided by this implementation, the terminal device does not need to wait until insufficient memory affects the user's use before releasing memory, but can actively identify events such as user login, logout or switching. Once events such as user login, logout or switching are detected, the swap partition corresponding to each user and the target anonymous page corresponding to each user can be automatically determined, and the target anonymous page corresponding to each user can be swapped out to the swap partition corresponding to each user, so as to release memory, increase the available memory for active users, ensure the performance of active users, and improve user experience.

[0010] Among them, when a user logs in to the terminal device, the terminal device can detect a user login event. When a user logs out of the terminal device, the terminal device can detect a user logout event. When the active user of the terminal device switches from one user to another user, the terminal device can detect a user switching event. It should be understood that the active user refers to the user who is currently using the terminal device.

[0011] Exemplarily, before the terminal device stores the target anonymous page corresponding to each user in the swap partition allocated to each user, the method may further include:

[0012] The terminal device obtains a preset total swap partition size;

[0013] The terminal device determines the size of the swap partition corresponding to each of the users according to the size of the preset total swap partition, and determines the swap partition corresponding to each of the users according to the size of the swap partition corresponding to each of the users.

[0014] In the memory management method provided by the implementation, the terminal device can determine the size of the swap partition corresponding to each user according to the size of the preset total swap partition, ensuring that a reasonable swap partition is allocated to each user. For each user, the swap partition corresponding to the user can be a continuous area in the preset total swap partition, or can be multiple non-continuous areas in the preset total swap partition.

[0015] In a possible implementation manner of the first aspect, the terminal device determines, according to the preset total swap partition size, the size of the swap partition corresponding to each of the users, which may include:

[0016] The terminal device determines the size of the swap partition corresponding to each user according to the preset total swap partition size and the user priority corresponding to each user, wherein the user priority corresponding to each user is determined according to the time when each user logs into the terminal device, or according to the last active time of each user; or

[0017] The terminal device determines the size of the swap partition corresponding to each of the users according to the size of the preset total swap partition and the size of the swap partition required by each of the users. The size of the swap partition required by each of the users is determined according to the size of each anonymous page corresponding to each of the users.

[0018] In the memory management method provided by the implementation, the terminal device can determine the size of the swap partition corresponding to each user according to the preset total swap partition size and the user priority corresponding to each user. The higher the user priority, the larger the swap partition corresponding to the user; the lower the user priority, the smaller the swap partition corresponding to the user, so that a larger swap partition is allocated to a user with a higher user priority, so that as many anonymous pages corresponding to a user with a higher user priority as possible can be saved to the swap partition, so as to keep as many applications corresponding to the user with a higher user priority as possible alive, thereby facilitating the user with a higher user priority to quickly start the application and improve the user experience.

[0019] Optionally, the user priority can be determined based on the user's most recent active time, or based on the time and duration when each user switches to an inactive user. The earlier the user's most recent active time, or the earlier or longer the time when the user switches to an inactive user, the lower the user priority corresponding to the user; the later the user's most recent active time, or the later or shorter the time when the user switches to an inactive user, the higher the user priority corresponding to the user, so that the most recently active user can have a larger swap partition, so as to save as many anonymous pages corresponding to the most recently active user as possible to the swap partition, so as to keep as many applications corresponding to the most recently active user as possible alive, thereby facilitating the most recently active user to quickly start the application and improve the user experience.

[0020] Optionally, the user priority can be determined based on the user's login time. The earlier the user's login time, the lower the user priority corresponding to the user; the later the user's login time, the higher the user priority corresponding to the user, so that the recently logged-in user can have a larger swap partition, so as to save as many anonymous pages corresponding to the recently logged-in user as possible to the swap partition, so as to keep as many applications corresponding to the recently logged-in user as possible alive, thereby facilitating the recently logged-in user to quickly start the application and improve the user experience.

[0021] In some embodiments, the terminal device can determine the size of the swap partition corresponding to each user based on the size of the preset total swap partition and the size of the swap partition required by each user, so as to allocate the swap partition corresponding to each user according to the size of the swap partition required by each user, so that the swap partition corresponding to each user can meet the storage requirements of the anonymous pages corresponding to each user as much as possible, so as to save as many anonymous pages as possible for each user to the corresponding swap partition, and to keep as many applications corresponding to each user as possible active, thereby facilitating the rapid startup of applications by each user and improving user experience.

[0022] For each user, the size of the swap partition required by the user can be determined according to the size of each anonymous page corresponding to the user. For example, the sum of the sizes of all anonymous pages corresponding to the user can be determined as the size of the swap partition required by the user.

[0023] In another possible implementation manner of the first aspect, the terminal device determines, according to the preset total swap partition size, the size of the swap partition corresponding to each of the users, which may include:

[0024] The terminal device determines a first user among the users, where the first user is an active user of the terminal device;

[0025] The terminal device determines the size of the swap partition corresponding to the first user according to the size of the preset total swap partition and the size of each anonymous page corresponding to the first user;

[0026] The terminal device determines the size of the swap partition corresponding to each second user according to the preset total swap partition size, the size of the swap partition corresponding to the first user, and the user priority corresponding to each second user, where the second user is a user other than the first user among the users; or

[0027] The terminal device determines the size of the swap partition corresponding to each second user based on the preset size of the total swap partition, the size of the swap partition corresponding to the first user, and the size of the swap partition required by each second user. The size of the swap partition required by each second user is determined based on the size of each anonymous page corresponding to each second user.

[0028] In the memory management method provided by the implementation, the terminal device can first determine the size of the swap partition corresponding to the active user according to the size of each anonymous page corresponding to the active user. Subsequently, the terminal device can determine the size of the swap partition corresponding to other inactive users according to the size of the remaining swap partition, so as to give priority to determining the swap partition corresponding to the active user, and ensure that the active user has a larger swap partition, so that the anonymous pages corresponding to the active user can be saved to the swap partition as much as possible, so as to keep as many applications corresponding to the active user as possible alive, which can increase the speed of application switching for the active user and improve the user experience.

[0029] Optionally, when the size of the swap partition required by the active user is smaller than the preset size of the total swap partition, the terminal device may determine the size of the swap partition required by the active user as the size of the swap partition corresponding to the active user, so that the swap partition corresponding to the active user can meet the storage requirements of the anonymous pages corresponding to the active user, thereby keeping as many applications corresponding to the active user as possible active, thereby improving the user experience.

[0030] Optionally, when the size of the swap partition required by the active user is greater than or equal to the size of the preset total swap partition, the terminal device may determine M times the size of the preset total swap partition as the size of the swap partition corresponding to the first user, so as to allocate a larger swap partition to the active user as much as possible, thereby improving the user experience of the active user. Wherein, M is less than 1, and the value of M can be specifically determined according to the actual scenario.

[0031] In another possible implementation, the terminal device may determine the size of the currently required total swap partition based on the size of the swap partition required by each user, and may determine the size of the swap partition corresponding to each user based on the currently required total swap partition size and the preset total swap partition size.

[0032] Exemplarily, when the size of the total swap partition currently required is less than or equal to the size of the preset total swap partition, it indicates that the preset total swap partition can meet the swap-out requirements of all anonymous pages corresponding to each user. At this time, the terminal device can determine the size of the swap partition required by each user as the size of the swap partition corresponding to each user. Alternatively, the terminal device can determine the size of the swap partition required by each inactive user as the size of the swap partition corresponding to each inactive user, and determine the size of the remaining swap partition as the size of the swap partition corresponding to the active user, so as to allocate a larger swap partition to the active user, facilitate the anonymous pages in the subsequent use process of the active user to be saved to the swap partition, keep the applications subsequently used by the active user alive, and improve the user experience of the active user.

[0033] Exemplarily, when the size of the currently required total swap partition is larger than the size of the preset total swap partition, the terminal device can determine the ratio between the size of the preset total swap partition and the size of the currently required total swap partition, and determine the size of the swap partition corresponding to each user based on the ratio and the size of the swap partition required by each user.

[0034] In one example, for each of the users, when the size of the swap partition corresponding to the user is smaller than the total size of the anonymous pages corresponding to the user, the target anonymous page is an anonymous page of a first target application, and the first target application is one or more of the applications corresponding to the user.

[0035] In the memory management method provided by the implementation, after determining the size of the swap partition corresponding to each user, for each user, when the size of the swap partition corresponding to the user is smaller than the size of the swap partition required by the user, it indicates that all anonymous pages corresponding to the user cannot be stored in the swap partition corresponding to the user. At this time, the terminal device can only store the anonymous pages of the first target application corresponding to the user (i.e., part of the applications in the corresponding applications) in the swap partition corresponding to the user.

[0036] Optionally, the first target application is determined according to application priorities of applications corresponding to the user.

[0037] In the memory management method provided by this implementation, the terminal device can obtain the application priority of each application corresponding to the user, and can determine the first target application corresponding to the user according to the application priority. Among them, the higher the application priority, the greater the probability of being determined as the first target application; the lower the application priority, the smaller the probability of being determined as the first target application. In other words, when the swap partition corresponding to a user cannot store all the anonymous pages corresponding to the user, the terminal device can determine the first target application that the user is most likely to use again according to the application priority, and can store the anonymous pages of the first target application in the swap partition to keep the first target application corresponding to the user alive, thereby increasing the startup speed when the user uses the first target application again and improving the user experience.

[0038] Optionally, the terminal device may determine the application priority of each application corresponding to each user according to the default setting. For example, a technician may determine the application priority of each application according to the usage of each application in other terminal devices, and may set the application priority of each application in the terminal device. The terminal device may determine the application priority set by the technician as the default setting.

[0039] Optionally, the terminal device may determine the application priority of each application corresponding to each user according to the usage of each application in the terminal device. For example, the terminal device may determine the application priority of each application according to the usage time or usage frequency of each application. Among them, the longer the usage time or the higher the usage frequency of the application, the higher the corresponding application priority; the shorter the usage time or the lower the usage frequency of the application, the lower the corresponding application priority.

[0040] In another example, the method may further include:

[0041] For each of the users, when the size of the swap partition corresponding to the user is smaller than the size of the swap partition corresponding to the user last time, the terminal device determines the second target application corresponding to the user and terminates the second target application. The swap partition corresponding to the user last time is the swap partition allocated to the user by the terminal device in the last preset trigger event.

[0042] In the memory management method provided by the implementation, after determining the size of the swap partition corresponding to each user, for each user, when the size of the swap partition corresponding to the user is smaller than the size of the swap partition corresponding to the user last time, and the size of the swap partition corresponding to the user is smaller than the size of the swap partition required by the user, the terminal device can determine the second target application corresponding to the user, and terminate or close the second target application to release part of the swap partition corresponding to the user. The swap partition corresponding to the user last time can be the swap partition allocated to the user by the terminal device in the previous preset trigger event.

[0043] Optionally, the second target application corresponding to the user is determined according to the application priority of each application corresponding to the user.

[0044] In the memory management method provided by this implementation, the terminal device can obtain the application priority of each application corresponding to the user, and can determine the second target application corresponding to the user according to the application priority. Among them, the lower the application priority, the greater the probability of being determined as the second target application; the higher the application priority, the smaller the probability of being determined as the second target application. That is, when the swap partition corresponding to a certain user becomes smaller, and the size of the swap partition after the reduction is smaller than the size of the swap partition required by the user, the terminal device can determine the second target application with a lower probability of being used again by the user according to the application priority, and terminate the second target application, that is, release the anonymous page of the second target application in the swap partition corresponding to the user, so as to retain the application that the user is most likely to use again as much as possible, thereby improving the user experience.

[0045] In a second aspect, an embodiment of the present application provides a memory management device, which is applied to a terminal device, wherein the terminal device supports multi-user login, and the device may include:

[0046] A trigger event detection module, used to detect a preset trigger event;

[0047] The anonymous page storage module is used to store the target anonymous page corresponding to each user in the exchange partition allocated to each user in response to the preset trigger event, and each user is a user who has logged in to the terminal device.

[0048] Exemplarily, the preset trigger event is a user login event, a user logout event, or a user switching event.

[0049] Exemplarily, the device may further include:

[0050] A total swap partition size acquisition module is used to obtain the size of a preset total swap partition;

[0051] The swap partition size determination module is used to determine the size of the swap partition corresponding to each user according to the size of the preset total swap partition, and determine the swap partition corresponding to each user according to the size of the swap partition corresponding to each user.

[0052] In a possible implementation of the second aspect, the swap partition size determination module is used to determine the size of the swap partition corresponding to each user according to the preset total swap partition size and the user priority corresponding to each user, the user priority corresponding to each user is determined according to the time when each user logs into the terminal device, or according to the last active time of each user; or, according to the preset total swap partition size and the size of the swap partition required by each user, determine the size of the swap partition corresponding to each user, the size of the swap partition required by each user is determined according to the size of each anonymous page corresponding to each user.

[0053] In another possible implementation manner of the second aspect, the exchange partition size determination module is further used to determine a first user among the users, where the first user is an active user of the terminal device.

[0054] The swap partition size determination module is further used to determine the size of the swap partition corresponding to the first user according to the preset total swap partition size and the size of each anonymous page corresponding to the first user; determine the size of the swap partition corresponding to each second user according to the preset total swap partition size, the size of the swap partition corresponding to the first user and the user priority corresponding to each second user, wherein the second user is a user other than the first user among the users;

[0055] Alternatively, the swap partition size determination module is further used to determine the size of the swap partition corresponding to each second user based on the size of the preset total swap partition, the size of the swap partition corresponding to the first user, and the size of the swap partition required by each second user, and the size of the swap partition required by each second user is determined based on the size of each anonymous page corresponding to each second user.

[0056] In one example, for each of the users, when the size of the swap partition corresponding to the user is smaller than the total size of the anonymous pages corresponding to the user, the target anonymous page is an anonymous page of a first target application, and the first target application is one or more of the applications corresponding to the user.

[0057] Optionally, the first target application is determined according to application priorities of applications corresponding to the user.

[0058] In another example, the apparatus may further include:

[0059] The target application termination module is used to determine the second target application corresponding to each of the users and terminate the second target application when the size of the exchange partition corresponding to the user is smaller than the size of the exchange partition corresponding to the user last time. The exchange partition corresponding to the user last time is the exchange partition allocated to the user by the terminal device in the previous preset trigger event.

[0060] Optionally, the second target application corresponding to the user is determined according to the application priority of each application corresponding to the user.

[0061] In a third aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the terminal device implements the memory management method described in any one of the first aspects above.

[0062] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the computer implements the memory management method described in any one of the above-mentioned first aspects.

[0063] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute the memory management method described in any one of the above-mentioned first aspects.

[0064] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] Figure 1 A schematic diagram of an application scenario of anonymous page swapping is provided;

[0066] Figure 2 is a schematic diagram of the structure of a terminal device to which the memory management method provided in an embodiment of the present application is applicable;

[0067] Figure 3 Schematic diagram of software architecture to which the memory management method provided in the embodiment of the present application is applicable;

[0068] Figure 4 This is an example of an application scenario provided by the embodiment of the present application. Figure 1 ;

[0069] Figure 5It is a flowchart of the memory management method provided in the embodiment of the present application;

[0070] Figure 6 This is an example of an application scenario provided by the embodiment of the present application. Figure 2 . DETAILED DESCRIPTION

[0071] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0072] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0073] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0074] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0075] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0076] In addition, the “plurality” mentioned in the embodiments of the present application should be interpreted as two or more.

[0077] The steps involved in the memory management method provided in the embodiments of the present application are only examples. Not all steps are mandatory steps, or not all information or messages are mandatory. They can be increased or decreased as needed during use. The same step or steps or messages with the same function in different embodiments of the present application can be referenced and learned from each other.

[0078] The business scenarios described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. A person of ordinary skill in the art will appreciate that, with the evolution of network architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0079] The terminal device can support multiple users to log in, for example, it can support user A, user B and user C to log in. When multiple users log in to the terminal device, there is generally only one active user (such as user A) in the terminal device at the same time, and the other users are inactive users (such as user B and user C). When the active user of the terminal device switches from user A to user B, all applications of user A will become background applications of user B. At this time, the applications that occupy memory in user A will still occupy the memory of the terminal device, resulting in less available memory for user B.

[0080] For example, when the active user in the terminal device is user A, an application corresponding to user A (such as the Android development environment (Android Studio)) can run in the foreground of the terminal device, and the Android Studio corresponding to user A occupies nearly 900M of memory. When the active user of the terminal device switches from user A to user B, that is, when the application running in the foreground of the terminal device switches from Android Studio corresponding to user A to an application of user B, the Android Studio corresponding to user A becomes the background application of user B. At this time, the Android Studio corresponding to user A is no longer running, but it still occupies nearly 900M of memory, resulting in less available memory for user B.

[0081] When user B's available memory is insufficient, for example, when user B's available memory is less than a specified threshold, or when user B's available memory is less than the memory required by the application to be currently started, the terminal device can swap out anonymous pages to release memory to increase user B's available memory, that is, the anonymous pages in the memory can be stored in the swap partition of the hard disk to release the memory occupied by the anonymous pages. Among them, the data in the hard disk is read and written in units of data blocks, and the swapped anonymous pages are generally randomly and scatteredly stored in the swap partition, that is, the anonymous pages of different users may be stored in the same data block, resulting in that when a subsequent application needs to swap in anonymous pages (i.e., load anonymous pages into memory), anonymous pages of other users will be swapped in, that is, additional useless data will be swapped in, reducing the efficiency of data swapping in, resulting in a poor user experience.

[0082] See also Figure 1 , Figure 1 A schematic diagram of an application scenario of anonymous page swapping is shown. In this application scenario, the users who have logged into the terminal device may include user A, user B and user C.

[0083] like Figure 1 As shown, application A1 and application A2 corresponding to user A occupy the memory of the terminal device, application B1 and application B2 corresponding to user B occupy the memory of the terminal device, and application C1, application C2 and application C3 corresponding to user C occupy the memory of the terminal device.

[0084] Assume that when starting application C4 corresponding to user C, that is, when application C4 corresponding to user C needs to be run in the foreground of the terminal device, if it is determined that the available memory of user C is insufficient, for example, the available memory of user C is less than the memory required by application C4, the terminal device can swap out the anonymous pages of application A1, the anonymous pages of application A2, the anonymous pages of application B1, the anonymous pages of application B2, the anonymous pages of application C1, the anonymous pages of application C2, and the anonymous pages of application C3 to the swap partition of the hard disk. It should be understood that anonymous pages can refer to pages without file background, that is, memory pages that do not have any mapping relationship with disk files, such as heaps, stacks, data segments, etc. Anonymous pages do not exist in the form of files, and therefore cannot be exchanged with disk files, but can be exchanged through the swap partition divided on the hard disk.

[0085] When swapping out anonymous pages, the terminal device may randomly and sporadically store the swapped out anonymous pages in the swap partition of the hard disk. Figure 1 As shown, the terminal device can store the anonymous pages of application A1, application B2 and application C1 in data block 1, and store the anonymous pages of application A2, application B1, application C2 and application C3 in data block 2.

[0086] When application C1 corresponding to user C is switched to the foreground application, the terminal device needs to swap the anonymous page of application C1 in the swap partition into the memory for use. Since the data in the hard disk is read and written in data blocks, the terminal device will swap all the data in data block 1 into the memory, resulting in the anonymous page of application A1 and the anonymous page of application B2 being swapped into the memory. However, the anonymous page of application A1 and the anonymous page of application B2 are obviously useless data for application C1, which greatly reduces the data swap efficiency of application C1 and reduces the user experience.

[0087] To solve the above problems, the embodiments of the present application provide a memory management method, a terminal device and a computer-readable storage medium, and the terminal device can support multi-user login. In the method, when a preset trigger event is detected, the terminal device can store the target anonymous page corresponding to each user to the swap partition allocated to each user. That is, in the embodiments of the present application, the swap partition can be set according to the user, so that the anonymous page corresponding to each user can be uniformly stored in the swap partition corresponding to the user, so that when the application of a certain user is swapped in anonymous pages later, the anonymous page can be swapped in only from the swap partition corresponding to the user, and the anonymous pages of other users will not be swapped in, thereby reducing the swapping in of useless data, improving the swapping efficiency, and enhancing the user experience, and having strong ease of use and practicality.

[0088] In the embodiments of the present application, the terminal device may be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a desktop computer, or the like, which is a terminal device that can support multiple users to log in and use. The embodiments of the present application do not impose any restrictions on the specific type of the terminal device.

[0089] The following first introduces the terminal device involved in the embodiment of the present application. Figure 2 , Figure 2 A schematic structural diagram of a terminal device 100 is shown.

[0090] The terminal device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, an antenna 1, an antenna 2, a mobile communication module 140, a wireless communication module 150, a sensor module 160, and a display screen 170. The sensor module 160 may include a pressure sensor 160A, a gyroscope sensor 160B, a magnetic sensor 160C, an acceleration sensor 160D, and a touch sensor 160E.

[0091] It is understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the terminal device 100. In other embodiments of the present application, the terminal device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0092] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0093] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.

[0094] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory, thereby avoiding repeated access, reducing the waiting time of the processor 110, and thus improving the efficiency of the system.

[0095] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0096] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 160E through the I2C bus interface. For example, the processor 110 may be coupled to the touch sensor 160E through the I2C interface, so that the processor 110 communicates with the touch sensor 160E through the I2C bus interface, thereby realizing the touch function of the terminal device 100.

[0097] The UART interface is a universal serial data bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is generally used to connect the processor 110 and the wireless communication module 150. For example: the processor 110 communicates with the Bluetooth module in the wireless communication module 150 through the UART interface to realize the Bluetooth function. The MIPI interface can be used to connect the processor 110 to peripheral devices such as the display screen 170. The MIPI interface includes a display serial interface (DSI) and the like. In some embodiments, the processor 110 and the display screen 170 communicate through the DSI interface to realize the display function of the terminal device 100.

[0098] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 with the display screen 170, the wireless communication module 150, the sensor module 160, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.

[0099] The USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the terminal device 100, and can also be used to transmit data between the terminal device 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 terminal devices, such as AR devices, etc.

[0100] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the terminal device 100. In other embodiments of the present application, the terminal device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0101] The wireless communication function of the terminal device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 140, the wireless communication module 150, the modem processor and the baseband processor.

[0102] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in terminal device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0103] The mobile communication module 140 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied to the terminal device 100. The mobile communication module 140 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 140 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 140 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 140 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 140 can be set in the same device as at least some of the modules of the processor 110.

[0104] 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-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor displays an image or video through the display screen 170. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 140 or other functional modules.

[0105] The wireless communication module 150 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the terminal device 100. The wireless communication module 150 can be one or more devices integrating at least one communication processing module. The wireless communication module 150 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 150 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0106] In some embodiments, the antenna 1 of the terminal device 100 is coupled to the mobile communication module 140, and the antenna 2 is coupled to the wireless communication module 150, so that the terminal device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include 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, and / or IR technology. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).

[0107] The terminal device 100 implements the display function through a GPU, a display screen 170, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 170 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or change display information.

[0108] The display screen 170 is used to display images, videos, etc. The display screen 170 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 (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the terminal device 100 may include 1 or N display screens 170, where N is a positive integer greater than 1.

[0109] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the terminal device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.

[0110] Video codecs are used to compress or decompress digital videos. The terminal device 100 may support one or more video codecs. Thus, the terminal device 100 may play or record videos in various coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0111] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of the terminal device 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0112] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the terminal device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as saving files such as videos in the external memory card.

[0113] The internal memory 121 can be used to store computer executable program codes, which may include instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as an image playback function, etc.), etc. The data storage area may store data created during the use of the terminal device 100 (such as a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 110 executes various functional applications and data processing of the terminal device 100 by running instructions stored in the internal memory 121 and / or instructions stored in a memory provided in the processor.

[0114] In some embodiments, a preset total swap partition may be provided in the storage data area, wherein the preset total swap partition may be provided with swap partitions corresponding to each user according to the user, so that the target anonymous page corresponding to each user may be stored in the swap partition corresponding to each user.

[0115] The pressure sensor 160A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 160A can be set on the display screen 170. There are many types of pressure sensors 160A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 160A, the capacitance between the electrodes changes. The terminal device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 170, the terminal device 100 detects the touch operation intensity according to the pressure sensor 160A. The terminal device 100 can also calculate the touch position according to the detection signal of the pressure sensor 160A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view 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, an instruction to create a new short message is executed.

[0116] The gyro sensor 160B may be used to determine the motion posture of the terminal device 100. In some embodiments, the angular velocity of the terminal device 100 around three axes (ie, x, y, and z axes) may be determined by the gyro sensor 160B.

[0117] The magnetic sensor 160C includes a Hall sensor, and the terminal device 100 can use the magnetic sensor 160C to detect the opening and closing of the flip leather case.

[0118] The acceleration sensor 160D can detect the magnitude of the acceleration of the terminal device 100 in various directions (generally three axes). When the terminal device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the terminal device and applied to applications such as horizontal and vertical screen switching and pedometers.

[0119] The touch sensor 160E is also called a "touch control device". The touch sensor 160E can be arranged on the display screen 170, and the touch sensor 160E and the display screen 170 form a touch screen, also called a "touch control screen". The touch sensor 160E is used to detect touch operations acting 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 the touch operation can be provided through the display screen 170. In other embodiments, the touch sensor 160E can also be arranged on the surface of the terminal device 100, which is different from the position of the display screen 170.

[0120] The software system of the terminal device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. For example, the software system of the terminal device 100 may adopt an Android operating system (OS), a Harmony OS, or an IOS with a layered architecture. The embodiment of the present application takes the Android system with a layered architecture as an example to exemplify the software structure of the terminal device 100.

[0121] See also Figure 3 , Figure 3 A software structure block diagram of the terminal device 100 provided in an embodiment of the present application is shown.

[0122] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system library, and the kernel layer.

[0123] The application layer may include a series of application packages. When the terminal device 100 supports multiple users to log in and use, the application layer may include applications corresponding to each user, and the applications may be isolated by user so that different users cannot access each other's data. For example, for each user, a space corresponding to the user may be set in the terminal device 100, and the application and related data corresponding to the user may be stored in the space, and the spaces corresponding to different users may be isolated from each other.

[0124] Optionally, the number of users supported by the terminal device 100 may be determined based on actual scenarios, and this embodiment of the present application does not impose any limitation on this. Figure 3 Only three examples are used for illustrative purposes.

[0125] like Figure 3 As shown, when the terminal device 100 supports user A, user B and user C to log in and use, the application layer may include applications corresponding to user A (such as calendar, network disk and The terminal device 100 includes the space corresponding to user A (hereinafter referred to as space A), the space corresponding to user B (hereinafter referred to as space B), and the space corresponding to user C (hereinafter referred to as space C). The applications and related data corresponding to user A can be stored in space A, the applications and related data corresponding to user B can be stored in space B, and the applications and related data corresponding to user C can be stored in space C. Space A, space B, and space C are isolated from each other.

[0126] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.

[0127] like Figure 3 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

[0128] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.

[0129] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0130] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0131] The phone manager is used to provide communication functions of the terminal device 100, such as management of call status (including connection, disconnection, etc.).

[0132] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, the terminal device vibrates, the indicator light flashes, etc.

[0133] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0134] Optionally, the resource manager may include an application management module. The application management module is used to manage the memory resources in the terminal device 100. Exemplarily, when a preset trigger event is detected, the application management module can determine the size of the swap partition corresponding to each user based on the size of the preset total swap partition, so that the user storage management module can determine the swap partition corresponding to each user based on the size of the swap partition corresponding to each user. At the same time, the application management module can also obtain application information corresponding to each user, determine the target anonymous page corresponding to each user based on the application information corresponding to each user, and trigger the swapping out of the target anonymous page to release the memory resources in the terminal device 100.

[0135] Exemplarily, when the swap partition corresponding to a certain user (e.g., user A) becomes smaller, the application management module may also determine the target application corresponding to user A, and may terminate or close the target application corresponding to user A. The swap partition corresponding to user A becoming smaller means that the swap partition corresponding to user A determined based on the current preset trigger event is smaller than the swap partition corresponding to user A determined based on the last preset trigger event.

[0136] For example, when the swap partition corresponding to user A is determined to be 1G based on the current preset trigger event, and the swap partition corresponding to user A is determined to be 1.2G based on the previous preset trigger event, the application management module can determine that the swap partition corresponding to user A becomes smaller. At this time, the application management module can determine the target application corresponding to user A, and trigger to kill the target application corresponding to user A, that is, terminate or close the target application corresponding to user A.

[0137] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.

[0138] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.

[0139] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0140] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0141] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0142] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0143] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0144] A 2D graphics engine is a drawing engine for 2D drawings.

[0145] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, sensor driver, and storage manager.

[0146] The storage manager at least includes a user storage management module and an enhanced swap (eswap) device. The eswap device is used to implement data exchange with the memory, that is, to swap out data in the memory (such as anonymous pages) to the swap partition (i.e., swap partition) of the hard disk, and to swap data in the swap partition into the memory.

[0147] It should be understood that swapping out data and swapping in data can be understood as data migration. That is, swapping out data can be understood as migrating data in the memory to the swap partition of the hard disk. Swapping in data can be understood as migrating data in the swap partition to the memory.

[0148] The user storage management module is used to manage the exchange partition corresponding to each user. In the embodiment of the present application, after the application management module determines the size of the exchange partition corresponding to each user, the user storage management module can set the exchange partition corresponding to each user in the hard disk according to the size of the exchange partition corresponding to each user, so that the target anonymous page corresponding to each user can be stored through the exchange partition corresponding to each user. That is, the user storage management module can divide the exchange partition of the hard disk into multiple exchange partitions according to the user. Therefore, when the application management module triggers the eswap device to swap out the target anonymous page corresponding to each user to the exchange partition of the hard disk, the user storage management module can store the target anonymous page corresponding to each user in the exchange partition corresponding to each user, thereby reducing the useless data when the subsequent data is swapped in, and improving the swap-in efficiency. In addition, when the exchange partition corresponding to a certain user becomes smaller, the user storage management module can also release part of the storage area corresponding to the user in the hard disk.

[0149] For example, after the application management module determines the size of the swap partition corresponding to user A, the size of the swap partition corresponding to user B, and the size of the swap partition corresponding to user C, the user storage management module can set the swap partition A corresponding to user A in the hard disk according to the size of the swap partition corresponding to user A, can set the swap partition B corresponding to user B in the hard disk according to the size of the swap partition corresponding to user B, and can set the swap partition C corresponding to user C in the hard disk according to the size of the swap partition corresponding to user C. Therefore, when the application management module triggers the eswap device to swap out anonymous pages, the user storage management module can store the target anonymous page corresponding to user A in the swap partition A, store the target anonymous page corresponding to user B in the swap partition B, and store the target anonymous page corresponding to user C in the swap partition C.

[0150] In some embodiments, the kernel layer further includes a Zram device, which can be used to compress anonymous pages in the memory. That is, the target anonymous page swapped out to the swap partition can be an uncompressed original anonymous page, or it can be an anonymous page compressed by the Zram device. It should be understood that the compression ratio of the anonymous page compression performed by the Zram device can be specifically determined according to the actual scenario. The following will be exemplified by taking the target anonymous page swapped out to the swap partition as an anonymous page compressed by the Zram device as an example.

[0151] Combine the following Figure 3 The software structure block diagram shown provides an exemplary description of the memory management method provided in the embodiment of the present application.

[0152] See also Figure 4 , Figure 4 The application scenario provided by the embodiment of the present application is shown Figure 1 In this application scenario, the users who have logged into the terminal device may include user A, user B, and user C. Figure 4 As shown, application 1 and application 2 corresponding to user A occupy the memory of the terminal device, application 3 and application 4 corresponding to user B occupy the memory of the terminal device, and application 5 and application 6 corresponding to user C occupy the memory of the terminal device. Among them, the user who has logged into the terminal device refers to the user who has logged in to the terminal device and has not logged out or logged out from the terminal device.

[0153] It should be understood that when each user logs in to use the terminal device, the terminal device can record and save the application information corresponding to each user in real time. In other words, the application management module can save the application information corresponding to user A, the application information corresponding to user B, and the application information corresponding to user C. Among them, the application information corresponding to the user may refer to the relevant information of the application corresponding to the user that occupies the memory of the terminal device. Optionally, the application information may include the identification of each application (such as name or number, etc.), the size of each anonymous page corresponding to each application, and the starting address of each anonymous page corresponding to each application in the memory. Optionally, such as Figure 4 As shown, the size of the anonymous page corresponding to each application may be the size after being compressed by the Zram device.

[0154] It should be noted that if Figure 4 As shown, the data of memory occupied by each application may also include the file page corresponding to the application. The management of the memory occupied by each file page may be performed according to the existing method, and the embodiment of the present application does not impose any limitation on this.

[0155] When a preset trigger event is detected, the terminal device can determine the swap partition corresponding to user A (hereinafter referred to as swap partition A), the swap partition corresponding to user B (hereinafter referred to as swap partition B), and the swap partition corresponding to user C (hereinafter referred to as swap partition C), and determine the target anonymous page corresponding to user A (e.g., the anonymous page of application 1 and the anonymous page of application 2), the target anonymous page corresponding to user B (e.g., the anonymous page of application 3 and the anonymous page of application 4), and the target anonymous page corresponding to user C (e.g., the anonymous page of application 5 and the anonymous page of application 6). For example, the application management module can determine the size of the swap partition corresponding to user A, the size of the swap partition corresponding to user B, and the size of the swap partition corresponding to user C. Subsequently, the user storage management module can determine the swap partition A corresponding to user A according to the size of the swap partition corresponding to user A, determine the swap partition B corresponding to user B according to the size of the swap partition corresponding to user B, and determine the swap partition C corresponding to user C according to the size of the swap partition corresponding to user C.

[0156] After determining the swap partition corresponding to each user, the application management module can determine the target anonymous page corresponding to each user according to the application information corresponding to each user, and can trigger the eswap device to swap out the target anonymous page corresponding to each user to the swap partition of the hard disk. Figure 4 As shown, the user storage management module can store the target anonymous pages corresponding to user A in the swap partition A (for example, saved as files 1 and 2 in the swap partition A), store the target anonymous pages corresponding to user B in the swap partition B (for example, saved as files 3 and 4 in the swap partition B), and store the target anonymous pages corresponding to user C in the swap partition C (for example, saved as files 5 and 6 in the swap partition C).

[0157] The memory management method provided in the embodiment of the present application will be described in detail below with reference to the accompanying drawings and specific application scenarios.

[0158] See also Figure 5 , Figure 5 The schematic flow chart of the memory management method provided by the embodiment of the present application is shown. The method can be applied to the above-mentioned terminal device. Among them, the terminal device can support multi-user login. Figure 5 As shown, the method may include:

[0159] S501, the terminal device detects a preset trigger event;

[0160] S502: In response to a preset trigger event, the terminal device stores the target anonymous page corresponding to each user in a swap partition allocated to each user.

[0161] In an embodiment of the present application, when a preset trigger event is detected, the terminal device can determine the exchange partition corresponding to each user. Subsequently, the terminal device can obtain the target anonymous page corresponding to each user, and can store the target anonymous page corresponding to each user to the exchange partition corresponding to each user. That is, in an embodiment of the present application, the exchange partition can be set according to the user, so that the anonymous page corresponding to each user can be uniformly stored in the exchange partition corresponding to the user, so that when the application corresponding to a certain user needs to be swapped in with an anonymous page, the anonymous page can be swapped in only from the exchange partition corresponding to the user, and the anonymous pages of other users will not be swapped in, thereby reducing the swapping in of useless data, improving the efficiency of data swapping, and improving the user experience.

[0162] See also Figure 6 , Figure 6 The application scenario provided by the embodiment of the present application is shown Figure 2 Among them, this application scenario is still based on Figure 1 The scenario shown is taken as an example for illustrative explanation, that is, the users who have logged into the terminal device may include user A, user B and user C, application A1 and application A2 corresponding to user A occupy the memory of the terminal device, application B1 and application B2 corresponding to user B occupy the memory of the terminal device, and application C1, application C2 and application C3 corresponding to user C occupy the memory of the terminal device.

[0163] When a preset trigger event is detected, the terminal device can determine the exchange partition A corresponding to user A, the exchange partition B corresponding to user B, and the exchange partition C corresponding to user C. At the same time, the terminal device can determine the target anonymous page corresponding to user A (such as the anonymous page of application A1 and the anonymous page of application A2), the target anonymous page corresponding to user B (such as the anonymous page of application B1 and the anonymous page of application B2), and the target anonymous page corresponding to user C (such as the anonymous page of application C1, the anonymous page of application C2, and the anonymous page of application C3).

[0164] Subsequently, the terminal device can store the target anonymous pages corresponding to user A (i.e., the anonymous pages of application A1 and the anonymous pages of application A2) to swap partition A, store the target anonymous pages corresponding to user B (i.e., the anonymous pages of application B1 and the anonymous pages of application B2) to swap partition B, and store the target anonymous pages corresponding to user C (i.e., the anonymous pages of application C1, the anonymous pages of application C2, and the anonymous pages of application C3) to swap partition C.

[0165] For example, Figure 6As shown, swap partition A may include data block 1, swap partition B may include data block 2, and swap partition C may include data block 3. The terminal device may store the anonymous pages of application A1 and application A2 in data block 1, the anonymous pages of application B1 and application B2 in data block 2, and the anonymous pages of application C1, application C2, and application C3 in data block 3, so that when an application corresponding to a certain user (for example, application B2 corresponding to user B) needs to swap in anonymous pages later, the terminal device may only swap in anonymous pages from swap partition B corresponding to user B, for example, only swap in data block 2, and not swap in anonymous pages of other users, which can reduce the swapping in of useless data, improve the swapping in efficiency of data, and enhance the user experience.

[0166] Optionally, the preset trigger event may be a user login event, a user logout event, or a user switching event. It should be understood that when a user logs in to a terminal device, the terminal device may detect a user login event. When a user logs out or logs out of a terminal device, the terminal device may detect a user logout event. When an active user of a terminal device switches from one user to another user, the terminal device may detect a user switching event. The active user refers to a user who is currently using the terminal device.

[0167] That is, in the embodiment of the present application, the terminal device does not need to wait until insufficient memory affects user use before releasing memory, but actively identifies events such as user login, logout or switching. Once events such as user login, logout or switching are detected, the swap partition corresponding to each user and the target anonymous page corresponding to each user can be automatically determined, and the target anonymous page corresponding to each user can be swapped out to the swap partition corresponding to each user, so as to release memory, increase the available memory for active users, ensure the performance of active users, and improve user experience.

[0168] It should be understood that the user can be a system user of the terminal device or a user corresponding to a specified application. Among them, the system user refers to a user who can use all or part of the functions in the terminal device. For example, a system user refers to a user who can use all or part of the applications in the terminal device. For example, one or more users who can log in to the terminal device to use the terminal device can be created in the terminal device. Therefore, after the terminal device is started, the user can enter the user's corresponding account and password to log in to the terminal device to use all or part of the applications in the terminal device. These users who can log in to the terminal device to use all or part of the applications in the terminal device are the system users of the terminal device.

[0169] Optionally, the specified application can be specifically determined according to actual conditions. For example, the technician can determine the specified application as a certain enterprise workbench according to the actual application scenario, and the user who logs in to the enterprise workbench can be the user described in the embodiment of the present application. For example, a specified enterprise workbench can be installed in the terminal device, and after the user logs in to the terminal device, the user can start the enterprise workbench and can log in as a user in the enterprise workbench. Alternatively, after the user logs in to the terminal device, the user can click on the link corresponding to the enterprise workbench in the terminal device, and can log in as a user through the enterprise workbench opened by the link. At this point, the user who logs in to the enterprise workbench can be the user described in the embodiment of the present application, that is, the user in the embodiment of the present application can include a user who logs in to the terminal device (for example, can be called a personal user) and a user who logs in to the enterprise workbench (for example, can be called an enterprise user).

[0170] Exemplarily, the terminal device may determine the exchange partition corresponding to each user according to the preset total exchange partition. It should be understood that the preset total exchange partition may be an exchange partition determined according to actual conditions, and the present application embodiment does not impose any limitation on this.

[0171] Optionally, the terminal device may obtain the size of the preset total swap partition, and determine the size of the swap partition corresponding to each user according to the size of the preset total swap partition, thereby determining the swap partition corresponding to each user according to the size of the swap partition corresponding to each user. For example, the terminal device may set the swap partition corresponding to each user in the preset total swap partition according to the size of the swap partition corresponding to each user. That is, the terminal device may divide the preset total swap partition into a plurality of swap partitions corresponding to each user according to the user. In other words, the swap partition corresponding to each user may be a part of the preset total swap partition, and the sum of the sizes of the swap partitions corresponding to each user may be less than or equal to the size of the preset total swap partition.

[0172] It should be noted that, for each user, the exchange partition corresponding to the user can be a continuous area in the preset total exchange partition, or can be multiple non-continuous areas in the preset total exchange partition. The embodiment of the present application does not impose any restrictions on this and can be determined specifically according to actual conditions.

[0173] The following is a detailed description of the process by which the terminal device determines the size of the swap partition corresponding to each user.

[0174] In a possible implementation manner, the terminal device may determine the size of the switch partition corresponding to each user according to a preset size of the total switch partition and a preset ratio (hereinafter referred to as a first preset ratio).

[0175] It should be noted that the first preset ratio refers to the ratio between the sizes of the exchange partitions corresponding to each user. It should be understood that the relationship between the users in the first preset ratio can be specifically determined according to the actual scenario. For example, the relationship between the users in the first preset ratio can be determined according to the order of the time of logging into the terminal device (hereinafter referred to as the login time) from early to late; or, the relationship between the users in the first preset ratio can be determined according to the order of the login time from late to early. For example, the relationship between the users in the first preset ratio can be determined according to the order of the most recent active time of each user from early to late; or, the relationship between the users in the first preset ratio can be determined according to the order of the most recent active time of each user from late to early.

[0176] The early or late login time may refer to how far or near the login time is from the current moment. The current moment may refer to the moment when the terminal device detects a preset trigger event. The farther the login time is from the current moment, the earlier the login time is, and the closer the login time is to the current moment, the later the login time is. The active time may refer to the time when the user is an active user of the terminal device. The most recent active time may refer to the most recent active time from the current moment.

[0177] For example, when the users who have logged into the terminal device include user A, user B, and user C, and the login time of user A is 10:30 on April 8, 2023, the login time of user B is 15:00 on April 8, 2023, and the login time of user C is 19:40 on April 8, 2023, it is assumed that the terminal device detects the time of the preset trigger event as 20:30 on April 8, 2023, and the terminal device can determine that the login time of user A is earlier than the login time of user B, and the login time of user B is earlier than the login time of user C. Therefore, the terminal device can determine that the first preset ratio is the size of the exchange partition A corresponding to user A: the size of the exchange partition B corresponding to user B: the size of the exchange partition C corresponding to user C. Alternatively, the terminal device can determine that the first preset ratio is the size of the exchange partition C corresponding to user C: the size of the exchange partition B corresponding to user B: the size of the exchange partition A corresponding to user A.

[0178] For example, when the users who have logged into the terminal device include user A, user B, and user C, it is assumed that the last active time of user A is 15:30 on April 8, 2023, the last active time of user B is 12:00 on April 8, 2023, and user C is an active user of the terminal device, which means that the last active time of user B is earlier than the last active time of user A, and the last active time of user A is earlier than the last active time of user C. Therefore, the terminal device can determine the first preset ratio as the size of the exchange partition B corresponding to user B: the size of the exchange partition A corresponding to user A: the size of the exchange partition C corresponding to user C. Alternatively, the terminal device can determine the first preset ratio as the size of the exchange partition C corresponding to user C: the size of the exchange partition A corresponding to user A: the size of the exchange partition B corresponding to user B.

[0179] The following will take the example of determining the relationship between the users in the first preset ratio according to the order of the most recent active time of each user from late to early as an example to exemplify the process of determining the first preset ratio.

[0180] In one example, the first preset ratio may be determined by the terminal device according to the size of the swap partition required by each user. For each user, the size of the swap partition required by the user may be determined according to the size of each anonymous page corresponding to the user. For example, the sum of the sizes of all anonymous pages corresponding to the user may be determined as the size of the swap partition required by the user.

[0181] It should be understood that when each user logs in to use the terminal device, the terminal device can record and save the application information corresponding to each user in real time. Among them, the application information corresponding to the user can refer to the relevant information of the application that occupies the terminal device memory among the applications corresponding to the user. Optionally, the application information may include the identification of the application (such as the name or number, etc.), the size of each anonymous page corresponding to the application, and the starting address of each anonymous page corresponding to the application in the memory. Therefore, when the anonymous page is swapped out based on the preset trigger event, for each user, the terminal device can determine the anonymous pages corresponding to the user and the size of each anonymous page according to the application information corresponding to the user. That is to say, for each anonymous page, the terminal device can determine the application corresponding to the anonymous page and the user corresponding to the anonymous page according to the starting address corresponding to the anonymous page and the application information corresponding to each user.

[0182] Optionally, the size of the anonymous page corresponding to each user may be the original size of the anonymous page, or may be the size compressed based on a compression ratio. It should be understood that the compression ratio may be specifically determined according to the actual scenario, and the present application embodiment does not impose any limitation on this.

[0183] It should be noted that each user may include an active user of the terminal device, wherein the anonymous page corresponding to the active user may not include the anonymous page corresponding to the foreground application, that is, the terminal device may not swap out the anonymous page of the foreground application to ensure the smooth operation of the foreground application.

[0184] For example, when the foreground application of the terminal device is application A1 corresponding to user A, assuming that the background applications corresponding to user A include application A2, application A3, and application A4, the terminal device determines that the anonymous pages corresponding to user A may include the anonymous page of application A2, the anonymous page of application A3, and the anonymous page of application A4. Therefore, for user A, when swapping out anonymous pages, the terminal device can swap out anonymous pages according to the anonymous page of application A2, the anonymous page of application A3, and the anonymous page of application A4.

[0185] Exemplarily, the terminal device may directly determine the ratio between the sizes of the swap partitions required by each user as the first preset ratio.

[0186] For example, when the users who have logged into the terminal device include user A, user B and user C, user A is an active user of the terminal device, the last active time of user B is earlier than the last active time of user C, and the size of the swap partition required by user A is 3G, the size of the swap partition required by user B is 2G, and the size of the swap partition required by user C is 1G, the terminal device can determine that the first preset ratio is the size of the swap partition A corresponding to user A: the size of the swap partition C corresponding to user C: the size of the swap partition B corresponding to user B, and the first preset ratio can be determined to be 3:1:2.

[0187] Assume that the preset total swap partition size is 3G. At this time, the terminal device can determine that the size of the swap partition A corresponding to user A is 3G*3 / (3+2+1)=1.5G, the size of the swap partition B corresponding to user B is 3G*2 / (3+2+1)=1G, and the size of the swap partition C corresponding to user C is 3G*1 / (3+2+1)=0.5G according to the first preset ratio.

[0188] In another example, the first preset ratio can be determined by the terminal device according to the user priority corresponding to each user. The higher the user priority, the larger the exchange partition corresponding to the user; the lower the user priority, the smaller the exchange partition corresponding to the user. Exemplarily, the terminal device can determine the numerical value corresponding to each user priority, and determine the first preset ratio according to the numerical value corresponding to each user priority. For example, the terminal device can determine the ratio between the numerical values ​​corresponding to each user priority as the first preset ratio.

[0189] It should be noted that the numerical value corresponding to the user priority can be specifically determined according to the actual scenario, and the embodiments of the present application do not impose any restrictions on this. It should be understood that the higher the user priority, the larger the numerical value corresponding to the user priority; the lower the user priority, the smaller the numerical value corresponding to the user priority. Exemplarily, the terminal device can determine the numerical value corresponding to the user priority according to the duration of the user switching to an inactive user. For example, a correspondence between the numerical value corresponding to the user priority and the duration interval can be set in the terminal device. Therefore, when it is necessary to determine the user priority corresponding to each user, the terminal device can also obtain the duration of each user switching to an inactive user, and determine the duration interval of the user priority corresponding to each user according to the duration of each user switching to an inactive user, so that the numerical value corresponding to each user priority can be determined according to the duration interval of each user priority and the corresponding relationship.

[0190] For example, when the users who have logged into the terminal device include user A, user B and user C, and user A is an active user of the terminal device, and the last active time of user B is earlier than the last active time of user C, if the user priority A corresponding to user A is greater than the user priority B corresponding to user B, the user priority B corresponding to user B is greater than the user priority C corresponding to user C, and the value corresponding to user priority A is 3, the value corresponding to user priority B is 2, and the value corresponding to user priority C is 1, at this time, the terminal device can determine that the first preset ratio is the size of the exchange partition A corresponding to user A: the size of the exchange partition C corresponding to user C: the size of the exchange partition B corresponding to user B, and the first preset ratio can be determined as 3:1:2.

[0191] Optionally, the user priority can be determined based on the user's most recent active time, or based on the time and duration when each user switches to an inactive user. The earlier the user's most recent active time, or the earlier or longer the time when the user switches to an inactive user, the lower the user priority corresponding to the user; the later the user's most recent active time, or the later or shorter the time when the user switches to an inactive user, the higher the user priority corresponding to the user, so that the most recently active user can have a larger swap partition, so as to save as many anonymous pages corresponding to the most recently active user as possible to the swap partition, so as to keep as many applications corresponding to the most recently active user as possible alive, thereby facilitating the most recently active user to quickly start the application and improve the user experience.

[0192] For example, when the users who have logged into the terminal device include user A, user B, and user C, it is assumed that the current time (i.e., the time when the terminal device detects the preset trigger event) is 19:00 on April 8, 2023, user C is the current active user of the terminal device, the time when user A switches to an inactive user is 21:00 on April 7, 2023, and the time when user B switches to an inactive user is 10:00 on April 8, 2023. That is, the last active time of user A is 21:00 on April 7, 2023, the last active time of user B is 10:00 on April 8, 2023, and the last active time of user C is 19:00 on April 8, 2023, indicating that the last active time of user A is earlier than the last active time of user B, and the last active time of user B is earlier than the last active time of user C. Therefore, the terminal device can determine that the user priority A corresponding to user A is lower than the user priority B corresponding to user B, and the user priority B corresponding to user B is lower than the user priority C corresponding to user C.

[0193] Optionally, the user priority can be determined based on the user's login time. The earlier the user's login time, the lower the user priority corresponding to the user; the later the user's login time, the higher the user priority corresponding to the user, so that the recently logged-in user can have a larger swap partition, so as to save as many anonymous pages corresponding to the recently logged-in user as possible to the swap partition, so as to keep as many applications corresponding to the recently logged-in user as possible alive, thereby facilitating the recently logged-in user to quickly start the application and improve the user experience.

[0194] For example, when the users who have logged into the terminal device include user A, user B, and user C, and the login time of user A is 10:30 on April 8, 2023, the login time of user B is 15:00 on April 8, 2023, and the login time of user C is 19:40 on April 8, 2023, the terminal device can determine that the login time of user A is earlier than the login time of user B, and the login time of user B is earlier than the login time of user C. Therefore, the terminal device can determine that the user priority corresponding to user A is lower than the user priority corresponding to user B, and the user priority corresponding to user B is lower than the user priority corresponding to user C.

[0195] In another example, the first preset ratio can be set by default by the terminal device. Exemplarily, since active users of the terminal device generally need to frequently switch applications, in order to ensure the speed of application switching for active users and improve user experience, a larger swap partition can be set for active users to save as many anonymous pages corresponding to active users as possible to the swap partition to keep as many applications corresponding to active users alive as possible, so that when active users need to switch applications, the terminal device can quickly start the switched application by swapping the anonymous pages in the swap partition into the memory. Therefore, the proportion corresponding to active users in the first preset ratio can be relatively large. For example, the first preset ratio can be set by default in the terminal device as N:1:1, ..., N is greater than 1, and the specific value of N can be determined according to the actual scenario. That is to say, the size of the first swap partition corresponding to each inactive user is the same, and the size of the swap partition corresponding to the active user can be N times the size of the swap partition corresponding to the inactive user, to ensure that the active user has a larger swap partition.

[0196] For example, when the users who have logged into the terminal device include user A, user B, and user C, and user A is an active user of the terminal device, and the last active time of user B is earlier than the last active time of user C, the terminal device can determine that the first preset ratio is the size of the swap partition A corresponding to user A: the size of the swap partition C corresponding to user C: the size of the swap partition B corresponding to user B, and determine the first preset ratio to be N:1:1. Assuming that N=2, the preset total swap partition size is 3G, the terminal device can determine that the size of the swap partition A corresponding to user A is 3G*2 / (2+1+1)=1.5G, the size of the swap partition B corresponding to user B is 3G*1 / (2+1+1)=0.75G, and the size of the swap partition C corresponding to user C is 3G*1 / (2+1+1)=0.75G according to the first preset ratio.

[0197] It should be noted that the first preset ratio is set to N:1:1, ... by default, which is only an exemplary explanation and should not be understood as a limitation on the embodiments of the present application. In the embodiments of the present application, the first preset ratio may also be set to other ratios by default, for example, the first preset ratio may be set to N1:N2:N3, ..., etc., where N1 is greater than N2, and N2 is greater than N3.

[0198] In another possible implementation, the terminal device may determine the size of the exchange partition corresponding to the first user based on the preset size of the total exchange partition and the size of the exchange partition required by the first user, and determine the size of the exchange partition corresponding to the second user based on the preset size of the total exchange partition, the size of the exchange partition corresponding to the first user and a preset ratio (hereinafter referred to as the second preset ratio).

[0199] It is understandable that the first user may be an active user of the terminal device, and the second user may be an inactive user of the terminal device. That is, the first user may be a user who is currently using the terminal device, and the second user may be a user other than the first user among the users who have logged into the terminal device. For example, when the users who have logged into the terminal device include user A, user B, and user C, if user A is the active user of the terminal device, then the first user is user A, and the second user may include user B and user C.

[0200] Optionally, when the size of the swap partition required by the first user is smaller than the preset size of the total swap partition, the terminal device may determine the size of the swap partition required by the first user as the size of the swap partition corresponding to the first user, so as to set a larger swap partition for active users, thereby saving as many anonymous pages corresponding to the active users as possible to the swap partition, thereby keeping as many applications corresponding to the active users as possible active, increasing the speed at which active users switch applications, and improving user experience.

[0201] Optionally, when the size of the swap partition required by the first user is greater than or equal to the size of the preset total swap partition, the terminal device may determine M times the size of the preset total swap partition as the size of the swap partition corresponding to the first user, where M is less than 1, and the value of M may be specifically determined according to an actual scenario.

[0202] In an embodiment of the present application, after determining the size of the swap partition corresponding to the first user, the terminal device can determine the size of the swap partition corresponding to the second user according to the size of the remaining swap partition and the second preset ratio. The size of the remaining swap partition refers to the size of the swap partition remaining after deducting the size of the swap partition corresponding to the first user from the size of the preset total swap partition. For example, when the size of the preset total swap partition is 8G, if the terminal device determines that the size of the swap partition corresponding to the first user is 5G, the terminal device can determine that the size of the remaining swap partition is 3G.

[0203] It should be understood that, similar to the first preset ratio, the relationship between the second users in the second preset ratio can be determined according to the actual scenario. For example, the relationship between the second users in the second preset ratio can be determined according to the order of login time from early to late; or, the relationship between the second users in the second preset ratio can be determined according to the order of login time from late to early. For example, the relationship between the second users in the second preset ratio can be determined according to the order of the most recent active time of the second users from early to late; or, the relationship between the second users in the second preset ratio can be determined according to the order of the most recent active time of the second users from late to early.

[0204] The following will be exemplified by taking the example of determining the relationship between the second users in the second preset ratio according to the order of the most recent active time of the second users from late to early.

[0205] Optionally, the second preset ratio may be determined by the terminal device according to the size of the swap partition required by each second user. Exemplarily, the terminal device may directly determine the ratio between the sizes of the swap partitions required by each second user as the second preset ratio.

[0206] For example, when the users who have logged into the terminal device include user A, user B, and user C, and user A is an active user of the terminal device, and the last active time of user B is earlier than the last active time of user C, assuming that the size of the swap partition required by user A is 5G, the size of the swap partition required by user B is 4G, and the size of the swap partition required by user C is 2G, the terminal device can determine that the second preset ratio is the size of the swap partition C corresponding to user C: the size of the swap partition B corresponding to user B, and the second preset ratio can be determined to be 2:4. Therefore, the terminal device can determine that the size of the swap partition A corresponding to user A is 5G, the size of the swap partition B corresponding to user B is (8-5)*4 / (2+4)=2G, and the size of the swap partition C corresponding to user C is (8-5)*2 / (2+4)=1G.

[0207] Optionally, the second preset ratio can be determined by the terminal device according to the user priority corresponding to each second user. The higher the user priority corresponding to the second user, the larger the exchange partition corresponding to the second user; the lower the user priority corresponding to the second user, the smaller the exchange partition corresponding to the second user. Exemplarily, the terminal device can determine the second preset ratio according to the numerical value corresponding to each user priority. For example, the terminal device can determine the ratio between the numerical values ​​corresponding to each user priority as the second preset ratio. It should be understood that the numerical values ​​corresponding to each user priority can refer to the above description and will not be repeated here.

[0208] Optionally, the second preset ratio may be set by default by the terminal device. For example, the terminal device may set the second preset ratio by default according to a rule that the sizes of the exchange partitions corresponding to the second users are the same, etc. For example, when the second users include user B and user C, the terminal device may set the second preset ratio by default to 1:1.

[0209] In another possible implementation, the terminal device may determine the size of the currently required total swap partition based on the size of the swap partition required by each user, and may determine the size of the swap partition corresponding to each user based on the currently required total swap partition size and the preset total swap partition size.

[0210] Exemplarily, when the size of the total swap partition currently required is less than or equal to the size of the preset total swap partition, it indicates that the preset total swap partition can meet the swap-out requirements of all anonymous pages corresponding to each user. At this time, the terminal device can determine the size of the swap partition required by each user as the size of the swap partition corresponding to each user. Alternatively, the terminal device can determine the size of the swap partition required by each second user as the size of the swap partition corresponding to each second user, and determine the size of the remaining swap partition as the size of the swap partition corresponding to the first user, so as to determine a larger swap partition for the first user, facilitate the storage of anonymous pages in the subsequent use of the first user, and improve the user experience of the first user.

[0211] Exemplarily, when the size of the currently required total swap partition is larger than the size of the preset total swap partition, the terminal device can determine the ratio between the size of the preset total swap partition and the size of the currently required total swap partition, and determine the size of the swap partition corresponding to each user based on the ratio and the size of the swap partition required by each user.

[0212] For example, when the users who have logged into the terminal device include user A, user B, and user C, and the size of the swap partition required by user A is 4G, the size of the swap partition required by user B is 3G, and the size of the swap partition required by user C is 1G, the terminal device can determine that the size of the total swap partition currently required is 8G. Assuming that the size of the preset total swap partition is 6G, the terminal device can determine that the ratio between the size of the preset total swap partition and the size of the total swap partition currently required is 6 / 8. At this time, the terminal device can determine that the size of the swap partition A corresponding to user A is 4G*6 / 8=3G based on the ratio and the size of the swap partition required by user A, and the size of the swap partition B corresponding to user B is 3G*6 / 8=2.25G based on the ratio and the size of the swap partition required by user B, and the size of the swap partition C corresponding to user C is 1G*6 / 8=0.75G based on the ratio and the size of the swap partition required by user C.

[0213] Exemplarily, when the size of the total swap partition currently required is larger than the preset size of the total swap partition, the terminal device may determine the size of the swap partition corresponding to each user based on the preset size of the total swap partition and a preset ratio (hereinafter referred to as the third preset ratio).

[0214] The third preset ratio may be the same as the first preset ratio described above. The process in which the terminal device can determine the size of the swap partition corresponding to each user according to the preset total swap partition size and the third preset ratio can refer to the specific content of the terminal device determining the size of the swap partition corresponding to each user according to the preset total swap partition size and the first preset ratio, which will not be repeated here.

[0215] In one example, after determining the size of the swap partition corresponding to each user, for each user, when the size of the swap partition corresponding to the user is smaller than the size of the swap partition required by the user, it indicates that all anonymous pages corresponding to the user cannot be stored in the swap partition corresponding to the user. At this time, the terminal device can determine the target application corresponding to the user (hereinafter referred to as the first target application) to store the anonymous pages corresponding to the first target application in the swap partition corresponding to the user.

[0216] Optionally, the terminal device may obtain the application priority of each application corresponding to the user, and may determine the first target application corresponding to the user according to the application priority.

[0217] It is understandable that the higher the application priority, the greater the probability of being determined as the first target application; the lower the application priority, the smaller the probability of being determined as the first target application. In other words, when the swap partition corresponding to a user cannot store all the anonymous pages corresponding to the user, the terminal device can determine the first target application that the user is most likely to use again based on the application priority, and can store the anonymous pages of the first target application in the swap partition to keep the first target application corresponding to the user alive, thereby increasing the startup speed when the user uses the first target application again and improving the user experience.

[0218] Optionally, the terminal device may determine the application priority of each application corresponding to each user according to the default setting. For example, a technician may determine the application priority of each application according to the usage of each application in other terminal devices, and may set the application priority of each application in the terminal device. The terminal device may determine the application priority set by the technician as the default setting.

[0219] It should be noted that the default setting may be a global default setting applicable to all users in the terminal device, that is, the application priority of the application corresponding to each user may be determined according to the default setting.

[0220] For example, the terminal device is set by default with application priority S1 for application 1, application priority S2 for application 2, application priority S3 for application 3, application priority S4 for application 4, and application priority S5 for application 5. When the users who have logged into the terminal device include user A, user B, and user C, and the applications corresponding to user A include application 1 and application 3, the applications corresponding to user B include application 3 and application 4, and the applications corresponding to user C include application 1 and application 4, the terminal device can determine, based on the default application priorities, that the application priority of application 1 corresponding to user A is S1 and the application priority of application 3 corresponding to user A is S3, the application priority of application 3 corresponding to user B is S3 and the application priority of application 4 corresponding to user B is S4, and the application priority of application 1 corresponding to user C is S1 and the application priority of application 4 corresponding to user C is S4.

[0221] Optionally, the terminal device may determine the application priority of each application corresponding to each user according to the usage of each application in the terminal device. For example, the terminal device may determine the application priority of each application according to the usage time or usage frequency of each application. Among them, the longer the usage time or the higher the usage frequency of the application, the higher the corresponding application priority; the shorter the usage time or the lower the usage frequency of the application, the lower the corresponding application priority.

[0222] It should be noted that the above-mentioned determination of the first target application according to the application priority is only an exemplary explanation and should not be understood as a limitation on the embodiments of the present application. In the embodiments of the present application, the terminal device can also determine the first target application corresponding to each user according to the current usage time of each application or the time when it is switched to a background application.

[0223] For example, the longer the current usage time of an application, the greater the probability of being determined as the first target application; the shorter the current usage time of an application, the smaller the probability of being determined as the first target application. For example, the later the application is switched to the background application, the greater the probability of being determined as the first target application; the earlier the application is switched to the background application, the smaller the probability of being determined as the first target application.

[0224] The current usage duration may refer to the duration that the application runs in the foreground before the preset trigger event is detected this time.

[0225] It should be understood that after determining the size of the swap partition corresponding to each user, for each user, when the size of the swap partition corresponding to the user is greater than or equal to the size of the swap partition required by the user, the terminal device can directly store all anonymous pages corresponding to the user in the swap partition corresponding to the user.

[0226] In another example, after determining the size of the swap partition corresponding to each user, for each user, when the size of the swap partition corresponding to the user is smaller than the size of the swap partition corresponding to the user last time, and the size of the swap partition corresponding to the user is smaller than the size of the swap partition required by the user, the terminal device can determine the second target application corresponding to the user, and kill the second target application, that is, terminate or close the second target application. The swap partition corresponding to the user last time can be the swap partition allocated to the user by the terminal device in the previous preset trigger event.

[0227] It should be understood that when there is a user login, user logout or user switching in the terminal device, the terminal device will re-determine the exchange partition corresponding to each user according to the above-mentioned method.

[0228] Optionally, the terminal device may determine the second target application corresponding to each user according to the application priority of each application corresponding to each user. The lower the application priority, the greater the probability of being determined as the second target application; the higher the application priority, the smaller the probability of being determined as the second target application. That is, when the swap partition corresponding to a certain user becomes smaller, and the size of the swap partition after the reduction is smaller than the size of the swap partition required by the user, the terminal device may determine the second target application with a lower probability of being used again by the user according to the application priority, and may terminate or close the second target application to retain the application that the user is most likely to use again as much as possible.

[0229] Similarly, the above-described determination of the second target application according to the application priority is only an exemplary explanation and should not be understood as a limitation on the embodiments of the present application. In the embodiments of the present application, the terminal device can also determine the second target application corresponding to each user according to the current usage time of each application or the time when it is switched to a background application.

[0230] For example, the longer the current usage time of an application, the lower the probability of being determined as the second target application; the shorter the current usage time of an application, the higher the probability of being determined as the second target application. For example, the later the application is switched to the background application, the lower the probability of being determined as the second target application; the earlier the application is switched to the background application, the higher the probability of being determined as the second target application.

[0231] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0232] Corresponding to the memory management method described in the above embodiment, the embodiment of the present application also provides a memory management device, and each module of the device can correspond to each step of the memory management method.

[0233] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0234] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0235] The embodiment of the present application also provides a terminal device, the terminal device includes at least one memory, at least one processor, and a computer program stored in the at least one memory and executable on the at least one processor, and when the processor executes the computer program, the terminal device implements the steps in any of the above-mentioned memory management method embodiments. Exemplarily, the structure of the terminal device can be as follows: Figure 2 shown.

[0236] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program. When the computer program is executed by a computer, the computer implements the steps in any of the above-mentioned memory management method embodiments.

[0237] An embodiment of the present application provides a computer program product. When the computer program product is executed on a terminal device, the terminal device implements the steps in any of the above-mentioned memory management method embodiments.

[0238] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may at least include: any entity or device that can carry the computer program code to the device / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, a computer-readable storage medium cannot be an electric carrier signal and a telecommunication signal.

[0239] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0240] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0241] In the embodiments provided in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0242] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0243] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A memory management method, applied to a terminal device, characterized in that: The terminal device supports multi-user login, and the method includes: The terminal device detects a preset trigger event; In response to the preset trigger event, the terminal device stores the target anonymous page corresponding to each user in a swap partition allocated to each user, and each user is a user who has logged into the terminal device.

2. The method according to claim 1, characterized in that: The preset trigger event is a user login event, a user logout event or a user switching event.

3. The method according to claim 1 or 2, characterized in that: Before the terminal device stores the target anonymous page corresponding to each user in the swap partition allocated to each user, the method further includes: The terminal device obtains a preset total swap partition size; The terminal device determines the size of the swap partition corresponding to each of the users according to the size of the preset total swap partition, and determines the swap partition corresponding to each of the users according to the size of the swap partition corresponding to each of the users.

4. The method according to claim 3, characterized in that The terminal device determines the size of the swap partition corresponding to each of the users according to the preset total swap partition size, including: The terminal device determines the size of the swap partition corresponding to each user according to the preset total swap partition size and the user priority corresponding to each user, wherein the user priority corresponding to each user is determined according to the time when each user logs into the terminal device, or according to the last active time of each user; or The terminal device determines the size of the swap partition corresponding to each of the users according to the size of the preset total swap partition and the size of the swap partition required by each of the users. The size of the swap partition required by each of the users is determined according to the size of each anonymous page corresponding to each of the users.

5. The method according to claim 3, characterized in that: The terminal device determines the size of the swap partition corresponding to each of the users according to the preset total swap partition size, including: The terminal device determines a first user among the users, where the first user is an active user of the terminal device; The terminal device determines the size of the swap partition corresponding to the first user according to the size of the preset total swap partition and the size of each anonymous page corresponding to the first user; The terminal device determines the size of the swap partition corresponding to each second user according to the preset total swap partition size, the size of the swap partition corresponding to the first user, and the user priority corresponding to each second user, where the second user is a user other than the first user among the users; or The terminal device determines the size of the swap partition corresponding to each second user based on the preset size of the total swap partition, the size of the swap partition corresponding to the first user, and the size of the swap partition required by each second user. The size of the swap partition required by each second user is determined based on the size of each anonymous page corresponding to each second user.

6. The method according to any one of claims 1 to 5, characterized in that For each of the users, when the size of the swap partition corresponding to the user is smaller than the total size of the anonymous pages corresponding to the user, the target anonymous page is an anonymous page of a first target application, and the first target application is one or more of the applications corresponding to the user.

7. The method according to claim 6, characterized in that The first target application is determined according to the application priority of each application corresponding to the user.

8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: For each of the users, when the size of the swap partition corresponding to the user is smaller than the size of the swap partition corresponding to the user last time, the terminal device determines the second target application corresponding to the user and terminates the second target application. The swap partition corresponding to the user last time is the swap partition allocated to the user by the terminal device in the last preset trigger event.

9. The method according to claim 8, characterized in that The second target application corresponding to the user is determined according to the application priority of each application corresponding to the user.

10. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the terminal device implements the memory management method according to any one of claims 1 to 9.

11. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a computer, the computer is enabled to implement the memory management method according to any one of claims 1 to 9.