Received: by 10.223.164.202 with SMTP id h10csp1193561wrb; Tue, 7 Nov 2017 23:51:44 -0800 (PST) X-Google-Smtp-Source: ABhQp+RsSQPy2mZVn8gHw3OBTVU1+1XqMXxE3akqjEFYqsWC7jEbmmg6KgmZ13N1CprgUAjZfHNL X-Received: by 10.84.163.75 with SMTP id n11mr1416281plg.287.1510127504611; Tue, 07 Nov 2017 23:51:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510127504; cv=none; d=google.com; s=arc-20160816; b=OxXrO2mfo2XM4UnTulTPEFVDBv195ySjPOd6iMTuNhi2W0uO6o4EdrcsmjNi6iIlzg VvTuzegGfK2ounXbkLns5rgu8gLErO2SwfW2FeArMJKXJ8JW97FM0JgGXKccrrrA4DS5 KkcPiBpZqE4DlLt0hcq/8e94HTn/1YSuBfM8Dmd8H2uYYw62dH7xZK5ygZX+fL2HwUI0 RaMM3bmdnyG+Q6/oftglJQid3oCu17gKW0C1eusl65b3uhQAJuCIIgqr/nsz5Ke3oq2r 3BBt8Wm3w+kMJ0OsuEFKKQWJ9NH9hFYrqYEQ2Qp4W/Q2M6v8dWHXpJ9G4fQL5dFK2+yj tFmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=XHQUe4+VeErfmsgIR0U23cV1BFOY8fFBewj/6ibaNFc=; b=Icqhm8U3nfaoXHfBlCgY0knul4o5uhSW/zk3sLEZyW/Ko8DcEq9ZQ4QhiXYPlgkuwo 3hhI+hp3dNm2YyTuALCMhFwEcaU8VrcQntIb6jFRiF86Lh+Qt+s+Sa2CvdIg4dOi1axh IK0hCQdKd5nY6Bx2jjhHnoN9eSzZYinJelDb6B9Lp+j5TIuaMITloJgA6V01ObR26jE9 co7KfkAyVbTL5/5w7ytdyemcJ2pKsff8Cba7CoKEC2l5LSFs5YIjRGu41J78+WSmcNBq 4YqIr7/HxDoGcnLRQUbVkl873Me9b/TMH/wI3Q4A9wpv9K5Lpdgw2meuExm60sRsrp9T HS4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=grJGuAA3; dkim=pass header.i=@codeaurora.org header.s=default header.b=SM1Jo4ML; 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 d10si2775830plo.388.2017.11.07.23.51.31; Tue, 07 Nov 2017 23:51:44 -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=@codeaurora.org header.s=default header.b=grJGuAA3; dkim=pass header.i=@codeaurora.org header.s=default header.b=SM1Jo4ML; 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 S1755304AbdKHG25 (ORCPT + 91 others); Wed, 8 Nov 2017 01:28:57 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:34020 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751926AbdKHG2y (ORCPT ); Wed, 8 Nov 2017 01:28:54 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id BA96D607EA; Wed, 8 Nov 2017 06:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510122532; bh=07TC+NaTnMFKMS5mWMPUXqdbSOLmCBZLmzT6604bydY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=grJGuAA3iFhKYHfNRWnKgHaqpInjMCSlXbbQ/Ud2VjfxCdxrmkPd0JF4Xm6sK5ur2 ebpzb81I6PvYrbWIiiP5IEvZL9ADly3/vIFzIfz9+uzcsNQtPfMQaEU4sGmgAIeKpU bujLwwzarIdpRNURdIaYolqJ/o+nW0K8s08BUz78= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lingutla-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: clingutla@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id C6BE060542; Wed, 8 Nov 2017 06:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510122530; bh=07TC+NaTnMFKMS5mWMPUXqdbSOLmCBZLmzT6604bydY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SM1Jo4MLK4Q4EbP07/pRJG+0m7b8isOKJR6p5g+vJtYhgWtC9WoS6W/vsvKY5rZDn xQx1e9sc+th/jXY7bpvwCyfbyxuC0edVZXj/fhOhe9fueF+u1t/An/HuDVK3EOYqkd Z8w7bGlbkbYYQUyu5qa75UO93N8B2D8cS5DXOs5E= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C6BE060542 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=clingutla@codeaurora.org From: Lingutla Chandrasekhar To: mingo@kernel.org, peterz@infradead.org Cc: mcgrof@kernel.org, keescook@chromium.org, shile.zhang@nokia.com, matt@codeblueprint.co.uk, akpm@linux-foundation.org, vegard.nossum@oracle.com, penguin-kernel@I-love.SAKURA.ne.jp, jsiddle@redhat.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Lingutla Chandrasekhar , Imran Khan Subject: [RFC] hung task: check specific tasks for long uninterruptible sleep state Date: Wed, 8 Nov 2017 11:58:13 +0530 Message-Id: <20171108062813.25240-1-clingutla@codeaurora.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <1503311156-16919-1-git-send-email-kimran@codeaurora.org> References: <1503311156-16919-1-git-send-email-kimran@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org khungtask by default monitors all tasks for long unterruptible sleep. This change introduces a sysctl option, /proc/sys/kernel/ hung_task_selective_monitoring, to enable monitoring selected tasks. If this sysctl option is enabled then only the tasks with /proc/$PID/hang_detection_enabled set are to be monitored, otherwise all tasks are monitored as default case. Some tasks may intentionally moves to uninterruptable sleep state, which shouldn't leads to khungtask panics, as those are recoverable hungs. So to avoid false hung reports, add an option to select tasks to be monitored and report/panic them only. Signed-off-by: Imran Khan Signed-off-by: Lingutla Chandrasekhar diff --git a/fs/proc/base.c b/fs/proc/base.c index 9d357b2ea6cb..810f9a5e209e 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2733,6 +2733,52 @@ static int proc_tgid_io_accounting(struct seq_file *m, struct pid_namespace *ns, } #endif /* CONFIG_TASK_IO_ACCOUNTING */ +#ifdef CONFIG_DETECT_HUNG_TASK +static ssize_t proc_hung_task_detection_enabled_read(struct file *file, + char __user *buf, size_t count, loff_t *ppos) +{ + struct task_struct *task = get_proc_task(file_inode(file)); + char buffer[PROC_NUMBUF]; + size_t len; + bool hang_detection_enabled; + + if (!task) + return -ESRCH; + hang_detection_enabled = task->hang_detection_enabled; + put_task_struct(task); + + len = snprintf(buffer, sizeof(buffer), "%d\n", hang_detection_enabled); + + return simple_read_from_buffer(buf, sizeof(buffer), ppos, buffer, len); +} + +static ssize_t proc_hung_task_detection_enabled_write(struct file *file, + const char __user *buf, size_t count, loff_t *ppos) +{ + struct task_struct *task; + bool hang_detection_enabled; + int rv; + + rv = kstrtobool_from_user(buf, count, &hang_detection_enabled); + if (rv < 0) + return rv; + + task = get_proc_task(file_inode(file)); + if (!task) + return -ESRCH; + task->hang_detection_enabled = hang_detection_enabled; + put_task_struct(task); + + return count; +} + +static const struct file_operations proc_hung_task_detection_enabled_operations = { + .read = proc_hung_task_detection_enabled_read, + .write = proc_hung_task_detection_enabled_write, + .llseek = generic_file_llseek, +}; +#endif + #ifdef CONFIG_USER_NS static int proc_id_map_open(struct inode *inode, struct file *file, const struct seq_operations *seq_ops) @@ -2976,6 +3022,10 @@ static const struct pid_entry tgid_base_stuff[] = { #ifdef CONFIG_HARDWALL ONE("hardwall", S_IRUGO, proc_pid_hardwall), #endif +#ifdef CONFIG_DETECT_HUNG_TASK + REG("hang_detection_enabled", 0666, + proc_hung_task_detection_enabled_operations), +#endif #ifdef CONFIG_USER_NS REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations), REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations), @@ -3367,6 +3417,10 @@ static const struct pid_entry tid_base_stuff[] = { #ifdef CONFIG_HARDWALL ONE("hardwall", S_IRUGO, proc_pid_hardwall), #endif +#ifdef CONFIG_DETECT_HUNG_TASK + REG("hang_detection_enabled", 0666, + proc_hung_task_detection_enabled_operations), +#endif #ifdef CONFIG_USER_NS REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations), REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations), diff --git a/include/linux/sched.h b/include/linux/sched.h index fdf74f27acf1..1280df0a6708 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -767,6 +767,7 @@ struct task_struct { #endif #ifdef CONFIG_DETECT_HUNG_TASK unsigned long last_switch_count; + bool hang_detection_enabled; #endif /* Filesystem information: */ struct fs_struct *fs; diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h index d6a18a3839cc..09d9f1c65fd2 100644 --- a/include/linux/sched/sysctl.h +++ b/include/linux/sched/sysctl.h @@ -11,6 +11,7 @@ extern int sysctl_hung_task_check_count; extern unsigned int sysctl_hung_task_panic; extern unsigned long sysctl_hung_task_timeout_secs; extern int sysctl_hung_task_warnings; +extern int sysctl_hung_task_selective_monitoring; extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 751593ed7c0b..321bcfa2e34a 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -20,12 +20,21 @@ #include #include +#include /* * The number of tasks checked: */ int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT; +/* + * Selective monitoring of hung tasks. + * + * if set to 1, khungtaskd only monitors tasks with 'hang_detection_enabled' + * value set, else monitors all tasks. + */ +int sysctl_hung_task_selective_monitoring; + /* * Limit number of tasks checked in a batch. * @@ -187,7 +196,10 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) } /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ if (t->state == TASK_UNINTERRUPTIBLE) - check_hung_task(t, timeout); + /* Check for selective monitoring */ + if (!sysctl_hung_task_selective_monitoring || + t->hang_detection_enabled) + check_hung_task(t, timeout); } unlock: rcu_read_unlock(); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index d9c31bc2eaea..30cc108ce2cc 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1093,6 +1093,16 @@ static struct ctl_table kern_table[] = { .proc_handler = proc_dointvec_minmax, .extra1 = &neg_one, }, + { + .procname = "hung_task_selective_monitoring", + .data = &sysctl_hung_task_selective_monitoring, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, + #endif #ifdef CONFIG_RT_MUTEXES { -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project. From 1583541235020732821@xxx Wed Nov 08 23:10:04 +0000 2017 X-GM-THRID: 1583410731281247141 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread