@@ -42,8 +42,10 @@ typedef enum {
4242 NS_MONITOR_STATE_GC_CRITICAL
4343} ns_monitor_state_e ;
4444
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)
4749
4850#define NS_MAINTENANCE_TIMER_INTERVAL 10 // Maintenance interval
4951
@@ -139,8 +141,14 @@ int ns_monitor_init(void)
139141
140142 if (ns_monitor_ptr ) {
141143 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+ );
144152 ns_monitor_ptr -> ns_monitor_heap_gc_state = NS_MONITOR_STATE_HEAP_GC_IDLE ;
145153 ns_monitor_ptr -> ns_maintenance_timer = 0 ;
146154 ns_monitor_ptr -> prev_heap_alloc_fail_cnt = 0 ;
@@ -164,8 +172,14 @@ int ns_monitor_clear(void)
164172int ns_monitor_heap_gc_threshold_set (uint8_t percentage_high , uint8_t percentage_critical )
165173{
166174 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+ );
169183 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 );
170184 return 0 ;
171185 }
0 commit comments