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