[Chapel Merge] Fix `memThreshold` memory tracking optimization

Branch: refs/heads/main
Revision: e063d68
Author: ronawho
Log Message:

Merge pull request #18480 from ronawho/fix-memtracking

Fix memThreshold memory tracking optimization

[discussed with @gbtitus, full review post-commit]

#18465 optimized memory leak tracking to avoid taking a lock when the real
allocation size is below memThreshold, but there were a few bugs in
the initial implementation.

For cases where the memory layer doesn't support chpl_real_alloc_size
(CHPL_MEM=cstdlib) we weren't handling the unknown size sentinel so we
weren't ever running the free hook, which made it look like we were
leaking all memory. Fix that to run the hook if the "real size" is 0
(the unknown sentinel.)

This was also broken under configurations that separately allocate
arrays (like CHPL_COMM=ugni). For those configs we were taking a comm
layer allocation and trying to ask jemalloc for the size of it, but this
results in mixed allocator calls, which is undefined behavior. Fix that
by making the higher level interface compute the size and passing it in
instead of computing it below the level where we know what allocator
memory came from.

Modified Files:
M runtime/include/chpl-mem-array.h

M runtime/include/chpl-mem-hook.h
M runtime/include/chpl-mem.h
M runtime/include/chplmemtrack.h
M runtime/src/chplmemtrack.c

Compare: https://github.com/chapel-lang/chapel/compare/5f5a7e443784...e063d686e43f