From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D554D500940 for ; Thu, 8 Jan 2026 14:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767883298; cv=none; b=IZrmxKTTPB6ShKwvQgkykxZ9wWlDeZGWYjZpM1702UKyHTqH9NMeWXVAnaQl+5Oh6zPD/eGjVawCi4y2dL7gV0POYabUq/mMddYx5Dphjkvm/HALEDBXc7ai5EzG1s7iPuNIzMFRN/IVnbTXpfDAz8FR7CN+lNyy4qrNGoa4d8Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767883298; c=relaxed/simple; bh=qxRU8CDItqYk6eAgN5buQwyDXgSajRU0PHagcG5vE9o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rWM8CD0F+aBR5nVqpLBvl/EQBkXu8mv0P3KhlUrUaPBoDabZwd9ikndODlND8tu0toCuF3pO6YyKs7EDJg9Ukh0SLHO+n8d6QbTdeADHkeRnUdMyWaQkqiA1zliWYRAUCrmIxQR3zuRD2YiOmc5mAfBcerdqSFwXqXXL79HowuA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=dxf9EINd; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="dxf9EINd" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-477632d9326so20279625e9.1 for ; Thu, 08 Jan 2026 06:41:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1767883291; x=1768488091; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OQ+0CEM/gC9KaMWWl3l3weCgUI45RLvdH6zbMMaX1uQ=; b=dxf9EINde38LGGdHX3ohm39j3EODIJtADWuiN9A/q/pXcXMixKGTO9qREy5sYiLWTq OU6bciyKUDBc3IX/RagwHrrAvP93QVHwqQzUGYUDc8QdCiAmtHv6uwNP+TzyYr7ZUuqZ IZctO3Chs0SttL46/fwrgLM5t6AM2OosvEP9Rw7fGg0YUQ7a6cJc5o4x4ONqSd4kAFOA APvYBbCLlEA7C1WOIo/tjdISreb2e0+eWgotZMpmW0aZTso9BXX4XIMas1cCbLpdzPu9 5YtuGTe1GaXrVJIyxEcM4D9op9QKH4xIF0egeN6EXB8BV+0t02hOAnZ263ps9O4DPyrB ad8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767883291; x=1768488091; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OQ+0CEM/gC9KaMWWl3l3weCgUI45RLvdH6zbMMaX1uQ=; b=reBNggjULC/5/XSUkuE02XUdUrLXvxV3icd1qRQ0d7LjzgvCJeoNxEjbPk97m2viWh BIq7pfIVg2+1+2ByO8iCSp5cYLrRVWG8RbMlV5yIJu49kEhWPl0MKHmY+en4v9C/FwSi YbaKRA8of7cikE9dOTW1r8dcrXozdsl/cNRJiN33NftpEoPZw/yT1+GxEuQ0vQC5XRqk kW11LnnKwHQe/0/Gszwt6OvROaXQhAHWxiyItoyEjl+KHP1AiGT4cgit7ne0/5XHDi41 1KCR09HIOYQiuQrd5QX4E6mfie9mQpqTN1grKsGG5oj6NsPeCCgdArgbHHhfttKFohNX C9zg== X-Forwarded-Encrypted: i=1; AJvYcCWsOqangMr67AFC0RGSHIOhTLFex4YhAM89e3/w4u63KJGBkKDbeNRQ8TsZ93FY/SB6FADQ5b5aKFzDLVY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0mKudClJ//fltFc91r6bo3baa+TmYUrEiHzDTAbbeVx4JrFek GmRjOMSBEJqEKNqFFiPyiCD2ypCOYB3my2Y5HEnZ79Wfi2VBSJp70sQFWdZl1oaJg1o= X-Gm-Gg: AY/fxX6fDV+/bC/WyjaJsZveWEMmtJmEKQiPgEk/A40zIQtCmUiB97m3WvosbkOpWgf WHPXBw12dnTSZ5W0P+zf1VwdxlYajRe5yr7nPKdYCDOk2PKoZpJfdY3SaA3bT6sCxvKqiYha7N+ usL4goN7iZlmtNCNhhWJnWUNJ6Arwp3DI6I4yMClpmcy22F/MAHfEPHe1EtuDMJ7KFXAq22MizA ixyHWQZ5Ndaus8SkSndSGFFCIJfgYseqzNfIEM58uRvUPBSbncl84eCkfWkEYLxUUa8E4AFGnfY SgCegBvkVtJXouJiP/++EHYhJWOaGnXX8J0g/4dSCR6125ObRCiGa/AmNbUhos7vGgOk3Z19esH oIjJdmpnqsEwcSH1xI5xcyqKQiDIB7X8FVzzlX6i9gsCItwGLkUA7AbD5GYOuyRNPDjAcLnGS/+ qDGc6B2u2oWwsLRw== X-Google-Smtp-Source: AGHT+IG3L9mRrAVoFcSEc4+EFfOwIKsAS71xEo/N8LGhSyW7RLlbQyj3VlQDvkD17flrJXH2d8INow== X-Received: by 2002:a05:6000:1448:b0:432:5c43:5d with SMTP id ffacd0b85a97d-432c37c87bbmr7637073f8f.36.1767883290967; Thu, 08 Jan 2026 06:41:30 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-432d286cdecsm2914867f8f.7.2026.01.08.06.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jan 2026 06:41:30 -0800 (PST) Date: Thu, 8 Jan 2026 15:41:28 +0100 From: Petr Mladek To: Aaron Tomlin Cc: akpm@linux-foundation.org, lance.yang@linux.dev, mhiramat@kernel.org, gregkh@linuxfoundation.org, joel.granados@kernel.org, sean@ashe.io, linux-kernel@vger.kernel.org Subject: Re: [v5 PATCH 2/2] hung_task: Enable runtime reset of hung_task_detect_count Message-ID: References: <20251231004125.2380105-1-atomlin@atomlin.com> <20251231004125.2380105-3-atomlin@atomlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251231004125.2380105-3-atomlin@atomlin.com> On Tue 2025-12-30 19:41:25, Aaron Tomlin wrote: > Introduce support for writing to /proc/sys/kernel/hung_task_detect_count. > > Writing a value of zero to this file atomically resets the counter of > detected hung tasks. This grants system administrators the ability to > clear the cumulative diagnostic history after resolving an incident, > simplifying monitoring without requiring a system restart. > --- a/kernel/hung_task.c > +++ b/kernel/hung_task.c > @@ -36,7 +37,7 @@ static int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT; > /* > * Total number of tasks detected as hung since boot: > */ > -static unsigned long __read_mostly sysctl_hung_task_detect_count; > +static atomic_long_t sysctl_hung_task_detect_count = ATOMIC_LONG_INIT(0); > > /* > * Limit number of tasks checked in a batch. > @@ -246,20 +247,26 @@ static inline void hung_task_diagnostics(struct task_struct *t) > } > > static void check_hung_task(struct task_struct *t, unsigned long timeout, > - unsigned long prev_detect_count) > + unsigned long prev_detect_count) > { > - unsigned long total_hung_task; > + unsigned long total_hung_task, cur_detect_count; > > if (!task_is_hung(t, timeout)) > return; > > /* > * This counter tracks the total number of tasks detected as hung > - * since boot. > + * since boot. If a reset occurred during the scan, we treat the > + * current count as the new delta to avoid an underflow error. > + * Ensure hang details are globally visible before the counter > + * update. > */ > - sysctl_hung_task_detect_count++; > + cur_detect_count = atomic_long_inc_return_release(&sysctl_hung_task_detect_count); The _release() feels a bit weird here because the counter might get incremented more times during one scan. IMHO, it should be perfectly fine to use the _relaxed version here because it is in the middle of the acquire/release, see below. The important thing here is that the load/modify/store operation is done atomically. > + if (cur_detect_count >= prev_detect_count) > + total_hung_task = cur_detect_count - prev_detect_count; > + else > + total_hung_task = cur_detect_count; > > - total_hung_task = sysctl_hung_task_detect_count - prev_detect_count; > trace_sched_process_hang(t); > > if (sysctl_hung_task_panic && total_hung_task >= sysctl_hung_task_panic) { > @@ -318,10 +325,12 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) > int max_count = sysctl_hung_task_check_count; > unsigned long last_break = jiffies; > struct task_struct *g, *t; > - unsigned long prev_detect_count = sysctl_hung_task_detect_count; > + unsigned long cur_detect_count, prev_detect_count, delta; > int need_warning = sysctl_hung_task_warnings; > unsigned long si_mask = hung_task_si_mask; > > + /* Acquire prevents reordering task checks before this point. */ > + prev_detect_count = atomic_long_read_acquire(&sysctl_hung_task_detect_count); This value is read before the scan started => _acquire semantic/barrier fits here. > /* > * If the system crashed already then all bets are off, > * do not report extra hung tasks: > @@ -346,7 +355,14 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) > unlock: > rcu_read_unlock(); > > - if (!(sysctl_hung_task_detect_count - prev_detect_count)) > + /* Ensures we see all hang details recorded during the scan. */ > + cur_detect_count = atomic_long_read_acquire(&sysctl_hung_task_detect_count); This value is read at the end of the scan => _release semantic/barrier should be here. > + if (cur_detect_count < prev_detect_count) > + delta = cur_detect_count; > + else > + delta = cur_detect_count - prev_detect_count; > + > + if (!delta) > return; > > if (need_warning || hung_task_call_panic) { Otherwise, I do not have anything more to add. I agree with the other proposals, for example: + remove 1st patch + split 2nd patch into two + changes in the sysctl code proposed by Joel Best Regards, Petr