Received: by 10.223.185.116 with SMTP id b49csp6683070wrg; Thu, 8 Mar 2018 11:24:15 -0800 (PST) X-Google-Smtp-Source: AG47ELvzokOhCBC0gWW6AQZevuxgc8Nzq52k2JHu/fK4jtcm5PpROB+VEQZcj+0u6vARJ6Tnm2wm X-Received: by 10.99.120.5 with SMTP id t5mr21708253pgc.156.1520537055577; Thu, 08 Mar 2018 11:24:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520537055; cv=none; d=google.com; s=arc-20160816; b=o18lvhYRBqpfF83r3zFDnDHHc9RlH90NfWLTayVrWAjiHT+WJ1aYCkbz4PYgVw03BD kamSdjCa4/8qUkGevIPAVYwEHWonMKnbgqR0AmCs58KFcOK6IErOXogTytjoByE+BCot mLPNPmEzcXr8j+MvDqnfrm2+KV9UhWbhHMdGytOhmkDAAOkICGszW4C00e/kUet0owZM c+5hI7zY705nptWVXBrwCqItWsjUJhUzXZcCI2PjPYYCqwIi0Ro1wFWuys8TVJ5vqklB OEL4CsprFX/vnRWsve3//4H5AudM2xTNQsv4TjooKH7xeNa+SFH+ABWqubGOejixn83w lXtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :arc-authentication-results; bh=AJizJigJ+ezbJ4t9hcEHB1c0mynI6qsv5skrVl1PWQo=; b=iceoVyF+nAR12+Tkz7NB7A0AvPuKfxgrSkb4x9bS8k90U2FyuYKnleneR6lwUdibhj uK+Tcr/ibCqbzqwENvfCnAypqXXg58vyJz5xmWA1qmkei21aJkyix3lUDhMU/6w18SKa o100SwLRAuU+EE2SJ4UoF4nSP35lcaHtivMtpTWr0Wsf9xS9M7myUxdJPXoECBgoFIbg WnoRPHq1fJQ1XPxHWaEYoWoAiEgwEzwUr6h6N2OskuZcSkV/mwmE5XQQzfKAaQRoQeep iX+9QtiFK8SjDKYr1SG12hblPDIRSu0D0pMoOP8P4GYNCbOjBQKAVVTg7PINPUhErFOy bRiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a18si13379242pgn.669.2018.03.08.11.24.00; Thu, 08 Mar 2018 11:24:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755301AbeCHTWM convert rfc822-to-8bit (ORCPT + 99 others); Thu, 8 Mar 2018 14:22:12 -0500 Received: from mga09.intel.com ([134.134.136.24]:49783 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752255AbeCHTWK (ORCPT ); Thu, 8 Mar 2018 14:22:10 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Mar 2018 11:22:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,441,1515484800"; d="scan'208";a="23101644" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga007.jf.intel.com with ESMTP; 08 Mar 2018 11:22:09 -0800 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 8 Mar 2018 11:22:09 -0800 Received: from FMSMSX109.amr.corp.intel.com ([169.254.15.144]) by FMSMSX153.amr.corp.intel.com ([169.254.9.82]) with mapi id 14.03.0319.002; Thu, 8 Mar 2018 11:22:09 -0800 From: "Dilger, Andreas" To: NeilBrown CC: "Drokin, Oleg" , Greg Kroah-Hartman , James Simmons , "Linux Kernel Mailing List" , Lustre Development List Subject: Re: [PATCH 09/17] staging: lustre: ldlm: use delayed_work for pools_recalc Thread-Topic: [PATCH 09/17] staging: lustre: ldlm: use delayed_work for pools_recalc Thread-Index: AQHTsbWwcg1PBh1G4kSkB4kmtYsxU6PHSDIA Date: Thu, 8 Mar 2018 19:22:08 +0000 Message-ID: <45DCA0E5-F003-416C-9CA8-3C9CC7B06CDE@intel.com> References: <151994679573.7628.1024109499321778846.stgit@noble> <151994708534.7628.3824921218925924808.stgit@noble> In-Reply-To: <151994708534.7628.3824921218925924808.stgit@noble> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.254.37.249] Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mar 1, 2018, at 16:31, NeilBrown wrote: > > ldlm currenty has a kthread which wakes up every so often > and calls ldlm_pools_recalc(). > The thread is started and stopped, but no other external interactions > happen. > > This can trivially be replaced by a delayed_work if we have > ldlm_pools_recalc() reschedule the work rather than just report > when to do that. > > Signed-off-by: NeilBrown Reviewed-by: Andreas Dilger > --- > drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 99 +++--------------------- > 1 file changed, 11 insertions(+), 88 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > index a0e486b57e08..53b8f33e54b5 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > @@ -784,9 +784,6 @@ static int ldlm_pool_granted(struct ldlm_pool *pl) > return atomic_read(&pl->pl_granted); > } > > -static struct ptlrpc_thread *ldlm_pools_thread; > -static struct completion ldlm_pools_comp; > - > /* > * count locks from all namespaces (if possible). Returns number of > * cached locks. > @@ -899,8 +896,12 @@ static unsigned long ldlm_pools_cli_scan(struct shrinker *s, > sc->gfp_mask); > } > > -static int ldlm_pools_recalc(enum ldlm_side client) > +static void ldlm_pools_recalc(struct work_struct *ws); > +static DECLARE_DELAYED_WORK(ldlm_recalc_pools, ldlm_pools_recalc); > + > +static void ldlm_pools_recalc(struct work_struct *ws) > { > + enum ldlm_side client = LDLM_NAMESPACE_CLIENT; > struct ldlm_namespace *ns; > struct ldlm_namespace *ns_old = NULL; > /* seconds of sleep if no active namespaces */ > @@ -982,92 +983,19 @@ static int ldlm_pools_recalc(enum ldlm_side client) > /* Wake up the blocking threads from time to time. */ > ldlm_bl_thread_wakeup(); > > - return time; > -} > - > -static int ldlm_pools_thread_main(void *arg) > -{ > - struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg; > - int c_time; > - > - thread_set_flags(thread, SVC_RUNNING); > - wake_up(&thread->t_ctl_waitq); > - > - CDEBUG(D_DLMTRACE, "%s: pool thread starting, process %d\n", > - "ldlm_poold", current_pid()); > - > - while (1) { > - /* > - * Recal all pools on this tick. > - */ > - c_time = ldlm_pools_recalc(LDLM_NAMESPACE_CLIENT); > - > - /* > - * Wait until the next check time, or until we're > - * stopped. > - */ > - wait_event_idle_timeout(thread->t_ctl_waitq, > - thread_is_stopping(thread) || > - thread_is_event(thread), > - c_time * HZ); > - > - if (thread_test_and_clear_flags(thread, SVC_STOPPING)) > - break; > - thread_test_and_clear_flags(thread, SVC_EVENT); > - } > - > - thread_set_flags(thread, SVC_STOPPED); > - wake_up(&thread->t_ctl_waitq); > - > - CDEBUG(D_DLMTRACE, "%s: pool thread exiting, process %d\n", > - "ldlm_poold", current_pid()); > - > - complete_and_exit(&ldlm_pools_comp, 0); > + schedule_delayed_work(&ldlm_recalc_pools, time * HZ); > } > > static int ldlm_pools_thread_start(void) > { > - struct task_struct *task; > - > - if (ldlm_pools_thread) > - return -EALREADY; > - > - ldlm_pools_thread = kzalloc(sizeof(*ldlm_pools_thread), GFP_NOFS); > - if (!ldlm_pools_thread) > - return -ENOMEM; > - > - init_completion(&ldlm_pools_comp); > - init_waitqueue_head(&ldlm_pools_thread->t_ctl_waitq); > + schedule_delayed_work(&ldlm_recalc_pools, 0); > > - task = kthread_run(ldlm_pools_thread_main, ldlm_pools_thread, > - "ldlm_poold"); > - if (IS_ERR(task)) { > - CERROR("Can't start pool thread, error %ld\n", PTR_ERR(task)); > - kfree(ldlm_pools_thread); > - ldlm_pools_thread = NULL; > - return PTR_ERR(task); > - } > - wait_event_idle(ldlm_pools_thread->t_ctl_waitq, > - thread_is_running(ldlm_pools_thread)); > return 0; > } > > static void ldlm_pools_thread_stop(void) > { > - if (!ldlm_pools_thread) > - return; > - > - thread_set_flags(ldlm_pools_thread, SVC_STOPPING); > - wake_up(&ldlm_pools_thread->t_ctl_waitq); > - > - /* > - * Make sure that pools thread is finished before freeing @thread. > - * This fixes possible race and oops due to accessing freed memory > - * in pools thread. > - */ > - wait_for_completion(&ldlm_pools_comp); > - kfree(ldlm_pools_thread); > - ldlm_pools_thread = NULL; > + cancel_delayed_work_sync(&ldlm_recalc_pools); > } > > static struct shrinker ldlm_pools_cli_shrinker = { > @@ -1081,20 +1009,15 @@ int ldlm_pools_init(void) > int rc; > > rc = ldlm_pools_thread_start(); > - if (rc) > - return rc; > - > - rc = register_shrinker(&ldlm_pools_cli_shrinker); > - if (rc) > - ldlm_pools_thread_stop(); > + if (!rc) > + rc = register_shrinker(&ldlm_pools_cli_shrinker); > > return rc; > } > > void ldlm_pools_fini(void) > { > - if (ldlm_pools_thread) > - unregister_shrinker(&ldlm_pools_cli_shrinker); > + unregister_shrinker(&ldlm_pools_cli_shrinker); > > ldlm_pools_thread_stop(); > } > > Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation