Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 79e3bda

Browse filesBrowse files
author
Daniel Shelepanov
committed
intermediate
1 parent 33a3f33 commit 79e3bda
Copy full SHA for 79e3bda

File tree

Expand file treeCollapse file tree

2 files changed

+17
-31
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-31
lines changed

‎engine.c

Copy file name to clipboardExpand all lines: engine.c
+10-27Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,9 @@ ptrackCheckpoint(void)
449449
uint32 lsn;
450450

451451
/*
452-
* We store LSN values as pg_atomic_uint64 in the ptrack map, but
453-
* pg_atomic_read_u64() returns uint64. That way, we have to put this
454-
* lsn into the buffer array of pg_atomic_uint64's. We are the only
452+
* We store LSN values as pg_atomic_uint32 in the ptrack map, but
453+
* pg_atomic_read_u32() returns uint32. That way, we have to put this
454+
* lsn into the buffer array of pg_atomic_uint32's. We are the only
455455
* one who write into this buffer, so we do it without locks.
456456
*
457457
* TODO: is it safe and can we do any better?
@@ -551,7 +551,7 @@ assign_ptrack_map_size(int newval, void *extra)
551551
!InitializingParallelWorker)
552552
{
553553
/* Cast to uint64 in order to avoid int32 overflow */
554-
ptrack_map_size = (uint64) 1024 * 1024 * newval;
554+
ptrack_map_size = (uint64)(1024 * 1024 * newval);
555555

556556
elog(DEBUG1, "assign_ptrack_map_size: ptrack_map_size set to " UINT64_FORMAT,
557557
ptrack_map_size);
@@ -688,30 +688,13 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
688688

689689
/*
690690
* Get a second position within ptrack map so that it fits
691-
* within the same cache line.
691+
* within the same memory page.
692692
*/
693-
size_t
694-
get_slot2(size_t slot1, uint64 hash) {
695-
size_t memory_page_ep; // ending point of a cache line
696-
size_t memory_page_sp; // starting point of a cache line
697-
size_t memory_page_interval;
698-
size_t slot2;
699-
700-
/* Get the ending point of a memory page within entries[]. */
701-
memory_page_ep = (MEMORY_PAGE_ALIGN(offsetof(PtrackMapHdr, entries) + slot1*sizeof(uint32))
702-
- offsetof(PtrackMapHdr, entries)) / sizeof(uint32);
703-
/* handling an overflow beyond the entries boundary */
704-
memory_page_ep = memory_page_ep > PtrackContentNblocks ? PtrackContentNblocks : memory_page_ep;
705-
706-
/* Get the starting point of a cache line within entries[]. */
707-
memory_page_sp = memory_page_ep - ENTRIES_PER_PAGE;
708-
709-
/* Handling overflow below zero (sp then must be larger than ep) */
710-
memory_page_sp = memory_page_sp > memory_page_ep ? 0 : memory_page_sp;
711-
712-
memory_page_interval = memory_page_ep - memory_page_sp;
713-
slot2 = (size_t)(memory_page_sp + (((hash << 32) | (hash >> 32)) % memory_page_interval));
714-
slot2 = (slot1 == slot2) ? ((slot1+1) % memory_page_interval) : slot2;
693+
inline size_t
694+
get_slot2(size_t slot1, uint32 hash) {
695+
size_t slot2;
696+
slot2 = TYPEALIGN_DOWN(ENTRIES_PER_PAGE, slot1) + ((hash << 16) | (hash >> 16)) % ENTRIES_PER_PAGE;
697+
slot2 = slot1 == slot2 ? slot2+1 : slot2;
715698
return slot2;
716699
}
717700

‎engine.h

Copy file name to clipboardExpand all lines: engine.h
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444
* A reasonable assumption for most systems. Postgres core
4545
* leverages the same value for this purpose.
4646
*/
47-
#define MEMORY_PAGE_SIZE 4096
48-
#define MEMORY_PAGE_ALIGN(LEN) TYPEALIGN(MEMORY_PAGE_SIZE, (LEN))
49-
#define ENTRIES_PER_PAGE (MEMORY_PAGE_SIZE/sizeof(XLogRecPtr))
47+
#define MEMORY_PAGE_SIZE 4096
48+
#define MEMORY_PAGE_ALIGN(LEN) TYPEALIGN(MEMORY_PAGE_SIZE, (LEN))
49+
#define MEMORY_PAGE_ALIGN_DOWN(LEN) TYPEALIGN_DOWN(MEMORY_PAGE_SIZE, (LEN))
50+
#define ENTRIES_PER_PAGE (MEMORY_PAGE_SIZE/sizeof(uint32))
5051

5152
/* Ptrack magic bytes */
5253
#define PTRACK_MAGIC "ptk"
@@ -73,6 +74,8 @@ typedef struct PtrackMapHdr
7374
*/
7475
uint32 version_num;
7576

77+
/* Padding needed to align entries[] by the page boundary */
78+
char padding[4096 - PTRACK_MAGIC_SIZE - sizeof(uint32) - 2*sizeof(pg_atomic_uint32)];
7679
/* LSN of current writing position */
7780
pg_atomic_uint32 latest_lsn;
7881
/* LSN of the moment, when map was last enabled. */
@@ -130,7 +133,7 @@ extern XLogRecPtr ptrack_read_file_maxlsn(RelFileNode smgr_rnode,
130133
ForkNumber forknum);
131134

132135
extern bool is_cfm_file_path(const char *path);
133-
extern size_t get_slot2(size_t slot1, uint64 hash);
136+
extern size_t get_slot2(size_t slot1, uint32 hash);
134137
#ifdef PGPRO_EE
135138
extern off_t get_cfs_relation_file_decompressed_size(RelFileNodeBackend rnode,
136139
const char *fullpath, ForkNumber forknum);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.