From patchwork Thu Jun 20 12:21:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinliang Zheng X-Patchwork-Id: 13705310 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 A0D60C27C79 for ; Thu, 20 Jun 2024 12:21:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA8198D00B2; Thu, 20 Jun 2024 08:21:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A56178D00AF; Thu, 20 Jun 2024 08:21:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F6C08D00B2; Thu, 20 Jun 2024 08:21:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 714B98D00AF for ; Thu, 20 Jun 2024 08:21:46 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C83CD41A71 for ; Thu, 20 Jun 2024 12:21:45 +0000 (UTC) X-FDA: 82251178170.24.668DA97 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf19.hostedemail.com (Postfix) with ESMTP id ED1691A0015 for ; Thu, 20 Jun 2024 12:21:42 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aFGmSRIr; spf=pass (imf19.hostedemail.com: domain of alexjlzheng@gmail.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=alexjlzheng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718886093; 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=XBS1AMhLDhTumK33C3908n6EvwlZ7BmKQIgA6mDuKXI=; b=N0UQPXjutWgo4QLEnV3iNIXZzso+x42gAgk4+rGLhL2pwsRAezPb3gB3uU7Nr2l2tWybL0 WYLNSJw71jTbXSRwQHJY74ftNbHxtb0EoS9LQXhQXaxEx1hkzZ46DLfT+UVkvkiRgHH2um WCWyAIyKgOH7CjBfibHQY6iw9rxM2vE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718886093; a=rsa-sha256; cv=none; b=sbbjWcp9305N9Qub9fXJDIpN4x0IJzN6cpERtdpdYCAqD9pcwi2zEO9u3zp1T13dp7f2rp JTVpDmBbaq2QERxKUlJ6ffZtUFTE2UCol2A0ipDgQsI4s5YzDOgbFFw+1b0KjcwvGUG7Xk LCYPY7C+BiDM9J5jLYk8cDB68qaK4Kk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aFGmSRIr; spf=pass (imf19.hostedemail.com: domain of alexjlzheng@gmail.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=alexjlzheng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-704090c11easo665225b3a.2 for ; Thu, 20 Jun 2024 05:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718886102; x=1719490902; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XBS1AMhLDhTumK33C3908n6EvwlZ7BmKQIgA6mDuKXI=; b=aFGmSRIrJzAJ4TW27bcA8YwnycOepZn2qJwpGHy4CYx5WB30sT6ZlE73SnBPNJqV8m g0Hen8s0uUEkoeqIy2ukmwDzdi0wqBxxkF6rYdReNXfesF5H+jv+V6QjKc9SeYP9cl/5 4rvguyXsv0U4HZtVk/F0c0OqEDnw2cR1bcdWa67O0shLf1g95gbwK4qpyYAvGy0lFiOD CK/4ufgyPZYk5XNPKSl2ihaeU6N/3Ir11F16ga4Po0XF0SkwIOQK/jf7Y2DHUcL89YNa 6/nynj216ziOE0t+6s8qbsB57ouG/qn3lYzZH/adMAuZC+2OCHh9NbClDXD4EfJGieP/ GKKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718886102; x=1719490902; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XBS1AMhLDhTumK33C3908n6EvwlZ7BmKQIgA6mDuKXI=; b=izum4iTBeUM1dTyi4HhROmbSRS5bhahomdFxyZHV6NJr+krFV7o75khyfjtXHkT/M/ ucsOmDPgC1lQSdeXvyozJx8iSOoMWbvGcis+jp6P8bvQJWv2TlRTMVFHaA3lVcGRYGPk Hf3Wk3dPlZ5L5PHoG/ylxhTP6Otv0Q23AoejKnMwJpEs5+RXtesZH/f8h07NbAnEOXNZ yfsEZgP/EtutJ7ZUxa9r47e1JaYItT9nBDNegAXUMuvyTpNEB9dydvxTdaMp++F4YCq4 MdxW7pA7IScu83owEINGC1ZpeEsRCNAdOqAlBzhSp1/6qNINR6hupZM/B8eElXwQdAqW h6Vw== X-Forwarded-Encrypted: i=1; AJvYcCVtElcGm+mSHc314EmkAtwwSNLCTlkMoQ0uT8Gi2xFlbS/BceQJbTgfc0p+29hp3yHhcS3W63FJHBYD1HqXLlEIYf8= X-Gm-Message-State: AOJu0YwMnTqrcpFvmOGi6oID9wYIio5ZW9ywwUvVAGhmNQOEsQUQgbay qmGSw5tr8zx5gBEK/Q/vMW993Y6mgrODWYuUcqbmxKDjTlTKYGOi X-Google-Smtp-Source: AGHT+IEZoRkDMCj3Y9QFI9+Shy3ZbsxWCR1UBXpiYlnmNJQ6tE2CzaTopi+87JJ6Cu3vTiMjQddHvw== X-Received: by 2002:a05:6a00:124f:b0:706:3ba3:a192 with SMTP id d2e1a72fcca58-7063ba3a6c5mr3335763b3a.22.1718886101652; Thu, 20 Jun 2024 05:21:41 -0700 (PDT) Received: from localhost.localdomain ([14.22.11.163]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb6dfcasm12688725b3a.172.2024.06.20.05.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 05:21:41 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: akpm@linux-foundation.org, brauner@kernel.org Cc: axboe@kernel.dk, oleg@redhat.com, tandersen@netflix.com, willy@infradead.org, mjguzik@gmail.com, alexjlzheng@tencent.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm: optimize the redundant loop of mm_update_owner_next() Date: Thu, 20 Jun 2024 20:21:24 +0800 Message-Id: <20240620122123.3877432-1-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Stat-Signature: y8nq9d46oy6p1whpzn6k378prnptz44o X-Rspamd-Queue-Id: ED1691A0015 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718886102-948684 X-HE-Meta: U2FsdGVkX19ygg637vDBhe3FtUx5fIr4k8p+lRDlaTZ92WnYHeY0YT7U5JBlDcNsRuk7pMMB+fLiOAnUWfkZp1gkjj+JPUh3vWw2SzMz3ZOV+yW/mNingBtCybTe/0EyiZ57TcnBgBhMkmEB1Occ2Ok++yIZfsZCucDt2qnrK9kLb+bpcBmjBsh9P3MXb2ZUjRj5eoinew1h4ExTGwDgOBoEzDMxiDNXGarTDKdbX6nlt4f6rpQkHLpiyxdc+vs8GsfGXN1BU2RfxcuAPyiGFkIwFjkVg1y1+xj0BJpXP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THVxEXVW5VvSIZgzBMYkc= 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: From: Jinliang Zheng When mm_update_owner_next() is racing with swapoff (try_to_unuse()) or /proc or ptrace or page migration (get_task_mm()), it is impossible to find an appropriate task_struct in the loop whose mm_struct is the same as the target mm_struct. If the above race condition is combined with the stress-ng-zombie and stress-ng-dup tests, such a long loop can easily cause a Hard Lockup in write_lock_irq() for tasklist_lock. Recognize this situation in advance and exit early. Signed-off-by: Jinliang Zheng --- kernel/exit.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/exit.c b/kernel/exit.c index f95a2c1338a8..81fcee45d630 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -484,6 +484,8 @@ void mm_update_next_owner(struct mm_struct *mm) * Search through everything else, we should not get here often. */ for_each_process(g) { + if (atomic_read(&mm->mm_users) <= 1) + break; if (g->flags & PF_KTHREAD) continue; for_each_thread(g, c) {