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.
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 getmemid segop as a shorthand for ENODEV
Instead of forcing every segment driver to implement a dummy function to
return (hopefully) ENODEV, handle NULL getmemid segop function pointer as
"return ENODEV" 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

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/vm/seg_kpm.c
          +++ new/usr/src/uts/common/vm/seg_kpm.c
↓ open down ↓ 94 lines elided ↑ open up ↑
  95   95   */
  96   96  int kpm_enable = 1;
  97   97  int kpm_smallpages = 0;
  98   98  int segmap_kpm = 1;
  99   99  
 100  100  /*
 101  101   * Private seg op routines.
 102  102   */
 103  103  faultcode_t segkpm_fault(struct hat *hat, struct seg *seg, caddr_t addr,
 104  104                          size_t len, enum fault_type type, enum seg_rw rw);
 105      -static void     segkpm_dump(struct seg *);
 106      -static void     segkpm_badop(void);
 107      -static int      segkpm_notsup(void);
 108      -static int      segkpm_capable(struct seg *, segcapability_t);
 109      -
 110      -#define SEGKPM_BADOP(t) (t(*)())segkpm_badop
 111      -#define SEGKPM_NOTSUP   (int(*)())segkpm_notsup
 112      -
 113      -static struct seg_ops segkpm_ops = {
 114      -        SEGKPM_BADOP(int),      /* dup */
 115      -        SEGKPM_BADOP(int),      /* unmap */
 116      -        SEGKPM_BADOP(void),     /* free */
 117      -        segkpm_fault,
 118      -        SEGKPM_BADOP(int),      /* faulta */
 119      -        SEGKPM_BADOP(int),      /* setprot */
 120      -        SEGKPM_BADOP(int),      /* checkprot */
 121      -        SEGKPM_BADOP(int),      /* kluster */
 122      -        SEGKPM_BADOP(size_t),   /* swapout */
 123      -        SEGKPM_BADOP(int),      /* sync */
 124      -        SEGKPM_BADOP(size_t),   /* incore */
 125      -        SEGKPM_BADOP(int),      /* lockop */
 126      -        SEGKPM_BADOP(int),      /* getprot */
 127      -        SEGKPM_BADOP(u_offset_t), /* getoffset */
 128      -        SEGKPM_BADOP(int),      /* gettype */
 129      -        SEGKPM_BADOP(int),      /* getvp */
 130      -        SEGKPM_BADOP(int),      /* advise */
 131      -        segkpm_dump,            /* dump */
 132      -        SEGKPM_NOTSUP,          /* pagelock */
 133      -        SEGKPM_BADOP(int),      /* setpgsz */
 134      -        SEGKPM_BADOP(int),      /* getmemid */
 135      -        SEGKPM_BADOP(lgrp_mem_policy_info_t *), /* getpolicy */
 136      -        segkpm_capable,         /* capable */
 137      -        seg_inherit_notsup      /* inherit */
      105 +static int      segkpm_pagelock(struct seg *seg, caddr_t addr, size_t len,
      106 +                        struct page ***page, enum lock_type type,
      107 +                        enum seg_rw rw);
      108 +
      109 +static const struct seg_ops segkpm_ops = {
      110 +        .fault          = segkpm_fault,
      111 +        .pagelock       = segkpm_pagelock,
      112 +//#ifndef SEGKPM_SUPPORT
      113 +#if 0
      114 +#error FIXME: define nop
      115 +        .dup            = nop,
      116 +        .unmap          = nop,
      117 +        .free           = nop,
      118 +        .faulta         = nop,
      119 +        .setprot        = nop,
      120 +        .checkprot      = nop,
      121 +        .kluster        = nop,
      122 +        .sync           = nop,
      123 +        .incore         = nop,
      124 +        .lockop         = nop,
      125 +        .getprot        = nop,
      126 +        .getoffset      = nop,
      127 +        .gettype        = nop,
      128 +        .getvp          = nop,
      129 +        .advise         = nop,
      130 +        .getpolicy      = nop,
      131 +#endif
 138  132  };
 139  133  
 140  134  /*
 141  135   * kpm_pgsz and kpm_pgshft are set by platform layer.
 142  136   */
 143  137  size_t          kpm_pgsz;       /* kpm page size */
 144  138  uint_t          kpm_pgshft;     /* kpm page shift */
 145  139  u_offset_t      kpm_pgoff;      /* kpm page offset mask */
 146  140  uint_t          kpmp2pshft;     /* kpm page to page shift */
 147  141  pgcnt_t         kpmpnpgs;       /* how many pages per kpm page */
↓ open down ↓ 129 lines elided ↑ open up ↑
 277  271          if (kpme->kpe_page == NULL) {
 278  272                  page_unlock(pp);
 279  273                  return;
 280  274          }
 281  275  
 282  276          vaddr = hat_kpm_page2va(pp, 1);
 283  277          hat_kpm_mapout(pp, kpme, vaddr);
 284  278          page_unlock(pp);
 285  279  }
 286  280  
 287      -static void
 288      -segkpm_badop()
 289      -{
 290      -        panic("segkpm_badop");
 291      -}
 292      -
 293  281  #else   /* SEGKPM_SUPPORT */
 294  282  
 295  283  /* segkpm stubs */
 296  284  
 297  285  /*ARGSUSED*/
 298      -int segkpm_create(struct seg *seg, void *argsp) { return (0); }
      286 +int segkpm_create(struct seg *seg, void *argsp)
      287 +{
      288 +        return (0);
      289 +}
 299  290  
 300  291  /* ARGSUSED */
 301  292  faultcode_t
 302  293  segkpm_fault(struct hat *hat, struct seg *seg, caddr_t addr, size_t len,
 303  294          enum fault_type type, enum seg_rw rw)
 304  295  {
 305      -        return ((faultcode_t)0);
      296 +        return (0);
 306  297  }
 307  298  
 308  299  /* ARGSUSED */
 309      -caddr_t segkpm_create_va(u_offset_t off) { return (NULL); }
      300 +caddr_t segkpm_create_va(u_offset_t off)
      301 +{
      302 +        return (NULL);
      303 +}
 310  304  
 311  305  /* ARGSUSED */
 312      -void segkpm_mapout_validkpme(struct kpme *kpme) {}
 313      -
 314      -static void
 315      -segkpm_badop() {}
 316      -
 317      -#endif  /* SEGKPM_SUPPORT */
 318      -
 319      -static int
 320      -segkpm_notsup()
      306 +void segkpm_mapout_validkpme(struct kpme *kpme)
 321  307  {
 322      -        return (ENOTSUP);
 323  308  }
 324  309  
 325      -/*
 326      - * segkpm pages are not dumped, so we just return
 327      - */
 328      -/*ARGSUSED*/
 329      -static void
 330      -segkpm_dump(struct seg *seg)
 331      -{}
      310 +#endif  /* SEGKPM_SUPPORT */
 332  311  
 333      -/*
 334      - * We claim to have no special capabilities.
 335      - */
 336      -/*ARGSUSED*/
      312 +/* ARGSUSED */
 337  313  static int
 338      -segkpm_capable(struct seg *seg, segcapability_t capability)
      314 +segkpm_pagelock(struct seg *seg, caddr_t addr, size_t len,
      315 +        struct page ***page, enum lock_type type, enum seg_rw rw)
 339  316  {
 340      -        return (0);
      317 +        return (ENOTSUP);
 341  318  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX