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 5*0209230bSgjelinek * Common Development and Distribution License (the "License"). 6*0209230bSgjelinek * 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*0209230bSgjelinek * Copyright 2006 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 407c478bd9Sstevel@tonic-gate #define RCAPD_DEFAULT_CONF_FILE "/etc/rcap.conf" 417c478bd9Sstevel@tonic-gate #define RCAPD_IGNORED_SET_FLUSH_IVAL 10 /* number of scans between */ 427c478bd9Sstevel@tonic-gate /* flushes of the ignored set */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * set the buffer length for /proc-based path names based on the actual 467c478bd9Sstevel@tonic-gate * length of the largest pid 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate #define RCAPD__STR(a) #a 497c478bd9Sstevel@tonic-gate #define RCAPD_STR(macro) RCAPD__STR(macro) 507c478bd9Sstevel@tonic-gate #define PROC_PATH_MAX (sizeof ("/proc/" RCAPD_STR(PID_MAX) \ 517c478bd9Sstevel@tonic-gate "/pagedata")) 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * lcollection_insert_update() result flags 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate #define LCST_CAP_CHANGED (1<<0) 577c478bd9Sstevel@tonic-gate #define LCST_CAP_REMOVED (1<<1) 587c478bd9Sstevel@tonic-gate #define LCST_CAP_ZERO (1<<2) 597c478bd9Sstevel@tonic-gate 60*0209230bSgjelinek typedef enum { 61*0209230bSgjelinek RCIDT_PROJECT, 62*0209230bSgjelinek RCIDT_ZONE 63*0209230bSgjelinek } rcid_type_t; 64*0209230bSgjelinek 65*0209230bSgjelinek typedef struct { 66*0209230bSgjelinek /* 67*0209230bSgjelinek * The following field could just be a rcid_type_t but it gets 68*0209230bSgjelinek * written out to a file as binary data for communication between 69*0209230bSgjelinek * 64-bit rcapd & 32-bit rcapstat, so we need to force a standard size 70*0209230bSgjelinek * and alignment here. 71*0209230bSgjelinek */ 72*0209230bSgjelinek uint64_t rcid_type; 73*0209230bSgjelinek int64_t rcid_val; 74*0209230bSgjelinek } rcid_t; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate typedef enum { 777c478bd9Sstevel@tonic-gate LCU_COMPLETE, /* an enumeration of all possible collections */ 787c478bd9Sstevel@tonic-gate LCU_ACTIVE_ONLY /* an enumeration of only once-active collections */ 797c478bd9Sstevel@tonic-gate } lcollection_update_type_t; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate struct lmapping; 827c478bd9Sstevel@tonic-gate struct lprocess; 837c478bd9Sstevel@tonic-gate struct lcollection; 847c478bd9Sstevel@tonic-gate struct prxmap; 857c478bd9Sstevel@tonic-gate struct psinfo; 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* 887c478bd9Sstevel@tonic-gate * Per-process data. 897c478bd9Sstevel@tonic-gate */ 907c478bd9Sstevel@tonic-gate typedef struct lprocess { 917c478bd9Sstevel@tonic-gate struct lprocess *lpc_prev; /* global process list */ 927c478bd9Sstevel@tonic-gate struct lprocess *lpc_next; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate pid_t lpc_pid; /* ID of this process */ 957c478bd9Sstevel@tonic-gate int lpc_unscannable; /* flag indicating zombie or */ 967c478bd9Sstevel@tonic-gate /* other unscannable process */ 977c478bd9Sstevel@tonic-gate uint64_t lpc_rss; /* resident set size (kB) */ 987c478bd9Sstevel@tonic-gate uint64_t lpc_unrm; /* scannable set size (kB) (est.) */ 997c478bd9Sstevel@tonic-gate uint64_t lpc_size; /* process image size (kB) */ 1007c478bd9Sstevel@tonic-gate int lpc_mark; /* mark-and-sweep flag */ 1017c478bd9Sstevel@tonic-gate struct lcollection *lpc_collection; /* owning collection */ 1027c478bd9Sstevel@tonic-gate int lpc_psinfo_fd; /* cached psinfo fd */ 1037c478bd9Sstevel@tonic-gate int lpc_pgdata_fd; /* cached pagedata fd */ 1047c478bd9Sstevel@tonic-gate int lpc_xmap_fd; /* cached xmap fd */ 1057c478bd9Sstevel@tonic-gate struct prxmap *lpc_xmap; /* xmap corresponding to */ 1067c478bd9Sstevel@tonic-gate /* current pagedata */ 1077c478bd9Sstevel@tonic-gate int lpc_nxmap; /* number of mappings in xmap */ 1087c478bd9Sstevel@tonic-gate prpageheader_t *lpc_prpageheader; /* accumulated mask of */ 1097c478bd9Sstevel@tonic-gate /* process's ref/mod bits */ 1107c478bd9Sstevel@tonic-gate struct lmapping *lpc_ignore; /* empirically-unpageable mappings */ 1117c478bd9Sstevel@tonic-gate } lprocess_t; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate /* 1147c478bd9Sstevel@tonic-gate * Collection statistics. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate typedef struct { 1177c478bd9Sstevel@tonic-gate uint64_t lcols_scan; /* scan attempts */ 1187c478bd9Sstevel@tonic-gate uint64_t lcols_pg_att; /* kB attempted to page */ 1197c478bd9Sstevel@tonic-gate uint64_t lcols_pg_eff; /* kB paged out (est.) */ 1207c478bd9Sstevel@tonic-gate uint64_t lcols_rss_sample; /* RSS samplings */ 1217c478bd9Sstevel@tonic-gate uint64_t lcols_unenforced_cap; /* times cap could have been */ 1227c478bd9Sstevel@tonic-gate /* enforced, but wasn't (due to low */ 1237c478bd9Sstevel@tonic-gate /* global memory pressure, or global */ 1247c478bd9Sstevel@tonic-gate /* scanner being activated) */ 1257c478bd9Sstevel@tonic-gate uint64_t lcols_rss_sum; /* sum of sampled RSS values */ 1267c478bd9Sstevel@tonic-gate uint64_t lcols_rss_act_sum; /* sum of sampled, excess RSS values */ 1277c478bd9Sstevel@tonic-gate uint64_t lcols_min_rss; /* minimum RSS (kB), this interval */ 1287c478bd9Sstevel@tonic-gate uint64_t lcols_max_rss; /* maximum RSS (kB), this interval */ 1297c478bd9Sstevel@tonic-gate uint64_t lcols_proc_in; /* processes tracked */ 1307c478bd9Sstevel@tonic-gate uint64_t lcols_proc_out; /* processes freed */ 1317c478bd9Sstevel@tonic-gate hrtime_t lcols_scan_time; /* time spent scanning (ns) */ 1327c478bd9Sstevel@tonic-gate hrtime_t lcols_scan_time_complete; /* time spent scanning (ns) */ 1337c478bd9Sstevel@tonic-gate /* at last completion */ 1347c478bd9Sstevel@tonic-gate uint64_t lcols_scan_count; /* number of complete scans */ 1357c478bd9Sstevel@tonic-gate uint64_t lcols_scan_ineffective; /* number of uninterrupted */ 1367c478bd9Sstevel@tonic-gate /* revolutions of clock hand after */ 1377c478bd9Sstevel@tonic-gate /* which the excess was not */ 1387c478bd9Sstevel@tonic-gate /* completely reduced */ 1397c478bd9Sstevel@tonic-gate } lcollection_stat_t; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * Collection. 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate typedef struct lcollection { 1457c478bd9Sstevel@tonic-gate struct lcollection *lcol_prev; /* global collection list */ 1467c478bd9Sstevel@tonic-gate struct lcollection *lcol_next; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate rcid_t lcol_id; /* numerical ID for this collection */ 1497c478bd9Sstevel@tonic-gate char lcol_name[LC_NAME_LEN]; /* name of this collection, or */ 1507c478bd9Sstevel@tonic-gate /* "unknown" */ 1517c478bd9Sstevel@tonic-gate uint64_t lcol_rss; /* RSS of all processes (kB) */ 1527c478bd9Sstevel@tonic-gate uint64_t lcol_image_size; /* image size of all processes (kB) */ 1537c478bd9Sstevel@tonic-gate uint64_t lcol_rss_cap; /* RSS cap (kB) */ 1547c478bd9Sstevel@tonic-gate lcollection_stat_t lcol_stat; /* statistics */ 1557c478bd9Sstevel@tonic-gate lcollection_stat_t lcol_stat_old; /* previous interval's statistics */ 1567c478bd9Sstevel@tonic-gate lprocess_t *lcol_lprocess; /* member processes */ 1577c478bd9Sstevel@tonic-gate int lcol_mark; /* mark-and-sweep flag */ 1587c478bd9Sstevel@tonic-gate lprocess_t *lcol_victim; /* victim process to resume scanning */ 1597c478bd9Sstevel@tonic-gate void *lcol_resaddr; /* address to resume scanning from */ 1607c478bd9Sstevel@tonic-gate } lcollection_t; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate /* 1637c478bd9Sstevel@tonic-gate * Collection report. 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate typedef struct lcollection_report { 1667c478bd9Sstevel@tonic-gate rcid_t lcol_id; /* numerical ID for this collection */ 1677c478bd9Sstevel@tonic-gate char lcol_name[LC_NAME_LEN]; /* name of this collection, or */ 1687c478bd9Sstevel@tonic-gate /* "unknown" */ 1697c478bd9Sstevel@tonic-gate uint64_t lcol_rss; /* RSS of all processes (kB) */ 1707c478bd9Sstevel@tonic-gate uint64_t lcol_image_size; /* image size of all processes (kB) */ 1717c478bd9Sstevel@tonic-gate uint64_t lcol_rss_cap; /* RSS limit (kB) */ 1727c478bd9Sstevel@tonic-gate lcollection_stat_t lcol_stat; /* statistics */ 1737c478bd9Sstevel@tonic-gate } lcollection_report_t; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate extern int get_psinfo(pid_t, struct psinfo *, int, int(*)(void *, int), void *, 1767c478bd9Sstevel@tonic-gate lprocess_t *); 177*0209230bSgjelinek extern lcollection_t *lcollection_find(rcid_t *); 1787c478bd9Sstevel@tonic-gate extern void lcollection_freq_move(lprocess_t *); 179*0209230bSgjelinek extern lcollection_t *lcollection_insert_update(rcid_t *, uint64_t, char *, 1807c478bd9Sstevel@tonic-gate int *changes); 1817c478bd9Sstevel@tonic-gate extern int lcollection_member(lcollection_t *, lprocess_t *); 1827c478bd9Sstevel@tonic-gate extern void lcollection_free(lcollection_t *); 1837c478bd9Sstevel@tonic-gate extern void lcollection_update(lcollection_update_type_t); 1847c478bd9Sstevel@tonic-gate extern void list_walk_collection(int (*)(lcollection_t *, void *), void *); 1857c478bd9Sstevel@tonic-gate extern int lprocess_update_psinfo_fd_cb(void *, int); 1867c478bd9Sstevel@tonic-gate extern void lprocess_free(lprocess_t *); 1877c478bd9Sstevel@tonic-gate extern void scan(lcollection_t *, int64_t); 1887c478bd9Sstevel@tonic-gate extern void scan_abort(void); 1897c478bd9Sstevel@tonic-gate extern void check_update_statistics(void); 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * Global (in rcapd only) variables. 1937c478bd9Sstevel@tonic-gate */ 1947c478bd9Sstevel@tonic-gate extern rcfg_t rcfg; 1957c478bd9Sstevel@tonic-gate extern uint64_t phys_total; 1967c478bd9Sstevel@tonic-gate extern int should_run; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate #endif 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate #endif /* _RCAPD_H */ 203