[v2] eal/rwlock: add note about writer starvation

Message ID 20210114165556.31353-1-stephen@networkplumber.org (mailing list archive)
State Not Applicable, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] eal/rwlock: add note about writer starvation |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS

Commit Message

Stephen Hemminger Jan. 14, 2021, 4:55 p.m. UTC
  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@networkplumber.org>
---
v2 - fix wording and spelling

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

Comments

Thomas Monjalon Feb. 11, 2021, 10:51 p.m. UTC | #1
14/01/2021 17:55, Stephen Hemminger:
> 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.

typo: "are expect"

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

Maybe add the URL in the commit message?

> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> --- a/lib/librte_eal/include/generic/rte_rwlock.h
> +++ b/lib/librte_eal/include/generic/rte_rwlock.h
> + * 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.

You did not get review, probably because nobody was Cc'ed.
+Cc Honnappa, Joyce and Konstantin
  
Honnappa Nagarahalli Feb. 12, 2021, 12:21 a.m. UTC | #2
<snip>

> 
> 14/01/2021 17:55, Stephen Hemminger:
> > 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.
> 
> typo: "are expect"
> 
> > The wikipedia page on reader-writer problem has a similar example
> > which summarizes the problem pretty well.
> 
> Maybe add the URL in the commit message?
> 
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> > --- a/lib/librte_eal/include/generic/rte_rwlock.h
> > +++ b/lib/librte_eal/include/generic/rte_rwlock.h
> > + * Note: This version of reader/writer locks is not fair because
                                ^^^^^^ may be "implementation" would be better?

> > + * 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.
This looks good. Though the writer starvation is prominent, the reader starvation is possible if there is a stream of writers when a writer holds the lock. Should we call this out too?

> 
> You did not get review, probably because nobody was Cc'ed.
> +Cc Honnappa, Joyce and Konstantin
>
  
Thomas Monjalon May 12, 2021, 7:10 p.m. UTC | #3
Ping for v3

12/02/2021 01:21, Honnappa Nagarahalli:
> <snip>
> 
> > 
> > 14/01/2021 17:55, Stephen Hemminger:
> > > 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.
> > 
> > typo: "are expect"
> > 
> > > The wikipedia page on reader-writer problem has a similar example
> > > which summarizes the problem pretty well.
> > 
> > Maybe add the URL in the commit message?
> > 
> > >
> > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > > ---
> > > --- a/lib/librte_eal/include/generic/rte_rwlock.h
> > > +++ b/lib/librte_eal/include/generic/rte_rwlock.h
> > > + * Note: This version of reader/writer locks is not fair because
>                                 ^^^^^^ may be "implementation" would be better?
> 
> > > + * 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.
> This looks good. Though the writer starvation is prominent, the reader starvation is possible if there is a stream of writers when a writer holds the lock. Should we call this out too?
> 
> > 
> > You did not get review, probably because nobody was Cc'ed.
> > +Cc Honnappa, Joyce and Konstantin
  
Thomas Monjalon Nov. 8, 2021, 10:18 a.m. UTC | #4
Ping again. Stephen?


12/05/2021 21:10, Thomas Monjalon:
> Ping for v3
> 
> 12/02/2021 01:21, Honnappa Nagarahalli:
> > <snip>
> > 
> > > 
> > > 14/01/2021 17:55, Stephen Hemminger:
> > > > 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.
> > > 
> > > typo: "are expect"
> > > 
> > > > The wikipedia page on reader-writer problem has a similar example
> > > > which summarizes the problem pretty well.
> > > 
> > > Maybe add the URL in the commit message?
> > > 
> > > >
> > > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > > > ---
> > > > --- a/lib/librte_eal/include/generic/rte_rwlock.h
> > > > +++ b/lib/librte_eal/include/generic/rte_rwlock.h
> > > > + * Note: This version of reader/writer locks is not fair because
> >                                 ^^^^^^ may be "implementation" would be better?
> > 
> > > > + * 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.
> > This looks good. Though the writer starvation is prominent, the reader starvation is possible if there is a stream of writers when a writer holds the lock. Should we call this out too?
> > 
> > > 
> > > You did not get review, probably because nobody was Cc'ed.
> > > +Cc Honnappa, Joyce and Konstantin
  

Patch

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