mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
aio: Implement support for reads in smgr/md/fd
This implements the following: 1) An smgr AIO target, for AIO on smgr files. This should be usable not just for md.c but also other SMGR implementation if we ever get them. 2) readv support in fd.c, which requires a small bit of infrastructure work in fd.c 3) smgr.c and md.c support for readv There still is nothing performing AIO, but as of this commit it would be possible. As part of this change FileGetRawDesc() actually ensures that the file is opened - previously it was basically not usable. It's used to reopen a file in IO workers. Reviewed-by: Noah Misch <noah@leadboat.com> Discussion: https://postgr.es/m/uvrtrknj4kdytuboidbhwclo4gxhswwcpgadptsjvjqcluzmah%40brqs62irg4dt Discussion: https://postgr.es/m/20210223100344.llw5an2aklengrmn@alap3.anarazel.de Discussion: https://postgr.es/m/stj36ea6yyhoxtqkhpieia2z4krnam7qyetc57rfezgk4zgapf@gcnactj4z56m
This commit is contained in:
@@ -94,6 +94,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "postmaster/startup.h"
|
||||
#include "storage/aio.h"
|
||||
#include "storage/fd.h"
|
||||
#include "storage/ipc.h"
|
||||
#include "utils/guc.h"
|
||||
@@ -1296,6 +1297,8 @@ LruDelete(File file)
|
||||
|
||||
vfdP = &VfdCache[file];
|
||||
|
||||
pgaio_closing_fd(vfdP->fd);
|
||||
|
||||
/*
|
||||
* Close the file. We aren't expecting this to fail; if it does, better
|
||||
* to leak the FD than to mess up our internal state.
|
||||
@@ -1989,6 +1992,8 @@ FileClose(File file)
|
||||
|
||||
if (!FileIsNotOpen(file))
|
||||
{
|
||||
pgaio_closing_fd(vfdP->fd);
|
||||
|
||||
/* close the file */
|
||||
if (close(vfdP->fd) != 0)
|
||||
{
|
||||
@@ -2212,6 +2217,32 @@ retry:
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
int
|
||||
FileStartReadV(PgAioHandle *ioh, File file,
|
||||
int iovcnt, off_t offset,
|
||||
uint32 wait_event_info)
|
||||
{
|
||||
int returnCode;
|
||||
Vfd *vfdP;
|
||||
|
||||
Assert(FileIsValid(file));
|
||||
|
||||
DO_DB(elog(LOG, "FileStartReadV: %d (%s) " INT64_FORMAT " %d",
|
||||
file, VfdCache[file].fileName,
|
||||
(int64) offset,
|
||||
iovcnt));
|
||||
|
||||
returnCode = FileAccess(file);
|
||||
if (returnCode < 0)
|
||||
return returnCode;
|
||||
|
||||
vfdP = &VfdCache[file];
|
||||
|
||||
pgaio_io_start_readv(ioh, vfdP->fd, iovcnt, offset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
FileWriteV(File file, const struct iovec *iov, int iovcnt, off_t offset,
|
||||
uint32 wait_event_info)
|
||||
@@ -2500,6 +2531,12 @@ FilePathName(File file)
|
||||
int
|
||||
FileGetRawDesc(File file)
|
||||
{
|
||||
int returnCode;
|
||||
|
||||
returnCode = FileAccess(file);
|
||||
if (returnCode < 0)
|
||||
return returnCode;
|
||||
|
||||
Assert(FileIsValid(file));
|
||||
return VfdCache[file].fd;
|
||||
}
|
||||
@@ -2780,6 +2817,7 @@ FreeDesc(AllocateDesc *desc)
|
||||
result = closedir(desc->desc.dir);
|
||||
break;
|
||||
case AllocateDescRawFD:
|
||||
pgaio_closing_fd(desc->desc.fd);
|
||||
result = close(desc->desc.fd);
|
||||
break;
|
||||
default:
|
||||
@@ -2848,6 +2886,8 @@ CloseTransientFile(int fd)
|
||||
/* Only get here if someone passes us a file not in allocatedDescs */
|
||||
elog(WARNING, "fd passed to CloseTransientFile was not obtained from OpenTransientFile");
|
||||
|
||||
pgaio_closing_fd(fd);
|
||||
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user