DETERMINING WHEN TO RELEASE A LOCK FROM A FIRST TASK HOLDING THE LOCK TO GRANT TO A SECOND TASK WAITING FOR THE LOCK
20180011744 · 2018-01-11
Inventors
- Gregg L. Liguori (Hyde Park, NY, US)
- Franklin E. McCune (Tucson, AZ)
- David C. Reed (Tucson, AZ)
- Michael R. Scott (Ocean View, HI, US)
Cpc classification
G06F9/4881
PHYSICS
International classification
Abstract
Provided are a computer program product, system, and method for determining when to release a lock from a first task holding the lock to grant to a second task waiting for the lock. A determination is made as to whether a holding of a lock to the resource by a first task satisfies a condition and whether the lock is swappable. The lock is released from the first task and granted to a second task waiting in a queue for the lock in response to determining that the holding of the lock satisfies the condition and that the lock is swappable. The first task is indicated in the queue waiting for the lock in response to granting the lock to the second task.
Claims
1. A computer program product for managing access to a resource in a computer system, the computer program product comprising a computer readable storage medium having computer readable program code embodied therein that when executed performs operations, the operations comprising: determining whether a holding of a lock to the resource by a first task satisfies a condition and whether the lock is swappable; releasing the lock from the first task and granting the lock to a second task waiting in a queue for the lock in response to determining that the holding of the lock satisfies the condition and that the lock is swappable; and indicating the first task in the queue waiting for the lock in response to granting the lock to the second task.
2. The computer program product of claim 1, wherein the holding of the lock satisfies the condition when the first task holds the lock for a predetermined time.
3. The computer program product of claim 1, wherein the holding of the lock satisfies the condition when the first task holds the lock for a predetermined time when the second task comprises a highest priority task.
4. The computer program product of claim 1, wherein the queue includes a plurality of tasks waiting for the lock, wherein the second task to which the lock is granted is a first waiter in the queue to receive the lock when released, and wherein the first task is added to the queue as the first waiter in the queue to receive the lock when released by the second task.
5. The computer program product of claim 1, wherein the operations further comprise: indicating the lock as swappable when the first task or second task holding the lock is waiting for at least one additional resource while holding the lock that is needed to complete a task operation using the resource; and indicating the lock as unswappable in response to at least one of the first task or second task holding the lock initiating processing of the resource to perform the task operation; the first task or the second task holding the lock changing content of the resource; the first task or the second task holding the lock obtaining access to the at least one additional resource needed to complete the task operation using the resource for which the lock is held; and the first task or the second task holding the lock obtaining at least one lock to the at least one additional resource needed to complete the task operation using the resource for which the lock is held, wherein when the releasing the lock from the first task and the granting the lock to the second task are only performed if the lock is indicated as swappable and not indicated as unswappable.
6. The computer program product of claim 1, wherein the first task holding the lock performs the determining whether the holding the lock satisfies the condition and whether the lock is swappable, wherein the operations further comprise: calling, by the first task, a swap function to cause the releasing of the lock from the first task, the granting of the lock to the second task, and the indicating the first task in the queue waiting for the lock in response to the first task determining that the holding of the lock satisfies the condition and that the lock is swappable.
7. The computer program product of claim 1, wherein a resource manager monitoring tasks accesses to resources and locks to the resources performs the operations of determining whether the holding of the lock satisfies the condition, whether the lock is swappable, the releasing the lock, the granting the lock, and the indicting the first task in the queue waiting for the lock.
8. The computer program product of claim 1, wherein a swap operation comprises the releasing the lock, the granting the lock, and the indicating the first task in the queue waiting for the lock, wherein the holding of the lock does not satisfy the condition if the swap operation has been performed a maximum number of times before the first task has released the lock after completing a task operation using the resource of the lock.
9. The computer program product of claim 1, wherein a swap operation comprises the releasing the lock, the granting the lock, and the indicating the first task in the queue waiting for the lock, wherein the holding of the lock does not satisfy the condition if the swap operation has been performed a maximum number of times to release the lock to grant to a task having a lower priority than the first task before the first task has released the lock after completing a task operation using the resource of the lock.
10. The computer program product of claim 1, wherein the operations further comprise: determining whether the second task in the queue has a higher priority than the first task, wherein the releasing the lock, the granting the lock, and the indicting the first task in the queue waiting for the lock are performed in response to the determining that the holding of the lock satisfies the condition, that the lock is swappable and that the second task in the queue has the higher priority than the first task.
11. The computer program product of claim 1, wherein the determining whether the holding of the lock satisfies the condition comprises determining that the first task has the lock for a predetermined time and additionally determining that the holding of the lock satisfies at least one condition that are members of a set of satisfied conditions consisting of: a swap operation, comprising the releasing the lock, the granting the lock, and the indicating the first task in the queue, having been performed less than a maximum number of times before the first task has released the lock after completing a task operation; the swap operation having been performed less than a maximum number of times to release the lock to grant to a task having a lower priority than the first task before the first task has released the lock after completing the task operation; and that the second task in the queue has a higher priority than the first task holding the lock.
12. A computer program product for managing access to a resource in a computer system, the computer program product comprising a computer readable storage medium having computer readable program code embodied therein that when executed performs operations, the operations comprising: determining whether a lock to the resource has been held by a first task for a predetermined time while the first task waits for at least one additional resource; releasing the lock from the first task and granting the lock to a second task waiting in a queue for the lock in response to determining that the first task has held the lock for the predetermined time while waiting for the at least one additional resource; and indicating the first task in the queue waiting for the lock in response to granting the lock to the second task.
13. The computer program product of claim 12, wherein the waiting for the at least one additional resource comprises waiting for at least one additional lock to the at least one additional resource, wherein the first task requires the lock and the at least one additional lock in order to complete an operation using the resource.
14. A system for managing access to a resource, comprising: a processor; and a computer readable storage medium having computer readable program code embodied therein that when executed by the processor performs operations, the operations comprising: determining whether a holding of a lock to the resource by a first task satisfies a condition and whether the lock is swappable; releasing the lock from the first task and granting the lock to a second task waiting in a queue for the lock in response to determining that the holding of the lock satisfies the condition and that the lock is swappable; and indicating the first task in the queue waiting for the lock in response to granting the lock to the second task.
15. The system of claim 14, wherein the holding of the lock satisfies the condition when the first task holds the lock for a predetermined time.
16. The system of claim 14, wherein the queue includes a plurality of tasks waiting for the lock, wherein the second task to which the lock is granted is a first waiter in the queue to receive the lock when released, and wherein the first task is added to the queue as the first waiter in the queue to receive the lock when released by the second task.
17. The system of claim 14, wherein the operations further comprise: indicating the lock as swappable when the first task or second task holding the lock is waiting for at least one additional resource while holding the lock that is needed to complete a task operation using the resource; and indicating the lock as unswappable in response to at least one of: the first task or second task holding the lock initiating processing of the resource to perform the task operation; the first task or the second task holding the lock changing content of the resource; the first task or the second task holding the lock obtaining access to the at least one additional resource needed to complete the task operation using the resource for which the lock is held; and the first task or the second task holding the lock obtaining at least one lock to the at least one additional resource needed to complete the task operation using the resource for which the lock is held, wherein when the releasing the lock from the first task and the granting the lock to the second task are only performed if the lock is indicated as swappable and not indicated as unswappable.
18. The system of claim 14, wherein a swap operation comprises the releasing the lock, the granting the lock, and the indicating the first task in the queue waiting for the lock, wherein the holding of the lock does not satisfy the condition if the swap operation has been performed a maximum number of times to release the lock to grant to a task having a lower priority than the first task before the first task has released the lock after completing a task operation using the resource of the lock.
19. The system of claim 14, wherein a swap operation comprises the releasing the lock, the granting the lock, and the indicating the first task in the queue waiting for the lock, wherein the holding of the lock does not satisfy the condition if the swap operation has been performed a maximum number of times to release the lock to grant to a task having a lower priority than the first task before the first task has released the lock after completing a task operation using the resource of the lock.
20. A method for managing access to a resource in a computer system, comprising: determining whether a holding of a lock to the resource by a first task satisfies a condition and whether the lock is swappable; releasing the lock from the first task and granting the lock to a second task waiting in a queue for the lock in response to determining that the holding of the lock satisfies the condition and that the lock is swappable; and indicating the first task in the queue waiting for the lock in response to granting the lock to the second task.
21. The method of claim 20, wherein the holding of the lock satisfies the condition when the first task holds the lock for a predetermined time.
22. The method of claim 20, wherein the queue includes a plurality of tasks waiting for the lock, wherein the second task to which the lock is granted is a first waiter in the queue to receive the lock when released, and wherein the first task is added to the queue as the first waiter in the queue to receive the lock when released by the second task.
23. The method of claim 20, further comprising: indicating the lock as swappable when the first task or second task holding the lock is waiting for at least one additional resource while holding the lock that is needed to complete a task operation using the resource; and indicating the lock as unswappable in response to at least one of: the first task or second task holding the lock initiating processing of the resource to perform the task operation; the first task or the second task holding the lock changing content of the resource; the first task or the second task holding the lock obtaining access to the at least one additional resource needed to complete the task operation using the resource for which the lock is held; and the first task or the second task holding the lock obtaining at least one lock to the at least one additional resource needed to complete the task operation using the resource for which the lock is held, wherein when the releasing the lock from the first task and the granting the lock to the second task are only performed if the lock is indicated as swappable and not indicated as unswappable.
24. The method of claim 20, wherein a swap operation comprises the releasing the lock, the granting the lock, and the indicating the first task in the queue waiting for the lock, wherein the holding of the lock does not satisfy the condition if the swap operation has been performed a maximum number of times to release the lock to grant to a task having a lower priority than the first task before the first task has released the lock after completing a task operation using the resource of the lock.
25. The method of claim 20, wherein a swap operation comprises the releasing the lock, the granting the lock, and the indicating the first task in the queue waiting for the lock, wherein the holding of the lock does not satisfy the condition if the swap operation has been performed a maximum number of times to release the lock to grant to a task having a lower priority than the first task before the first task has released the lock after completing a task operation using the resource of the lock.
Description
BRIEF DESCRIPTION OF THE DRAWINGS
[0018]
[0019]
[0020]
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
DETAILED DESCRIPTION
[0027] Described embodiments provide techniques to allow a next waiter in the lock queue to swap positions with the holding task holding the lock when the holding task is not able to obtain all the resources that are required in order to use the resource for which the lock is held to complete task operations. When the waiter task to which the lock is granted completes processing the resource, the lock may then be returned to the task which released the lock which was returned to the lock queue, such as in the position of the first waiter in the lock queue. This prevents a lockout situation, where two different tasks hold locks to resources each of the other tasks needs to proceed, by forcing one of the tasks holding one of the required locks to release the lock so the other task can complete using the resource for which it has the lock and then release the lock for the other task to reacquire and continue with task operations.
[0028]
[0029] The resource 112 may comprise data objects, files in a file system implemented in the operating system 108, database objects, such as tables, rows, columns, tablespaces, etc., applications and functions, storage resources, memory resources, etc. In further embodiments, the resources 112 being serialized by the locks 400 may comprise internal devices to the computing system 100, such as adaptors, storage devices, etc., or external computing resources external to the computing system 100, such as machines, robots, external devices, external storage, etc.
[0030] The operating system 108 may initialize tasks 200 in response to requests from host systems (not shown) that communicate requests to access the resource 112 or in response to application requests from applications executing in the computing system 100.
[0031]
[0032] The task operation 202 may require access to multiple resources 112 and the shared and/or exclusive locks 400 for those resources to complete a task operation 202.
[0033]
[0034]
[0035]
[0036]
[0037] In the described operations of
[0038]
[0039]
[0040] If (at block 806) the time held 416 for the lock 400.sub.i is less than a maximum hold time to release to a highest priority waiter 514 and if (at block 814) the time held 416 is at least the maximum hold time 504 to hold the lock 400.sub.i, then a determination is made (at block 816) whether the first waiter task 200.sub.W1 in the lock queue 116.sub.i has a higher priority than the holder task 200.sub.H. If (at block 816) the first waiter task 200.sub.W1 has a higher priority, then control proceeds to blocks 810 and 812 to perform the swap operation. If (at block 816) the first waiter task 200.sub.W1 has a lower priority and if (at block 818) swapping is only allowed to a higher priority waiter task 200.sub.W1, as indicated in the swap only to higher priority waiter task flag 510, then control ends without swapping. Otherwise, if (at block 818) swapping to a lower priority first waiter task 200.sub.W1 is allowed, then a determination is made (at block 820) as to whether a number of times swap operation performed to swap to lower priority waiter tasks 422 is equal to the maximum number of times swap operation performed for lower priority tasks 508. If (at block 802) the number of swap operations to lower priority tasks 422 is the maximum 508, then control ends as the maximum number of swaps to lower priority waiter tasks has been met. Otherwise, if (at block 820) the maximum number of swaps to lower priority tasks has not occurred, then the number of times swap operation performed to swap to lower priority waiter tasks 422 is incremented (at block 822) and control proceeds to block 810 to perform the swap positions with the lower priority first waiter task 200.sub.W1.
[0041] With the described embodiments, a lock for a resource is prevented from being held beyond a predetermined time by a holding task while the holding task is waiting for at least one additional resource to access before the resource can be used to perform a task operation by the holding task. When the lock is held beyond the predetermined or maximum time and the lock is swappable, then the lock may be released from the holding task and granted to a first waiter task in the lock queue, and the holding task that released the lock is added as the first waiter in the queue so that it may be provided the lock again when the new holder releases so it can access the resource and complete the task operation. Other factors may also be considered before a holding task has its lock swapped, such as whether a maximum number of swap operations have occurred and whether a swap may occur to a lower priority first waiter task in the lock queue.
[0042] The present invention may be a system, a method, and/or a computer program product. The computer program product may include a computer readable storage medium (or media) having computer readable program instructions thereon for causing a processor to carry out aspects of the present invention.
[0043] The computer readable storage medium can be a tangible device that can retain and store instructions for use by an instruction execution device. The computer readable storage medium may be, for example, but is not limited to, an electronic storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. A non-exhaustive list of more specific examples of the computer readable storage medium includes the following: a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanically encoded device such as punch-cards or raised structures in a groove having instructions recorded thereon, and any suitable combination of the foregoing. A computer readable storage medium, as used herein, is not to be construed as being transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission media (e.g., light pulses passing through a fiber-optic cable), or electrical signals transmitted through a wire.
[0044] Computer readable program instructions described herein can be downloaded to respective computing/processing devices from a computer readable storage medium or to an external computer or external storage device via a network, for example, the Internet, a local area network, a wide area network and/or a wireless network. The network may comprise copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. A network adapter card or network interface in each computing/processing device receives computer readable program instructions from the network and forwards the computer readable program instructions for storage in a computer readable storage medium within the respective computing/processing device.
[0045] Computer readable program instructions for carrying out operations of the present invention may be assembler instructions, instruction-set-architecture (ISA) instructions, machine instructions, machine dependent instructions, microcode, firmware instructions, state-setting data, or either source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like, and conventional procedural programming languages, such as the “C” programming language or similar programming languages. The computer readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate arrays (FPGA), or programmable logic arrays (PLA) may execute the computer readable program instructions by utilizing state information of the computer readable program instructions to personalize the electronic circuitry, in order to perform aspects of the present invention.
[0046] Aspects of the present invention are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer readable program instructions.
[0047] These computer readable program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer readable program instructions may also be stored in a computer readable storage medium that can direct a computer, a programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer readable storage medium having instructions stored therein comprises an article of manufacture including instructions which implement aspects of the function/act specified in the flowchart and/or block diagram block or blocks.
[0048] The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process, such that the instructions which execute on the computer, other programmable apparatus, or other device implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
[0049] The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts or carry out combinations of special purpose hardware and computer instructions.
[0050] The computing system 100 of
[0051] As shown in
[0052] Standard Architecture (ISA) bus, Micro Channel Architecture (MCA) bus, Enhanced ISA (EISA) bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnects (PCI) bus.
[0053] Computer system/server 902 typically includes a variety of computer system readable media. Such media may be any available media that is accessible by computer system/server 902, and it includes both volatile and non-volatile media, removable and non-removable media.
[0054] System memory 906 can include computer system readable media in the form of volatile memory, such as random access memory (RAM) 910 and/or cache memory 912. Computer system/server 902 may further include other removable/non-removable, volatile/non-volatile computer system storage media. By way of example only, storage system 913 can be provided for reading from and writing to a non-removable, non-volatile magnetic media (not shown and typically called a “hard drive”). Although not shown, a magnetic disk drive for reading from and writing to a removable, non-volatile magnetic disk (e.g., a “floppy disk”), and an optical disk drive for reading from or writing to a removable, non-volatile optical disk such as a CD-ROM, DVD-ROM or other optical media can be provided. In such instances, each can be connected to bus 908 by one or more data media interfaces. As will be further depicted and described below, memory 906 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
[0055] Program/utility 914, having a set (at least one) of program modules 916, may be stored in memory 906 by way of example, and not limitation, as well as an operating system, one or more application programs, other program modules, and program data. Each of the operating system, one or more application programs, other program modules, and program data or some combination thereof, may include an implementation of a networking environment. The components of the computer 902 may be implemented as program modules 916 which generally carry out the functions and/or methodologies of embodiments of the invention as described herein. The systems of
[0056] Computer system/server 902 may also communicate with one or more external devices 918 such as a keyboard, a pointing device, a display 920, etc.; one or more devices that enable a user to interact with computer system/server 902; and/or any devices (e.g., network card, modem, etc.) that enable computer system/server 902 to communicate with one or more other computing devices. Such communication can occur via Input/Output (I/O) interfaces 922. Still yet, computer system/server 902 can communicate with one or more networks such as a local area network (LAN), a general wide area network (WAN), and/or a public network (e.g., the Internet) via network adapter 924. As depicted, network adapter 924 communicates with the other components of computer system/server 902 via bus 908. It should be understood that although not shown, other hardware and/or software components could be used in conjunction with computer system/server 902. Examples, include, but are not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data archival storage systems, etc.
[0057] The terms “an embodiment”, “embodiment”, “embodiments”, “the embodiment”, “the embodiments”, “one or more embodiments”, “some embodiments”, and “one embodiment” mean “one or more (but not all) embodiments of the present invention(s)” unless expressly specified otherwise.
[0058] The terms “including”, “comprising”, “having” and variations thereof mean “including but not limited to”, unless expressly specified otherwise.
[0059] The enumerated listing of items does not imply that any or all of the items are mutually exclusive, unless expressly specified otherwise.
[0060] The terms “a”, “an” and “the” mean “one or more”, unless expressly specified otherwise.
[0061] Devices that are in communication with each other need not be in continuous communication with each other, unless expressly specified otherwise. In addition, devices that are in communication with each other may communicate directly or indirectly through one or more intermediaries.
[0062] A description of an embodiment with several components in communication with each other does not imply that all such components are required. On the contrary a variety of optional components are described to illustrate the wide variety of possible embodiments of the present invention.
[0063] When a single device or article is described herein, it will be readily apparent that more than one device/article (whether or not they cooperate) may be used in place of a single device/article. Similarly, where more than one device or article is described herein (whether or not they cooperate), it will be readily apparent that a single device/article may be used in place of the more than one device or article or a different number of devices/articles may be used instead of the shown number of devices or programs. The functionality and/or the features of a device may be alternatively embodied by one or more other devices which are not explicitly described as having such functionality/features. Thus, other embodiments of the present invention need not include the device itself.
[0064] The foregoing description of various embodiments of the invention has been presented for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise form disclosed. Many modifications and variations are possible in light of the above teaching. It is intended that the scope of the invention be limited not by this detailed description, but rather by the claims appended hereto. The above specification, examples and data provide a complete description of the manufacture and use of the composition of the invention. Since many embodiments of the invention can be made without departing from the spirit and scope of the invention, the invention resides in the claims herein after appended.