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

Commit1b88b89

Browse files
committed
Specialize checkpointer sort functions.
When sorting a potentially large number of dirty buffers, thecheckpointer can benefit from a faster sort routine. One reportedimprovement on a large buffer pool system was 1.4s -> 0.6s.Reviewed-by: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/CA%2BhUKGJ2-eaDqAum5bxhpMNhvuJmRDZxB_Tow0n-gse%2BHG0Yig%40mail.gmail.com
1 parent519e4c9 commit1b88b89

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

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

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ static void FindAndDropRelFileNodeBuffers(RelFileNode rnode,
488488
staticvoidAtProcExit_Buffers(intcode,Datumarg);
489489
staticvoidCheckForBufferLeaks(void);
490490
staticintrnode_comparator(constvoid*p1,constvoid*p2);
491-
staticintbuffertag_comparator(constvoid*p1,constvoid*p2);
492-
staticintckpt_buforder_comparator(constvoid*pa,constvoid*pb);
491+
staticinlineintbuffertag_comparator(constBufferTag*a,constBufferTag*b);
492+
staticinlineintckpt_buforder_comparator(constCkptSortItem*a,constCkptSortItem*b);
493493
staticintts_ckpt_progress_comparator(Datuma,Datumb,void*arg);
494494

495495

@@ -1831,6 +1831,13 @@ UnpinBuffer(BufferDesc *buf, bool fixOwner)
18311831
}
18321832
}
18331833

1834+
#defineST_SORT sort_checkpoint_bufferids
1835+
#defineST_ELEMENT_TYPE CkptSortItem
1836+
#defineST_COMPARE(a,b) ckpt_buforder_comparator(a, b)
1837+
#defineST_SCOPE static
1838+
#defineST_DEFINE
1839+
#include<lib/sort_template.h>
1840+
18341841
/*
18351842
* BufferSync -- Write out all dirty buffers in the pool.
18361843
*
@@ -1931,8 +1938,7 @@ BufferSync(int flags)
19311938
* end up writing to the tablespaces one-by-one; possibly overloading the
19321939
* underlying system.
19331940
*/
1934-
qsort(CkptBufferIds,num_to_scan,sizeof(CkptSortItem),
1935-
ckpt_buforder_comparator);
1941+
sort_checkpoint_bufferids(CkptBufferIds,num_to_scan);
19361942

19371943
num_spaces=0;
19381944

@@ -4567,11 +4573,9 @@ WaitBufHdrUnlocked(BufferDesc *buf)
45674573
/*
45684574
* BufferTag comparator.
45694575
*/
4570-
staticint
4571-
buffertag_comparator(constvoid*a,constvoid*b)
4576+
staticinlineint
4577+
buffertag_comparator(constBufferTag*ba,constBufferTag*bb)
45724578
{
4573-
constBufferTag*ba= (constBufferTag*)a;
4574-
constBufferTag*bb= (constBufferTag*)b;
45754579
intret;
45764580

45774581
ret=rnode_comparator(&ba->rnode,&bb->rnode);
@@ -4598,12 +4602,9 @@ buffertag_comparator(const void *a, const void *b)
45984602
* It is important that tablespaces are compared first, the logic balancing
45994603
* writes between tablespaces relies on it.
46004604
*/
4601-
staticint
4602-
ckpt_buforder_comparator(constvoid*pa,constvoid*pb)
4605+
staticinlineint
4606+
ckpt_buforder_comparator(constCkptSortItem*a,constCkptSortItem*b)
46034607
{
4604-
constCkptSortItem*a= (constCkptSortItem*)pa;
4605-
constCkptSortItem*b= (constCkptSortItem*)pb;
4606-
46074608
/* compare tablespace */
46084609
if (a->tsId<b->tsId)
46094610
return-1;
@@ -4694,6 +4695,13 @@ ScheduleBufferTagForWriteback(WritebackContext *context, BufferTag *tag)
46944695
IssuePendingWritebacks(context);
46954696
}
46964697

4698+
#defineST_SORT sort_pending_writebacks
4699+
#defineST_ELEMENT_TYPE PendingWriteback
4700+
#defineST_COMPARE(a,b) buffertag_comparator(&a->tag, &b->tag)
4701+
#defineST_SCOPE static
4702+
#defineST_DEFINE
4703+
#include<lib/sort_template.h>
4704+
46974705
/*
46984706
* Issue all pending writeback requests, previously scheduled with
46994707
* ScheduleBufferTagForWriteback, to the OS.
@@ -4713,8 +4721,7 @@ IssuePendingWritebacks(WritebackContext *context)
47134721
* Executing the writes in-order can make them a lot faster, and allows to
47144722
* merge writeback requests to consecutive blocks into larger writebacks.
47154723
*/
4716-
qsort(&context->pending_writebacks,context->nr_pending,
4717-
sizeof(PendingWriteback),buffertag_comparator);
4724+
sort_pending_writebacks(context->pending_writebacks,context->nr_pending);
47184725

47194726
/*
47204727
* Coalesce neighbouring writes, but nothing else. For that we iterate

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp