From patchwork Thu Jun 20 15:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinliang Zheng X-Patchwork-Id: 13705720 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 C89E2C27C79 for ; Thu, 20 Jun 2024 15:28:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B9818D00BC; Thu, 20 Jun 2024 11:28:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 168988D00A7; Thu, 20 Jun 2024 11:28:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 057498D00BC; Thu, 20 Jun 2024 11:28:05 -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 DBADA8D00A7 for ; Thu, 20 Jun 2024 11:28:05 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6CB3D14011C for ; Thu, 20 Jun 2024 15:28:05 +0000 (UTC) X-FDA: 82251647730.26.E84BD06 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf20.hostedemail.com (Postfix) with ESMTP id 223681C0020 for ; Thu, 20 Jun 2024 15:28:01 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="CoIjR+E/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of alexjlzheng@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=alexjlzheng@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718897275; a=rsa-sha256; cv=none; b=sIdTD7uNgW8RNk5CzpDrbC6e9YVrynrA98DTrk52dSw53hNZZA1bDfH8xGDjnIJUSzfYtQ EC1OPVZKB+VFAl2ounLf96GBZsO9h7oVeVuOESfsDIa8ZjnAghfpqwhPhN1g8vPknwzT5T vqEc3i0y5JJbkZlbxkTqjJWrN4Otiww= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="CoIjR+E/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of alexjlzheng@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=alexjlzheng@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718897275; 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=h8UoW2gDsuC/WTMxd+s3ovig9iw85Gd97u2Lu7zIm6Y=; b=Hw4VGVu2po/ZbaoJbc3NjBcpgVMJv633xx6k6tTeWtJGAaJRRsFjVWMyArW7H2O2RvDV2b iihUD6Ei1XzoxFKz7fRE495t4/RrWsJqbJh83x6oyNzzbXhOgJ4wjX4BFcahwLyNwfadci w/AwFxydeNAUr8sAM54qnnSkF8TPWRs= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f44b45d6abso8401045ad.0 for ; Thu, 20 Jun 2024 08:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718897281; x=1719502081; 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=h8UoW2gDsuC/WTMxd+s3ovig9iw85Gd97u2Lu7zIm6Y=; b=CoIjR+E/+AOeJ4WC+9fFwox2KgzeMia6f01zNYe+M+7DckOXlgLEJitVQpOwtj6teh Y6Z2CNmhYgN/QVhRmYBuj1uucywEta0yYC3CMT6l8aMWOBsE+rnmcG7vhs+D7TeWZ1ha KkxNQwkvKQyTJ2dHqSKu12nsP+fTgFBJ43UZ77ECLnw/tE0+msw/1YzbXU46ELFoO1fN jivY4JvxFWIf+aHtmiV4pmGALrwL0oo9eXjIFSDQf0+Yxvj5Me69u7neQrfa8iQ1hoPx oc0bfANSqFuKAbd0gF9TZjy2mCmjGDTuIrrEqvhJkxzeSZE+NZh/Skbct0jPONtitWxm RzCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718897281; x=1719502081; 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=h8UoW2gDsuC/WTMxd+s3ovig9iw85Gd97u2Lu7zIm6Y=; b=J2P6ZEmYAvW0PaZkcXfD1trmI+bYXpGJ+jQ+ubjAH56Hf1JIjo84oUO/Rogb8F41aT HE+yywToGQafIBGommKwp3Ek7PC1Q4AD+OaY1Z7Qs8nTGk2QrOLxRXsmkKpU8pb1QkTd AL+efPy9Ne6EXjvvHH/QvJSdxnkb2CtjQ28DP1MRbvGbYLCQ2FZg67hUc8HEv3Qtsg59 1rfZs13NfRsTQFNawj1cIM6vdAyfsrxhoVKz7B2yWpW9/ZVRqq3nID6oMrcLRtM+CQ/8 No43ZAaTswS67OKC0XA5+Ceze/cXhw3yKA3mXokYw5tLBlHsHwLBVSVLeFSb5aQRZFAY 07Tw== X-Forwarded-Encrypted: i=1; AJvYcCV9QfeKcoWKaDYmOsbi1pw++MjLPWse8Hdy8RbdQ+hQ2HzqwJ3TNZHJsMD1Xpw1rr/24HBSplNMEI7vhlftvwZsrsY= X-Gm-Message-State: AOJu0YylVXCLn+YuQKrXmwGecmoqMKJ5XNzQGSvSA3g9dmADo5iEw8EJ ls4HN2jTkvJ/yLa5dT6fUYwc6lAxSG/WOCqtKldyelG3lLUVTslrA5S5W5po X-Google-Smtp-Source: AGHT+IH2PX87ma1FbvOUxHxU3rIiaC1u7ZoE6yOCEBnMvfmo46HNm3smP9a+wJ28x9vaE7WsL1i28g== X-Received: by 2002:a17:902:e543:b0:1f7:187f:cb5b with SMTP id d9443c01a7336-1f9aa46612bmr57851965ad.64.1718897280851; Thu, 20 Jun 2024 08:28:00 -0700 (PDT) Received: from localhost.localdomain ([43.132.141.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f86e1d82aesm113382685ad.253.2024.06.20.08.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 08:28:00 -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 v2] mm: optimize the redundant loop of mm_update_next_owner() Date: Thu, 20 Jun 2024 23:27:45 +0800 Message-Id: <20240620152744.4038983-1-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspamd-Queue-Id: 223681C0020 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 1tjnnq9soj6q5d4nmjyi4t67zujphoid X-HE-Tag: 1718897281-83401 X-HE-Meta: U2FsdGVkX1+Fzp/OJEBrT0hcx2jmo6eABfgz8wIvbhbH8PIQEzqbiEePAV7WuNmxBUI4+1sUJacEMUPn5usYiALOvO5NYkdMRzdinpWJqQubQ10tSJDTbZDcq5lHi/z5/mEw/WuihjO00hxa9CD2cf3F+Ytx8yMVhz3NCKQpL4oceQ/HYm4QrbY17yH3XcovQOKWuzsd0IIFKyGqitlu0JrAPSasU7WAaCJvXPaq4pk7532TUO/lbzIh5BnsPFjOouVu+ImfIlTpKUB3PVdq38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iDbV8Yv34d4M6A= 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_next_owner() 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 Acked-by: Michal Hocko --- Changelog: V2: Fix mm_update_owner_next() to mm_update_next_owner() in comment --- 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) {