This commit was manufactured by cvs2svn to create tag
[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 shrink_count;
53         unsigned long last_shrink;
54         int over_limit_failures;
55         int hier; // hiearchy, root = 0
56 } ckrm_mem_res_t;
57
58 extern atomic_t ckrm_mem_real_count;
59 extern unsigned int ckrm_tot_lru_pages;
60 extern struct list_head ckrm_shrink_list;
61 extern spinlock_t ckrm_mem_lock;
62 extern struct ckrm_res_ctlr mem_rcbs;
63
64 #define page_class(page)        ((ckrm_mem_res_t*)((page)->memclass))
65
66 // used to fill reclaim_flags, used only when memory is low in the system
67 #define CLS_CLEAR               (0)      // class under its guarantee
68 #define CLS_OVER_GUAR   (1 << 0) // class is over its guarantee
69 #define CLS_PARENT_OVER (1 << 1) // parent is over 120% mark over limit
70 #define CLS_OVER_75             (1 << 2) // class over 75% mark bet guar(0) & limit(100)
71 #define CLS_OVER_100    (1 << 3) // class over its limit
72 #define CLS_OVER_110    (1 << 4) // class over 110% mark over limit
73 #define CLS_FLAGS_ALL   ( CLS_OVER_GUAR | CLS_PARENT_OVER | CLS_OVER_75 | \
74                                         CLS_OVER_100 | CLS_OVER_110 )
75 #define CLS_SHRINK_BIT  (31)      // used to both lock and set the bit
76 #define CLS_SHRINK              (1 << CLS_SHRINK_BIT) // shrink the given class
77
78 // used in flags. set when a class is more than 90% of its maxlimit
79 #define MEM_NEAR_LIMIT 1
80
81 extern void ckrm_set_aggressive(ckrm_mem_res_t *);
82 extern unsigned int ckrm_setup_reclamation(void);
83 extern void ckrm_teardown_reclamation(void);
84 extern void ckrm_get_reclaim_bits(unsigned int *, unsigned int *);
85 extern void ckrm_init_mm_to_task(struct mm_struct *, struct task_struct *);
86 extern void ckrm_mem_evaluate_mm(struct mm_struct *);
87 extern void ckrm_mem_evaluate_page_byadd(struct page *, struct mm_struct *);
88 extern void ckrm_near_limit(ckrm_mem_res_t *);
89 #define ckrm_get_reclaim_flags(cls)     ((cls)->reclaim_flags)
90
91 #else
92
93 #define ckrm_init_mm_to_current(a)                      do {} while (0)
94 #define ckrm_mem_evaluate_mm(a)                         do {} while (0)
95 #define ckrm_mem_evaluate_page_byadd(a,b)       do {} while (0)
96 #define page_class(page)                                        (NULL)
97 #define ckrm_get_reclaim_flags(a)                       (0)
98 #define ckrm_setup_reclamation()                        (0)
99 #define ckrm_teardown_reclamation()                     do {} while (0)
100 #define ckrm_get_reclaim_bits(a, b)                     do { *(a) = 0; *(b)= 0; } while (0)
101 #define ckrm_init_mm_to_task(a,b)                       do {} while (0)
102
103 #endif // CONFIG_CKRM_RES_MEM
104
105 #endif //_LINUX_CKRM_MEM_H
106