Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit8ab4241

Browse files
anarazelnmisch
andcommitted
localbuf: Add Valgrind buffer access instrumentation
This mirrors1e0dfd1 (+46ef520), for temporary table buffers. Thisis mainly interesting right now because the AIO work currently triggersspurious valgrind errors, and the fix for that is cleaner if temp buffersbehave the same as shared buffers.This requires one change beyond the annotations themselves, namely to pinlocal buffers while writing them out in FlushRelationBuffers().Reviewed-by: Noah Misch <noah@leadboat.com>Co-authored-by: Noah Misch <noah@leadboat.com>Discussion:https://postgr.es/m/3pd4322mogfmdd5nln3zphdwhtmq3rzdldqjwb2sfqzcgs22lf@ok2gletdaoe6
1 parenta13d490 commit8ab4241

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4895,8 +4895,21 @@ FlushRelationBuffers(Relation rel)
48954895
errcallback.previous=error_context_stack;
48964896
error_context_stack=&errcallback;
48974897

4898+
/* Make sure we can handle the pin */
4899+
ReservePrivateRefCountEntry();
4900+
ResourceOwnerEnlarge(CurrentResourceOwner);
4901+
4902+
/*
4903+
* Pin/upin mostly to make valgrind work, but it also seems
4904+
* like the right thing to do.
4905+
*/
4906+
PinLocalBuffer(bufHdr, false);
4907+
4908+
48984909
FlushLocalBuffer(bufHdr,srel);
48994910

4911+
UnpinLocalBuffer(BufferDescriptorGetBuffer(bufHdr));
4912+
49004913
/* Pop the error context stack */
49014914
error_context_stack=errcallback.previous;
49024915
}

‎src/backend/storage/buffer/localbuf.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include"storage/bufmgr.h"
2424
#include"storage/fd.h"
2525
#include"utils/guc_hooks.h"
26+
#include"utils/memdebug.h"
2627
#include"utils/memutils.h"
2728
#include"utils/resowner.h"
2829

@@ -183,6 +184,8 @@ FlushLocalBuffer(BufferDesc *bufHdr, SMgrRelation reln)
183184
instr_timeio_start;
184185
Pagelocalpage= (char*)LocalBufHdrGetBlock(bufHdr);
185186

187+
Assert(LocalRefCount[-BufferDescriptorGetBuffer(bufHdr)-1]>0);
188+
186189
/*
187190
* Try to start an I/O operation. There currently are no reasons for
188191
* StartLocalBufferIO to return false, so we raise an error in that case.
@@ -808,6 +811,15 @@ PinLocalBuffer(BufferDesc *buf_hdr, bool adjust_usagecount)
808811
buf_state+=BUF_USAGECOUNT_ONE;
809812
}
810813
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);
811823
}
812824
LocalRefCount[bufid]++;
813825
ResourceOwnerRememberBuffer(CurrentResourceOwner,
@@ -843,6 +855,9 @@ UnpinLocalBufferNoOwner(Buffer buffer)
843855
Assert(BUF_STATE_GET_REFCOUNT(buf_state)>0);
844856
buf_state-=BUF_REFCOUNT_ONE;
845857
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);
846861
}
847862
}
848863

@@ -923,6 +938,16 @@ GetLocalBufferStorage(void)
923938
next_buf_in_block++;
924939
total_bufs_allocated++;
925940

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+
926951
return (Block)this_buf;
927952
}
928953

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp