Remove a pointless layer of indirection in the WAL encryption buffer

The performance improvement should be tiny but this also makes the code
easier to follow.
pull/238/head
Andreas Karlsson 2 months ago committed by Andreas Karlsson
parent 4a9e09101b
commit c7cc1d6ec4
  1. 11
      contrib/pg_tde/src/access/pg_tde_xlog_smgr.c

@ -55,12 +55,12 @@ static ssize_t TDEXLogWriteEncryptedPages(int fd, const void *buf, size_t count,
typedef struct EncryptionStateData typedef struct EncryptionStateData
{ {
char *segBuf;
char db_map_path[MAXPGPATH]; char db_map_path[MAXPGPATH];
pg_atomic_uint64 enc_key_lsn; /* to sync with readers */ pg_atomic_uint64 enc_key_lsn; /* to sync with readers */
} EncryptionStateData; } EncryptionStateData;
static EncryptionStateData *EncryptionState = NULL; static EncryptionStateData *EncryptionState = NULL;
static char *EncryptionBuf;
/* TODO: can be swapped out to the disk */ /* TODO: can be swapped out to the disk */
static InternalKey EncryptionKey = static InternalKey EncryptionKey =
@ -126,7 +126,6 @@ void
TDEXLogShmemInit(void) TDEXLogShmemInit(void)
{ {
bool foundBuf; bool foundBuf;
char *allocptr;
EncryptionState = (EncryptionStateData *) EncryptionState = (EncryptionStateData *)
ShmemInitStruct("TDE XLog Encryption State", ShmemInitStruct("TDE XLog Encryption State",
@ -137,11 +136,9 @@ TDEXLogShmemInit(void)
if (EncryptXLog) if (EncryptXLog)
{ {
allocptr = ((char *) EncryptionState) + sizeof(EncryptionStateData); EncryptionBuf = (char *) TYPEALIGN(PG_IO_ALIGN_SIZE, ((char *) EncryptionState) + sizeof(EncryptionStateData));
allocptr = (char *) TYPEALIGN(PG_IO_ALIGN_SIZE, allocptr);
EncryptionState->segBuf = allocptr;
Assert((char *) EncryptionState + TDEXLogEncryptStateSize() >= (char *) EncryptionState->segBuf + TDEXLogEncryptBuffSize()); Assert((char *) EncryptionState + TDEXLogEncryptStateSize() >= (char *) EncryptionBuf + TDEXLogEncryptBuffSize());
} }
pg_atomic_init_u64(&EncryptionState->enc_key_lsn, 0); pg_atomic_init_u64(&EncryptionState->enc_key_lsn, 0);
@ -158,7 +155,7 @@ TDEXLogWriteEncryptedPages(int fd, const void *buf, size_t count, off_t offset,
{ {
char iv_prefix[16]; char iv_prefix[16];
InternalKey *key = &EncryptionKey; InternalKey *key = &EncryptionKey;
char *enc_buff = EncryptionState->segBuf; char *enc_buff = EncryptionBuf;
Assert(count <= TDEXLogEncryptBuffSize()); Assert(count <= TDEXLogEncryptBuffSize());

Loading…
Cancel
Save