From e115a6edfaa07203c6d6d40eba9e4f097efe0cf2 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 25 Oct 2023 12:40:24 -0400 Subject: [PATCH] export: move cache_open() before workers are forked. If each worker has a separate open on a cache channel, then each worker will potentially receive every upcall request resulting in duplicated work. A worker will only not see a request that another worker sees if that other worker answers the request before this worker gets a chance to read it. To avoid duplicate effort between threads and so get maximum benefit from multiple threads, open the cache channels before forking. Note that the kernel provides locking so that only one thread can be reading to writing to any channel at any given moment. Fixes: 5fc3bac9e0c3 ("mountd: Ensure we don't share cache file descriptors among processes.") Signed-off-by: NeilBrown Signed-off-by: Steve Dickson --- utils/exportd/exportd.c | 8 ++++++-- utils/mountd/mountd.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/utils/exportd/exportd.c b/utils/exportd/exportd.c index 2dd12cb..6f86644 100644 --- a/utils/exportd/exportd.c +++ b/utils/exportd/exportd.c @@ -289,12 +289,16 @@ main(int argc, char **argv) else if (num_threads > MAX_THREADS) num_threads = MAX_THREADS; + /* Open cache channel files BEFORE forking so each upcall is + * only handled by one thread. Kernel provides locking for both + * read and write. + */ + cache_open(); + if (num_threads > 1) fork_workers(); - /* Open files now to avoid sharing descriptors among forked processes */ - cache_open(); v4clients_init(); /* Process incoming upcalls */ diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c index bcf749f..f9c62cd 100644 --- a/utils/mountd/mountd.c +++ b/utils/mountd/mountd.c @@ -916,12 +916,16 @@ main(int argc, char **argv) else if (num_threads > MAX_THREADS) num_threads = MAX_THREADS; + /* Open cache channel files BEFORE forking so each upcall is + * only handled by one thread. Kernel provides locking for both + * read and write. + */ + cache_open(); + if (num_threads > 1) fork_workers(); nfsd_path_init(); - /* Open files now to avoid sharing descriptors among forked processes */ - cache_open(); v4clients_init(); xlog(L_NOTICE, "Version " VERSION " starting"); -- 1.8.3.1