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

Commitc8f3bc2

Browse files
committed
Optimize latches to send fewer signals.
Don't send signals to processes that aren't sleeping.Author: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/CA+hUKGJjxPDpzBE0a3hyUywBvaZuC89yx3jK9RFZgfv_KHU7gg@mail.gmail.com
1 parentd1b9099 commitc8f3bc2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

‎src/backend/storage/ipc/latch.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ void
274274
InitLatch(Latch*latch)
275275
{
276276
latch->is_set= false;
277+
latch->maybe_sleeping= false;
277278
latch->owner_pid=MyProcPid;
278279
latch->is_shared= false;
279280

@@ -321,6 +322,7 @@ InitSharedLatch(Latch *latch)
321322
#endif
322323

323324
latch->is_set= false;
325+
latch->maybe_sleeping= false;
324326
latch->owner_pid=0;
325327
latch->is_shared= true;
326328
}
@@ -523,6 +525,10 @@ SetLatch(Latch *latch)
523525

524526
latch->is_set= true;
525527

528+
pg_memory_barrier();
529+
if (!latch->maybe_sleeping)
530+
return;
531+
526532
#ifndefWIN32
527533

528534
/*
@@ -589,6 +595,7 @@ ResetLatch(Latch *latch)
589595
{
590596
/* Only the owner should reset the latch */
591597
Assert(latch->owner_pid==MyProcPid);
598+
Assert(latch->maybe_sleeping== false);
592599

593600
latch->is_set= false;
594601

@@ -1270,6 +1277,14 @@ WaitEventSetWait(WaitEventSet *set, long timeout,
12701277
* ordering, so that we cannot miss seeing is_set if a notification
12711278
* has already been queued.
12721279
*/
1280+
if (set->latch&& !set->latch->is_set)
1281+
{
1282+
/* about to sleep on a latch */
1283+
set->latch->maybe_sleeping= true;
1284+
pg_memory_barrier();
1285+
/* and recheck */
1286+
}
1287+
12731288
if (set->latch&&set->latch->is_set)
12741289
{
12751290
occurred_events->fd=PGINVALID_SOCKET;
@@ -1280,6 +1295,9 @@ WaitEventSetWait(WaitEventSet *set, long timeout,
12801295
occurred_events++;
12811296
returned_events++;
12821297

1298+
/* could have been set above */
1299+
set->latch->maybe_sleeping= false;
1300+
12831301
break;
12841302
}
12851303

@@ -1291,6 +1309,12 @@ WaitEventSetWait(WaitEventSet *set, long timeout,
12911309
rc=WaitEventSetWaitBlock(set,cur_timeout,
12921310
occurred_events,nevents);
12931311

1312+
if (set->latch)
1313+
{
1314+
Assert(set->latch->maybe_sleeping);
1315+
set->latch->maybe_sleeping= false;
1316+
}
1317+
12941318
if (rc==-1)
12951319
break;/* timeout occurred */
12961320
else

‎src/include/storage/latch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
typedefstructLatch
111111
{
112112
sig_atomic_tis_set;
113+
sig_atomic_tmaybe_sleeping;
113114
boolis_shared;
114115
intowner_pid;
115116
#ifdefWIN32

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp