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; } From patchwork Fri Aug 9 10:31:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Jain X-Patchwork-Id: 13758681 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 7BF08C52D7C for ; Fri, 9 Aug 2024 10:32:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0EA656B0098; Fri, 9 Aug 2024 06:32:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09ACF6B009A; Fri, 9 Aug 2024 06:32:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA4846B009C; Fri, 9 Aug 2024 06:32:37 -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 CFEBA6B0098 for ; Fri, 9 Aug 2024 06:32:37 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8A4FC1A0C8B for ; Fri, 9 Aug 2024 10:32:37 +0000 (UTC) X-FDA: 82432343154.03.ECB4EB9 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP id E324880019 for ; Fri, 9 Aug 2024 10:32:35 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.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=1723199491; 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=sFXhh648nndX5eKnDKkGLK3WTPnegS5ZW4xE+814tng=; b=GH8HfHsBsvYHF6GMw3ortpLLNWO9hw9YtBiOinxQc4jH8UrxMP8f7PW75GFtSCF0hoFxQ1 7cSTLzKAVuEg+B6IVNV6w+YMGI5LLCnTS3b/82m1SZEJ7SZji2ukRR5/0/n7Ca2Ruwvy63 jnzxrEmdAo66klu5cogHMRxRok7KmD4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723199491; a=rsa-sha256; cv=none; b=U0sktI9WAvadFrHpFDzGaenM84mzkSyKFULIr9fL+aLLt0gEiECXeZjhnZilZbK1kHyl+W +K6/gB/MiSGPdeai2JH91nMEz+WNZ4tBIgaPxXnjy+ajCFHi+MX3AF65sNyyJmNd58Z4dN TbV9+Npjl26XurkJrT7lrkqmVDtlpVU= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.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 BC37613D5; Fri, 9 Aug 2024 03:33:00 -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 A366D3F766; Fri, 9 Aug 2024 03:32:21 -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 2/2] selftests/mm: Do not fail test for a single migration failure Date: Fri, 9 Aug 2024 16:01:29 +0530 Message-Id: <20240809103129.365029-3-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-Queue-Id: E324880019 X-Stat-Signature: en6ttphujssp7dyzz7wiw9czkjrsts6c X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1723199555-61037 X-HE-Meta: U2FsdGVkX1+Z/4kBw5y8Gr4QhzJQaVDozsRl8Mh/Me4FnMD5PHrS2QlKmUTVvgv8Qi6EysbjWAO8OBoqITtXSd2KUQADFSWa+QgbHvUiBMq1R9hX9oaY12oXBUVt0W9jWoq3S7Hkm9ZbgwvfdixbQTOsu1NN4n7gIqBsBe04mPZAZoUDVONlpvla+yIP/WHxmP9tGuDmFftgLO75Eg/mhefbwl+wMSkDK95BlSATb2CeWK4bqYmCFlYsJI2+lB0yPtZ//0RozGqPEegqWn7tlqQOBK3iA10w/cfWlLWf0KNPYHmw3Q0yUF3H+JGkrN0rwapP+k1SaxO2ZZ6q3pRVJdi4+mppWyJiQJZeDqh288XcZ+KnfsMJR23m0JnpKFNYpH2o+dMTgVCvrkgWlGW0GX7oDVaTFMxZVwhwhJsBkAGQmeQQE1ziqlIAzujU1LrUxVCo/bOFJV6cyfz9sugG4xUNBikW5/1m8rYBMknAM9bhKDcSZ9BViCLvSIfcQJH6ECp/qIInAtd+xrX08Lcpx82wqOSGtCF8oMRQj8dhakzGhKN/xmmcCDnygYMQes0iYlc5v0jCL0KU0AjFIXAjrQN/0iLSWTiEc1HOCf9f4kMyk+ox0E6Hgo6gZm8+he1rG2zECwY8Tyeq6bJRqxV0otaO+dhTgnSjRAQbGkPAVU8CesKlVn/hYPKis4aMCleoDfDQBpy8cVfowxBLBesVhNuTk6Z/sm/rO0jM2ZUEyHJfOagAtqhtkWKvqszy9x83czjEBsd+RdMGhgzdEXvmpzi7sJrrbr23tXpVItTYNfRthRR0ZacEGKIPIliDEg31E+Dbi1bTVylICiNVZXTSeHFOzLY+gCHiILxepb+VmxFn+577La1JkhvXFqEDF9Rn1n7cmGv72kVfQxGkMYhcO1rufh71Sxez3kQe2o5MH2xq9Z46xjwTSxeGOXgKTvVS4PRhJF1NEQ7QbScSNEs auQB7TzG ueZhxlMIITaSgxM1WDD6FUCy6QMPeQGUsDOv5aU4Wq80KyAwg86C+IvSyrB2QC3NF8Gh+cF9KyEj8wd85t8Ai49oxIeQX//qWKAA0PXqmy8jpjNEWUcohng1AtV9QhmSHo3eaur1wrviytV0R5k2aznFfyh1iwTEjNH4qac/Bw+eVR1CAIqsaPrPdXFYCLhVNlApBlCA5GfZWaJ8= 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: Do not fail the test for just a single instance of migration failure, since migration is a best-effort service. Signed-off-by: Dev Jain Suggested-by: David Hildenbrand Reviewed-by: Ryan Roberts Tested-by: Ryan Roberts --- tools/testing/selftests/mm/migration.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftests/mm/migration.c index 6908569ef406..64bcbb7151cf 100644 --- a/tools/testing/selftests/mm/migration.c +++ b/tools/testing/selftests/mm/migration.c @@ -15,10 +15,10 @@ #include #include -#define TWOMEG (2<<20) -#define RUNTIME (20) - -#define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1))) +#define TWOMEG (2<<20) +#define RUNTIME (20) +#define MAX_RETRIES 100 +#define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1))) FIXTURE(migration) { @@ -65,6 +65,7 @@ int migrate(uint64_t *ptr, int n1, int n2) int ret, tmp; int status = 0; struct timespec ts1, ts2; + int failures = 0; if (clock_gettime(CLOCK_MONOTONIC, &ts1)) return -1; @@ -79,13 +80,17 @@ int migrate(uint64_t *ptr, int n1, int n2) ret = move_pages(0, 1, (void **) &ptr, &n2, &status, MPOL_MF_MOVE_ALL); if (ret) { - if (ret > 0) + if (ret > 0) { + /* Migration is best effort; try again */ + if (++failures < MAX_RETRIES) + continue; printf("Didn't migrate %d pages\n", ret); + } else perror("Couldn't migrate pages"); return -2; } - + failures = 0; tmp = n2; n2 = n1; n1 = tmp;