4141 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
4242 * Portions Copyright (c) 1994, Regents of the University of California
4343 *
44- * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.45 2009/01/01 17:23:36 momjian Exp $
44+ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.46 2009/04/02 19:14:33 momjian Exp $
4545 *
4646 *-------------------------------------------------------------------------
4747 */
5757#include "storage/fd.h"
5858#include "storage/shmem.h"
5959#include "miscadmin.h"
60+ #include "pg_trace.h"
6061
6162
6263/*
@@ -372,6 +373,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
372373{
373374 SlruShared shared = ctl -> shared ;
374375
376+ TRACE_POSTGRESQL_SLRU_READPAGE_START ((uintptr_t )ctl , pageno , write_ok , xid );
375377 /* Outer loop handles restart if we must wait for someone else's I/O */
376378 for (;;)
377379 {
@@ -399,6 +401,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
399401 }
400402 /* Otherwise, it's ready to use */
401403 SlruRecentlyUsed (shared , slotno );
404+ TRACE_POSTGRESQL_SLRU_READPAGE_DONE (slotno );
402405 return slotno ;
403406 }
404407
@@ -446,6 +449,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
446449 SlruReportIOError (ctl , pageno , xid );
447450
448451 SlruRecentlyUsed (shared , slotno );
452+ TRACE_POSTGRESQL_SLRU_READPAGE_DONE (slotno );
449453 return slotno ;
450454 }
451455}
@@ -470,6 +474,8 @@ SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
470474 SlruShared shared = ctl -> shared ;
471475 int slotno ;
472476
477+ TRACE_POSTGRESQL_SLRU_READPAGE_READONLY ((uintptr_t )ctl , pageno , xid );
478+
473479 /* Try to find the page while holding only shared lock */
474480 LWLockAcquire (shared -> ControlLock , LW_SHARED );
475481
@@ -511,6 +517,8 @@ SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata)
511517 int pageno = shared -> page_number [slotno ];
512518 bool ok ;
513519
520+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_START ((uintptr_t )ctl , pageno , slotno );
521+
514522 /* If a write is in progress, wait for it to finish */
515523 while (shared -> page_status [slotno ] == SLRU_PAGE_WRITE_IN_PROGRESS &&
516524 shared -> page_number [slotno ] == pageno )
@@ -525,7 +533,10 @@ SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata)
525533 if (!shared -> page_dirty [slotno ] ||
526534 shared -> page_status [slotno ] != SLRU_PAGE_VALID ||
527535 shared -> page_number [slotno ] != pageno )
536+ {
537+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_DONE ();
528538 return ;
539+ }
529540
530541 /*
531542 * Mark the slot write-busy, and clear the dirtybit. After this point, a
@@ -569,6 +580,8 @@ SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata)
569580 /* Now it's okay to ereport if we failed */
570581 if (!ok )
571582 SlruReportIOError (ctl , pageno , InvalidTransactionId );
583+
584+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_DONE ();
572585}
573586
574587/*
@@ -593,6 +606,8 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
593606
594607 SlruFileName (ctl , path , segno );
595608
609+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_START ((uintptr_t )ctl , path , pageno , slotno );
610+
596611 /*
597612 * In a crash-and-restart situation, it's possible for us to receive
598613 * commands to set the commit status of transactions whose bits are in
@@ -607,13 +622,15 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
607622 {
608623 slru_errcause = SLRU_OPEN_FAILED ;
609624 slru_errno = errno ;
625+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
610626 return false;
611627 }
612628
613629 ereport (LOG ,
614630 (errmsg ("file \"%s\" doesn't exist, reading as zeroes" ,
615631 path )));
616632 MemSet (shared -> page_buffer [slotno ], 0 , BLCKSZ );
633+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (true, -1 , -1 );
617634 return true;
618635 }
619636
@@ -622,6 +639,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
622639 slru_errcause = SLRU_SEEK_FAILED ;
623640 slru_errno = errno ;
624641 close (fd );
642+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
625643 return false;
626644 }
627645
@@ -631,16 +649,20 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
631649 slru_errcause = SLRU_READ_FAILED ;
632650 slru_errno = errno ;
633651 close (fd );
652+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
634653 return false;
635654 }
636655
637656 if (close (fd ))
638657 {
639658 slru_errcause = SLRU_CLOSE_FAILED ;
640659 slru_errno = errno ;
660+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
641661 return false;
642662 }
643663
664+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (true, -1 , -1 );
665+
644666 return true;
645667}
646668
@@ -668,6 +690,8 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
668690 char path [MAXPGPATH ];
669691 int fd = -1 ;
670692
693+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_START ((uintptr_t )ctl , pageno , slotno );
694+
671695 /*
672696 * Honor the write-WAL-before-data rule, if appropriate, so that we do not
673697 * write out data before associated WAL records. This is the same action
@@ -753,6 +777,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
753777 {
754778 slru_errcause = SLRU_OPEN_FAILED ;
755779 slru_errno = errno ;
780+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
756781 return false;
757782 }
758783
@@ -781,6 +806,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
781806 slru_errno = errno ;
782807 if (!fdata )
783808 close (fd );
809+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
784810 return false;
785811 }
786812
@@ -794,6 +820,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
794820 slru_errno = errno ;
795821 if (!fdata )
796822 close (fd );
823+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
797824 return false;
798825 }
799826
@@ -808,17 +835,20 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
808835 slru_errcause = SLRU_FSYNC_FAILED ;
809836 slru_errno = errno ;
810837 close (fd );
838+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
811839 return false;
812840 }
813841
814842 if (close (fd ))
815843 {
816844 slru_errcause = SLRU_CLOSE_FAILED ;
817845 slru_errno = errno ;
846+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
818847 return false;
819848 }
820849 }
821850
851+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (true, -1 , -1 );
822852 return true;
823853}
824854
0 commit comments