Print this page
use NULL dump segop as a shorthand for no-op
Instead of forcing every segment driver to implement a dummy function that
does nothing, handle NULL dump segop function pointer as a no-op shorthand.
segspt_ops can be static
There is nothing that needs access to this structure outside of the spt
segment driver itself.
const-ify make segment ops structures
There is no reason to keep the segment ops structures writable.
use NULL setpagesize segop as a shorthand for ENOTSUP
Instead of forcing every segment driver to implement a dummp function to
return (hopefully) ENOTSUP, handle NULL setpagesize segop function pointer
as "return ENOTSUP" shorthand.
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.
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
remove xhat
The xhat infrastructure was added to support hardware such as the zulu
graphics card - hardware which had on-board MMUs.  The VM used the xhat code
to keep the CPU's and Zulu's page tables in-sync.  Since the only xhat user
was zulu (which is gone), we can safely remove it simplifying the whole VM
subsystem.
Assorted notes:
- AS_BUSY flag was used solely by xhat

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/vm/seg_spt.c
          +++ new/usr/src/uts/common/vm/seg_spt.c
↓ open down ↓ 68 lines elided ↑ open up ↑
  69   69   * the system) they can patch the segspt_minfree to smaller number.
  70   70   */
  71   71  pgcnt_t segspt_minfree = 0;
  72   72  
  73   73  static int segspt_create(struct seg *seg, caddr_t argsp);
  74   74  static int segspt_unmap(struct seg *seg, caddr_t raddr, size_t ssize);
  75   75  static void segspt_free(struct seg *seg);
  76   76  static void segspt_free_pages(struct seg *seg, caddr_t addr, size_t len);
  77   77  static lgrp_mem_policy_info_t *segspt_getpolicy(struct seg *seg, caddr_t addr);
  78   78  
  79      -static void
  80      -segspt_badop()
  81      -{
  82      -        panic("segspt_badop called");
  83      -        /*NOTREACHED*/
  84      -}
  85      -
  86      -#define SEGSPT_BADOP(t) (t(*)())segspt_badop
  87      -
  88      -struct seg_ops segspt_ops = {
  89      -        SEGSPT_BADOP(int),              /* dup */
  90      -        segspt_unmap,
  91      -        segspt_free,
  92      -        SEGSPT_BADOP(int),              /* fault */
  93      -        SEGSPT_BADOP(faultcode_t),      /* faulta */
  94      -        SEGSPT_BADOP(int),              /* setprot */
  95      -        SEGSPT_BADOP(int),              /* checkprot */
  96      -        SEGSPT_BADOP(int),              /* kluster */
  97      -        SEGSPT_BADOP(size_t),           /* swapout */
  98      -        SEGSPT_BADOP(int),              /* sync */
  99      -        SEGSPT_BADOP(size_t),           /* incore */
 100      -        SEGSPT_BADOP(int),              /* lockop */
 101      -        SEGSPT_BADOP(int),              /* getprot */
 102      -        SEGSPT_BADOP(u_offset_t),       /* getoffset */
 103      -        SEGSPT_BADOP(int),              /* gettype */
 104      -        SEGSPT_BADOP(int),              /* getvp */
 105      -        SEGSPT_BADOP(int),              /* advise */
 106      -        SEGSPT_BADOP(void),             /* dump */
 107      -        SEGSPT_BADOP(int),              /* pagelock */
 108      -        SEGSPT_BADOP(int),              /* setpgsz */
 109      -        SEGSPT_BADOP(int),              /* getmemid */
 110      -        segspt_getpolicy,               /* getpolicy */
 111      -        SEGSPT_BADOP(int),              /* capable */
 112      -        seg_inherit_notsup              /* inherit */
       79 +static const struct seg_ops segspt_ops = {
       80 +        .unmap          = segspt_unmap,
       81 +        .free           = segspt_free,
       82 +        .getpolicy      = segspt_getpolicy,
 113   83  };
 114   84  
 115   85  static int segspt_shmdup(struct seg *seg, struct seg *newseg);
 116   86  static int segspt_shmunmap(struct seg *seg, caddr_t raddr, size_t ssize);
 117   87  static void segspt_shmfree(struct seg *seg);
 118   88  static faultcode_t segspt_shmfault(struct hat *hat, struct seg *seg,
 119   89                  caddr_t addr, size_t len, enum fault_type type, enum seg_rw rw);
 120   90  static faultcode_t segspt_shmfaulta(struct seg *seg, caddr_t addr);
 121   91  static int segspt_shmsetprot(register struct seg *seg, register caddr_t addr,
 122   92                          register size_t len, register uint_t prot);
 123   93  static int segspt_shmcheckprot(struct seg *seg, caddr_t addr, size_t size,
 124   94                          uint_t prot);
 125   95  static int      segspt_shmkluster(struct seg *seg, caddr_t addr, ssize_t delta);
 126      -static size_t   segspt_shmswapout(struct seg *seg);
 127   96  static size_t segspt_shmincore(struct seg *seg, caddr_t addr, size_t len,
 128   97                          register char *vec);
 129   98  static int segspt_shmsync(struct seg *seg, register caddr_t addr, size_t len,
 130   99                          int attr, uint_t flags);
 131  100  static int segspt_shmlockop(struct seg *seg, caddr_t addr, size_t len,
 132  101                          int attr, int op, ulong_t *lockmap, size_t pos);
 133  102  static int segspt_shmgetprot(struct seg *seg, caddr_t addr, size_t len,
 134  103                          uint_t *protv);
 135  104  static u_offset_t segspt_shmgetoffset(struct seg *seg, caddr_t addr);
 136  105  static int segspt_shmgettype(struct seg *seg, caddr_t addr);
 137  106  static int segspt_shmgetvp(struct seg *seg, caddr_t addr, struct vnode **vpp);
 138  107  static int segspt_shmadvise(struct seg *seg, caddr_t addr, size_t len,
 139  108                          uint_t behav);
 140      -static void segspt_shmdump(struct seg *seg);
 141  109  static int segspt_shmpagelock(struct seg *, caddr_t, size_t,
 142  110                          struct page ***, enum lock_type, enum seg_rw);
 143      -static int segspt_shmsetpgsz(struct seg *, caddr_t, size_t, uint_t);
 144  111  static int segspt_shmgetmemid(struct seg *, caddr_t, memid_t *);
 145  112  static lgrp_mem_policy_info_t *segspt_shmgetpolicy(struct seg *, caddr_t);
 146      -static int segspt_shmcapable(struct seg *, segcapability_t);
 147  113  
 148      -struct seg_ops segspt_shmops = {
 149      -        segspt_shmdup,
 150      -        segspt_shmunmap,
 151      -        segspt_shmfree,
 152      -        segspt_shmfault,
 153      -        segspt_shmfaulta,
 154      -        segspt_shmsetprot,
 155      -        segspt_shmcheckprot,
 156      -        segspt_shmkluster,
 157      -        segspt_shmswapout,
 158      -        segspt_shmsync,
 159      -        segspt_shmincore,
 160      -        segspt_shmlockop,
 161      -        segspt_shmgetprot,
 162      -        segspt_shmgetoffset,
 163      -        segspt_shmgettype,
 164      -        segspt_shmgetvp,
 165      -        segspt_shmadvise,       /* advise */
 166      -        segspt_shmdump,
 167      -        segspt_shmpagelock,
 168      -        segspt_shmsetpgsz,
 169      -        segspt_shmgetmemid,
 170      -        segspt_shmgetpolicy,
 171      -        segspt_shmcapable,
 172      -        seg_inherit_notsup
      114 +const struct seg_ops segspt_shmops = {
      115 +        .dup            = segspt_shmdup,
      116 +        .unmap          = segspt_shmunmap,
      117 +        .free           = segspt_shmfree,
      118 +        .fault          = segspt_shmfault,
      119 +        .faulta         = segspt_shmfaulta,
      120 +        .setprot        = segspt_shmsetprot,
      121 +        .checkprot      = segspt_shmcheckprot,
      122 +        .kluster        = segspt_shmkluster,
      123 +        .sync           = segspt_shmsync,
      124 +        .incore         = segspt_shmincore,
      125 +        .lockop         = segspt_shmlockop,
      126 +        .getprot        = segspt_shmgetprot,
      127 +        .getoffset      = segspt_shmgetoffset,
      128 +        .gettype        = segspt_shmgettype,
      129 +        .getvp          = segspt_shmgetvp,
      130 +        .advise         = segspt_shmadvise,
      131 +        .pagelock       = segspt_shmpagelock,
      132 +        .getmemid       = segspt_shmgetmemid,
      133 +        .getpolicy      = segspt_shmgetpolicy,
 173  134  };
 174  135  
 175  136  static void segspt_purge(struct seg *seg);
 176  137  static int segspt_reclaim(void *, caddr_t, size_t, struct page **,
 177  138                  enum seg_rw, int);
 178  139  static int spt_anon_getpages(struct seg *seg, caddr_t addr, size_t len,
 179  140                  page_t **ppa);
 180  141  
 181  142  
 182  143  
↓ open down ↓ 1734 lines elided ↑ open up ↑
1917 1878                          /*
1918 1879                           * Load up the translation keeping it
1919 1880                           * locked and don't unlock the page.
1920 1881                           */
1921 1882                          for (; pidx < npages; a += pgsz, pidx += pgcnt) {
1922 1883                                  hat_memload_array(sptseg->s_as->a_hat,
1923 1884                                      a, pgsz, &ppa[pidx], sptd->spt_prot,
1924 1885                                      HAT_LOAD_LOCK | HAT_LOAD_SHARE);
1925 1886                          }
1926 1887                  } else {
1927      -                        if (hat == seg->s_as->a_hat) {
     1888 +                        /*
     1889 +                         * Migrate pages marked for migration
     1890 +                         */
     1891 +                        if (lgrp_optimizations())
     1892 +                                page_migrate(seg, shm_addr, ppa, npages);
1928 1893  
1929      -                                /*
1930      -                                 * Migrate pages marked for migration
1931      -                                 */
1932      -                                if (lgrp_optimizations())
1933      -                                        page_migrate(seg, shm_addr, ppa,
1934      -                                            npages);
1935      -
1936      -                                /* CPU HAT */
1937      -                                for (; pidx < npages;
1938      -                                    a += pgsz, pidx += pgcnt) {
1939      -                                        hat_memload_array(sptseg->s_as->a_hat,
1940      -                                            a, pgsz, &ppa[pidx],
1941      -                                            sptd->spt_prot,
1942      -                                            HAT_LOAD_SHARE);
1943      -                                }
1944      -                        } else {
1945      -                                /* XHAT. Pass real address */
1946      -                                hat_memload_array(hat, shm_addr,
1947      -                                    size, ppa, sptd->spt_prot, HAT_LOAD_SHARE);
     1894 +                        for (; pidx < npages; a += pgsz, pidx += pgcnt) {
     1895 +                                hat_memload_array(sptseg->s_as->a_hat,
     1896 +                                    a, pgsz, &ppa[pidx],
     1897 +                                    sptd->spt_prot,
     1898 +                                    HAT_LOAD_SHARE);
1948 1899                          }
1949 1900  
1950 1901                          /*
1951 1902                           * And now drop the SE_SHARED lock(s).
1952 1903                           */
1953 1904                          if (dyn_ism_unmap) {
1954 1905                                  for (i = 0; i < npages; i++) {
1955 1906                                          page_unlock(ppa[i]);
1956 1907                                  }
1957 1908                          }
↓ open down ↓ 219 lines elided ↑ open up ↑
2177 2128                           * Load up the translation keeping it
2178 2129                           * locked and don't unlock the page.
2179 2130                           */
2180 2131                          for (; pidx < npages; a += pgsz, pidx += pgcnt) {
2181 2132                                  sz = MIN(pgsz, ptob(npages - pidx));
2182 2133                                  hat_memload_array(sptseg->s_as->a_hat, a,
2183 2134                                      sz, &ppa[pidx], sptd->spt_prot,
2184 2135                                      HAT_LOAD_LOCK | HAT_LOAD_SHARE);
2185 2136                          }
2186 2137                  } else {
2187      -                        if (hat == seg->s_as->a_hat) {
     2138 +                        /*
     2139 +                         * Migrate pages marked for migration.
     2140 +                         */
     2141 +                        if (lgrp_optimizations())
     2142 +                                page_migrate(seg, shm_addr, ppa, npages);
2188 2143  
2189      -                                /*
2190      -                                 * Migrate pages marked for migration.
2191      -                                 */
2192      -                                if (lgrp_optimizations())
2193      -                                        page_migrate(seg, shm_addr, ppa,
2194      -                                            npages);
2195      -
2196      -                                /* CPU HAT */
2197      -                                for (; pidx < npages;
2198      -                                    a += pgsz, pidx += pgcnt) {
2199      -                                        sz = MIN(pgsz, ptob(npages - pidx));
2200      -                                        hat_memload_array(sptseg->s_as->a_hat,
2201      -                                            a, sz, &ppa[pidx],
2202      -                                            sptd->spt_prot, HAT_LOAD_SHARE);
2203      -                                }
2204      -                        } else {
2205      -                                /* XHAT. Pass real address */
2206      -                                hat_memload_array(hat, shm_addr,
2207      -                                    ptob(npages), ppa, sptd->spt_prot,
2208      -                                    HAT_LOAD_SHARE);
     2144 +                        for (; pidx < npages; a += pgsz, pidx += pgcnt) {
     2145 +                                sz = MIN(pgsz, ptob(npages - pidx));
     2146 +                                hat_memload_array(sptseg->s_as->a_hat,
     2147 +                                    a, sz, &ppa[pidx],
     2148 +                                    sptd->spt_prot, HAT_LOAD_SHARE);
2209 2149                          }
2210 2150  
2211 2151                          /*
2212 2152                           * And now drop the SE_SHARED lock(s).
2213 2153                           */
2214 2154                          for (i = 0; i < npages; i++)
2215 2155                                  page_unlock(ppa[i]);
2216 2156                  }
2217 2157                  AS_LOCK_EXIT(sptseg->s_as, &sptseg->s_as->a_lock);
2218 2158  
↓ open down ↓ 38 lines elided ↑ open up ↑
2257 2197          return (0);
2258 2198  }
2259 2199  
2260 2200  /*ARGSUSED*/
2261 2201  static int
2262 2202  segspt_shmkluster(struct seg *seg, caddr_t addr, ssize_t delta)
2263 2203  {
2264 2204          return (0);
2265 2205  }
2266 2206  
2267      -/*ARGSUSED*/
2268      -static size_t
2269      -segspt_shmswapout(struct seg *seg)
2270      -{
2271      -        return (0);
2272      -}
2273      -
2274 2207  /*
2275 2208   * duplicate the shared page tables
2276 2209   */
2277 2210  int
2278 2211  segspt_shmdup(struct seg *seg, struct seg *newseg)
2279 2212  {
2280 2213          struct shm_data         *shmd = (struct shm_data *)seg->s_data;
2281 2214          struct anon_map         *amp = shmd->shm_amp;
2282 2215          struct shm_data         *shmd_new;
2283 2216          struct seg              *spt_seg = shmd->shm_sptseg;
↓ open down ↓ 723 lines elided ↑ open up ↑
3007 2940                   */
3008 2941                  if (shmd->shm_softlockcnt > 0)
3009 2942                          segspt_purge(seg);
3010 2943  
3011 2944                  page_mark_migrate(seg, shm_addr, size, amp, 0, NULL, 0, 0);
3012 2945          }
3013 2946  
3014 2947          return (0);
3015 2948  }
3016 2949  
3017      -/*ARGSUSED*/
3018      -void
3019      -segspt_shmdump(struct seg *seg)
3020      -{
3021      -        /* no-op for ISM segment */
3022      -}
3023      -
3024      -/*ARGSUSED*/
3025      -static faultcode_t
3026      -segspt_shmsetpgsz(struct seg *seg, caddr_t addr, size_t len, uint_t szc)
3027      -{
3028      -        return (ENOTSUP);
3029      -}
3030      -
3031 2950  /*
3032 2951   * get a memory ID for an addr in a given segment
3033 2952   */
3034 2953  static int
3035 2954  segspt_shmgetmemid(struct seg *seg, caddr_t addr, memid_t *memidp)
3036 2955  {
3037 2956          struct shm_data *shmd = (struct shm_data *)seg->s_data;
3038 2957          struct anon     *ap;
3039 2958          size_t          anon_index;
3040 2959          struct anon_map *amp = shmd->shm_amp;
↓ open down ↓ 59 lines elided ↑ open up ↑
3100 3019  
3101 3020          /*
3102 3021           * Get policy info
3103 3022           *
3104 3023           * Assume starting anon index of 0
3105 3024           */
3106 3025          anon_index = seg_page(seg, addr);
3107 3026          policy_info = lgrp_shm_policy_get(amp, anon_index, NULL, 0);
3108 3027  
3109 3028          return (policy_info);
3110      -}
3111      -
3112      -/*ARGSUSED*/
3113      -static int
3114      -segspt_shmcapable(struct seg *seg, segcapability_t capability)
3115      -{
3116      -        return (0);
3117 3029  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX