Bruce,
I made the following change to my GC_allochblk_nth() function - it crashes whenever I run with that change.
Heres what happens and a backtrace - it is followed by a section of GC_allochblk_nth() where I made the modification.
(lldb) run
run
There is a running process, kill it and restart?: [Y/n] y
y
Process 70812 launched: '/Users/meister/Development/cando/clasp/build/cando.app/Contents/MacOS/clasp_boehm_d' (x86_64)
Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS
Process 70812 stopped
* thread #1: tid = 0x98121, 0x00007fff8ad77866 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGABRT
frame #0: 0x00007fff8ad77866 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill + 10:
-> 0x7fff8ad77866: jae 0x7fff8ad77870 ; __pthread_kill + 20
0x7fff8ad77868: movq %rax, %rdi
0x7fff8ad7786b: jmpq 0x7fff8ad74175 ; cerror_nocancel
0x7fff8ad77870: ret
(lldb) bt
bt
* thread #1: tid = 0x98121, 0x00007fff8ad77866 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGABRT
* frame #0: 0x00007fff8ad77866 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x00007fff8d71635c libsystem_pthread.dylib`pthread_kill + 92
frame #2: 0x00007fff9265bb1a libsystem_c.dylib`abort + 125
frame #3: 0x0000000105e3badd libgc.1.dylib`GC_abort + 157
frame #4: 0x0000000105e2c4ad libgc.1.dylib`GC_add_to_heap + 45
frame #5: 0x0000000105e2c9bc libgc.1.dylib`GC_expand_hp_inner + 556
frame #6: 0x0000000105e2cd0e libgc.1.dylib`GC_collect_or_expand + 478
frame #7: 0x0000000105e2cfc9 libgc.1.dylib`GC_allocobj + 345
frame #8: 0x0000000105e33f09 libgc.1.dylib`GC_generic_malloc_inner + 345
frame #9: 0x0000000105e33ec4 libgc.1.dylib`GC_generic_malloc_inner + 276
frame #10: 0x0000000105e340d4 libgc.1.dylib`GC_generic_malloc + 148
frame #11: 0x0000000105e347a0 libgc.1.dylib`GC_malloc_uncollectable + 384
frame #12: 0x0000000100b4087a clasp_boehm_d`core::Lisp_O* gctools::allocateRootClass<core::Lisp_O>() + 26 at /Users/meister/Development/cando/clasp/src/main/../../src/gctools/gcalloc.h:272
frame #13: 0x0000000100b0556b clasp_boehm_d`core::Lisp_O::createLispEnvironment(bool, int, int) + 27 at /Users/meister/Development/cando/clasp/src/main/../../src/core/lisp.cc:327
frame #14: 0x0000000100b2ed79 clasp_boehm_d`LispHolder + 73 at /Users/meister/Development/cando/clasp/src/main/../../src/core/lisp.cc:3782
frame #15: 0x0000000100b2ed21 clasp_boehm_d`LispHolder + 49 at /Users/meister/Development/cando/clasp/src/main/../../src/core/lisp.cc:3783
frame #16: 0x000000010000233a clasp_boehm_d`startup(int, char**, bool&, int&, int&) + 90 at /Users/meister/Development/cando/clasp/src/main/main.cc:74
frame #17: 0x000000010000311a clasp_boehm_d`main + 314 at /Users/meister/Development/cando/clasp/src/main/main.cc:199
(lldb)
Heres the change I made:
STATIC struct hblk *
GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n,
GC_bool may_split)
{
struct hblk *hbp;
hdr * hhdr; /* Header corr. to hbp */
/* Initialized after loop if hbp !=0 */
/* Gcc uninitialized use warning is bogus. */
struct hblk *thishbp;
hdr * thishdr; /* Header corr. to hbp */
signed_word size_needed; /* number of bytes in requested objects */
signed_word size_avail; /* bytes available in this block */
may_split = FALSE; // meister modification suggested by Bruce Hoult
size_needed = HBLKSIZE * OBJ_SZ_TO_BLOCKS(sz);
/* search for a big enough block in free list */
hbp = GC_hblkfreelist[n];
for(; 0 != hbp; hbp = hhdr -> hb_next) {
GET_HDR(hbp, hhdr);
size_avail = hhdr->hb_sz;
if (size_avail < size_needed) continue;
if (size_avail != size_needed) {
signed_word next_size;
...
You also seem to have two N7gctools17GCVector_moveableIN4core11CacheRecordEEE of 1.2 MB each.
So when you allocate one of those, the GC has to find 300 contiguous pages. That's a lot.
If those two are all you ever have, then no problem. If you're constantly allocating and GCing them then that's potentially a big big problem.
Unfortunately, in a non-moving memory manager there is no perfect algorithm to decide when or whether to split up or combine large memory blocks. That applies to both malloc and gc.
In my own code, I try not to allocate anything larger than a heap block. I try to avoid very large arrays (including strings), and when I do need them I use an implementation that uses lots of small blocks and an index.
That would probably be a big change to your code.
While you have a locally-modified version of the GC, may I suggest you go to GC_allochblk_nth() and add "may_split = FALSE;" as the first statement (overriding the parameter's passed value). Let me know if that makes any difference and if so we can try something a little more subtle :)
Bruce,
The C++ files are read by the Clang library - they are used to construct C++ abstract syntax trees that I search using the ASTMatcher facilities of the Clang library. I can monitor clang/llvm allocations on OS X using the heap command line program because they are allocated using new/delete. They dont appear to leak memory.
I have some large arrays (largest is 393K, see below) but I dont think that many - I could be wrong on that. Ill count how many are larger than 4K.
After parsing/generating-AST/matching features in the AST for the same C++ file 10 times
A summary of the memory usage according to the Boehm GC library routines...
Done walk of memory 1093 ClassKinds 82 LispKinds 18 ContainerKinds 1 StringKinds
TOTAL invalidHeaderTotalSize = 8682352
TOTAL memory usage (bytes): 34446496
TOTAL GC_get_heap_size() 352399360
TOTAL GC_get_free_bytes() 35569664
TOTAL GC_get_bytes_since_gc() 141379680
TOTAL GC_get_total_bytes() 316783433851
So the Boehm GC says its using 0.3GB (GC_get_heap_size()) but the OS X Activity monitor reports that the process is consuming 6.34GB of memory.
If I can believe the Boehm GC number then Im leaking memory somewhere else.
An inventory of the largest reachable objects
-------------------- Reachable StringKinds -------------------
strs: total_size: 5401416 count: 88618 avg.sz: 60 largest: 1024 N7gctools17GCString_moveableIcEE
-------------------- Reachable ContainerKinds -------------------
cont: total_size: 3569344 count: 47460 avg.sz: 75 largest: 393240 N7gctools17GCVector_moveableINS_9smart_ptrIN4core3T_OEEEEE
cont: total_size: 2359344 count: 2 avg.sz: 1179672 largest: 1179672 N7gctools17GCVector_moveableIN4core11CacheRecordEEE
cont: total_size: 177512 count: 5112 avg.sz: 34 largest: 88 N7gctools16GCArray_moveableINS_9smart_ptrIN4core3T_OEEELi0EEE
cont: total_size: 160584 count: 1336 avg.sz: 120 largest: 288 N7gctools17GCVector_moveableIN4core16RequiredArgumentEEE
cont: total_size: 54040 count: 73 avg.sz: 740 largest: 3296 N7gctools17GCVector_moveableINS_9smart_ptrIN4core8Symbol_OEEEEE
cont: total_size: 32256 count: 112 avg.sz: 288 largest: 288 N7gctools17GCVector_moveableIN4core16OptionalArgumentEEE
cont: total_size: 15736 count: 281 avg.sz: 56 largest: 56 N7gctools17GCVector_moveableINS_9smart_ptrIN4core6Cons_OEEEEE
cont: total_size: 14784 count: 50 avg.sz: 295 largest: 672 N7gctools17GCVector_moveableIN4core15KeywordArgumentEEE
cont: total_size: 8216 count: 1 avg.sz: 8216 largest: 8216 N7gctools17GCVector_moveableIN4core14DynamicBindingEEE
cont: total_size: 3288 count: 1 avg.sz: 3288 largest: 3288 N7gctools17GCVector_moveableINS_9smart_ptrIN6clbind10ClassRep_OEEEEE
cont: total_size: 2168 count: 1 avg.sz: 2168 largest: 2168 N7gctools17GCVector_moveableIN10asttooling12_GLOBAL__N_112RegistryMaps27SymbolMatcherDescriptorPairEEE
cont: total_size: 1560 count: 1 avg.sz: 1560 largest: 1560 N7gctools17GCVector_moveableINS_9smart_ptrIN4core11Character_OEEEEE
cont: total_size: 1560 count: 1 avg.sz: 1560 largest: 1560 N7gctools17GCVector_moveableINS_9smart_ptrIN4core5Str_OEEEEE
cont: total_size: 1448 count: 1 avg.sz: 1448 largest: 1448 N7gctools17GCVector_moveableIN4core14ExceptionEntryEEE
cont: total_size: 808 count: 13 avg.sz: 62 largest: 136 N7gctools17GCVector_moveableINS_9smart_ptrIN4core9Package_OEEEEE
cont: total_size: 784 count: 14 avg.sz: 56 largest: 56 N7gctools17GCVector_moveableIPN10asttooling8internal17MatcherDescriptorEEE
cont: total_size: 152 count: 1 avg.sz: 152 largest: 152 N7gctools17GCVector_moveableIN4core11AuxArgumentEEE
cont: total_size: 56 count: 1 avg.sz: 56 largest: 56 N7gctools17GCVector_moveableINS_9smart_ptrIN4core16SourceFileInfo_OEEEEE
-------------------- Reachable LispKinds -------------------
lisp: total_size: 11301888 count: 353160 avg.sz: 32 N4core6Cons_OE
lisp: total_size: 2454176 count: 76693 avg.sz: 32 N4core5Str_OE
lisp: total_size: 1724448 count: 53889 avg.sz: 32 N4core8Bignum_OE
lisp: total_size: 1607040 count: 25110 avg.sz: 64 N4core10Instance_OE
lisp: total_size: 1295120 count: 32378 avg.sz: 40 N4core13BranchSNode_OE
lisp: total_size: 852768 count: 26649 avg.sz: 32 N4core11LeafSNode_OE
lisp: total_size: 657440 count: 16436 avg.sz: 40 N4core8Symbol_OE
lisp: total_size: 446408 count: 11160 avg.sz: 40 N4core15VectorObjects_OE
lisp: total_size: 418920 count: 10473 avg.sz: 40 N4core26VectorObjectsWithFillPtr_OE
lisp: total_size: 268912 count: 4802 avg.sz: 56 N4core18CompiledFunction_OE
lisp: total_size: 229760 count: 7180 avg.sz: 32 N4core14CompiledBody_OE
lisp: total_size: 203680 count: 5092 avg.sz: 40 N4core12ValueFrame_OE
lisp: total_size: 194112 count: 8088 avg.sz: 24 N4core8Fixnum_OE
lisp: total_size: 148064 count: 4627 avg.sz: 32 N4core16StrWithFillPtr_OE
lisp: total_size: 136064 count: 1546 avg.sz: 88 N4core19LambdaListHandler_OE
lisp: total_size: 96376 count: 1721 avg.sz: 56 N4core9BuiltIn_OE
lisp: total_size: 74272 count: 2320 avg.sz: 32 N4core15SourcePosInfo_OE
How are you reading the c++ files? Are they, or anything else, GC objects larger than 4 KB?
Apologies if this is a duplicate - I ran into trouble with the size due to a graph I included.
I used the code that Peter sent me as-is - it works very well - thanks!
Im writing a Common Lisp implementation that interoperates with C++ and uses LLVM as the back end. Ive written a static analyzer for my C++ code to help me clean it up and add features. When I run the static analyzer on the 165 C++ source files using the Boehm GC it blows up.
At the end of processing 165 source files the process consumes about 30GB (gigabytes) of memory.
So I run the static analyzer on one source file 10 times and use the code that Peter sent me and walk the reachable objects and add up their memory footprint. There are a handful of objects that dont have valid headers - I filter them out and currently dont count them. I find that the total reachable memory used by the system remains pretty constant at 62MB to 34MB (it spikes and then goes down).
But the total memory used by my process goes up and up and up very quickly!
I ran the OS X program heap on the process and it reports non-object heap memory - which I assume is allocated by the Boehm GC (this assumption may be wrong - please correct me if you know better).
Here is a graph that shows all of the memory usage each time after parsing/generating an AST/searching the AST for the same C++ file. A bit of explanation
The Y axis is log(Bytes) The red points are what heap reports as non-object memory - I assume this is total Boehm memory. The green points are the total reachable Boehm memory that has a valid header that I built. The blue points are the reachable Boehm memory that was allocated just since the start of loading the most recent C++ file. I measure this by writing an integer marker into the header of each newly allocated object and changing that marker each time I read the source file - this lets me track what objects are allocated since the last operation.
Graph link: http://imgur.com/tSN5jRL
This cant be memory fragmentation can it?
Is Boehm not reusing memory properly?
Am I not configuring Boehm properly?
_______________________________________________
bdwgc mailing list
https://lists.opendylan.org/mailman/listinfo/bdwgc
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.