mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: "Dilger\, Andreas" <andreas.dilger@intel.com>
Cc: "Drokin\, Oleg" <oleg.drokin@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	James Simmons <jsimmons@infradead.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	Lustre Development List <lustre-devel@lists.lustre.org>
Subject: Re: [PATCH 11/17] staging: lustre: ptlrpc: use workqueue for pinger
Date: Mon, 12 Mar 2018 08:37:49 +1100	[thread overview]
Message-ID: <87k1uie1jm.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <63D7C945-5CBC-4434-BAF1-F3EBA912CDEF@intel.com>

[-- Attachment #1: Type: text/plain, Size: 5910 bytes --]

On Thu, Mar 08 2018, Dilger, Andreas wrote:

> On Mar 1, 2018, at 16:31, NeilBrown <neilb@suse.com> wrote:
>> 
>> lustre has a "Pinger" kthread which periodically pings peers
>> to ensure all hosts are functioning.
>> 
>> This can more easily be done using a work queue.
>> 
>> As maintaining contact with other peers is import for
>> keeping the filesystem running, and as the filesystem might
>> be involved in freeing memory, it is safest to have a
>> separate WQ_MEM_RECLAIM workqueue.
>> 
>> The SVC_EVENT functionality to wake up the thread can be
>> replaced with mod_delayed_work().
>> 
>> Also use round_jiffies_up_relative() rather than setting a
>> minimum of 1 second delay.  The PING_INTERVAL is measured in
>> seconds so this meets the need is allow the workqueue to
>> keep wakeups synchronized.
>> 
>> Signed-off-by: NeilBrown <neilb@suse.com>
>
> Looks reasonable.  Fortunately, pinging the server does not need
> to be very accurate since it is only done occasionally when the
> client is otherwise idle, so it shouldn't matter if the workqueue
> operation is delayed by a few seconds.
>
> Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>

Thanks a lot for the thorough review!
The above implies that we don't need WQ_MEM_RECLAIM.  I didn't dig in to
exactly when and why pings happened so I thought having WQ_MEM_RECLAIM
we safest.  If pings only happen when the client is otherwise idle, the
it isn't needed.  I'll remove it.

Thanks,
NeilBrown


>
>> ---
>> drivers/staging/lustre/lustre/ptlrpc/pinger.c |   81 +++++++------------------
>> 1 file changed, 24 insertions(+), 57 deletions(-)
>> 
>> diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
>> index b5f3cfee8e75..0775b7a048bb 100644
>> --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c
>> +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
>> @@ -217,21 +217,18 @@ static void ptlrpc_pinger_process_import(struct obd_import *imp,
>> 	}
>> }
>> 
>> -static int ptlrpc_pinger_main(void *arg)
>> -{
>> -	struct ptlrpc_thread *thread = arg;
>> -
>> -	/* Record that the thread is running */
>> -	thread_set_flags(thread, SVC_RUNNING);
>> -	wake_up(&thread->t_ctl_waitq);
>> +static struct workqueue_struct *pinger_wq;
>> +static void ptlrpc_pinger_main(struct work_struct *ws);
>> +static DECLARE_DELAYED_WORK(ping_work, ptlrpc_pinger_main);
>> 
>> -	/* And now, loop forever, pinging as needed. */
>> -	while (1) {
>> -		unsigned long this_ping = cfs_time_current();
>> -		long time_to_next_wake;
>> -		struct timeout_item *item;
>> -		struct obd_import *imp;
>> +static void ptlrpc_pinger_main(struct work_struct *ws)
>> +{
>> +	unsigned long this_ping = cfs_time_current();
>> +	long time_to_next_wake;
>> +	struct timeout_item *item;
>> +	struct obd_import *imp;
>> 
>> +	do {
>> 		mutex_lock(&pinger_mutex);
>> 		list_for_each_entry(item, &timeout_list, ti_chain) {
>> 			item->ti_cb(item, item->ti_cb_data);
>> @@ -260,50 +257,24 @@ static int ptlrpc_pinger_main(void *arg)
>> 		       time_to_next_wake,
>> 		       cfs_time_add(this_ping,
>> 				    PING_INTERVAL * HZ));
>> -		if (time_to_next_wake > 0) {
>> -			wait_event_idle_timeout(thread->t_ctl_waitq,
>> -						thread_is_stopping(thread) ||
>> -						thread_is_event(thread),
>> -						max_t(long, time_to_next_wake, HZ));
>> -			if (thread_test_and_clear_flags(thread, SVC_STOPPING))
>> -				break;
>> -			/* woken after adding import to reset timer */
>> -			thread_test_and_clear_flags(thread, SVC_EVENT);
>> -		}
>> -	}
>> +	} while (time_to_next_wake <= 0);
>> 
>> -	thread_set_flags(thread, SVC_STOPPED);
>> -	wake_up(&thread->t_ctl_waitq);
>> -
>> -	CDEBUG(D_NET, "pinger thread exiting, process %d\n", current_pid());
>> -	return 0;
>> +	queue_delayed_work(pinger_wq, &ping_work,
>> +			   round_jiffies_up_relative(time_to_next_wake));
>> }
>> 
>> -static struct ptlrpc_thread pinger_thread;
>> -
>> int ptlrpc_start_pinger(void)
>> {
>> -	struct task_struct *task;
>> -	int rc;
>> -
>> -	if (!thread_is_init(&pinger_thread) &&
>> -	    !thread_is_stopped(&pinger_thread))
>> +	if (pinger_wq)
>> 		return -EALREADY;
>> 
>> -	init_waitqueue_head(&pinger_thread.t_ctl_waitq);
>> -
>> -	strcpy(pinger_thread.t_name, "ll_ping");
>> -
>> -	task = kthread_run(ptlrpc_pinger_main, &pinger_thread,
>> -			   pinger_thread.t_name);
>> -	if (IS_ERR(task)) {
>> -		rc = PTR_ERR(task);
>> -		CERROR("cannot start pinger thread: rc = %d\n", rc);
>> -		return rc;
>> +	pinger_wq = alloc_workqueue("ptlrpc_pinger", WQ_MEM_RECLAIM, 1);
>> +	if (!pinger_wq) {
>> +		CERROR("cannot start pinger workqueue\n");
>> +		return -ENOMEM;
>> 	}
>> -	wait_event_idle(pinger_thread.t_ctl_waitq,
>> -			thread_is_running(&pinger_thread));
>> 
>> +	queue_delayed_work(pinger_wq, &ping_work, 0);
>> 	return 0;
>> }
>> 
>> @@ -313,16 +284,13 @@ int ptlrpc_stop_pinger(void)
>> {
>> 	int rc = 0;
>> 
>> -	if (thread_is_init(&pinger_thread) ||
>> -	    thread_is_stopped(&pinger_thread))
>> +	if (!pinger_wq)
>> 		return -EALREADY;
>> 
>> 	ptlrpc_pinger_remove_timeouts();
>> -	thread_set_flags(&pinger_thread, SVC_STOPPING);
>> -	wake_up(&pinger_thread.t_ctl_waitq);
>> -
>> -	wait_event_idle(pinger_thread.t_ctl_waitq,
>> -			thread_is_stopped(&pinger_thread));
>> +	cancel_delayed_work_sync(&ping_work);
>> +	destroy_workqueue(pinger_wq);
>> +	pinger_wq = NULL;
>> 
>> 	return rc;
>> }
>> @@ -505,6 +473,5 @@ static int ptlrpc_pinger_remove_timeouts(void)
>> 
>> void ptlrpc_pinger_wake_up(void)
>> {
>> -	thread_add_flags(&pinger_thread, SVC_EVENT);
>> -	wake_up(&pinger_thread.t_ctl_waitq);
>> +	mod_delayed_work(pinger_wq, &ping_work, 0);
>> }
>> 
>> 
>
> Cheers, Andreas
> --
> Andreas Dilger
> Lustre Principal Architect
> Intel Corporation

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2018-03-11 21:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01 23:31 [PATCH 00/17] staging: remove requirement that lustre be built as module NeilBrown
2018-03-01 23:31 ` [PATCH 11/17] staging: lustre: ptlrpc: use workqueue for pinger NeilBrown
2018-03-08 23:53   ` Dilger, Andreas
2018-03-11 21:37     ` NeilBrown [this message]
2018-03-01 23:31 ` [PATCH 06/17] staging: lustre: get entropy from nid when nid set NeilBrown
2018-03-08  0:19   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 01/17] staging: lustre: obd_mount: use correct niduuid suffix NeilBrown
2018-03-07 20:49   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 12/17] staging: lustre: remove unused flag from ptlrpc_thread NeilBrown
2018-03-08 23:54   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 13/17] staging: lustre: remove 'ptlrpc_thread usage' for sai_agl_thread NeilBrown
2018-03-09  0:12   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 14/17] staging: lustre: change sai_thread to sai_task NeilBrown
2018-03-09  0:20   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 05/17] staging: lustre: lnet: keep ln_nportals consistent NeilBrown
2018-03-07 21:24   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 08/17] staging: lustre: obdclass: use workqueue for zombie management NeilBrown
2018-03-08  0:27   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 02/17] staging: lustre: fix bug in osc_enter_cache_try NeilBrown
2018-03-07 20:51   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 03/17] staging: lustre: statahead: remove incorrect test on agl_list_empty() NeilBrown
2018-03-07 21:08   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 10/17] staging: lustre: ptlrpc: use delayed_work in sec_gc NeilBrown
2018-03-08 19:23   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 15/17] staging: lustre: ptlrpc: move thread creation out of module initialization NeilBrown
2018-03-09  0:31   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 17/17] Revert "staging: Disable lustre file system for MIPS, SH, and XTENSA" NeilBrown
2018-03-09  0:37   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 07/17] staging: lustre: ptlrpc: change GFP_NOFS to GFP_KERNEL NeilBrown
2018-03-08  0:20   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 16/17] staging: lustre: allow monolithic builds NeilBrown
2018-03-09  0:32   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 09/17] staging: lustre: ldlm: use delayed_work for pools_recalc NeilBrown
2018-03-08 19:22   ` Dilger, Andreas
2018-03-01 23:31 ` [PATCH 04/17] staging: lustre: obdclass: don't require lct_owner to be non-NULL NeilBrown
2018-03-07 21:10   ` Dilger, Andreas

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=87k1uie1jm.fsf@notabene.neil.brown.name \
    --to=neilb@suse.com \
    --cc=andreas.dilger@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jsimmons@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lustre-devel@lists.lustre.org \
    --cc=oleg.drokin@intel.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

all inboxes | Powered by JetHome®