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