From patchwork Thu Jul 9 10:41:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 39991 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B924C386197E; Thu, 9 Jul 2020 10:41:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id D6A893861962 for ; Thu, 9 Jul 2020 10:41:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D6A893861962 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=schwab@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9221DAE39 for ; Thu, 9 Jul 2020 10:41:09 +0000 (UTC) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] nscd: bump GC cycle during cache pruning (bug 26130) X-Yow: I left my WALLET in the BATHROOM!! Date: Thu, 09 Jul 2020 12:41:09 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.91 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. Use atomic_fetch_add to modify the GC cycle counter, including in the gc function. --- 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 94163d9ce3..c0b9b4da3d 100644 --- a/nscd/cache.c +++ b/nscd/cache.c @@ -453,6 +453,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]) @@ -493,6 +498,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. */