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

Fix usage discrepancies #654

Merged
merged 2 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
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
16 changes: 2 additions & 14 deletions src/memory/binned.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,26 +410,14 @@ function free(ptr)
return
end

function used_memory()
sz = 0
@lock pool_lock for (pid, pl) in enumerate(pools_used)
bytes = poolsize(pid)
sz += bytes * length(pl)
end

return sz
end
used_memory() = @lock allocated_lock mapreduce(sizeof, +, values(allocated); init=0)

function cached_memory()
sz = 0
sz = @lock freed_lock mapreduce(sizeof, +, freed; init=0)
@lock pool_lock for (pid, pl) in enumerate(pools_avail)
bytes = poolsize(pid)
sz += bytes * length(pl)
end
@lock freed_lock for block in freed
sz += sizeof(block)
end

return sz
end

Expand Down
6 changes: 5 additions & 1 deletion src/memory/simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ end

used_memory() = @lock allocated_lock mapreduce(sizeof, +, values(allocated); init=0)

cached_memory() = @lock(pool_lock, @lock(freed_lock, mapreduce(sizeof, +, union(pool, freed); init=0)))
function cached_memory()
sz = @lock freed_lock mapreduce(sizeof, +, freed; init=0)
sz += @lock pool_lock mapreduce(sizeof, +, pool; init=0)
return sz
end

end
8 changes: 7 additions & 1 deletion src/memory/split.jl
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ end

used_memory() = @lock allocated_lock mapreduce(sizeof, +, values(allocated); init=0)

cached_memory() = @lock(pool_lock, @lock(freed_lock, mapreduce(sizeof, +, union(pool_small, pool_large, pool_huge, freed); init=0)))
function cached_memory()
sz = @lock freed_lock mapreduce(sizeof, +, freed; init=0)
@lock pool_lock for pool in (pool_small, pool_large, pool_huge)
sz += mapreduce(sizeof, +, pool; init=0)
end
return sz
end

end