From patchwork Mon Jan 13 07:42:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriele Monaco X-Patchwork-Id: 13936819 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 17BF9E7719E for ; Mon, 13 Jan 2025 07:42:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39DBE6B007B; Mon, 13 Jan 2025 02:42:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 34DC26B0083; Mon, 13 Jan 2025 02:42:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 245706B0085; Mon, 13 Jan 2025 02:42:56 -0500 (EST) 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 15C306B007B for ; Mon, 13 Jan 2025 02:42:56 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C6E18C0EB6 for ; Mon, 13 Jan 2025 07:42:55 +0000 (UTC) X-FDA: 83001637110.09.3D90A10 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id F2B854000D for ; Mon, 13 Jan 2025 07:42:53 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="CXuo0nD/"; spf=pass (imf12.hostedemail.com: domain of gmonaco@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=gmonaco@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=1736754174; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=li7KN2ZkdprLVEkY+yennw/HxJMCnQ5+PjjvDBmLdJc=; b=x46V9E4TkdnXjKnqxs/pW4sSVbXvV7El6DuLq3Hz60tMYk3dcUkWT+BC48QPGHjxNnrIGi QQOviCkVtU1GbZQm6ByZ9JArKYl5fUCC6ne6Qt3zrgDKfbowDm8GeNasxuvs0q7zF+JzrE t42ue1fC8bxlV3W4SWnWUKUbyCJG1+o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736754174; a=rsa-sha256; cv=none; b=5MDXR4GQy+ogSMR9/plKXq9x51PMIAfKuuvC9brDuj/H2hI8St187CwYWUk9gT8MBm6FnA fHvpO9VnqPBsIqvg0d9Yn+CqeBRCpO8HNEDJIQIrXL8NNbS6Nb5d2fhpVPirZEX2vUNPb+ iPHfymvAu6joX5AOSNWGVCivby2XbRk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="CXuo0nD/"; spf=pass (imf12.hostedemail.com: domain of gmonaco@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=gmonaco@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736754173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=li7KN2ZkdprLVEkY+yennw/HxJMCnQ5+PjjvDBmLdJc=; b=CXuo0nD/k60W+iSAj3oy5/CSTDeuIuJSDSoQStVsQDC5tcYX8pEUSa5zJ5LUJNsReGtFO7 S7CmIybf/az6mUIuxW4hwl2zYbFe18DQUAXFIuLOSZJxYo3JoOPv8CWdcVoU0RG1E1bfz5 pZgDteFmCkWLQHgNR7T1wxNBAYrye/k= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-lDX4ZxFfMki3bWWqM0Vn9w-1; Mon, 13 Jan 2025 02:42:49 -0500 X-MC-Unique: lDX4ZxFfMki3bWWqM0Vn9w-1 X-Mimecast-MFC-AGG-ID: lDX4ZxFfMki3bWWqM0Vn9w Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 400001955D4E; Mon, 13 Jan 2025 07:42:48 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.39.192.91]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 321A3195E3D9; Mon, 13 Jan 2025 07:42:44 +0000 (UTC) From: Gabriele Monaco To: Mathieu Desnoyers , Peter Zijlstra , Ingo Molnar , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Juri Lelli , Gabriele Monaco Subject: [PATCH v4 0/3] sched: Restructure task_mm_cid_work for predictability Date: Mon, 13 Jan 2025 08:42:28 +0100 Message-ID: <20250113074231.61638-1-gmonaco@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Queue-Id: F2B854000D X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 97mu36fhossjiubrn3qbzpbist3iqkcn X-HE-Tag: 1736754173-127910 X-HE-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5u5OKa8O8ELhkVUDQgOarj7hq6VeoW1ITPvmFJSHAyPOnsqJZt9Mi9JE3yh0W2r9H7TSkO5SNIXAJtBdxpyrHK9LVZJtzSx6zruTu9cIGscBr3DoZaG8ejfXpfgSdtFz9NgSzl5liFQMKIGZGbfiMp7nlcE/Ql5MdbRIzs0dLSVssmkklDF1wonYFcDI8cuC6fGrOpuI9aay4tBNavd/pOYQA5iHqokglQs547LBo4SaKflcwaLwUhEEagJFG/jQgyAV7Sq5yCvgez0Y3JXdPS9tx2Bv5LYMZl8Nc= 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: List-Subscribe: List-Unsubscribe: This patchset moves the task_mm_cid_work to a preemptible and migratable context. This reduces the impact of this task to the scheduling latency of real time tasks. The change makes the recurrence of the task a bit more predictable. We also add optimisation and fixes to make sure the task_mm_cid_work works as intended. The behaviour causing latency was introduced in commit 223baf9d17f2 ("sched: Fix performance regression introduced by mm_cid") which introduced a task work tied to the scheduler tick. That approach presents two possible issues: * the task work runs before returning to user and causes, in fact, a scheduling latency (with order of magnitude significant in PREEMPT_RT) * periodic tasks with short runtime are less likely to run during the tick, hence they might not run the task work at all Patch 1 allows the mm_cids to be actually compacted when a process reduces its number of threads, which was not the case since the same mm_cids were reused to improve cache locality, more details in [3]. Patch 2 contains the main changes, removing the task_work on the scheduler tick and using a delayed_work instead. Additionally, we terminate the call immediately if we see that no mm_cid is actually active, which could happen on processes sleeping for long time or which exited but whose mm has not been freed yet. Patch 3 adds a selftest to validate the functionality of the task_mm_cid_work (i.e. to compact the mm_cids). The test fails if patch 1 is not applied and is flaky without patch 2. We expect it to always pass with the entire patchset applied. Changes since V3 [1]: * Fixes on the selftest * Minor style issues in comments and indentation * Use of perror where possible * Add a barrier to align threads execution * Improve test failure and error handling Changes since V2 [2]: * Change the order of the patches * Merge patches changing the main delayed_work logic * Improved self-test to spawn 1 less thread and use the main one instead Changes since V1 [3]: * Re-arm the delayed_work at each invocation * Cancel the work synchronously at mmdrop * Remove next scan fields and completely rely on the delayed_work * Shrink mm_cid allocation with nr thread/affinity (Mathieu Desnoyers) * Add self test Overhead comparison in [3] [1] - https://lore.kernel.org/linux-kernel/20241216130909.240042-1-gmonaco@redhat.com/ [2] - https://lore.kernel.org/linux-kernel/20241213095407.271357-1-gmonaco@redhat.com/ [3] - https://lore.kernel.org/linux-kernel/20241205083110.180134-2-gmonaco@redhat.com/ Gabriele Monaco (2): sched: Move task_mm_cid_work to mm delayed work rseq/selftests: Add test for mm_cid compaction Mathieu Desnoyers (1): sched: Compact RSEQ concurrency IDs with reduced threads and affinity include/linux/mm_types.h | 23 ++- include/linux/sched.h | 1 - kernel/sched/core.c | 66 +------ kernel/sched/sched.h | 32 ++- tools/testing/selftests/rseq/.gitignore | 1 + tools/testing/selftests/rseq/Makefile | 2 +- .../selftests/rseq/mm_cid_compaction_test.c | 185 ++++++++++++++++++ 7 files changed, 231 insertions(+), 79 deletions(-) create mode 100644 tools/testing/selftests/rseq/mm_cid_compaction_test.c base-commit: 5bc55a333a2f7316b58edc7573e8e893f7acb532