From patchwork Fri Feb 7 05:15:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13964341 X-Patchwork-Delegate: cel@kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2F4D63D for ; Fri, 7 Feb 2025 05:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905441; cv=none; b=A4N1giCwoDzZJ6Uv/D+V3DcGptnjcXk1eT+whrMV24PhTI5/1Ok7gKXBVW4JhQXqA4iJJCzemsc/J/JmGPjj6ls9mu8NEjzjqsIxL7gWK9Se1NmLxMx1+eNV4TJOfV71u6rr/PpZMDPLwin39hcIDqm9zL4SmlJv8sTKL60lrGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905441; c=relaxed/simple; bh=P58Z1clrmoR8B9QFLaCAYX5Z3bc0GI8/X9ODmnHVcCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=So1E/C1AyBKbw7np3tSNXlJTTVRPhrFwLyoKXwz6/KGdYGT937quekTK8+trwt/XlLtYToMDrcw8MXLsQj37TcPo3uxrr41FhiRD5gKMgzCgDe/Y0LupFLcXZpQYE73L5Gr5LcgoKipnR8CrBaTeaui4wM6qbGIk850299B3nVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=DME1VThq; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=kagxxzki; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=DME1VThq; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=kagxxzki; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="DME1VThq"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="kagxxzki"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="DME1VThq"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="kagxxzki" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 04E9B1F38D; Fri, 7 Feb 2025 05:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905438; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VI54pzrJtIgzOmCySuFeZgjbA1rlXuRQdxYMMtme1fw=; b=DME1VThqCMUlI++YfScAXu+wz43Ajfib8BZr0jpfzOkEXwytx/53xI1n8H0PElatzkyDRV vijfq4jGmmB8CVTpnOh7pAMljnDxRnf4upQQ1WHpkw+qwxhFO7NmgQhNHE7oWvRBVz/q6x 2Vpvooyro1NJWdv61uBkyta2fgoHSDI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905438; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VI54pzrJtIgzOmCySuFeZgjbA1rlXuRQdxYMMtme1fw=; b=kagxxzkiJoYCufjD83sVLrpADmmiqdUgMBMmVnfXzRVYWjerXcN9/3iJIOFuySYmezqUN5 g109zE9YYWYHvACg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905438; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VI54pzrJtIgzOmCySuFeZgjbA1rlXuRQdxYMMtme1fw=; b=DME1VThqCMUlI++YfScAXu+wz43Ajfib8BZr0jpfzOkEXwytx/53xI1n8H0PElatzkyDRV vijfq4jGmmB8CVTpnOh7pAMljnDxRnf4upQQ1WHpkw+qwxhFO7NmgQhNHE7oWvRBVz/q6x 2Vpvooyro1NJWdv61uBkyta2fgoHSDI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905438; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VI54pzrJtIgzOmCySuFeZgjbA1rlXuRQdxYMMtme1fw=; b=kagxxzkiJoYCufjD83sVLrpADmmiqdUgMBMmVnfXzRVYWjerXcN9/3iJIOFuySYmezqUN5 g109zE9YYWYHvACg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8A6A113694; Fri, 7 Feb 2025 05:17:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id xXXJD1uXpWf2FgAAD6G6ig (envelope-from ); Fri, 07 Feb 2025 05:17:15 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey , Dave Chinner Subject: [PATCH 1/6] nfsd: filecache: remove race handling. Date: Fri, 7 Feb 2025 16:15:11 +1100 Message-ID: <20250207051701.3467505-2-neilb@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250207051701.3467505-1-neilb@suse.de> References: <20250207051701.3467505-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO The race that this code tries to protect against is not interesting. The code is problematic as we access the "nf" after we have given our reference to the lru system. While that take 2+ seconds to free things it is still poor form. The only interesting race I can find would be with nfsd_file_close_inode_sync(); This is the only place that really doesn't want the file to stay on the LRU when unhashed (which is the direct consequence of the race). However for the race to happen, some other thread must own a reference to a file and be putting in while nfsd_file_close_inode_sync() is trying to close all files for an inode. If this is possible, that other thread could simply call nfsd_file_put() a little bit later and the result would be the same: not all files are closed when nfsd_file_close_inode_sync() completes. If this was really a problem, we would need to wait in close_inode_sync for the other references to be dropped. We probably don't want to do that. So it is best to simply remove this code. Reviewed-by: Jeff Layton Signed-off-by: NeilBrown --- fs/nfsd/filecache.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index a1cdba42c4fa..b13255bcbb96 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -371,20 +371,10 @@ nfsd_file_put(struct nfsd_file *nf) /* Try to add it to the LRU. If that fails, decrement. */ if (nfsd_file_lru_add(nf)) { - /* If it's still hashed, we're done */ - if (test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { - nfsd_file_schedule_laundrette(); - return; - } - - /* - * We're racing with unhashing, so try to remove it from - * the LRU. If removal fails, then someone else already - * has our reference. - */ - if (!nfsd_file_lru_remove(nf)) - return; + nfsd_file_schedule_laundrette(); + return; } + } if (refcount_dec_and_test(&nf->nf_ref)) nfsd_file_free(nf); From patchwork Fri Feb 7 05:15:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13964342 X-Patchwork-Delegate: cel@kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C830E63D for ; Fri, 7 Feb 2025 05:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905447; cv=none; b=ZA7zWivBYt7L8/9QjB86TVOWE1HKMMcimHUmziiJRsSQfxC1u9UxQ7YzI/9vEQQCJiFOoThH0y6dJYcLuZ2po2ZS00wdfAX+w8qGxODDUNt85opyKovlTzTqNXhJk/seUu8vj0fGi9ZJT7nlvNB+fUTOBlc6/6BU6wSc6brbMs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905447; c=relaxed/simple; bh=equMA7yXGGv1zxOSRqamOEKqs21phBtiEgE2QnzQYJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k78fPuFD28PsA4rjv7VTaPl0bLGj/4QANFZLp5DroVVbI/o2K853T/Kf5VqLUbBKcGWUa306k3nkc0CDk3GECzqCGbkiI9XTW0K5PtNjlKzpxzbLjYWiuBXHyE56IiPbWfbt3yM511kLQevNoL91VsP8rtPc2hmJu5BL6ghbiV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=tsgTtIXZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=N9bo/xDu; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=tsgTtIXZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=N9bo/xDu; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="tsgTtIXZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="N9bo/xDu"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="tsgTtIXZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="N9bo/xDu" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id 046F621133; Fri, 7 Feb 2025 05:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905444; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tRIrh/TYxUKaMGRbEpT7gGZ3zPSuoMMG7o/Hi0VbAYY=; b=tsgTtIXZsjvEue0GU7uAFh+2tVduKGtTbJNrsg0AteoC/hOcab03oyovJMLGyYk3H2rhGm UynXxne3HJiDQIlSnJIKy4mjJ1Gt9mpnA22Y4dNOaV2Hkxtzgy6aMBM8bIBStB+uWNvHhN +FLjn12+si2nUnMqpvA9Kd51k4HIc+U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905444; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tRIrh/TYxUKaMGRbEpT7gGZ3zPSuoMMG7o/Hi0VbAYY=; b=N9bo/xDuY3hIkgofWK3tjWaO3KxjqMphYveqRK5waMQr+fzS5FWOe1MleQjk4+ktCPep8R bkKDY/FbCyns3SDw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905444; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tRIrh/TYxUKaMGRbEpT7gGZ3zPSuoMMG7o/Hi0VbAYY=; b=tsgTtIXZsjvEue0GU7uAFh+2tVduKGtTbJNrsg0AteoC/hOcab03oyovJMLGyYk3H2rhGm UynXxne3HJiDQIlSnJIKy4mjJ1Gt9mpnA22Y4dNOaV2Hkxtzgy6aMBM8bIBStB+uWNvHhN +FLjn12+si2nUnMqpvA9Kd51k4HIc+U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905444; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tRIrh/TYxUKaMGRbEpT7gGZ3zPSuoMMG7o/Hi0VbAYY=; b=N9bo/xDuY3hIkgofWK3tjWaO3KxjqMphYveqRK5waMQr+fzS5FWOe1MleQjk4+ktCPep8R bkKDY/FbCyns3SDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 81EBC13694; Fri, 7 Feb 2025 05:17:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id LJ1NDWGXpWf6FgAAD6G6ig (envelope-from ); Fri, 07 Feb 2025 05:17:21 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey , Dave Chinner Subject: [PATCH 2/6] nfsd: filecache: use nfsd_file_dispose_list() in nfsd_file_close_inode_sync() Date: Fri, 7 Feb 2025 16:15:12 +1100 Message-ID: <20250207051701.3467505-3-neilb@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250207051701.3467505-1-neilb@suse.de> References: <20250207051701.3467505-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[from(RLewrxuus8mos16izbn)]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO nfsd_file_close_inode_sync() contains an exactly copy of nfsd_file_dispose_list(). This patch removes it and calls nfsd_file_dispose_list() instead. Reviewed-by: Jeff Layton Signed-off-by: NeilBrown --- fs/nfsd/filecache.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index b13255bcbb96..7dc20143c854 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -666,17 +666,12 @@ nfsd_file_close_inode(struct inode *inode) void nfsd_file_close_inode_sync(struct inode *inode) { - struct nfsd_file *nf; LIST_HEAD(dispose); trace_nfsd_file_close(inode); nfsd_file_queue_for_close(inode, &dispose); - while (!list_empty(&dispose)) { - nf = list_first_entry(&dispose, struct nfsd_file, nf_gc); - list_del_init(&nf->nf_gc); - nfsd_file_free(nf); - } + nfsd_file_dispose_list(&dispose); } static int From patchwork Fri Feb 7 05:15:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13964343 X-Patchwork-Delegate: cel@kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B566214F9C4 for ; Fri, 7 Feb 2025 05:17:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905458; cv=none; b=ApkPuXhAI/KbkXkNKmNByC7JsrEU+uMm+OfhXky6Ni43ra+2gEMa48bl9lq4lUuILjOXOk7tCnTnWSXrYwFnY6xjGGajHCpCZDszvpGbDfEtHD5wG1B4Mv51fp+1H+76VWld+0J/5qPYVv/iE+6VYSJzcV3k4nXMdS0Uzd/qgOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905458; c=relaxed/simple; bh=KC6nTzpRfm0bzN7DfpVBGHyIPHAIcuS5GJXYc37UfM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ex/jis/D4KOcPJWH7y+B4CkJmWVClIW/Q+vjZl90AFsj88P/ayQMkDLeqI/ahpOGjekHD0Tamy4m0jMf7LL1ytV+eGcvpd6o05nBin6SXvIaVDmAVKDNBHZor8qdA/Tv3EHcMmCEojiL7SwKyvlKn0+NBh4zcmEkqMFcyL4/tf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=VOD3aDka; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=UzWZGOSp; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=BRWS4iG3; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=AcVl84BB; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="VOD3aDka"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="UzWZGOSp"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="BRWS4iG3"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AcVl84BB" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id F2A681F38D; Fri, 7 Feb 2025 05:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905455; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RGQmne6MLxrqXqQde476+/Bu4qVQH5In4NR8Qgo5FDA=; b=VOD3aDka0C5Xod1Dvq3czjpiRHLoVd5VWX2m4D/hrb0gD5kFghqTdLL2PIo4YRAWALo03c /ljhaxpBshhijTE5sXS9Ds67GCnsqo0GW4FRUBrXxPm755LON7DN8WFMfpPKx0QXkqxeWE emQhl4oA6P+dsEtfWDj333btW8KunqM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905455; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RGQmne6MLxrqXqQde476+/Bu4qVQH5In4NR8Qgo5FDA=; b=UzWZGOSpl9TlhUMP2dLhH2O0/WK6xKzIfCfomKHuuD/Fsth/7Q3Vd2nfdhoq0Lta1jXwEa pTWTz1c+fVgsKsBQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905454; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RGQmne6MLxrqXqQde476+/Bu4qVQH5In4NR8Qgo5FDA=; b=BRWS4iG3HY7kyszK+yY+5Oe7eYYP0Y18+JQC9qZh34El+H0TP2sUaQW/KMEz9dJPZX7ttO 0n4DrlRs0d6xtmTMWaX+CnvCOWhJf8DCi47x2oi5l/1jnN8nOKjuwSfR/q5vhMs0dCMTMZ DvGOW7W8pWsMvVf/JcvAKMpmJ/OZsuw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905454; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RGQmne6MLxrqXqQde476+/Bu4qVQH5In4NR8Qgo5FDA=; b=AcVl84BBcPWt+o6jmzZenF7JR5Ffr1uJ9QezPUMvH+r0FCZqMC+28p/gsuR8r/xVeVUrQR 9R2uNcZuV0NTv6Bw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7ADCE13694; Fri, 7 Feb 2025 05:17:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id zS3xC2uXpWcBFwAAD6G6ig (envelope-from ); Fri, 07 Feb 2025 05:17:31 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey , Dave Chinner Subject: [PATCH 3/6] nfsd: filecache: use list_lru_walk_node() in nfsd_file_gc() Date: Fri, 7 Feb 2025 16:15:13 +1100 Message-ID: <20250207051701.3467505-4-neilb@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250207051701.3467505-1-neilb@suse.de> References: <20250207051701.3467505-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[from(RLewrxuus8mos16izbn)]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO list_lru_walk() is only useful when the aim is to remove all elements from the list_lru. It will repeated visit rotated element of the first per-node sublist before proceeding to subsrequent sublists. This patch changes to use list_lru_walk_node() and list_lru_count_node() on each individual node. Signed-off-by: NeilBrown Reviewed-by: Jeff Layton --- fs/nfsd/filecache.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 7dc20143c854..04588c03bdfe 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -532,10 +532,14 @@ static void nfsd_file_gc(void) { LIST_HEAD(dispose); - unsigned long ret; + unsigned long ret = 0; + int nid; - ret = list_lru_walk(&nfsd_file_lru, nfsd_file_lru_cb, - &dispose, list_lru_count(&nfsd_file_lru)); + for_each_node_state(nid, N_NORMAL_MEMORY) { + unsigned long nr = list_lru_count_node(&nfsd_file_lru, nid); + ret += list_lru_walk_node(&nfsd_file_lru, nid, nfsd_file_lru_cb, + &dispose, &nr); + } trace_nfsd_file_gc_removed(ret, list_lru_count(&nfsd_file_lru)); nfsd_file_dispose_list_delayed(&dispose); } From patchwork Fri Feb 7 05:15:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13964344 X-Patchwork-Delegate: cel@kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BED0C14F9C4 for ; Fri, 7 Feb 2025 05:17:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905463; cv=none; b=FWGjy4Guallh0z4A8gVbB/8I2gdHyHjAHa9+7Ojz2jcZ/LEt+BauppDBRtPstSWOw7RPYgsfkVoqUyVsXxmAdD5VxJ22vP+KfJ/0x+IiG7Qfz19N3IVFIRgarTW3MXfQi+r9cNKgGlu3MBK3jFzh+QonNN9aVAMrIs8qLeF9i0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905463; c=relaxed/simple; bh=nSZz6Pj/s3cItEYEKl6cBiUdDVPYLP9oqzN5JfVeY4E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AvhQVRPYIciWvnkAdlrnTOD/D4toBVALNL2uzY+TNG3IITISWNSyH515yi+rZFTFhY0K6BPwELsnM5/ioQ6dCF3iilv8IQaCVt+HyVHKTqVaijoiKV9nVJy8byD/b7dh/SOuGSoYfLfnyGI9p0+b7uYPo8RWLbuOHhMBILAV0BY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jHvCXHrA; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=3SnG58GO; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jHvCXHrA; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=3SnG58GO; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jHvCXHrA"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="3SnG58GO"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jHvCXHrA"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="3SnG58GO" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 0685B1F38D; Fri, 7 Feb 2025 05:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905460; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TDMUVU9C7kxdtq5b8fVLw7+0ebUWoLiL7My3XjJVuLE=; b=jHvCXHrAgppUGuoPio/Z+v2YsmDCvHp3WrSC0S4tXno+G2vxJVuJsJCDjnX69GV5P+wCym eqfzYnEdpsuV2g7dPTu8EhIZvrcjCYISXjfDcv3rfGsUpUDdby+38OTRZv6lSQo0zo0lGP ZBq1zjG69oMF7MNSbBK8N/eJLd0VHoU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905460; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TDMUVU9C7kxdtq5b8fVLw7+0ebUWoLiL7My3XjJVuLE=; b=3SnG58GOtxf4VKlaMr93jWizOVPNKwRM6/goC+WAXt6VSweZvPd08y6hZ4Y9yjQM6FZYB+ HaqcUL44tSDYwHCA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905460; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TDMUVU9C7kxdtq5b8fVLw7+0ebUWoLiL7My3XjJVuLE=; b=jHvCXHrAgppUGuoPio/Z+v2YsmDCvHp3WrSC0S4tXno+G2vxJVuJsJCDjnX69GV5P+wCym eqfzYnEdpsuV2g7dPTu8EhIZvrcjCYISXjfDcv3rfGsUpUDdby+38OTRZv6lSQo0zo0lGP ZBq1zjG69oMF7MNSbBK8N/eJLd0VHoU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905460; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TDMUVU9C7kxdtq5b8fVLw7+0ebUWoLiL7My3XjJVuLE=; b=3SnG58GOtxf4VKlaMr93jWizOVPNKwRM6/goC+WAXt6VSweZvPd08y6hZ4Y9yjQM6FZYB+ HaqcUL44tSDYwHCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 839FA13694; Fri, 7 Feb 2025 05:17:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 1YkcDnGXpWcUFwAAD6G6ig (envelope-from ); Fri, 07 Feb 2025 05:17:37 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey , Dave Chinner Subject: [PATCH 4/6] nfsd: filecache: introduce NFSD_FILE_RECENT Date: Fri, 7 Feb 2025 16:15:14 +1100 Message-ID: <20250207051701.3467505-5-neilb@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250207051701.3467505-1-neilb@suse.de> References: <20250207051701.3467505-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[from(RLewrxuus8mos16izbn)]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: The filecache lru is walked in 2 circumstances for 2 different reasons. 1/ When called from the shrinker we want to discard the first few entries on the list, ignoring any with NFSD_FILE_REFERENCED set because they should really be at the end of the LRU as they have been referenced recently. So those ones are ROTATED. 2/ When called from the nfsd_file_gc() timer function we want to discard anything that hasn't been used since before the previous call, and mark everything else as unused at this point in time. Using the same flag for both of these can result in some unexpected outcomes. If the shrinker callback clears NFSD_FILE_REFERENCED then the nfsd_file_gc() will think the file hasn't been used in a while, while really it has. I think it is easier to reason about the behaviour if we instead have two flags. NFSD_FILE_REFERENCED means "this should be at the end of the LRU, please put it there when convenient" NFSD_FILE_RECENT means "this has been used recently - since the last run of nfsd_file_gc() When either caller finds an NFSD_FILE_REFERENCED entry, that entry should be moved to the end of the LRU and the flag cleared. This can safely happen at any time. The actual order on the lru might not be strictly least-recently-used, but that is normal for linux lrus. The shrinker callback can ignore the "recent" flag. If it ends up freeing something that is "recent" that simply means that memory pressure is sufficient to limit the acceptable cache age to less than the nfsd_file_gc frequency. The gc caller should primarily focus on NFSD_FILE_RECENT. It should free everything that doesn't have this flag set, and should clear the flag on everything else. When it clears the flag it is convenient to clear the "REFERENCED" flag and move to the end of the LRU too. With this, calls from the shrinker do not prematurely age files. It will focus only on freeing those that are least recently used. Signed-off-by: NeilBrown Reviewed-by: Jeff Layton --- fs/nfsd/filecache.c | 21 +++++++++++++++++++-- fs/nfsd/filecache.h | 1 + fs/nfsd/trace.h | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 04588c03bdfe..9faf469354a5 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -318,10 +318,10 @@ nfsd_file_check_writeback(struct nfsd_file *nf) mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK); } - static bool nfsd_file_lru_add(struct nfsd_file *nf) { set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); + set_bit(NFSD_FILE_RECENT, &nf->nf_flags); if (list_lru_add_obj(&nfsd_file_lru, &nf->nf_lru)) { trace_nfsd_file_lru_add(nf); return true; @@ -528,6 +528,23 @@ nfsd_file_lru_cb(struct list_head *item, struct list_lru_one *lru, return LRU_REMOVED; } +static enum lru_status +nfsd_file_gc_cb(struct list_head *item, struct list_lru_one *lru, + void *arg) +{ + struct nfsd_file *nf = list_entry(item, struct nfsd_file, nf_lru); + + if (test_and_clear_bit(NFSD_FILE_RECENT, &nf->nf_flags)) { + /* "REFERENCED" really means "should be at the end of the LRU. + * As we are putting it there we can clear the flag + */ + clear_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); + trace_nfsd_file_gc_aged(nf); + return LRU_ROTATE; + } + return nfsd_file_lru_cb(item, lru, arg); +} + static void nfsd_file_gc(void) { @@ -537,7 +554,7 @@ nfsd_file_gc(void) for_each_node_state(nid, N_NORMAL_MEMORY) { unsigned long nr = list_lru_count_node(&nfsd_file_lru, nid); - ret += list_lru_walk_node(&nfsd_file_lru, nid, nfsd_file_lru_cb, + ret += list_lru_walk_node(&nfsd_file_lru, nid, nfsd_file_gc_cb, &dispose, &nr); } trace_nfsd_file_gc_removed(ret, list_lru_count(&nfsd_file_lru)); diff --git a/fs/nfsd/filecache.h b/fs/nfsd/filecache.h index d5db6b34ba30..de5b8aa7fcb0 100644 --- a/fs/nfsd/filecache.h +++ b/fs/nfsd/filecache.h @@ -38,6 +38,7 @@ struct nfsd_file { #define NFSD_FILE_PENDING (1) #define NFSD_FILE_REFERENCED (2) #define NFSD_FILE_GC (3) +#define NFSD_FILE_RECENT (4) unsigned long nf_flags; refcount_t nf_ref; unsigned char nf_may; diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h index ad2c0c432d08..9af723eeb2b0 100644 --- a/fs/nfsd/trace.h +++ b/fs/nfsd/trace.h @@ -1039,6 +1039,7 @@ DEFINE_CLID_EVENT(confirmed_r); { 1 << NFSD_FILE_HASHED, "HASHED" }, \ { 1 << NFSD_FILE_PENDING, "PENDING" }, \ { 1 << NFSD_FILE_REFERENCED, "REFERENCED" }, \ + { 1 << NFSD_FILE_RECENT, "RECENT" }, \ { 1 << NFSD_FILE_GC, "GC" }) DECLARE_EVENT_CLASS(nfsd_file_class, @@ -1317,6 +1318,7 @@ DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_lru_del_disposed); DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_in_use); DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_writeback); DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_referenced); +DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_aged); DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_disposed); DECLARE_EVENT_CLASS(nfsd_file_lruwalk_class, @@ -1346,6 +1348,7 @@ DEFINE_EVENT(nfsd_file_lruwalk_class, name, \ TP_ARGS(removed, remaining)) DEFINE_NFSD_FILE_LRUWALK_EVENT(nfsd_file_gc_removed); +DEFINE_NFSD_FILE_LRUWALK_EVENT(nfsd_file_gc_recent); DEFINE_NFSD_FILE_LRUWALK_EVENT(nfsd_file_shrinker_removed); TRACE_EVENT(nfsd_file_close, From patchwork Fri Feb 7 05:15:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13964345 X-Patchwork-Delegate: cel@kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C881014F9C4 for ; Fri, 7 Feb 2025 05:17:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905473; cv=none; b=keM+elW6iijkj6dVfVGXWKKskp0mJ0AjPH6JmzedCtYjqL1CLY2kJr2mqThjKZ5TbR9ibzfsdvyUdHDRLpe5srhKAaNWbnzBHSDohf2tbCuXjjRQg2gLN/9eR96uZmV/sSFI/Pg13rCFJZFsKUFC0VaVGw1x6nlSScQOnK0wB8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905473; c=relaxed/simple; bh=BLdjNi4jt+e1njUxgffpEoCfT/OEDGut/T7MPmYKMA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BmQgnPGGn3JgtwEmjRIYEucwNFWet+I5YtuuYyqq/44DSJdlrhpN9NMbpeBdFzzJ7CvGQxNltib0bxjrorK6RA1PaBQ7jGgO7FH5c6q1eIQz/PDIhkwGMXpDG7iRfI/y1IOfsUbg5wBea4nwd/DOd6g6wWvipZsZ7jf0VKfC2mU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=12vu3uee; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=pRf3/HIG; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=12vu3uee; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=pRf3/HIG; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="12vu3uee"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="pRf3/HIG"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="12vu3uee"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="pRf3/HIG" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 00EA51F38D; Fri, 7 Feb 2025 05:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905470; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=srMh542wBPbyvKGDrB6pMPkBocvKPHx47uRByHLSBJI=; b=12vu3ueewO/UtWcsyVBCA65lK5qWJp07YUyuctZSLmqZOfeD+hRfuC/Nr8C0DdS9aZZXtj nvV1rJjkVKwCv4REZLsnwoq3Tavc8Oo74bCCTYfpPkN+02h7mqPsW/ufosYnKF/ZYNT/bi tFiRxKMTVVS54QffGYGBE9riJkcwg1M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905470; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=srMh542wBPbyvKGDrB6pMPkBocvKPHx47uRByHLSBJI=; b=pRf3/HIGOMcTUgjuB/ZY+iITR23dOL0cHX2QCG27FeCk75lFBv6U2WyjJSiAokV+EXSICX 0F5xzpFRrbG5EADA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=12vu3uee; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="pRf3/HIG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905470; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=srMh542wBPbyvKGDrB6pMPkBocvKPHx47uRByHLSBJI=; b=12vu3ueewO/UtWcsyVBCA65lK5qWJp07YUyuctZSLmqZOfeD+hRfuC/Nr8C0DdS9aZZXtj nvV1rJjkVKwCv4REZLsnwoq3Tavc8Oo74bCCTYfpPkN+02h7mqPsW/ufosYnKF/ZYNT/bi tFiRxKMTVVS54QffGYGBE9riJkcwg1M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905470; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=srMh542wBPbyvKGDrB6pMPkBocvKPHx47uRByHLSBJI=; b=pRf3/HIGOMcTUgjuB/ZY+iITR23dOL0cHX2QCG27FeCk75lFBv6U2WyjJSiAokV+EXSICX 0F5xzpFRrbG5EADA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 79A3513694; Fri, 7 Feb 2025 05:17:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id tSG3C3uXpWceFwAAD6G6ig (envelope-from ); Fri, 07 Feb 2025 05:17:47 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey , Dave Chinner Subject: [PATCH 5/6] nfsd: filecache: don't repeatedly add/remove files on the lru list Date: Fri, 7 Feb 2025 16:15:15 +1100 Message-ID: <20250207051701.3467505-6-neilb@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250207051701.3467505-1-neilb@suse.de> References: <20250207051701.3467505-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 00EA51F38D X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:dkim,suse.de:mid,suse.de:email]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; R_RATELIMIT(0.00)[from(RLewrxuus8mos16izbn)]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Level: There is no need to remove a file from the lru every time we access it, and then add it back. It is sufficient to set the REFERENCED flag every time we put the file. The order in the lru of REFERENCED files is largely irrelevant as they will all be moved to the end. With this patch, files are only added when they are allocated (if want_gc) and they are only removed by the list_lru_(shrink_)walk callback or when forcibly removing a file. This should reduce contention on the list_lru spinlock(s) and reduce memory traffic a little. Signed-off-by: NeilBrown --- fs/nfsd/filecache.c | 51 +++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 9faf469354a5..d1ce0bc86ff7 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -318,15 +318,14 @@ nfsd_file_check_writeback(struct nfsd_file *nf) mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK); } -static bool nfsd_file_lru_add(struct nfsd_file *nf) +static void nfsd_file_lru_add(struct nfsd_file *nf) { - set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); - set_bit(NFSD_FILE_RECENT, &nf->nf_flags); - if (list_lru_add_obj(&nfsd_file_lru, &nf->nf_lru)) { + refcount_inc(&nf->nf_ref); + if (list_lru_add_obj(&nfsd_file_lru, &nf->nf_lru)) trace_nfsd_file_lru_add(nf); - return true; - } - return false; + else + WARN_ON(1); + nfsd_file_schedule_laundrette(); } static bool nfsd_file_lru_remove(struct nfsd_file *nf) @@ -362,20 +361,10 @@ nfsd_file_put(struct nfsd_file *nf) if (test_bit(NFSD_FILE_GC, &nf->nf_flags) && test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { - /* - * If this is the last reference (nf_ref == 1), then try to - * transfer it to the LRU. - */ - if (refcount_dec_not_one(&nf->nf_ref)) - return; - - /* Try to add it to the LRU. If that fails, decrement. */ - if (nfsd_file_lru_add(nf)) { - nfsd_file_schedule_laundrette(); - return; - } - + set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); + set_bit(NFSD_FILE_RECENT, &nf->nf_flags); } + if (refcount_dec_and_test(&nf->nf_ref)) nfsd_file_free(nf); } @@ -510,13 +499,12 @@ nfsd_file_lru_cb(struct list_head *item, struct list_lru_one *lru, } /* - * Put the reference held on behalf of the LRU. If it wasn't the last - * one, then just remove it from the LRU and ignore it. + * Put the reference held on behalf of the LRU if it is the last + * reference, else rotate. */ - if (!refcount_dec_and_test(&nf->nf_ref)) { + if (!refcount_dec_if_one(&nf->nf_ref)) { trace_nfsd_file_gc_in_use(nf); - list_lru_isolate(lru, &nf->nf_lru); - return LRU_REMOVED; + return LRU_ROTATE; } /* Refcount went to zero. Unhash it and queue it to the dispose list */ @@ -1046,16 +1034,8 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct net *net, nf = nfsd_file_lookup_locked(net, current_cred(), inode, need, want_gc); rcu_read_unlock(); - if (nf) { - /* - * If the nf is on the LRU then it holds an extra reference - * that must be put if it's removed. It had better not be - * the last one however, since we should hold another. - */ - if (nfsd_file_lru_remove(nf)) - refcount_dec(&nf->nf_ref); + if (nf) goto wait_for_construction; - } new = nfsd_file_alloc(net, inode, need, want_gc); if (!new) { @@ -1149,6 +1129,9 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct net *net, */ if (status != nfs_ok || inode->i_nlink == 0) nfsd_file_unhash(nf); + else if (want_gc) + nfsd_file_lru_add(nf); + clear_and_wake_up_bit(NFSD_FILE_PENDING, &nf->nf_flags); if (status == nfs_ok) goto out; From patchwork Fri Feb 7 05:15:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13964346 X-Patchwork-Delegate: cel@kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6F8B14F9C4 for ; Fri, 7 Feb 2025 05:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905479; cv=none; b=sp2FaHjvDczxWI4fZy0w7shdTGzC/T4XAP0xUdkPZ3EeVmUGc7/9IDjXwEUVCRX/JVo8sf3BF9BTCrBMsuQOp9E8TsBuUSjJOG0qkOJIQ196IimcRksh0zioGSFb0VXGTUo9qEzTkrkkwctQP5R/lS/lpWmg/WaSW0gbw7sik/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738905479; c=relaxed/simple; bh=gG7CdlQKviFJzEOM5RuuOe2cC5NxRie4hTd9xCT0XOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U1NE2OuqcK1i22v05x/Mvg3KvUB6Nv04OHF0i+oL2uFTiasdQ10G4IwS8hQ612JvTCgWxvPkzRC326JuU0MtxkZPM5xD8Kt/vAtq14YJV/LMG4Wn0Q4IPoc0GP9vrVlvTbBP207S5bG0DXRVxRrygUzqZIKXv2voJkKqZjexD+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=cqVqqPrE; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Yocfy0o6; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=E/V9emz4; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=amaDs3YJ; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="cqVqqPrE"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Yocfy0o6"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="E/V9emz4"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="amaDs3YJ" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id EB02921133; Fri, 7 Feb 2025 05:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905476; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g6wzLGMXv76tyWMql3E+wb6WTpmcsY+i+ln/Az0yDQk=; b=cqVqqPrEEgwnZLTvmVIL2XNTStxEFQlcJiUvJ7/dQnqrEy7kMv/SopedFBPyerp9q6s12K Q73vSF0+wtszAoaCMOF/OH5Mveg/tOUpFA5/vy+CQwzKHB1qZeeYxkhYy9gmGFrwtjltqm AzfsO6ho2pWPwoNL80J7tcRWEEAv5PM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905476; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g6wzLGMXv76tyWMql3E+wb6WTpmcsY+i+ln/Az0yDQk=; b=Yocfy0o6sE4fKgzdG9J/SBvug5yB/rLPM5HWIPJ2/jOUr/pJpP1NNa6dYF5W2plmYCNPQp Zoj8qgZ1VB0CnzAA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="E/V9emz4"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=amaDs3YJ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738905475; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g6wzLGMXv76tyWMql3E+wb6WTpmcsY+i+ln/Az0yDQk=; b=E/V9emz4cG7CBb0jtePV/1fh2ZiqHrxPCdqzQZHUxc6Ys1tZYipJCXKEsZ+DsTwoEavHNm dJsin7cwBDya/5VGG6m9XJ14NU/hMcjB1LZM6S3MHrewYfUd5qVmNoOnSHdn6a1uDUg7mK JlHOlb1jxxn6FR0TyzqvNsIPBN1qB/0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738905475; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g6wzLGMXv76tyWMql3E+wb6WTpmcsY+i+ln/Az0yDQk=; b=amaDs3YJlTImEx9wJreBqtzGHc+OFfbrIgJcNgdpM+8O/VliKzoH9CD3iGx1X2dC7myRSN CNx4daA+jA5M8PCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7ED2813694; Fri, 7 Feb 2025 05:17:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id M8HtDIGXpWcpFwAAD6G6ig (envelope-from ); Fri, 07 Feb 2025 05:17:53 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey , Dave Chinner Subject: [PATCH 6/6] nfsd: filecache: drop the list_lru lock during lock gc scans Date: Fri, 7 Feb 2025 16:15:16 +1100 Message-ID: <20250207051701.3467505-7-neilb@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250207051701.3467505-1-neilb@suse.de> References: <20250207051701.3467505-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: EB02921133 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim,suse.de:mid]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; R_RATELIMIT(0.00)[from(RLewrxuus8mos16izbn)]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO Under a high NFSv3 load with lots of different files being accessed, the LRU list of garbage-collectable files can become quite long. Asking list_lru_scan_node() to scan the whole list can result in a long period during which a spinlock is held, blocking the addition of new LRU items. So ask list_lru_scan_node() to scan only a few entries at a time, and repeat until the scan is complete. If the shrinker runs between two consecutive calls of list_lru_scan_node() it could invalidate the "remaining" counter which could lead to premature freeing. So add a spinlock to avoid that. Signed-off-by: NeilBrown --- fs/nfsd/filecache.c | 27 ++++++++++++++++++++++++--- fs/nfsd/filecache.h | 6 ++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index d1ce0bc86ff7..54df5e23f119 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -533,6 +533,13 @@ nfsd_file_gc_cb(struct list_head *item, struct list_lru_one *lru, return nfsd_file_lru_cb(item, lru, arg); } +/* If the shrinker runs between calls to list_lru_walk_node() in + * nfsd_file_gc(), the "remaining" count will be wrong. This could + * result in premature freeing of some files. This may not matter much + * but is easy to fix with this spinlock which temporarily disables + * the shrinker. + */ +static DEFINE_SPINLOCK(nfsd_gc_lock); static void nfsd_file_gc(void) { @@ -540,11 +547,21 @@ nfsd_file_gc(void) unsigned long ret = 0; int nid; + spin_lock(&nfsd_gc_lock); for_each_node_state(nid, N_NORMAL_MEMORY) { - unsigned long nr = list_lru_count_node(&nfsd_file_lru, nid); - ret += list_lru_walk_node(&nfsd_file_lru, nid, nfsd_file_gc_cb, - &dispose, &nr); + unsigned long remaining = list_lru_count_node(&nfsd_file_lru, nid); + + while (remaining > 0) { + unsigned long nr = min(remaining, NFSD_FILE_GC_BATCH); + remaining -= nr; + ret += list_lru_walk_node(&nfsd_file_lru, nid, nfsd_file_gc_cb, + &dispose, &nr); + if (nr) + /* walk aborted early */ + remaining = 0; + } } + spin_unlock(&nfsd_gc_lock); trace_nfsd_file_gc_removed(ret, list_lru_count(&nfsd_file_lru)); nfsd_file_dispose_list_delayed(&dispose); } @@ -569,8 +586,12 @@ nfsd_file_lru_scan(struct shrinker *s, struct shrink_control *sc) LIST_HEAD(dispose); unsigned long ret; + if (!spin_trylock(&nfsd_gc_lock)) + return SHRINK_STOP; + ret = list_lru_shrink_walk(&nfsd_file_lru, sc, nfsd_file_lru_cb, &dispose); + spin_unlock(&nfsd_gc_lock); trace_nfsd_file_shrinker_removed(ret, list_lru_count(&nfsd_file_lru)); nfsd_file_dispose_list_delayed(&dispose); return ret; diff --git a/fs/nfsd/filecache.h b/fs/nfsd/filecache.h index de5b8aa7fcb0..5865f9c72712 100644 --- a/fs/nfsd/filecache.h +++ b/fs/nfsd/filecache.h @@ -3,6 +3,12 @@ #include +/* + * Limit the time that the list_lru_one lock is held during + * an LRU scan. + */ +#define NFSD_FILE_GC_BATCH (16UL) + /* * This is the fsnotify_mark container that nfsd attaches to the files that it * is holding open. Note that we have a separate refcount here aside from the