From patchwork Sat Sep 24 15:22:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Tomlin X-Patchwork-Id: 12987725 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 3EB1BC07E9D for ; Sat, 24 Sep 2022 15:22:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94B778E0008; Sat, 24 Sep 2022 11:22:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FAAB8E0007; Sat, 24 Sep 2022 11:22:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 774A18E0008; Sat, 24 Sep 2022 11:22:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6174B8E0007 for ; Sat, 24 Sep 2022 11:22:37 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 29E8080EDB for ; Sat, 24 Sep 2022 15:22:37 +0000 (UTC) X-FDA: 79947345954.02.BF4CEEE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id AE77314000A for ; Sat, 24 Sep 2022 15:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664032956; 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: content-transfer-encoding:content-transfer-encoding; bh=+1snCaUxjImmAZmhoUxFGMZM8+j1Rt0OvqNSuvK1WBc=; b=BkMZ0Jbu6JmiKW2lFK6yJMQ726SWx4tklaRfiNOUFIB3/Q7hb+8w9gaVHBVNd3IJmq/0dw WsQvFHpl+evIAEYk7xbVglGxy9eSJawQa2CBw0jQKRBjaDfTZaK7TZTgjD4ahlXmUsdyBW rcq9ZU2irDrM0YxfcZn7no5t8I5SMTo= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-176-fmRnrp4KMDKVTLTkPMno5Q-1; Sat, 24 Sep 2022 11:22:35 -0400 X-MC-Unique: fmRnrp4KMDKVTLTkPMno5Q-1 Received: by mail-wm1-f71.google.com with SMTP id p24-20020a05600c1d9800b003b4b226903dso4336975wms.4 for ; Sat, 24 Sep 2022 08:22:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=+1snCaUxjImmAZmhoUxFGMZM8+j1Rt0OvqNSuvK1WBc=; b=fpkvIAZZ1FQ0OcjDC67TDeXUwUDAi5d0A9p65BkPM+kYrVlwdKvBFff1Ae+46y8Q0/ aK+uPL4svd9ImhNyN9Skp2tmLot/X6YKQ67RiqRjEGCLfEp2nzWbiL72V5+OEYFl4Wpn YjGujBT4qhw/so8+Yu317clBp/ilr3IhtAiQOnl6V8XOg1z1+NTP0P6qiTBg8E8MJ1sP vfBghqqqalv4ZAWNYt+cUz8zzXmmBnyGBvhofIgNnIB+VyNsXh+p6x5CJZ3NOjavXa59 t+pTocmBh8189bgkm1Zpz3HE+n4YejffoTJepGnvrNkRy/2PSPkMOfJesP38fn/Ifgah SGXA== X-Gm-Message-State: ACrzQf1AZ436M104qkr/W5zCKzFWNzIzPzRxA+6GYDlhpnSr37prIhCz LL1ZV1nD3Rl46AJ85mVGAhZvXnyM95KmlHgtwc26Y3cInnZdH1oTkqMQGFELfT6OKJU5DLp+R4g +Ld08MX2wqg== X-Received: by 2002:a5d:464e:0:b0:228:c179:6b0a with SMTP id j14-20020a5d464e000000b00228c1796b0amr8134542wrs.402.1664032949122; Sat, 24 Sep 2022 08:22:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4TaZvijmxZ2nQ7hQk8K9Er9662cfbHWMFdqgZM+aw7znzTA9McjO7K/BHPrwx/RsX90TFDUw== X-Received: by 2002:a5d:464e:0:b0:228:c179:6b0a with SMTP id j14-20020a5d464e000000b00228c1796b0amr8134522wrs.402.1664032948866; Sat, 24 Sep 2022 08:22:28 -0700 (PDT) Received: from localhost (cpc111743-lutn13-2-0-cust979.9-3.cable.virginm.net. [82.17.115.212]) by smtp.gmail.com with ESMTPSA id v8-20020adfa1c8000000b0022865038308sm10129123wrv.93.2022.09.24.08.22.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Sep 2022 08:22:27 -0700 (PDT) From: Aaron Tomlin To: frederic@kernel.org, mtosatti@redhat.com Cc: cl@linux.com, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, pauld@redhat.com, neelx@redhat.com, oleksandr@natalenko.name, atomlin@atomlin.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v8 0/5] Ensure quiet_vmstat() is called when the idle tick was stopped too Date: Sat, 24 Sep 2022 16:22:22 +0100 Message-Id: <20220924152227.819815-1-atomlin@redhat.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BkMZ0Jbu; spf=pass (imf23.hostedemail.com: domain of atomlin@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=atomlin@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664032956; a=rsa-sha256; cv=none; b=IuC5I0CW87JtaChscOAria2ZYS2cq/2yI+a6vzcvKh4Tug2+rWCbU0tlNPxazthFyrq3BI M/L4HYjnKyqk4vTVogJftHvoUwjw5DpwPBkBFIJOAjuxeBfutAntr5K5vZcC6rUHzkUx+L h+x/oBusp99InVDFKXgpTwVrX4I2PcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664032956; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=+1snCaUxjImmAZmhoUxFGMZM8+j1Rt0OvqNSuvK1WBc=; b=RGxXc0QtH2gRF7qqIHAmaTJpCjzvicp7U7nLjUAPmAvT9gWV2Q03YJBvTYRjDMCIyQ3rpP w9BKbgpwUFwPAZN4wwSq8KOeQPdqtIFFqGyA09BgeifKCzGtc+lLvTouZj04ixjdWKYK5k brzizrka7Rk1Q9TCs8QnoirCXuZSTTU= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BkMZ0Jbu; spf=pass (imf23.hostedemail.com: domain of atomlin@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=atomlin@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: xfw3dkurqqiw89t5crff4qm8ad6rb58r X-Rspamd-Queue-Id: AE77314000A X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1664032956-149168 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: Hi Frederic, Marcelo, This patch series addresses the following two problems: 1. A customer provided some evidence which indicates that the idle tick was stopped; albeit, CPU-specific vmstat counters still remained populated. Thus one can only assume quiet_vmstat() was not invoked on return to the idle loop. If I understand correctly, I suspect this divergence might erroneously prevent a reclaim attempt by kswapd. If the number of zone specific free pages are below their per-cpu drift value then zone_page_state_snapshot() is used to compute a more accurate view of the aforementioned statistic. Thus any task blocked on the NUMA node specific pfmemalloc_wait queue will be unable to make significant progress via direct reclaim unless it is killed after being woken up by kswapd (see throttle_direct_reclaim()) 2. With a SCHED_FIFO task that busy loops on a given CPU, and kworker for that CPU at SCHED_OTHER priority, queuing work to sync per-vmstats will either cause that work to never execute, or stalld (i.e. stall daemon) boosts kworker priority which causes a latency violation As seen previously, the trivial test program (i.e. attached at the end of this cover letter) executed inside a KVM VM, was used to determine the somewhat impact under vanilla and with the proposed changes. Firstly, the mlock(2) and munlock(2) system calls was used solely to modify vmstat item 'NR_MLOCK'. In another scenario, the nanosleep(2) system call was used several times to suspend execution for a period of time to approximately compute the number of CPU-cycles in the idle code path. The following is an average count of CPU-cycles across the aforementioned system calls and the idle loop, respectively. I believe these results are negligible: Vanilla Modified Cycles per idle loop 151858 153258 (+1.0%) Cycles per syscall 8461 8690 (+2.6%) Any feedback would be appreciated. Thanks. Changes since v7 [1] - Added trivial helpers for modification and testing (Andrew Morton) - Modified comment since we do now cancel any delayed work if the tick is stopped in quiet_vmstat() - Moved check to ensure vmstat differentials do not remain if the tick is stopped on exiting to user-mode into a separate patch (Frederic Weisbecker) Changes since v6 [2]: - Clean vmstat_dirty before differential sync loop - Cancel pending work if tick stopped - Do not queue work to remote CPU if tick stopped Changes since v5 [3]: - Introduced __tick_nohz_user_enter_prepare() - Switched to EXPORT_SYMBOL_GPL() Changes since v4 [4]: - Moved vmstat_dirty specific changes into a separate patch (Marcelo Tosatti) Changes since v3 [5]: - Used EXPORT_SYMBOL() on tick_nohz_user_enter_prepare() - Replaced need_update() - Introduced CPU-specific variable namely vmstat_dirty and mark_vmstat_dirty() [1]: https://lore.kernel.org/lkml/20220817191346.287594886@redhat.com/ [2]: https://lore.kernel.org/linux-mm/20220808194820.676246-1-atomlin@redhat.com/ [3]: https://lore.kernel.org/lkml/20220801234258.134609-1-atomlin@redhat.com/ [4]: https://lore.kernel.org/lkml/20220621172207.1501641-1-atomlin@redhat.com/ [5]: https://lore.kernel.org/lkml/20220422193647.3808657-1-atomlin@redhat.com/ Aaron Tomlin (4): mm/vmstat: Add CPU-specific variable to track a vmstat discrepancy mm/vmstat: Use vmstat_dirty to track CPU-specific vmstat discrepancies tick/nohz_full: Ensure quiet_vmstat() is called on exit to user-mode when the idle tick is stopped tick/sched: Ensure quiet_vmstat() is called when the idle tick was stopped too Marcelo Tosatti (1): mm/vmstat: Do not queue vmstat_update if tick is stopped include/linux/tick.h | 5 ++- kernel/time/tick-sched.c | 18 ++++++++- mm/vmstat.c | 80 +++++++++++++++++++++------------------- 3 files changed, 62 insertions(+), 41 deletions(-)