lkml.org 
[lkml]   [2021]   [Aug]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH 1/1] mm/vmstat: Protect per cpu variables with preempt disable on RT
    From
    Date
    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

    \
     
     \ /
      Last update: 2021-08-06 09:52    [W:2.281 / U:0.128 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site