[dpdk-dev] [PATCH v2] eal/rwlock: add note about writer starvation

Stephen Hemminger stephen at networkplumber.org
Thu Jan 14 17:55:56 CET 2021


The implementation of reader/writer locks in DPDK (from first release)
is simple and fast. But it can lead to writer starvation issues.

It is not easy to fix this without changing ABI and potentially
breaking customer applications that are expect the unfair behavior.

The wikipedia page on reader-writer problem has a similar example
which summarizes the problem pretty well.

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
v2 - fix wording and spelling

 lib/librte_eal/include/generic/rte_rwlock.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/librte_eal/include/generic/rte_rwlock.h b/lib/librte_eal/include/generic/rte_rwlock.h
index da9bc3e9c0e2..15980e2d93e5 100644
--- a/lib/librte_eal/include/generic/rte_rwlock.h
+++ b/lib/librte_eal/include/generic/rte_rwlock.h
@@ -15,6 +15,12 @@
  * one writer. All readers are blocked until the writer is finished
  * writing.
  *
+ * Note: This version of reader/writer locks is not fair because
+ * readers do not block for pending writers. A stream of readers can
+ * subsequently lock out all potential writers and starve them.
+ * This is because after the first reader locks the resource,
+ * no writer can lock it. The writer will only be able to get the lock
+ * when it will only be released by the last reader.
  */
 
 #ifdef __cplusplus
-- 
2.29.2



More information about the dev mailing list