TECHNICAL FIELD

This application relates to the computer field, and in particular, to an information writing method and apparatus.

BACKGROUND

A non-volatile dual in-line memory module (NVDIMM) is a memory that integrates a random access memory (RAM) and a non-volatile memory (NVM). The NVDIMM includes different products. An NVDIMM-P is an NVDIMM that has appeared recently. A typical NVDIMM-P includes a memory bus, a controller, a dynamic random access memory (DRAM), and a flash memory.

In comparison with a dual in-line memory module (DIMM), data stored in the NVDIMM includes persistent data. In this case, a data loss can be avoided when a power failure occurs on a host, improving reliability of the host. However, the persistent data stored in the NVDIMM may be easily thieved. Therefore, the NVDIMM increases a security risk while improving the reliability of the host. In addition, storage performance of a flash memory degrades due to long-term reading and writing of the persistent data. For example, memory leak occurs on the flash memory due to long-term reading and writing of the flash memory. To resolve the foregoing problem, a sanitize operation needs to be performed on the persistent data in the NVDIMM. Before the sanitize operation is performed, data that needs to be stored in the NVM has been stored in another memory. For example, the other memory is a solid state disk (SSD). In this case, information stored in the NVM is useless information, and all information stored in the NVM can be sanitized using the sanitize operation. All the information includes user data and metadata such that a storage status of the NVM is changed to an initial status, and the foregoing problem is resolved.

However, in other approaches, a problem of relatively high power consumption exists when the sanitize operation is performed on the persistent data in the NVDIMM. How to reduce power consumption during the sanitize operation is a problem that currently needs to be resolved urgently.

SUMMARY

This application provides an information writing method and apparatus, to resolve the foregoing problems.

According to a first aspect, an information writing method is provided and applied to an NVDIMM. The NVDIMM includes an NVDIMM controller and an NVM. The method includes receiving, by the NVDIMM controller, a sanitize command from a host, where the sanitize command is used to instruct the NVDIMM controller to sanitize data in the NVM using a first write pattern, and the first write pattern is one of at least two patterns of writing information into the NVM, and writing, by the NVDIMM controller, information into the NVM according to the sanitize command.

Optionally, the information that is written by the NVDIMM controller according to the instruction of the sanitize command is the same as information that is written into the NVM in a power-saving write pattern.

Optionally, the receiving, by the NVDIMM controller, a sanitize command from a host includes receiving, by the NVDIMM controller, the sanitize command from the host using a command bus.

Optionally, the method further includes setting, by the NVDIMM controller, a sanitizing status to a readable state, where the readable state indicates that the host is allowed to track execution of the sanitize command.

Optionally, before the receiving, by the NVDIMM controller, a sanitize command from a host, the method further includes receiving, by the NVDIMM controller, a first check command from the host, where the first check command is used to instruct the NVDIMM controller to check whether an uncompleted read and/or write request exists in a buffer, checking, by the NVDIMM controller, the buffer according to the first check command, sending, by the NVDIMM controller, a first check result to the host, where the first check result is used to indicate that no uncompleted read and/or write request exists in the buffer, receiving, by the NVDIMM controller, a second check command from the host, where the second check command is used to instruct the NVDIMM controller to check whether an uncompleted write request exists in a controller of the NVM, checking, by the NVDIMM controller, the controller of the NVM according to the second check command, and sending, by the NVDIMM controller, a second check result to the host, where the second check result is used to indicate that no uncompleted write request exists in the controller of the NVM.

Optionally, the sanitize command is a command code in the NVDIMM-P protocol for a double data rate 5 (DDR5) interface, or the sanitize command is a command code in the NVDIMM-P protocol for a double data rate 4 (DDR4) interface.

According to a second aspect, an information writing method is provided and applied to an NVDIMM. The NVDIMM includes an NVDIMM controller and an NVM. The method includes generating, by a host, a sanitize command, where the sanitize command is used to instruct the NVDIMM controller to sanitize data in the NVM using a first write pattern, and the first write pattern is one of at least two patterns of writing information into the NVM, and sending, by the host, the sanitize command to the NVDIMM controller.

Optionally, the generating, by a host, a sanitize command includes generating, by the host, the sanitize command based on a type of the NVM, where the information that is written by the NVDIMM controller according to the instruction of the sanitize command is the same as information that is written into the NVM in a power-saving write pattern.

Optionally, the sending, by the host, the sanitize command to the NVDIMM controller includes sending, by the host, the sanitize command to the NVDIMM controller using a command bus.

Optionally, the method further includes sending, by the host, a tracking command to the NVDIMM controller, where the tracking command is used to track execution of the sanitize command.

Optionally, the method further includes sending, by the host, a first check command to the NVDIMM controller, where the first check command is used to instruct the NVDIMM controller to check whether an uncompleted read and/or write request exists in a buffer, receiving, by the host, a first check result from the NVDIMM controller, where the first check result is used to indicate that no uncompleted read and/or write request exists in the buffer, sending, by the host, a second check command to the NVDIMM controller, where the second check command is used to instruct the NVDIMM controller to check whether an uncompleted write request exists in a controller of the NVM, and receiving, by the host, a second check result from the NVDIMM controller, where the second check result is used to indicate that no uncompleted write request exists in the controller of the NVM, and the sending, by the host, the sanitize command to the NVDIMM controller includes sending, by the host, the sanitize command to the NVDIMM controller based on the first check result and the second check result.

Optionally, the sanitize command is a command code in the NVDIMM-P protocol for a DDR5 interface, or the sanitize command is a command code in the NVDIMM-P protocol for a DDR4 interface.

According to a third aspect, an information writing apparatus is provided, where the apparatus can implement functions performed by the NVDIMM controller in the method of the first aspect, and the functions may be implemented by hardware, or may be implemented by hardware executing corresponding software. The hardware or software includes one or more units or modules that correspond to the foregoing functions. In a possible design, the apparatus is a chip.

According to a fourth aspect, an information writing apparatus is provided, where the apparatus can implement functions performed by the host in the method of the second aspect, and the functions may be implemented by hardware, or may be implemented by hardware executing corresponding software. The hardware or software includes one or more units or modules that correspond to the foregoing functions. In a possible design, the apparatus is a chip.

According to a fifth aspect, this application further provides a computer system, where the computer system includes the information writing apparatus of the third aspect and the information writing apparatus of the fourth aspect.

According to a sixth aspect, this application further provides a computer program product, where the computer program product includes computer program code, and when the computer program code is run by an NVDIMM controller, the NVDIMM controller performs the method of the first aspect.

According to a seventh aspect, this application provides a computer program product, where the computer program product includes computer program code, and when the computer program code is run by a host, the host performs the method of the second aspect.

