Hard disk access method, device, storage medium and electronic device
By pre-allocating tag resources to the hard disk, the data access problem caused by bad disks under the AHCI controller is solved, and the effect of reducing data cache accumulation, avoiding storage data loss and improving the timeliness of reading and writing data is achieved.
Patent Information
- Application Number
- CN202210090223.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-25
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2042-01-25
AI Technical Summary
Under the AHCI controller, if the accessed hard disk is a bad disk, other normal hard disks cannot be accessed, resulting in large accumulation of data caches, loss of storage data, and delay in reading and writing data.
By allocating tag resources to the hard disk in advance according to the target allocation method, we ensure that the target hard disk can be processed using the free target tag resources when needed, and avoiding the idle tag resources being occupied by bad disks.
It effectively solves the problems of data cache accumulation, storage data loss and read and write data delay caused by bad disks, and improves the timeliness of data access.
Smart Images

Figure CN114443300B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of communications, and in particular, to a hard disk access method, device, storage medium and electronic device. Background Art
[0002] With the rapid development of big data technology and the rapid growth of data, people have deeply realized the value of data. Therefore, research on the reliability, stability and efficiency of data transmission has received much attention.
[0003] In the related art, an AHCI (Advanced Host Controller Interface) controller can be connected to multiple SATA (Serial Advanced Technology Attachment) hard disks. The AHCI controller generally has a maximum of 32 request tags. For a SATA hard disk (Serial Advanced Technology Attachment) under AHCI control, Attachment hard disk, also known as serial port hard disk) IO request, AHCI controller can allocate free tag resources to IO request, and send it to SATA hard disk, and among multiple SATA hard disks under AHCI controller, if SATA hard disk is bad, for example, hard disk with timed out IO request access, 32 tags all send IO request to access the bad disk, and other normal hard disks in the same AHCI controller cannot send IO request due to no tag resources, therefore, IO request of other normal hard disks in the same AHCI controller will be blocked, and wait for obtaining free tag, wherein, it takes tens of seconds to trigger timeout processing for accessing timed out hard disk (for example, Linux kernel triggers timeout processing after 30 seconds by default), and then, during the access period, all IO requests cannot be sent, resulting in large accumulation of data cache, loss of stored data, delay in reading data and slow response.
[0004] There is currently no effective solution to the problem that when the hard disk being accessed is a bad disk, other normal hard disks cannot be accessed, resulting in a large amount of data cache accumulation, storage data loss, and data reading and writing delays. Summary of the invention
[0005] The embodiments of the present invention provide a hard disk access method, device, storage medium and electronic device to at least solve the problem in the related art that when the hard disk being accessed is a bad disk, other normal hard disks cannot be accessed, resulting in a large amount of data cache accumulation, storage data loss, and data reading and writing delays.
[0006] According to one embodiment of the present invention, a hard disk access method is provided, comprising: upon receiving a target request for requesting target processing of a target hard disk, determining whether there is a target tag resource that is pre-allocated to the target hard disk in a target allocation manner and is currently idle; and upon determining that the target tag resource exists, performing the target processing on the target hard disk through the target tag resource.
[0007] In an exemplary embodiment, before determining whether there are idle target label resources pre-allocated to the target hard disk, the method also includes: determining a first number of configured label resources and a second number of hard disks connected to the controller, wherein the hard disks connected to the controller include the target hard disk; and allocating label resources to the hard disk based on the first number and the second number.
[0008] In an exemplary embodiment, allocating label resources to the hard disks based on the first quantity and the second quantity includes: when the first quantity is greater than the second quantity, allocating the first quantity of label resources evenly to each hard disk included in the second quantity of hard disks according to the maximum quantity allowed for even distribution, wherein, if there are remaining unallocated label resources, the remaining unallocated label resources are allocated to some of the hard disks included in the hard disks according to a predetermined allocation method; when the first quantity is greater than the second quantity, allocating the first quantity of label resources to the second quantity of hard disks based on the weight of each hard disk, wherein the number of label resources allocated to each hard disk is greater than or equal to 1; when the first quantity is less than the second quantity, allocating label resources to the hard disks by polling.
[0009] In an exemplary embodiment, allocating label resources to the plurality of hard disks by polling includes: allocating a first sub-number of label resources included in a first number of label resources to a second sub-number of hard disks included in a second number of hard disks, wherein the first sub-number is less than or equal to the first number, and the second sub-number is less than or equal to the first sub-number; in the case where it is determined that hard disks other than the second sub-number of hard disks included in the second number of hard disks need to be processed, polling whether there are free label resources in the label resources pre-allocated to the second sub-number of hard disks, and in the case where it is determined that there are free label resources, allocating the free label resources pre-allocated to the second sub-number of hard disks to the other hard disks.
[0010] In an exemplary embodiment, before evenly allocating the first number of label resources to the second number of hard disks based on the weight of each hard disk, the method further includes: determining the latency requirement of each hard disk; and configuring a corresponding weight for each hard disk based on the latency requirement of each hard disk.
[0011] In an exemplary embodiment, the method further includes: determining a third number of hard disks connected to the controller after an update when it is determined that the number of hard disks connected to the controller is updated; and reallocating label resources to the hard disks based on the first number and the third number.
[0012] In an exemplary embodiment, the method further includes: when it is determined that the number of hard disks connected to the controller is reduced, allocating label resources allocated to the reduced hard disks to one or more hard disks included in the hard disks currently connected to the controller; when it is determined that the number of hard disks connected to the controller is increased, allocating part of the resources included in the label resources allocated to the second number of hard disks to one or more hard disks included in the increased hard disks.
[0013] In an exemplary embodiment, after the target processing is performed on the target hard disk through the target tag resource, the method further includes: after determining that the target processing is completed, setting the state of the target tag resource to idle.
[0014] In an exemplary embodiment, after performing the target processing on the target hard disk through the target tag resource, the method further includes: when it is determined that the target tag resource does not exist, performing a waiting operation until the target tag resource appears; and performing the target processing on the target hard disk through the target tag resource.
[0015] According to another embodiment of the present invention, a hard disk access device is provided, comprising: a judgment module for judging whether there is a target label resource that is pre-allocated to the target hard disk according to a target allocation method and is currently idle when a target request for requesting target processing of the target hard disk is received; and a first execution module for executing the target processing on the target hard disk through the target label resource when it is determined that the target label resource exists.
[0016] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any one of the above method embodiments when run.
[0017] According to yet another embodiment of the present invention, there is provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0018] Through the present invention, corresponding label resources can be allocated to the hard disk in advance according to the target allocation method, and then when the target hard disk needs to be processed, the idle target label resources pre-allocated to the target hard disk can be used to perform target processing on the target hard disk, thereby avoiding the situation where all idle label resources are occupied by bad disks and normal hard disks cannot be accessed, and the problem existing in the related technology that when the hard disk being accessed is a bad disk, other normal hard disks cannot be accessed, thereby causing a large amount of data cache accumulation, storage data loss, and read and write data delays is effectively solved, thereby achieving the effect of reducing the large amount of data cache accumulation, avoiding storage data loss, and improving the timeliness of reading and writing data. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 is a schematic diagram of an AHCI controller storage solution in the related art;
[0020] Figure 2 It is a flow chart of AHCI controller processing IO request in related technology;
[0021] Figure 3 It is a hardware structure block diagram of a mobile terminal of a hard disk access method according to an embodiment of the present invention;
[0022] Figure 4 is a flow chart of a hard disk access method according to an embodiment of the present invention;
[0023] Figure 5 It is a flowchart of a solution for allocating tag resources to a hard disk according to a specific embodiment of the present invention;
[0024] Figure 6 It is a flowchart of issuing an IO request for a hard disk tag resource allocation solution according to a specific embodiment of the present invention;
[0025] Figure 7 is a structural block diagram of a hard disk access device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with the embodiments.
[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0028] First, the related technologies involved in the present invention are described:
[0029] Figure 1 Schematic diagram of AHCI controller storage solution in related art, such as Figure 1 As shown, this hardware solution is a common AHCI controller storage solution. The AHCI controller is connected to a PM (Port Multiplier) chip, and the PM chip is connected to N SATA hard disks.
[0030] Figure 2 It is a flowchart of the AHCI controller processing IO request in the related art, such as Figure 2 As shown, the process includes the following steps:
[0031] S202, when the AHCI controller receives an IO (input / output) request, it needs to obtain an idle tag resource;
[0032] S204, the AHCI controller performs processing on the corresponding target SATA hard disk based on the IO request;
[0033] S206, after the above processing is completed, the target SATA hard disk notifies the AHCI controller of a response indicating the completion of the processing;
[0034] S208: The AHCI controller determines the completed specific IO request according to the tag resource, and releases the corresponding tag resource.
[0035] The following describes how the present invention solves the problems existing in the prior art in conjunction with embodiments:
[0036] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 3 FIG. 1 is a hardware structure block diagram of a mobile terminal of a hard disk access method according to an embodiment of the present invention. Figure 3 As shown, the mobile terminal may include one or more ( Figure 3 Only one is shown in the figure) a processor 302 (the processor 302 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 304 for storing data, wherein the mobile terminal may also include a transmission device 306 and an input / output device 308 for communication functions. It can be understood by those skilled in the art that Figure 3 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 3 More or fewer components as shown, or with Figure 3Different configurations shown.
[0037] The memory 304 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the hard disk access method in the embodiment of the present invention. The processor 302 executes various functional applications and data processing by running the computer program stored in the memory 304, that is, to implement the above method. The memory 304 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 304 may further include a memory remotely arranged relative to the processor 302, and these remote memories can be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0038] The transmission device 306 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 306 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 306 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0039] In this embodiment, a hard disk access method is provided, such as Figure 4 As shown, the method comprises the following steps:
[0040] S402, when receiving a target request for requesting target processing of a target hard disk, determining whether there is a target tag resource that is pre-allocated to the target hard disk according to a target allocation method and is currently idle;
[0041] S404: When it is determined that the target tag resource exists, execute the target processing on the target hard disk through the target tag resource.
[0042] The operations above may be performed by a controller, such as an AHCI controller, or a device with control capabilities, or other processing devices or processing units with similar processing capabilities. The following takes the controller performing the operations above as an example (only an exemplary description, in actual operation, other devices or modules may also be used to perform the operations above):
[0043] In the above embodiment, the controller can receive a target request and determine, based on the target request, whether there are idle target tag resources that can be pre-allocated to the target hard disk according to the target allocation method, wherein there can be multiple target allocation methods and they can be predetermined or adjusted according to actual application conditions. For example, the tag resources can be allocated to the corresponding hard disks according to the tag information carried by all the target tag resources themselves. For example, tag resources with tags 1-3 are allocated to the first hard disk, and tag resources with tags 4-6 are allocated to the second hard disk, wherein the tag information carried by the target tag resources is 1, and the corresponding target hard disk can recognize the tag information and pair with it. Of course, the tag information can be in multiple forms, and using numbers as tag identifiers is only an illustrative example.
[0044] In the above embodiment, the target request can be an IO request. After receiving the IO request, the controller can allocate an idle target tag resource to the IO request, and then access the corresponding target hard disk based on the target tag resource, wherein the target processing can be to read the data stored in the corresponding target hard disk based on the target tag resource, or to update the data stored in the corresponding target hard disk based on the target tag resource, or to write new data to the corresponding target hard disk based on the target tag resource, and so on.
[0045] In the above embodiment, corresponding label resources can be allocated to the hard disk in advance according to the target allocation method, and then when the target hard disk needs to be processed, the idle target label resources pre-allocated to the target hard disk can be used to perform target processing on the target hard disk, thereby avoiding the situation where all idle label resources are occupied by bad disks and normal hard disks cannot be accessed, effectively solving the problem in the related technology that when the hard disk being accessed is a bad disk, other normal hard disks cannot be accessed, resulting in a large amount of data cache accumulation, storage data loss, and delays in reading and writing data, thereby achieving the effect of reducing the large amount of data cache accumulation, avoiding storage data loss, and improving the timeliness of reading and writing data.
[0046] In an exemplary embodiment, before determining whether there are idle target label resources pre-allocated to the target hard disk, the method further includes: determining a first number of configured label resources and a second number of hard disks connected to the controller, wherein the hard disks connected to the controller include the target hard disk; and allocating label resources to the hard disk based on the first number and the second number. In this embodiment, the number of label resources that can be used by the controller and the number of hard disks connected to the controller can both be multiple, and then certain label resources can be allocated to some or all of the hard disks, wherein the label resources allocated to each hard disk can be used only by the hard disk, or only by the hard disk most of the time, thereby avoiding the problem that all label resources are occupied by bad disks, resulting in the inaccessibility of normal hard disks.
[0047] In an exemplary embodiment, allocating label resources to the hard disks based on the first quantity and the second quantity includes: when the first quantity is greater than the second quantity, allocating the first quantity of label resources evenly to each hard disk included in the second quantity of hard disks according to the maximum quantity allowed for even distribution, wherein, if there are remaining unallocated label resources, the remaining unallocated label resources are allocated to some of the hard disks included in the hard disks according to a predetermined allocation method; when the first quantity is greater than the second quantity, allocating the first quantity of label resources to the second quantity of hard disks based on the weight of each hard disk, wherein the number of label resources allocated to each hard disk is greater than or equal to 1; when the first quantity is less than the second quantity, allocating label resources to the hard disks by polling. In this embodiment, when the first number of label resources are evenly distributed to the second number of hard disks, the label resources allocated to each hard disk can be determined based on the ratio of the first number to the second number. Of course, there may be a situation where the ratio is not an integer. For example, the ratio is 3.2. In this case, 3.2 can be rounded down to 3, that is, 3 label resources are first allocated to each hard disk, and the remaining resources are then allocated. The remaining resources can be allocated in order from small to large according to the hard disk numbers. Of course, they can also be allocated in other ways, for example, in order from large to small according to the hard disk numbers, or according to the weights of the hard disks.
[0048] In the above embodiment, the weight of the hard disk can be determined based on the resource allocation priority of the hard disk. For example, if there is a hard disk that needs priority allocation of resources, it means that the weight of the hard disk is relatively large, wherein the resource allocation priority of the hard disk can be pre-configured, or determined based on the performance of the hard disk itself or the type and importance of the data stored in the hard disk. In addition, when allocating tag resources to the hard disk by polling, part or all of the tag resources in the first number can be allocated to the tag resources with large weights based on the weight of each hard disk. When it is necessary to access a hard disk to which no tag resources are allocated, it can be determined by polling whether there are currently idle tag resources that can be temporarily allocated to the hard disk.
[0049] In an exemplary embodiment, allocating label resources to the plurality of hard disks by polling includes: allocating a first sub-number of label resources included in the first number of label resources to a second sub-number of hard disks included in the second number of hard disks, wherein the first sub-number is less than or equal to the first number, and the second sub-number is less than or equal to the first sub-number; in the case where it is determined that other hard disks other than the second sub-number of hard disks included in the second number of hard disks need to be processed, polling whether there are free label resources in the label resources pre-allocated to the second sub-number of hard disks, and in the case where it is determined that there are free label resources, allocating the free label resources pre-allocated to the second sub-number of hard disks to the other hard disks. In this embodiment, when it is necessary to access a hard disk to which a label resource is not allocated, it can be determined by polling whether there are free label resources (which can be unallocated label resources or label resources that have been allocated to a hard disk but are not currently used), and in the case where it is determined that there are free label resources, the free label resources can be temporarily borrowed to access the hard disk. Among them, after completing the processing, the above-mentioned second number of hard disks will release the corresponding label resources and feedback the identifier of the label resource to the controller. Based on the identifier, the controller can determine which hard disk's request has been processed, and then determine which label resources are in an idle state.
[0050] In an exemplary embodiment, before evenly distributing the first number of label resources to the second number of hard disks based on the weight of each hard disk, the method further includes: determining the latency requirement of each hard disk; and configuring a corresponding weight for each hard disk based on the latency requirement of each hard disk. In this embodiment, in addition to determining the weight of each hard disk based on the latency requirement of each hard disk, the weight of each hard disk can also be determined based on the high performance requirement of each hard disk. For example, if there is a hard disk that requires data caching to cache quickly and read and write data quickly, and the system responds quickly, the corresponding label resources can be preferentially allocated to the hard disk based on this requirement, or multiple label resources can be allocated to the hard disk with this requirement.
[0051] In an exemplary embodiment, the method further includes: determining a third number of hard disks connected to the controller after the update when it is determined that the number of hard disks connected to the controller is updated; and reallocating label resources to the hard disks based on the first number and the third number. In this embodiment, the number of hard disks connected to the controller can be increased or decreased according to actual needs. For example, when the demand for data storage increases, some hard disks used to store data can be appropriately increased. When the demand for data storage decreases, or when some hard disks have not been accessed for a long time, some hard disks connected to the controller can be appropriately reduced. In addition, the original hard disk can be updated according to actual needs. For example, when there is a bad disk or a hard disk with poor hard disk parameters such as capacity and performance, it can be updated to a hard disk with relatively high parameters. Of course, in actual situations, there may be other situations where the hard disk needs to be adjusted.
[0052] In an exemplary embodiment, the method further includes: when it is determined that the number of hard disks connected to the controller is reduced, allocating the label resources allocated to the reduced hard disks to one or more hard disks included in the hard disks currently connected to the controller; when it is determined that the number of hard disks connected to the controller is increased, allocating part of the resources included in the label resources allocated to the second number of hard disks to one or more hard disks included in the increased hard disks. In this embodiment, part of the free resources included in the label resources allocated to the second number of hard disks can be allocated to the increased one or more hard disks.
[0053] In an exemplary embodiment, after the target processing is performed on the target hard disk through the target tag resource, the method further includes: after determining that the target processing is completed, setting the state of the target tag resource to idle. In this embodiment, after the target hard disk completes the corresponding processing, the corresponding tag resource is released, and the released tag resource enters the idle state. The hard disk can feed back the identifier of the corresponding tag resource to the controller, and the controller can determine which hard disk has completed the request based on the identifier of the tag resource, and then determine which tag resources are in the idle state.
[0054] In an exemplary embodiment, after performing the target processing on the target hard disk through the target label resource, the method further includes: when it is determined that the target label resource does not exist, performing a waiting operation until the target label resource appears; performing the target processing on the target hard disk through the target label resource. In this embodiment, if there are no idle target label resources, the number of target hard disks with small weights or low priorities that have been allocated target label resources can be reduced according to actual application conditions, and the label resources of the reduced target hard disks can be allocated to the hard disks waiting for the allocation of label resources.
[0055] Obviously, the above-described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.
[0056] The present invention will be specifically described below in conjunction with specific embodiments:
[0057] Figure 5 5 is a flowchart of a solution for allocating tag resources to a hard disk according to a specific embodiment of the present invention. As shown in FIG. 5 , the process includes the following steps:
[0058] S502, first obtain the number of tag resources (corresponding to the above-mentioned label resources) of the AHCI storage controller in the system, wherein the number of free tag resources can represent the number of IO requests that the AHCI controller can support to be processed concurrently;
[0059] S504, obtaining the number of SATA hard disks connected to the AHCI storage controller in the current system;
[0060] S506, allocate a certain number of free tag resources to each SATA hard disk, which can be evenly allocated. For example, if the AHCI controller supports M tags and N SATA hard disks are connected, then the number of free tag resources allocated to each SATA hard disk is M / N. If it is not divisible, the excess tag resources are allocated one by one according to the hard disk serial number.
[0061] In addition, if the SATA hard disk under the AHCI controller is unplugged or newly connected, the dynamic allocation of SATA hard disk tag resources can be triggered again;
[0062] It should be noted that the average allocation of tag resources is only one of the allocation strategies. In addition, the strategy of dynamically setting the priority can also be supported. For high-priority SATA hard disks, more free tag resources can be allocated according to the priority weight (that is, the weight of the hard disk mentioned above). For low-priority SATA hard disks, the number of free tag resources allocated can be reduced. However, at least one free tag resource must be guaranteed for each hard disk.
[0063] The priority strategy allocates tag resources (i.e., allocates tag resources according to the weight of the hard disks mentioned above). You can define the priority of each hard disk. For example, there are currently 3 SATA hard disks, the priority of hard disk 1 is set to 1, the priority of hard disk 2 is 4, and the priority of hard disk 3 is 3. The tag resource allocation can be:
[0064] Hard disk 1: 1 / (1+4+3)*32tag=4 tags
[0065] Hard disk 2: 4 / (1+4+3)*32tag=16 tags
[0066] Hard disk No. 3: 3 / (1+4+3)*32tag=12 tags
[0067] If the number is not divisible evenly, you can give priority to taking integers. After allocating tag resources to all hard disks, if there are still remaining tag resources, you can allocate the excess tag resources one by one according to the hard disk serial number, but also ensure that at least each hard disk has one free tag resource. Therefore, for the IO business on some hard disks that requires low latency and high performance, you can appropriately increase the priority of hard disk tag resource allocation.
[0068] When the number of hard disks exceeds 32 and it cannot be guaranteed that each hard disk has a tag resource, a polling strategy for tag resource allocation can be adopted. For example, there are 36 hard disks. First, a tag resource is allocated to each of the 32 hard disks. The remaining 4 hard disks wait for free tag resources. When IO requests are completed in the 32 hard disks and the tag resources are released, the remaining 4 hard disks are given priority to obtain tag resources. And so on, polling is used to obtain tag resources in turn. Among them, the hard disk that has obtained the tag resource cannot obtain the tag resource again if the tag resource is not released, thereby ensuring that the IO of the hard disks with excess tag resources can be accessed normally.
[0069] Figure 66 is a flowchart of issuing an IO request for a hard disk tag resource allocation solution according to a specific embodiment of the present invention. As shown in FIG. 6 , the process includes the following steps:
[0070] S602, the AHCI controller driver receives a read / write IO request and sends it;
[0071] S604, determining whether the target SATA hard disk corresponding to the IO request has idle tag resources;
[0072] S606, if the target SATA hard disk still has idle tag resources (corresponding to the above-mentioned tag resources), then the tag resources are acquired, and then an IO request is issued through the AHCI controller;
[0073] S608, if the target SATA hard disk has no idle tag resources, then block and wait, release the tag resources after the IO request issued by the target SATA hard disk is processed, and then wake up the blocked IO to obtain the tag resources and send them down.
[0074] As can be seen from the foregoing embodiments, the present invention proposes a method in an embodiment of the present invention for an erroneous disk with IO abnormality under an AHCI controller, for example, a hard disk with IO access timeout. The application of this method will not affect the allocation of idle tag resources of other normal SATA disks, nor will it affect the hard disk processing of the IO request sent to the normal SATA disk. The entire device system does not have a series of problems caused by the blockage of all IO requests that cannot be issued, such as data cache accumulation, slow system response, storage data loss, and crashes in severe cases. In addition, the embodiments of the present invention also achieve the following purposes:
[0075] A request distribution scheme under an AHCI controller is implemented. The scheme allocates corresponding tag resources to each hard disk by acquiring the number of tag resources of the AHCI controller in the system and the number of hard disks connected to the controller. When multiple hard disks are connected to the AHCI controller, if a hard disk is broken, for example, a timed-out hard disk, the influence range of the broken disk can be controlled by adopting the present invention, that is, the reading and writing issuance of normal disk IO requests is not affected, thereby achieving isolation of IO request risks.
[0076] Dynamic allocation of tag resources is implemented. When a hard disk is removed or inserted in the system, that is, when the number of hard disks is changed, the number of free tag resources of each hard disk can be dynamically reallocated. The strategy for allocating free tag resources to each hard disk includes but is not limited to:
[0077] When the number of tag resources is greater than the number of hard disks connected to the controller, an average allocation strategy can be used to allocate resources based on the priority of each hard disk (that is, based on the weight of each hard disk).
[0078] When the number of tag resources is less than the number of hard disks connected to the controller, a polling allocation strategy can be used to ensure that each hard disk can obtain tag resources.
[0079] By dynamically allocating tag resources, the application effectively solves the problems of uneven tag resource distribution, large accumulation of data cache, storage data loss, delays in reading and writing data, and slow system response, further improving the utilization efficiency of tag resources.
[0080] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0081] In this embodiment, a hard disk access device is also provided, which is used to implement the above embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0082] Figure 7 is a structural block diagram of a hard disk access device according to an embodiment of the present invention. Figure 7 As shown, the device comprises:
[0083] The judging module 72 is used to judge whether there is a target label resource that is pre-allocated to the target hard disk according to the target allocation mode and is currently idle when receiving a target request for requesting target processing of the target hard disk;
[0084] The first execution module 74 is configured to execute the target processing on the target hard disk through the target tag resource when it is determined that the target tag resource exists.
[0085] In an exemplary embodiment, the apparatus further comprises:
[0086] A first determination module, configured to determine a first number of configured label resources and a second number of hard disks connected to the controller before determining whether there are idle target label resources pre-allocated for the target hard disk, wherein the hard disks connected to the controller include the target hard disk;
[0087] A first allocation module is configured to allocate label resources to the hard disk based on the first quantity and the second quantity.
[0088] In an exemplary embodiment, the first allocation module comprises:
[0089] a first allocating unit, configured to, when the first number is greater than the second number, evenly allocate the first number of label resources to each hard disk included in the second number of hard disks according to a maximum number allowed for even allocation, wherein, when there are remaining unallocated label resources, the remaining unallocated label resources are allocated to part of the hard disks included in the hard disks according to a predetermined allocation method;
[0090] A second allocating unit, configured to allocate the first number of label resources to the second number of hard disks based on a weight of each of the hard disks when the first number is greater than the second number, wherein the number of label resources allocated to each of the hard disks is greater than or equal to 1;
[0091] A third allocation unit is configured to allocate label resources to the hard disk in a polling manner when the first quantity is smaller than the second quantity.
[0092] In an exemplary embodiment, the third allocation unit comprises:
[0093] A first allocating subunit is configured to allocate a first sub-number of label resources included in the first number of label resources to a second sub-number of hard disks included in the second number of hard disks, wherein the first sub-number is less than or equal to the first number, and the second sub-number is less than or equal to the first sub-number;
[0094] The second allocation sub-unit is used to poll whether there are free label resources in the label resources pre-allocated to the second sub-number of hard disks when it is determined that hard disks other than the second sub-number of hard disks included in the second number of hard disks need to be processed, and if it is determined that there are free label resources, allocate the free label resources pre-allocated to the second sub-number of hard disks to the other hard disks.
[0095] In an exemplary embodiment, the above device further comprises:
[0096] A second determination module, configured to determine a latency requirement of each hard disk before evenly allocating the first number of label resources to the second number of hard disks based on the weight of each hard disk;
[0097] A configuration module is used to configure a corresponding weight for each hard disk based on the latency requirement of each hard disk.
[0098] In an exemplary embodiment, the above device further comprises:
[0099] A third determining module, configured to determine an updated third number of hard disks connected to the controller when it is determined that the number of hard disks connected to the controller is updated;
[0100] The second allocation module is used to reallocate label resources to the hard disk based on the first quantity and the third quantity.
[0101] In an exemplary embodiment, the above device further comprises:
[0102] A third allocation module is used to allocate the label resources allocated to the reduced hard disks to one or more hard disks included in the hard disks currently connected to the controller when it is determined that the number of hard disks connected to the controller is reduced;
[0103] The fourth allocation module is used to allocate part of the resources included in the label resources allocated to the second number of hard disks to one or more hard disks included in the added hard disks when it is determined that the number of hard disks connected to the controller increases.
[0104] In an exemplary embodiment, the above device further comprises:
[0105] The fourth determination module is used to set the state of the target tag resource to idle after executing the target processing on the target hard disk through the target tag resource and determining that the target processing is completed.
[0106] In an exemplary embodiment, the above device further comprises:
[0107] a fifth determining module, configured to, after executing the target processing on the target hard disk through the target tag resource, if it is determined that the target tag resource does not exist, perform a waiting operation until the target tag resource appears;
[0108] The second execution module is used to execute the target processing on the target hard disk through the target tag resource.
[0109] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0110] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0111] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0112] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0113] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0114] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0115] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0116] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A hard disk access method, characterized in that: include: In case of receiving a target request for requesting target processing of a target hard disk, determining whether there is a target tag resource that is pre-allocated to the target hard disk according to a target allocation method and is currently idle, wherein the target hard disk includes a Serial Advanced Technology Attachment (SATA) hard disk; In the case where it is determined that the target tag resource exists, the target processing is performed on the target hard disk through the target tag resource.
2. The method according to claim 1, characterized in that Before determining whether there is an idle target tag resource pre-allocated to the target hard disk, the method further includes: Determine a first number of configured label resources and a second number of hard disks connected to a controller, wherein the hard disks connected to the controller include the target hard disk; Label resources are allocated to hard disks connected to the controller based on the first quantity and the second quantity.
3. The method according to claim 2, characterized in that Allocating label resources to the hard disks connected to the controller based on the first quantity and the second quantity includes: In the case where the first number is greater than the second number, the first number of label resources are evenly distributed to each hard disk included in the second number of hard disks connected to the controller according to the maximum number allowed for even distribution, wherein, in the case where there are remaining unallocated label resources, the remaining unallocated label resources are allocated to part of the hard disks included in the hard disks connected to the controller according to a predetermined allocation method; In a case where the first number is greater than the second number, allocating the first number of label resources to the second number of hard disks connected to the controller based on the weight of each hard disk connected to the controller, wherein the number of label resources allocated to each hard disk connected to the controller is greater than or equal to 1; When the first number is smaller than the second number, label resources are allocated to the hard disks connected to the controller in a polling manner.
4. The method according to claim 3, characterized in that Allocating label resources to multiple hard disks connected to the controller in a polling manner includes: Allocating a first sub-number of label resources included in the first number of label resources to a second sub-number of hard disks included in a second number of hard disks connected to the controller, wherein the first sub-number is less than or equal to the first number, and the second sub-number is less than or equal to the first sub-number; When it is determined that hard disks other than the second sub-number of hard disks included in the second number of hard disks connected to the controller need to be processed, poll whether there are free label resources in the label resources pre-allocated to the second sub-number of hard disks; if it is determined that there are free label resources, allocate the free label resources pre-allocated to the second sub-number of hard disks to the other hard disks.
5. The method according to claim 3, characterized in that: Before evenly allocating the first number of label resources to the second number of hard disks connected to the controller based on the weight of each hard disk connected to the controller, the method further includes: Determining a latency requirement for each hard disk connected to the controller; A corresponding weight is configured for each hard disk connected to the controller based on a latency requirement of each hard disk connected to the controller.
6. The method according to claim 2, characterized in that The method further comprises: In the case where it is determined that the number of hard disks connected to the controller is updated, determining an updated third number of hard disks connected to the controller; Label resources are reallocated to hard disks connected to the controller based on the first quantity and the third quantity.
7. The method according to claim 2, characterized in that The method further comprises: In the case where it is determined that the number of hard disks connected to the controller is reduced, allocating the label resources allocated to the reduced hard disks to one or more hard disks included in the hard disks currently connected to the controller; When it is determined that the number of hard disks connected to the controller increases, part of the resources included in the label resources allocated to the second number of hard disks connected to the controller are allocated to one or more hard disks included in the increased hard disks.
8. The method according to claim 1, characterized in that After performing the target processing on the target hard disk through the target tag resource, the method further includes: After determining that the target processing is completed, the state of the target tag resource is set to idle.
9. The method according to claim 1, characterized in that: After performing the target processing on the target hard disk through the target tag resource, the method further includes: When it is determined that the target tag resource does not exist, performing a waiting operation until the target tag resource appears; The target processing is performed on the target hard disk through the target tag resource.
10. A hard disk access device, characterized in that: include: a determination module, configured to determine, upon receiving a target request for requesting target processing of a target hard disk, whether there is a target tag resource that is pre-allocated to the target hard disk in a target allocation manner and is currently idle, wherein the target hard disk includes a Serial Advanced Technology Attachment (SATA) hard disk; The first execution module is used to execute the target processing on the target hard disk through the target tag resource when it is determined that the target tag resource exists.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 9 when executed by a processor.
12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method described in any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
TLP field resource management method and device, computer equipment and storage medium
CN109710411A
NVME hard disk storage space allocation method and device and storage medium
CN112269542A