File access method and device, electronic equipment and storage medium

By detecting the delayed copy attribute of file descriptors, the file object is obtained only when the target file is actually accessed, which solves the performance bottleneck caused by frequent calls to the fget() function in Unixbench-syscall and improves the accuracy and effectiveness of system call performance testing.

CN120872756BActive Publication Date: 2026-08-25UNIONTECH SOFTWARE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510897069.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-30
Publication Date
2026-08-25
Estimated Expiration
2045-06-30

AI Technical Summary

Technical Problem

The Unixbench-syscall performance test revealed a performance bottleneck caused by frequent calls to the fget() function, especially since the dup() function was closed before it was used to copy file descriptors, resulting in unnecessary kernel overhead and inaccurate system call performance test results.

Method used

By detecting whether a file descriptor is a delayed copy descriptor, the file object is only obtained when the target file is actually accessed, avoiding unnecessary calls to the fget() function and implementing a delayed binding mechanism.

Benefits of technology

This reduces CPU resource waste and improves the accuracy of system call performance test results and the effectiveness of benchmark tests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120872756B_ABST
    Figure CN120872756B_ABST
Patent Text Reader

Abstract

The present disclosure provides a file access method, device, electronic equipment and storage medium. The method comprises: in response to detecting that an access operation on a target file is initiated through a first file descriptor, determining whether the first file descriptor is an original file descriptor; if the determination is no, delaying a copy file descriptor according to a copy attribute tag of the first file descriptor; if the determination is yes, determining a second file descriptor associated with the first file descriptor according to an original file descriptor tag of the first file descriptor; obtaining a second file object corresponding to the second file descriptor, and determining the second file object as a first file object corresponding to the first file descriptor; and accessing the target file through the first file object. The present disclosure obtains the first file object corresponding to the first file descriptor only when the access operation on the target file is initiated through the first file descriptor, which can avoid waste of CPU resources and improve the accuracy of system call performance test results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer science and technology, and specifically to a file access method, apparatus, electronic device, and storage medium. Background Technology

[0002] During performance testing with Unixbench (a widely used system performance benchmarking tool), flame graph analysis revealed a significant performance bottleneck in Unixbench-syscall (the system call performance testing module), primarily concentrated in the call path of the fget() function.

[0003] Further analysis confirmed that the root cause of the problem lay in the frequent calls to the `dup()` function, which triggered calls to the `fget()` function. Specifically, during the copying of file descriptors using `dup()`, the system calls `fget()` to obtain the kernel file object corresponding to the original file descriptor to complete the copying operation. However, in actual test scenarios, the newly generated file descriptors were not used for any read, write, or access operations after creation; instead, they were immediately closed.

[0004] This pattern leads to redundant calls to the fget() function. Although the file object lookup and reference count increment operations are performed, the new file descriptor is not actually used, and the related resources are released in a short time. This causes unnecessary kernel overhead, which not only wastes CPU (Central Processing Unit) resources but also affects the accuracy of system call performance test results and reduces the effectiveness of benchmark tests.

[0005] Therefore, it is necessary to propose a file access method to solve at least one of the above-mentioned technical problems. Summary of the Invention

[0006] Firstly, this disclosure provides a file access method, the method comprising:

[0007] In response to detecting an access operation to a target file initiated through a first file descriptor, determine whether the first file descriptor is an original file descriptor;

[0008] If not, determine whether the first file descriptor is a delayed copy file descriptor based on the copy attribute label of the first file descriptor;

[0009] If so, determine the second file descriptor associated with the first file descriptor based on the original file descriptor label of the first file descriptor;

[0010] Obtain the second file object corresponding to the second file descriptor, and determine the second file object as the first file object corresponding to the first file descriptor;

[0011] The target file is accessed through the first file object.

[0012] In some alternative implementations, the method further includes, prior to detecting an access operation to the target file initiated through the first file descriptor:

[0013] Perform a copy operation on the second file descriptor to generate the first file descriptor, wherein the first file descriptor and the second file descriptor correspond to the same file object;

[0014] Determine whether to initiate an access operation to the target file through the first file descriptor;

[0015] If not, generate the original file descriptor tag of the first file descriptor based on the second file descriptor, and determine that the first file descriptor is a delayed copy file descriptor.

[0016] In some optional implementations, after determining whether to initiate an access operation to the target file through the first file descriptor, the method further includes:

[0017] If it is determined that it is, obtain the second file object corresponding to the second file descriptor, and determine the second file object as the first file object corresponding to the first file descriptor;

[0018] The target file is accessed through the first file object.

[0019] In some optional implementations, after generating the original file descriptor tag of the first file descriptor based on the second file descriptor and determining that the first file descriptor is a delayed copy file descriptor, the method further includes:

[0020] In response to detecting a close operation on the first file descriptor, determine whether the first file descriptor has performed an access operation on the target file;

[0021] If confirmed, set the first file object to null and close the first file descriptor;

[0022] If the determination is not correct, set the first file object to empty.

[0023] In some optional implementations, after generating the original file descriptor tag of the first file descriptor based on the second file descriptor and determining that the first file descriptor is a delayed copy file descriptor, the method further includes:

[0024] In response to detecting a close operation for the second file descriptor, the second file object of the second file descriptor is copied to the first file object of the first file descriptor;

[0025] Set the second file object to null and close the second file descriptor.

[0026] In some alternative implementations, after determining whether the first file descriptor is an original file descriptor in response to detecting an access operation to the target file initiated through the first file descriptor, the method further includes:

[0027] If it is determined that it is not, obtain the first file object of the first file descriptor;

[0028] The target file is accessed through the first file object.

[0029] Secondly, this disclosure provides a file access device, the device comprising:

[0030] The first determining unit is configured to determine whether the first file descriptor is an original file descriptor in response to detecting an access operation to a target file initiated through the first file descriptor.

[0031] If the determination is not made, the second determining unit is used to determine whether the first file descriptor is a delayed copy file descriptor based on the copy attribute label of the first file descriptor;

[0032] If it is determined that the second file descriptor is associated with the first file descriptor, the third determining unit is used to determine the second file descriptor associated with the first file descriptor based on the original file descriptor label of the first file descriptor.

[0033] The fourth determining unit is used to obtain the second file object corresponding to the second file descriptor and determine the second file object as the first file object corresponding to the first file descriptor;

[0034] An access unit is used to access the target file through the first file object.

[0035] Thirdly, this disclosure provides an electronic device, including:

[0036] One or more processors;

[0037] Storage device, on which one or more programs are stored,

[0038] When the above-described one or more programs are executed by the above-described one or more processors, the above-described one or more processors implement the method as described in any embodiment of the first aspect of this disclosure.

[0039] Fourthly, this disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by one or more processors, implements the method described in any embodiment of the first aspect of this disclosure.

[0040] Fifthly, this disclosure provides a computer program product including a computer program / instructions that, when executed by a processor, implement the method described in any embodiment of the first aspect of this disclosure.

[0041] The file access method provided in the embodiments of this disclosure, in response to detecting an access operation to a target file initiated through a first file descriptor, determines whether the first file descriptor is an original file descriptor; if not, delays copying the file descriptor according to the copy attribute tag of the first file descriptor; if yes, determines a second file descriptor associated with the first file descriptor according to the original file descriptor tag of the first file descriptor; obtains a second file object corresponding to the second file descriptor, and identifies the second file object as the first file object corresponding to the first file descriptor; and accesses the target file through the first file object. By setting an original file descriptor tag, this disclosure ensures that after copying the second file descriptor to generate the first file descriptor, the file object corresponding to the first file descriptor is only obtained when an access operation to the target file is initiated through the first file descriptor. This reduces calls to the fget() function, avoids wasting CPU resources, improves the accuracy of system call performance test results, and enhances the effectiveness and reference value of benchmark tests. Attached Figure Description

[0042] Other features, objects, and advantages of this disclosure will become more apparent from the following detailed description of non-limiting embodiments, taken with reference to the accompanying drawings. The drawings are for illustrative purposes only and are not intended to limit the scope of this disclosure. In the drawings:

[0043] Figure 1 This is a flowchart of an embodiment of the document access method according to this disclosure;

[0044] Figure 2 This is a flowchart of another embodiment of the file access method according to this disclosure;

[0045] Figure 3 This is a flowchart of one embodiment of the document closing operation according to this disclosure;

[0046] Figure 4 This is a schematic diagram of a structure of an embodiment of a file access device according to the present disclosure;

[0047] Figure 5 This is a schematic diagram of the structure of a computer system suitable for implementing embodiments of the present disclosure. Detailed Implementation

[0048] The present disclosure will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.

[0049] It should be noted that, unless otherwise specified, the embodiments and features described in this disclosure can be combined with each other. This disclosure will now be described in detail with reference to the accompanying drawings and embodiments.

[0050] The terms "first," "second," etc., used in this disclosure and its claims are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this disclosure can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, the term "and / or" in the specification and claims is used to describe the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. In embodiments of this disclosure, the term "multiple" refers to two or more, and other quantifiers are similar.

[0051] The file access method provided in this disclosure can be applied to computer devices based on the Linux operating system. The computer devices may include, but are not limited to, any of the following: servers, smartphones, voice recorders, tablet computers, e-book readers, MP3 (Moving Picture Experts Group Audio Layer III) players, MP4 (Moving Picture Experts Group Audio Layer IV) players, laptops, in-vehicle computers, desktop computers, set-top boxes, smart TVs, wearable devices, etc.

[0052] The operating system in this embodiment refers to the Linux operating system. This embodiment does not limit the type of Linux operating system. For example, the Linux operating system may include, but is not limited to, any one of Debian, Ubuntu, CentOS (Community Enterprise Operating System), Tongxin UOS (Tongxin UOS desktop operating system), etc.

[0053] refer to Figure 1 , Figure 1 A flowchart 100 is shown as an embodiment of a file access method according to the present disclosure, the flowchart 100 including at least the following steps 101-105.

[0054] Step 101: In response to detecting an access operation to the target file initiated through the first file descriptor, determine whether the first file descriptor is an original file descriptor.

[0055] In this embodiment, a file descriptor can be a non-negative integer identifier allocated by the operating system kernel to a process, used to represent a file, pipe, socket, or other I / O resource opened by the process.

[0056] For example, a file descriptor can refer to a "number", such as 0 for standard input, 1 for standard output, and 2 for error output.

[0057] The dup() call can refer to an operation used to copy an existing file descriptor. During the call, a new file descriptor is created and shares the same file object as the original file descriptor.

[0058] The target file can refer to the file resource that is to be accessed, as pointed to by the first file descriptor.

[0059] A raw file descriptor can refer to a file descriptor that was not generated through a dup() function call or other copying mechanism.

[0060] In this embodiment, the first file descriptor can refer to the original file descriptor, or it can refer to the operation of copying an existing file descriptor through the dup() function, which generates a new file descriptor during the call process and shares the same file object as the original file descriptor.

[0061] In the steps, in response to the detection that an access operation to the target file needs to be initiated through the first file descriptor, it can be first determined whether the first file descriptor is the original file descriptor, and then it can be decided how to handle the access request.

[0062] Step 102: If not, determine whether the first file descriptor is a delayed copy file descriptor based on the copy attribute label of the first file descriptor.

[0063] In this embodiment, when the first file descriptor is not the original file descriptor, that is, when the first file descriptor is a copy of an existing file descriptor through the dup() function and a new file descriptor is generated during the call process, it can be determined whether the first file descriptor is a delayed copy file descriptor based on the copy attribute label of the first file descriptor.

[0064] The copy attribute tag can be used to identify the type of copy behavior for the first file descriptor, such as whether it is a delayed copy. Delayed copy refers to the behavior where, after the file descriptor copy operation is completed, the new file descriptor is not accessed immediately, but is only used for the first time at a later point in time.

[0065] The delayed copy tag can be used to identify file descriptors that are not accessed immediately after the copy operation is completed, but are used for the first time at a later point in time.

[0066] In some alternative implementations, when the first file descriptor is a delayed copy file descriptor, the location of the first file object of the first file descriptor is not used to store the first file object itself, but can instead store copy attribute tags (e.g., delayed copy tags).

[0067] In the steps, in response to the detection that an access operation to the target file needs to be initiated through the first file descriptor, it can be determined whether a copy attribute tag indicating that the first file descriptor is a delayed copy file descriptor is stored at the location of the first file object of the first file descriptor. If a copy attribute tag is stored, it indicates that the first file descriptor is a delayed copy file descriptor. If no copy attribute tag is stored, the location of the first file object of the first file descriptor may store the first file object itself, indicating that the first file descriptor is not a delayed copy file descriptor.

[0068] Step 103: If confirmed, determine the second file descriptor associated with the first file descriptor based on the original file descriptor label of the first file descriptor.

[0069] In this embodiment, when the copy attribute label indicates that the first file descriptor is a delayed copy file descriptor, that is, when the first file descriptor is determined to be a delayed copy file descriptor, the associated second file descriptor can be determined based on the original file descriptor label carried by the first file descriptor.

[0070] The original file descriptor label is used to identify the original file descriptor corresponding to the first file descriptor. In other words, it is used to identify which original file descriptor the first file descriptor was generated from during the file descriptor copying operation.

[0071] The second file descriptor can refer to the original file descriptor of the first file descriptor, that is, the file descriptor that was copied in the file descriptor copy operation.

[0072] In some alternative implementations, when the first file descriptor is a delayed copy file descriptor, the location of the first file object of the first file descriptor may store not only the copy attribute tag, but also the original file descriptor tag of the first file descriptor (e.g., the original file descriptor). Then, based on the original file descriptor tag, the original file descriptor associated with the first file descriptor is determined as the second file descriptor.

[0073] Step 104: Obtain the second file object corresponding to the second file descriptor, and determine the second file object as the first file object corresponding to the first file descriptor.

[0074] In this embodiment, a file object can refer to a data structure in the operating system kernel used to represent an instance of an open file, such as the struct file (file object structure) in Linux. This data structure records runtime state information such as the file's access mode, current read / write position, and reference count.

[0075] The first file descriptor and the second file descriptor can correspond to the same file object. That is, the first file descriptor and the second file descriptor point to the same open file instance in kernel mode, indicating that they are different ways of referencing the same file or I / O resource.

[0076] Suppose the first file descriptor has file descriptor number 3 and the second file descriptor has file descriptor number 4. Although the first and second file descriptors have different file descriptor numbers, they actually point to the same opened file instance. This means that they share runtime state information such as the file's access permissions, read / write position, and reference count.

[0077] The second file object can refer to an open file instance allocated to the second file descriptor, which is used to manage the access behavior of the second file descriptor to the target file.

[0078] Specifically, the second file object corresponding to the second file descriptor can be obtained by executing the fget() function, and then identified as the first file object.

[0079] If the second file is identified as the first file object corresponding to the first file descriptor, it means that the second file object is the same as the first file object corresponding to the first file descriptor, and that the first file descriptor was copied from the second file descriptor and shares the same file resources with it.

[0080] Step 105: Access the target file through the first file object.

[0081] In this embodiment, after confirming that the second file object is consistent with the first file object corresponding to the first file descriptor, the storage copy attribute tag and the original file descriptor tag stored at the location of the first file object in the first file descriptor can be deleted, and the copy attribute tag and the original file descriptor tag can be replaced with the first file object itself. Then, the access operation to the target file is performed based on the first file object.

[0082] Therefore, before initiating an access operation to the target file through the first file descriptor, the `fget()` function is not immediately called to obtain its corresponding first file object. Instead, the retrieval and binding operation is performed only when the access is actually needed. This delayed binding mechanism can effectively reduce the number of unnecessary `fget()` calls. This avoids wasting CPU resources, improves the accuracy of system call performance test results, and enhances the effectiveness and reference value of benchmark tests.

[0083] refer to Figure 2 , Figure 2 A flowchart 200 is shown as an embodiment of a file access method according to the present disclosure, the flowchart 200 including at least the following steps 201-213.

[0084] Step 201: Perform a copy operation on the second file descriptor to generate the first file descriptor.

[0085] Here, when it is necessary to perform a copy operation on the second file descriptor to generate the first file descriptor, the system can call relevant system interfaces such as dup() to create a new file descriptor (the first file descriptor) that shares the same file object with the original file descriptor (the second file descriptor). That is, the first file descriptor and the second file descriptor correspond to the same file object.

[0086] Step 202: Determine whether to initiate an access operation to the target file through the first file descriptor.

[0087] In this embodiment, after generating the first file descriptor, the system can detect whether there is an access operation to the target file initiated through the first file descriptor.

[0088] If it is determined that the first file descriptor has initiated an access operation to the target file, it means that file access needs to be performed through the first file descriptor, and there is no need to perform delayed copying. At this time, steps 204-205 can be executed. If it is determined that the first file descriptor has not yet initiated an access operation to the target file, it means that the delayed copying mechanism can be used. Before the actual access to the target file through the first file descriptor occurs, the file object can be temporarily not bound, thereby optimizing the efficiency of kernel resource utilization. At this time, step 203 can be executed.

[0089] Step 203: Based on the second file descriptor, generate the original file descriptor label for the first file descriptor, and determine that the first file descriptor is a delayed copy file descriptor.

[0090] In this embodiment, when a delayed copy mechanism needs to be performed on the first file descriptor, an original file descriptor identifier for the first file descriptor can be generated based on the second file descriptor to identify the second file descriptor as the original file descriptor of the first file descriptor. For example, the location of the first file object of the first file descriptor can be used as the original file descriptor label bit to indicate the original file descriptor of the first file descriptor. In other words, when a delayed copy mechanism needs to be applied to the first file descriptor, the first file object itself is not stored at the location of the first file object of the first file descriptor, but the original file descriptor is stored instead.

[0091] Furthermore, the first file descriptor can be identified as a delayed copy file descriptor. That is, before the first file descriptor actually accesses the target file for the first time, the binding operation of the file object can be temporarily suspended until the first file descriptor actually initiates the access to the target file. In this way, the system can skip the redundant resource allocation of unused file descriptors, thereby achieving the goal of optimizing the efficiency of kernel resource utilization.

[0092] Specifically, the first file descriptor can be determined to be a delayed copy file descriptor by setting a copy attribute label. For example, the location of the first file object of the first file descriptor can be used as the copy attribute label bit to indicate whether the first file descriptor is a delayed copy file descriptor. In other words, when the delayed copy mechanism needs to be applied to the first file descriptor, the first file object itself is not stored at the location of the first file object of the first file descriptor, but the file descriptor is delayed copyed.

[0093] In other words, when the delayed copy mechanism needs to be applied to the first file descriptor, the first file object itself is not stored at the location of the first file object in the first file descriptor. Instead, the original file descriptor and the delayed copy file descriptor are stored.

[0094] In some alternative implementations, step 206 can be executed after the delayed copy of the first file descriptor is completed, that is, after step 203, when the actual access to the target file is initiated through the first file descriptor.

[0095] Step 204: Obtain the second file object corresponding to the second file descriptor, and determine the second file object as the first file object corresponding to the first file descriptor.

[0096] If it is determined that the first file descriptor has initiated an access operation to the target file, it means that file access needs to be performed through the first file descriptor. At this time, there is no need to perform a delayed copy operation. The second file object corresponding to the second file descriptor can be obtained directly, and the second file object can be identified as the first file object corresponding to the first file descriptor to complete the binding process of the first file object.

[0097] Step 205: Access the target file through the first file object.

[0098] In this step, after the second file object is determined to be the first file object corresponding to the first file descriptor, the target file can be accessed directly through the first file object, avoiding access errors or performance degradation caused by the delay mechanism.

[0099] Step 206: If an access operation to the target file is detected through the first file descriptor, determine whether the first file descriptor is the original file descriptor.

[0100] Specifically, the implementation method and technical effects of step 206 can be found in the relevant description of step 101, and will not be repeated here.

[0101] If confirmed, proceed to steps 207-208; if confirmed not, proceed to steps 209-212.

[0102] Step 207: Obtain the first file object of the first file descriptor.

[0103] In this embodiment, when the first file descriptor is a raw file descriptor, the first file object of the first file descriptor can be directly obtained to complete the preparation for accessing the target file.

[0104] Step 208: Access the target file through the first file object.

[0105] In this step, after obtaining the first file object of the first file descriptor, the target file can be accessed directly through the first file object.

[0106] Step 209: Determine whether the first file descriptor is a delayed copy file descriptor based on the copy attribute label of the first file descriptor.

[0107] Specifically, the implementation method and technical effects of step 209 can be found in the relevant description of step 102, and will not be repeated here.

[0108] Step 210: Determine the second file descriptor associated with the first file descriptor based on the original file descriptor label of the first file descriptor.

[0109] Specifically, the implementation method and technical effects of step 210 can be found in the relevant description of step 103, and will not be repeated here.

[0110] Step 211: Obtain the second file object corresponding to the second file descriptor, and determine the second file object as the first file object corresponding to the first file descriptor.

[0111] Specifically, the implementation method and technical effects of step 211 can be found in the relevant description of step 104, and will not be repeated here.

[0112] Step 212: Access the target file through the first file object.

[0113] Specifically, the implementation method and technical effects of step 212 can be found in the relevant description of step 105, and will not be repeated here.

[0114] refer to Figure 3 , Figure 3 A flowchart 300 is shown as an embodiment of a file closing operation according to the present disclosure, the flowchart 300 including at least the following steps 301-305.

[0115] In some optional implementations, after generating the original file descriptor label of the first file descriptor and determining that the first file descriptor is a delayed copy file descriptor, that is, after completing the delayed copy of the first file descriptor, the following steps 301-303 may be included.

[0116] Step 301: When a close operation is detected for the first file descriptor, determine whether an access operation for the target file has been performed on the first file descriptor.

[0117] In this embodiment, when the first file descriptor has performed an access operation on the target file, that is, the storage copy attribute tag and the original file descriptor tag stored at the location of the first file object of the first file descriptor have been deleted, and the copy attribute tag and the original file descriptor tag have been replaced with the first file object itself, it indicates that the first file descriptor has been bound to the corresponding file resource. In order to ensure the integrity of resource release, step 302 can be executed to perform the normal file descriptor closing process, first performing the clearing operation of the first file object, and then closing the first file descriptor.

[0118] When the first file descriptor does not perform an access operation on the target file, that is, the storage copy attribute label and the original file descriptor label are stored at the location of the first file object of the first file descriptor, and at this time, the first file descriptor has not yet been bound to any kernel file resources. At this time, step 303 can be executed, and the location of the first file object can be directly set to empty, that is, the first file object is set to empty.

[0119] Step 302: If confirmed, set the first file object to null and close the first file descriptor.

[0120] Step 303: If not, set the first file object to empty.

[0121] In some optional implementations, after generating the original file descriptor label of the first file descriptor and determining that the first file descriptor is a delayed copy file descriptor, that is, after completing the delayed copy of the first file descriptor, the following steps 304-305 may also be included.

[0122] Step 304: When a close operation is detected for the second file descriptor, the second file object of the second file descriptor is copied to the first file object of the first file descriptor.

[0123] Here, since the second file descriptor is the original file descriptor, in order to ensure that the first file descriptor still has the ability to access the target file after the second file descriptor is closed, the second file object corresponding to the second file descriptor can be copied and bound to the first file descriptor before closing the second file descriptor, so as its first file object, thereby completing the transfer and inheritance of resources.

[0124] Step 305: Set the second file object to null and close the second file descriptor.

[0125] In this embodiment, the second file descriptor is bound to the corresponding file resource. To ensure the integrity of resource release, the second file object is cleared and the second file descriptor is closed.

[0126] The file access method provided in the embodiments of this disclosure, in response to detecting an access operation to a target file initiated through a first file descriptor, determines whether the first file descriptor is an original file descriptor; if not, it is a delayed copy file descriptor based on the copy attribute tag of the first file descriptor; if it is, it determines a second file descriptor associated with the first file descriptor based on the original file descriptor tag of the first file descriptor; it obtains a second file object corresponding to the second file descriptor and identifies the second file object as the first file object corresponding to the first file descriptor; and it accesses the target file through the first file object. By setting an original file descriptor tag, this disclosure ensures that after the second file descriptor is copied to generate the first file descriptor, the file object corresponding to the first file descriptor is only obtained when an access operation to the target file is initiated through the first file descriptor. This reduces calls to the fget() function, avoids wasting CPU resources, improves the accuracy of system call performance test results, and enhances the effectiveness and reference value of benchmark tests.

[0127] Further reference Figure 4 As an implementation of the methods shown in the above figures, this disclosure provides an embodiment of a file access device, which is similar to... Figure 2 The illustrated method embodiment corresponds to this. This device can be applied to computer devices based on the Linux operating system.

[0128] like Figure 4 As shown, the file access device 400 of this embodiment includes: a first determining unit 401, a second determining unit 402, a third determining unit 403, a fourth determining unit 404, and an access unit 405. The first determining unit 401 is configured to, in response to detecting an access operation to a target file initiated through a first file descriptor, determine whether the first file descriptor is an original file descriptor; if not, the second determining unit 402 is configured to determine whether the first file descriptor is a delayed copy file descriptor based on the copy attribute tag of the first file descriptor; if yes, the third determining unit 403 is configured to determine a second file descriptor associated with the first file descriptor based on the original file descriptor tag of the first file descriptor; the fourth determining unit 404 is configured to obtain a second file object corresponding to the second file descriptor and determine the second file object as the first file object corresponding to the first file descriptor; the access unit 405 is configured to access the target file through the first file object.

[0129] In some alternative implementations, before detecting an access operation to the target file initiated through the first file descriptor, the apparatus 400 further includes:

[0130] Perform a copy operation on the second file descriptor to generate the first file descriptor, wherein the first file descriptor and the second file descriptor correspond to the same file object;

[0131] Determine whether to initiate an access operation to the target file through the first file descriptor;

[0132] If not, generate the original file descriptor label for the first file descriptor based on the second file descriptor, and determine the first file descriptor as a delayed copy file descriptor.

[0133] In some alternative implementations, after determining whether to initiate an access operation to the target file through the first file descriptor, the apparatus 400 further includes:

[0134] If it is determined, obtain the second file object corresponding to the second file descriptor, and identify the second file object as the first file object corresponding to the first file descriptor;

[0135] Access the target file through the first file object.

[0136] In some alternative implementations, after generating the original file descriptor tag of the first file descriptor based on the second file descriptor and determining that the first file descriptor is a delayed copy file descriptor, the apparatus 400 further includes:

[0137] In response to detecting a close operation on the first file descriptor, determine whether the first file descriptor has performed an access operation on the target file;

[0138] If confirmed, set the first file object to null and close the first file descriptor;

[0139] If you are not sure, set the first file object to empty.

[0140] In some alternative implementations, after generating the original file descriptor tag of the first file descriptor based on the second file descriptor and determining that the first file descriptor is a delayed copy file descriptor, the apparatus 400 further includes:

[0141] In response to detecting a close operation for the second file descriptor, the second file object of the second file descriptor is copied to the first file object of the first file descriptor;

[0142] Set the second file object to null and close the second file descriptor.

[0143] In some alternative implementations, after determining whether the first file descriptor is an original file descriptor in response to detecting an access operation to the target file initiated through the first file descriptor, the apparatus 400 further includes:

[0144] If confirmed, obtain the first file object of the first file descriptor;

[0145] Access the target file through the first file object.

[0146] It should be noted that the implementation details and technical effects of each unit in the file access device provided in the embodiments of this disclosure can be referred to the descriptions of other embodiments in this disclosure, and will not be repeated here.

[0147] The following is for reference. Figure 5 It shows a schematic diagram of the structure of a computer system 500 suitable for implementing the terminal device of this disclosure. Figure 5 The computer system 500 shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of this disclosure.

[0148] like Figure 5 As shown, the computer system 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of the computer system 500. The processing device 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0149] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 508 including, for example, magnetic tapes, hard disks, etc.; and communication devices 509. Communication device 509 allows computer system 500 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 A computer system 500 with various electronic devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0150] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, it performs the functions defined in the methods of embodiments of this disclosure.

[0151] It should be noted that the computer-readable medium described above in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0152] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.

[0153] The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the following functions: Figure 2 The illustrated embodiments and their alternative implementations demonstrate file access methods.

[0154] Computer program code for performing the operations of this disclosure can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and Python, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0155] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0156] The units described in the embodiments of this disclosure can be implemented in software or in hardware. The names of the units are not necessarily limiting in certain circumstances; for example, the first determining unit can also be described as an "original file descriptor determining unit".

[0157] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.

Claims

1. A file access method, characterized in that, The method includes: In response to detecting an access operation to a target file initiated through a first file descriptor, determine whether the first file descriptor is an original file descriptor; If not, determine whether the first file descriptor is a delayed copy file descriptor based on the copy attribute label of the first file descriptor; If so, determine the second file descriptor associated with the first file descriptor based on the original file descriptor label of the first file descriptor; Obtain the second file object corresponding to the second file descriptor, and determine the second file object as the first file object corresponding to the first file descriptor; Access the target file through the first file object; The method further includes, prior to detecting an access operation to the target file initiated through the first file descriptor: Perform a copy operation on the second file descriptor to generate the first file descriptor, wherein the first file descriptor and the second file descriptor correspond to the same file object; Determine whether to initiate an access operation to the target file through the first file descriptor; If not, generate the original file descriptor tag of the first file descriptor based on the second file descriptor, and determine that the first file descriptor is a delayed copy file descriptor; After generating the original file descriptor tag of the first file descriptor based on the second file descriptor, and determining that the first file descriptor is a delayed copy file descriptor, the method further includes: In response to detecting a close operation on the first file descriptor, determine whether the first file descriptor has performed an access operation on the target file; If confirmed, set the first file object to null and close the first file descriptor; If the determination is not correct, set the first file object to empty.

2. The method according to claim 1, characterized in that, After determining whether to initiate an access operation to the target file through the first file descriptor, the method further includes: If it is determined that it is, obtain the second file object corresponding to the second file descriptor, and determine the second file object as the first file object corresponding to the first file descriptor; The target file is accessed through the first file object.

3. The method according to claim 1, characterized in that, After generating the original file descriptor tag of the first file descriptor based on the second file descriptor, and determining that the first file descriptor is a delayed copy file descriptor, the method further includes: In response to detecting a close operation for the second file descriptor, the second file object of the second file descriptor is copied to the first file object of the first file descriptor; Set the second file object to null and close the second file descriptor.

4. The method according to claim 1, characterized in that, After detecting an access operation to a target file initiated through a first file descriptor and determining whether the first file descriptor is an original file descriptor, the method further includes: If confirmed, obtain the first file object of the first file descriptor; The target file is accessed through the first file object.

5. A file access device, characterized in that, The device includes: The first determining unit is configured to determine whether the first file descriptor is an original file descriptor in response to detecting an access operation to a target file initiated through the first file descriptor. If the determination is not made, the second determining unit is used to determine whether the first file descriptor is a delayed copy file descriptor based on the copy attribute label of the first file descriptor; If it is determined that the second file descriptor is associated with the first file descriptor, the third determining unit is used to determine the second file descriptor associated with the first file descriptor based on the original file descriptor label of the first file descriptor. The fourth determining unit is used to obtain the second file object corresponding to the second file descriptor and determine the second file object as the first file object corresponding to the first file descriptor; An access unit is used to access the target file through the first file object; The apparatus further includes, prior to detecting an access operation to the target file initiated through the first file descriptor: Perform a copy operation on the second file descriptor to generate the first file descriptor, wherein the first file descriptor and the second file descriptor correspond to the same file object; Determine whether to initiate an access operation to the target file through the first file descriptor; If not, generate the original file descriptor tag of the first file descriptor based on the second file descriptor, and determine that the first file descriptor is a delayed copy file descriptor; After generating the original file descriptor tag of the first file descriptor based on the second file descriptor, and determining that the first file descriptor is a delayed copy file descriptor, the apparatus further includes: In response to detecting a close operation on the first file descriptor, determine whether the first file descriptor has performed an access operation on the target file; If confirmed, set the first file object to null and close the first file descriptor; If the determination is not correct, set the first file object to empty.

6. An electronic device, characterized in that, include: One or more processors; Storage device, on which one or more programs are stored, When one or more programs are executed by one or more processors, the one or more processors implement the method as described in any one of claims 1-4.

7. A computer-readable storage medium, characterized in that, It stores a computer program thereon, wherein the computer program, when executed by one or more processors, implements the method as claimed in any one of claims 1-4.

8. A computer program product, characterized in that, Includes a computer program / instruction that, when executed by a processor, implements the method as described in any one of claims 1-4.

Citation Information

Patent Citations

  • File identifier management method and device and electronic equipment

    CN115080508A

  • Data access method, device and equipment

    CN117991975A