Parallel dynamic memory allocation using a lock-free pop-only FIFO
First Claim
1. A method of allocating memory, the method comprising:
- receiving a first memory allocation request specifying a first amount of memory;
receiving a second memory allocation request simultaneously with the first memory allocation request, wherein the second memory allocation request specifies the first amount of memory;
identifying a first-in first-out buffer (FIFO) node size included in a plurality of different FIFO node sizes based on the first amount of memory;
selecting a first FIFO and a second FIFO based on the FIFO node size, wherein the first FIFO and the second FIFO are each populated with FIFO nodes of the FIFO node size, and at least one of the first FIFO and the second FIFO comprises a lock-free pop-only FIFO;
determining that a first compare-and-swap (CAS) operation succeeded, wherein the first CAS operation swaps a first FIFO head value associated with the first FIFO with a next value of a FIFO node included in the first FIFO;
in response to determining that the first CAS operation succeeded, popping a first FIFO head node associated with the first FIFO head value from the first FIFO to satisfy the first memory allocation request;
determining that a second CAS operation succeeded, wherein the second CAS operation swaps a second FIFO head value associated with the second FIFO with a next value of a FIFO node included in the second FIFO; and
in response to determining that the second CAS operation succeeded, popping a second FIFO head node associated with the second FIFO head value from the second FIFO, simultaneously with the popping of the first FIFO head node, to satisfy the second memory allocation request.
1 Assignment
0 Petitions
Accused Products
Abstract
One embodiment of the present invention sets forth a technique for dynamically allocating memory using one or more lock-free pop-only FIFOs. One or more lock-free FIFOs are populated with FIFO nodes, where each FIFO node represents a memory allocation of a predetermined size. Each particular lock-free FIFO includes memory allocations of a single size. Different lock-free FIFOs may include memory allocations for different sizes to service allocation requests for different size memory allocations. A lock-free mechanism is used to pop FIFO nodes from the FIFO. The use of the lock-free FIFO allows multiple consumers to simultaneously attempt to pop the head FIFO node without first obtaining a lock to ensure exclusive access of the FIFO.
24 Citations
28 Claims
-
1. A method of allocating memory, the method comprising:
-
receiving a first memory allocation request specifying a first amount of memory; receiving a second memory allocation request simultaneously with the first memory allocation request, wherein the second memory allocation request specifies the first amount of memory; identifying a first-in first-out buffer (FIFO) node size included in a plurality of different FIFO node sizes based on the first amount of memory; selecting a first FIFO and a second FIFO based on the FIFO node size, wherein the first FIFO and the second FIFO are each populated with FIFO nodes of the FIFO node size, and at least one of the first FIFO and the second FIFO comprises a lock-free pop-only FIFO; determining that a first compare-and-swap (CAS) operation succeeded, wherein the first CAS operation swaps a first FIFO head value associated with the first FIFO with a next value of a FIFO node included in the first FIFO; in response to determining that the first CAS operation succeeded, popping a first FIFO head node associated with the first FIFO head value from the first FIFO to satisfy the first memory allocation request; determining that a second CAS operation succeeded, wherein the second CAS operation swaps a second FIFO head value associated with the second FIFO with a next value of a FIFO node included in the second FIFO; and in response to determining that the second CAS operation succeeded, popping a second FIFO head node associated with the second FIFO head value from the second FIFO, simultaneously with the popping of the first FIFO head node, to satisfy the second memory allocation request. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
-
-
12. A parallel processing unit, comprising:
-
a memory heap; a first first-in first-out buffer (FIFO) that is populated with a first quantity of FIFO nodes that each represent a portion of memory from the memory heap; a second FIFO that is populated with a second quantity of FIFO nodes that each represent the portion of memory from the memory heap; and a memory allocation engine that is configured to; receive a first memory allocation request specifying a first amount of memory; receive a second memory allocation request simultaneously with the first memory allocation request, wherein the second memory allocation request specifies the first amount of memory; identify a first-in first-out buffer (FIFO) node size included in a plurality of different FIFO node sizes based on the first amount of memory; select the first FIFO and the second FIFO based on the FIFO node size, wherein the first FIFO and the second FIFO are each populated with FIFO nodes of the FIFO node size, and at least one of the first FIFO and the second FIFO comprises a lock-free pop-only FIFO; determine that a first compare-and-swap (CAS) operation succeeded, wherein the first CAS operation swaps a first FIFO head value associated with the first FIFO with a next value of a FIFO node included in the first FIFO; in response to determining that the first CAS operation succeeded, pop a first FIFO head node associated with the first FIFO head value from the first FIFO to satisfy the first memory allocation request; determine that a second CAS operation succeeded, wherein the second CAS operation swaps a second FIFO head value associated with the second FIFO with a next value of a FIFO node included in the second FIFO; and in response to determining that the second CAS operation succeeded, pop a second FIFO head node associated with the second FIFO head value from the second FIFO, simultaneously with the popping of the first FIFO head node, to satisfy the second memory allocation request. - View Dependent Claims (13, 14, 15, 16, 17, 18)
-
-
19. A non-transitory computer-readable storage medium storing instructions that, when executed by a processor, cause the processor to allocate memory, by performing the steps of:
-
receiving a first memory allocation request specifying a first amount of memory; receiving a second memory allocation request simultaneously with the first memory allocation request, wherein the second memory allocation request specifies the first amount of memory; identifying a first-in first-out buffer (FIFO) node size included in a plurality of different FIFO node sizes based on the first amount of memory; selecting a first FIFO and a second FIFO based on the FIFO node size, wherein the first FIFO and the second FIFO are each populated with FIFO nodes of the FIFO node size, and at least one of the first FIFO and the second FIFO comprises a lock-free pop-only FIFO; determining that a first compare-and-swap (CAS) operation succeeded, wherein the first CAS operation swaps a first FIFO head value associated with the first FIFO with a next value of a FIFO node included in the first FIFO; in response to determining that the first CAS operation succeeded, popping a first FIFO head node associated with the first FIFO head value from the first FIFO to satisfy the first memory allocation request; determining that a second CAS operation succeeded, wherein the second CAS operation swaps a second FIFO head value associated with the second FIFO with a next value of a FIFO node included in the second FIFO; and in response to determining that the second CAS operation succeeded, popping a second FIFO head node associated with the second FIFO head value from the second FIFO, simultaneously with the popping of the first FIFO head node, to satisfy the second memory allocation request. - View Dependent Claims (20, 21, 22, 23, 24, 25, 26, 27)
-
-
28. A method of allocating memory, the method comprising:
-
receiving a first memory allocation request specifying a first amount of memory; receiving a second memory allocation request simultaneously with the first memory allocation request, wherein the second memory allocation request specifies the first amount of memory; identifying a first-in first-out buffer (FIFO) node size based on the first amount of memory; selecting a first FIFO and a second FIFO that are each populated with FIFO nodes of the FIFO node size, wherein the first FIFO is configured as a lock-free pop-only FIFO, and wherein the second FIFO is configured as a lock-free FIFO; popping a first FIFO head node from the first FIFO to satisfy the first memory allocation request; and popping a second FIFO head node from the second FIFO, simultaneously with the popping of the first FIFO head node, to satisfy the second memory allocation request.
-
Specification