4 #include <linux/sched.h>
6 #ifdef CONFIG_MTPROF_KMEM
9 /** @def TRUE Logical value of true. */
14 /** @def FALSE Logical value of false. */
18 /* TODO: relationship amoung differnent definations */
19 #define MAX_PROCESS_NUM (16*1024) /* MAX PID defined by linux: 32 *1024 - 1 */
20 #define MAX_KMEM_MON_NUM (20*1024)
21 #define MAX_ADDR_TABLE (64*1024) /* NOTICE: for the hash */
22 #define MAX_CALLER_TABLE (80*1024)
23 #define MAX_FAIL_PARAMETER 256
24 #define MAX_MEM_CLASS_NUM 64
25 #define MAX_CMD_LINE 64
26 #define MAX_PID_LEN 6 /* because 16*1024 = 16384 */
27 #define MAX_ADDR_IDX (16*1024) /* 14 */
31 KMEM_MON_TYPE_KMALLOC
= 0, /* kmalloc() or kfree(). */
32 KMEM_MON_TYPE_KMEM_CACHE
, /* kmem_cache_*(). */
33 KMEM_MON_TYPE_PAGES
, /* __get_free_pages() and friends. */
36 KMEM_MON_TYPE_VMALLOC
,
38 KMEM_MON_TYPE_KMALLOCWRAPPER
,
41 typedef struct mem_class_info_struct
{
42 MEM_CLASS_T mem_class
;
44 int index
[MAX_KMEM_MON_NUM
];
47 /* TODO: keep caller backtrace */
48 typedef struct caller_info_struct
{
49 unsigned long caller_addr
;
50 int bytes_req
, bytes_alloc
;
52 int freq_alloc
, freq_free
;
54 MEM_CLASS_T mem_class
;
58 /* NOTICE: if the node is not used, caller_hash == 0 */
59 typedef struct addr_info_struct
{
65 typedef struct process_info_struct
{
68 char cmdline
[MAX_CMD_LINE
];
69 char comm
[TASK_COMM_LEN
]; /* executable name excluding path
70 - access with [gs]et_task_comm (which lock
72 - initialized normally by setup_new_exec */
73 int start_idx
; /* ->kmalloc->pem... */
74 /* TODO: use an array to arrage all mem nodes */
77 /* ========================================================================== */
79 * @struct kmem_info_struct
81 * @brief keep information for kernel memory monitoring
85 * @typedef kmem_mon_info_t
86 * @brief Type definition for the kmem_mon_info_struct.
88 typedef struct mem_info_struct
{
89 MEM_CLASS_T mem_class
;
91 /* these information should be kept in caller table */
92 size_t total_bytes_req
;
93 size_t total_bytes_alloc
;
95 size_t total_bytes_free
;
100 int peak_every_req
; /* peak size of a single requirment */
101 unsigned long peak_caller
; /* code position' */
104 /* TODO: allocation failures */
107 unsigned long fail_caller
;
108 char last_fail_parameter
[MAX_FAIL_PARAMETER
]; /* only record the latest failure's paramter */
110 int caller_start_idx
;
113 /* TODO: additional info for different memory class */
117 #endif /* #ifdef CONFIG_MTPROF_KMEM */
119 extern void kmem_mon_kmalloc(unsigned long caller
, const void *addr
, int bytes_req
,
121 extern void kmem_mon_kfree(unsigned long caller
, const void *addr
);
122 extern void kmem_mon_pmem_alloc(int req
, int alloc
);
123 extern void kmem_mon_pmem_free(int size
);
124 extern void kmem_mon_m4u_alloc(int req
, int alloc
);
125 extern void kmem_mon_m4u_dealloc(const unsigned int addr
, const unsigned int req_size
);
126 extern void kmem_mon_vmalloc(unsigned long caller
, const void *addr
, int bytes_req
,
128 extern void kmem_mon_vfree(int size
);
129 extern void kmem_mon_ashmem_mmap(int size
);
130 extern void kmem_mon_ashmem_release(int size
);
131 extern void kmem_mon_kmallocwrapper(unsigned long caller
, int size
);
132 /* extern void kmem_mon_kmallocwrapper(unsigned long caller, const void *addr, int bytes_req, int bytes_alloc); */
133 extern void kmem_mon_kfreewrapper(const void *addr
);
134 extern void kmem_mon_kmem_cache_alloc(unsigned long caller
, const void *addr
, size_t bytes_req
,
136 extern void kmem_mon_kmem_cache_free(unsigned long caller
, const void *addr
);
138 #endif /* __KMEM_MON_H__ */