xref: /titanic_44/usr/src/cmd/rcap/common/rcapd.h (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _RCAPD_H
28 #define	_RCAPD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <procfs.h>
38 #include "rcapd_conf.h"
39 
40 #define	LC_NAME_LEN			32
41 #define	RCAPD_DEFAULT_CONF_FILE		"/etc/rcap.conf"
42 #define	RCAPD_IGNORED_SET_FLUSH_IVAL	10	/* number of scans between */
43 						/* flushes of the ignored set */
44 
45 /*
46  * set the buffer length for /proc-based path names based on the actual
47  * length of the largest pid
48  */
49 #define	RCAPD__STR(a)		#a
50 #define	RCAPD_STR(macro)	RCAPD__STR(macro)
51 #define	PROC_PATH_MAX		(sizeof ("/proc/" RCAPD_STR(PID_MAX) \
52 				    "/pagedata"))
53 
54 /*
55  * lcollection_insert_update() result flags
56  */
57 #define	LCST_CAP_CHANGED		(1<<0)
58 #define	LCST_CAP_REMOVED		(1<<1)
59 #define	LCST_CAP_ZERO			(1<<2)
60 
61 typedef int64_t rcid_t;
62 
63 typedef enum {
64 	LCU_COMPLETE,	/* an enumeration of all possible collections */
65 	LCU_ACTIVE_ONLY	/* an enumeration of only once-active collections */
66 } lcollection_update_type_t;
67 
68 struct lmapping;
69 struct lprocess;
70 struct lcollection;
71 struct prxmap;
72 struct psinfo;
73 
74 /*
75  * Per-process data.
76  */
77 typedef struct lprocess {
78 	struct lprocess *lpc_prev;	/* global process list */
79 	struct lprocess *lpc_next;
80 
81 	pid_t		lpc_pid;	/* ID of this process */
82 	int		lpc_unscannable; /* flag indicating zombie or */
83 					/* other unscannable process */
84 	uint64_t	lpc_rss;	/* resident set size (kB) */
85 	uint64_t	lpc_unrm;	/* scannable set size (kB) (est.) */
86 	uint64_t	lpc_size;	/* process image size (kB) */
87 	int		lpc_mark;	/* mark-and-sweep flag */
88 	struct lcollection *lpc_collection; /* owning collection */
89 	int		lpc_psinfo_fd;	/* cached psinfo fd */
90 	int		lpc_pgdata_fd;	/* cached pagedata fd */
91 	int		lpc_xmap_fd;	/* cached xmap fd */
92 	struct prxmap	*lpc_xmap;	/* xmap corresponding to */
93 					/* current pagedata */
94 	int		lpc_nxmap;	/* number of mappings in xmap */
95 	prpageheader_t *lpc_prpageheader; /* accumulated mask of */
96 					/* process's ref/mod bits */
97 	struct lmapping	*lpc_ignore;	/* empirically-unpageable mappings */
98 } lprocess_t;
99 
100 /*
101  * Collection statistics.
102  */
103 typedef struct {
104 	uint64_t lcols_scan;		/* scan attempts */
105 	uint64_t lcols_pg_att;		/* kB attempted to page */
106 	uint64_t lcols_pg_eff;		/* kB paged out (est.) */
107 	uint64_t lcols_rss_sample;	/* RSS samplings */
108 	uint64_t lcols_unenforced_cap;	/* times cap could have been */
109 					/* enforced, but wasn't (due to low */
110 					/* global memory pressure, or global */
111 					/* scanner being activated) */
112 	uint64_t lcols_rss_sum;		/* sum of sampled RSS values */
113 	uint64_t lcols_rss_act_sum;	/* sum of sampled, excess RSS values */
114 	uint64_t lcols_min_rss;		/* minimum RSS (kB), this interval */
115 	uint64_t lcols_max_rss;		/* maximum RSS (kB), this interval */
116 	uint64_t lcols_proc_in;		/* processes tracked */
117 	uint64_t lcols_proc_out;	/* processes freed */
118 	hrtime_t lcols_scan_time;	/* time spent scanning (ns) */
119 	hrtime_t lcols_scan_time_complete; /* time spent scanning (ns) */
120 					/* at last completion */
121 	uint64_t lcols_scan_count;	/* number of complete scans */
122 	uint64_t lcols_scan_ineffective; /* number of uninterrupted */
123 					/* revolutions of clock hand after */
124 					/* which the excess was not */
125 					/* completely reduced */
126 } lcollection_stat_t;
127 
128 /*
129  * Collection.
130  */
131 typedef struct lcollection {
132 	struct lcollection *lcol_prev;	/* global collection list */
133 	struct lcollection *lcol_next;
134 
135 	rcid_t lcol_id;			/* numerical ID for this collection */
136 	char lcol_name[LC_NAME_LEN];	/* name of this collection, or */
137 					/* "unknown" */
138 	uint64_t lcol_rss;		/* RSS of all processes (kB) */
139 	uint64_t lcol_image_size;	/* image size of all processes (kB) */
140 	uint64_t lcol_rss_cap;		/* RSS cap (kB) */
141 	int lcol_stat_invalidate;	/* flag to reset interval statistics */
142 	lcollection_stat_t lcol_stat;	/* statistics */
143 	lcollection_stat_t lcol_stat_old; /* previous interval's statistics */
144 	lprocess_t *lcol_lprocess;	/* member processes */
145 	int lcol_mark;			/* mark-and-sweep flag */
146 	lprocess_t *lcol_victim;	/* victim process to resume scanning */
147 	void *lcol_resaddr;		/* address to resume scanning from */
148 } lcollection_t;
149 
150 /*
151  * Collection report.
152  */
153 typedef struct lcollection_report {
154 	rcid_t lcol_id;			/* numerical ID for this collection */
155 	char lcol_name[LC_NAME_LEN];	/* name of this collection, or */
156 					/* "unknown" */
157 	uint64_t lcol_rss;		/* RSS of all processes (kB) */
158 	uint64_t lcol_image_size;	/* image size of all processes (kB) */
159 	uint64_t lcol_rss_cap;		/* RSS limit (kB) */
160 	lcollection_stat_t lcol_stat;	/* statistics */
161 } lcollection_report_t;
162 
163 extern int get_psinfo(pid_t, struct psinfo *, int, int(*)(void *, int), void *,
164     lprocess_t *);
165 extern lcollection_t *lcollection_find(id_t);
166 extern void lcollection_freq_move(lprocess_t *);
167 extern lcollection_t *lcollection_insert_update(rcid_t, uint64_t, char *,
168     int *changes);
169 extern int lcollection_member(lcollection_t *, lprocess_t *);
170 extern void lcollection_set_type(rctype_t);
171 extern void lcollection_free(lcollection_t *);
172 extern void lcollection_update(lcollection_update_type_t);
173 extern void list_walk_collection(int (*)(lcollection_t *, void *), void *);
174 extern int lprocess_update_psinfo_fd_cb(void *, int);
175 extern void lprocess_free(lprocess_t *);
176 extern void scan(lcollection_t *, int64_t);
177 extern void scan_abort(void);
178 extern void check_update_statistics(void);
179 
180 /*
181  * The collection-specific function determining the collection ID from a
182  * process' psinfo.
183  */
184 extern rcid_t(*rc_getidbypsinfo)(struct psinfo *);
185 
186 /*
187  * Global (in rcapd only) variables.
188  */
189 extern rcfg_t rcfg;
190 extern uint64_t phys_total;
191 extern int should_run;
192 
193 #ifdef	__cplusplus
194 }
195 #endif
196 
197 #endif /* _RCAPD_H */
198