Print this page
2831 svc.startd and svc.configd waste memory.

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/svc/startd/restarter.c
          +++ new/usr/src/cmd/svc/startd/restarter.c
↓ open down ↓ 365 lines elided ↑ open up ↑
 366  366          pg = safe_scf_pg_create(h);
 367  367          svc_name = startd_alloc(max_scf_name_size);
 368  368          inst_name = startd_alloc(max_scf_name_size);
 369  369  
 370  370  rep_retry:
 371  371          if (snap != NULL)
 372  372                  scf_snapshot_destroy(snap);
 373  373          if (inst->ri_logstem != NULL)
 374  374                  startd_free(inst->ri_logstem, PATH_MAX);
 375  375          if (inst->ri_common_name != NULL)
 376      -                startd_free(inst->ri_common_name, max_scf_value_size);
      376 +                startd_free(inst->ri_common_name,
      377 +                    strlen(inst->ri_common_name) + 1);
 377  378          if (inst->ri_C_common_name != NULL)
 378      -                startd_free(inst->ri_C_common_name, max_scf_value_size);
      379 +                startd_free(inst->ri_C_common_name,
      380 +                    strlen(inst->ri_C_common_name) + 1);
 379  381          snap = NULL;
 380  382          inst->ri_logstem = NULL;
 381  383          inst->ri_common_name = NULL;
 382  384          inst->ri_C_common_name = NULL;
 383  385  
 384  386          if (scf_handle_decode_fmri(h, name, NULL, scf_svc, scf_inst, NULL,
 385  387              NULL, SCF_DECODE_FMRI_EXACT) != 0) {
 386  388                  switch (scf_error()) {
 387  389                  case SCF_ERROR_CONNECTION_BROKEN:
 388  390                          libscf_handle_rebind(h);
↓ open down ↓ 133 lines elided ↑ open up ↑
 522  524                   * group has been deleted.
 523  525                   */
 524  526                  inst->ri_flags = RINST_CONTRACT;
 525  527                  break;
 526  528  
 527  529          default:
 528  530                  assert(0);
 529  531                  abort();
 530  532          }
 531  533  
 532      -        switch (libscf_get_template_values(scf_inst, snap,
 533      -            &inst->ri_common_name, &inst->ri_C_common_name)) {
      534 +        r = libscf_get_template_values(scf_inst, snap,
      535 +            &inst->ri_common_name, &inst->ri_C_common_name);
      536 +
      537 +        /*
      538 +         * Copy our names to smaller buffers to reduce our memory footprint.
      539 +         */
      540 +        if (inst->ri_common_name != NULL) {
      541 +                char *tmp = safe_strdup(inst->ri_common_name);
      542 +                startd_free(inst->ri_common_name, max_scf_value_size);
      543 +                inst->ri_common_name = tmp;
      544 +        }
      545 +
      546 +        if (inst->ri_C_common_name != NULL) {
      547 +                char *tmp = safe_strdup(inst->ri_C_common_name);
      548 +                startd_free(inst->ri_C_common_name, max_scf_value_size);
      549 +                inst->ri_C_common_name = tmp;
      550 +        }
      551 +
      552 +        switch (r) {
 534  553          case 0:
 535  554                  break;
 536  555  
 537  556          case ECONNABORTED:
 538  557                  libscf_handle_rebind(h);
 539  558                  goto rep_retry;
 540  559  
 541  560          case ECANCELED:
 542  561                  goto deleted;
 543  562  
↓ open down ↓ 127 lines elided ↑ open up ↑
 671  690          if (snap != NULL)
 672  691                  scf_snapshot_destroy(snap);
 673  692          scf_pg_destroy(pg);
 674  693          scf_instance_destroy(scf_inst);
 675  694          scf_service_destroy(scf_svc);
 676  695          startd_free((void *)inst->ri_i.i_fmri, strlen(inst->ri_i.i_fmri) + 1);
 677  696          uu_list_destroy(inst->ri_queue);
 678  697          if (inst->ri_logstem != NULL)
 679  698                  startd_free(inst->ri_logstem, PATH_MAX);
 680  699          if (inst->ri_common_name != NULL)
 681      -                startd_free(inst->ri_common_name, max_scf_value_size);
      700 +                startd_free(inst->ri_common_name,
      701 +                    strlen(inst->ri_common_name) + 1);
 682  702          if (inst->ri_C_common_name != NULL)
 683      -                startd_free(inst->ri_C_common_name, max_scf_value_size);
      703 +                startd_free(inst->ri_C_common_name,
      704 +                    strlen(inst->ri_C_common_name) + 1);
 684  705          startd_free(inst->ri_utmpx_prefix, max_scf_value_size);
 685  706          startd_free(inst, sizeof (restarter_inst_t));
 686  707          return (ENOENT);
 687  708  }
 688  709  
 689  710  static void
 690  711  restarter_delete_inst(restarter_inst_t *ri)
 691  712  {
 692  713          int id;
 693  714          restarter_inst_t *rip;
↓ open down ↓ 39 lines elided ↑ open up ↑
 733  754          while (ri->ri_method_thread != 0 || ri->ri_method_waiters > 0)
 734  755                  (void) pthread_cond_wait(&ri->ri_method_cv, &ri->ri_lock);
 735  756  
 736  757          while ((e = uu_list_teardown(ri->ri_queue, &cookie)) != NULL)
 737  758                  startd_free(e, sizeof (*e));
 738  759          uu_list_destroy(ri->ri_queue);
 739  760  
 740  761          startd_free((void *)ri->ri_i.i_fmri, strlen(ri->ri_i.i_fmri) + 1);
 741  762          startd_free(ri->ri_logstem, PATH_MAX);
 742  763          if (ri->ri_common_name != NULL)
 743      -                startd_free(ri->ri_common_name, max_scf_value_size);
      764 +                startd_free(ri->ri_common_name,
      765 +                    strlen(ri->ri_common_name) + 1);
 744  766          if (ri->ri_C_common_name != NULL)
 745      -                startd_free(ri->ri_C_common_name, max_scf_value_size);
      767 +                startd_free(ri->ri_C_common_name,
      768 +                    strlen(ri->ri_C_common_name) + 1);
 746  769          startd_free(ri->ri_utmpx_prefix, max_scf_value_size);
 747  770          (void) pthread_mutex_destroy(&ri->ri_lock);
 748  771          (void) pthread_mutex_destroy(&ri->ri_queue_lock);
 749  772          startd_free(ri, sizeof (restarter_inst_t));
 750  773  }
 751  774  
 752  775  /*
 753  776   * instance_is_wait_style()
 754  777   *
 755  778   *   Returns 1 if the given instance is a "wait-style" service instance.
↓ open down ↓ 1078 lines elided ↑ open up ↑
1834 1857          to.tv_sec = 3;
1835 1858          to.tv_nsec = 0;
1836 1859          (void) pthread_cond_reltimedwait_np(&rip->ri_queue_cv,
1837 1860              &rip->ri_queue_lock, &to);
1838 1861  
1839 1862          if (uu_list_first(rip->ri_queue) != NULL)
1840 1863                  goto again;
1841 1864  
1842 1865          rip->ri_queue_thread = 0;
1843 1866          MUTEX_UNLOCK(&rip->ri_queue_lock);
     1867 +
1844 1868  out:
1845 1869          (void) scf_handle_unbind(h);
1846 1870          scf_handle_destroy(h);
1847 1871          free(fmri);
1848 1872          return (NULL);
1849 1873  }
1850 1874  
1851 1875  static int
1852 1876  is_admin_event(restarter_event_type_t t) {
1853 1877  
↓ open down ↓ 664 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX