Data protection method, electronic device, and storage medium

By setting write and read permissions for shared memory blocks of terminal devices in a Linux distributed storage system, the problem of data loss and corruption in terminal device memory when user programs are unexpectedly terminated is solved, achieving effective data protection and rapid response.

CN114595169BActive Publication Date: 2026-01-02ALIBABA (CHINA) CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210178870.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-25
Publication Date
2026-01-02
Estimated Expiration
2042-02-25

AI Technical Summary

Technical Problem

In Linux distributed storage systems, data in the memory of terminal devices is easily lost or corrupted when user programs terminate unexpectedly or malfunction, lacking an effective protection mechanism.

Method used

The target shared memory block is identified among multiple shared memory blocks on the terminal device, and its read/write permissions are set to writable before data is written. After data is written, it is restored to readable, ensuring that data is not lost when the user program terminates unexpectedly and preventing write requests from non-users from polluting the data.

Benefits of technology

It protects the memory data of terminal devices, prevents data loss and contamination, simplifies the data protection process, and improves the speed and efficiency of data protection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114595169B_ABST
    Figure CN114595169B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a kind of data protection method, electronic equipment and storage medium, the method comprises: in response to the data write request generated by the user program installed in terminal equipment, determine the target shared memory block corresponding to this write request in the multiple shared memory blocks contained in terminal equipment, then set the read-write permission of this target shared memory block as writable, and write the data to be written in data write request into target shared memory block, after data write completes, set the read-write permission of target shared memory block as readable.The above-mentioned method, since shared memory will not be released due to accidental termination of user program, therefore, data written in shared memory block will not be lost due to termination of user program, realize data protection.Again through the setting of read-write permission, only when terminal equipment responds to the data write request generated by user, data in target shared memory block can be modified, so as to realize data protection.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of memory storage, and in particular to a data protection method, an electronic device and a storage medium. BACKGROUND

[0002] A Linux-based distributed storage system can share storage load by multiple storage servers, thereby improving the reliability, availability and access efficiency of the system. The distributed storage system often adopts a client (i.e. terminal device) / server (Client / Server, referred to as C / S) architecture. In this architecture, the distributed storage process of data can be specifically that data generated due to the running of a user program installed on a terminal device is first written to the memory of the client, and then periodically persisted to the server.

[0003] However, for data stored in the memory of the terminal device and not persisted, when the user program is unexpectedly terminated, the data in the memory of the terminal device will be lost; when the user program occurs an exception and automatically generates a data write request, the data in the memory of the terminal device will be contaminated. The above situations will all result in the data in the memory of the terminal device being unprotected.

[0004] Therefore, how to protect the data in the memory of the terminal device has become a problem to be solved. SUMMARY

[0005] In view of this, the embodiments of the present application provide a data protection method, an electronic device and a storage medium to protect the data in the memory of the terminal device.

[0006] In a first aspect, the embodiments of the present application provide a data protection method, comprising:

[0007] In response to a data write request of a user program in a terminal device, determining a target shared memory block corresponding to the data write request in a plurality of shared memory blocks contained in the terminal device;

[0008] Setting the read-write permission of the target shared memory block as writable;

[0009] Writing the to-be-written data in the data write request to the target shared memory block;

[0010] After the to-be-written data is written, setting the read-write permission of the target shared memory block as readable.

[0011] In a second aspect, the embodiments of the present application provide another data protection method applied to a terminal device, comprising:

[0012] In response to a data write request generated by a user program in a terminal device, a target shared memory block corresponding to the data write request is determined in a plurality of shared memory blocks included in the terminal device;

[0013] The data to be written in the data write request is written into the target shared memory block.

[0014] In a third aspect, an embodiment of the present application provides another data protection method applied to a terminal device, comprising:

[0015] In response to a data write request generated by a user program in a terminal device, a target memory block corresponding to the data write request is determined in a plurality of memory blocks included in the terminal device;

[0016] The read-write permission of the target memory block is set to writable;

[0017] The data to be written in the data write request is written into the target memory block;

[0018] After the data to be written is written, the read-write permission of the target memory block is set to readable.

[0019] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor;

[0020] The memory is configured to store a computer program;

[0021] The processor is configured to execute the computer program to implement the data protection method according to the first aspect to the third aspect.

[0022] In a fifth aspect, an embodiment of the present application provides a non-transitory machine readable storage medium, which stores executable code, and when the executable code is executed by a processor of an electronic device, the processor can at least implement the data protection method according to the first aspect to the third aspect.

[0023] The data protection method provided by the embodiment of the present application, in response to a data write request generated by a user program in a terminal device, determines a target shared memory block corresponding to the write data request in a plurality of shared memory blocks included in the terminal device, and sets the read-write permission of the target shared memory block to writable. Based on this writable permission, the data to be written in the data write request can be written into the target shared memory block, and after the data is written, the read-write permission of the target shared memory block is set to readable.

[0024] It can be seen that in the above method, the data to be written is written into the target shared memory block set by the terminal device, and since the shared memory space will not be released due to the unexpected termination of the user program, the data written by the user into the target shared memory block will not be lost due to the termination of the user program, thereby realizing data protection. And by setting the read-write permission of the target shared memory block, the target shared memory block can be modified only in response to the data write request generated by the user, and the data write request generated for other reasons cannot modify the data in the target memory block, thereby realizing data protection. BRIEF DESCRIPTION OF DRAWINGS

[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.

[0026] Figure 1 A flowchart of a data protection method provided by an embodiment of the present application;

[0027] Figure 2 A flowchart of another data protection method provided by an embodiment of the present application;

[0028] Figure 3 A flowchart of another data protection method provided by an embodiment of the present application;

[0029] Figure 4 A flowchart of another data protection method provided by an embodiment of the present application;

[0030] Figure 5 A flowchart of another data protection method provided by an embodiment of the present application;

[0031] Figure 6 A structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0032] In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the following will combine the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the protection scope of the present application.

[0033] The terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the description of the invention and the appended claims, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be understood that the terms "and / or", "at least one of", "one or more of", and "and / or at least one of" as used herein in the disclosure refers to and encompasses any possible combinations of one or more of the associated listed items.

[0034] It should be understood that the term "and / or" as used herein is merely an associating relationship of the associated objects, and means that there can be three relationships, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone. In addition, the character " / " herein generally means that the front and rear associated objects are in an "or" relationship.

[0035] Depending on the context, the word "if" as used herein can be interpreted to mean "when" or "while" or "in response to determining" or "in response to identifying." Similarly, the phrase "if it is determined" or "if an (expressed condition or event) is identified," can be interpreted to mean "when it is determined" or "in response to determining" or "when an (expressed condition or event) is identified" or "in response to identifying an (expressed condition or event)," depending on the context.

[0036] It should also be noted that the terms "comprises", "comprising", or any other variations thereof, are intended to cover a non-exclusive inclusion, such that a product or a process that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such product or process. Without more limitations, an element defined by the phrase "comprising a" does not exclude the existence of additional identical elements in the product or process that includes the element.

[0037] Some embodiments of the present application will be described in detail with reference to the drawings, which are shown below. The following embodiments and features in the embodiments can be combined with each other without conflict. In addition, the sequence of steps in each of the following method embodiments is only an example, not a strict limitation.

[0038] Figure 1 A flowchart of a data protection method according to an embodiment of the present application is shown in FIG. 1. The data protection method according to an embodiment of the present application can be executed by a terminal device. As shown in FIG. 1, the method includes the following steps: Figure 1

[0039] S101, in response to a data write request generated by a user program in the terminal device, determining a target shared memory block corresponding to the data write request in a plurality of shared memory blocks included in the terminal device.

[0040] ​When the user program runs in the terminal device, the user can generate a data write request for the user program. Optionally, the terminal device can be a device supporting a Linux system, and the user program can be a program providing file editing capability. The data write request can be a data write request triggered by the user for a to-be-edited file in the user program. At this time, for the terminal device in the user state, the terminal device can determine, in response to the data write request, a target shared memory block corresponding to the data write request in a plurality of shared memory blocks included in the terminal device.

[0041] Optionally, a part of the entire memory space of the terminal device can be set as a shared memory space, and the shared memory space can be specially allocated to the user program, that is, a corresponding relationship between the shared memory space and the user program is established. The shared memory space corresponding to the user program can be composed of a plurality of shared memory blocks. Optionally, different user programs can be installed in the terminal device, and different user programs can have different shared memory spaces. The size of the shared memory space and the size of the shared memory block can be set based on the 4K alignment principle, that is, the size of the shared memory space and the shared memory block needs to be an integer power of 2 of 4K, such as 4K, 8K, 16K, etc.

[0042] Based on the above description, the terminal device can actually determine a target memory block in a plurality of shared memory blocks included in the shared memory space corresponding to the user program. In an optional determination manner, the terminal device determines, in response to the data write request, a target position of to-be-written data in the to-be-edited file in the data write request according to a position offset in the data write request. The position offset is an offset of the position of the to-be-written data in the data write request in the to-be-edited file relative to the position of the first character in the to-be-edited file. Then, a target address corresponding to the target position is determined according to the corresponding relationship between the position and the memory address to which the shared memory space belongs. The shared memory block to which the target address belongs is the target shared memory block corresponding to the data write request, and the to-be-written data should be mapped to the target address.

[0043] In another optional determination manner, the plurality of shared memory blocks in the shared memory space corresponding to the user program can also be allocated to different to-be-edited files in the user program, that is, there is a corresponding relationship between each to-be-edited file and the allocated shared memory block. The terminal device can determine at least one shared memory block corresponding to the to-be-edited file according to the user program identifier and the file identifier in the data write request. Then, the terminal device can determine the target position of the to-be-written data in the to-be-edited file according to the position offset in the data write request. Then, the terminal device can determine the target address corresponding to the target position according to the corresponding relationship between the position and the memory address of the at least one shared memory block corresponding to the to-be-edited file. The shared memory block to which the target address belongs is the target shared memory block corresponding to the data write request, and the to-be-written data should be mapped to the target address. This manner has a smaller query range and a faster query speed.

[0044] In S102, the read-write permission of the target shared memory block is set as writable.

[0045] In S103, the to-be-written data in the data write request is written into the target shared memory block.

[0046] In S104, after the to-be-written data is written, the read-write permission of the target shared memory block is set as readable.

[0047] Before the process of S101 is performed, the read-write permission of the target shared memory block is readable. After the process of S101 is performed, the terminal device can set the read-write permission of the target shared memory block as writable. At this time, the to-be-written data in the data write request can be written into the target shared memory block. After the to-be-written data is written, the terminal device re-sets the read-write permission of the target shared memory block as readable, and at this time, the response to the data write request is completed.

[0048] In the above process, the to-be-written data in the data write request is written into the shared memory block, and the shared memory block will not be released due to the accidental exit of the user program, that is, even if the user program accidentally exits, the data written by the user and stored in the target shared memory block will not be lost, so that the protection of the data written by the user can be implemented.

[0049] In addition, through the above setting of the read-write permission, the target shared memory block is in a writable state only during the response to the data write request generated by the user, and is in a readable state and cannot be written with data at other times. Based on this permission setting manner, when a non-user-generated data write request occurs, the to-be-written data in the request will not be written into the target shared memory block, so that the data written by the user before will not be contaminated, and the protection of the user input data is implemented. The non-user-generated data write request can include a data write request generated when the user program runs abnormally.

[0050] Optionally, the setting of the read-write permission of the target shared memory block can be performed by a central processing unit (CPU) having a permission modification capability in the terminal device, that is, by a hardware manner. More specifically, the setting of the read-write permission can be implemented by modifying the value of a PKRU register in the CPU. In contrast, the steps S101 and S103 can be implemented by executing the code in the user program, that is, by a software manner.

[0051] Optionally, the data written by the user into the target shared memory block can also be periodically persisted in the server, so as to persistently save the data written by the user.

[0052] In the embodiment, in response to the data write request generated by the user program, the target shared memory block corresponding to the data write request is determined in the plurality of shared memory blocks included in the terminal device, and the read-write permission of the target shared memory block is set as writable. Based on the writable permission, the data to be written in the data write request can be written into the target shared memory block, and the read-write permission of the target shared memory block is set as readable after the data is written.

[0053] It can be seen that, in the above method, the shared memory space will not be released due to the accidental termination of the user program, and therefore, the data written into the target shared memory block will not be lost due to the termination of the user program, so as to achieve data protection. By setting the read-write permission of the target shared memory block, the target shared memory block can be modified only in response to the data write request generated by the user, and the data in the target memory block cannot be modified due to other reasons, so as to achieve data protection.

[0054] In addition, the above embodiments and each embodiment provided below are executed when the terminal device is in the user state, that is, when the data protection is provided, the terminal device does not switch between the user state and the kernel state, so as to simplify the implementation process of the data protection and improve the implementation speed of the data protection.

[0055] In practice, the user can also generate a data read request for the user program. At this time, the terminal device responds to the data read request and reads data from the target shared memory block. Since the terminal device sets the read-write permission of the shared memory block as shown in steps S102 and S104, the state of the target shared memory block is readable at all times except during the response to the data write request generated by the user, and therefore, the permission state of each shared memory block in the shared memory space remains unchanged when the terminal device responds to the data read request, and is still readable.

[0056] On the basis of the above embodiments, Figure 2Another flowchart of a data protection method provided by an embodiment of the present application is shown in FIG. 2. Before responding to the data write request, the data protection method can further include the following steps: Figure 2 The embodiment shown in FIG. 1 implements the allocation and division of the shared memory space and the shared memory blocks. The terminal device can determine the target shared memory block corresponding to the data write request according to the division result.

[0057] Before step S101, the data protection method can further include the following steps as shown in FIG. 2: Figure 2 The data protection method can further include the following steps as shown in FIG. 2:

[0058] S201, in response to the start of the user program, setting a non-shared memory space in the terminal device as a shared memory space corresponding to the user program.

[0059] In a normal case, the entire memory space contained in the terminal device is a non-shared memory space. In response to the start of the user program, the user program in the terminal device can apply for a shared memory space from the terminal device by calling the mmap function, i.e., setting a non-shared memory space in the terminal device as a shared memory space by calling the mmap function. This shared memory space can be referred to as zone. This shared memory space corresponds to the user program. Meanwhile, the correspondence between the first address of the shared memory space and the user program can be recorded. Optionally, the shared memory space is usually a part of the entire non-shared memory space.

[0060] S202, dividing the shared memory space into a plurality of shared memory blocks.

[0061] Then, the mmap function is continuously called to divide the shared memory space allocated to the user program into a plurality of shared memory blocks, each of which can be referred to as block. The application basis of the shared memory space and the division basis of the shared memory blocks can be the 4K alignment principle in the embodiment shown in FIG. 1. Figure 1

[0062] S203, setting the read-write permission of the plurality of shared memory blocks as readable and the state of the plurality of shared memory blocks as unoccupied.

[0063] Next, the terminal device sets the read-write permission of the plurality of shared memory blocks as readable and also sets the state of the plurality of shared memory blocks as unoccupied. The unoccupied state of the shared memory block indicates that no data has been written into the shared memory block. It is easy to understand that, since the user program is just started at this time, the user has not generated a data write request, and therefore the plurality of shared memory blocks are not written with data, i.e., are in the unoccupied state. The setting of the state of the shared memory block can be achieved by changing the value of the preset identification bit in the shared memory block, such as setting the preset identification bit to 0, which indicates that the shared memory block is in the unoccupied state.

[0064] ​After the user program is started, the application, the division and the state setting of the shared memory block can be realized by executing the above steps S201-S203, so as to realize the initialization of the shared memory block. Based on the initialization result, the terminal device can write data and protect data in the manner shown in Figure 1 .

[0065] In this embodiment, before the data protection is performed by using the shared memory and the permission setting mechanism, the shared memory block can also be initialized to realize the normal writing and protection of data based on the initialization result. In addition, the parts not described in detail in this embodiment can be referred to the related description of the embodiment shown in Figure 1 . The execution process and technical effects of this technical solution can be referred to the description in the embodiment shown in Figure 1 , which will not be described here.

[0066] Optionally, when the user program exits, the terminal device can also recycle the shared memory space allocated for the user program when the user program is started in response to the exit of the user program, that is, the shared memory space allocated for the user program is released, and the shared memory space can be reset to a non-shared memory space.

[0067] Figure 1 The response process of the data write request is introduced in the embodiment shown in Figure 1 . When the data write request is a non-first data write request generated by the user for the to-be-edited file in the user program, the data writing and data protection can be performed in the manner shown in the embodiment. Figure 1 When the data write request is a first data write request generated by the user for the to-be-edited file in the user program, the terminal device can automatically allocate an unoccupied shared memory block for each to-be-edited file in the user program at the program startup. After the allocation, the shared memory block is in an occupied state. The allocated shared memory block can be the shared memory block with the earliest memory address in the plurality of shared memory blocks contained in the shared memory space allocated for the user program, and the to-be-written data in the first data write request generated by the user can be directly written into the shared memory block. The specific writing process can be referred to the related description in the embodiment shown in .

[0068] According to the above manner, when a to-be-edited file has not been written for a long time, the shared memory block allocated for the to-be-edited file is in an occupied state, but actually no data is written into the shared memory block, that is, the shared memory block is not used. At the same time, another to-be-edited file has a large amount of data writing, and it is possible that the shared memory block allocated for the to-be-edited file is full and there is no other shared memory block in the terminal device in an unoccupied state, so that the data writing of the other to-be-edited file cannot be completed. Therefore, the shared memory blocks contained in the shared memory space corresponding to the application program are not fully used.

[0069] When the data write request is the first data write request generated by the user to the file to be edited in the user program, another optional way is that the terminal device program is started, and the target shared memory block is not allocated for the file to be edited immediately, but the allocation of the shared memory block is performed when the first data write request is received, so as to ensure sufficient use of the shared memory block.

[0070] Then Figure 3 Another data containing method provided by an embodiment of the present application is shown in a flowchart. The method can include the following steps:

[0071] S301, in response to the first data write request generated by the user to the file to be edited in the user program, determining the shared memory space corresponding to the user program.

[0072] S302, in the plurality of shared memory blocks contained in the shared memory space, determining an unoccupied shared memory block as a target shared memory block.

[0073] S303, setting the state of the target shared memory block as occupied.

[0074] When the user first writes to the file to be edited in the user program, that is, the first data write request is generated, the terminal device can determine the shared memory space allocated to the user program and the state of each shared memory block contained in the shared memory space according to the user program identifier in the first data write request. Then, the first shared memory block in the unoccupied state can be determined as the target shared memory block according to the address sequence of the plurality of shared memory blocks, and the state of the target shared memory block is set as the occupied state.

[0075] S304, setting the read-write permission of the target shared memory block as writable.

[0076] S305, writing the data to be written in the first data write request into the target shared memory block.

[0077] S306, after the writing of the data to be written is completed, setting the read-write permission of the target shared memory block as readable.

[0078] The execution process of steps 304-306 is similar to the corresponding steps of the foregoing embodiments, and specific reference can be made to the related description in the foregoing embodiments, which will not be repeated here. Figure 1

[0079] ​In the embodiment, when the user generates a first data write request of the to-be-edited file, an unoccupied shared memory block can be selected from the plurality of shared memory blocks contained in the shared memory space corresponding to the user program, and the to-be-written data in the first data write request can be written into the unoccupied shared memory block, and the written data will not be contaminated by data in other to-be-edited files. In addition, parts not described in detail in the embodiment can refer to the related descriptions in the above embodiments. The execution process and technical effects of the technical solution can refer to the descriptions in the above embodiments, and will not be described here again.

[0080] In practice, optionally, as data write requests are continuously generated, the to-be-written data in the data write requests can be continuously written into a shared memory block. For a data write request generated by the user after the shared memory block is full, the terminal device can respond to the data write request, and re-determine another shared memory block with an unoccupied state from the plurality of shared memory blocks corresponding to the user program according to the method shown in the embodiment, and write the to-be-written data in the data write request into the re-determined shared memory block. Figure 3

[0081] It can be seen that in the process of writing the to-be-edited file by the user, the terminal device can allocate a plurality of shared memory blocks in sequence, that is, after one shared memory block is full, another shared memory block is re-allocated, so as to ensure full use of the shared memory block.

[0082] In the above embodiments, when the user generates a first data write request or when a data write request is generated after a memory data block is full, an unoccupied shared memory block needs to be allocated for the to-be-edited file. For the allocation process, in practice, optionally, the following situations can also occur:

[0083] The plurality of shared memory blocks contained in the shared memory space allocated by the terminal device for the user program are all occupied, at this time, the allocation of the shared memory block cannot be performed, so that the to-be-written data in the data write request cannot be written. At the same time, the terminal device can also display corresponding prompt information to prompt the writing failure.

[0084] As can be easily understood, the data in the shared memory will be lost when the terminal device is closed, therefore, in order to realize the persistent storage of the user-written data, optionally, the data written into the shared memory block can also be sent to the server regularly, that is, the data in the shared memory block is stored persistently on the server.

[0085] ​Specifically, when a preset persistence period is reached, the data in the target shared memory block can be stored persistently on the server, at which time the terminal device can delete the correspondence between the target shared memory block and the to-be-edited file, that is, release the target shared memory block corresponding to the to-be-edited file back to the shared memory space corresponding to the user program, and at the same time, set the state of the released target shared memory to an unoccupied state.

[0086] When the user generates a data write request for another to-be-edited file, the previously released shared memory block can also be allocated to another to-be-edited file in the user program, and the content input by the user for the other to-be-edited file can be written into the previously released shared memory block. The correspondence between the shared memory block and the other to-be-edited file can be established in the process of responding to the data write request. This correspondence can ensure that when the user adds content to the other to-be-edited file, the added content will be written into the target shared memory block until the target shared memory block is full.

[0087] Figure 4 A flowchart of another data protection method provided by an embodiment of the application is shown in FIG. 8. This method can also be executed by a terminal device. As shown in FIG. 8, the method can include the following steps: Figure 4

[0088] S401, in response to a data write request generated by a user for a user program in a terminal device, determining a target shared memory block corresponding to the data write request from a plurality of shared memory blocks contained in the terminal device.

[0089] S402, writing to-be-written data in the data write request into the target shared memory block.

[0090] During the running of the user program in the terminal device, the user can generate a data write request therefor. Optionally, the terminal device can be a device supporting a Linux system, and the data write request generated by the user can be a data write request generated for a to-be-edited file in the user program. At this time, the terminal device in the user mode can determine a target shared memory block corresponding to the data write request from a plurality of shared memory blocks contained in the terminal device in response to the data write request generated by the user. The process of determining the shared memory block can refer to the related description in the embodiment shown in FIG. 4, which will not be repeated here. Figure 1

[0091] Optionally, a part of the memory space of the terminal device can be set as a shared memory space, and the shared memory space can have been allocated to the user program, that is, there is a correspondence between the shared memory space and the user program. Moreover, the shared memory space corresponding to the user program can also be composed of a plurality of shared memory blocks. The size of the shared memory space and the shared memory block can be set based on the 4K alignment principle.​​

[0092] Optionally, when the data write request generated by the user is a non-first data write request generated by the to-be-edited file, the target shared memory block corresponding to the non-first data write request can be directly determined by responding to the non-first data write request, and the to-be-written data in the request can be written into the target shared memory block.

[0093] When the data write request generated by the user is a first data write request generated by the user for the to-be-edited file, the terminal device can respond to the first data write request, determine the shared memory space corresponding to the user program, and then determine a shared memory block in an unoccupied state, i.e., a target shared memory block, from the shared memory blocks contained in the shared memory space, and the to-be-written data in the first data write request can be written into the target shared memory block. The terminal device can also set the state of the target shared memory block to which the data is written to an occupied state.

[0094] Optionally, for the first data write request generated by the user, when all the shared memory blocks contained in the shared memory space corresponding to the user program are in an occupied state, the first data write request cannot be responded to, and the terminal device can generate a write failure message to notify the user.

[0095] In the embodiment, in response to the data write request generated by the user for the user program, a target shared memory block corresponding to the write data request is determined from the plurality of shared memory blocks contained in the terminal device, and the to-be-written data in the data write request is written into the target shared memory block. In the above method, since the shared memory space will not be released due to the unexpected termination of the user program, the data written into the target shared memory block will not be lost due to the termination of the user program, thereby realizing the protection of the data written by the user. In the above method, the terminal device is in the user state, that is, when the data written by the user is protected, the terminal device does not need to switch between the user state and the kernel state, thereby simplifying the implementation process of data protection and improving the implementation speed of data protection.

[0096] In addition, the parts not described in detail in the embodiment can refer to the related descriptions of the embodiments shown in Figure 1 . The execution process and technical effects of the technical solutions can refer to the descriptions in the embodiments shown in Figure 1 , which will not be described here in detail.

[0097] On the basis of the embodiments shown in Figure 4 , optionally, initialization of the shared memory block can be performed before responding to the data write request.

[0098] The initialization process can be described as follows: in response to the start of the user program, the terminal device can set part of the non-shared memory space of the terminal device as the shared memory space corresponding to the user program by calling the mmap function, or divide the shared memory space into a plurality of shared memory blocks by calling the mmap function. Finally, the states of the plurality of shared memory blocks are set as unoccupied states. The specific process can be referred to Figure 2 The related description in the embodiments shown in FIG. 1 is not repeated here.

[0099] Optionally, the user can also generate a data read request for the user program, and at this time, the terminal device can directly respond to the request to read data from the corresponding shared memory block.

[0100] In order to realize the persistent storage of the data written by the user into the to-be-edited file, the data written into the shared memory block can also be persistently stored on the server, at which time the terminal device can delete the corresponding relationship between the shared memory block and the to-be-edited file, that is, release the shared memory block back to the shared memory space corresponding to the user program. After that, when the user generates a data write request for other to-be-edited files, the to-be-written data contained in the request can be written into the shared memory block released before.

[0101] Optionally, when the user program exits, the shared memory space allocated to the user program can also be released, that is, the shared memory space can be re-set as a non-shared memory space.

[0102] In addition, the parts not described in detail in the above content can refer to the related description of the embodiments shown in FIG. 1 and FIG. 2. Figure 2 and Figure 3 The specific implementation process and technical effects of the above content can refer to the description in the embodiments shown in FIG. 1 and FIG. 2, which are not repeated here. Figure 2 and Figure 3 The specific implementation process and technical effects of the above content can refer to the description in the embodiments shown in FIG. 1 and FIG. 2, which are not repeated here.

[0103] Figure 5 Another flowchart of a data containing method provided by the embodiments of the present application is shown. The method can also be executed by a terminal device. As shown in FIG. 4, Figure 5 the method can include the following steps:

[0104] S501, in response to a data write request generated by a user for a user program in a terminal device, determining a target memory block corresponding to the data write request in a plurality of memory blocks contained in the terminal device.

[0105] When the user program runs in the terminal device, the user can generate a data write request for the user program. Optionally, the terminal device can be a device supporting a Linux system, and the user program can be a program providing file editing capability. The data write request can be a data write request triggered by the user for a to-be-edited file in the user program. At this time, for the terminal device in the user mode, the terminal device can determine a target memory block corresponding to the data write request in a plurality of memory blocks included in the terminal device in response to the data write request.

[0106] Optionally, the entire memory space of the terminal device can be divided into a plurality of sub-memory spaces, and any sub-memory space can be allocated to the user program, that is, a corresponding relationship between the sub-memory space and the user program is established. Moreover, the sub-memory space corresponding to the user program can be composed of a plurality of memory blocks. Optionally, different user programs can be installed in the terminal device, and different user programs can have different sub-memory spaces. The size of the sub-memory space and the size of the memory block can be set based on the 4K alignment principle.

[0107] The determination process of the target memory block is similar to the process in the embodiment shown in Figure 1 The process in the embodiment shown in

[0108] S502, set the read-write permission of the target memory block to writable.

[0109] S503, write the to-be-written data in the data write request into the target memory block.

[0110] S504, after the to-be-written data is written, set the read-write permission of the target memory block to readable.

[0111] Before the process of step S101 is performed, the read-write permission of the target memory block is readable. After the process of step S101 is performed, the terminal device can set the read-write permission of the target memory block to writable. At this time, the to-be-written data in the data write request can be written into the target memory block. After the to-be-written data is written, the terminal device re-sets the read-write permission of the target memory block to readable, and at this time, the response to the data write request is completed.

[0112] Through the above setting of the read-write permission, the target memory block is in a writable state only during the response to the data write request generated by the user, and is in a readable state and cannot be written with data at other times. Based on this permission setting mode, when a data write request generated by the user is generated, the to-be-written data in the request will not be written into the target memory block, and the data written by the user before will not be polluted, and data protection is achieved. In addition to the data write request generated by the user, the user program may also generate a data write request when an exception occurs in the running of the user program.

[0113] In the embodiment, in response to a data write request generated by a user program, a target memory block corresponding to the data write request is determined in a plurality of memory blocks included in the terminal device, and the read-write permission of the target memory block is set as writable. Based on the writable permission, the data to be written in the data write request can be written into the target memory block, and the read-write permission of the target memory block is set as readable after the data is written. It can be seen that, in the above method, by setting the read-write permission of the target memory block, the target memory block can be modified only in response to the data write request generated by the user, and the data in the target memory block cannot be modified due to other reasons, thereby realizing data protection.

[0114] The above embodiments and each embodiment provided below are executed when the terminal device is in the user mode, that is, when data protection is provided, the terminal device does not switch between the user mode and the kernel mode, thereby simplifying the implementation process of data protection and improving the implementation speed of data protection.

[0115] In addition, parts not described in detail in the above content can refer to the related description of the embodiments shown in Figure 1 . The specific implementation process and technical effects of the above content can refer to the description in the embodiments shown in Figure 1 , which will not be described here.

[0116] On the basis of the embodiments shown in Figure 5 , optionally, initialization of the memory block can be performed before responding to the data write request. The specific initialization process is the same as the initialization mode of the shared memory block in the above embodiments, which will not be described here.

[0117] When the user generates a first data write request for the to-be-edited file, optionally, the target memory block can be determined from a plurality of memory blocks pre-allocated for the to-be-edited file, thereby realizing data writing; optionally, the target memory block can also be allocated for the to-be-edited file in response to the first data write request, thereby ensuring sufficient use of the memory block. The specific process can refer to the related content in the embodiments shown in Figure 3 , which will not be described here.

[0118] Optionally, at the corresponding time, the sub-memory space allocated to the user program and the memory block allocated to the to-be-edited file can also be released.

[0119] Parts not described in detail in the above content can refer to the related description of the embodiments shown in Figure 2-3 . The specific implementation process and technical effects of the above content can refer to the description in the embodiments shown in Figure 2-3 , which will not be described here.

[0120] The above Figure 1-3The data protection method provided by the embodiments shown can be applied in a network file storage system supporting a Linux operating system. For ease of understanding, the specific implementation process of the data protection method provided by each of the above embodiments can be exemplarily described in this scenario.

[0121] The network file storage system (hereinafter referred to as the storage system) can be a user program installed on a terminal device, and the system contains a plurality of files to be edited. In response to the start of the storage system, the storage system in the terminal device can call the mmap function to set part of the non-shared memory space of the terminal device to a shared memory space, and allocate the shared memory space to the storage system. At the same time, the shared memory space is divided into a plurality of shared memory blocks, and the read-write permissions of the shared memory blocks are set to readable, and the state is set to an unoccupied state.

[0122] Then, when the user generates a first data write request 1 for file 1 in the storage system, the terminal device can determine the first memory block 1 in the unoccupied state as the target shared memory block according to the address sequence of the plurality of readable shared memory blocks divided above. At this time, the shared memory block 1 is in the occupied state. The CPU of the terminal device sets the read-write permission of the shared memory block 1 to writable by modifying the value in the PKRU register, and the to-be-written data in the first data write request 1 can be written into the shared memory block 1. After the to-be-written data is written, the terminal device immediately sets the read-write permission of the shared memory block 1 to readable.

[0123] Through the above setting of read-write permissions, the situation that the to-be-written data in the data write request generated by the non-user is written into the target memory block can be avoided, the pollution of the data input by the non-user to the data input by the user is improved, and thus the protection of the data written by the user is realized. In addition, the data in the shared memory block will not be lost due to accidental exit of the storage system, and the data written by the user can also be protected.

[0124] After the first data write request 1, the user can also generate a data write request 2 for file 1, and since the data write request 2 is to add new content in file 1, the to-be-written data in the data write request 2 can continue to be written into the shared memory block 1. And with the continuous increase of the content in file 1, the shared memory block 1 can be filled. After being filled, when the user generates a data write request 3 for file 1, the terminal device can allocate a shared memory block 2 in the unoccupied state for the data write request 3 to write the to-be-written data in the data write request 3 into the shared memory block 2.

[0125] In the process of responding to the data write request, there is a process of allocating the shared memory block. Since the user can perform data write on other files in the storage system before performing data write on file 1, when the memory block is allocated for the data write request generated by the user on file 1, it is very likely that the plurality of shared memory blocks contained in the shared memory space are all in the occupied state, and the data write request generated by the user on file 1 cannot be responded. The terminal device can generate a prompt information to remind the user.

[0126] For the data written in the shared memory block by the user, the data can also be persistently saved to the server. Then, after the data in the memory block is persistently saved to the server, the shared memory block can be released back to the shared memory space allocated for the storage system, and the shared memory block can be allocated to other files in the storage system. When the entire storage system is closed, the shared memory space allocated for the storage system is also released, that is, the shared memory space can be re-set as a non-shared memory space.

[0127] Optionally, the user can also read the data written in the shared memory block.

[0128] In addition, the data protection method provided in each of the above embodiments can also be applied to a network disk supporting a Linux operating system. The user can perform data write and read on the files stored in the network disk according to the method provided in each of the above embodiments.

[0129] The above Figure 4 The embodiments shown in the above can also be applied in the storage system or the network disk scenario. Compared with the above, the process of setting the read-write permission is missing, and other processes can be referred to the related content in the above description. The above Figure 5 The embodiments shown in the above can also be applied in the storage system or the network disk scenario. Compared with the above, the process of applying and dividing the shared memory space is missing, and other processes can be referred to the related content in the above description.

[0130] In a possible design, the data protection method can also be executed by an electronic device, such as Figure 6 The electronic device can include a processor 21 and a memory 22. The memory 22 is configured to store a program supporting the electronic device to execute the data protection method provided in the above Figures 1 to 5 The processor 21 is configured to execute the program stored in the memory 22.

[0131] The program includes one or more computer instructions, and the one or more computer instructions can implement the program related to the data protection method provided in the above Figures 1-5 embodiments when executed by the processor 21.

[0132] Optionally, the structure of the electronic device can further include a communication interface 23 for the electronic device to communicate with other devices or communication networks.

[0133] In addition, the embodiment of the present application provides a computer storage medium for storing computer software instructions for the electronic device, which contains the program for executing the above-mentioned Figures 1-5 The program involved in the data protection method in the embodiment.

[0134] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A data protection method, characterized by, The method comprises: in response to the start of a user program, setting a non-shared memory space in a terminal device as a shared memory space corresponding to the user program, different user programs having different shared memory spaces; dividing the shared memory space into a plurality of shared memory blocks; by modifying the value of a register in a central processing unit included in the terminal device, setting the read-write permission of the plurality of shared memory blocks as readable, and the state of the plurality of shared memory blocks as unoccupied; in response to a data write request of a user program in a terminal device, determining a target shared memory block in an unoccupied state corresponding to the data write request in a plurality of shared memory blocks included in the terminal device; wherein the plurality of shared memory blocks included in the terminal device constitute a shared memory space corresponding to the user program, the shared memory space is a part of the entire memory space of the terminal device, and the shared memory space will not be released due to accidental termination of the user program; by modifying the value of a register in a central processing unit included in the terminal device, setting the read-write permission of the target shared memory block as writable; writing the to-be-written data in the data write request into the target shared memory block, and setting the target shared memory block as occupied; after the to-be-written data is written, by modifying the value of a register in a central processing unit included in the terminal device, setting the read-write permission of the target shared memory block as readable; in response to the exit of the user program, setting the shared memory space corresponding to the user program as a non-shared memory space.

2. The method of claim 1, wherein, The method further comprises: in response to the first data write request of the user to the to-be-edited file in the user program, determining a shared memory space corresponding to the user program; among a plurality of shared memory blocks included in the shared memory space, determining a shared memory block in an unoccupied state as the target shared memory block; setting the state of the target shared memory block as occupied.

3. The method of claim 2, wherein, The method further comprises: determining the correspondence between the to-be-edited file and the target shared memory block; after the data in the target shared memory block is stored to a server, deleting the correspondence between the target shared memory block and the to-be-edited file; setting the state of the target shared memory block as unoccupied.

4. The method of claim 2, wherein, The method further comprises: if all the plurality of shared memory blocks in the shared memory space corresponding to the user program are in an occupied state, generating a write failure message.

5. The method of claim 1, wherein, The method further comprises: in response to a data read request of the user program in the terminal device, determining a shared memory block corresponding to the data read request in a plurality of shared memory blocks included in the terminal device; keeping the read-write permission of the shared memory block corresponding to the data read request as readable; performing data reading from the shared memory block corresponding to the data read request.

6. An electronic device, comprising: The method comprises: a memory and a processor; the memory is used to store a computer program; The processor is configured to execute the computer program to implement the data protection method according to any one of claims 1 to 5.

7. A non-transitory machine-readable storage medium, comprising: The non-transitory machine readable storage medium stores executable code, which when executed by a processor of an electronic device, causes the processor to perform the data protection method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • System and method for safe sharing dynamic memory of multi-application space

    CN101329657A

  • Method and device for information interaction, method and device for object management, and system

    CN108062252A

  • Shared memory permission configuration method, memory unit and system

    CN113849428A