Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.

Commit f44cf19

Browse files
authored
Merge pull request #704 from JuliaGPU/tb/binned_repopulate
Repopulate the pool from freed blocks before allocating.
2 parents d06fea8 + 31916fb commit f44cf19

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/memory/binned.jl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ function pool_alloc(bytes, pid=-1)
234234
end
235235
end
236236

237+
if block === nothing
238+
@pool_timeit "0. repopulate" begin
239+
repopulate()
240+
end
241+
242+
@lock pool_lock begin
243+
if pid != -1 && !isempty(pools_avail[pid])
244+
block = pop!(pools_avail[pid])
245+
end
246+
end
247+
end
248+
237249
if block === nothing
238250
@pool_timeit "1. try alloc" begin
239251
block = actual_alloc(bytes)
@@ -306,15 +318,17 @@ function pool_alloc(bytes, pid=-1)
306318
end
307319

308320
if block !== nothing && pid != -1
309-
@inbounds used = pools_used[pid]
310-
@inbounds avail = pools_avail[pid]
321+
@lock pool_lock begin
322+
@inbounds used = pools_used[pid]
323+
@inbounds avail = pools_avail[pid]
311324

312-
# mark the buffer as used
313-
push!(used, block)
325+
# mark the buffer as used
326+
push!(used, block)
314327

315-
# update pool usage
316-
current_usage = length(used) / (length(avail) + length(used))
317-
pool_usage[pid] = max(pool_usage[pid], current_usage)
328+
# update pool usage
329+
current_usage = length(used) / (length(avail) + length(used))
330+
pool_usage[pid] = max(pool_usage[pid], current_usage)
331+
end
318332
end
319333

320334
return block

0 commit comments

Comments
 (0)