From: Jiri Wiesner <jwiesner@suse.de>
To: Julian Anastasov <ja@ssi.bg>
Cc: Simon Horman <horms@verge.net.au>,
lvs-devel@vger.kernel.org,
yunhong-cgl jiang <xintian1976@gmail.com>,
dust.li@linux.alibaba.com
Subject: Re: [RFC PATCHv6 4/7] ipvs: use kthreads for stats estimation
Date: Mon, 21 Nov 2022 17:05:27 +0100 [thread overview]
Message-ID: <20221121160527.GN3484@incl> (raw)
In-Reply-To: <20221031145647.156930-5-ja@ssi.bg>
On Mon, Oct 31, 2022 at 04:56:44PM +0200, Julian Anastasov wrote:
> Estimating all entries in single list in timer context
> causes large latency with multiple rules.
>
> Spread the estimator structures in multiple chains and
> use kthread(s) for the estimation. Every chain is
> processed under RCU lock. First kthread determines
> parameters to use, eg. maximum number of estimators to
> process per kthread based on chain's length, allowing
> sub-100us cond_resched rate and estimation taking 1/8
> of the CPU.
>
> First kthread also plays the role of distributor of
> added estimators to all kthreads.
>
> We also add delayed work est_reload_work that will
> make sure the kthread tasks are properly started/stopped.
>
> ip_vs_start_estimator() is changed to report errors
> which allows to safely store the estimators in
> allocated structures.
>
> Signed-off-by: Julian Anastasov <ja@ssi.bg>
> ---
Tested-by: Jiri Wiesner <jwiesner@suse.de>
Reviewed-by: Jiri Wiesner <jwiesner@suse.de>
> @@ -953,9 +1005,17 @@ struct netns_ipvs {
> struct ctl_table_header *lblcr_ctl_header;
> struct ctl_table *lblcr_ctl_table;
> /* ip_vs_est */
> - struct list_head est_list; /* estimator list */
> - spinlock_t est_lock;
> - struct timer_list est_timer; /* Estimation timer */
> + struct delayed_work est_reload_work;/* Reload kthread tasks */
> + struct mutex est_mutex; /* protect kthread tasks */
> + struct hlist_head est_temp_list; /* Ests during calc phase */
> + struct ip_vs_est_kt_data **est_kt_arr; /* Array of kthread data ptrs */
> + unsigned long est_max_threads;/* rlimit */
Not an rlimit anymore.
> + int est_calc_phase; /* Calculation phase */
> + int est_chain_max; /* Calculated chain_max */
> + int est_kt_count; /* Allocated ptrs */
> + int est_add_ktid; /* ktid where to add ests */
> + atomic_t est_genid; /* kthreads reload genid */
> + atomic_t est_genid_done; /* applied genid */
> /* ip_vs_sync */
> spinlock_t sync_lock;
> struct ipvs_master_sync_state *ms;
> - INIT_LIST_HEAD(&est->list);
> +/* Start estimation for stats */
> +int ip_vs_start_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats)
> +{
> + struct ip_vs_estimator *est = &stats->est;
> + int ret;
> +
> + if (!ipvs->est_max_threads && ipvs->enable)
> + ipvs->est_max_threads = 4 * num_possible_cpus();
To avoid the magic number - 4, a symbolic constant could be used. The 4 is related to the design decision that a fully loaded kthread should take 1/8 of the CPU time of a CPU.
> +
> + est->ktid = -1;
> + est->ktrow = IPVS_EST_NTICKS - 1; /* Initial delay */
> +
> + /* We prefer this code to be short, kthread 0 will requeue the
> + * estimator to available chain. If tasks are disabled, we
> + * will not allocate much memory, just for kt 0.
> + */
> + ret = 0;
> + if (!ipvs->est_kt_count || !ipvs->est_kt_arr[0])
> + ret = ip_vs_est_add_kthread(ipvs);
> + if (ret >= 0)
> + hlist_add_head(&est->list, &ipvs->est_temp_list);
> + else
> + INIT_HLIST_NODE(&est->list);
> + return ret;
> +}
--
Jiri Wiesner
SUSE Labs
next prev parent reply other threads:[~2022-11-21 16:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-31 14:56 [RFC PATCHv6 0/7] ipvs: Use kthreads for stats Julian Anastasov
2022-10-31 14:56 ` [RFC PATCHv6 1/7] ipvs: add rcu protection to stats Julian Anastasov
2022-11-12 7:51 ` Jiri Wiesner
2022-10-31 14:56 ` [RFC PATCHv6 2/7] ipvs: use common functions for stats allocation Julian Anastasov
2022-11-12 8:22 ` Jiri Wiesner
2022-10-31 14:56 ` [RFC PATCHv6 3/7] ipvs: use u64_stats_t for the per-cpu counters Julian Anastasov
2022-11-12 9:00 ` Jiri Wiesner
2022-11-12 9:09 ` Jiri Wiesner
2022-11-12 16:01 ` Julian Anastasov
2022-11-14 11:46 ` Julian Anastasov
2022-11-15 12:26 ` Jiri Wiesner
2022-11-15 16:53 ` Julian Anastasov
2022-11-16 17:37 ` Jiri Wiesner
2022-11-19 7:46 ` Jiri Wiesner
2022-10-31 14:56 ` [RFC PATCHv6 4/7] ipvs: use kthreads for stats estimation Julian Anastasov
2022-11-10 15:39 ` Jiri Wiesner
2022-11-10 20:16 ` Julian Anastasov
2022-11-11 17:21 ` Jiri Wiesner
2022-11-21 16:05 ` Jiri Wiesner [this message]
2022-10-31 14:56 ` [RFC PATCHv6 5/7] ipvs: add est_cpulist and est_nice sysctl vars Julian Anastasov
2022-11-21 16:29 ` Jiri Wiesner
2022-10-31 14:56 ` [RFC PATCHv6 6/7] ipvs: run_estimation should control the kthread tasks Julian Anastasov
2022-11-21 16:32 ` Jiri Wiesner
2022-10-31 14:56 ` [RFC PATCHv6 7/7] ipvs: debug the tick time Julian Anastasov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221121160527.GN3484@incl \
--to=jwiesner@suse.de \
--cc=dust.li@linux.alibaba.com \
--cc=horms@verge.net.au \
--cc=ja@ssi.bg \
--cc=lvs-devel@vger.kernel.org \
--cc=xintian1976@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).