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{
373374SlruShared 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 */
376378for (;;)
377379{
@@ -399,6 +401,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
399401}
400402/* Otherwise, it's ready to use */
401403SlruRecentlyUsed (shared ,slotno );
404+ TRACE_POSTGRESQL_SLRU_READPAGE_DONE (slotno );
402405return slotno ;
403406}
404407
@@ -446,6 +449,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
446449SlruReportIOError (ctl ,pageno ,xid );
447450
448451SlruRecentlyUsed (shared ,slotno );
452+ TRACE_POSTGRESQL_SLRU_READPAGE_DONE (slotno );
449453return slotno ;
450454}
451455}
@@ -470,6 +474,8 @@ SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
470474SlruShared shared = ctl -> shared ;
471475int 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 */
474480LWLockAcquire (shared -> ControlLock ,LW_SHARED );
475481
@@ -511,6 +517,8 @@ SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata)
511517int pageno = shared -> page_number [slotno ];
512518bool 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 */
515523while (shared -> page_status [slotno ]== SLRU_PAGE_WRITE_IN_PROGRESS &&
516524shared -> page_number [slotno ]== pageno )
@@ -525,7 +533,10 @@ SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata)
525533if (!shared -> page_dirty [slotno ]||
526534shared -> page_status [slotno ]!= SLRU_PAGE_VALID ||
527535shared -> page_number [slotno ]!= pageno )
536+ {
537+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_DONE ();
528538return ;
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 */
570581if (!ok )
571582SlruReportIOError (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
594607SlruFileName (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{
608623slru_errcause = SLRU_OPEN_FAILED ;
609624slru_errno = errno ;
625+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false,slru_errcause ,slru_errno );
610626return false;
611627}
612628
613629ereport (LOG ,
614630(errmsg ("file \"%s\" doesn't exist, reading as zeroes" ,
615631path )));
616632MemSet (shared -> page_buffer [slotno ],0 ,BLCKSZ );
633+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (true,-1 ,-1 );
617634return true;
618635}
619636
@@ -622,6 +639,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
622639slru_errcause = SLRU_SEEK_FAILED ;
623640slru_errno = errno ;
624641close (fd );
642+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false,slru_errcause ,slru_errno );
625643return false;
626644}
627645
@@ -631,16 +649,20 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
631649slru_errcause = SLRU_READ_FAILED ;
632650slru_errno = errno ;
633651close (fd );
652+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false,slru_errcause ,slru_errno );
634653return false;
635654}
636655
637656if (close (fd ))
638657{
639658slru_errcause = SLRU_CLOSE_FAILED ;
640659slru_errno = errno ;
660+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false,slru_errcause ,slru_errno );
641661return false;
642662}
643663
664+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (true,-1 ,-1 );
665+
644666return true;
645667}
646668
@@ -668,6 +690,8 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
668690char path [MAXPGPATH ];
669691int 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{
754778slru_errcause = SLRU_OPEN_FAILED ;
755779slru_errno = errno ;
780+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false,slru_errcause ,slru_errno );
756781return false;
757782}
758783
@@ -781,6 +806,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
781806slru_errno = errno ;
782807if (!fdata )
783808close (fd );
809+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false,slru_errcause ,slru_errno );
784810return false;
785811}
786812
@@ -794,6 +820,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
794820slru_errno = errno ;
795821if (!fdata )
796822close (fd );
823+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false,slru_errcause ,slru_errno );
797824return false;
798825}
799826
@@ -808,17 +835,20 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
808835slru_errcause = SLRU_FSYNC_FAILED ;
809836slru_errno = errno ;
810837close (fd );
838+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false,slru_errcause ,slru_errno );
811839return false;
812840}
813841
814842if (close (fd ))
815843{
816844slru_errcause = SLRU_CLOSE_FAILED ;
817845slru_errno = errno ;
846+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false,slru_errcause ,slru_errno );
818847return false;
819848}
820849}
821850
851+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (true,-1 ,-1 );
822852return true;
823853}
824854