public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] nscd: bump GC cycle during cache pruning (bug 26130)
@ 2020-09-17 15:59 Andreas Schwab
  0 siblings, 0 replies; only message in thread
From: Andreas Schwab @ 2020-09-17 15:59 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5e74e6f85842892bc25da8e8c70d8dadd485941a

commit 5e74e6f85842892bc25da8e8c70d8dadd485941a
Author: Andreas Schwab <schwab@suse.de>
Date:   Wed Jun 17 16:05:13 2020 +0200

    nscd: bump GC cycle during cache pruning (bug 26130)
    
    While nscd prunes a cache it becomes inconsistent temporarily, which is
    visible to clients if that cache is shared.  Bump the GC cycle counter so
    that the clients notice the modification window.
    
    Uniformly use atomic_fetch_add to modify the GC cycle counter.

Diff:
---
 nscd/cache.c | 9 +++++++++
 nscd/mem.c   | 4 ++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/nscd/cache.c b/nscd/cache.c
index 0c4dfc0dcf..38ddd6d7ec 100644
--- a/nscd/cache.c
+++ b/nscd/cache.c
@@ -452,6 +452,11 @@ prune_cache (struct database_dyn *table, time_t now, int fd)
 	  pthread_rwlock_wrlock (&table->lock);
 	}
 
+      /* Now we start modifying the data.  Make sure all readers of the
+	 data are aware of this and temporarily don't use the data.  */
+      atomic_fetch_add_relaxed (&table->head->gc_cycle, 1);
+      assert ((table->head->gc_cycle & 1) == 1);
+
       while (first <= last)
 	{
 	  if (mark[first])
@@ -492,6 +497,10 @@ prune_cache (struct database_dyn *table, time_t now, int fd)
 	  ++first;
 	}
 
+      /* Now we are done modifying the data.  */
+      atomic_fetch_add_relaxed (&table->head->gc_cycle, 1);
+      assert ((table->head->gc_cycle & 1) == 0);
+
       /* It's all done.  */
       pthread_rwlock_unlock (&table->lock);
 
diff --git a/nscd/mem.c b/nscd/mem.c
index 3d10bb9b46..de5bd12db5 100644
--- a/nscd/mem.c
+++ b/nscd/mem.c
@@ -264,7 +264,7 @@ gc (struct database_dyn *db)
 
   /* Now we start modifying the data.  Make sure all readers of the
      data are aware of this and temporarily don't use the data.  */
-  ++db->head->gc_cycle;
+  atomic_fetch_add_relaxed (&db->head->gc_cycle, 1);
   assert ((db->head->gc_cycle & 1) == 1);
 
 
@@ -490,7 +490,7 @@ gc (struct database_dyn *db)
 
 
   /* Now we are done modifying the data.  */
-  ++db->head->gc_cycle;
+  atomic_fetch_add_relaxed (&db->head->gc_cycle, 1);
   assert ((db->head->gc_cycle & 1) == 0);
 
   /* We are done.  */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-17 15:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 15:59 [glibc] nscd: bump GC cycle during cache pruning (bug 26130) Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).