@@ -42,8 +42,10 @@ typedef enum {
42
42
NS_MONITOR_STATE_GC_CRITICAL
43
43
} ns_monitor_state_e ;
44
44
45
- #define HEAP_HIGH_WATERWARK (0.95) /* Heap usage HIGH threshold */
46
- #define HEAP_CRITICAL_WATERMARK (0.99) /* Heap usage CRITICAL threshold */
45
+ #define DEFAULT_HEAP_PERCENTAGE_THRESHOLD_HIGH 95
46
+ #define DEFAULT_HEAP_PERCENTAGE_THRESHOLD_CRITICAL 99
47
+
48
+ #define SET_WATERMARK (SECTOR_SIZE , THRESHOLD ) (SECTOR_SIZE * THRESHOLD / 100)
47
49
48
50
#define NS_MAINTENANCE_TIMER_INTERVAL 10 // Maintenance interval
49
51
@@ -139,8 +141,14 @@ int ns_monitor_init(void)
139
141
140
142
if (ns_monitor_ptr ) {
141
143
ns_monitor_ptr -> mem_stats = ns_dyn_mem_get_mem_stat ();
142
- ns_monitor_ptr -> heap_high_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * HEAP_HIGH_WATERWARK ;
143
- ns_monitor_ptr -> heap_critical_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * HEAP_CRITICAL_WATERMARK ;
144
+ ns_monitor_ptr -> heap_high_watermark = SET_WATERMARK (
145
+ ns_monitor_ptr -> mem_stats -> heap_sector_size ,
146
+ DEFAULT_HEAP_PERCENTAGE_THRESHOLD_HIGH
147
+ );
148
+ ns_monitor_ptr -> heap_critical_watermark = SET_WATERMARK (
149
+ ns_monitor_ptr -> mem_stats -> heap_sector_size ,
150
+ DEFAULT_HEAP_PERCENTAGE_THRESHOLD_CRITICAL
151
+ );
144
152
ns_monitor_ptr -> ns_monitor_heap_gc_state = NS_MONITOR_STATE_HEAP_GC_IDLE ;
145
153
ns_monitor_ptr -> ns_maintenance_timer = 0 ;
146
154
ns_monitor_ptr -> prev_heap_alloc_fail_cnt = 0 ;
@@ -164,8 +172,14 @@ int ns_monitor_clear(void)
164
172
int ns_monitor_heap_gc_threshold_set (uint8_t percentage_high , uint8_t percentage_critical )
165
173
{
166
174
if (ns_monitor_ptr && (percentage_critical <= 100 ) && (percentage_high < percentage_critical )) {
167
- ns_monitor_ptr -> heap_high_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * percentage_high / 100 ;
168
- ns_monitor_ptr -> heap_critical_watermark = ns_monitor_ptr -> mem_stats -> heap_sector_size * percentage_critical / 100 ;
175
+ ns_monitor_ptr -> heap_high_watermark = SET_WATERMARK (
176
+ ns_monitor_ptr -> mem_stats -> heap_sector_size ,
177
+ percentage_high
178
+ );
179
+ ns_monitor_ptr -> heap_critical_watermark = SET_WATERMARK (
180
+ ns_monitor_ptr -> mem_stats -> heap_sector_size ,
181
+ percentage_critical
182
+ );
169
183
tr_debug ("Monitor set 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 );
170
184
return 0 ;
171
185
}
0 commit comments