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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/rcap/rcapadm/rcapadm.c
          +++ new/usr/src/cmd/rcap/rcapadm/rcapadm.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright (c) 2011, Joyent, Inc. All rights reserved.
  24   25   */
  25   26  
  26   27  #include <sys/types.h>
  27   28  #include <sys/stat.h>
  28   29  #include <sys/wait.h>
  29   30  #include <fcntl.h>
  30   31  #include <errno.h>
  31   32  #include <signal.h>
  32   33  #include <stdio.h>
  33   34  #include <stdlib.h>
↓ open down ↓ 104 lines elided ↑ open up ↑
 138  139          (void) printf(gettext("                          report rate"
 139  140              " (sec): %d\n"), conf.rcfg_report_interval);
 140  141          (void) printf(gettext("                    RSS sampling rate"
 141  142              " (sec): %d\n"), conf.rcfg_rss_sample_interval);
 142  143  
 143  144          scf_simple_prop_free(temporary_prop);
 144  145          scf_simple_prop_free(persistent_prop);
 145  146          scf_handle_destroy(h);
 146  147  }
 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 +
 148  159  /*
 149  160   * Update the in-kernel memory cap for the specified zone.
 150  161   */
 151  162  static int
 152  163  update_zone_mcap(char *zonename, char *maxrss)
 153  164  {
 154      -        zoneid_t zone_id;
 155  165          uint64_t num;
 156  166  
 157  167          if (getzoneid() != GLOBAL_ZONEID || zonecfg_in_alt_root())
 158  168                  return (E_SUCCESS);
 159  169  
 160  170          /* get the running zone from the kernel */
 161      -        if ((zone_id = getzoneidbyname(zonename)) == -1) {
      171 +        if (getzoneidbyname(zonename) == -1) {
 162  172                  (void) fprintf(stderr, gettext("zone '%s' must be running\n"),
 163  173                      zonename);
 164  174                  return (E_ERROR);
 165  175          }
 166  176  
 167  177          if (zonecfg_str_to_bytes(maxrss, &num) == -1) {
 168  178                  (void) fprintf(stderr, gettext("invalid max-rss value\n"));
 169  179                  return (E_ERROR);
 170  180          }
 171  181  
 172      -        if (zone_setattr(zone_id, ZONE_ATTR_PHYS_MCAP, &num, 0) == -1) {
      182 +        if (set_zone_cap(zonename, num) == -1) {
 173  183                  (void) fprintf(stderr, gettext("could not set memory "
 174  184                      "cap for zone '%s'\n"), zonename);
 175  185                  return (E_ERROR);
 176  186          }
 177  187  
 178  188          return (E_SUCCESS);
 179  189  }
 180  190  
 181  191  int
 182  192  main(int argc, char *argv[])
↓ open down ↓ 159 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX