History

count alloc pressure better and display it with (vm-stats)

Sigrid Solveig Haflínudóttir committed 10 months ago

Commit c9dfea01 parent 8ba2cfd3 files · +9 −3Browse files

Unified · Split

3 files
  1. src/cvalues.c +7 −3
  2. src/htable.c +1 −0
  3. src/sl.c +1 −0
src/cvalues.c+7−3
@@ -128,11 +128,11 @@ cvalue_(const sl_type *type, usize sz, bool nofinalize) · 127 unmodified lines
128128 void *data = MEM_ALLOC(sz);
129129 if(sl_unlikely(data == nil))
130130 cthrow(lerrorf(sl_errmem, "no memory for a cv"), type);
131+ slvm.malloc_pressure += sz;
131132 pcv = alloc_words(CVALUE_NWORDS);
132133 pcv->type = type;
133134 pcv->data = data;
134135 cv_autorelease(pcv);
135− slvm.malloc_pressure += sz;
136136 }
137137 if(str){
138138 ((char*)pcv->data)[--sz] = '\0';
@@ -212,6 +212,7 @@ cv_pin(sl_cv *cv) · 73 unmodified lines
212212 void *data = MEM_ALLOC(sz);
213213 if(sl_unlikely(data == nil))
214214 cthrow(lerrorf(sl_errmem, "no memory to pin a cv"), cv);
215+ slvm.malloc_pressure += sz;
215216 memcpy(data, cv_data(cv), sz);
216217 cv->data = data;
217218 cv_autorelease(cv);
@@ -789,8 +790,11 @@ cvalue_copy(sl_v v) · 571 unmodified lines
789790 usize len = cv_len(cv) + (cv_isstr(cv) ? 1 : 0);
790791 bool inlined = isinlined(cv);
791792 void *data = nil;
792− if(!inlined && sl_unlikely((data = MEM_ALLOC(len)) == nil))
793− cthrow(lerrorf(sl_errmem, "no memory for a cv copy"), v);
793+ if(!inlined){
794+ if(sl_unlikely((data = MEM_ALLOC(len)) == nil))
795+ cthrow(lerrorf(sl_errmem, "no memory for a cv copy"), v);
796+ slvm.malloc_pressure += len;
797+ }
794798
795799 PUSH(v);
796800 sl_cv *ncv = alloc_words(nw);
src/htable.c+1−0
@@ -18,6 +18,7 @@ htable_new(sl_htable *h, usize size) · 17 unmodified lines
1818 size *= 2; // aim for 50% occupancy
1919 if((h->table = MEM_ALLOC(size * sizeof(*h->table))) == nil)
2020 return nil;
21+ slvm.malloc_pressure += size * sizeof(*h->table);
2122 }
2223 h->size = size;
2324 h->i = 0;
src/sl.c+1−0
@@ -1364,6 +1364,7 @@ BUILTIN("vm-stats", vm_stats) · 1363 unmodified lines
13641364 ios_printf(io, "heap total %10"PRIuPTR" bytes\n", slvm.heapsize);
13651365 ios_printf(io, "heap free %10"PRIuPTR" bytes\n", (uintptr)(slvm.lim-slvm.curheap));
13661366 ios_printf(io, "heap used %10"PRIuPTR" bytes\n", (uintptr)(slvm.curheap-slvm.fromspace));
1367+ ios_printf(io, "alloc pressure %10"PRIuPTR" bytes\n", (uintptr)slvm.malloc_pressure);
13671368 ios_printf(io, "stack %10"PRIu64" bytes\n", (u64int)sl.nstack*sizeof(sl_v));
13681369 ios_printf(io, "finalizers %10"PRIu32"\n", (u32int)slvm.nfinalizers);
13691370 ios_printf(io, "max finalizers %10"PRIu32"\n", (u32int)slvm.maxfinalizers);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t