From 12f635aa04c4a5c60307b3696c0f63f5f205989a Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Thu, 24 Oct 2024 17:09:38 +0300 Subject: [PATCH] Fix warnings --- pgxn/neon/file_cache.c | 1 - pgxn/neon/file_cache.h | 64 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 pgxn/neon/file_cache.h diff --git a/pgxn/neon/file_cache.c b/pgxn/neon/file_cache.c index fc46872c0a..d124ce59ba 100644 --- a/pgxn/neon/file_cache.c +++ b/pgxn/neon/file_cache.c @@ -688,7 +688,6 @@ lfc_load_pages(void) uint32 entry_offset; uint32 hash; int shard_no; - size_t i; FileCacheStateEntry* fs = lfc_state; size_t max_entries = lfc_state_size; diff --git a/pgxn/neon/file_cache.h b/pgxn/neon/file_cache.h new file mode 100644 index 0000000000..65985eb54d --- /dev/null +++ b/pgxn/neon/file_cache.h @@ -0,0 +1,64 @@ +/*------------------------------------------------------------------------- + * + * file_cache.h + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + *------------------------------------------------------------------------- + */ +#ifndef file_cache_h +#define file_cache_h + +#include "neon_pgversioncompat.h" + +/* Local file storage allocation chunk. + * Should be power of two. Using larger than page chunks can + * 1. Reduce hash-map memory footprint: 8TB database contains billion pages + * and size of hash entry is 40 bytes, so we need 40Gb just for hash map. + * 1Mb chunks can reduce hash map size to 320Mb. + * 2. Improve access locality, subsequent pages will be allocated together improving seqscan speed + */ +#define BLOCKS_PER_CHUNK 128 /* 1Mb chunk */ +#define CHUNK_BITMAP_SIZE ((BLOCKS_PER_CHUNK + 31) / 32) + +typedef struct +{ + BufferTag key; + uint32 bitmap[CHUNK_BITMAP_SIZE]; +} FileCacheEntryDesc; + +PGDLLEXPORT void LfcPrewarmMain(Datum main_arg); + +extern void lfc_writev(NRelFileInfo rinfo, ForkNumber forkNum, + BlockNumber blkno, const void *const *buffers, + BlockNumber nblocks); +/* returns number of blocks read, with one bit set in *read for each */ +extern int lfc_readv_select(NRelFileInfo rinfo, ForkNumber forkNum, + BlockNumber blkno, void **buffers, + BlockNumber nblocks, bits8 *mask); + +extern bool lfc_cache_contains(NRelFileInfo rinfo, ForkNumber forkNum, + BlockNumber blkno); +extern int lfc_cache_containsv(NRelFileInfo rinfo, ForkNumber forkNum, + BlockNumber blkno, int nblocks, bits8 *bitmap); +extern void lfc_evict(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno); +extern void lfc_init(void); + +static inline bool +lfc_read(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, + void *buffer) +{ + bits8 rv = 0; + return lfc_readv_select(rinfo, forkNum, blkno, &buffer, 1, &rv) == 1; +} + +static inline void +lfc_write(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, + const void *buffer) +{ + return lfc_writev(rinfo, forkNum, blkno, &buffer, 1); +} + +#endif