Received: by 10.223.185.116 with SMTP id b49csp231186wrg; Thu, 8 Mar 2018 16:21:42 -0800 (PST) X-Google-Smtp-Source: AG47ELs4d3K2IrFTsObkXOhuX6CWDopVFoPcaP4ga+pI/scmF3usQDruTpIMvVOEpwxv9YbmW3vS X-Received: by 2002:a17:902:9882:: with SMTP id s2-v6mr26302991plp.196.1520554902177; Thu, 08 Mar 2018 16:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520554902; cv=none; d=google.com; s=arc-20160816; b=GGNI9Vhxqxl+Mj3bs/9DytKHMngTEteiw2iJntEmu0jp9Yo7qtS7hBLG2IJqnb0EmY ggUCUk2+myqVfehTRSayWxd1YqVn9murvk1UqkODZyhQdsaTroZ/Wdf2n9lfJj8SwQYZ v8OImRKjuHk3osV9tzWkmzA4jkzHfEqhCaEWT6dTNH5FAqiC9cbNcsINHRc52JNsZYYj ttMWEF43yQS3rvTGaTSvkpZnhisU1XX2udQB7Ultc3khfUHlKZePHCpHLOxSqTSUrAgf JNRNV9ei5OYrY/dQY3N0ozscSYsWAkowj3oGOOFc0rdtJzrFCOCy4qk85B4YLiCmYS+q VHCQ== 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=K5OoQ2paL6wGyArYJAy1bGbsOpJSSjKlF13P25bL5EY=; b=TxzpwZZQIJe7LimnSCSYA44DMHL5++Bk8FGqg96puCodvd2ApZujPRYr5i+4HVY+ja sNvcVgVHqebENvKau0hMoZiMJ8PmiqfhUEW7VQOrylJtZM2jaOdiHLR/Rc3DXwv4JW73 5cHEvt64zuKYpR+uOfmsRxG59TL5ZcrNGi5Ho2jaYXaRkJ+hm83hKS9ikB5mzsbr5q// 6tqmC9uwD/1d7j2YAe17VMfTFs+ZnRivJNajRqM5PHgR1U26nu36cAkAmskjEMza2aPm zqhHQJd8Q25QjffWusSOYstbB6fOYcgJ+jwsPYjIzlr+L0copuLEDmxpw1USVjERvznB tvZw== 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 y2si13803497pgs.359.2018.03.08.16.21.25; Thu, 08 Mar 2018 16:21:42 -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 S1751083AbeCIAUa convert rfc822-to-8bit (ORCPT + 99 others); Thu, 8 Mar 2018 19:20:30 -0500 Received: from mga06.intel.com ([134.134.136.31]:62103 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800AbeCIAU3 (ORCPT ); Thu, 8 Mar 2018 19:20:29 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Mar 2018 16:20:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,443,1515484800"; d="scan'208";a="40422668" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga002.jf.intel.com with ESMTP; 08 Mar 2018 16:20:29 -0800 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 8 Mar 2018 16:20:29 -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 16:20:28 -0800 From: "Dilger, Andreas" To: NeilBrown CC: "Drokin, Oleg" , Greg Kroah-Hartman , James Simmons , "Linux Kernel Mailing List" , Lustre Development List , "Yong, Fan" Subject: Re: [PATCH 14/17] staging: lustre: change sai_thread to sai_task. Thread-Topic: [PATCH 14/17] staging: lustre: change sai_thread to sai_task. Thread-Index: AQHTsbXQSDgx/3sOlU+zYkVjojObd6PHm4mA Date: Fri, 9 Mar 2018 00:20:27 +0000 Message-ID: References: <151994679573.7628.1024109499321778846.stgit@noble> <151994708553.7628.2646121829758742627.stgit@noble> In-Reply-To: <151994708553.7628.2646121829758742627.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: <4B69DC9A63AFD644B9885120A8F308DE@intel.com> 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: > > Rather than allocating a ptlrpc_thread for the > stat-ahead thread, just use the task_struct provided > by kthreads directly. > > As nothing ever waits for the sai_task, it must call do_exit() > directly rather than simply return from the function. > Also it cannot use kthread_should_stop() to know when to stop. > > There is one caller which can ask it to stop so we need a simple > signaling mechanism. I've chosen to set ->sai_task to NULL > when the thread should finish up. The thread notices this and > cleans up and exits. > lli_sa_lock is used to avoid races between waking up the process > and the process exiting. > > Signed-off-by: NeilBrown CC'd Fan Yong, who is the author for this code. Reviewed-by: Andreas Dilger > --- > .../staging/lustre/lustre/llite/llite_internal.h | 2 > drivers/staging/lustre/lustre/llite/statahead.c | 118 +++++++++----------- > 2 files changed, 54 insertions(+), 66 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h > index 0c2d717fd526..d46bcf71b273 100644 > --- a/drivers/staging/lustre/lustre/llite/llite_internal.h > +++ b/drivers/staging/lustre/lustre/llite/llite_internal.h > @@ -1070,7 +1070,7 @@ struct ll_statahead_info { > sai_agl_valid:1,/* AGL is valid for the dir */ > sai_in_readpage:1;/* statahead in readdir() */ > wait_queue_head_t sai_waitq; /* stat-ahead wait queue */ > - struct ptlrpc_thread sai_thread; /* stat-ahead thread */ > + struct task_struct *sai_task; /* stat-ahead thread */ > struct task_struct *sai_agl_task; /* AGL thread */ > struct list_head sai_interim_entries; /* entries which got async > * stat reply, but not > diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c > index 39241b952bf4..155ce3cf6f60 100644 > --- a/drivers/staging/lustre/lustre/llite/statahead.c > +++ b/drivers/staging/lustre/lustre/llite/statahead.c > @@ -267,7 +267,7 @@ sa_kill(struct ll_statahead_info *sai, struct sa_entry *entry) > > /* called by scanner after use, sa_entry will be killed */ > static void > -sa_put(struct ll_statahead_info *sai, struct sa_entry *entry) > +sa_put(struct ll_statahead_info *sai, struct sa_entry *entry, struct ll_inode_info *lli) > { > struct sa_entry *tmp, *next; > > @@ -295,7 +295,11 @@ sa_put(struct ll_statahead_info *sai, struct sa_entry *entry) > sa_kill(sai, tmp); > } > > - wake_up(&sai->sai_thread.t_ctl_waitq); > + spin_lock(&lli->lli_sa_lock); > + if (sai->sai_task) > + wake_up_process(sai->sai_task); > + spin_unlock(&lli->lli_sa_lock); > + > } > > /* > @@ -403,7 +407,6 @@ static struct ll_statahead_info *ll_sai_alloc(struct dentry *dentry) > sai->sai_max = LL_SA_RPC_MIN; > sai->sai_index = 1; > init_waitqueue_head(&sai->sai_waitq); > - init_waitqueue_head(&sai->sai_thread.t_ctl_waitq); > > INIT_LIST_HEAD(&sai->sai_interim_entries); > INIT_LIST_HEAD(&sai->sai_entries); > @@ -465,7 +468,7 @@ static void ll_sai_put(struct ll_statahead_info *sai) > lli->lli_sai = NULL; > spin_unlock(&lli->lli_sa_lock); > > - LASSERT(thread_is_stopped(&sai->sai_thread)); > + LASSERT(sai->sai_task == NULL); > LASSERT(sai->sai_agl_task == NULL); > LASSERT(sai->sai_sent == sai->sai_replied); > LASSERT(!sa_has_callback(sai)); > @@ -646,7 +649,6 @@ static int ll_statahead_interpret(struct ptlrpc_request *req, > struct ll_inode_info *lli = ll_i2info(dir); > struct ll_statahead_info *sai = lli->lli_sai; > struct sa_entry *entry = (struct sa_entry *)minfo->mi_cbdata; > - wait_queue_head_t *waitq = NULL; > __u64 handle = 0; > > if (it_disposition(it, DISP_LOOKUP_NEG)) > @@ -657,7 +659,6 @@ static int ll_statahead_interpret(struct ptlrpc_request *req, > * sai should be always valid, no need to refcount > */ > LASSERT(sai); > - LASSERT(!thread_is_stopped(&sai->sai_thread)); > LASSERT(entry); > > CDEBUG(D_READA, "sa_entry %.*s rc %d\n", > @@ -681,8 +682,9 @@ static int ll_statahead_interpret(struct ptlrpc_request *req, > spin_lock(&lli->lli_sa_lock); > if (rc) { > if (__sa_make_ready(sai, entry, rc)) > - waitq = &sai->sai_waitq; > + wake_up(&sai->sai_waitq); > } else { > + int first = 0; > entry->se_minfo = minfo; > entry->se_req = ptlrpc_request_addref(req); > /* > @@ -693,14 +695,15 @@ static int ll_statahead_interpret(struct ptlrpc_request *req, > */ > entry->se_handle = handle; > if (!sa_has_callback(sai)) > - waitq = &sai->sai_thread.t_ctl_waitq; > + first = 1; > > list_add_tail(&entry->se_list, &sai->sai_interim_entries); > + > + if (first && sai->sai_task) > + wake_up_process(sai->sai_task); > } > sai->sai_replied++; > > - if (waitq) > - wake_up(waitq); > spin_unlock(&lli->lli_sa_lock); > > return rc; > @@ -942,17 +945,13 @@ static int ll_statahead_thread(void *arg) > struct inode *dir = d_inode(parent); > struct ll_inode_info *lli = ll_i2info(dir); > struct ll_sb_info *sbi = ll_i2sbi(dir); > - struct ll_statahead_info *sai; > - struct ptlrpc_thread *sa_thread; > + struct ll_statahead_info *sai = lli->lli_sai; > struct page *page = NULL; > __u64 pos = 0; > int first = 0; > int rc = 0; > struct md_op_data *op_data; > > - sai = ll_sai_get(dir); > - sa_thread = &sai->sai_thread; > - sa_thread->t_pid = current_pid(); > CDEBUG(D_READA, "statahead thread starting: sai %p, parent %pd\n", > sai, parent); > > @@ -965,21 +964,7 @@ static int ll_statahead_thread(void *arg) > > op_data->op_max_pages = ll_i2sbi(dir)->ll_md_brw_pages; > > - if (sbi->ll_flags & LL_SBI_AGL_ENABLED) > - ll_start_agl(parent, sai); > - > - atomic_inc(&sbi->ll_sa_total); > - spin_lock(&lli->lli_sa_lock); > - if (thread_is_init(sa_thread)) > - /* If someone else has changed the thread state > - * (e.g. already changed to SVC_STOPPING), we can't just > - * blindly overwrite that setting. > - */ > - thread_set_flags(sa_thread, SVC_RUNNING); > - spin_unlock(&lli->lli_sa_lock); > - wake_up(&sa_thread->t_ctl_waitq); > - > - while (pos != MDS_DIR_END_OFF && thread_is_running(sa_thread)) { > + while (pos != MDS_DIR_END_OFF && sai->sai_task) { > struct lu_dirpage *dp; > struct lu_dirent *ent; > > @@ -996,7 +981,7 @@ static int ll_statahead_thread(void *arg) > > dp = page_address(page); > for (ent = lu_dirent_start(dp); > - ent && thread_is_running(sa_thread) && !sa_low_hit(sai); > + ent && sai->sai_task && !sa_low_hit(sai); > ent = lu_dirent_next(ent)) { > struct lu_fid fid; > __u64 hash; > @@ -1046,13 +1031,7 @@ static int ll_statahead_thread(void *arg) > > fid_le_to_cpu(&fid, &ent->lde_fid); > > - /* wait for spare statahead window */ > do { > - wait_event_idle(sa_thread->t_ctl_waitq, > - !sa_sent_full(sai) || > - sa_has_callback(sai) || > - !list_empty(&sai->sai_agls) || > - !thread_is_running(sa_thread)); > sa_handle_callback(sai); > > spin_lock(&lli->lli_agl_lock); > @@ -1072,8 +1051,16 @@ static int ll_statahead_thread(void *arg) > spin_lock(&lli->lli_agl_lock); > } > spin_unlock(&lli->lli_agl_lock); > - } while (sa_sent_full(sai) && > - thread_is_running(sa_thread)); > + > + set_current_state(TASK_IDLE); > + if (sa_sent_full(sai) && > + !sa_has_callback(sai) && > + agl_list_empty(sai) && > + sai->sai_task) > + /* wait for spare statahead window */ > + schedule(); > + __set_current_state(TASK_RUNNING); > + } while (sa_sent_full(sai) && sai->sai_task); > > sa_statahead(parent, name, namelen, &fid); > } > @@ -1096,7 +1083,7 @@ static int ll_statahead_thread(void *arg) > > if (rc < 0) { > spin_lock(&lli->lli_sa_lock); > - thread_set_flags(sa_thread, SVC_STOPPING); > + sai->sai_task = NULL; > lli->lli_sa_enabled = 0; > spin_unlock(&lli->lli_sa_lock); > } > @@ -1105,12 +1092,14 @@ static int ll_statahead_thread(void *arg) > * statahead is finished, but statahead entries need to be cached, wait > * for file release to stop me. > */ > - while (thread_is_running(sa_thread)) { > - wait_event_idle(sa_thread->t_ctl_waitq, > - sa_has_callback(sai) || > - !thread_is_running(sa_thread)); > - > + while (sai->sai_task) { > sa_handle_callback(sai); > + > + set_current_state(TASK_IDLE); > + if (!sa_has_callback(sai) && > + sai->sai_task) > + schedule(); > + __set_current_state(TASK_RUNNING); > } > out: > if (sai->sai_agl_task) { > @@ -1126,26 +1115,23 @@ static int ll_statahead_thread(void *arg) > */ > while (sai->sai_sent != sai->sai_replied) { > /* in case we're not woken up, timeout wait */ > - wait_event_idle_timeout(sa_thread->t_ctl_waitq, > - sai->sai_sent == sai->sai_replied, > - HZ>>3); > + schedule_timeout_idle(HZ>>3); > } > > /* release resources held by statahead RPCs */ > sa_handle_callback(sai); > > - spin_lock(&lli->lli_sa_lock); > - thread_set_flags(sa_thread, SVC_STOPPED); > - spin_unlock(&lli->lli_sa_lock); > - > CDEBUG(D_READA, "statahead thread stopped: sai %p, parent %pd\n", > sai, parent); > > + spin_lock(&lli->lli_sa_lock); > + sai->sai_task = NULL; > + spin_unlock(&lli->lli_sa_lock); > + > wake_up(&sai->sai_waitq); > - wake_up(&sa_thread->t_ctl_waitq); > ll_sai_put(sai); > > - return rc; > + do_exit(rc); > } > > /* authorize opened dir handle @key to statahead */ > @@ -1187,13 +1173,13 @@ void ll_deauthorize_statahead(struct inode *dir, void *key) > lli->lli_opendir_pid = 0; > lli->lli_sa_enabled = 0; > sai = lli->lli_sai; > - if (sai && thread_is_running(&sai->sai_thread)) { > + if (sai && sai->sai_task) { > /* > * statahead thread may not quit yet because it needs to cache > * entries, now it's time to tell it to quit. > */ > - thread_set_flags(&sai->sai_thread, SVC_STOPPING); > - wake_up(&sai->sai_thread.t_ctl_waitq); > + wake_up_process(sai->sai_task); > + sai->sai_task = NULL; > } > spin_unlock(&lli->lli_sa_lock); > } > @@ -1463,7 +1449,7 @@ static int revalidate_statahead_dentry(struct inode *dir, > */ > ldd = ll_d2d(*dentryp); > ldd->lld_sa_generation = lli->lli_sa_generation; > - sa_put(sai, entry); > + sa_put(sai, entry, lli); > return rc; > } > > @@ -1483,7 +1469,6 @@ static int start_statahead_thread(struct inode *dir, struct dentry *dentry) > { > struct ll_inode_info *lli = ll_i2info(dir); > struct ll_statahead_info *sai = NULL; > - struct ptlrpc_thread *thread; > struct task_struct *task; > struct dentry *parent = dentry->d_parent; > int rc; > @@ -1523,18 +1508,21 @@ static int start_statahead_thread(struct inode *dir, struct dentry *dentry) > CDEBUG(D_READA, "start statahead thread: [pid %d] [parent %pd]\n", > current_pid(), parent); > > - task = kthread_run(ll_statahead_thread, parent, "ll_sa_%u", > - lli->lli_opendir_pid); > - thread = &sai->sai_thread; > + task = kthread_create(ll_statahead_thread, parent, "ll_sa_%u", > + lli->lli_opendir_pid); > if (IS_ERR(task)) { > rc = PTR_ERR(task); > CERROR("can't start ll_sa thread, rc : %d\n", rc); > goto out; > } > > - wait_event_idle(thread->t_ctl_waitq, > - thread_is_running(thread) || thread_is_stopped(thread)); > - ll_sai_put(sai); > + if (ll_i2sbi(parent->d_inode)->ll_flags & LL_SBI_AGL_ENABLED) > + ll_start_agl(parent, sai); > + > + atomic_inc(&ll_i2sbi(parent->d_inode)->ll_sa_total); > + sai->sai_task = task; > + > + wake_up_process(task); > > /* > * We don't stat-ahead for the first dirent since we are already in > > Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation