Remove obsolete locking comment from AddBufferToRing()

Started by Chao Liabout 1 month ago4 messageshackers
Jump to latest
#1Chao Li
li.evan.chao@gmail.com

Hi,

While working on another patch, I spotted this stale comment on AddBufferToRing():
```
/*
* AddBufferToRing -- add a buffer to the buffer ring
*
* Caller must hold the buffer header spinlock on the buffer. Since this
* is called with the spinlock held, it had better be quite cheap.
*/
static void
AddBufferToRing(BufferAccessStrategy strategy, BufferDesc *buf)
```

It says the caller must hold the buffer header spinlock, but this is no longer true. The only caller of AddBufferToRing() is StrategyGetBuffer(), which pins the buffer without acquiring the buffer header lock.

This seems to be an oversight in 5e899859287. The commit explicitly removed buffer header locking from StrategyGetBuffer() and updated its comment as:
```
- *     To ensure that no one else can pin the buffer before we do, we must
- *     return the buffer with the buffer header spinlock still held.
+ *     It is the callers responsibility to ensure the buffer ownership can be
+ *     tracked via TrackNewBufferPin().
```

In the attached patch, I just deleted the stale paragraph without adding anything.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

t254228_1
v1-0001-Remove-obsolete-locking-comment-from-AddBufferToR.patchapplication/octet-stream; name=v1-0001-Remove-obsolete-locking-comment-from-AddBufferToR.patch; x-unix-mode=0644Download+0-4
#2Pierre Forstmann
pierre.forstmann@gmail.com
In reply to: Chao Li (#1)
Re: Remove obsolete locking comment from AddBufferToRing()

The following review has been posted through the commitfest application:
make installcheck-world: not tested
Implements feature: not tested
Spec compliant: not tested
Documentation: tested, passed

Hello,

This comment patching looks good to me.

Regards,
PF

The new status of this patch is: Ready for Committer

#3Heikki Linnakangas
hlinnaka@iki.fi
In reply to: Chao Li (#1)
Re: Remove obsolete locking comment from AddBufferToRing()

On 16/10/2026 11:10, Chao Li wrote:

Hi,

While working on another patch, I spotted this stale comment on AddBufferToRing():
```
/*
* AddBufferToRing -- add a buffer to the buffer ring
*
* Caller must hold the buffer header spinlock on the buffer. Since this
* is called with the spinlock held, it had better be quite cheap.
*/
static void
AddBufferToRing(BufferAccessStrategy strategy, BufferDesc *buf)
```

It says the caller must hold the buffer header spinlock, but this is no longer true. The only caller of AddBufferToRing() is StrategyGetBuffer(), which pins the buffer without acquiring the buffer header lock.

This seems to be an oversight in 5e899859287. The commit explicitly removed buffer header locking from StrategyGetBuffer() and updated its comment as:
```
- *     To ensure that no one else can pin the buffer before we do, we must
- *     return the buffer with the buffer header spinlock still held.
+ *     It is the callers responsibility to ensure the buffer ownership can be
+ *     tracked via TrackNewBufferPin().
```

In the attached patch, I just deleted the stale paragraph without adding anything.

Committed, thanks

- Heikki

#4Chao Li
li.evan.chao@gmail.com
In reply to: Heikki Linnakangas (#3)
Re: Remove obsolete locking comment from AddBufferToRing()

On Nov 5, 2026, at 23:10, Heikki Linnakangas <hlinnaka@iki.fi> wrote:

On 16/10/2026 11:10, Chao Li wrote:

Hi,
While working on another patch, I spotted this stale comment on AddBufferToRing():
```
/*
* AddBufferToRing -- add a buffer to the buffer ring
*
* Caller must hold the buffer header spinlock on the buffer. Since this
* is called with the spinlock held, it had better be quite cheap.
*/
static void
AddBufferToRing(BufferAccessStrategy strategy, BufferDesc *buf)
```
It says the caller must hold the buffer header spinlock, but this is no longer true. The only caller of AddBufferToRing() is StrategyGetBuffer(), which pins the buffer without acquiring the buffer header lock.
This seems to be an oversight in 5e899859287. The commit explicitly removed buffer header locking from StrategyGetBuffer() and updated its comment as:
```
- *     To ensure that no one else can pin the buffer before we do, we must
- *     return the buffer with the buffer header spinlock still held.
+ *     It is the callers responsibility to ensure the buffer ownership can be
+ *     tracked via TrackNewBufferPin().
```
In the attached patch, I just deleted the stale paragraph without adding anything.

Committed, thanks

- Heikki

Thanks for pushing.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/