From patchwork Wed Aug 17 19:13:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 12946315 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B83AFC25B08 for ; Wed, 17 Aug 2022 19:17:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 304928D0002; Wed, 17 Aug 2022 15:17:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B38E6B0074; Wed, 17 Aug 2022 15:17:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17C278D0002; Wed, 17 Aug 2022 15:17:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 057FE6B0073 for ; Wed, 17 Aug 2022 15:17:04 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C455CA0770 for ; Wed, 17 Aug 2022 19:17:03 +0000 (UTC) X-FDA: 79810042326.12.BDA1CB5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 5F3AD40078 for ; Wed, 17 Aug 2022 19:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660763822; 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=KLLNBxmpbpr4obz0Y9Ar5bs74PZNem8kHeSYZqRUVUWMmfSiLrwifdEr/RjPDuJ4cS722M urFHDo4+lkl1/dn+Dka2M17QddJI40Z0ionhYMZg7RoM9s5lJwWbRokv0o49gfxX0MebIu BfDm5Z/vY72/pp7O//Ry9NXdl/3k07E= 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 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660763823; a=rsa-sha256; cv=none; b=uJ0punnwR9KeHlGH1HgY8mTgUMc85ub0RbfM913Kg6Kciq+9ZIvM7zH4kZ8oQ1exaUJdeI AxF7Knpk2dOY+SVTkfacWjGOl1fnNkqHIbZhLFHQ9Ny3xZRRdRNr2mkA7xGNOaxp04BHDD DVFBpPtm/KyP7WvBa2WcwNtlfAGHyzY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KLLNBxmp; spf=pass (imf01.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660763823; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=QYqdYLqJ3BIjbiDz9gg2I/w9f9Ix7ZBsTkYeq0twwGo=; b=N8FL/wPhWMtZ6lAazIlU0vn/kN1hiVYU9Yj/bm45VnF3mtTJHtaTWtHZ0Jykvu7ZnpI82/ Lpt7Y0aMQwI6QUwWjx95CXJ34M0XDUJ8jO8jfQZEqBTkiKwLJLLJlqmd+D65aUyUFhZDC7 js5yVvhoS0tv2l2vyKBWDZgQ1d0+gPA= X-Stat-Signature: zy6gafoumaoe9dijzgf8bt751duaj1wi X-Rspamd-Queue-Id: 5F3AD40078 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KLLNBxmp; spf=pass (imf01.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1660763823-680542 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: >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; /*