Skip to contentSkip to conversation

file: Use release ordering in file_ref_put()

RFC PATCH New Pranith Kumar 1 participant 1 message Nov 1 VFS

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 file: Use release ordering in file_ref_put()

file_ref_put() uses a fully ordered atomic decrement for every put, although it only requires release ordering for the decrement. Acquire ordering is needed only when the caller may destroy the file. On that path, __file_ref_put() already executes smp_acquire__after_ctrl_dep() after successfully changing the count to FILE_REF_DEAD.

Use atomic_long_dec_return_release() for the common decrement. On arm64 LSE this changes the fput() instruction from LDADDAL to LDADDL, so subsequent independent loads need not wait for an acquire that the common path does not require.

A pipe workload that performs 20,000 write/read pairs while a sleeping helper keeps the file table shared runs in 2.92% fewer cycles with this change.

---
 include/linux/file_ref.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/file_ref.h +1 -1
index 31551e4cb8f3..a5e262d7083c 100644
@@ -154,7 +154,7 @@ static __always_inline __must_check bool file_ref_put(file_ref_t *ref)
 	 * fails then we need to handle the last reference drop and
 	 * cases inside the saturation and dead zones.
 	 */
-	cnt = atomic_long_dec_return(&ref->refcnt);
+	cnt = atomic_long_dec_return_release(&ref->refcnt);
 	if (cnt >= 0)
 		return false;
 	return __file_ref_put(ref, cnt);
Signature · 1 line
2.47.3