|
23 | 23 | #include "storage/bufmgr.h"
|
24 | 24 | #include "storage/fd.h"
|
25 | 25 | #include "utils/guc_hooks.h"
|
| 26 | +#include "utils/memdebug.h" |
26 | 27 | #include "utils/memutils.h"
|
27 | 28 | #include "utils/resowner.h"
|
28 | 29 |
|
@@ -183,6 +184,8 @@ FlushLocalBuffer(BufferDesc *bufHdr, SMgrRelation reln)
|
183 | 184 | instr_time io_start;
|
184 | 185 | Page localpage = (char *) LocalBufHdrGetBlock(bufHdr);
|
185 | 186 |
|
| 187 | + Assert(LocalRefCount[-BufferDescriptorGetBuffer(bufHdr) - 1] > 0); |
| 188 | + |
186 | 189 | /*
|
187 | 190 | * Try to start an I/O operation. There currently are no reasons for
|
188 | 191 | * StartLocalBufferIO to return false, so we raise an error in that case.
|
@@ -808,6 +811,15 @@ PinLocalBuffer(BufferDesc *buf_hdr, bool adjust_usagecount)
|
808 | 811 | buf_state += BUF_USAGECOUNT_ONE;
|
809 | 812 | }
|
810 | 813 | pg_atomic_unlocked_write_u32(&buf_hdr->state, buf_state);
|
| 814 | + |
| 815 | + /* |
| 816 | + * See comment in PinBuffer(). |
| 817 | + * |
| 818 | + * If the buffer isn't allocated yet, it'll be marked as defined in |
| 819 | + * GetLocalBufferStorage(). |
| 820 | + */ |
| 821 | + if (LocalBufHdrGetBlock(buf_hdr) != NULL) |
| 822 | + VALGRIND_MAKE_MEM_DEFINED(LocalBufHdrGetBlock(buf_hdr), BLCKSZ); |
811 | 823 | }
|
812 | 824 | LocalRefCount[bufid]++;
|
813 | 825 | ResourceOwnerRememberBuffer(CurrentResourceOwner,
|
@@ -843,6 +855,9 @@ UnpinLocalBufferNoOwner(Buffer buffer)
|
843 | 855 | Assert(BUF_STATE_GET_REFCOUNT(buf_state) > 0);
|
844 | 856 | buf_state -= BUF_REFCOUNT_ONE;
|
845 | 857 | pg_atomic_unlocked_write_u32(&buf_hdr->state, buf_state);
|
| 858 | + |
| 859 | + /* see comment in UnpinBufferNoOwner */ |
| 860 | + VALGRIND_MAKE_MEM_NOACCESS(LocalBufHdrGetBlock(buf_hdr), BLCKSZ); |
846 | 861 | }
|
847 | 862 | }
|
848 | 863 |
|
@@ -923,6 +938,16 @@ GetLocalBufferStorage(void)
|
923 | 938 | next_buf_in_block++;
|
924 | 939 | total_bufs_allocated++;
|
925 | 940 |
|
| 941 | + /* |
| 942 | + * Caller's PinLocalBuffer() was too early for Valgrind updates, so do it |
| 943 | + * here. The block is actually undefined, but we want consistency with |
| 944 | + * the regular case of not needing to allocate memory. This is |
| 945 | + * specifically needed when method_io_uring.c fills the block, because |
| 946 | + * Valgrind doesn't recognize io_uring reads causing undefined memory to |
| 947 | + * become defined. |
| 948 | + */ |
| 949 | + VALGRIND_MAKE_MEM_DEFINED(this_buf, BLCKSZ); |
| 950 | + |
926 | 951 | return (Block) this_buf;
|
927 | 952 | }
|
928 | 953 |
|
|
0 commit comments