From mboxrd@z Thu Jan 1 00:00:00 1970 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 E900CC27C79 for ; Thu, 20 Jun 2024 17:32:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BFB86B02E0; Thu, 20 Jun 2024 13:32:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76E126B02E2; Thu, 20 Jun 2024 13:32:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6361E6B02E8; Thu, 20 Jun 2024 13:32:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3F4856B02E0 for ; Thu, 20 Jun 2024 13:32:07 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D4B711403FB for ; Thu, 20 Jun 2024 17:32:06 +0000 (UTC) X-FDA: 82251960252.18.D48D013 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id E8ED2160025 for ; Thu, 20 Jun 2024 17:32:04 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=U2C20ZG1; spf=pass (imf08.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@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=1718904718; 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:in-reply-to:references:references:dkim-signature; bh=Pbk4cgzT1VG7tOZDuYBYOA1Nhbg3doz5Ktn2A96vAeU=; b=qvmh87S5sGLBrt18YVuZ0bRMZ+L0SxHhRd6HwYjfeB4P8R4/jgNEzjfSIZ2PlFi87dAcrk 9EiID/mpgxMLR+ZpuEFxqMJC1JgxvjcieAT6bGnIuV3lehHT1NxKqD4RP19XuP36uFchL4 dcsskspXttoG8Se3FeVYoq1FPUmEtos= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=U2C20ZG1; spf=pass (imf08.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718904718; a=rsa-sha256; cv=none; b=iMsL15+1YSFQqufb/Khbd8lMCx4BZdJo8Ii1Eh9QTv7XPuuEHRqljFBKFqRbecYYYtVmru 9Q5/2bx24r8NmaViMItYdrxoxUBmYobWPoAqE1GLj00ifoGurVbHICKJK1S2luWvcir1Tl 2fwy/74Qj6NzN/ZwTEgaD1yiG3J8Yes= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718904724; 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: in-reply-to:in-reply-to:references:references; bh=Pbk4cgzT1VG7tOZDuYBYOA1Nhbg3doz5Ktn2A96vAeU=; b=U2C20ZG1HIIiW4AbCtZzGD/URiLX8D7RY6ObrK3MROE2moZVo/8uT/ch0ix2hKnzYoI5Gs BFZBqAJaa1ffz2WIkN2kHWlXBLsqQhzFToKPWclqzrVydSQFDByWzCbbI8ziLDq4FrBt8t ttFG5+dyPxSD14wRvA+Ogo0BWPEe+kQ= Received: from mx-prod-mc-02.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-627-nIihs8qsPvyqSOk7Jx1A5Q-1; Thu, 20 Jun 2024 13:32:00 -0400 X-MC-Unique: nIihs8qsPvyqSOk7Jx1A5Q-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C4A25195608C; Thu, 20 Jun 2024 17:31:57 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.39]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id F2CF9300022B; Thu, 20 Jun 2024 17:31:52 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 20 Jun 2024 19:30:25 +0200 (CEST) Date: Thu, 20 Jun 2024 19:30:19 +0200 From: Oleg Nesterov To: alexjlzheng@gmail.com, Michal Hocko , "Eric W. Biederman" Cc: akpm@linux-foundation.org, brauner@kernel.org, axboe@kernel.dk, tandersen@netflix.com, willy@infradead.org, mjguzik@gmail.com, alexjlzheng@tencent.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] mm: optimize the redundant loop of mm_update_next_owner() Message-ID: <20240620172958.GA2058@redhat.com> References: <20240620152744.4038983-1-alexjlzheng@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240620152744.4038983-1-alexjlzheng@tencent.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Stat-Signature: ht48h6oftxz7qscgf8j9e61fkkuspkoe X-Rspam-User: X-Rspamd-Queue-Id: E8ED2160025 X-Rspamd-Server: rspam02 X-HE-Tag: 1718904724-266077 X-HE-Meta: U2FsdGVkX1+hcoAaq+MgG3brCzPQ7AtzlSqWwTiE1CLyatNMYIkCPV1UAspoYeD3juHBvADNCOSu6rnFoRs7T+dtNos6h/sRUWKmbmeXVWzCHhWPB54bbgWDdYxQCcCXKLCAPMLgM4LN0fFsAOsgcqk1g+ua4xtjQkZCHEJuS9VRriO33+T1//mI+nV4bt1iYDjwqqZMzp65AKx4UqIPGCLn0LX8GpZpfogXmZLlDfvloqOe5PfcOPqaVb3v1gzNhHZo/vr9b3gE5UiUZzQy6buH32uJ9at8zwsg5eOVqUtiJbRYFUihd6UwzTUZR9iBlBFzSaZyh2f6orq/Rr7EC0KhSSWzVLoYKSJRHPlG+XYii7mM5Y27qgjaN/VDFFLZkIqsWYteQT5ORWpQuzq81CvIyRzInkLaqJyf/WZsdK1L7yDb/T9ljVopeVjAAP4yTWgDRI7JzyaCxz869TN2OFeEgu4UrWziIlMoI/asZ7lsB7T4eGpemU8l1uPA/n1stBRketjgIgBOQegaxxzWa2238XGZ0LE9KhqfRNa4iwOffrlBZlA/oe4XT8+vI1kY8Wy9iL1rZG/C4xi+NSX98JlpCX2hMgPYyE6rQX4J6ud5qie9C1r52NL5mBoyZLVZPbnGWSEM4HDG369AWAAnJengWOz7tyKs0VYFjhoI7Nm9SsP8B8/6KSNnJsMnNaNDWSg+FOKYJejYFMj6Qo6anqDLzxoQMkXTJmGutPx8sVkHZhPoVq4QPh9r+lI/xQ4lbGEY+E323G520MkmHZEidLXa/1UrzuLtiQqrbxtAd2jeh3BlXNq2f73uM2GaaIJh9AecvnvluuE8jRKVaf/o/YkEn1jC7Tck/HI18eDEhjuVAv6HUTFxM3nG5KRscars2fiMardsyIbJcl8erWbrH+2fwLOsaDzuiuP79kqoAroeJLBS8lGqcxXKzNvQdD6+H3rn92mI9u8OzRxMwDp dKVqejw3 Es9zQnIO7EIeHxhBXQMWvTe1uJdxHpW9PNmnzn9bipzDyjQDbLKI6D0RQ8gF6VPxqsl63NQ6DD4ZW/C5NHGXMcXxmQA+8YiIaViqCUNwUCpZFSD8xVS8QIJMOgF0NIul4ns0pNG1wBWfLiQWFB7Mvzs0VOB0CAkhR8ttG5fKw9KVPjfm1598dLTHb3/7fpXvqdwo77CSHvCEFIgxj3waqyrbK/YWNU8ztMncHYKSaPemxO67jimXH2UZNmGvWYwP2he6mUthRkJ2sZBrOZxZYhqSh+DwLh42fL9FZgVPRgJGQQJDvrg0vLYI2y93K62WHaB5lpU9bbcGoB2BLYY9TY6Psn1rTm5phDNmKXna9LyFAovs= 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: Can't review, I forgot everything about mm_update_next_owner(). So I am sorry for the noise I am going to add, feel free to ignore. Just in case, I see nothing wrong in this patch. On 06/20, alexjlzheng@gmail.com wrote: > > 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. But this patch won't help if (say) ptrace_access_vm() sleeps while for_each_process() tries to find another owner, right? > @@ -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; I think this deserves a comment to explain that this is optimization for the case we race with the pending mmput(). mm_update_next_owner() checks mm_users at the start. And. Can we drop tasklist and use rcu_read_lock() before for_each_process? Yes, this will probably need more changes even if possible... Or even better. Can't we finally kill mm_update_next_owner() and turn the ugly mm->owner into mm->mem_cgroup ? Michal, Eric, iirc you had the patch(es) which do this? Oleg.