summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Munro2020-08-01 11:39:36 +0000
committerThomas Munro2020-08-01 12:23:35 +0000
commite2b37d9e7cabc90633c4bd822e1bcfdd1bda44c4 (patch)
treef6cb217ead9b6e235c312ef2d4e2b53ec1716b9e
parent022350b8495a8a7ff0ff8dd6791572e91e7cd6fe (diff)
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
-rw-r--r--src/backend/access/transam/slru.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 61249f4a12d..9e145f1c36a 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -669,7 +669,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
SlruShared shared = ctl->shared;
int segno = pageno / SLRU_PAGES_PER_SEGMENT;
int rpageno = pageno % SLRU_PAGES_PER_SEGMENT;
- int offset = rpageno * BLCKSZ;
+ off_t offset = rpageno * BLCKSZ;
char path[MAXPGPATH];
int fd;
@@ -699,17 +699,9 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
return true;
}
- if (lseek(fd, (off_t) offset, SEEK_SET) < 0)
- {
- slru_errcause = SLRU_SEEK_FAILED;
- slru_errno = errno;
- CloseTransientFile(fd);
- return false;
- }
-
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_SLRU_READ);
- if (read(fd, shared->page_buffer[slotno], BLCKSZ) != BLCKSZ)
+ if (pg_pread(fd, shared->page_buffer[slotno], BLCKSZ, offset) != BLCKSZ)
{
pgstat_report_wait_end();
slru_errcause = SLRU_READ_FAILED;
@@ -749,7 +741,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
SlruShared shared = ctl->shared;
int segno = pageno / SLRU_PAGES_PER_SEGMENT;
int rpageno = pageno % SLRU_PAGES_PER_SEGMENT;
- int offset = rpageno * BLCKSZ;
+ off_t offset = rpageno * BLCKSZ;
char path[MAXPGPATH];
int fd = -1;
@@ -862,18 +854,9 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
}
}
- if (lseek(fd, (off_t) offset, SEEK_SET) < 0)
- {
- slru_errcause = SLRU_SEEK_FAILED;
- slru_errno = errno;
- if (!fdata)
- CloseTransientFile(fd);
- return false;
- }
-
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_SLRU_WRITE);
- if (write(fd, shared->page_buffer[slotno], BLCKSZ) != BLCKSZ)
+ if (pg_pwrite(fd, shared->page_buffer[slotno], BLCKSZ, offset) != BLCKSZ)
{
pgstat_report_wait_end();
/* if write didn't set errno, assume problem is no disk space */