Skip to content

Commit e2b37d9

Browse files
committed
Use pg_pread() and pg_pwrite() in slru.c.
This avoids lseek() system calls at every SLRU I/O, as was done for relation files in commit c24dcd0c. Reviewed-by: Ashwin Agrawal <aagrawal@pivotal.io> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CA%2BhUKG%2Biqke4uTRFj8D8uEUUgj%2BRokPSp%2BCWM6YYzaaamG9Wvg%40mail.gmail.com Discussion: https://postgr.es/m/CA%2BhUKGJ%2BoHhnvqjn3%3DHro7xu-YDR8FPr0FL6LF35kHRX%3D_bUzg%40mail.gmail.com
1 parent 022350b commit e2b37d9

File tree

1 file changed

+4
-21
lines changed
  • src/backend/access/transam

1 file changed

+4
-21
lines changed

src/backend/access/transam/slru.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
669669
SlruShared shared = ctl->shared;
670670
int segno = pageno / SLRU_PAGES_PER_SEGMENT;
671671
int rpageno = pageno % SLRU_PAGES_PER_SEGMENT;
672-
int offset = rpageno * BLCKSZ;
672+
off_t offset = rpageno * BLCKSZ;
673673
char path[MAXPGPATH];
674674
int fd;
675675

@@ -699,17 +699,9 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
699699
return true;
700700
}
701701

702-
if (lseek(fd, (off_t) offset, SEEK_SET) < 0)
703-
{
704-
slru_errcause = SLRU_SEEK_FAILED;
705-
slru_errno = errno;
706-
CloseTransientFile(fd);
707-
return false;
708-
}
709-
710702
errno = 0;
711703
pgstat_report_wait_start(WAIT_EVENT_SLRU_READ);
712-
if (read(fd, shared->page_buffer[slotno], BLCKSZ) != BLCKSZ)
704+
if (pg_pread(fd, shared->page_buffer[slotno], BLCKSZ, offset) != BLCKSZ)
713705
{
714706
pgstat_report_wait_end();
715707
slru_errcause = SLRU_READ_FAILED;
@@ -749,7 +741,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
749741
SlruShared shared = ctl->shared;
750742
int segno = pageno / SLRU_PAGES_PER_SEGMENT;
751743
int rpageno = pageno % SLRU_PAGES_PER_SEGMENT;
752-
int offset = rpageno * BLCKSZ;
744+
off_t offset = rpageno * BLCKSZ;
753745
char path[MAXPGPATH];
754746
int fd = -1;
755747

@@ -862,18 +854,9 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
862854
}
863855
}
864856

865-
if (lseek(fd, (off_t) offset, SEEK_SET) < 0)
866-
{
867-
slru_errcause = SLRU_SEEK_FAILED;
868-
slru_errno = errno;
869-
if (!fdata)
870-
CloseTransientFile(fd);
871-
return false;
872-
}
873-
874857
errno = 0;
875858
pgstat_report_wait_start(WAIT_EVENT_SLRU_WRITE);
876-
if (write(fd, shared->page_buffer[slotno], BLCKSZ) != BLCKSZ)
859+
if (pg_pwrite(fd, shared->page_buffer[slotno], BLCKSZ, offset) != BLCKSZ)
877860
{
878861
pgstat_report_wait_end();
879862
/* if write didn't set errno, assume problem is no disk space */

0 commit comments

Comments
 (0)