IP Library Granted Patent US 11,928,359
Granted Patent B2
US 11,928,359 · App. 17/867,880 · Granted Mar 12, 2024

Memory swapping method and apparatus

Inventors: Chengke Wang (Hangzhou, CN); Yongjun Wei (Hangzhou, CN); Xie Miao (Hangzhou, CN); Wei Fang (Hangzhou, CN)
Assignee: HUAWEI TECHNOLOGIES CO., LTD.
G06F3/0656G06F3/0608G06F3/064G06F3/0659G06F3/0673
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 11,928,359
App. No.
17/867,880
Granted
Mar 12, 2024
Kind
B2
Abstract

A memory swapping method and apparatus are provided. The method includes: selecting n to-be-swapped-out pages; compressing the n to-be-swapped-out pages into n compressed blocks, and buffering the n compressed blocks in a compressed data buffer area; organizing at least one of the n compressed blocks into m to-be-written units; and writing the m to-be-written units into a swap area of a non-volatile storage device in a maximum of m batches, where at least one of the m to-be-written units is stored in a segment of continuous space in the swap area. The method reduces a quantity of write times during memory swapping, thereby prolonging a service life of the non-volatile storage device.

Claims (50)

1. A memory swapping method, comprising:

selecting n to-be-swapped-out pages, wherein n is an integer greater than 0;

compressing the n to-be-swapped-out pages into n compressed blocks, grouping the n compressed blocks into at least one group based on a group identifier, and buffering the at least one group in a compressed data buffer area, wherein compressed blocks comprised in each group have a same group identifier;

organizing at least one compressed block in one group into m to-be-written units, wherein m is an integer less than or equal to n and greater than 0, and a size of each of the m to-be-written units is an integer quantity of pages; and

writing the m to-be-written units into a swap area of a non-volatile storage device in a maximum of m batches, wherein at least one to-be-written unit in the m to-be-written units is stored in a segment of continuous space in the swap area,

wherein before the organizing at least one compressed block in one group into m to-be-written units, the method further comprises;

selecting a part of the at least one group based on a second indication, wherein the second indication comprises the group identifier, and the second indication is sent by an operating system or an application at an application layer, and

wherein the second indication further comprises a quantity of compressed blocks or a to-be-swapped-out data volume, and the quantity of compressed blocks or the to-be-swapped-out data volume indicates a quantity of to-be-swapped-out compressed blocks in a group indicated by the group identifier or a volume of to-be-swapped-out data in the group indicated by the group identifier.

2. The method according to claim 1 , wherein the selecting n to-be-swapped-out pages comprises:

receiving a first indication, wherein the first indication comprises the group identifier, and the first indication is sent by the operating system or the application at the application layer; and

selecting the n to-be-swapped-out pages with the group identifier.

3. The method according to claim 2 , wherein the group identifier comprises an identifier of a process group corresponding to similar resource use behaviors, a process identifier, an application identifier, or an access time.

4. A memory swapping method, comprising:

selecting n to-be-swapped-out pages, wherein n is an integer greater than 0;

compressing the n to-be-swapped-out pages into n compressed blocks, grouping the n compressed blocks into at least one group based on a group identifier, and buffering the at least one group in a compressed data buffer area, wherein compressed blocks comprised in each group have a same group identifier;

organizing at least one compressed block in one group into m to-be-written units, wherein m is an integer less than or equal to n and greater than 0, and a size of each of the m to-be-written units is an integer quantity of pages; and

writing the n to-be-written units into a swap area of a non-volatile storage device in a maximum of m batches, wherein at least one to-be-written unit in the m to-be-written units is stored in a segment of continuous space in the swap area,

wherein before the writing the m to-be-written units into a swap area of a non-volatile storage device in a maximum of m batches, the method further comprises:

creating a mapping table, wherein the mapping table comprises a correspondence between a page identifier of the at least one of the n compressed blocks and a swap area address corresponding to the at least one of the n compressed blocks, the page identifier is an identifier of at least one to-be-swapped-out page corresponding to the at least one of the n compressed blocks, the swap area address is an address of a segment of space that belongs to the swap area and that is allocated to the at least one of the n compressed blocks, and the mapping table is used to obtain the swap area address during page swap-in by using the page identifier.

5. The method according to claim 4 , further comprising:

obtaining, from the mapping table based on a page identifier of a page that is requested to be swapped in, a swap area address corresponding to the page identifier of the page that is requested to be swapped in; and

reading a compressed block from the obtained swap area address, and storing the at least one of the n compressed blocks in the compressed data buffer area.

6. The method according to claim 4 , further comprising:

obtaining, from the mapping table based on a page identifier of a page that is requested to be swapped in, a swap area address corresponding to the page identifier of the page that is requested to be swapped in; and

reading, from the obtained swap area address, a to-be-written unit in which the at least one of the n compressed blocks is located, and storing the to-be-written unit in the compressed data buffer area.

7. The method according to claim 6 , further comprising:

marking a status of the to-be-written unit as “being swapped in”.

8. A computer device, wherein the computer device comprises a processor and a memory, the memory is configured to store instructions, and the processor is configured to invoke the instructions to:

select n to-be-swapped-out pages, wherein n is an integer greater than 0;

compress the n to-be-swapped-out pages into n compressed blocks, grouping the n compressed blocks into at least one group based on a group identifier, and buffering the at least one group in a compressed data buffer area, wherein compressed blocks comprised in each group have a same group identifier;

organize at least one compressed block in one group into m to-be-written units, wherein m is an integer less than or equal to n and greater than 0, and a size of each of the m to-be-written units is an integer quantity of pages; and

write the m to-be-written units into a swap area of a non-volatile storage device in a maximum of m batches, wherein at least one of the m to-be-written units in the m to-be-written units is stored in a segment of continuous space in the swap area,

wherein the processor is further configured to:

select a part of the at least one group based on a second indication is sent by an operating system or an application at an application layer, and

wherein the second indication further comprises a quantity of compressed blocks or a to-be-swapped-out data volume, and the quantity of compressed blocks or the to-be-swapped-out data volume indicates a quantity of to-be-swapped-out compressed blocks in a group indicated by the group identifier or a volume of to-be-swapped-out data in the group indicated by the group identifier.

9. The computer device according to claim 8 , wherein the processor is further configured to:

receive a first indication, wherein the first indication comprises the group identifier, and the first indication is sent by the operating system or the application at the application layer; and

select the n to-be-swapped-out pages with the group identifier.

10. The computer device according to claim 9 , wherein

the group identifier comprises an identifier of a process group corresponding to similar resource use behaviors, a process identifier, an application identifier, or an access time.

11. A computer device, wherein the computer device comprises a processor and a memory, the memory is configured to store instructions, and the processor is configured to invoke the instructions to:

select n to-be-swapped-out pages, wherein n is an integer greater than 0,

compress the n to-be-swapped-out pages into n compressed blocks, grouping the n compressed blocks into at least one group based on a group identifier, and buffering the at least one group in a compressed data buffer area, wherein compressed blocks comprised in each group have a same group identifier;

organize at least one compressed block in one group into m to-be-written units, wherein m is an integer less than or equal to n and greater than 0, and a size of each of the m to-be-written units is an integer quantity of pages; and

write the m to-be-written units into a swap area of a non-volatile storage device in a maximum of m batches, wherein at least one of the m to-be-written units in the m to-be-written units is stored in a segment of continuous space in the swap area,

wherein the processor is further configured to:

create a mapping table, wherein the mapping table comprises a correspondence between a page identifier of the at least one of the n compressed blocks and a swap area address corresponding to the at least one of the n compressed blocks, the page identifier is an identifier of at least one to-be-swapped-out page corresponding to the at least one of the n compressed blocks, the swap area address is an address of a segment of space that belongs to the swap area and that is allocated to the at least one of the n compressed blocks, and the mapping table is used to obtain the swap area address during page swap-in by using the page identifier.

12. The computer device according to claim 11 , wherein the processor is further configured to:

obtain, from the mapping table based on a page identifier of a page that is requested to be swapped in, a swap area address corresponding to the page identifier of the page that is requested to be swapped in; and

read a compressed block from the obtained swap area address, and store the at least one of the n compressed blocks in the compressed data buffer area.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Dec 12, 2023
From: WANG, CHENGKE; WEI, YONGJUN; MIAO, XIE; FANG, WEI
To: HUAWEI TECHNOLOGIES CO., LTD.
Reel/Frame 065836/0411 →
Priority Claims (1)
CN 202010066109.0 · Jan 20, 2020 · national
Continuity (2)
Continuation PCTCN2020113676 · Sep 7, 2020
Related Publication 20220350531A1 · Nov 3, 2022