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