-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep profile and history data in shared memory #66
base: master
Are you sure you want to change the base?
Changes from 1 commit
49ff16c
ef33592
3bfb23d
08b7e8c
f0b62aa
9a69965
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,16 +129,27 @@ probe_waits(const bool write_history, const bool write_profile) | |
int32 wait_event_info = proc->wait_event_info, | ||
pid = proc->pid; | ||
|
||
// FIXME: zero pid actually doesn't indicate that process slot is freed. | ||
// After process termination this field becomes unchanged and thereby | ||
// stores the pid of previous process. The possible indicator of process | ||
// termination might be a condition `proc->procLatch->owner_pid == 0`. | ||
// Abother option is to use the lists of freed PGPROCs from ProcGlocal: | ||
// freeProcs, walsenderFreeProcs, bgworkerFreeProcs and autovacFreeProcs | ||
// to define indexes of all freed slots in allProcs. | ||
// The most appropriate solution here is to iterate over ProcArray items | ||
// to explicitly access to the all live PGPROC entries. This will | ||
// require to build iterator object over protected procArray. | ||
/* | ||
* FIXME: zero pid actually doesn't indicate that process slot is freed. | ||
* After process termination this field becomes unchanged and thereby | ||
* stores the pid of previous process. The possible indicator of process | ||
* termination might be a condition `proc->procLatch->owner_pid == 0`. | ||
* But even in this case ProcArrayLock doesn't protect `owner_pid` | ||
* field from concurrent modifications that might cause race conditions. | ||
* | ||
* Abother option is to use the lists of freed PGPROCs from ProcGlocal: | ||
* freeProcs, walsenderFreeProcs, bgworkerFreeProcs and autovacFreeProcs | ||
* to define indexes of all freed slots in allProcs. But this requires | ||
* acquiring ProcStructLock spinlock that is impractical for iteration | ||
* over so long lists. | ||
* | ||
* The most appropriate solution here is to iterate over ProcArray items | ||
* under ProcArrayLock and over AuxiliaryProcs under ProcStructLock | ||
* spinlock (AuxiliaryProcs contains just NUM_AUXILIARY_PROCS=5 slots) | ||
* or without any locks as it's done in pg_stat_get_activity() function. | ||
* These arrays are not accessible externally and require to add some | ||
* iterator object into corresponding containing modules. | ||
*/ | ||
if (pid == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that we can follow pg_stat_get_activity and get away without any locks. The only risk is that we take a few incorrect samples and attribute wait_event_info to a wrong pid. That doesn't seem to be a problem. At least pg_stat_activity lives with it. Concerning the Shall we decide to sample non-waiting states (wait_event_info == 0), then we could iterate over BackendStatusArray to visit only live backends, like pg_stat_activity does via pgstat_read_current_status. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In pg_stat_activity we iterate over auxiliary PROC slots without any lock. This is practical as these slots are reserved for long-lived background workers as bgwriter, checkpointer, walwriter, archiver and wal_receiver. Any changes in this specific range of slots occur very rare and most commonly are initiated by external forces. Although we might use
Yes, in current case it works. But when we will start to add the state "no wait" as pointed in #10 we have to consider the working criteria whether PROC slot is freed.
Requesting PROC slots from pid values gotten from |
||
continue; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be uint32 as in PGPROC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks. Will fix it.