Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5326326rdb; Wed, 13 Dec 2023 05:51:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjyY0fAdUhZ/3rvqCPs3Y1elomOOFyc1fORDzGjk1U7Cm8+uYWyYwR7XQgINQLYCyexbVj X-Received: by 2002:a05:6359:6d90:b0:170:302e:be37 with SMTP id tg16-20020a0563596d9000b00170302ebe37mr6566539rwb.57.1702475504804; Wed, 13 Dec 2023 05:51:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702475504; cv=none; d=google.com; s=arc-20160816; b=W4k9TuO2vwZhmoP6vjPF/BI4DJbG/Zn1m1LPyphBHUrRu1TUDkDc5TQ5lomYBITGYU 7HrLVn7ihD8r9aL4sSo+mBDHeOufIoyZmdMFcyTww3s4/bXpIG07XQBlsHUfU9tnUMTt tA+dEVlLXL9qGv7CRp8rgbNJzd8VplIf/fXo0GIO56v5rKpSaD6FBssylVUhW2+BxQVQ sANLYrL5MjcwsJf22X7B4/0aeml/kvByBUsfhpKGS7ZjoyQy6jNV+CTlH66lRNoq2IXE kvs0XmqZoxZCQZvq8EYepf5F/qF/J62P2qMs43/lOjfK1kGGifxhEzkUQFMCnztjprRQ O83g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ExN3aXWl+sIeMUeAn84eZ7A4PvMHoy42dD/Wo7lzJak=; fh=9eDgTo8aIuwg9MpGeudPwJT3CA93x8I1cKC8E1Wz3RU=; b=AdjfQW3lB4fILDw6PR3JwdPVB4pE+Axx8EhWUxGiRC5PGhDyiv/WzjKKB1Ll2JtnbO 04wqvdzO2bpfiDHrHHfJwzxIjWF04kUcyQDnCQi5ErFOmes6s9zPyPeErM6mN+oaQrWV dtv1ini+2kMCJTB2OAIwtvTeRZrlnLKJtopTcCI+k9Wj5lkv2AS/JaXTtEPAVdjWnpjp hNdHp7IikdqNyRQ99q+F+YBtzTBbNECTp4oSUghNIzOeD1QXOaUg3eQtPgQ4ypBt+2Sj iTcJRddDzfOogpSAdtxW0Qhg39mWw07OEvRUCpn1QHYwoIq1Ieqk90S7G0Z51PDvzDe0 s0Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iKyTxqSm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id z4-20020a656644000000b005c1faa82c06si9351269pgv.470.2023.12.13.05.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 05:51:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iKyTxqSm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id ADF74809E202; Wed, 13 Dec 2023 05:51:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379098AbjLMNuP (ORCPT + 99 others); Wed, 13 Dec 2023 08:50:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378960AbjLMNuK (ORCPT ); Wed, 13 Dec 2023 08:50:10 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AE4BD5 for ; Wed, 13 Dec 2023 05:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475415; h=from:from:reply-to:subject:subject: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=ExN3aXWl+sIeMUeAn84eZ7A4PvMHoy42dD/Wo7lzJak=; b=iKyTxqSmxZW4bLX5/AWuwgT4/6GQVx4jK3ncip00GAEh3L+PvmcmudSMrsoUoIdsvzZWsE R8CIM29dbb+vp3gB1FQvv+gOXdwNANLjSt3qcztsprzYJnx29cinm1eOS8QobJDfgZr0QW su2C/l1pINqYHC4OdQ83apSR6Zu3Jag= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-lg-8yNpGM3GXbqS7N0i_IQ-1; Wed, 13 Dec 2023 08:50:10 -0500 X-MC-Unique: lg-8yNpGM3GXbqS7N0i_IQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 13EAE83718B; Wed, 13 Dec 2023 13:50:10 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2723840C6EBA; Wed, 13 Dec 2023 13:50:09 +0000 (UTC) From: David Howells To: Marc Dionne Cc: David Howells , linux-afs@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Oleg Nesterov Subject: [PATCH v2 02/40] afs: fix the usage of read_seqbegin_or_lock() in afs_find_server*() Date: Wed, 13 Dec 2023 13:49:24 +0000 Message-ID: <20231213135003.367397-3-dhowells@redhat.com> In-Reply-To: <20231213135003.367397-1-dhowells@redhat.com> References: <20231213135003.367397-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 05:51:12 -0800 (PST) From: Oleg Nesterov David Howells says: (5) afs_find_server(). There could be a lot of servers in the list and each server can have multiple addresses, so I think this would be better with an exclusive second pass. The server list isn't likely to change all that often, but when it does change, there's a good chance several servers are going to be added/removed one after the other. Further, this is only going to be used for incoming cache management/callback requests from the server, which hopefully aren't going to happen too often - but it is remotely drivable. (6) afs_find_server_by_uuid(). Similarly to (5), there could be a lot of servers to search through, but they are in a tree not a flat list, so it should be faster to process. Again, it's not likely to change that often and, again, when it does change it's likely to involve multiple changes. This can be driven remotely by an incoming cache management request but is mostly going to be driven by setting up or reconfiguring a volume's server list - something that also isn't likely to happen often. Make the "seq" counter odd on the 2nd pass, otherwise read_seqbegin_or_lock() never takes the lock. Signed-off-by: Oleg Nesterov Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org Link: https://lore.kernel.org/r/20231130115614.GA21581@redhat.com/ --- fs/afs/server.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/afs/server.c b/fs/afs/server.c index b5237206eac3..0bd2f5ba6900 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -27,7 +27,7 @@ struct afs_server *afs_find_server(struct afs_net *net, const struct afs_addr_list *alist; struct afs_server *server = NULL; unsigned int i; - int seq = 0, diff; + int seq = 1, diff; rcu_read_lock(); @@ -35,6 +35,7 @@ struct afs_server *afs_find_server(struct afs_net *net, if (server) afs_unuse_server_notime(net, server, afs_server_trace_put_find_rsq); server = NULL; + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&net->fs_addr_lock, &seq); if (srx->transport.family == AF_INET6) { @@ -90,7 +91,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_net *net, const uuid_t *uu { struct afs_server *server = NULL; struct rb_node *p; - int diff, seq = 0; + int diff, seq = 1; _enter("%pU", uuid); @@ -102,7 +103,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_net *net, const uuid_t *uu if (server) afs_unuse_server(net, server, afs_server_trace_put_uuid_rsq); server = NULL; - + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&net->fs_lock, &seq); p = net->fs_servers.rb_node;