c696c0a2a7abec6747e4be2e2a9280f5e6f4bd3d
[cascardo/linux.git] / include / linux / low-mem-notify.h
1 #ifndef _LINUX_LOW_MEM_NOTIFY_H
2 #define _LINUX_LOW_MEM_NOTIFY_H
3
4 extern unsigned low_mem_margin_percent;
5 extern unsigned long low_mem_minfree;
6 void low_mem_notify(void);
7 extern const struct file_operations low_mem_notify_fops;
8
9 /*
10  * Return TRUE if we are in a low memory state.
11  */
12 static inline bool is_low_mem_situation(void)
13 {
14         const int lru_base = NR_LRU_BASE - LRU_BASE;
15         const int file_mem_multiplier = 2;  /* between 1 and 2 seems right */
16         /*
17          * We declare a low-memory condition when free memory is low and there
18          * isn't much reclaimable file memory.
19          */
20         unsigned long free_mem = global_page_state(NR_FREE_PAGES);
21         unsigned long file_mem =
22                         global_page_state(lru_base + LRU_ACTIVE_FILE) +
23                         global_page_state(lru_base + LRU_INACTIVE_FILE);
24         unsigned long min_file_mem = file_mem_multiplier *
25                         (min_filelist_kbytes >> (PAGE_SHIFT - 10));
26         bool is_low_mem = free_mem < low_mem_minfree && file_mem < min_file_mem;
27
28 #ifdef CONFIG_LOW_MEM_NOTIFY_DEBUG
29         {
30                 static bool was_low_mem;
31                 if (is_low_mem && !was_low_mem)
32                         printk(KERN_INFO "entering low_mem: %lu\n", in_use);
33                 else if (!is_low_mem && was_low_mem)
34                         printk(KERN_INFO "exiting low_mem: %lu\n", in_use);
35                 was_low_mem = is_low_mem;
36         }
37 #endif
38
39         return is_low_mem;
40 }
41
42 #endif