ckrm_E16rc1 cpu controller version 8.2
[linux-2.6.git] / include / linux / ckrm_mem.h
1 /* include/linux/ckrm_mem.h : memory control for CKRM
2  *
3  * Copyright (C) Jiantao Kong, IBM Corp. 2003
4  *           (C) Shailabh Nagar, IBM Corp. 2003
5  *           (C) Chandra Seetharaman, IBM Corp. 2004
6  * 
7  * 
8  * Memory control functions of the CKRM kernel API 
9  *
10  * Latest version, more details at http://ckrm.sf.net
11  * 
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  */
18
19 /* Changes
20  *
21  * 28 Aug 2003
22  *        Created.
23  */
24
25 #ifndef _LINUX_CKRM_MEM_H
26 #define _LINUX_CKRM_MEM_H
27
28 #ifdef CONFIG_CKRM_RES_MEM
29
30 #include <linux/list.h>
31 #include <linux/ckrm_rc.h>
32
33 typedef struct ckrm_mem_res {
34         unsigned long reclaim_flags; 
35         unsigned long flags; 
36         struct ckrm_core_class *core; // the core i am part of...
37         struct ckrm_core_class *parent; // parent of the core i am part of....
38         struct ckrm_shares shares;
39         struct list_head mcls_list; // list of all 1-level classes
40         struct list_head shrink_list; // list of classes need to be shrunk
41         atomic_t nr_users; // # of references to this class/data structure
42         atomic_t pg_total;  // # of pages used by this class
43         int pg_guar; // # of pages this class is guaranteed
44         int pg_limit; // max # of pages this class can get
45         int pg_borrowed; // # of pages this class borrowed from its parent
46         int pg_lent; // # of pages this class lent to its children
47         int pg_unused; // # of pages left to this class (after giving the
48                                 // guarantees to children. need to borrow from parent if
49                                 // more than this is needed.
50         int nr_active[MAX_NR_ZONES];
51         int nr_inactive[MAX_NR_ZONES];
52         int tmp_cnt;
53         int shrink_count;
54         unsigned long last_shrink;
55         int over_limit_failures;
56         int hier; // hiearchy, root = 0
57 } ckrm_mem_res_t;
58
59 extern atomic_t ckrm_mem_real_count;
60 extern unsigned int ckrm_tot_lru_pages;
61 extern struct list_head ckrm_shrink_list;
62 extern spinlock_t ckrm_mem_lock;
63 extern struct ckrm_res_ctlr mem_rcbs;
64
65 #define page_class(page)        ((ckrm_mem_res_t*)((page)->memclass))
66
67 // used to fill reclaim_flags, used only when memory is low in the system
68 #define CLS_CLEAR               (0)      // class under its guarantee
69 #define CLS_OVER_GUAR   (1 << 0) // class is over its guarantee
70 #define CLS_PARENT_OVER (1 << 1) // parent is over 110% mark over limit
71 #define CLS_OVER_25             (1 << 2) // class over 25% mark bet guar(0) & limit(100)
72 #define CLS_OVER_50             (1 << 3) // class over 50% mark bet guar(0) & limit(100)
73 #define CLS_OVER_75             (1 << 4) // class over 75% mark bet guar(0) & limit(100)
74 #define CLS_OVER_100    (1 << 5) // class over its limit
75 #define CLS_OVER_110    (1 << 6) // class over 110% mark over limit
76 #define CLS_FLAGS_ALL   ( CLS_OVER_GUAR | CLS_PARENT_OVER | CLS_OVER_25 | \
77                                         CLS_OVER_50 | CLS_OVER_75 | CLS_OVER_100 | CLS_OVER_110 )
78 #define CLS_SHRINK_BIT  (31)      // used to both lock and set the bit
79 #define CLS_SHRINK              (1 << CLS_SHRINK_BIT) // shrink the given class
80
81 // used in flags. set when a class is more than 90% of its maxlimit
82 #define MEM_AT_LIMIT 1
83
84 extern void ckrm_set_aggressive(ckrm_mem_res_t *);
85 extern unsigned int ckrm_setup_reclamation(void);
86 extern void ckrm_teardown_reclamation(void);
87 extern void ckrm_get_reclaim_bits(unsigned int *, unsigned int *);
88 extern void ckrm_init_mm_to_task(struct mm_struct *, struct task_struct *);
89 extern void ckrm_mem_evaluate_mm(struct mm_struct *);
90 extern void ckrm_at_limit(ckrm_mem_res_t *);
91 extern int ckrm_memclass_valid(ckrm_mem_res_t *);
92 #define ckrm_get_reclaim_flags(cls)     ((cls)->reclaim_flags)
93
94 #else
95
96 #define ckrm_init_mm_to_current(a)                      do {} while (0)
97 #define ckrm_mem_evaluate_mm(a)                         do {} while (0)
98 #define ckrm_get_reclaim_flags(a)                       (0)
99 #define ckrm_setup_reclamation()                        (0)
100 #define ckrm_teardown_reclamation()                     do {} while (0)
101 #define ckrm_get_reclaim_bits(a, b)                     do { *(a) = 0; *(b)= 0; } while (0)
102 #define ckrm_init_mm_to_task(a,b)                       do {} while (0)
103
104 #endif // CONFIG_CKRM_RES_MEM
105
106 #endif //_LINUX_CKRM_MEM_H
107