Received: by 10.223.164.202 with SMTP id h10csp3770wrb; Wed, 22 Nov 2017 02:52:38 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ11k1Kll1jgHqPWLV9UcFwDPjAlmirHzh2B04DuinWb4r6ZJ2dC7+nQRn6NAoIOfPQqDlT X-Received: by 10.159.231.23 with SMTP id w23mr21288520plq.436.1511347958163; Wed, 22 Nov 2017 02:52:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511347958; cv=none; d=google.com; s=arc-20160816; b=XCAkc5sDVe/qo5NZTd3i4QqpBwdEfnAkeDTGIzWqM08LZAqsC2H3O+KWoiQSBR9ALV 28arxqNqtwteCBcYDALphyPGRhxMA3ANd/f5z13x+u+tjwQAYBPVPKmr7z6hsLnTsfw7 2lGqIfhVmk9/gjZurog7lTvCgPjymO8clkmxHn1qcQo4YQ2LSL6MdcWwQVVHuBin+lJP xlI5vLi2r8pnUOyq2q6R0tM3NsaIoI0U6Mc489W6YY7lXyk0xXQzHv2gdUjnY1z7mziO XZ5omsJHysiPKH+D6NL3I7kqmq4FACAEmM60RH2XY/Svb2sXKOLM3/gAxF0rkT6xjEyH fn/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=DLgtrBghKXII4df9CBTQcjkWlfXVpvpKumObr1cyHFU=; b=O5lRYZwJtDHssYa8GPVD5htEgtZS7jy2lCE3FzPWAlQgk/YXGSTvfWvKza0I0cRHIp VeDSpN6puRfWw1k81BCaExQCupgSav2bKBobqJfkod3X9KaFzLuhGz1Use72mvbWF+zt 3Jp2TepWXoVQwltSd8FevrbDLF7zw+QOCoD1nJl6SP2p5pOaWsG4rPPvQXY+B8JbxOt6 /OPbvM9nsMfLJbppv3TCyVSTweGtcCBsR3FkQtO6j1u0cANeu2ih1mrbaP+mWXktnQ6q ve5WhgXXipmezGWh8yxwUqXFI8fkcCPpgxtNkAzSUhuAb8kSGk91AlR6DghuO1PUF7P+ 3+Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=VMXWQ0lp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17si13108745pge.556.2017.11.22.02.52.26; Wed, 22 Nov 2017 02:52:38 -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; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=VMXWQ0lp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752105AbdKVKvs (ORCPT + 77 others); Wed, 22 Nov 2017 05:51:48 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:58576 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751863AbdKVKvq (ORCPT ); Wed, 22 Nov 2017 05:51:46 -0500 Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20171122105144epoutp0400b0f56463f1696c46d052b16e68d051~5YulL_mWW0825708257epoutp04o for ; Wed, 22 Nov 2017 10:51:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20171122105144epoutp0400b0f56463f1696c46d052b16e68d051~5YulL_mWW0825708257epoutp04o DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1511347904; bh=DLgtrBghKXII4df9CBTQcjkWlfXVpvpKumObr1cyHFU=; h=From:To:Cc:Subject:Date:References:From; b=VMXWQ0lpafwmfpI7BP/7JCjg9VD61+70Zvrk0c9CVY0h/kdpH3XqzKCG3L41SSYmD 6rnJAR3J7kAhLX3mMSMU1TNBnFghwb0gL9SGfwJi1N2virzwkKQC/vjG5BIlGZZQTy eDmgLfgr7xYAWh4cLxGYDWnfe/nbL0oVaMEqAF2A= Received: from epsmges5p3new.samsung.com (unknown [182.195.40.75]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20171122105143epcas5p3da417aa50d8efe75ac1057e90660c8f1~5YuklQDkJ3269132691epcas5p3s; Wed, 22 Nov 2017 10:51:43 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id D5.33.04545.FB6551A5; Wed, 22 Nov 2017 19:51:43 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20171122105142epcas5p173b7205da12e1fc72e16ec74c49db665~5YukIEWtC2237422374epcas5p13; Wed, 22 Nov 2017 10:51:42 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20171122105142epsmtrp20e30bd7fb1199039b8b0bc7b0a8dece7~5YukGPo-R0556705567epsmtrp2H; Wed, 22 Nov 2017 10:51:42 +0000 (GMT) X-AuditID: b6c32a4b-cdfff700000011c1-ec-5a1556bf68f2 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id D7.9C.04104.EB6551A5; Wed, 22 Nov 2017 19:51:42 +0900 (KST) Received: from localhost.localdomain (unknown [107.108.92.210]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20171122105139epsmtip2283cb6b67fe18efec5d2a5182a6cffe8~5YuhDWDRO0397403974epsmtip29; Wed, 22 Nov 2017 10:51:39 +0000 (GMT) From: Maninder Singh To: kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, jkosina@suse.cz, pombredanne@nexb.com, jpoimboe@redhat.com, akpm@linux-foundation.org, vbabka@suse.cz, mhocko@suse.com, guptap@codeaurora.org, vinmenon@codeaurora.org Cc: a.sahrawat@samsung.com, pankaj.m@samsung.com, lalit.mohan@samsung.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Maninder Singh , Vaneet Narang Subject: [PATCH 1/1] stackdepot: interface to check entries and size of stackdepot. Date: Wed, 22 Nov 2017 16:17:41 +0530 Message-Id: <1511347661-38083-1-git-send-email-maninder1.s@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHJsWRmVeSWpSXmKPExsWy7bCmuu7+MNEog7YX4hYXd6dazFm/hs2i efF6NotvD1ewWeyes5jF4sDPE4wWPXOaGC36F5tZXN41h83i3pr/rBaH57exWNzvc7C492Yr k8X/3+dYLQ6dnMtoMbuxj9Fi/dYD7A6CHpf7epk8Nn2axO5xYsZvFo/9c9eweyzfaeLxft9V No++LasYPdZvucricWbBEXaPz5vkAriiUm0yUhNTUosUUvOS81My89JtlbyD453jTc0MDHUN LS3MlRTyEnNTbZVcfAJ03TJzgL5RUihLzCkFCgUkFhcr6dvZFOWXlqQqZOQXl9gqRRsaGukZ GpjrGRkZ6ZmYxloZmQKVJKRmvDj8mLVgk1PF2gOzmBsY15p1MXJySAiYSJx8+Jepi5GLQ0hg N6PEx9lH2SGcT4wSk+88YoVwvjFKrNj4lA2m5fPJ71BVexkl9rz9D9X/hVHi+PNvjCBVbAJ6 Eqt27WEBsUUEXjFKtJwxArGZBc4zSvQ3gNnCAqESN99+ZgKxWQRUJS6++cgOYvMKuEvc7WyC 2iYncfLYZLAzJATes0ksOTeBFSLhIrFg40oW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E/GHGAU4GJV4eGckiUQJsSaWFVfmHmKU4GBWEuHdqyAaJcSbklhZlVqUH19UmpNafIhR moNFSZxXPv9YpJBAemJJanZqakFqEUyWiYNTqoGx+26iSGf/9L55+e0crnXHWOrPBGsJnHv3 vvLXsjXf5mSyHVNhFrG02i5pzNP4szx532nPyJ8CHxbfXGSQ8KbP3/fmxVX3utXunCibsJUx YqnRjQkfJC55Hgvd+TvtUpqu+W/jY2/r8nv4bCOvVcuYWe9L++SVET7xn9HCg7djMm8e26Mf ev62EktxRqKhFnNRcSIAimu/cWcCAAA= X-CMS-MailID: 20171122105142epcas5p173b7205da12e1fc72e16ec74c49db665 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-MTR: 20171122105142epcas5p173b7205da12e1fc72e16ec74c49db665 CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20171122105142epcas5p173b7205da12e1fc72e16ec74c49db665 X-RootMTR: 20171122105142epcas5p173b7205da12e1fc72e16ec74c49db665 References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch provides interface to check all the stack enteries saved in stackdepot so far as well as memory consumed by stackdepot. 1) Take current depot_index and offset to calculate end address for one iteration of (/sys/kernel/debug/depot_stack/depot_entries). 2) Fill end marker in every slab to point its end, and then use it while traversing all the slabs of stackdepot. "debugfs code inspired from page_onwer's way of printing BT" checked on ARM and x86_64. $cat /sys/kernel/debug/depot_stack/depot_size Memory consumed by Stackdepot:208 KB $ cat /sys/kernel/debug/depot_stack/depot_entries stack count 1 backtrace init_page_owner+0x1e/0x210 start_kernel+0x310/0x3cd secondary_startup_64+0xa5/0xb0 0xffffffffffffffff Signed-off-by: Vaneet Narang Signed-off-by: Maninder Singh --- include/linux/stackdepot.h | 13 +++ include/linux/stacktrace.h | 6 ++ lib/stackdepot.c | 183 ++++++++++++++++++++++++++++++++++++++++++++ mm/page_owner.c | 6 -- 4 files changed, 202 insertions(+), 6 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 7978b3e..dd95b11 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -23,6 +23,19 @@ typedef u32 depot_stack_handle_t; +/* + * structure to store markers which + * will be used while printing entries + * stored in stackdepot. + */ +struct depot_stack_data { + int print_offset; + int print_counter; + int print_index; + unsigned long end_marker; + void *end_address; +}; + struct stack_trace; depot_stack_handle_t depot_save_stack(struct stack_trace *trace, gfp_t flags); diff --git a/include/linux/stacktrace.h b/include/linux/stacktrace.h index ba29a06..1cfd27d 100644 --- a/include/linux/stacktrace.h +++ b/include/linux/stacktrace.h @@ -4,6 +4,12 @@ #include +/* + * TODO: teach PAGE_OWNER_STACK_DEPTH (__dump_page_owner and save_stack) + * to use off stack temporal storage + */ +#define PAGE_OWNER_STACK_DEPTH (16) + struct task_struct; struct pt_regs; diff --git a/lib/stackdepot.c b/lib/stackdepot.c index f87d138..3067fcb 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include #define DEPOT_STACK_BITS (sizeof(depot_stack_handle_t) * 8) @@ -111,6 +113,7 @@ static bool init_stack_slab(void **prealloc) int required_size = offsetof(struct stack_record, entries) + sizeof(unsigned long) * size; struct stack_record *stack; + void *address; required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN); @@ -119,6 +122,17 @@ static bool init_stack_slab(void **prealloc) WARN_ONCE(1, "Stack depot reached limit capacity"); return NULL; } + + /* + * write POSION_END if any space left in + * current slab to represent its end. + * later used while printing all the stacks. + */ + if (depot_offset < STACK_ALLOC_SIZE) { + address = stack_slabs[depot_index] + depot_offset; + memset(address, POISON_END, sizeof(unsigned long)); + } + depot_index++; depot_offset = 0; /* @@ -285,3 +299,172 @@ depot_stack_handle_t depot_save_stack(struct stack_trace *trace, return retval; } EXPORT_SYMBOL_GPL(depot_save_stack); + +#define DEPOT_SIZE 64 + +static ssize_t read_depot_stack_size(struct file *file, char __user *buf, size_t count, loff_t *ppos) +{ + char kbuf[DEPOT_SIZE]; + ssize_t ret = 0; + unsigned long size = depot_index * (1 << STACK_ALLOC_ORDER) * PAGE_SIZE; + + ret = snprintf(kbuf, count, "Memory consumed by Stackdepot:%lu KB\n", size >> 10); + if (ret >= count) + return -ENOMEM; + + return simple_read_from_buffer(buf, count, ppos, kbuf, ret); +} + +static ssize_t print_depot_stack(char __user *buf, size_t count, struct stack_trace *trace, loff_t *ppos) +{ + char *kbuf; + int ret = 0; + + kbuf = kvmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + ret = snprintf(kbuf, count, "stack count %d backtrace\n", (int)*ppos); + ret += snprint_stack_trace(kbuf + ret, count - ret, trace, 0); + ret += snprintf(kbuf + ret, count - ret, "\n"); + + if (ret >= count) { + ret = -ENOMEM; + goto err; + } + + if (copy_to_user(buf, kbuf, ret)) + ret = -EFAULT; + +err: + kvfree(kbuf); + return ret; +} + +/* + * read_depot_stack() + * + * function to print all the entries present + * in depot_stack database currently in system. + */ +static ssize_t read_depot_stack(struct file *file, char __user *buf, size_t count, loff_t *ppos) +{ + struct stack_record *stack; + void *address; + struct depot_stack_data *debugfs_data; + + debugfs_data = (struct depot_stack_data *)file->private_data; + + if (!debugfs_data) + return -EINVAL; + + while (debugfs_data->print_counter <= debugfs_data->print_index) { + unsigned long entries[PAGE_OWNER_STACK_DEPTH]; + struct stack_trace trace = { + .nr_entries = 0, + .entries = entries, + .max_entries = PAGE_OWNER_STACK_DEPTH, + .skip = 0 + }; + + address = stack_slabs[debugfs_data->print_counter] + debugfs_data->print_offset; + if (address == debugfs_data->end_address) + break; + + if (*((unsigned long *)address) == debugfs_data->end_marker) { + debugfs_data->print_counter++; + debugfs_data->print_offset = 0; + continue; + } + + stack = address; + trace.nr_entries = trace.max_entries = stack->size; + trace.entries = stack->entries; + + debugfs_data->print_offset += offsetof(struct stack_record, entries) + + (stack->size * sizeof(unsigned long)); + debugfs_data->print_offset = ALIGN(debugfs_data->print_offset, 1 << STACK_ALLOC_ALIGN); + if (debugfs_data->print_offset >= STACK_ALLOC_SIZE) { + debugfs_data->print_counter++; + debugfs_data->print_offset = 0; + } + + *ppos = *ppos + 1; /* one stack found, print it */ + return print_depot_stack(buf, count, &trace, ppos); + } + + return 0; +} + +int read_depot_open(struct inode *inode, struct file *file) +{ + struct depot_stack_data *debugfs_data; + unsigned long flags; + + debugfs_data = kzalloc(sizeof(struct depot_stack_data), GFP_KERNEL); + if (!debugfs_data) + return -ENOMEM; + /* + * First time depot_stack/depot_entries is called. + * (/sys/kernel/debug/depot_stack/depot_entries) + * initialise print depot_index and stopping address. + */ + memset(&(debugfs_data->end_marker), POISON_END, sizeof(unsigned long)); + + spin_lock_irqsave(&depot_lock, flags); + debugfs_data->print_index = depot_index; + debugfs_data->end_address = stack_slabs[depot_index] + depot_offset; + spin_unlock_irqrestore(&depot_lock, flags); + + file->private_data = debugfs_data; + return 0; +} + +int read_depot_release(struct inode *inode, struct file *file) +{ + void *debugfs_data = file->private_data; + + kfree(debugfs_data); + return 0; +} + +static const struct file_operations proc_depot_stack_operations = { + .open = read_depot_open, + .read = read_depot_stack, + .release = read_depot_release, +}; + +static const struct file_operations proc_depot_stack_size_operations = { + .read = read_depot_stack_size, +}; + +static int __init depot_stack_init(void) +{ + struct dentry *dentry, *dentry_root; + + dentry_root = debugfs_create_dir("depot_stack", NULL); + + if (!dentry_root) { + pr_warn("debugfs 'depot_stack' dir creation failed\n"); + return -ENOMEM; + } + + dentry = debugfs_create_file("depot_entries", 0400, dentry_root, + NULL, &proc_depot_stack_operations); + + if (IS_ERR(dentry)) + goto err; + + dentry = debugfs_create_file("depot_size", 0400, dentry_root, + NULL, &proc_depot_stack_size_operations); + + if (IS_ERR(dentry)) + goto err; + + return 0; + +err: + debugfs_remove_recursive(dentry_root); + return PTR_ERR(dentry); +} +late_initcall(depot_stack_init) diff --git a/mm/page_owner.c b/mm/page_owner.c index 4f44b95..341b326 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -13,12 +13,6 @@ #include "internal.h" -/* - * TODO: teach PAGE_OWNER_STACK_DEPTH (__dump_page_owner and save_stack) - * to use off stack temporal storage - */ -#define PAGE_OWNER_STACK_DEPTH (16) - struct page_owner { unsigned int order; gfp_t gfp_mask; -- 1.7.1 From 1585250508301500658@xxx Mon Nov 27 19:58:14 +0000 2017 X-GM-THRID: 1585250508301500658 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread