Print this page
OS-399 zone phys. mem. cap should be a rctl and have associated kstat
        
*** 19,28 ****
--- 19,29 ----
   * CDDL HEADER END
   */
  
  /*
   * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
   */
  
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <sys/wait.h>
*** 143,166 ****
          scf_simple_prop_free(temporary_prop);
          scf_simple_prop_free(persistent_prop);
          scf_handle_destroy(h);
  }
  
  /*
   * Update the in-kernel memory cap for the specified zone.
   */
  static int
  update_zone_mcap(char *zonename, char *maxrss)
  {
-         zoneid_t zone_id;
          uint64_t num;
  
          if (getzoneid() != GLOBAL_ZONEID || zonecfg_in_alt_root())
                  return (E_SUCCESS);
  
          /* get the running zone from the kernel */
!         if ((zone_id = getzoneidbyname(zonename)) == -1) {
                  (void) fprintf(stderr, gettext("zone '%s' must be running\n"),
                      zonename);
                  return (E_ERROR);
          }
  
--- 144,176 ----
          scf_simple_prop_free(temporary_prop);
          scf_simple_prop_free(persistent_prop);
          scf_handle_destroy(h);
  }
  
+ static int
+ set_zone_cap(char *zonename, uint64_t mcap)
+ {
+         char cmd[128 + ZONENAME_MAX];
+ 
+         (void) snprintf(cmd, sizeof (cmd), "/usr/bin/prctl -r "
+             "-n zone.max-physical-memory -v %llu -i zone %s", mcap, zonename);
+         return (system(cmd));
+ }
+ 
  /*
   * Update the in-kernel memory cap for the specified zone.
   */
  static int
  update_zone_mcap(char *zonename, char *maxrss)
  {
          uint64_t num;
  
          if (getzoneid() != GLOBAL_ZONEID || zonecfg_in_alt_root())
                  return (E_SUCCESS);
  
          /* get the running zone from the kernel */
!         if (getzoneidbyname(zonename) == -1) {
                  (void) fprintf(stderr, gettext("zone '%s' must be running\n"),
                      zonename);
                  return (E_ERROR);
          }
  
*** 167,177 ****
          if (zonecfg_str_to_bytes(maxrss, &num) == -1) {
                  (void) fprintf(stderr, gettext("invalid max-rss value\n"));
                  return (E_ERROR);
          }
  
!         if (zone_setattr(zone_id, ZONE_ATTR_PHYS_MCAP, &num, 0) == -1) {
                  (void) fprintf(stderr, gettext("could not set memory "
                      "cap for zone '%s'\n"), zonename);
                  return (E_ERROR);
          }
  
--- 177,187 ----
          if (zonecfg_str_to_bytes(maxrss, &num) == -1) {
                  (void) fprintf(stderr, gettext("invalid max-rss value\n"));
                  return (E_ERROR);
          }
  
!         if (set_zone_cap(zonename, num) == -1) {
                  (void) fprintf(stderr, gettext("could not set memory "
                      "cap for zone '%s'\n"), zonename);
                  return (E_ERROR);
          }