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