Print this page
const-ify make segment ops structures
There is no reason to keep the segment ops structures writable.
use NULL capable segop as a shorthand for no-capabilities
Instead of forcing every segment driver to implement a dummy "return 0"
function, handle NULL capable segop function pointer as "no copabilities
supported" shorthand.
segop_getpolicy already checks for a NULL op
seg_inherit_notsup is redundant since segop_inherit checks for NULL properly
no need for bad-op segment op functions
The segment drivers have a number of bad-op functions that simply panic.
Keeping the function pointer NULL will accomplish the same thing in most
cases.  In other cases, keeping the function pointer NULL will result in
proper error code being returned.
use C99 initializers in segment ops structures
remove whole-process swapping
Long before Unix supported paging, it used process swapping to reclaim
memory.  The code is there and in theory it runs when we get *extremely* low
on memory.  In practice, it never runs since the definition of low-on-memory
is antiquated. (XXX: define what antiquated means)
You can check the number of swapout/swapin events with kstats:
$ kstat -p ::vm:swapin ::vm:swapout

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/vm/seg_map.c
          +++ new/usr/src/uts/common/vm/seg_map.c
↓ open down ↓ 79 lines elided ↑ open up ↑
  80   80  static int      segmap_kluster(struct seg *seg, caddr_t addr, ssize_t);
  81   81  static int      segmap_getprot(struct seg *seg, caddr_t addr, size_t len,
  82   82                          uint_t *protv);
  83   83  static u_offset_t       segmap_getoffset(struct seg *seg, caddr_t addr);
  84   84  static int      segmap_gettype(struct seg *seg, caddr_t addr);
  85   85  static int      segmap_getvp(struct seg *seg, caddr_t addr, struct vnode **vpp);
  86   86  static void     segmap_dump(struct seg *seg);
  87   87  static int      segmap_pagelock(struct seg *seg, caddr_t addr, size_t len,
  88   88                          struct page ***ppp, enum lock_type type,
  89   89                          enum seg_rw rw);
  90      -static void     segmap_badop(void);
  91   90  static int      segmap_getmemid(struct seg *seg, caddr_t addr, memid_t *memidp);
  92      -static lgrp_mem_policy_info_t   *segmap_getpolicy(struct seg *seg,
  93      -    caddr_t addr);
  94      -static int      segmap_capable(struct seg *seg, segcapability_t capability);
  95   91  
  96   92  /* segkpm support */
  97   93  static caddr_t  segmap_pagecreate_kpm(struct seg *, vnode_t *, u_offset_t,
  98   94                          struct smap *, enum seg_rw);
  99   95  struct smap     *get_smap_kpm(caddr_t, page_t **);
 100   96  
 101      -#define SEGMAP_BADOP(t) (t(*)())segmap_badop
 102      -
 103      -static struct seg_ops segmap_ops = {
 104      -        SEGMAP_BADOP(int),      /* dup */
 105      -        SEGMAP_BADOP(int),      /* unmap */
 106      -        segmap_free,
 107      -        segmap_fault,
 108      -        segmap_faulta,
 109      -        SEGMAP_BADOP(int),      /* setprot */
 110      -        segmap_checkprot,
 111      -        segmap_kluster,
 112      -        SEGMAP_BADOP(size_t),   /* swapout */
 113      -        SEGMAP_BADOP(int),      /* sync */
 114      -        SEGMAP_BADOP(size_t),   /* incore */
 115      -        SEGMAP_BADOP(int),      /* lockop */
 116      -        segmap_getprot,
 117      -        segmap_getoffset,
 118      -        segmap_gettype,
 119      -        segmap_getvp,
 120      -        SEGMAP_BADOP(int),      /* advise */
 121      -        segmap_dump,
 122      -        segmap_pagelock,        /* pagelock */
 123      -        SEGMAP_BADOP(int),      /* setpgsz */
 124      -        segmap_getmemid,        /* getmemid */
 125      -        segmap_getpolicy,       /* getpolicy */
 126      -        segmap_capable,         /* capable */
 127      -        seg_inherit_notsup      /* inherit */
       97 +static const struct seg_ops segmap_ops = {
       98 +        .free           = segmap_free,
       99 +        .fault          = segmap_fault,
      100 +        .faulta         = segmap_faulta,
      101 +        .checkprot      = segmap_checkprot,
      102 +        .kluster        = segmap_kluster,
      103 +        .getprot        = segmap_getprot,
      104 +        .getoffset      = segmap_getoffset,
      105 +        .gettype        = segmap_gettype,
      106 +        .getvp          = segmap_getvp,
      107 +        .dump           = segmap_dump,
      108 +        .pagelock       = segmap_pagelock,
      109 +        .getmemid       = segmap_getmemid,
 128  110  };
 129  111  
 130  112  /*
 131  113   * Private segmap routines.
 132  114   */
 133  115  static void     segmap_unlock(struct hat *hat, struct seg *seg, caddr_t addr,
 134  116                          size_t len, enum seg_rw rw, struct smap *smp);
 135  117  static void     segmap_smapadd(struct smap *smp);
 136  118  static struct smap *segmap_hashin(struct smap *smp, struct vnode *vp,
 137  119                          u_offset_t off, int hashid);
↓ open down ↓ 764 lines elided ↑ open up ↑
 902  884   *
 903  885   * For segmap we always "approve" of this action from our standpoint.
 904  886   */
 905  887  /*ARGSUSED*/
 906  888  static int
 907  889  segmap_kluster(struct seg *seg, caddr_t addr, ssize_t delta)
 908  890  {
 909  891          return (0);
 910  892  }
 911  893  
 912      -static void
 913      -segmap_badop()
 914      -{
 915      -        panic("segmap_badop");
 916      -        /*NOTREACHED*/
 917      -}
 918      -
 919  894  /*
 920  895   * Special private segmap operations
 921  896   */
 922  897  
 923  898  /*
 924  899   * Add smap to the appropriate free list.
 925  900   */
 926  901  static void
 927  902  segmap_smapadd(struct smap *smp)
 928  903  {
↓ open down ↓ 1252 lines elided ↑ open up ↑
2181 2156          return (ENOTSUP);
2182 2157  }
2183 2158  
2184 2159  static int
2185 2160  segmap_getmemid(struct seg *seg, caddr_t addr, memid_t *memidp)
2186 2161  {
2187 2162          struct segmap_data *smd = (struct segmap_data *)seg->s_data;
2188 2163  
2189 2164          memidp->val[0] = (uintptr_t)smd->smd_sm->sm_vp;
2190 2165          memidp->val[1] = smd->smd_sm->sm_off + (uintptr_t)(addr - seg->s_base);
2191      -        return (0);
2192      -}
2193      -
2194      -/*ARGSUSED*/
2195      -static lgrp_mem_policy_info_t *
2196      -segmap_getpolicy(struct seg *seg, caddr_t addr)
2197      -{
2198      -        return (NULL);
2199      -}
2200      -
2201      -/*ARGSUSED*/
2202      -static int
2203      -segmap_capable(struct seg *seg, segcapability_t capability)
2204      -{
2205 2166          return (0);
2206 2167  }
2207 2168  
2208 2169  
2209 2170  #ifdef  SEGKPM_SUPPORT
2210 2171  
2211 2172  /*
2212 2173   * segkpm support routines
2213 2174   */
2214 2175  
↓ open down ↓ 141 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX