From patchwork Fri Dec 10 22:46:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 523062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97C49C433F5 for ; Fri, 10 Dec 2021 22:46:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344745AbhLJWuB (ORCPT ); Fri, 10 Dec 2021 17:50:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344718AbhLJWuB (ORCPT ); Fri, 10 Dec 2021 17:50:01 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC70C061746; Fri, 10 Dec 2021 14:46:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EF7ECB827BD; Fri, 10 Dec 2021 22:46:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77424C341CC; Fri, 10 Dec 2021 22:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1639176382; bh=q6RfDfuJeEvi3q8xEd4Z830faXUH5/x9+E+1EHvZKnw=; h=Date:From:To:Subject:In-Reply-To:From; b=hZ/ho0/mgu9TXq5bYNROEZ1C7CzlgHK2ZjVorUjxZrVhPg4kPGbHm9CS5WCb8OKSV 19VdtnGrI1+JwZJuHTnXM0Ee6nR/ArlXmUFb3qe/73iwCEdbY7sUBiMNDLe/Vrfhv2 msLIFg4uJrNGREhT6TOEw0vV5BGtzW5rUYBHBQE4= Date: Fri, 10 Dec 2021 14:46:22 -0800 From: Andrew Morton To: akpm@linux-foundation.org, john.stultz@linaro.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, oleksandr@natalenko.name, sj@kernel.org, stable@vger.kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org Subject: [patch 05/21] timers: implement usleep_idle_range() Message-ID: <20211210224622.Dk89hIymE%akpm@linux-foundation.org> In-Reply-To: <20211210144539.663efee2c80d8450e6180230@linux-foundation.org> User-Agent: s-nail v14.8.16 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: SeongJae Park Subject: timers: implement usleep_idle_range() Patch series "mm/damon: Fix fake /proc/loadavg reports", v3. This patchset fixes DAMON's fake load report issue. The first patch makes yet another variant of usleep_range() for this fix, and the second patch fixes the issue of DAMON by making it using the newly introduced function. This patch (of 2): Some kernel threads such as DAMON could need to repeatedly sleep in micro seconds level. Because usleep_range() sleeps in uninterruptible state, however, such threads would make /proc/loadavg reports fake load. To help such cases, this commit implements a variant of usleep_range() called usleep_idle_range(). It is same to usleep_range() but sets the state of the current task as TASK_IDLE while sleeping. Link: https://lkml.kernel.org/r/20211126145015.15862-1-sj@kernel.org Link: https://lkml.kernel.org/r/20211126145015.15862-2-sj@kernel.org Signed-off-by: SeongJae Park Suggested-by: Andrew Morton Reviewed-by: Thomas Gleixner Tested-by: Oleksandr Natalenko Cc: John Stultz Cc: Signed-off-by: Andrew Morton --- include/linux/delay.h | 14 +++++++++++++- kernel/time/timer.c | 16 +++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) --- a/include/linux/delay.h~timers-implement-usleep_idle_range +++ a/include/linux/delay.h @@ -20,6 +20,7 @@ */ #include +#include extern unsigned long loops_per_jiffy; @@ -58,7 +59,18 @@ void calibrate_delay(void); void __attribute__((weak)) calibration_delay_done(void); void msleep(unsigned int msecs); unsigned long msleep_interruptible(unsigned int msecs); -void usleep_range(unsigned long min, unsigned long max); +void usleep_range_state(unsigned long min, unsigned long max, + unsigned int state); + +static inline void usleep_range(unsigned long min, unsigned long max) +{ + usleep_range_state(min, max, TASK_UNINTERRUPTIBLE); +} + +static inline void usleep_idle_range(unsigned long min, unsigned long max) +{ + usleep_range_state(min, max, TASK_IDLE); +} static inline void ssleep(unsigned int seconds) { --- a/kernel/time/timer.c~timers-implement-usleep_idle_range +++ a/kernel/time/timer.c @@ -2054,26 +2054,28 @@ unsigned long msleep_interruptible(unsig EXPORT_SYMBOL(msleep_interruptible); /** - * usleep_range - Sleep for an approximate time - * @min: Minimum time in usecs to sleep - * @max: Maximum time in usecs to sleep + * usleep_range_state - Sleep for an approximate time in a given state + * @min: Minimum time in usecs to sleep + * @max: Maximum time in usecs to sleep + * @state: State of the current task that will be while sleeping * * In non-atomic context where the exact wakeup time is flexible, use - * usleep_range() instead of udelay(). The sleep improves responsiveness + * usleep_range_state() instead of udelay(). The sleep improves responsiveness * by avoiding the CPU-hogging busy-wait of udelay(), and the range reduces * power usage by allowing hrtimers to take advantage of an already- * scheduled interrupt instead of scheduling a new one just for this sleep. */ -void __sched usleep_range(unsigned long min, unsigned long max) +void __sched usleep_range_state(unsigned long min, unsigned long max, + unsigned int state) { ktime_t exp = ktime_add_us(ktime_get(), min); u64 delta = (u64)(max - min) * NSEC_PER_USEC; for (;;) { - __set_current_state(TASK_UNINTERRUPTIBLE); + __set_current_state(state); /* Do not return before the requested sleep time has elapsed */ if (!schedule_hrtimeout_range(&exp, delta, HRTIMER_MODE_ABS)) break; } } -EXPORT_SYMBOL(usleep_range); +EXPORT_SYMBOL(usleep_range_state); From patchwork Fri Dec 10 22:46:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 523388 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B4A4C433FE for ; Fri, 10 Dec 2021 22:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344750AbhLJWuF (ORCPT ); Fri, 10 Dec 2021 17:50:05 -0500 Received: from sin.source.kernel.org ([145.40.73.55]:56974 "EHLO sin.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344718AbhLJWuE (ORCPT ); Fri, 10 Dec 2021 17:50:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id B4E98CE2B7D; Fri, 10 Dec 2021 22:46:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D744C00446; Fri, 10 Dec 2021 22:46:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1639176385; bh=xc+JETihgXXiqFz+VxJKnyLRp8GtucnyUYHiLi2tBko=; h=Date:From:To:Subject:In-Reply-To:From; b=wKkojB9qiP7L8VhAuqE8tbOQLuu6A7HnEMTqWibjBuoWcIShSrua/HVUrPvRy8tcJ tpBhJD9LmgkFyZ21EJ7Yv79wLepROv2EbHRqCrgT+wc0+JzDKA2fAdprQSXFQzmOSI DPsQPm+YvPun06Qrkm9f0ZZjpOdWGtj3zCmlGK/A= Date: Fri, 10 Dec 2021 14:46:25 -0800 From: Andrew Morton To: akpm@linux-foundation.org, john.stultz@linaro.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, oleksandr@natalenko.name, sj@kernel.org, stable@vger.kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org Subject: [patch 06/21] mm/damon/core: fix fake load reports due to uninterruptible sleeps Message-ID: <20211210224625.aHoRXImMJ%akpm@linux-foundation.org> In-Reply-To: <20211210144539.663efee2c80d8450e6180230@linux-foundation.org> User-Agent: s-nail v14.8.16 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: SeongJae Park Subject: mm/damon/core: fix fake load reports due to uninterruptible sleeps Because DAMON sleeps in uninterruptible mode, /proc/loadavg reports fake load while DAMON is turned on, though it is doing nothing. This can confuse users[1]. To avoid the case, this commit makes DAMON sleeps in idle mode. [1] https://lore.kernel.org/all/11868371.O9o76ZdvQC@natalenko.name/ Link: https://lkml.kernel.org/r/20211126145015.15862-3-sj@kernel.org Fixes: 2224d8485492 ("mm: introduce Data Access MONitor (DAMON)") Reported-by: Oleksandr Natalenko Signed-off-by: SeongJae Park Tested-by: Oleksandr Natalenko Cc: John Stultz Cc: Thomas Gleixner Cc: Signed-off-by: Andrew Morton --- mm/damon/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/mm/damon/core.c~mm-damon-core-fix-fake-load-reports-due-to-uninterruptible-sleeps +++ a/mm/damon/core.c @@ -981,9 +981,9 @@ static unsigned long damos_wmark_wait_us static void kdamond_usleep(unsigned long usecs) { if (usecs > 100 * 1000) - schedule_timeout_interruptible(usecs_to_jiffies(usecs)); + schedule_timeout_idle(usecs_to_jiffies(usecs)); else - usleep_range(usecs, usecs + 1); + usleep_idle_range(usecs, usecs + 1); } /* Returns negative error code if it's not activated but should return */ @@ -1038,7 +1038,7 @@ static int kdamond_fn(void *data) ctx->callback.after_sampling(ctx)) done = true; - usleep_range(ctx->sample_interval, ctx->sample_interval + 1); + kdamond_usleep(ctx->sample_interval); if (ctx->primitive.check_accesses) max_nr_accesses = ctx->primitive.check_accesses(ctx); From patchwork Fri Dec 10 22:47:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 523061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8676C4332F for ; Fri, 10 Dec 2021 22:47:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345000AbhLJWup (ORCPT ); Fri, 10 Dec 2021 17:50:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345010AbhLJWun (ORCPT ); Fri, 10 Dec 2021 17:50:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC8D8C061D60; Fri, 10 Dec 2021 14:47:03 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 56D6FB82A22; Fri, 10 Dec 2021 22:47:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C38DC00446; Fri, 10 Dec 2021 22:47:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1639176423; bh=e371BC48yi+1zkcqf7J8rWC7iV2JeIwQviTRnB13Kls=; h=Date:From:To:Subject:In-Reply-To:From; b=qpY/s0wadtl/IEGFGEEkLlISN9uKcIInlTINk0m2DjQs5BGhAuKhd8kgRCr/Q5Kzt ExOFW5fXLpg4sEkumGTwfamiV/ioV46/NLt1vgiy8drY7LIbTamCPgCU7N22BlR1pV NKbqorpTmn54M2J3Sjpv63prhg7JMlUTJA4khRg0= Date: Fri, 10 Dec 2021 14:47:02 -0800 From: Andrew Morton To: akpm@linux-foundation.org, cl@linux.com, faiyazm@codeaurora.org, gerald.schaefer@linux.ibm.com, gregkh@linuxfoundation.org, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, maier@linux.ibm.com, mm-commits@vger.kernel.org, penberg@kernel.org, rientjes@google.com, stable@vger.kernel.org, torvalds@linux-foundation.org, vbabka@suse.cz Subject: [patch 18/21] mm/slub: fix endianness bug for alloc/free_traces attributes Message-ID: <20211210224702.RW6YwnTh2%akpm@linux-foundation.org> In-Reply-To: <20211210144539.663efee2c80d8450e6180230@linux-foundation.org> User-Agent: s-nail v14.8.16 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gerald Schaefer Subject: mm/slub: fix endianness bug for alloc/free_traces attributes On big-endian s390, the alloc/free_traces attributes produce endless output, because of always 0 idx in slab_debugfs_show(). idx is de-referenced from *v, which points to a loff_t value, with unsigned int idx = *(unsigned int *)v; This will only give the upper 32 bits on big-endian, which remain 0. Instead of only fixing this de-reference, during discussion it seemed more appropriate to change the seq_ops so that they use an explicit iterator in private loc_track struct. This patch adds idx to loc_track, which will also fix the endianness bug. Link: https://lore.kernel.org/r/20211117193932.4049412-1-gerald.schaefer@linux.ibm.com Link: https://lkml.kernel.org/r/20211126171848.17534-1-gerald.schaefer@linux.ibm.com Fixes: 64dd68497be7 ("mm: slub: move sysfs slab alloc/free interfaces to debugfs") Signed-off-by: Gerald Schaefer Reported-by: Steffen Maier Acked-by: Vlastimil Babka Cc: Faiyaz Mohammed Cc: Greg Kroah-Hartman Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Signed-off-by: Andrew Morton --- mm/slub.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/mm/slub.c~mm-slub-fix-endianness-bug-for-alloc-free_traces-attributes +++ a/mm/slub.c @@ -5081,6 +5081,7 @@ struct loc_track { unsigned long max; unsigned long count; struct location *loc; + loff_t idx; }; static struct dentry *slab_debugfs_root; @@ -6052,11 +6053,11 @@ __initcall(slab_sysfs_init); #if defined(CONFIG_SLUB_DEBUG) && defined(CONFIG_DEBUG_FS) static int slab_debugfs_show(struct seq_file *seq, void *v) { - - struct location *l; - unsigned int idx = *(unsigned int *)v; struct loc_track *t = seq->private; + struct location *l; + unsigned long idx; + idx = (unsigned long) t->idx; if (idx < t->count) { l = &t->loc[idx]; @@ -6105,16 +6106,18 @@ static void *slab_debugfs_next(struct se { struct loc_track *t = seq->private; - v = ppos; - ++*ppos; + t->idx = ++(*ppos); if (*ppos <= t->count) - return v; + return ppos; return NULL; } static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos) { + struct loc_track *t = seq->private; + + t->idx = *ppos; return ppos; } From patchwork Fri Dec 10 22:47:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 523387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9125CC433F5 for ; Fri, 10 Dec 2021 22:47:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344977AbhLJWuw (ORCPT ); Fri, 10 Dec 2021 17:50:52 -0500 Received: from sin.source.kernel.org ([145.40.73.55]:57454 "EHLO sin.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344934AbhLJWuv (ORCPT ); Fri, 10 Dec 2021 17:50:51 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 97AC8CE2D8E; Fri, 10 Dec 2021 22:47:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47AB7C341C8; Fri, 10 Dec 2021 22:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1639176432; bh=d2MtOu+m2tsl2wKYkPsdG7dDlrmKCsZx/QeAMFAPQW8=; h=Date:From:To:Subject:In-Reply-To:From; b=BFnypslsZzIqgnvX3BgWS+MdXDJFCHWn2csm6ZjBHW8kZnBqishXBmr+U02yE2OM7 Wn85SUkwcUzlaoRNOqBCmrLtvKgNeJbI2LY4ppNX1fsRcjhpkcL8ml/GpvFymV2StM QZ4+FL1hJHAItta1/aKhs/X0LyJaRxPJA/9Uuuu4= Date: Fri, 10 Dec 2021 14:47:11 -0800 From: Andrew Morton To: akpm@linux-foundation.org, axboe@kernel.dk, hch@infradead.org, jisoo2146.oh@samsung.com, junho89.kim@samsung.com, linux-mm@kvack.org, mj0123.lee@samsung.com, mm-commits@vger.kernel.org, nanich.lee@samsung.com, peterz@infradead.org, seunghwan.hyun@samsung.com, sookwan7.kim@samsung.com, stable@vger.kernel.org, torvalds@linux-foundation.org, willy@infradead.org, yt0928.kim@samsung.com Subject: [patch 21/21] mm: bdi: initialize bdi_min_ratio when bdi is unregistered Message-ID: <20211210224711.NY_S5okYu%akpm@linux-foundation.org> In-Reply-To: <20211210144539.663efee2c80d8450e6180230@linux-foundation.org> User-Agent: s-nail v14.8.16 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Manjong Lee Subject: mm: bdi: initialize bdi_min_ratio when bdi is unregistered Initialize min_ratio if it is set during bdi unregistration. This can prevent problems that may occur a when bdi is removed without resetting min_ratio. For example. 1) insert external sdcard 2) set external sdcard's min_ratio 70 3) remove external sdcard without setting min_ratio 0 4) insert external sdcard 5) set external sdcard's min_ratio 70 << error occur(can't set) Because when an sdcard is removed, the present bdi_min_ratio value will remain. Currently, the only way to reset bdi_min_ratio is to reboot. [akpm@linux-foundation.org: tweak comment and coding style] Link: https://lkml.kernel.org/r/20211021161942.5983-1-mj0123.lee@samsung.com Signed-off-by: Manjong Lee Acked-by: Peter Zijlstra (Intel) Cc: Changheun Lee Cc: Jens Axboe Cc: Christoph Hellwig Cc: Matthew Wilcox Cc: Cc: Cc: Cc: Cc: Cc: Signed-off-by: Andrew Morton --- mm/backing-dev.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/mm/backing-dev.c~mm-bdi-initialize-bdi_min_ratio-when-bdi-unregister +++ a/mm/backing-dev.c @@ -945,6 +945,13 @@ void bdi_unregister(struct backing_dev_i wb_shutdown(&bdi->wb); cgwb_bdi_unregister(bdi); + /* + * If this BDI's min ratio has been set, use bdi_set_min_ratio() to + * update the global bdi_min_ratio. + */ + if (bdi->min_ratio) + bdi_set_min_ratio(bdi, 0); + if (bdi->dev) { bdi_debug_unregister(bdi); device_unregister(bdi->dev);