Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5177560rwb; Wed, 17 Aug 2022 12:29:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR4YGjnaXGwsqWdMnTKZLqNAq3heE5Hmzj+UWsXDGpWTareFVT33xf19pjmDoMWYs7ISZWuj X-Received: by 2002:a17:90b:390c:b0:1f5:8859:ac76 with SMTP id ob12-20020a17090b390c00b001f58859ac76mr5078815pjb.137.1660764594902; Wed, 17 Aug 2022 12:29:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660764594; cv=none; d=google.com; s=arc-20160816; b=dM3KvRealukaNWWg4DZ8+3TYefzhLJdWFvjvO6KWlhQzC9LezBLsQ5p7xnCj/EYxNs 7XTmmy/N53yHTpn5dWiHDxG4FcPwHvbpM1SHaidnN1Jea6h70ia87FuE/miQH61zJEMQ ECQks4IL3tU6hFu9wa/GzudhGPMTslJePg0HPDfSRMS0HbosOqQzVPis54iBqK0dSOR2 myyi62OIMEhz4N0nX7cOXGo/txA4EExnUGiUUt/yvWPfz/e5BPsG3bRHpvOiDnbD9QLg tKWA52ZCtCFsS7OLMrWQQxFEzZNhFJS8NodhE4HNS3tiSj8ZCebUVt0LKVekxWNrIBTK qXbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=QYqdYLqJ3BIjbiDz9gg2I/w9f9Ix7ZBsTkYeq0twwGo=; b=VhBqZPM7d5H+NzmjadlDp4TDTw7CdubMwaoL4SYFLYRFHqZmEmrjVDkI8e5yj3fjJB i0TEVi6xTHZZ142/1ZeZzI1B7FVJrvuLn8fqsBsemobdWTnSgQlld56eKIPZz2fIrwpy KLR5E5BnS/XXFASIxg6nUSzrnr1XnOoMuMyJv9H237/KffOEbl0R94CjA0RSgDW/BZq1 t6WpyxRCKsj+Q0dTHvqMubawhfCt9Aa2I4dDtU5s2kbMvlTEh0sZWenh+7XH0F357Z64 2vTg2r9Cl9S51IpymdGZU6r5vW9sCSibEeMI+eGOpUyrQ6qXiEobryOwLIsOnvG/a7f0 2+WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IXqj2PJL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o16-20020a63e350000000b004128ea1a97dsi16800762pgj.399.2022.08.17.12.29.43; Wed, 17 Aug 2022 12:29:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IXqj2PJL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241445AbiHQTRS (ORCPT + 99 others); Wed, 17 Aug 2022 15:17:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241420AbiHQTRH (ORCPT ); Wed, 17 Aug 2022 15:17:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C9AB4D142 for ; Wed, 17 Aug 2022 12:17:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660763825; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=QYqdYLqJ3BIjbiDz9gg2I/w9f9Ix7ZBsTkYeq0twwGo=; b=IXqj2PJL6F/OSUcl/FRTAQOSxknwailMAuT+BwIqbHe/uvBr3DjSoB6MWwjeshCL5wCTn+ X927gSoo3Vn7rRpyaUqOnIlKRdtC9YvqAl32KG3MCSH9B+xEZd1LDqE//gbs6Gjjb3UnHj WFHReMJrMTtXKDlMv7pRUZi78dEX4pI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-620-neGK6-J5PMOWa2OM7VkZOw-1; Wed, 17 Aug 2022 15:17:01 -0400 X-MC-Unique: neGK6-J5PMOWa2OM7VkZOw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 996B43C10142; Wed, 17 Aug 2022 19:17:00 +0000 (UTC) Received: from fuller.cnet (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 67B28492CA4; Wed, 17 Aug 2022 19:17:00 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 5DF1F416D8A2; Wed, 17 Aug 2022 16:16:24 -0300 (-03) Message-ID: <20220817191524.263315216@redhat.com> User-Agent: quilt/0.66 Date: Wed, 17 Aug 2022 16:13:49 -0300 From: Marcelo Tosatti To: atomlin@redhat.com, frederic@kernel.org Cc: cl@linux.com, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, pauld@redhat.com, neelx@redhat.com, oleksandr@natalenko.name, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Marcelo Tosatti Subject: [PATCH v7 3/3] mm/vmstat: do not queue vmstat_update if tick is stopped References: <20220817191346.287594886@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >From the vmstat shepherd, for CPUs that have the tick stopped, do not queue local work to flush the per-CPU vmstats, since in that case the flush is performed on return to userspace or when entering idle. Per-cpu pages can be freed remotely from housekeeping CPUs. Move the quiet_vmstat call after ts->tick_stopped = 1 assignment. Signed-off-by: Marcelo Tosatti --- kernel/time/tick-sched.c | 6 +++--- mm/vmstat.c | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) Index: linux-2.6/mm/vmstat.c =================================================================== --- linux-2.6.orig/mm/vmstat.c +++ linux-2.6/mm/vmstat.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "internal.h" @@ -1973,19 +1974,27 @@ static void vmstat_update(struct work_st */ void quiet_vmstat(void) { + struct delayed_work *dw; + if (system_state != SYSTEM_RUNNING) return; if (!__this_cpu_read(vmstat_dirty)) return; + refresh_cpu_vm_stats(false); + /* - * Just refresh counters and do not care about the pending delayed - * vmstat_update. It doesn't fire that often to matter and canceling - * it would be too expensive from this path. - * vmstat_shepherd will take care about that for us. + * If the tick is stopped, cancel any delayed work to avoid + * interruptions to this CPU in the future. + * + * Otherwise just refresh counters and do not care about the pending + * delayed vmstat_update. It doesn't fire that often to matter + * and canceling it would be too expensive from this path. */ - refresh_cpu_vm_stats(false); + dw = &per_cpu(vmstat_work, smp_processor_id()); + if (delayed_work_pending(dw) && tick_nohz_tick_stopped()) + cancel_delayed_work(dw); } /* @@ -2007,6 +2016,9 @@ static void vmstat_shepherd(struct work_ for_each_online_cpu(cpu) { struct delayed_work *dw = &per_cpu(vmstat_work, cpu); + if (tick_nohz_tick_stopped_cpu(cpu)) + continue; + if (!delayed_work_pending(dw) && per_cpu(vmstat_dirty, cpu)) queue_delayed_work_on(cpu, mm_percpu_wq, dw, 0); Index: linux-2.6/kernel/time/tick-sched.c =================================================================== --- linux-2.6.orig/kernel/time/tick-sched.c +++ linux-2.6/kernel/time/tick-sched.c @@ -905,9 +905,6 @@ static void tick_nohz_stop_tick(struct t ts->do_timer_last = 0; } - /* Attempt to fold when the idle tick is stopped or not */ - quiet_vmstat(); - /* Skip reprogram of event if its not changed */ if (ts->tick_stopped && (expires == ts->next_tick)) { /* Sanity check: make sure clockevent is actually programmed */ @@ -935,6 +932,9 @@ static void tick_nohz_stop_tick(struct t trace_tick_stop(1, TICK_DEP_MASK_NONE); } + /* Attempt to fold when the idle tick is stopped or not */ + quiet_vmstat(); + ts->next_tick = tick; /*