Print this page
OS-399 zone phys. mem. cap should be a rctl and have associated kstat


   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 /*
  23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.

  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/stat.h>
  28 #include <sys/wait.h>
  29 #include <fcntl.h>
  30 #include <errno.h>
  31 #include <signal.h>
  32 #include <stdio.h>
  33 #include <stdlib.h>
  34 #include <strings.h>
  35 #include <unistd.h>
  36 #include <libscf.h>
  37 #include <libscf_priv.h>
  38 #include <libintl.h>
  39 #include <locale.h>
  40 #include <zone.h>
  41 #include <libzonecfg.h>
  42 
  43 #include "utils.h"


 128                 (void) printf(gettext("                                      "
 129                     "state: %s\n"), *persistent ? gettext("enabled") :
 130                     gettext("disabled"));
 131 
 132         (void) printf(gettext("           memory cap enforcement"
 133             " threshold: %d%%\n"), conf.rcfg_memory_cap_enforcement_pressure);
 134         (void) printf(gettext("                    process scan rate"
 135             " (sec): %d\n"), conf.rcfg_proc_walk_interval);
 136         (void) printf(gettext("                 reconfiguration rate"
 137             " (sec): %d\n"), conf.rcfg_reconfiguration_interval);
 138         (void) printf(gettext("                          report rate"
 139             " (sec): %d\n"), conf.rcfg_report_interval);
 140         (void) printf(gettext("                    RSS sampling rate"
 141             " (sec): %d\n"), conf.rcfg_rss_sample_interval);
 142 
 143         scf_simple_prop_free(temporary_prop);
 144         scf_simple_prop_free(persistent_prop);
 145         scf_handle_destroy(h);
 146 }
 147 










 148 /*
 149  * Update the in-kernel memory cap for the specified zone.
 150  */
 151 static int
 152 update_zone_mcap(char *zonename, char *maxrss)
 153 {
 154         zoneid_t zone_id;
 155         uint64_t num;
 156 
 157         if (getzoneid() != GLOBAL_ZONEID || zonecfg_in_alt_root())
 158                 return (E_SUCCESS);
 159 
 160         /* get the running zone from the kernel */
 161         if ((zone_id = getzoneidbyname(zonename)) == -1) {
 162                 (void) fprintf(stderr, gettext("zone '%s' must be running\n"),
 163                     zonename);
 164                 return (E_ERROR);
 165         }
 166 
 167         if (zonecfg_str_to_bytes(maxrss, &num) == -1) {
 168                 (void) fprintf(stderr, gettext("invalid max-rss value\n"));
 169                 return (E_ERROR);
 170         }
 171 
 172         if (zone_setattr(zone_id, ZONE_ATTR_PHYS_MCAP, &num, 0) == -1) {
 173                 (void) fprintf(stderr, gettext("could not set memory "
 174                     "cap for zone '%s'\n"), zonename);
 175                 return (E_ERROR);
 176         }
 177 
 178         return (E_SUCCESS);
 179 }
 180 
 181 int
 182 main(int argc, char *argv[])
 183 {
 184         char *subopts, *optval;
 185         int modified = 0;
 186         boolean_t refresh = B_FALSE;
 187         int opt;
 188         char *zonename;
 189         char *maxrss = NULL;
 190 
 191         (void) setpname("rcapadm");
 192         (void) setlocale(LC_ALL, "");




   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 /*
  23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
  25  */
  26 
  27 #include <sys/types.h>
  28 #include <sys/stat.h>
  29 #include <sys/wait.h>
  30 #include <fcntl.h>
  31 #include <errno.h>
  32 #include <signal.h>
  33 #include <stdio.h>
  34 #include <stdlib.h>
  35 #include <strings.h>
  36 #include <unistd.h>
  37 #include <libscf.h>
  38 #include <libscf_priv.h>
  39 #include <libintl.h>
  40 #include <locale.h>
  41 #include <zone.h>
  42 #include <libzonecfg.h>
  43 
  44 #include "utils.h"


 129                 (void) printf(gettext("                                      "
 130                     "state: %s\n"), *persistent ? gettext("enabled") :
 131                     gettext("disabled"));
 132 
 133         (void) printf(gettext("           memory cap enforcement"
 134             " threshold: %d%%\n"), conf.rcfg_memory_cap_enforcement_pressure);
 135         (void) printf(gettext("                    process scan rate"
 136             " (sec): %d\n"), conf.rcfg_proc_walk_interval);
 137         (void) printf(gettext("                 reconfiguration rate"
 138             " (sec): %d\n"), conf.rcfg_reconfiguration_interval);
 139         (void) printf(gettext("                          report rate"
 140             " (sec): %d\n"), conf.rcfg_report_interval);
 141         (void) printf(gettext("                    RSS sampling rate"
 142             " (sec): %d\n"), conf.rcfg_rss_sample_interval);
 143 
 144         scf_simple_prop_free(temporary_prop);
 145         scf_simple_prop_free(persistent_prop);
 146         scf_handle_destroy(h);
 147 }
 148 
 149 static int
 150 set_zone_cap(char *zonename, uint64_t mcap)
 151 {
 152         char cmd[128 + ZONENAME_MAX];
 153 
 154         (void) snprintf(cmd, sizeof (cmd), "/usr/bin/prctl -r "
 155             "-n zone.max-physical-memory -v %llu -i zone %s", mcap, zonename);
 156         return (system(cmd));
 157 }
 158 
 159 /*
 160  * Update the in-kernel memory cap for the specified zone.
 161  */
 162 static int
 163 update_zone_mcap(char *zonename, char *maxrss)
 164 {

 165         uint64_t num;
 166 
 167         if (getzoneid() != GLOBAL_ZONEID || zonecfg_in_alt_root())
 168                 return (E_SUCCESS);
 169 
 170         /* get the running zone from the kernel */
 171         if (getzoneidbyname(zonename) == -1) {
 172                 (void) fprintf(stderr, gettext("zone '%s' must be running\n"),
 173                     zonename);
 174                 return (E_ERROR);
 175         }
 176 
 177         if (zonecfg_str_to_bytes(maxrss, &num) == -1) {
 178                 (void) fprintf(stderr, gettext("invalid max-rss value\n"));
 179                 return (E_ERROR);
 180         }
 181 
 182         if (set_zone_cap(zonename, num) == -1) {
 183                 (void) fprintf(stderr, gettext("could not set memory "
 184                     "cap for zone '%s'\n"), zonename);
 185                 return (E_ERROR);
 186         }
 187 
 188         return (E_SUCCESS);
 189 }
 190 
 191 int
 192 main(int argc, char *argv[])
 193 {
 194         char *subopts, *optval;
 195         int modified = 0;
 196         boolean_t refresh = B_FALSE;
 197         int opt;
 198         char *zonename;
 199         char *maxrss = NULL;
 200 
 201         (void) setpname("rcapadm");
 202         (void) setlocale(LC_ALL, "");