From patchwork Fri Aug 9 10:31:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Jain X-Patchwork-Id: 13758680 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 ABB62C52D71 for ; Fri, 9 Aug 2024 10:32:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E5F96B0095; Fri, 9 Aug 2024 06:32:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2962F6B0098; Fri, 9 Aug 2024 06:32:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15E3F6B009A; Fri, 9 Aug 2024 06:32:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id EBA2D6B0095 for ; Fri, 9 Aug 2024 06:32:23 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9F347A0D3E for ; Fri, 9 Aug 2024 10:32:23 +0000 (UTC) X-FDA: 82432342566.20.F48260F Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf21.hostedemail.com (Postfix) with ESMTP id 075801C000B for ; Fri, 9 Aug 2024 10:32:21 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf21.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723199468; 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:in-reply-to:references:references; bh=MXl+EL6fG1M8U2ghMklL5faCNP7TYg3ihRGw43xYU9M=; b=e89cPTiBOnBJTpVsjM0ltM5y6ot8Sx8LC3Xugl7OH9ai01Ju0vN0jeUa3V79PhosMIu70M ovGrLVelukcWsk/uWVbF3m2+qUej/Ad1LqEPG/kozLAZTlcgVkprKFNp/jkI+DWuCl1NT1 BcTKmh1yXNfTP8ycB4YVbaSrsCPHf1M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723199468; a=rsa-sha256; cv=none; b=uLf07f30OAgRCcJQqKvX/zJb0286q/+bIco2qvA20/67iDEqG7KODaj02Qo0hk/T915OWy JjdckIip8yJQG12ZsbaFlBWtN/AWwO9N/vO07KuoeF9FpzN/WlXDTz+l89jm/gKsSKilYX thAHQjlEmu2OoA0yJNqPJOm0YaU9+Rg= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf21.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D281E13D5; Fri, 9 Aug 2024 03:32:46 -0700 (PDT) Received: from e116581.blr.arm.com (e116581.arm.com [10.162.42.15]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2551F3F766; Fri, 9 Aug 2024 03:31:58 -0700 (PDT) From: Dev Jain To: akpm@linux-foundation.org, shuah@kernel.org, david@redhat.com, willy@infradead.org Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, osalvador@suse.de, baolin.wang@linux.alibaba.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, ioworker0@gmail.com, gshan@redhat.com, mark.rutland@arm.com, kirill.shutemov@linux.intel.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, broonie@kernel.org, mgorman@techsingularity.net, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Dev Jain Subject: [PATCH 1/2] mm: Retry migration earlier upon refcount mismatch Date: Fri, 9 Aug 2024 16:01:28 +0530 Message-Id: <20240809103129.365029-2-dev.jain@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809103129.365029-1-dev.jain@arm.com> References: <20240809103129.365029-1-dev.jain@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 075801C000B X-Stat-Signature: t3qhtqadyn5y7mekzruqxofxmdjxrn7g X-Rspam-User: X-HE-Tag: 1723199541-650844 X-HE-Meta: U2FsdGVkX1/+Q1OzPommOb/9FINNkwBQg9uq629kmrhZVAG6Z3Dvmpxy1fAfwrBDZIKpxuHNHXw1aIsstqdjdhoaBhpUtjrrkCg55RpYNRfTYZuFMjtPi2jm8kA8lsseNeYjqQfFD78Cle+gxT+H/C+L+m1YNMNb6La8xhfXSjWpJiygkVf/zjhHe16eyViGkB6Mp22AJ3WijhcJtt9/QAEW0gRvLz9j4MOKxmjfjfTS/wL+0Wgr9lCR5jd+10fpdwaNfI0X7Xgl7bdLEp4znJRwpWCGcrO1+gSrl0WgBKcYGMASNInW+5xBA4/lcq94//sE6pmddZ0EkuTMrcWX2CvfSOZe1cuknhtMaeJYgjEwWR0N41ZPI+w3Shc4kB1I224PagrHNlFtgeDyLs3ycKzxPK0BOzGY4XngZ0VywprZXgzCrOnjD4eN+TYwXf5BXNq78eDpSu6pynBS80Yx9BgZsPS4yW+xumyTbtGQx4saflLnaNlqCncaAFqAPAhbZfkN+giuZeFuhZeEcGuYz9iqjc9KJJxAfpIEU4jodcpQ2yafBE7HWT+65pN/OING7sKXWYbc3dlIJ0rXfCH0uZm8uc3ftaob/gkl60wew3oJPoEjmKiiKzR7LcSngPUn1QzFd2Ke3iGqPGfKAFoaYlRvFf7qJ8Uplrn4g0DMlKy/5re6RpmIjCyGmfoJF4MiVoP3WTlMOuRLBHQE4m6JrAOTSfgMEnwgntiCh5afXDCNKSpHvuohoEfnb8WdZw70rf5AXXdDzNug52BKiMZvkaYkSkCtrOhcmkjKbdGxUDF89gbHr++Wnu8Z0nWp+e7V0/UlrD9R9qMlFRsvYlK+OZUPB0pTgaa9EZRLfNoWKAt1oLBYK+imbCevA3+xF58RnHDnGOYYoMc9GUzP8u0YxayKzb738C/OBW12RTMXL9zoq22PYb61yMK35R0Z28z6A/y7F0OHhOMxMergBey nGhsoTU1 VSCT8NaVmXlZTfsKmzcNJnIQOLhsBbH6so5M2y39eQKQAeIylWMSZeHaV8ChSc5/eyQRNrS6UySGOFhNdil+HjISivlZsiFipbt5ncC3VKW9VKQ+z7lHmCMWXxVbMYkt7NDOwqvXDiBwtyNcix4IqPFf41A== 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: As already being done in __migrate_folio(), wherein we backoff if the folio refcount is wrong, make this check during the unmapping phase, upon the failure of which, the original state of the PTEs will be restored and the folio lock will be dropped via migrate_folio_undo_src(), any racing thread will make progress and migration will be retried. Signed-off-by: Dev Jain --- mm/migrate.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index e7296c0fb5d5..477acf996951 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1250,6 +1250,15 @@ static int migrate_folio_unmap(new_folio_t get_new_folio, } if (!folio_mapped(src)) { + /* + * Someone may have changed the refcount and maybe sleeping + * on the folio lock. In case of refcount mismatch, bail out, + * let the system make progress and retry. + */ + struct address_space *mapping = folio_mapping(src); + + if (folio_ref_count(src) != folio_expected_refs(mapping, src)) + goto out; __migrate_folio_record(dst, old_page_state, anon_vma); return MIGRATEPAGE_UNMAP; }