All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Andrew Morton <akpm@linux-foundation.org>,
	Mel Gorman <mgorman@techsingularity.net>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, Hugh Dickins <hughd@google.com>,
	Linux-MM <linux-mm@kvack.org>,
	Linux-RT-Users <linux-rt-users@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] mm/vmstat: Protect per cpu variables with preempt disable on RT
Date: Fri, 6 Aug 2021 09:50:03 +0200	[thread overview]
Message-ID: <df1f16f9-1a29-5525-4673-f437fb03dc92@suse.cz> (raw)
In-Reply-To: <20210805162206.664dfc8c090f2be5ea313d57@linux-foundation.org>

On 8/6/21 1:22 AM, Andrew Morton wrote:
> On Thu,  5 Aug 2021 17:00:19 +0100 Mel Gorman <mgorman@techsingularity.net> wrote:
> 
>> From: Ingo Molnar <mingo@elte.hu>
>> 
>> Disable preemption on -RT for the vmstat code. On vanila the code runs
>> in IRQ-off regions while on -RT it may not when stats are updated under
>> a local_lock. "preempt_disable" ensures that the same resources is not
>> updated in parallel due to preemption.
>> 
>> This patch differs from the preempt-rt version where __count_vm_event and
>> __count_vm_events are also protected. The counters are explicitly "allowed
>> to be to be racy" so there is no need to protect them from preemption. Only
>> the accurate page stats that are updated by a read-modify-write need
>> protection. This patch also differs in that a preempt_[en|dis]able_rt
>> helper is not used. As vmstat is the only user of the helper, it was
>> suggested that it be open-coded in vmstat.c instead of risking the helper
>> being used in unnecessary contexts.
>> 
>> ...
>>
>> --- a/mm/vmstat.c
>> +++ b/mm/vmstat.c
>> @@ -319,6 +319,16 @@ void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
>>  	long x;
>>  	long t;
>>  
>> +	/*
>> +	 * Accurate vmstat updates require a RMW. On !PREEMPT_RT kernels,
>> +	 * atomicity is provided by IRQs being disabled -- either explicitly
>> +	 * or via local_lock_irq. On PREEMPT_RT, local_lock_irq only disables
>> +	 * CPU migrations and preemption potentially corrupts a counter so
>> +	 * disable preemption.
>> +	 */
>> +	if (IS_ENABLED(CONFIG_PREEMPT_RT))
>> +		preempt_disable();
> 
> This is so obvious I expect it has been discussed, but...  why not
> 
> static inline void preempt_disable_if_rt(void)
> {
> 	if (IS_ENABLED(CONFIG_PREEMPT_RT))
> 		preempt_disable();
> }

Yeah v1 introduced similar more generic ones in include/linux/preempt.h and
Thomas didn't like that. I guess it would be more acceptable when confined to
mm/vmstat.c

  reply	other threads:[~2021-08-06  7:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-05 16:00 [PATCH 0/1 v2] Protect vmstats on PREEMPT_RT Mel Gorman
2021-08-05 16:00 ` [PATCH 1/1] mm/vmstat: Protect per cpu variables with preempt disable on RT Mel Gorman
2021-08-05 23:22   ` Andrew Morton
2021-08-06  7:50     ` Vlastimil Babka [this message]
2021-08-06  8:44     ` Mel Gorman
2021-08-06 12:38   ` Vlastimil Babka
2021-08-31 16:45   ` Sebastian Andrzej Siewior
2021-09-02 20:07     ` Andrew Morton
2021-09-06 13:48     ` Mel Gorman
2021-09-06 14:03       ` Sebastian Andrzej Siewior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df1f16f9-1a29-5525-4673-f437fb03dc92@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=mgorman@techsingularity.net \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.