@@ -42,8 +42,8 @@ typedef enum {
42
42
NS_MONITOR_STATE_GC_CRITICAL
43
43
} ns_monitor_state_e ;
44
44
45
- #define HEAP_HIGH_THRESHOLD (0.7 ) /* Heap usage HIGH threshold */
46
- #define HEAP_CRITICAL_THRESHOLD (0.9 ) /* Heap usage CRITICAL threshold */
45
+ #define HEAP_HIGH_WATERWARK (0.80 ) /* Heap usage HIGH threshold */
46
+ #define HEAP_CRITICAL_WATERMARK (0.90 ) /* Heap usage CRITICAL threshold */
47
47
48
48
#define NS_MAINTENANCE_TIMER_INTERVAL 10 // Maintenance interval
49
49
@@ -81,17 +81,19 @@ static void ns_monitor_heap_gc(bool full_gc)
81
81
static void ns_monitor_periodic_heap_health_check (void )
82
82
{
83
83
if (ns_monitor_ptr -> mem_stats -> heap_sector_allocated_bytes > ns_monitor_ptr -> heap_critical_watermark ) {
84
+ // Heap usage above CRITICAL
84
85
if (ns_monitor_ptr -> ns_monitor_heap_gc_state != NS_MONITOR_STATE_GC_CRITICAL ) {
85
86
ns_mem_heap_size_t prev_heap_sector_allocated_bytes = ns_monitor_ptr -> mem_stats -> heap_sector_allocated_bytes ;
86
- // Heap usage above CRITICAL
87
+ tr_debug ( "heap %lu/%lu" , ( unsigned long ) ns_monitor_ptr -> mem_stats -> heap_sector_allocated_bytes , ( unsigned long ) ns_monitor_ptr -> mem_stats -> heap_sector_size );
87
88
ns_monitor_heap_gc (true);
88
89
ns_monitor_ptr -> ns_monitor_heap_gc_state = NS_MONITOR_STATE_GC_CRITICAL ;
89
90
tr_info ("Stack GC critical: freed %lu bytes" , (unsigned long )(prev_heap_sector_allocated_bytes - ns_monitor_ptr -> mem_stats -> heap_sector_allocated_bytes ));
90
91
}
91
92
} else if (ns_monitor_ptr -> mem_stats -> heap_sector_allocated_bytes > ns_monitor_ptr -> heap_high_watermark ) {
93
+ // Heap usage above HIGH
92
94
if (ns_monitor_ptr -> ns_monitor_heap_gc_state == NS_MONITOR_STATE_HEAP_GC_IDLE ) {
93
95
ns_mem_heap_size_t prev_heap_sector_allocated_bytes = ns_monitor_ptr -> mem_stats -> heap_sector_allocated_bytes ;
94
- // Heap usage above HIGH
96
+ tr_debug ( "heap %lu/%lu" , ( unsigned long ) ns_monitor_ptr -> mem_stats -> heap_sector_allocated_bytes , ( unsigned long ) ns_monitor_ptr -> mem_stats -> heap_sector_size );
95
97
ns_monitor_heap_gc (false);
96
98
ns_monitor_ptr -> ns_monitor_heap_gc_state = NS_MONITOR_STATE_HEAP_GC_HIGH ;
97
99
tr_info ("Stack GC high: freed %lu bytes" , (unsigned long )(prev_heap_sector_allocated_bytes - ns_monitor_ptr -> mem_stats -> heap_sector_allocated_bytes ));
@@ -119,7 +121,6 @@ void ns_monitor_timer(uint16_t seconds)
119
121
120
122
if (ns_monitor_ptr -> ns_maintenance_timer >= NS_MAINTENANCE_TIMER_INTERVAL ) {
121
123
ns_monitor_ptr -> ns_maintenance_timer -= NS_MAINTENANCE_TIMER_INTERVAL ;
122
- tr_debug ("ns_monitor_maintenance_timer(), used %lu/%lu" , (unsigned long )ns_monitor_ptr -> mem_stats -> heap_sector_allocated_bytes , (unsigned long )ns_monitor_ptr -> mem_stats -> heap_sector_size );
123
124
ns_monitor_periodic_heap_health_check ();
124
125
}
125
126
}
@@ -136,12 +137,12 @@ int ns_monitor_init(void)
136
137
137
138
if (ns_monitor_ptr ) {
138
139
ns_monitor_ptr -> mem_stats = ns_dyn_mem_get_mem_stat ();
139
- ns_monitor_ptr -> heap_high_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * HEAP_HIGH_THRESHOLD ;
140
- ns_monitor_ptr -> heap_critical_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * HEAP_CRITICAL_THRESHOLD ;
140
+ ns_monitor_ptr -> heap_high_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * HEAP_HIGH_WATERWARK ;
141
+ ns_monitor_ptr -> heap_critical_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * HEAP_CRITICAL_WATERMARK ;
141
142
ns_monitor_ptr -> ns_monitor_heap_gc_state = NS_MONITOR_STATE_HEAP_GC_IDLE ;
142
143
ns_monitor_ptr -> ns_maintenance_timer = 0 ;
143
144
ns_monitor_ptr -> prev_heap_alloc_fail_cnt = 0 ;
144
- tr_debug ("monitor high %lu, critical %lu" , (unsigned long )ns_monitor_ptr -> heap_high_watermark , (unsigned long )ns_monitor_ptr -> heap_critical_watermark );
145
+ tr_debug ("Monitor high: %lu, critical:%lu total: %lu" , (unsigned long )ns_monitor_ptr -> heap_high_watermark , (unsigned long )ns_monitor_ptr -> heap_critical_watermark , ( unsigned long ) ns_monitor_ptr -> mem_stats -> heap_sector_size );
145
146
return 0 ;
146
147
}
147
148
@@ -164,6 +165,7 @@ int ns_monitor_heap_gc_threshold_set(uint8_t percentage_high, uint8_t percentage
164
165
if (ns_monitor_ptr && (percentage_critical <= 100 ) && (percentage_high < percentage_critical )) {
165
166
ns_monitor_ptr -> heap_high_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * percentage_high / 100 ;
166
167
ns_monitor_ptr -> heap_critical_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * percentage_critical / 100 ;
168
+ tr_debug ("Monitor high:%lu, critical:%lu total:%lu" , (unsigned long )ns_monitor_ptr -> heap_high_watermark , (unsigned long )ns_monitor_ptr -> heap_critical_watermark , (unsigned long )ns_monitor_ptr -> mem_stats -> heap_sector_size );
167
169
return 0 ;
168
170
}
169
171
0 commit comments