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

Fix SplittingPool reclaim. #556

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/memory/split.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ end
function pool_alloc(sz)
szclass = size_class(sz)

# round of the block size
# round off the block size
req_sz = sz
roundoff = if szclass == SMALL
SMALL_ROUNDOFF
Expand Down Expand Up @@ -422,12 +422,19 @@ function free(ptr)
end

function reclaim(sz::Int=typemax(Int))
freed = 0
if !isempty(freed)
blocks = Set(freed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because the same block might be twice in the freed list? Or did you just want a lightweight copy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

freed might be modified concurrently (from a finalizer), so I just want a copy re.

if !isempty(freed)
# `freed` may be modified concurrently, so take a copy
blocks = Set(freed)
empty!(freed)
@pool_timeit "$phase.1a repopulate" repopulate(blocks)
@pool_timeit "$phase.1b compact" incremental_compact!(blocks)
end

I guess I decided back then to use a Set because incremental_compact! pops values, but that might have been a relic of past developments (I should probably go through the different uses of containers now that the code has stabilized a bit).

empty!(freed)
repopulate(blocks)
incremental_compact!(blocks)
end

freed_sz = 0
for available in (available_huge, available_large, available_small)
freed >= sz && break
freed += reclaim!(available, sz-freed)
freed_sz >= sz && break
freed_sz += reclaim!(available, sz-freed_sz)
end
return freed
return freed_sz
end

used_memory() = mapreduce(sizeof, +, values(allocated); init=0)
Expand Down