mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Add nbtree Valgrind buffer lock checks.
Holding just a buffer pin (with no buffer lock) on an nbtree buffer/page provides very weak guarantees, especially compared to heapam, where it's often safe to read a page while only holding a buffer pin. This commit has Valgrind enforce the following rule: it is never okay to access an nbtree buffer without holding both a pin and a lock on the buffer. A draft version of this patch detected questionable code that was cleaned up by commitsfa7ff642and7154aa16. The code in question used to access an nbtree buffer page's special/opaque area with no buffer lock (only a buffer pin). This practice (which isn't obviously unsafe) is hereby formally disallowed in nbtree. There doesn't seem to be any reason to allow it, and banning it keeps things simple for Valgrind. The new checks are implemented by adding custom nbtree client requests (located in LockBuffer() wrapper functions); these requests are "superimposed" on top of the generic bufmgr.c Valgrind client requests added by commit1e0dfd16. No custom resource management cleanup code is needed to undo the effects of marking buffers as non-accessible under this scheme. Author: Peter Geoghegan Reviewed-By: Anastasia Lubennikova, Georgios Kokolatos Discussion: https://postgr.es/m/CAH2-WzkLgyN3zBvRZ1pkNJThC=xi_0gpWRUb_45eexLH1+k2_Q@mail.gmail.com
This commit is contained in:
@@ -271,11 +271,13 @@
|
||||
* Valgrind understands PostgreSQL memory contexts. This permits detecting
|
||||
* memory errors that Valgrind would not detect on a vanilla build. It also
|
||||
* enables detection of buffer accesses that take place without holding a
|
||||
* buffer pin. See also src/tools/valgrind.supp.
|
||||
* buffer pin (or without holding a buffer lock in the case of index access
|
||||
* methods that superimpose their own custom client requests on top of the
|
||||
* generic bufmgr.c requests). See also src/tools/valgrind.supp.
|
||||
*
|
||||
* "make installcheck" is significantly slower under Valgrind. The client
|
||||
* requests fall in hot code paths, so USE_VALGRIND slows native execution by
|
||||
* a few percentage points even when not run under Valgrind.
|
||||
* requests fall in hot code paths, so USE_VALGRIND slows execution by a few
|
||||
* percentage points even when not run under Valgrind.
|
||||
*
|
||||
* You should normally use MEMORY_CONTEXT_CHECKING with USE_VALGRIND;
|
||||
* instrumentation of repalloc() is inferior without it.
|
||||
|
||||
Reference in New Issue
Block a user