Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753929AbbGXDOY (ORCPT ); Thu, 23 Jul 2015 23:14:24 -0400 Received: from mga01.intel.com ([192.55.52.88]:7325 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752208AbbGXDOW (ORCPT ); Thu, 23 Jul 2015 23:14:22 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,535,1432623600"; d="scan'208";a="611910402" Message-ID: <55B1ACFD.9020200@intel.com> Date: Fri, 24 Jul 2015 11:11:57 +0800 From: Pan Xinhui User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: "linux-kernel@vger.kernel.org" CC: Thomas Gleixner , Borislav Petkov , "mingo@redhat.com" , "hpa@zytor.com" , "x86@kernel.org" , "bp@suse.de" , "Kani, Toshimitsu" , "jgross@suse.com" , "mcgrof@suse.com" , "mnipxh@163.com" , "yanmin_zhang@linux.intel.com" , "Elliott, Robert (Server Storage)" Subject: [PATCH] x86/mm/pat: Do a small optimization when dump PAT memtype list Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3138 Lines: 106 From: Pan Xinhui There are many nodes in the PAT memtype rb-tree. When we dump this tree we call kzalloc every time to copy nodes. Actually these kzalloc are not necessary. Lets do a optimization now. Let seq_file core create an *entry* when open and free it when release. *entry* is stored as seq->private, so we can use it in seq_operations callback who traverse/output the PAT memtype rb-tree only. Lots of unnecessary kzalloc could be avoided now. Signed-off-by: Pan Xinhui --- v1 -> v2: Use seq_open/release_private. let seq_file core handle memory alloc/free. seq_operations callbacks now only traverse/output the PAT rb-tree. --- arch/x86/mm/pat.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index 268b2c8..53920be 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c @@ -1001,41 +1001,33 @@ EXPORT_SYMBOL_GPL(pgprot_writethrough); #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_X86_PAT) -static struct memtype *memtype_get_idx(loff_t pos) +static struct memtype *memtype_get_idx(struct memtype *entry, loff_t pos) { - struct memtype *print_entry; int ret; - print_entry = kzalloc(sizeof(struct memtype), GFP_KERNEL); - if (!print_entry) - return NULL; - spin_lock(&memtype_lock); - ret = rbt_memtype_copy_nth_element(print_entry, pos); + ret = rbt_memtype_copy_nth_element(entry, pos); spin_unlock(&memtype_lock); - if (!ret) { - return print_entry; - } else { - kfree(print_entry); - return NULL; - } + return ret ? NULL : entry; } static void *memtype_seq_start(struct seq_file *seq, loff_t *pos) { + struct memtype *entry = seq->private; + if (*pos == 0) { ++*pos; seq_puts(seq, "PAT memtype list:\n"); } - return memtype_get_idx(*pos); + return memtype_get_idx(entry, *pos); } static void *memtype_seq_next(struct seq_file *seq, void *v, loff_t *pos) { ++*pos; - return memtype_get_idx(*pos); + return memtype_get_idx((struct memtype *)v, *pos); } static void memtype_seq_stop(struct seq_file *seq, void *v) @@ -1048,7 +1040,6 @@ static int memtype_seq_show(struct seq_file *seq, void *v) seq_printf(seq, "%s @ 0x%Lx-0x%Lx\n", cattr_name(print_entry->type), print_entry->start, print_entry->end); - kfree(print_entry); return 0; } @@ -1062,14 +1053,15 @@ static const struct seq_operations memtype_seq_ops = { static int memtype_seq_open(struct inode *inode, struct file *file) { - return seq_open(file, &memtype_seq_ops); + return seq_open_private(file, &memtype_seq_ops, + sizeof(struct memtype)); } static const struct file_operations memtype_fops = { .open = memtype_seq_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release, + .release = seq_release_private, }; static int __init pat_memtype_list_init(void) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/