@@ -156,15 +156,20 @@ SimpleLruShmemSize(int nslots, int nlsns)
156156 if (nlsns > 0 )
157157 sz += MAXALIGN (nslots * nlsns * sizeof (XLogRecPtr )); /* group_lsn[] */
158158
159+ /* size of lwlocks */
160+ sz = add_size (sz , LWLockTrancheShmemSize (nslots ));
161+
159162 return BUFFERALIGN (sz ) + BLCKSZ * nslots ;
160163}
161164
162165void
163166SimpleLruInit (SlruCtl ctl , const char * name , int nslots , int nlsns ,
164- LWLock * ctllock , const char * subdir )
167+ LWLock * ctllock , const char * subdir ,
168+ const char * lwlocks_tranche )
165169{
166- SlruShared shared ;
167- bool found ;
170+ SlruShared shared ;
171+ bool found ;
172+ LWLockPadded * lwlock_array ;
168173
169174 shared = (SlruShared ) ShmemInitStruct (name ,
170175 SimpleLruShmemSize (nslots , nlsns ),
@@ -212,13 +217,18 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
212217 }
213218
214219 ptr += BUFFERALIGN (offset );
220+
221+ /* Create tranche and lwlocks required for slots */
222+ LWLockCreateTranche (lwlocks_tranche , nslots , & lwlock_array );
223+
224+ /* Initialize slots */
215225 for (slotno = 0 ; slotno < nslots ; slotno ++ )
216226 {
217227 shared -> page_buffer [slotno ] = ptr ;
218228 shared -> page_status [slotno ] = SLRU_PAGE_EMPTY ;
219229 shared -> page_dirty [slotno ] = false;
220230 shared -> page_lru_count [slotno ] = 0 ;
221- shared -> buffer_locks [slotno ] = LWLockAssign () ;
231+ shared -> buffer_locks [slotno ] = & lwlock_array [ slotno ]. lock ;
222232 ptr += BLCKSZ ;
223233 }
224234 }
0 commit comments