Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp28360863rwd; Tue, 4 Jul 2023 18:23:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lQDr2nDr6Av99sC38kIbf31T34zEZYsiAeu2k+2un5mLdQxmafnT5hutgOmR0FII+K6eD X-Received: by 2002:a05:6a20:2447:b0:12b:b9c0:aa61 with SMTP id t7-20020a056a20244700b0012bb9c0aa61mr14373090pzc.29.1688520220018; Tue, 04 Jul 2023 18:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688520220; cv=none; d=google.com; s=arc-20160816; b=SXnQAC2+0pikzirMgqBOyCAu35M3MB802T7V0TjaE0GfAPkZxgTCqmwYFpXqxHfkxp 3FzMkjkJCVe/BiDT4HXZjbtqFdM6OdXAgSGOf7Z8zsEBpAaRqBPu/0R4IoH8t0GVisx4 6gdezUvck1VCfr3NWPWECvhu99cU3RSmicjNl2X9R6y0G+ZEJmDuwcsAYo2oFopLRDBl Npk+URPmQrx9CJr4mc3huxTYzYkVF1k0asvzKoT9W5cigEML2RDCluEPmlCLG5pV+GR9 8LFGO/UiASTziqwkNo3veYImmSlHi4qLVmqKxDISXGifkbTDLvN71MiRw244eSfCDMDN zv2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding:dkim-signature :dkim-signature; bh=8g/P+lz2J9H9FHAfC3uIcGSPWcazDIR8ftztqEUCOrw=; fh=prpaJtz2kvK6JgUs4447rtm1pDQU9vyI1Km5GBTBT9o=; b=vfGVAOgRb2BmTBHGYVHYgsxz3QDbb8P+WWUir/JL+JYJDJ06K+nt2VauRhoJegkmvQ 0VU90toNYs7+85eUWL6of728NNiNFLBaWGfFWJYxbHwY4UD/m3qz8rP5koCPV2lnTIeB h18F2YKcyhOwBHXLAsaT9q6s1KuC9HBrIxoPq0srOwUpocTyC4i2OT27E8csWKNCqsk7 e1pIgdo8WUP6/IlrmgergepLHXYKweL+fcqBP4zASv7Qd2TCOou3hTgx4bZUQja2HaRm C9FwJXytCFSR4vXhEUCv3MyauL6fR6VdjC2xsRrU4I2WLFwZfCvWMKRHUQcE0lnccZhe XxlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=JBYWfP6D; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t13-20020a1709027fcd00b001b88ff83e45si6613260plb.571.2023.07.04.18.23.27; Tue, 04 Jul 2023 18:23:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=JBYWfP6D; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230504AbjGEBIl (ORCPT + 99 others); Tue, 4 Jul 2023 21:08:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjGEBIl (ORCPT ); Tue, 4 Jul 2023 21:08:41 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDF4210DD for ; Tue, 4 Jul 2023 18:08:39 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 776DC1F8D9; Wed, 5 Jul 2023 01:08:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1688519318; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8g/P+lz2J9H9FHAfC3uIcGSPWcazDIR8ftztqEUCOrw=; b=JBYWfP6D9ruK6DBpyORnY68G0plFdmYaKIPLJxKlVlHfSzyZu7nIHXlmZTMLVrr9YdEYxX nLTkaT+kA6C5H9XpKdjGc8DcgQILdHkPT1KsBQGJbZzKv4EhczWcVn9n2ir0sKgBMlQ43f Zvpql0D1h9f168Qek9MRAJL6IcWfsmE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1688519318; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8g/P+lz2J9H9FHAfC3uIcGSPWcazDIR8ftztqEUCOrw=; b=831aMR7AaHqwKAKKf8yFkpKuAqPAXc2PYIarvTBkVXKHO2ieBbAn/L9WhJGl1GQQH5UHdN ETix3kc4tWrNpLDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 210EB133F7; Wed, 5 Jul 2023 01:08:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CxE0MZPCpGQ/FAAAMHmgww (envelope-from ); Wed, 05 Jul 2023 01:08:35 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "NeilBrown" To: "Chuck Lever" Cc: linux-nfs@vger.kernel.org, "Chuck Lever" , lorenzo@kernel.org, jlayton@redhat.com, david@fromorbit.com Subject: Re: [PATCH v2 0/9] SUNRPC service thread scheduler optimizations In-reply-to: <168842897573.139194.15893960758088950748.stgit@manet.1015granger.net> References: <168842897573.139194.15893960758088950748.stgit@manet.1015granger.net> Date: Wed, 05 Jul 2023 11:08:32 +1000 Message-id: <168851931219.8939.14382911673248383020@noble.neil.brown.name> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org I've been pondering this scheduling mechanism in sunrpc/svc some more, and I wonder if rather than optimising the search, we should eliminate it. Instead we could have a linked list of idle threads using llist.h svc_enqueue_xprt calls llist_del_first() and if the result is not NULL, that thread is deemed busy (because it isn't on the list) and is woken. choose_victim() could also use llist_del_first(). If nothing is there it could set a flag which gets cleared by the next thread to go idle. That thread exits .. or something. Some interlock would be needed but it shouldn't be too hard. svc_exit_thread would have difficulty removing itself from the idle list, if it wasn't busy.. Possibly we could disallow that case (I think sending a signal to a thread can make it exit while idle). Alternately we could use llist_del_all() to clear the list, then wake them all up so that they go back on the list if there is nothing to do and if they aren't trying to exit. That is fairly heavy handed, but isn't a case that we need to optimise. If you think that might be worth pursuing, I could have a go at writing the patch - probably on top of all the cleanups in your series before the xarray is added. I also wonder if we should avoid waking too many threads up at once. If multiple events happen in quick succession, we currently wake up multiple threads and if there is any scheduling delay (which is expected based on Commit 22700f3c6df5 ("SUNRPC: Improve ordering of transport processi= ng")) then by the time the threads wake up, there may no longer be work to do as another thread might have gone idle and taken the work. Instead we could have a limit on the number of threads waking up - possibly 1 or 3. If the counter is maxed out, don't do a wake up. When a thread wakes up, it decrements the counter, dequeues some work, and if there is more to do, then it queues another task. I imagine the same basic protocol would be used for creating new threads when load is high - start just one at a time, though maybe a new thread would handle a first request before possibly starting another thread. But this is a stretch goal - not the main focus. Thanks, NeilBrown