xref: /titanic_52/usr/src/cmd/rcap/common/rcapd.h (revision d75e6a5d480f559280524b60d52730c76a25524f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50209230bSgjelinek  * Common Development and Distribution License (the "License").
60209230bSgjelinek  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d75e6a5dStn143363  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _RCAPD_H
277c478bd9Sstevel@tonic-gate #define	_RCAPD_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <procfs.h>
377c478bd9Sstevel@tonic-gate #include "rcapd_conf.h"
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #define	LC_NAME_LEN			32
40*d75e6a5dStn143363 #define	RCAP_FMRI			"svc:/system/rcap:default"
41*d75e6a5dStn143363 #define	CONFIG_PG			"config"
42*d75e6a5dStn143363 #define	PRESSURE			"pressure"
43*d75e6a5dStn143363 #define	RECONFIG_INT			"reconfig_interval"
44*d75e6a5dStn143363 #define	REPORT_INT			"report_interval"
45*d75e6a5dStn143363 #define	RSS_SAMPLE_INT			"rss_sample_interval"
46*d75e6a5dStn143363 #define	WALK_INT			"walk_interval"
477c478bd9Sstevel@tonic-gate #define	RCAPD_IGNORED_SET_FLUSH_IVAL	10	/* number of scans between */
487c478bd9Sstevel@tonic-gate 						/* flushes of the ignored set */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * set the buffer length for /proc-based path names based on the actual
527c478bd9Sstevel@tonic-gate  * length of the largest pid
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate #define	RCAPD__STR(a)		#a
557c478bd9Sstevel@tonic-gate #define	RCAPD_STR(macro)	RCAPD__STR(macro)
567c478bd9Sstevel@tonic-gate #define	PROC_PATH_MAX		(sizeof ("/proc/" RCAPD_STR(PID_MAX) \
577c478bd9Sstevel@tonic-gate 				    "/pagedata"))
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * lcollection_insert_update() result flags
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate #define	LCST_CAP_CHANGED		(1<<0)
637c478bd9Sstevel@tonic-gate #define	LCST_CAP_REMOVED		(1<<1)
647c478bd9Sstevel@tonic-gate #define	LCST_CAP_ZERO			(1<<2)
657c478bd9Sstevel@tonic-gate 
660209230bSgjelinek typedef enum {
670209230bSgjelinek 	RCIDT_PROJECT,
680209230bSgjelinek 	RCIDT_ZONE
690209230bSgjelinek } rcid_type_t;
700209230bSgjelinek 
710209230bSgjelinek typedef struct {
720209230bSgjelinek 	/*
730209230bSgjelinek 	 * The following field could just be a rcid_type_t but it gets
740209230bSgjelinek 	 * written out to a file as binary data for communication between
750209230bSgjelinek 	 * 64-bit rcapd & 32-bit rcapstat, so we need to force a standard size
760209230bSgjelinek 	 * and alignment here.
770209230bSgjelinek 	 */
780209230bSgjelinek 	uint64_t	rcid_type;
790209230bSgjelinek 	int64_t		rcid_val;
800209230bSgjelinek } rcid_t;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate typedef enum {
837c478bd9Sstevel@tonic-gate 	LCU_COMPLETE,	/* an enumeration of all possible collections */
847c478bd9Sstevel@tonic-gate 	LCU_ACTIVE_ONLY	/* an enumeration of only once-active collections */
857c478bd9Sstevel@tonic-gate } lcollection_update_type_t;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate struct lmapping;
887c478bd9Sstevel@tonic-gate struct lprocess;
897c478bd9Sstevel@tonic-gate struct lcollection;
907c478bd9Sstevel@tonic-gate struct prxmap;
917c478bd9Sstevel@tonic-gate struct psinfo;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * Per-process data.
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate typedef struct lprocess {
977c478bd9Sstevel@tonic-gate 	struct lprocess *lpc_prev;	/* global process list */
987c478bd9Sstevel@tonic-gate 	struct lprocess *lpc_next;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	pid_t		lpc_pid;	/* ID of this process */
1017c478bd9Sstevel@tonic-gate 	int		lpc_unscannable; /* flag indicating zombie or */
1027c478bd9Sstevel@tonic-gate 					/* other unscannable process */
1037c478bd9Sstevel@tonic-gate 	uint64_t	lpc_rss;	/* resident set size (kB) */
1047c478bd9Sstevel@tonic-gate 	uint64_t	lpc_unrm;	/* scannable set size (kB) (est.) */
1057c478bd9Sstevel@tonic-gate 	uint64_t	lpc_size;	/* process image size (kB) */
1067c478bd9Sstevel@tonic-gate 	int		lpc_mark;	/* mark-and-sweep flag */
1077c478bd9Sstevel@tonic-gate 	struct lcollection *lpc_collection; /* owning collection */
1087c478bd9Sstevel@tonic-gate 	int		lpc_psinfo_fd;	/* cached psinfo fd */
1097c478bd9Sstevel@tonic-gate 	int		lpc_pgdata_fd;	/* cached pagedata fd */
1107c478bd9Sstevel@tonic-gate 	int		lpc_xmap_fd;	/* cached xmap fd */
1117c478bd9Sstevel@tonic-gate 	struct prxmap	*lpc_xmap;	/* xmap corresponding to */
1127c478bd9Sstevel@tonic-gate 					/* current pagedata */
1137c478bd9Sstevel@tonic-gate 	int		lpc_nxmap;	/* number of mappings in xmap */
1147c478bd9Sstevel@tonic-gate 	prpageheader_t *lpc_prpageheader; /* accumulated mask of */
1157c478bd9Sstevel@tonic-gate 					/* process's ref/mod bits */
1167c478bd9Sstevel@tonic-gate 	struct lmapping	*lpc_ignore;	/* empirically-unpageable mappings */
1177c478bd9Sstevel@tonic-gate } lprocess_t;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate  * Collection statistics.
1217c478bd9Sstevel@tonic-gate  */
1227c478bd9Sstevel@tonic-gate typedef struct {
1237c478bd9Sstevel@tonic-gate 	uint64_t lcols_scan;		/* scan attempts */
1247c478bd9Sstevel@tonic-gate 	uint64_t lcols_pg_att;		/* kB attempted to page */
1257c478bd9Sstevel@tonic-gate 	uint64_t lcols_pg_eff;		/* kB paged out (est.) */
1267c478bd9Sstevel@tonic-gate 	uint64_t lcols_rss_sample;	/* RSS samplings */
1277c478bd9Sstevel@tonic-gate 	uint64_t lcols_unenforced_cap;	/* times cap could have been */
1287c478bd9Sstevel@tonic-gate 					/* enforced, but wasn't (due to low */
1297c478bd9Sstevel@tonic-gate 					/* global memory pressure, or global */
1307c478bd9Sstevel@tonic-gate 					/* scanner being activated) */
1317c478bd9Sstevel@tonic-gate 	uint64_t lcols_rss_sum;		/* sum of sampled RSS values */
1327c478bd9Sstevel@tonic-gate 	uint64_t lcols_rss_act_sum;	/* sum of sampled, excess RSS values */
1337c478bd9Sstevel@tonic-gate 	uint64_t lcols_min_rss;		/* minimum RSS (kB), this interval */
1347c478bd9Sstevel@tonic-gate 	uint64_t lcols_max_rss;		/* maximum RSS (kB), this interval */
1357c478bd9Sstevel@tonic-gate 	uint64_t lcols_proc_in;		/* processes tracked */
1367c478bd9Sstevel@tonic-gate 	uint64_t lcols_proc_out;	/* processes freed */
1377c478bd9Sstevel@tonic-gate 	hrtime_t lcols_scan_time;	/* time spent scanning (ns) */
1387c478bd9Sstevel@tonic-gate 	hrtime_t lcols_scan_time_complete; /* time spent scanning (ns) */
1397c478bd9Sstevel@tonic-gate 					/* at last completion */
1407c478bd9Sstevel@tonic-gate 	uint64_t lcols_scan_count;	/* number of complete scans */
1417c478bd9Sstevel@tonic-gate 	uint64_t lcols_scan_ineffective; /* number of uninterrupted */
1427c478bd9Sstevel@tonic-gate 					/* revolutions of clock hand after */
1437c478bd9Sstevel@tonic-gate 					/* which the excess was not */
1447c478bd9Sstevel@tonic-gate 					/* completely reduced */
1457c478bd9Sstevel@tonic-gate } lcollection_stat_t;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate  * Collection.
1497c478bd9Sstevel@tonic-gate  */
1507c478bd9Sstevel@tonic-gate typedef struct lcollection {
1517c478bd9Sstevel@tonic-gate 	struct lcollection *lcol_prev;	/* global collection list */
1527c478bd9Sstevel@tonic-gate 	struct lcollection *lcol_next;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	rcid_t lcol_id;			/* numerical ID for this collection */
1557c478bd9Sstevel@tonic-gate 	char lcol_name[LC_NAME_LEN];	/* name of this collection, or */
1567c478bd9Sstevel@tonic-gate 					/* "unknown" */
1577c478bd9Sstevel@tonic-gate 	uint64_t lcol_rss;		/* RSS of all processes (kB) */
1587c478bd9Sstevel@tonic-gate 	uint64_t lcol_image_size;	/* image size of all processes (kB) */
1597c478bd9Sstevel@tonic-gate 	uint64_t lcol_rss_cap;		/* RSS cap (kB) */
1607c478bd9Sstevel@tonic-gate 	lcollection_stat_t lcol_stat;	/* statistics */
1617c478bd9Sstevel@tonic-gate 	lcollection_stat_t lcol_stat_old; /* previous interval's statistics */
1627c478bd9Sstevel@tonic-gate 	lprocess_t *lcol_lprocess;	/* member processes */
1637c478bd9Sstevel@tonic-gate 	int lcol_mark;			/* mark-and-sweep flag */
1647c478bd9Sstevel@tonic-gate 	lprocess_t *lcol_victim;	/* victim process to resume scanning */
1657c478bd9Sstevel@tonic-gate 	void *lcol_resaddr;		/* address to resume scanning from */
1667c478bd9Sstevel@tonic-gate } lcollection_t;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * Collection report.
1707c478bd9Sstevel@tonic-gate  */
1717c478bd9Sstevel@tonic-gate typedef struct lcollection_report {
1727c478bd9Sstevel@tonic-gate 	rcid_t lcol_id;			/* numerical ID for this collection */
1737c478bd9Sstevel@tonic-gate 	char lcol_name[LC_NAME_LEN];	/* name of this collection, or */
1747c478bd9Sstevel@tonic-gate 					/* "unknown" */
1757c478bd9Sstevel@tonic-gate 	uint64_t lcol_rss;		/* RSS of all processes (kB) */
1767c478bd9Sstevel@tonic-gate 	uint64_t lcol_image_size;	/* image size of all processes (kB) */
1777c478bd9Sstevel@tonic-gate 	uint64_t lcol_rss_cap;		/* RSS limit (kB) */
1787c478bd9Sstevel@tonic-gate 	lcollection_stat_t lcol_stat;	/* statistics */
1797c478bd9Sstevel@tonic-gate } lcollection_report_t;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate extern int get_psinfo(pid_t, struct psinfo *, int, int(*)(void *, int), void *,
1827c478bd9Sstevel@tonic-gate     lprocess_t *);
1830209230bSgjelinek extern lcollection_t *lcollection_find(rcid_t *);
1847c478bd9Sstevel@tonic-gate extern void lcollection_freq_move(lprocess_t *);
1850209230bSgjelinek extern lcollection_t *lcollection_insert_update(rcid_t *, uint64_t, char *,
1867c478bd9Sstevel@tonic-gate     int *changes);
1877c478bd9Sstevel@tonic-gate extern int lcollection_member(lcollection_t *, lprocess_t *);
1887c478bd9Sstevel@tonic-gate extern void lcollection_free(lcollection_t *);
1897c478bd9Sstevel@tonic-gate extern void lcollection_update(lcollection_update_type_t);
1907c478bd9Sstevel@tonic-gate extern void list_walk_collection(int (*)(lcollection_t *, void *), void *);
1917c478bd9Sstevel@tonic-gate extern int lprocess_update_psinfo_fd_cb(void *, int);
1927c478bd9Sstevel@tonic-gate extern void lprocess_free(lprocess_t *);
1937c478bd9Sstevel@tonic-gate extern void scan(lcollection_t *, int64_t);
1947c478bd9Sstevel@tonic-gate extern void scan_abort(void);
1957c478bd9Sstevel@tonic-gate extern void check_update_statistics(void);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * Global (in rcapd only) variables.
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate extern rcfg_t rcfg;
2017c478bd9Sstevel@tonic-gate extern uint64_t phys_total;
2027c478bd9Sstevel@tonic-gate extern int should_run;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate #endif
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate #endif /* _RCAPD_H */
209