Received: by 10.192.165.156 with SMTP id m28csp1226992imm; Wed, 11 Apr 2018 15:02:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx48XGwKi3b59uSraR64pontpfcdwuRyEdgoaJe4LdWoTpADxJ9JQJJiEFVvQ2BvYbEkHC6VN X-Received: by 10.98.238.3 with SMTP id e3mr5410150pfi.88.1523484121509; Wed, 11 Apr 2018 15:02:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523484121; cv=none; d=google.com; s=arc-20160816; b=rW3LfcfzPlRL8nH+L2h+SH0dtsQvZpoRJXRnqJPFTsQ29cDlknqBQR7VMwEmIgdxE5 SHTMcK9PI4KD13hm8LK2jJkJfXbTGXREpr2JWLMcElsU5FJlLKp9PT1KdwM8p0tf+D4w qdr8kC35SFqcckZ5ihs52AimDMuUBRtdjoiuYhZFawMy7OmbycuZb5o39raPOAX3wSVb cHOz8JnkGnmWrHjyrUfUO1J45NNW8YLu5jpqmkDgDae+GMMm/EaMp8FNa5VTRmeouJC+ NCMvdaCdlryVjT2Va7Hz1AJXFN6mL/Leu3Kq6u33JWmNRxoVvY5amPenVdiL/LQg/Aoy /2sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from:arc-authentication-results; bh=GKcHrTMCvSBH0D0+F0WdD7Nvk5Y0eRhUA0+B6v0EzuY=; b=NLwlmqeuF/3srmS9mVhzxGqDqeimmC8MaytxpfHs3EUSFtmWOmhWQKRNaIx8ZSk0Iw P/TGZey6IX7JcR/syVnAzOl0c86hmw/YakGdmSo6E6qAg0OUMhNejUDau2jjRHQptZ7J hLUIg45U3o1eTNBB14g6bo7kK01NVEqBirb24hSQ9aCEvAGroqmTgcuTRCIsu/VFmcRB k+tk8sEFheVlHt/V4YhYhY9v1nVjz03G6OP58bXXMz8Bs7giseouiDEgSb9wahZCB4C9 bHDmfV89qKYG+Gi4x+x8M00TuR2lfb214d0RlNnqf26BRRuvROkCiquSxezupECkxacC rq4w== 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 bb5-v6si1852154plb.709.2018.04.11.15.01.24; Wed, 11 Apr 2018 15:02:01 -0700 (PDT) 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 S1754265AbeDKV5L (ORCPT + 99 others); Wed, 11 Apr 2018 17:57:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:46008 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754242AbeDKV5K (ORCPT ); Wed, 11 Apr 2018 17:57:10 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B455FAFB1; Wed, 11 Apr 2018 21:57:08 +0000 (UTC) From: NeilBrown To: Oleg Drokin , Greg Kroah-Hartman , James Simmons , Andreas Dilger Date: Thu, 12 Apr 2018 07:54:49 +1000 Subject: [PATCH 15/20] staging: lustre: llite: use more private data in dump_pgcache Cc: Linux Kernel Mailing List , Lustre Development List Message-ID: <152348368905.12394.1871073958371633773.stgit@noble> In-Reply-To: <152348312863.12394.11915752362061083241.stgit@noble> References: <152348312863.12394.11915752362061083241.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The dump_page_cache debugfs file allocates and frees an 'env' in each call to vvp_pgcache_start,next,show. This is likely to be fast, but does introduce the need to check for errors. It is reasonable to allocate a single 'env' when the file is opened, and use that throughout. So create 'seq_private' structure which stores the sbi, env, and refcheck, and attach this to the seqfile. Then use it throughout instead of allocating 'env' repeatedly. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/llite/vvp_dev.c | 150 ++++++++++++------------- 1 file changed, 72 insertions(+), 78 deletions(-) diff --git a/drivers/staging/lustre/lustre/llite/vvp_dev.c b/drivers/staging/lustre/lustre/llite/vvp_dev.c index 987c03b058e6..a2619dc04a7f 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_dev.c +++ b/drivers/staging/lustre/lustre/llite/vvp_dev.c @@ -390,6 +390,12 @@ struct vvp_pgcache_id { struct lu_object_header *vpi_obj; }; +struct seq_private { + struct ll_sb_info *sbi; + struct lu_env *env; + u16 refcheck; +}; + static void vvp_pgcache_id_unpack(loff_t pos, struct vvp_pgcache_id *id) { BUILD_BUG_ON(sizeof(pos) != sizeof(__u64)); @@ -531,95 +537,71 @@ static void vvp_pgcache_page_show(const struct lu_env *env, static int vvp_pgcache_show(struct seq_file *f, void *v) { + struct seq_private *priv = f->private; loff_t pos; - struct ll_sb_info *sbi; struct cl_object *clob; - struct lu_env *env; struct vvp_pgcache_id id; - u16 refcheck; - int result; - env = cl_env_get(&refcheck); - if (!IS_ERR(env)) { - pos = *(loff_t *)v; - vvp_pgcache_id_unpack(pos, &id); - sbi = f->private; - clob = vvp_pgcache_obj(env, &sbi->ll_cl->cd_lu_dev, &id); - if (clob) { - struct inode *inode = vvp_object_inode(clob); - struct cl_page *page = NULL; - struct page *vmpage; - - result = find_get_pages_contig(inode->i_mapping, - id.vpi_index, 1, - &vmpage); - if (result > 0) { - lock_page(vmpage); - page = cl_vmpage_page(vmpage, clob); - unlock_page(vmpage); - put_page(vmpage); - } + pos = *(loff_t *)v; + vvp_pgcache_id_unpack(pos, &id); + clob = vvp_pgcache_obj(priv->env, &priv->sbi->ll_cl->cd_lu_dev, &id); + if (clob) { + struct inode *inode = vvp_object_inode(clob); + struct cl_page *page = NULL; + struct page *vmpage; + int result; + + result = find_get_pages_contig(inode->i_mapping, + id.vpi_index, 1, + &vmpage); + if (result > 0) { + lock_page(vmpage); + page = cl_vmpage_page(vmpage, clob); + unlock_page(vmpage); + put_page(vmpage); + } - seq_printf(f, "%8x@" DFID ": ", id.vpi_index, - PFID(lu_object_fid(&clob->co_lu))); - if (page) { - vvp_pgcache_page_show(env, f, page); - cl_page_put(env, page); - } else { - seq_puts(f, "missing\n"); - } - lu_object_ref_del(&clob->co_lu, "dump", current); - cl_object_put(env, clob); + seq_printf(f, "%8x@" DFID ": ", id.vpi_index, + PFID(lu_object_fid(&clob->co_lu))); + if (page) { + vvp_pgcache_page_show(priv->env, f, page); + cl_page_put(priv->env, page); } else { - seq_printf(f, "%llx missing\n", pos); + seq_puts(f, "missing\n"); } - cl_env_put(env, &refcheck); - result = 0; + lu_object_ref_del(&clob->co_lu, "dump", current); + cl_object_put(priv->env, clob); } else { - result = PTR_ERR(env); + seq_printf(f, "%llx missing\n", pos); } - return result; + return 0; } static void *vvp_pgcache_start(struct seq_file *f, loff_t *pos) { - struct ll_sb_info *sbi; - struct lu_env *env; - u16 refcheck; - - sbi = f->private; + struct seq_private *priv = f->private; - env = cl_env_get(&refcheck); - if (!IS_ERR(env)) { - sbi = f->private; - if (sbi->ll_site->ls_obj_hash->hs_cur_bits > - 64 - PGC_OBJ_SHIFT) { - pos = ERR_PTR(-EFBIG); - } else { - *pos = vvp_pgcache_find(env, &sbi->ll_cl->cd_lu_dev, - *pos); - if (*pos == ~0ULL) - pos = NULL; - } - cl_env_put(env, &refcheck); + if (priv->sbi->ll_site->ls_obj_hash->hs_cur_bits > + 64 - PGC_OBJ_SHIFT) { + pos = ERR_PTR(-EFBIG); + } else { + *pos = vvp_pgcache_find(priv->env, &priv->sbi->ll_cl->cd_lu_dev, + *pos); + if (*pos == ~0ULL) + pos = NULL; } + return pos; } static void *vvp_pgcache_next(struct seq_file *f, void *v, loff_t *pos) { - struct ll_sb_info *sbi; - struct lu_env *env; - u16 refcheck; + struct seq_private *priv = f->private; + + *pos = vvp_pgcache_find(priv->env, &priv->sbi->ll_cl->cd_lu_dev, *pos + 1); + if (*pos == ~0ULL) + pos = NULL; - env = cl_env_get(&refcheck); - if (!IS_ERR(env)) { - sbi = f->private; - *pos = vvp_pgcache_find(env, &sbi->ll_cl->cd_lu_dev, *pos + 1); - if (*pos == ~0ULL) - pos = NULL; - cl_env_put(env, &refcheck); - } return pos; } @@ -637,17 +619,29 @@ static const struct seq_operations vvp_pgcache_ops = { static int vvp_dump_pgcache_seq_open(struct inode *inode, struct file *filp) { - struct seq_file *seq; - int rc; - - rc = seq_open(filp, &vvp_pgcache_ops); - if (rc) - return rc; + struct seq_private *priv; + + priv = __seq_open_private(filp, &vvp_pgcache_ops, sizeof(*priv)); + if (!priv) + return -ENOMEM; + + priv->sbi = inode->i_private; + priv->env = cl_env_get(&priv->refcheck); + if (IS_ERR(priv->env)) { + int err = PTR_ERR(priv->env); + seq_release_private(inode, filp); + return err; + } + return 0; +} - seq = filp->private_data; - seq->private = inode->i_private; +static int vvp_dump_pgcache_seq_release(struct inode *inode, struct file *file) +{ + struct seq_file *seq = file->private_data; + struct seq_private *priv = seq->private; - return 0; + cl_env_put(priv->env, &priv->refcheck); + return seq_release_private(inode, file); } const struct file_operations vvp_dump_pgcache_file_ops = { @@ -655,5 +649,5 @@ const struct file_operations vvp_dump_pgcache_file_ops = { .open = vvp_dump_pgcache_seq_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release, + .release = vvp_dump_pgcache_seq_release, };