From patchwork Wed Sep 9 14:55:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 1360682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BmlSK0n0hz9sVR for ; Thu, 10 Sep 2020 00:55:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A028395CC42; Wed, 9 Sep 2020 14:55:25 +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 AC7353851C0C for ; Wed, 9 Sep 2020 14:55:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AC7353851C0C 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 756A9AD03 for ; Wed, 9 Sep 2020 14:55:37 +0000 (UTC) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] nscd: bump GC cycle during cache pruning (bug 26130) X-Yow: .. Once upon a time, four AMPHIBIOUS HOG CALLERS attacked a family of DEFENSELESS, SENSITIVE COIN COLLECTORS and brought DOWN their PROPERTY VALUES!! Date: Wed, 09 Sep 2020 16:55:21 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 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. Uniformly use atomic_fetch_add to modify the GC cycle counter. --- 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. */