Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp89345pxt; Thu, 5 Aug 2021 18:59:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtfXgovFCI5ReRTOLk6OeqRjaDs8seScb1zzdDXH+udYQ6TxfV48BBOi3frzGeUuHwFkp4 X-Received: by 2002:a05:6602:3359:: with SMTP id c25mr42050ioz.181.1628215189876; Thu, 05 Aug 2021 18:59:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628215189; cv=none; d=google.com; s=arc-20160816; b=P+1sZAMk3M8+IHlJKySxc4i40VVqrElhy5TifWR0Z1GZlu8aiob0UT5N9IKskAPM9J vKb7kUDs28mBuBrmYE91zEl6NMfvLlV5YbACG1ffISRksB9Txdb7IDkX5CoJvgVgi7em 6cNPkVvmwaXLl3m/Vytg/To87ZgfqNuSxxmpWCjt1Nt0j25CWMnOdonCr1RG+Bo2tTth RJ/j438kcoL7pEuLWiET7753djAJqgA1Hb8Q5xIc14ZjZknWQxxg+3b3ip/cW2DNztY6 QPiquNL+OkayNSKmKI4k5MYh9Pp/JEUy0/+2o1/4Wb90BQwLKV6zcg+xOQip1HvqgpTC PdCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=VriZ6gXvj5q81QHYV29FG9APDzVDEFZciHw7khc9QeU=; b=yrvcuJXEePOYVPlGWkQ7a5MS2LYLFOqiKc3yGo4qP7ssCXm98egOkZuaWtqC1PioVA WZ2w4LWQfmXaDmsuMxpErAAGYrdGceycD18F5oTPt3UXzOowoMPuKaIsfj+ct3/RQ8M1 wVPX7zll5trubKSQ0ZROR09b1hLcWnmW/KXWubOGmIV7Fx6C693ocdgemSUfVYTTuMTk PrlzMDBH0dKhVrhE0FiO/n+hmwIJB1FS5pdF36Hlsx2Wjeg+lSHSPSogtJ+FCmru6+0r a36CO9tWmP+Cyd/Vvh2ZamRP0Vjvojf7rChQXcE2nRvvum/Q2wOpVbUKjHsTeloDsYxo m91w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=PTOpokAD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y11si7922068ilc.54.2021.08.05.18.59.08; Thu, 05 Aug 2021 18:59:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=PTOpokAD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234051AbhHEXWX (ORCPT + 99 others); Thu, 5 Aug 2021 19:22:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:33132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbhHEXWW (ORCPT ); Thu, 5 Aug 2021 19:22:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 09D3060EB9; Thu, 5 Aug 2021 23:22:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628205727; bh=i33xhaeVpXGV2BhPzbhlBwQZn8O01SRCEx1xg2D/ogc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PTOpokADg1joo1BVq/LCyTP9Dfnys2JPYFddBTo/oM2s9Oq8QuhsyXA1enMA2eGac 0x4GIL0nALbQznW9/AXuBTYRAWOBBTmZ1dxdvKyj5e0dgMs+brROUIjE84aqWvlSR8 Dddsnpxxa3os65Jvg4JFsDxb4S8YyKSRDuS2cUWc= Date: Thu, 5 Aug 2021 16:22:06 -0700 From: Andrew Morton To: Mel Gorman Cc: Thomas Gleixner , Ingo Molnar , Vlastimil Babka , Hugh Dickins , Linux-MM , Linux-RT-Users , LKML Subject: Re: [PATCH 1/1] mm/vmstat: Protect per cpu variables with preempt disable on RT Message-Id: <20210805162206.664dfc8c090f2be5ea313d57@linux-foundation.org> In-Reply-To: <20210805160019.1137-2-mgorman@techsingularity.net> References: <20210805160019.1137-1-mgorman@techsingularity.net> <20210805160019.1137-2-mgorman@techsingularity.net> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 5 Aug 2021 17:00:19 +0100 Mel Gorman wrote: > From: Ingo Molnar > > 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(); } ?