Listing 1. Algorithm of MAT and ST Watermarks Heuristic 1 static int low_vm_enough_memory(long pages) 2 { 3 unsigned long committed; 4 unsigned long deny_threshold, notify_threshold; 5 int cap_sys_admin = 0; 6 7 if (cap_capable(current, CAP_SYS_ADMIN) == 0) 8 cap_sys_admin = 1; 9 10 if (deny_percentage==0||notify_percentage==0) 11 return __vm_enough_memory(pages,cap_sys_admin); 12 13 deny_threshold= 14 totalram_pages*deny_percentage/100; 15 notify_threshold= 16 totalram_pages*notify_percentage/ 100; 17 18 vm_acct_memory(pages); 19 committed = atomic_read(&vm_committed_space); 20 if (committed >= deny_threshold) { 21 enter_watermark_state(1); 22 if (cap_sys_admin) 23 return 0; 24 vm_unacct_memory(pages); 25 return -ENOMEM; 26 } else if (committed >= notify_threshold) { 27 enter_watermark_state(1); 28 return 0; 29 } 30 enter_watermark_state(0); 31 return 0; 32 }