xref: /illumos-gate/usr/src/cmd/rcap/common/rcapd.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 2007 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 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/types.h>
34 #include <procfs.h>
35 #include "rcapd_conf.h"
36 
37 #define	LC_NAME_LEN			32
38 #define	RCAP_FMRI			"svc:/system/rcap:default"
39 #define	CONFIG_PG			"config"
40 #define	PRESSURE			"pressure"
41 #define	RECONFIG_INT			"reconfig_interval"
42 #define	REPORT_INT			"report_interval"
43 #define	RSS_SAMPLE_INT			"rss_sample_interval"
44 #define	WALK_INT			"walk_interval"
45 #define	RCAPD_IGNORED_SET_FLUSH_IVAL	10	/* number of scans between */
46 						/* flushes of the ignored set */
47 
48 /*
49  * set the buffer length for /proc-based path names based on the actual
50  * length of the largest pid
51  */
52 #define	RCAPD__STR(a)		#a
53 #define	RCAPD_STR(macro)	RCAPD__STR(macro)
54 #define	PROC_PATH_MAX		(sizeof ("/proc/" RCAPD_STR(PID_MAX) \
55 				    "/pagedata"))
56 
57 /*
58  * lcollection_insert_update() result flags
59  */
60 #define	LCST_CAP_CHANGED		(1<<0)
61 #define	LCST_CAP_REMOVED		(1<<1)
62 #define	LCST_CAP_ZERO			(1<<2)
63 
64 typedef enum {
65 	RCIDT_PROJECT,
66 	RCIDT_ZONE
67 } rcid_type_t;
68 
69 typedef struct {
70 	/*
71 	 * The following field could just be a rcid_type_t but it gets
72 	 * written out to a file as binary data for communication between
73 	 * 64-bit rcapd & 32-bit rcapstat, so we need to force a standard size
74 	 * and alignment here.
75 	 */
76 	uint64_t	rcid_type;
77 	int64_t		rcid_val;
78 } rcid_t;
79 
80 typedef enum {
81 	LCU_COMPLETE,	/* an enumeration of all possible collections */
82 	LCU_ACTIVE_ONLY	/* an enumeration of only once-active collections */
83 } lcollection_update_type_t;
84 
85 struct lmapping;
86 struct lprocess;
87 struct lcollection;
88 struct prxmap;
89 struct psinfo;
90 
91 /*
92  * Per-process data.
93  */
94 typedef struct lprocess {
95 	struct lprocess *lpc_prev;	/* global process list */
96 	struct lprocess *lpc_next;
97 
98 	pid_t		lpc_pid;	/* ID of this process */
99 	int		lpc_unscannable; /* flag indicating zombie or */
100 					/* other unscannable process */
101 	uint64_t	lpc_rss;	/* resident set size (kB) */
102 	uint64_t	lpc_unrm;	/* scannable set size (kB) (est.) */
103 	uint64_t	lpc_size;	/* process image size (kB) */
104 	int		lpc_mark;	/* mark-and-sweep flag */
105 	struct lcollection *lpc_collection; /* owning collection */
106 	int		lpc_psinfo_fd;	/* cached psinfo fd */
107 	int		lpc_pgdata_fd;	/* cached pagedata fd */
108 	int		lpc_xmap_fd;	/* cached xmap fd */
109 	struct prxmap	*lpc_xmap;	/* xmap corresponding to */
110 					/* current pagedata */
111 	int		lpc_nxmap;	/* number of mappings in xmap */
112 	prpageheader_t *lpc_prpageheader; /* accumulated mask of */
113 					/* process's ref/mod bits */
114 	struct lmapping	*lpc_ignore;	/* empirically-unpageable mappings */
115 } lprocess_t;
116 
117 /*
118  * Collection statistics.
119  */
120 typedef struct {
121 	uint64_t lcols_scan;		/* scan attempts */
122 	uint64_t lcols_pg_att;		/* kB attempted to page */
123 	uint64_t lcols_pg_eff;		/* kB paged out (est.) */
124 	uint64_t lcols_rss_sample;	/* RSS samplings */
125 	uint64_t lcols_unenforced_cap;	/* times cap could have been */
126 					/* enforced, but wasn't (due to low */
127 					/* global memory pressure, or global */
128 					/* scanner being activated) */
129 	uint64_t lcols_rss_sum;		/* sum of sampled RSS values */
130 	uint64_t lcols_rss_act_sum;	/* sum of sampled, excess RSS values */
131 	uint64_t lcols_min_rss;		/* minimum RSS (kB), this interval */
132 	uint64_t lcols_max_rss;		/* maximum RSS (kB), this interval */
133 	uint64_t lcols_proc_in;		/* processes tracked */
134 	uint64_t lcols_proc_out;	/* processes freed */
135 	hrtime_t lcols_scan_time;	/* time spent scanning (ns) */
136 	hrtime_t lcols_scan_time_complete; /* time spent scanning (ns) */
137 					/* at last completion */
138 	uint64_t lcols_scan_count;	/* number of complete scans */
139 	uint64_t lcols_scan_ineffective; /* number of uninterrupted */
140 					/* revolutions of clock hand after */
141 					/* which the excess was not */
142 					/* completely reduced */
143 } lcollection_stat_t;
144 
145 /*
146  * Collection.
147  */
148 typedef struct lcollection {
149 	struct lcollection *lcol_prev;	/* global collection list */
150 	struct lcollection *lcol_next;
151 
152 	rcid_t lcol_id;			/* numerical ID for this collection */
153 	char lcol_name[LC_NAME_LEN];	/* name of this collection, or */
154 					/* "unknown" */
155 	uint64_t lcol_rss;		/* RSS of all processes (kB) */
156 	uint64_t lcol_image_size;	/* image size of all processes (kB) */
157 	uint64_t lcol_rss_cap;		/* RSS cap (kB) */
158 	lcollection_stat_t lcol_stat;	/* statistics */
159 	lcollection_stat_t lcol_stat_old; /* previous interval's statistics */
160 	lprocess_t *lcol_lprocess;	/* member processes */
161 	int lcol_mark;			/* mark-and-sweep flag */
162 	lprocess_t *lcol_victim;	/* victim process to resume scanning */
163 	void *lcol_resaddr;		/* address to resume scanning from */
164 } lcollection_t;
165 
166 /*
167  * Collection report.
168  */
169 typedef struct lcollection_report {
170 	rcid_t lcol_id;			/* numerical ID for this collection */
171 	char lcol_name[LC_NAME_LEN];	/* name of this collection, or */
172 					/* "unknown" */
173 	uint64_t lcol_rss;		/* RSS of all processes (kB) */
174 	uint64_t lcol_image_size;	/* image size of all processes (kB) */
175 	uint64_t lcol_rss_cap;		/* RSS limit (kB) */
176 	lcollection_stat_t lcol_stat;	/* statistics */
177 } lcollection_report_t;
178 
179 extern int get_psinfo(pid_t, struct psinfo *, int, int(*)(void *, int), void *,
180     lprocess_t *);
181 extern lcollection_t *lcollection_find(rcid_t *);
182 extern void lcollection_freq_move(lprocess_t *);
183 extern lcollection_t *lcollection_insert_update(rcid_t *, uint64_t, char *,
184     int *changes);
185 extern int lcollection_member(lcollection_t *, lprocess_t *);
186 extern void lcollection_free(lcollection_t *);
187 extern void lcollection_update(lcollection_update_type_t);
188 extern void list_walk_collection(int (*)(lcollection_t *, void *), void *);
189 extern int lprocess_update_psinfo_fd_cb(void *, int);
190 extern void lprocess_free(lprocess_t *);
191 extern void scan(lcollection_t *, int64_t);
192 extern void scan_abort(void);
193 extern void check_update_statistics(void);
194 
195 /*
196  * Global (in rcapd only) variables.
197  */
198 extern rcfg_t rcfg;
199 extern uint64_t phys_total;
200 extern int should_run;
201 
202 #ifdef	__cplusplus
203 }
204 #endif
205 
206 #endif /* _RCAPD_H */
207