Print this page
11909 THREAD_KPRI_RELEASE does nothing of the sort
Reviewed by: Bryan Cantrill <bryan@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/vm/page_lock.c
          +++ new/usr/src/uts/common/vm/page_lock.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
       23 + * Copyright 2019 Joyent, Inc.
  23   24   */
  24   25  
  25   26  
  26   27  /*
  27   28   * VM - page locking primitives
  28   29   */
  29   30  #include <sys/param.h>
  30   31  #include <sys/t_lock.h>
  31   32  #include <sys/vtrace.h>
  32   33  #include <sys/debug.h>
↓ open down ↓ 324 lines elided ↑ open up ↑
 357  358          if (se == SE_EXCL) {
 358  359                  if (!(es & SE_EXCL_WANTED) && (pp->p_selock & SE_EWANTED)) {
 359  360                          /*
 360  361                           * if the caller wants a writer lock (but did not
 361  362                           * specify exclusive access), and there is a pending
 362  363                           * writer that wants exclusive access, return failure
 363  364                           */
 364  365                          retval = 0;
 365  366                  } else if ((pp->p_selock & ~SE_EWANTED) == 0) {
 366  367                          /* no reader/writer lock held */
 367      -                        THREAD_KPRI_REQUEST();
 368  368                          /* this clears our setting of the SE_EWANTED bit */
 369  369                          pp->p_selock = SE_WRITER;
 370  370                          retval = 1;
 371  371                  } else {
 372  372                          /* page is locked */
 373  373                          if (es & SE_EXCL_WANTED) {
 374  374                                  /* set the SE_EWANTED bit */
 375  375                                  pp->p_selock |= SE_EWANTED;
 376  376                          }
 377  377                          retval = 0;
↓ open down ↓ 166 lines elided ↑ open up ↑
 544  544          }
 545  545  
 546  546          /*
 547  547           * The caller wants a writer lock.  We try for it only if
 548  548           * SE_EWANTED is not set, or if the caller specified
 549  549           * SE_EXCL_WANTED.
 550  550           */
 551  551          if (!(old & SE_EWANTED) || (es & SE_EXCL_WANTED)) {
 552  552                  if ((old & ~SE_EWANTED) == 0) {
 553  553                          /* no reader/writer lock held */
 554      -                        THREAD_KPRI_REQUEST();
 555  554                          /* this clears out our setting of the SE_EWANTED bit */
 556  555                          pp->p_selock = SE_WRITER;
 557  556                          mutex_exit(pse);
 558  557                          return (1);
 559  558                  }
 560  559          }
 561  560          if (es & SE_EXCL_WANTED) {
 562  561                  /* page is locked, set the SE_EWANTED bit */
 563  562                  pp->p_selock |= SE_EWANTED;
 564  563          }
↓ open down ↓ 18 lines elided ↑ open up ↑
 583  582                   * retired, if the page is slated for retirement, or a
 584  583                   * share lock is requested.
 585  584                   */
 586  585                  mutex_exit(pse);
 587  586                  VM_STAT_ADD(page_trylock_failed);
 588  587                  return (0);
 589  588          }
 590  589  
 591  590          if (se == SE_EXCL) {
 592  591                  if (pp->p_selock == 0) {
 593      -                        THREAD_KPRI_REQUEST();
 594  592                          pp->p_selock = SE_WRITER;
 595  593                          mutex_exit(pse);
 596  594                          return (1);
 597  595                  }
 598  596          } else {
 599  597                  if (pp->p_selock >= 0) {
 600  598                          pp->p_selock += SE_READER;
 601  599                          mutex_exit(pse);
 602  600                          return (1);
 603  601                  }
↓ open down ↓ 17 lines elided ↑ open up ↑
 621  619          mutex_enter(pse);
 622  620  
 623  621          old = pp->p_selock;
 624  622          if ((old & ~SE_EWANTED) == SE_READER) {
 625  623                  pp->p_selock = old & ~SE_READER;
 626  624                  if (CV_HAS_WAITERS(&pp->p_cv))
 627  625                          cv_broadcast(&pp->p_cv);
 628  626          } else if ((old & ~SE_EWANTED) == SE_DELETED) {
 629  627                  panic("page_unlock_nocapture: page %p is deleted", (void *)pp);
 630  628          } else if (old < 0) {
 631      -                THREAD_KPRI_RELEASE();
 632  629                  pp->p_selock &= SE_EWANTED;
 633  630                  if (CV_HAS_WAITERS(&pp->p_cv))
 634  631                          cv_broadcast(&pp->p_cv);
 635  632          } else if ((old & ~SE_EWANTED) > SE_READER) {
 636  633                  pp->p_selock = old - SE_READER;
 637  634          } else {
 638  635                  panic("page_unlock_nocapture: page %p is not locked",
 639  636                      (void *)pp);
 640  637          }
 641  638  
↓ open down ↓ 13 lines elided ↑ open up ↑
 655  652          mutex_enter(pse);
 656  653  
 657  654          old = pp->p_selock;
 658  655          if ((old & ~SE_EWANTED) == SE_READER) {
 659  656                  pp->p_selock = old & ~SE_READER;
 660  657                  if (CV_HAS_WAITERS(&pp->p_cv))
 661  658                          cv_broadcast(&pp->p_cv);
 662  659          } else if ((old & ~SE_EWANTED) == SE_DELETED) {
 663  660                  panic("page_unlock: page %p is deleted", (void *)pp);
 664  661          } else if (old < 0) {
 665      -                THREAD_KPRI_RELEASE();
 666  662                  pp->p_selock &= SE_EWANTED;
 667  663                  if (CV_HAS_WAITERS(&pp->p_cv))
 668  664                          cv_broadcast(&pp->p_cv);
 669  665          } else if ((old & ~SE_EWANTED) > SE_READER) {
 670  666                  pp->p_selock = old - SE_READER;
 671  667          } else {
 672  668                  panic("page_unlock: page %p is not locked", (void *)pp);
 673  669          }
 674  670  
 675  671          if (pp->p_selock == 0) {
 676  672                  /*
 677  673                   * If the T_CAPTURING bit is set, that means that we should
 678  674                   * not try and capture the page again as we could recurse
 679  675                   * which could lead to a stack overflow panic or spending a
 680  676                   * relatively long time in the kernel making no progress.
 681  677                   */
 682  678                  if ((pp->p_toxic & PR_CAPTURE) &&
 683  679                      !(curthread->t_flag & T_CAPTURING) &&
 684  680                      !PP_RETIRED(pp)) {
 685      -                        THREAD_KPRI_REQUEST();
 686  681                          pp->p_selock = SE_WRITER;
 687  682                          mutex_exit(pse);
 688  683                          page_unlock_capture(pp);
 689  684                  } else {
 690  685                          mutex_exit(pse);
 691  686                  }
 692  687          } else {
 693  688                  mutex_exit(pse);
 694  689          }
 695  690  }
↓ open down ↓ 9 lines elided ↑ open up ↑
 705  700   */
 706  701  int
 707  702  page_tryupgrade(page_t *pp)
 708  703  {
 709  704          kmutex_t *pse = PAGE_SE_MUTEX(pp);
 710  705  
 711  706          mutex_enter(pse);
 712  707          if (!(pp->p_selock & SE_EWANTED)) {
 713  708                  /* no threads want exclusive access, try upgrade */
 714  709                  if (pp->p_selock == SE_READER) {
 715      -                        THREAD_KPRI_REQUEST();
 716  710                          /* convert to exclusive lock */
 717  711                          pp->p_selock = SE_WRITER;
 718  712                          mutex_exit(pse);
 719  713                          return (1);
 720  714                  }
 721  715          }
 722  716          mutex_exit(pse);
 723  717          return (0);
 724  718  }
 725  719  
↓ open down ↓ 5 lines elided ↑ open up ↑
 731  725  page_downgrade(page_t *pp)
 732  726  {
 733  727          kmutex_t *pse = PAGE_SE_MUTEX(pp);
 734  728          int excl_waiting;
 735  729  
 736  730          ASSERT((pp->p_selock & ~SE_EWANTED) != SE_DELETED);
 737  731          ASSERT(PAGE_EXCL(pp));
 738  732  
 739  733          mutex_enter(pse);
 740  734          excl_waiting =  pp->p_selock & SE_EWANTED;
 741      -        THREAD_KPRI_RELEASE();
 742  735          pp->p_selock = SE_READER | excl_waiting;
 743  736          if (CV_HAS_WAITERS(&pp->p_cv))
 744  737                  cv_broadcast(&pp->p_cv);
 745  738          mutex_exit(pse);
 746  739  }
 747  740  
 748  741  void
 749  742  page_lock_delete(page_t *pp)
 750  743  {
 751  744          kmutex_t *pse = PAGE_SE_MUTEX(pp);
 752  745  
 753  746          ASSERT(PAGE_EXCL(pp));
 754  747          ASSERT(pp->p_vnode == NULL);
 755  748          ASSERT(pp->p_offset == (u_offset_t)-1);
 756  749          ASSERT(!PP_ISFREE(pp));
 757  750  
 758  751          mutex_enter(pse);
 759      -        THREAD_KPRI_RELEASE();
 760  752          pp->p_selock = SE_DELETED;
 761  753          if (CV_HAS_WAITERS(&pp->p_cv))
 762  754                  cv_broadcast(&pp->p_cv);
 763  755          mutex_exit(pse);
 764  756  }
 765  757  
 766  758  int
 767  759  page_deleted(page_t *pp)
 768  760  {
 769  761          return (pp->p_selock == SE_DELETED);
↓ open down ↓ 298 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX