Memory management method, terminal device and computer-readable storage medium

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

WO2024230268A1PCT designated stage expired Publication Date: 2024-11-14HUAWEI TECH CO LTD

Patent Information

Application Number
PCT/CN2024/077911
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-05-06
Filing Date
2024-02-21
Publication Date
2024-11-14

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 the anonymous pages of other users being swapped in when the anonymous pages are swapped in, which reduces the efficiency of data swapping and causes poor user experience.

Method used

When the terminal device detects a preset trigger event (such as user login, logout or switch), it stores the target anonymous pages of each user to the exchange partition assigned to the user, ensuring that the anonymous pages are stored in the exchange partition corresponding to the user. avoid swapping useless data.

Benefits of technology

Improves the efficiency of swapping anonymous pages, improves the user experience, and ensures the performance and memory availability of active users.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024077911_14112024_PF_FP_ABST
    Figure CN2024077911_14112024_PF_FP_ABST
Patent Text Reader

Abstract

The present application is adapted to the technical field of terminals, and particularly relates to a memory management method, a terminal device and a computer-readable storage medium. In the method, when detecting a preset trigger event, a terminal device can separately store a target anonymous page corresponding to each user into an exchange partition allocated to the user. That is, in the present application, exchange partitions can be set according to users, such that the anonymous page corresponding to each user can be uniformly stored in an exchange partition corresponding to the user, and therefore when an application of a certain user subsequently performs anonymous page swap-in, swap-in can be only performed on the anonymous page in the exchange partition corresponding to the user, and anonymous pages of other users cannot be swapped in, thereby reducing swap-in of useless data, improving swap-in efficiency, improving user experience, and achieving high usability and practicability.
Need to check novelty before this filing date? Find Prior Art

Description

Memory management method, terminal device, and computer-readable storage medium

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on May 6, 2023, with application number 202310506106.8 and application name “Memory Management Method, Terminal Device and Computer-Readable Storage Medium”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] 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

[0003] Currently, terminal devices can support multiple user logins, for example, user A, user B, and user C. When multiple users are logged into a terminal device, there is typically only one active user (e.g., user A) at a time, while the other users are inactive (e.g., user B and user C). When the active user switches from user A to user B, all of user A's applications become user B's background applications. At this point, the memory-consuming applications of user A continue to occupy the terminal device's memory, resulting in less available memory for user B. When user B's available memory is insufficient, the terminal device can free up memory by swapping out anonymous pages, thereby increasing user B's available memory. Specifically, anonymous pages in memory can be stored in the hard drive's swap partition to free up the memory occupied by anonymous pages. However, swapped-out anonymous pages are typically stored randomly and fragmented in the swap partition, meaning that anonymous pages from different users may be stored in the same data block. Consequently, when a user subsequently needs to swap in an anonymous page (e.g., load an anonymous page into memory), the anonymous page of another user will be swapped in. This results in the addition of unnecessary data, reducing data swapping efficiency and resulting in a poor user experience.

[0004] Summary of the Invention

[0005] 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, resulting in low swap-in efficiency and poor user experience.

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

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

[0008] 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, where each user is a user who has logged into the terminal device.

[0009] 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 in 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 only be swapped in 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.

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

[0011] 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. Instead, it 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 to release memory, increase the available memory for active users, ensure the performance of active users, and improve user experience.

[0012] When a user logs in to a 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, the terminal device can detect a user switch event. It should be understood that an active user refers to the user currently using the terminal device.

[0013] 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:

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

[0015] 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.

[0016] In the memory management method provided by this implementation, the terminal device can determine the size of the swap partition corresponding to each user based on the preset total swap partition size, 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 multiple non-contiguous areas in the preset total swap partition.

[0017] In a possible implementation of the first aspect, the terminal device determining, based on the preset total swap partition size, the size of the swap partition corresponding to each user may include:

[0018] 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

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

[0020] In the memory management method provided by this implementation, the terminal device can determine the size of the swap partition corresponding to each user based on 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. Larger swap partitions are allocated to users with higher user priorities, allowing as many anonymous pages corresponding to users with higher user priorities as possible to be saved in the swap partition, thereby keeping as many applications corresponding to users with higher user priorities as possible alive, thereby facilitating the rapid startup of applications by users with higher user priorities and improving user experience.

[0021] Optionally, 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 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 the user switches to an inactive user, the higher the user priority corresponding to the user, so that recently active users can have a larger swap partition, so as to save as many anonymous pages corresponding to recently active users as possible to the swap partition, and to keep as many applications corresponding to recently active users as possible alive, thereby facilitating the recently active users to quickly start applications and improving user experience.

[0022] Optionally, 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. This allows recently logged-in users to have a larger swap partition, saving as many anonymous pages corresponding to recently logged-in users as possible to the swap partition, thereby keeping as many applications corresponding to recently logged-in users as possible active, thereby facilitating the recently logged-in users to quickly start applications and improving user experience.

[0023] 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, and 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 to the corresponding swap partition for each user, and keep as many applications corresponding to each user as possible alive, thereby facilitating the rapid startup of applications by each user recently and improving user experience.

[0024] For each user, the size of the swap partition required by the user can be determined based on the sizes of the anonymous pages 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.

[0025] In another possible implementation of the first aspect, the terminal device determining, based on the preset total swap partition size, the size of the swap partition corresponding to each user may include:

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

[0027] The terminal device determines 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;

[0028] 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

[0029] The terminal device determines the size of the swap partition corresponding to each second user based on the preset total swap partition size, 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.

[0030] In the memory management method provided by this implementation, a terminal device can first determine the size of the swap partition corresponding to the active user based on 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 based on the size of the remaining swap partition, prioritizing the swap partition corresponding to the active user and ensuring that the active user has a larger swap partition. This allows the active user to save as many anonymous pages as possible to the swap partition, thereby keeping as many applications corresponding to the active user as possible active, thereby increasing the speed at which the active user can switch applications and improving the user experience.

[0031] 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 alive and improving the user experience.

[0032] Optionally, when the size of the swap partition required by the active user is greater than or equal to the preset total swap partition size, the terminal device may determine M times the preset total swap partition size as the size of the swap partition corresponding to the first user, thereby allocating a larger swap partition to the active user as possible and improving the user experience. M is less than 1, and the value of M can be determined based on actual scenarios.

[0033] In another possible implementation, the terminal device can determine the size of the currently required total swap partition based on the size of the swap partition required by each user, and can 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.

[0034] For example, when the size of the currently required total swap partition 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. In this case, 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 storage of anonymous pages used by the active user in the swap partition, keep the applications subsequently used by the active user alive, and improve the user experience of the active user.

[0035] 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.

[0036] 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 the anonymous page of the first target application, and the first target application is one or more of the applications corresponding to the user.

[0037] In the memory management method provided by this implementation, after determining the size of the swap partition corresponding to each user, for each user, if 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 it is impossible to store all of the anonymous pages corresponding to the user in the swap partition corresponding to the user. In this case, the terminal device can only store the anonymous pages of the first target application corresponding to the user (i.e., some of the applications corresponding to the user) in the swap partition corresponding to the user.

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

[0039] 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 based on 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 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.

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

[0041] Optionally, the terminal device may determine the application priority of each application corresponding to each user based on the usage of each application in the terminal device. For example, the terminal device may determine the application priority of each application based on the usage time or usage frequency of each application. Applications with longer usage time or higher usage frequency have higher corresponding application priorities; applications with shorter usage time or lower usage frequency have lower corresponding application priorities.

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

[0043] 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 previous preset trigger event.

[0044] In the memory management method provided by this 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 previously, 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 previously can be the swap partition allocated to the user by the terminal device in the previous preset trigger event.

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

[0046] 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 based on 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 based on 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.

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

[0048] A trigger event detection module, configured to detect a preset trigger event;

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

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

[0051] Exemplarily, the device may further include:

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

[0053] 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.

[0054] 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 based on the preset total swap partition size and the user priority corresponding to each user, where the user priority corresponding to each user is determined based on the time when each user logs into the terminal device, or based on the last active time of each user; or, to determine the size of the swap partition corresponding to each user based on the preset total swap partition size and the size of the swap partition required by each user, where the size of the swap partition required by each user is determined based on the size of each anonymous page corresponding to each user.

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

[0056] The swap partition size determination module is further configured to determine the size of the swap partition corresponding to the first user based on the preset total swap partition size and the size of each anonymous page corresponding to the first user; and determine the size of the swap partition corresponding to each second user based on 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;

[0057] 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 preset total swap partition size, 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.

[0058] 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 the anonymous page of the first target application, and the first target application is one or more of the applications corresponding to the user.

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

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

[0061] 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 swap partition corresponding to the user is smaller than the size of the swap partition corresponding to the user last time. The swap partition corresponding to the user last time is the swap partition allocated to the user by the terminal device in the previous preset trigger event.

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

[0063] 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. When the processor executes the computer program, the terminal device implements the memory management method described in any one of the first aspects above.

[0064] 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. When the computer program is executed by a computer, the computer implements the memory management method described in any one of the first aspects above.

[0065] 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.

[0066] 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

[0067] FIG1 provides a schematic diagram of an application scenario of anonymous page swapping;

[0068] FIG2 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;

[0069] FIG3 is a schematic diagram of a software architecture to which the memory management method provided in an embodiment of the present application is applicable;

[0070] FIG4 is a schematic diagram of an application scenario provided in an embodiment of the present application;

[0071] FIG5 is a flow chart of a memory management method according to an embodiment of the present application;

[0072] FIG6 is a second schematic diagram of an application scenario provided in an embodiment of the present application. DETAILED DESCRIPTION

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

[0074] It will also be understood that the term "and / or" used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0075] As used in this specification and the appended claims, the term "if" can be interpreted as "when" or "upon" 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 "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.

[0076] 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.

[0077] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

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

[0079] The steps involved in the memory management method provided in the embodiments of the present application are merely examples. Not all steps are mandatory, nor are all information or messages required. These steps can be added or removed 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.

[0080] 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. Ordinary technicians in this field will know 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.

[0081] Terminal devices can support multiple users logging in, for example, users A, B, and C. When multiple users are logged in, there is generally only one active user (e.g., user A) at a time, and the other users are inactive (e.g., user B and user C). When the active user of a terminal device switches from user A to user B, all of user A's applications become user B's background applications. At this point, the memory-consuming applications of user A will continue to occupy the terminal device's memory, resulting in less available memory for user B.

[0082] For example, when the active user on 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, Android Studio corresponding to user A becomes the background application of user B. At this time, 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.

[0083] 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 he is currently starting, the terminal device can swap out anonymous pages to free up 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 free up the memory occupied by the anonymous pages. The data in the hard disk is read and written in units of data blocks, and the swapped-out anonymous pages are generally stored randomly and sporadically in the swap partition. That is, the anonymous pages of different users may be stored in the same data block. As a result, when an application subsequently needs to swap in anonymous pages (i.e., 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 and resulting in a poor user experience.

[0084] Please refer to Figure 1, which shows a schematic diagram of an application scenario of anonymous page swapping. In this application scenario, the users who have logged into the terminal device may include user A, user B, and user C.

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

[0086] Assume that when application C4 corresponding to user C is started, 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.

[0087] When swapping out anonymous pages, the terminal device can randomly and sporadically store the swapped out anonymous pages in the swap partition of the hard disk. For example, as shown in Figure 1, 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.

[0088] When application C1 corresponding to user C is switched to the foreground application, the terminal device needs to swap the anonymous pages of application C1 in the swap partition into the memory for use. Since 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, causing the anonymous pages of application A1 and application B2 to be swapped into the memory as well. However, the anonymous pages of application A1 and application B2 are obviously useless data for application C1, which greatly reduces the data swap efficiency of application C1 and degrades the user experience.

[0089] To solve the above problems, an embodiment of the present application provides a memory management method, a terminal device, and a computer-readable storage medium, wherein the terminal device can support multi-user login. In this method, when a preset trigger event is detected, the terminal device can store the target anonymous page corresponding to each user in the swap partition allocated to each user. That is, in an embodiment 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 a user's application subsequently swaps in an anonymous page, the anonymous page can only be swapped in 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, with strong ease of use and practicality.

[0090] In the embodiment of the present application, the terminal device can be a mobile phone, a tablet computer, a wearable device, an in-vehicle 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 other terminal device that can support multiple users to log in and use. The embodiment of the present application does not impose any restrictions on the specific type of the terminal device.

[0091] The following first introduces the terminal device involved in the embodiment of the present application. Please refer to Figure 2, which shows a schematic structural diagram of a terminal device 100.

[0092] 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.

[0093] It should be understood that the structures illustrated in the embodiments of the present application do 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, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0094] 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 processing unit (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). The different processing units may be independent devices or integrated into one or more processors.

[0095] 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.

[0096] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory, avoiding repeated accesses and reducing processor 110 latency, thereby improving system efficiency.

[0097] In some embodiments, the processor 110 may include one or more interfaces. The interfaces 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.

[0098] The I2C interface is a bidirectional synchronous serial bus that includes a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple I2C bus lines. The processor 110 may be coupled to the touch sensor 160E via the I2C bus interface. For example, the processor 110 may be coupled to the touch sensor 160E via the I2C interface, enabling communication between the processor 110 and the touch sensor 160E via the I2C bus interface, thereby implementing the touch function of the terminal device 100.

[0099] 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 via the UART interface to implement 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 the display serial interface (DSI) and the like. In some embodiments, the processor 110 and the display screen 170 communicate via the DSI interface to implement the display function of the terminal device 100.

[0100] The GPIO interface can be configured through software. The GPIO interface can be configured as a control signal or a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 to the display 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.

[0101] The USB interface 130 is an interface that complies with USB standards and may be a Mini USB interface, a Micro USB interface, a USB Type-C interface, or the like. The USB interface 130 can be used to connect a charger to charge the terminal device 100 and to transfer data between the terminal device 100 and peripheral devices. It can also be used to connect headphones to play audio. This interface can also be used to connect to other terminal devices, such as AR devices.

[0102] It is understood that the interface connection relationship between the modules illustrated in the embodiments of the present application is merely an illustrative 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 a different interface connection method from the above embodiments, or a combination of multiple interface connection methods.

[0103] 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.

[0104] 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 antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In other embodiments, the antennas can be used in conjunction with a tuning switch.

[0105] 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.

[0106] The modem processor may include a modulator and a demodulator. The modulator is used to modulate the low-frequency baseband signal to be transmitted into a medium- or 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 being processed by the baseband processor, the low-frequency baseband signal is passed to the application processor. The application processor displays images or videos 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 provided in the same device as the mobile communication module 140 or other functional modules.

[0107] 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. 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, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 150 can also receive the signal to be sent from the processor 110, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0108] 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).

[0109] The terminal device 100 implements display functions through a GPU, display screen 170, and an application processor. The GPU is a microprocessor for image processing that 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 modify display information.

[0110] Display screen 170 is used to display images, videos, and the like. 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 (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, or a quantum dot light-emitting diode (QLED). In some embodiments, terminal device 100 may include one or N display screens 170, where N is a positive integer greater than one.

[0111] The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. For example, when the terminal device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.

[0112] Video codecs are used to compress or decompress digital video. Terminal device 100 may support one or more video codecs. This allows terminal device 100 to play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, and MPEG4.

[0113] The NPU is a neural network (NN) computing processor. Drawing on the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it rapidly processes input information and can continuously self-learn. The NPU can enable intelligent cognitive applications in the terminal device 100, such as image recognition, face recognition, speech recognition, and text comprehension.

[0114] 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 data storage functions. For example, files such as videos can be saved in the external memory card.

[0115] The internal memory 121 can be used to store computer executable program code, which may include instructions. The internal memory 121 may include a program storage area and a data storage area. 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.

[0116] 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, so that the target anonymous page corresponding to each user can be stored in the swap partition corresponding to each user.

[0117] Pressure sensor 160A is used to sense pressure signals and convert them into electrical signals. In some embodiments, pressure sensor 160A can be located on display screen 170. There are many types of pressure sensors 160A, such as resistive, inductive, and capacitive. A capacitive pressure sensor can include at least two parallel plates made of conductive material. When force acts on pressure sensor 160A, the capacitance between the electrodes changes. Terminal device 100 determines the intensity of the pressure based on this change in capacitance. When a touch operation is applied to display screen 170, terminal device 100 detects the touch operation intensity based on pressure sensor 160A. Terminal device 100 can also calculate the touch location based on the detection signal from pressure sensor 160A. In some embodiments, touch operations applied to the same touch location but with different touch operation intensities can correspond to different operation instructions. For example, when a touch operation with an intensity less than a first pressure threshold is applied to a short message application icon, an instruction to view short messages is executed. When a touch operation with an intensity greater than or equal to the first pressure threshold is applied to a short message application icon, an instruction to create a new short message is executed.

[0118] 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.

[0119] 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.

[0120] Accelerometer 160D can detect the magnitude of acceleration of the terminal device 100 in all directions (generally three axes). When the terminal device 100 is stationary, it can detect the magnitude and direction of gravity. It can also be used to identify the terminal device's posture, enabling applications such as switching between landscape and portrait modes and pedometers.

[0121] The touch sensor 160E is also referred to as a "touch device." The touch sensor 160E can be disposed on the display screen 170. The touch sensor 160E and the display screen 170 form a touch screen, also referred to as a "touch screen." The touch sensor 160E is used to detect touch operations applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operations to the application processor to determine the type of touch event. Visual output related to the touch operations can be provided via the display screen 170. In other embodiments, the touch sensor 160E can also be disposed on the surface of the terminal device 100, at a location different from that of the display screen 170.

[0122] The software system of the terminal device 100 can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. For example, the software system of the terminal device 100 can 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 illustrate the software structure of the terminal device 100.

[0123] Please refer to FIG3 , which shows a software structure block diagram of the terminal device 100 provided in an embodiment of the present application.

[0124] A layered architecture divides software into several layers, each with distinct roles and responsibilities. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers: the application layer, the application framework layer, the Android runtime and system libraries, and the kernel layer.

[0125] The application layer can include a series of application packages. When the terminal device 100 supports multiple users logging in and using it, the application layer can include applications corresponding to each user, and applications can be isolated by user, so that different users cannot access each other's data. For example, for each user, the terminal device 100 can be provided with a space corresponding to the user, and the user's corresponding applications and related data can be stored in this space, and the spaces corresponding to different users are isolated from each other.

[0126] Optionally, the number of users supported by the terminal device 100 can be determined based on the actual scenario. The embodiment of the present application does not impose any restrictions on this. Figure 3 only uses 3 as an example for illustrative purposes.

[0127] As shown in FIG3 , when the terminal device 100 supports user A, user B, and user C to log in and use, the application layer may include the application corresponding to user A (such as calendar, network disk, and WeChat). The terminal device 100 includes the following: 1. The applications corresponding to user A (such as cloud disk, WeLink, and email), and 2. The applications corresponding to user B (such as gallery, browser, and camera) are located in the terminal device 100. 3. The terminal device 100 includes the following: 1. The terminal device 100 includes the following: 2. The terminal device 100 includes the following: 3. The terminal device 100 includes the following: 4. The terminal device 100 includes the following: 5. The terminal device 100 includes the following: 6. The terminal device 100 includes the following: 7. The terminal device 100 includes the following: 8. The terminal device 100 includes the following: 9. The terminal device 100 includes the following: 10. The terminal device 100 includes the following: 11. The terminal device 100 includes the following: 12. The terminal device 100 includes the following: 13. The terminal device 100 includes the following: 14. The terminal device 100 includes the following: 15. The terminal device 100 includes the following: 16. The terminal device 100 includes the following: 17. The terminal device 100 includes the following: 18. The terminal device 100 includes the following: 19. The terminal device 100 includes the following: 20. The terminal device 100 includes the following: 21. The terminal device 100 includes the following: 22. The terminal device 100 includes the following: 23. The terminal device 100 includes the following: 24. The terminal device 100 includes the following: 25. The terminal device 100 includes the following: 26. The terminal device 100 includes the following: 27. The terminal device 100 includes the following: 28. The terminal device 100 includes the following: 29. The terminal device 100 includes the following: 30. The terminal device

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

[0129] As shown in FIG3 , the application framework layer may include a window manager, a content provider, a view system, a telephony manager, a resource manager, a notification manager, and the like.

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

[0131] 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.

[0132] The view system includes visual controls, such as those for displaying text and images. The view system is used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.

[0133] The phone manager is used to provide communication functions of the terminal device 100, such as management of call status (including answering, hanging up, etc.).

[0134] The Notification Manager allows applications to display notifications in the status bar. These messages can be displayed briefly and then disappear automatically, without requiring user interaction. For example, the Notification Manager can be used to notify users of completed downloads and message reminders. The Notification Manager can also display notifications in the top status bar of the system as icons or scrolling text, such as notifications from background applications, or as dialog windows on the screen. Examples include displaying text messages in the status bar, emitting alert sounds, vibrating the device, or flashing indicator lights.

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

[0136] Optionally, the resource manager may include an application management module. The application management module is used to manage 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 preset size of the 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 of the target anonymous page to release memory resources in the terminal device 100.

[0137] For example, when the swap partition corresponding to a user (e.g., user A) becomes smaller, the application management module may further determine the target application corresponding to user A and terminate or close the target application corresponding to user A. The shrinking of the swap partition corresponding to user A 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 previous preset trigger event.

[0138] For example, if the swap partition corresponding to user A is determined to be 1GB based on the current preset trigger event, and the swap partition corresponding to user A was determined to be 1.2GB based on the previous preset trigger event, the application management module may determine that the swap partition corresponding to user A has become smaller. In this case, the application management module may determine the target application corresponding to user A and trigger the killing of the target application corresponding to user A, that is, terminate or close the target application corresponding to user A.

[0139] Android Runtime includes core libraries and a virtual machine. Android runtime is responsible for scheduling and management of the Android system.

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

[0141] The application layer and application framework layer run in a virtual machine. The virtual machine executes Java files in the application layer and application framework layer as binary files. The virtual machine manages object lifecycles, stack management, thread management, security and exception management, and garbage collection.

[0142] The system library can 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.

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

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

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

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

[0147] 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.

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

[0149] It should be understood that swapping out data and swapping in data can be understood as migrating data. In other words, 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.

[0150] The user storage management module is used to manage the swap partition corresponding to each user. In an embodiment of the present application, after the application management module determines the size of the swap partition corresponding to each user, the user storage management module can set the swap partition corresponding to each user in the hard disk according to the size of the swap partition corresponding to each user, so that the target anonymous page corresponding to each user can be stored through the swap partition corresponding to each user. That is, the user storage management module can divide the swap partition of the hard disk into multiple swap 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 swap partition of the hard disk, the user storage management module can store the target anonymous page corresponding to each user in the swap partition corresponding to each user, thereby reducing useless data when subsequent data is swapped in and improving swap-in efficiency. In addition, when the swap 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.

[0151] For example, after the application management module determines the sizes of the swap partitions corresponding to user A, user B, and user C, the user storage management module can set up swap partition A corresponding to user A on the hard disk based on the sizes of the swap partitions corresponding to user A, set up swap partition B corresponding to user B on the hard disk based on the sizes of the swap partitions corresponding to user B, and set up swap partition C corresponding to user C on the hard disk based on the sizes of the swap partitions 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 pages corresponding to user A in swap partition A, store the target anonymous pages corresponding to user B in swap partition B, and store the target anonymous pages corresponding to user C in swap partition C.

[0152] In some embodiments, the kernel layer further includes a ZRAM device, which can be used to compress anonymous pages in memory. That is, the target anonymous page swapped out to the swap partition can be the original uncompressed anonymous page, or it can be an anonymous page compressed by the ZRAM device. It should be understood that the compression ratio used by the ZRAM device for anonymous page compression can be determined based on the actual scenario. The following explanation will be given using the example of a case where the target anonymous page swapped out to the swap partition is an anonymous page compressed by the ZRAM device.

[0153] The memory management method provided in the embodiment of the present application is exemplarily described below with reference to the software structure block diagram shown in FIG3 .

[0154] Please refer to Figure 4, which shows a schematic diagram of an application scenario provided by an embodiment of the present application. In this application scenario, users who have logged into the terminal device may include user A, user B, and user C. As shown in Figure 4, applications 1 and 2 corresponding to user A occupy the terminal device's memory, applications 3 and 4 corresponding to user B occupy the terminal device's memory, and applications 5 and 6 corresponding to user C occupy the terminal device's memory. A user who has logged into the terminal device refers to a user who has logged into the terminal device and has not yet logged out or logged out of the terminal device.

[0155] 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. That is, 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 can refer to the relevant information of the application that occupies the memory of the terminal device among the applications corresponding to the user. 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, as shown in Figure 4, the size of the anonymous page corresponding to each application can be the size after compression by the ZRAM device.

[0156] It should be noted that, as shown in Figure 4, 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 existing methods, and the present embodiment does not impose any restrictions on this.

[0157] Upon detecting a preset trigger event, the terminal device may 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 pages corresponding to user A (e.g., the anonymous pages of application 1 and the anonymous pages of application 2), the target anonymous pages corresponding to user B (e.g., the anonymous pages of application 3 and the anonymous pages of application 4), and the target anonymous pages corresponding to user C (e.g., the anonymous pages of application 5 and the anonymous pages of application 6). For example, the application management module may 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 may determine the swap partition A corresponding to user A based on the size of the swap partition corresponding to user A, determine the swap partition B corresponding to user B based on the size of the swap partition corresponding to user B, and determine the swap partition C corresponding to user C based on the size of the swap partition corresponding to user C.

[0158] After determining the swap partition corresponding to each user, the application management module can determine the target anonymous page corresponding to each user based on 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. At this time, as shown in Figure 4, the user storage management module can store the target anonymous page corresponding to user A in swap partition A (for example, saved as files 1 and 2 in swap partition A), store the target anonymous page corresponding to user B in swap partition B (for example, saved as files 3 and 4 in swap partition B), and store the target anonymous page corresponding to user C in swap partition C (for example, saved as files 5 and 6 in swap partition C).

[0159] 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.

[0160] Please refer to Figure 5, which shows a schematic flow chart of the memory management method provided in an embodiment of the present application. The method can be applied to the terminal device mentioned above. The terminal device can support multi-user login. As shown in Figure 5, the method may include:

[0161] S501: The terminal device detects a preset trigger event;

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

[0163] 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 in 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 swap in the 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 enhancing the user experience.

[0164] Please refer to Figure 6, which shows a second schematic diagram of an application scenario provided by an embodiment of the present application. This application scenario is still illustrated using the scenario shown in Figure 1 as an example, where the users logged into the terminal device may include user A, user B, and user C. Applications A1 and A2 corresponding to user A occupy the memory of the terminal device, applications B1 and B2 corresponding to user B occupy the memory of the terminal device, and applications C1, C2, and C3 corresponding to user C occupy the memory of the terminal device.

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

[0166] 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 the 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 the 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 the swap partition C.

[0167] For example, as shown in FIG6 , 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. This allows the terminal device to swap in anonymous pages only from swap partition B corresponding to user B when an application corresponding to a certain user (e.g., application B2 corresponding to user B) needs to swap in anonymous pages. For example, only data block 2 may be swapped in to memory, without swapping in anonymous pages of other users. This reduces the swapping in of useless data, improves data swapping efficiency, and enhances user experience.

[0168] 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 into a terminal device, the terminal device may detect a user login event. When a user logs out or logs out of the terminal device, the terminal device may detect a user logout event. When the active user of the terminal device switches from one user to another, the terminal device may detect a user switching event. The active user refers to the user currently using the terminal device.

[0169] 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. Instead, it 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 to release memory, increase the available memory for active users, ensure the performance of active users, and improve user experience.

[0170] It should be understood that a user can be a system user of a terminal device or a user corresponding to a specified application. Among them, a system user refers to a user who can use all or part of the functions of 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.

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

[0172] 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 embodiment does not impose any limitation on this.

[0173] Optionally, the terminal device may obtain the size of a preset total swap partition, and determine the size of the swap partition corresponding to each user based on the size of the preset total swap partition, thereby determining the swap partition corresponding to each user based on the size of the swap partition corresponding to each user. For example, the terminal device may set a swap partition corresponding to each user based on the size of the swap partition corresponding to each user in the preset total swap partition. That is, the terminal device may divide the preset total swap partition into multiple 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.

[0174] 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.

[0175] The following describes in detail the process of the terminal device determining the size of the swap partition corresponding to each user.

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

[0177] 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 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.

[0178] 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 further away the login time is from the current moment, the earlier the login time is; the closer the login time is to the current moment, the later the login time is. 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.

[0179] For example, if the users logged into the terminal device include user A, user B, and user C, and user A's login time is 10:30 on April 8, 2023, user B's login time is 3:00 on April 8, 2023, and user C's login time is 19:40 on April 8, 2023, and the terminal device detects the preset trigger event at 20:30 on April 8, 2023, the terminal device can determine that user A's login time is earlier than user B's login time, and user B's login time is earlier than user C's login time. Therefore, the terminal device can determine the first preset ratio as the size of swap partition A corresponding to user A: the size of swap partition B corresponding to user B: the size of swap partition C corresponding to user C. Alternatively, the terminal device can determine the first preset ratio as the size of swap partition C corresponding to user C: the size of swap partition B corresponding to user B: the size of swap partition A corresponding to user A.

[0180] For example, when the users who have logged into the terminal device include user A, user B, and user C, assuming that user A was most recently active at 15:30 on April 8, 2023, user B was most recently active at 12:00 on April 8, 2023, and user C is an active user of the terminal device, this means that user B's most recent active time is earlier than user A's most recent active time, and user A's most recent active time is earlier than user C's most recent active time. Therefore, the terminal device can determine the first preset ratio as the size of the swap partition B corresponding to user B: the size of the swap partition A corresponding to user A: the size of the swap partition C corresponding to user C. Alternatively, the terminal device can determine the first preset ratio as the size of the swap partition C corresponding to user C: the size of the swap partition A corresponding to user A: the size of the swap partition B corresponding to user B.

[0181] 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.

[0182] In one example, the first preset ratio may be determined by the terminal device based on 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 based on 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.

[0183] 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 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 swapping out anonymous pages based on a 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 based on the application information corresponding to the user. In other words, for each anonymous page, the terminal device can determine the application corresponding to the anonymous page and the user corresponding to the anonymous page based on the starting address corresponding to the anonymous page and the application information corresponding to each user.

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

[0185] It should be noted that each user may include active users of the terminal device. The anonymous pages corresponding to the active users may not include the anonymous pages corresponding to the foreground application, that is, the terminal device may not swap out the anonymous pages of the foreground application to ensure the smooth operation of the foreground application.

[0186] 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 based on the anonymous page of application A2, the anonymous page of application A3, and the anonymous page of application A4.

[0187] 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.

[0188] 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.

[0189] 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.

[0190] In another example, the first preset ratio can be determined by the terminal device based on 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 based on 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.

[0191] 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 based on the duration of time the user switches 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 time each user switches to an inactive user, and determine the duration interval of the user priority corresponding to each user based on the duration of time each user switches to an inactive user, so that the numerical value corresponding to each user priority can be determined based on the duration interval of each user priority and the correspondence.

[0192] 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 the first preset ratio as 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.

[0193] Optionally, 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 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 the user switches to an inactive user, the higher the user priority corresponding to the user, so that recently active users can have a larger swap partition, so as to save as many anonymous pages corresponding to recently active users as possible to the swap partition, and to keep as many applications corresponding to recently active users as possible alive, thereby facilitating the recently active users to quickly start applications and improving user experience.

[0194] For example, when the users who have logged into the terminal device include user A, user B, and user C, assume that the current time (i.e., the time when the terminal device detects a 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.

[0195] Optionally, 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. This allows recently logged-in users to have a larger swap partition, saving as many anonymous pages corresponding to recently logged-in users as possible to the swap partition, thereby keeping as many applications corresponding to recently logged-in users as possible active, thereby facilitating the recently logged-in users to quickly start applications and improving user experience.

[0196] For example, if the users who have logged into the terminal device include user A, user B, and user C, and user A's login time is 10:30 on April 8, 2023, user B's login time is 15:00 on April 8, 2023, and user C's login time is 19:40 on April 8, 2023, the terminal device can determine that user A's login time is earlier than user B's login time, and user B's login time is earlier than user C's login time. 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.

[0197] In another example, the first preset ratio can be set by default on the terminal device. For example, since active users of the terminal device generally need to frequently switch applications, to ensure the speed of application switching for active users and improve the user experience, a larger swap partition can be set for the active users to save 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 alive. This allows the terminal device to quickly start the switched applications by swapping the anonymous pages in the swap partition into memory when the active users need to switch applications. Therefore, the proportion of active users in the first preset ratio can be relatively large. For example, the terminal device can be set by default to a first preset ratio of N:1:1, ..., where N is greater than 1. The specific value of N can be determined based on the actual scenario. In other words, the swap partitions corresponding to the inactive users are the same size, 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.

[0198] For example, when the users 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 a first preset ratio as the size of swap partition A corresponding to user A: the size of swap partition C corresponding to user C: the size of swap partition B corresponding to user B, and determine the first preset ratio as N:1:1. Assuming that N=2 and the preset total swap partition size is 3G, the terminal device can determine, based on the first preset ratio, the size of swap partition A corresponding to user A as 3G*2 / (2+1+1)=1.5G, the size of swap partition B corresponding to user B as 3G*1 / (2+1+1)=0.75G, and the size of swap partition C corresponding to user C as 3G*1 / (2+1+1)=0.75G.

[0199] It should be noted that the first preset ratio is set to N:1:1, ... by default, which is only for illustrative purposes and should not be construed as limiting 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.

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

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

[0202] Optionally, when the size of the swap partition required by the first user is smaller than the size of the preset 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 the active user, thereby saving as many anonymous pages corresponding to the active user as possible to the swap partition, thereby keeping as many applications corresponding to the active user as possible active, increasing the speed at which the active user switches applications, and improving the user experience.

[0203] Optionally, when the size of the swap partition required by the first user is greater than or equal to the preset total swap partition size, the terminal device may determine M times the preset total swap partition size as the size of the swap partition corresponding to the first user. M is less than 1, and the value of M may be determined based on actual scenarios.

[0204] 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 based on 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.

[0205] 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 based on the actual scenario. For example, the relationship between the second users in the second preset ratio can be determined based on the order of login time from earliest to latest; or the relationship between the second users in the second preset ratio can be determined based on the order of login time from latest to earliest. For example, the relationship between the second users in the second preset ratio can be determined based on the order of the most recent active time of each second user from earliest to latest; or the relationship between the second users in the second preset ratio can be determined based on the order of the most recent active time of each second user from latest to earliest.

[0206] The following will be exemplified by taking as an example the determination of the relationship between the second users in the second preset ratio in order from latest active time of the second users.

[0207] Optionally, the second preset ratio may be determined by the terminal device according to the sizes of the swap partitions required by the second users. Exemplarily, the terminal device may directly determine the ratio between the sizes of the swap partitions required by the second users as the second preset ratio.

[0208] 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 the second preset ratio as the size of swap partition C corresponding to user C: the size of swap partition B corresponding to user B, and can determine the second preset ratio as 2:4. Therefore, the terminal device can determine that the size of swap partition A corresponding to user A is 5G, the size of swap partition B corresponding to user B is (8-5)*4 / (2+4)=2G, and the size of swap partition C corresponding to user C is (8-5)*2 / (2+4)=1G.

[0209] Optionally, the second preset ratio can be determined by the terminal device based on 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; and 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 based on the numerical values ​​corresponding to the respective user priorities. For example, the terminal device can determine the ratio between the numerical values ​​corresponding to the respective user priorities as the second preset ratio. It should be understood that the numerical values ​​corresponding to the respective user priorities can be referred to in the above description and will not be repeated here.

[0210] 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 based on the rule that the exchange partitions corresponding to the second users are of the same size, 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.

[0211] In another possible implementation, the terminal device can determine the size of the currently required total swap partition based on the size of the swap partition required by each user, and can 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.

[0212] For example, when the size of the currently required total swap partition 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 storage of anonymous pages during subsequent use by the first user, and improve the user experience of the first user.

[0213] 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.

[0214] For example, if the users logged into a terminal device include user A, user B, and user C, and the swap partition size required by user A is 4GB, the swap partition size required by user B is 3GB, and the swap partition size required by user C is 1GB, the terminal device can determine that the currently required total swap partition size is 8GB. Assuming that the preset total swap partition size is 6GB, the terminal device can determine that the ratio between the preset total swap partition size and the currently required total swap partition size is 6 / 8. In this case, based on this ratio and the swap partition size required by user A, the terminal device can determine that the size of swap partition A corresponding to user A is 4GB*6 / 8=3GB. Based on this ratio and the swap partition size required by user B, the terminal device can determine that the size of swap partition B corresponding to user B is 3GB*6 / 8=2.25GB. Based on this ratio and the swap partition size required by user C, the terminal device can determine that the size of swap partition C corresponding to user C is 1GB*6 / 8=0.75GB.

[0215] For example, when the size of the currently required total swap partition 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).

[0216] The third preset ratio may be the same as the first preset ratio described above. The process by which the terminal device determines the size of the swap partition corresponding to each user based on 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 based on the preset total swap partition size and the first preset ratio, and is not further described here.

[0217] 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 it is impossible to store all anonymous pages corresponding to the user in the swap partition corresponding to the user. In this case, the terminal device can determine the target application corresponding to the user (hereinafter referred to as the first target application) and store the anonymous pages corresponding to the first target application in the swap partition corresponding to the user.

[0218] 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.

[0219] 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 of 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 improving the startup speed when the user uses the first target application again and enhancing the user experience.

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

[0221] 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.

[0222] For example, the terminal device is set by default with an application priority of S1 for application 1, an application priority of S2 for application 2, an application priority of S3 for application 3, an application priority of S4 for application 4, and an application priority of 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, the application priority of application 3 corresponding to user A is S3, the application priority of application 3 corresponding to user B is S3, 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.

[0223] Optionally, the terminal device may determine the application priority of each application corresponding to each user based on the usage of each application in the terminal device. For example, the terminal device may determine the application priority of each application based on the usage time or usage frequency of each application. Applications with longer usage time or higher usage frequency have higher corresponding application priorities; applications with shorter usage time or lower usage frequency have lower corresponding application priorities.

[0224] It should be noted that the above-mentioned determination of the first target application based on the application priority is only for illustrative purposes and should not be understood as limiting the embodiments of the present application. In the embodiments of the present application, the terminal device may also determine the first target application corresponding to each user based on the current usage duration of each application or the time when it is switched to a background application.

[0225] For example, the longer an app is currently in use, the greater its probability of being determined as the first target app; the shorter an app is currently in use, the smaller its probability of being determined as the first target app. For example, the later an app is switched to a background app, the greater its probability of being determined as the first target app; the earlier an app is switched to a background app, the smaller its probability of being determined as the first target app.

[0226] The current usage duration may refer to the duration that the application has been running in the foreground before the preset trigger event is detected.

[0227] 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.

[0228] 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 previously, 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, i.e., terminate or close the second target application. The swap partition corresponding to the user previously may be the swap partition allocated to the user by the terminal device in the previous preset trigger event.

[0229] It should be understood that when a user logs in, logs out, or switches users in the terminal device, the terminal device will re-determine the swap partition corresponding to each user according to the aforementioned method.

[0230] Optionally, the terminal device may determine the second target application corresponding to each user based on 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 based on the application priority, and may terminate or close the second target application to retain as many applications as possible that the user is most likely to use again.

[0231] Similarly, the above-described determination of the second target application based on application priority is only for illustrative purposes and should not be construed as limiting the embodiments of the present application. In the embodiments of the present application, the terminal device may also determine the second target application corresponding to each user based on the current usage duration of each application or the time when it is switched to a background application.

[0232] For example, the longer an app is currently in use, the lower its probability of being determined as the second target app; the shorter an app is currently in use, the higher its probability of being determined as the second target app. For example, the later an app is switched to a background app, the lower its probability of being determined as the second target app; the earlier an app is switched to a background app, the higher its probability of being determined as the second target app.

[0233] 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 this application.

[0234] 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 correspondingly implement each step of the memory management method.

[0235] 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 this application. Their specific functions and technical effects can be found in the method embodiment section and will not be repeated here.

[0236] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and 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 into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into 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, and will not be repeated here.

[0237] The present application also provides a terminal device comprising 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. When the processor executes the computer program, the terminal device implements the steps of any of the aforementioned memory management method embodiments. For example, the structure of the terminal device may be as shown in FIG2 .

[0238] 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 of any of the above-mentioned memory management method embodiments.

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

[0240] 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. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. Among them, the computer program includes computer program code, which 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 or a telecommunication signal.

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

[0242] Those skilled 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 beyond the scope of this application.

[0243] In the embodiments provided in this 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 merely illustrative. For example, the division of the modules or units is merely a logical function division. In actual implementation, there may be other division methods, 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.

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

[0245] The above-described embodiments 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, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection 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 preset size of the 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 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. 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 exchange partition corresponding to the user is smaller than the size of the exchange 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. A corresponding exchange partition is a exchange partition allocated by the terminal device to the user in a previous 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.

Citation Information

Patent Citations

  • Virtualized platform based Method for swapping in disc page

    CN101853219A

  • Method and device for eliminating sensitive data of Linux system memory

    CN104007993A

  • Memory exchange method and display equipment

    CN111949564A

  • Exchange partition management method and device, electronic equipment and storage medium

    CN112882798A

  • Virtual memory management method and electronic equipment

    CN113722087A

Cited By

  • Inactive user data management method and device, equipment and storage medium

    CN122045147A