mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +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:
@@ -117,9 +117,10 @@ typedef enum PgAioTargetID
|
||||
{
|
||||
/* intentionally the zero value, to help catch zeroed memory etc */
|
||||
PGAIO_TID_INVALID = 0,
|
||||
PGAIO_TID_SMGR,
|
||||
} PgAioTargetID;
|
||||
|
||||
#define PGAIO_TID_COUNT (PGAIO_TID_INVALID + 1)
|
||||
#define PGAIO_TID_COUNT (PGAIO_TID_SMGR + 1)
|
||||
|
||||
|
||||
/*
|
||||
@@ -191,6 +192,8 @@ struct PgAioTargetInfo
|
||||
typedef enum PgAioHandleCallbackID
|
||||
{
|
||||
PGAIO_HCB_INVALID,
|
||||
|
||||
PGAIO_HCB_MD_READV,
|
||||
} PgAioHandleCallbackID;
|
||||
|
||||
|
||||
|
||||
@@ -60,11 +60,15 @@ typedef struct PgAioWaitRef
|
||||
*/
|
||||
typedef union PgAioTargetData
|
||||
{
|
||||
/* just as an example placeholder for later */
|
||||
struct
|
||||
{
|
||||
uint32 queue_id;
|
||||
} wal;
|
||||
RelFileLocator rlocator; /* physical relation identifier */
|
||||
BlockNumber blockNum; /* blknum relative to begin of reln */
|
||||
BlockNumber nblocks;
|
||||
ForkNumber forkNum:8; /* don't waste 4 byte for four values */
|
||||
bool is_temp:1; /* proc can be inferred by owning AIO */
|
||||
bool skip_fsync:1;
|
||||
} smgr;
|
||||
} PgAioTargetData;
|
||||
|
||||
|
||||
|
||||
@@ -101,6 +101,8 @@ extern PGDLLIMPORT int max_safe_fds;
|
||||
* prototypes for functions in fd.c
|
||||
*/
|
||||
|
||||
struct PgAioHandle;
|
||||
|
||||
/* Operations on virtual Files --- equivalent to Unix kernel file ops */
|
||||
extern File PathNameOpenFile(const char *fileName, int fileFlags);
|
||||
extern File PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode);
|
||||
@@ -109,6 +111,7 @@ extern void FileClose(File file);
|
||||
extern int FilePrefetch(File file, off_t offset, off_t amount, uint32 wait_event_info);
|
||||
extern ssize_t FileReadV(File file, const struct iovec *iov, int iovcnt, off_t offset, uint32 wait_event_info);
|
||||
extern ssize_t FileWriteV(File file, const struct iovec *iov, int iovcnt, off_t offset, uint32 wait_event_info);
|
||||
extern int FileStartReadV(struct PgAioHandle *ioh, File file, int iovcnt, off_t offset, uint32 wait_event_info);
|
||||
extern int FileSync(File file, uint32 wait_event_info);
|
||||
extern int FileZero(File file, off_t offset, off_t amount, uint32 wait_event_info);
|
||||
extern int FileFallocate(File file, off_t offset, off_t amount, uint32 wait_event_info);
|
||||
|
||||
@@ -14,11 +14,14 @@
|
||||
#ifndef MD_H
|
||||
#define MD_H
|
||||
|
||||
#include "storage/aio_types.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/relfilelocator.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "storage/sync.h"
|
||||
|
||||
extern const PgAioHandleCallbacks aio_md_readv_cb;
|
||||
|
||||
/* md storage manager functionality */
|
||||
extern void mdinit(void);
|
||||
extern void mdopen(SMgrRelation reln);
|
||||
@@ -36,6 +39,9 @@ extern uint32 mdmaxcombine(SMgrRelation reln, ForkNumber forknum,
|
||||
BlockNumber blocknum);
|
||||
extern void mdreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
|
||||
void **buffers, BlockNumber nblocks);
|
||||
extern void mdstartreadv(PgAioHandle *ioh,
|
||||
SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
|
||||
void **buffers, BlockNumber nblocks);
|
||||
extern void mdwritev(SMgrRelation reln, ForkNumber forknum,
|
||||
BlockNumber blocknum,
|
||||
const void **buffers, BlockNumber nblocks, bool skipFsync);
|
||||
@@ -46,6 +52,7 @@ extern void mdtruncate(SMgrRelation reln, ForkNumber forknum,
|
||||
BlockNumber old_blocks, BlockNumber nblocks);
|
||||
extern void mdimmedsync(SMgrRelation reln, ForkNumber forknum);
|
||||
extern void mdregistersync(SMgrRelation reln, ForkNumber forknum);
|
||||
extern int mdfd(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, uint32 *off);
|
||||
|
||||
extern void ForgetDatabaseSyncRequests(Oid dbid);
|
||||
extern void DropRelationFiles(RelFileLocator *delrels, int ndelrels, bool isRedo);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#define SMGR_H
|
||||
|
||||
#include "lib/ilist.h"
|
||||
#include "storage/aio_types.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/relfilelocator.h"
|
||||
|
||||
@@ -73,6 +74,8 @@ typedef SMgrRelationData *SMgrRelation;
|
||||
#define SmgrIsTemp(smgr) \
|
||||
RelFileLocatorBackendIsTemp((smgr)->smgr_rlocator)
|
||||
|
||||
extern const PgAioTargetInfo aio_smgr_target_info;
|
||||
|
||||
extern void smgrinit(void);
|
||||
extern SMgrRelation smgropen(RelFileLocator rlocator, ProcNumber backend);
|
||||
extern bool smgrexists(SMgrRelation reln, ForkNumber forknum);
|
||||
@@ -97,6 +100,10 @@ extern uint32 smgrmaxcombine(SMgrRelation reln, ForkNumber forknum,
|
||||
extern void smgrreadv(SMgrRelation reln, ForkNumber forknum,
|
||||
BlockNumber blocknum,
|
||||
void **buffers, BlockNumber nblocks);
|
||||
extern void smgrstartreadv(PgAioHandle *ioh,
|
||||
SMgrRelation reln, ForkNumber forknum,
|
||||
BlockNumber blocknum,
|
||||
void **buffers, BlockNumber nblocks);
|
||||
extern void smgrwritev(SMgrRelation reln, ForkNumber forknum,
|
||||
BlockNumber blocknum,
|
||||
const void **buffers, BlockNumber nblocks,
|
||||
@@ -127,4 +134,11 @@ smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
|
||||
smgrwritev(reln, forknum, blocknum, &buffer, 1, skipFsync);
|
||||
}
|
||||
|
||||
extern void pgaio_io_set_target_smgr(PgAioHandle *ioh,
|
||||
SMgrRelationData *smgr,
|
||||
ForkNumber forknum,
|
||||
BlockNumber blocknum,
|
||||
int nblocks,
|
||||
bool skip_fsync);
|
||||
|
||||
#endif /* SMGR_H */
|
||||
|
||||
Reference in New Issue
Block a user