From patchwork Wed Aug 17 08:14:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 12945626 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 E2189C25B08 for ; Wed, 17 Aug 2022 08:14:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8FF78D0002; Wed, 17 Aug 2022 04:14:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E40FE8D0001; Wed, 17 Aug 2022 04:14:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D06D18D0002; Wed, 17 Aug 2022 04:14:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C1BFC8D0001 for ; Wed, 17 Aug 2022 04:14:24 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 97CAA407C1 for ; Wed, 17 Aug 2022 08:14:24 +0000 (UTC) X-FDA: 79808372448.20.7F13DFE Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf03.hostedemail.com (Postfix) with ESMTP id 5D63A201D4 for ; Wed, 17 Aug 2022 08:14:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660724063; x=1692260063; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=YgX2oWE22h0TBxS39QPKndxaK0c4rvOlVqgEtY2CsnQ=; b=YLmXo494AA39yaHU81GU4MfFANe0zkLgMCg2kPAtLrv8ojEdFHb3Lv7n vHKIgZQk9YpvCVRX0EtrCDm/IpRdYYFD6H3hrhZ5Ud2rZ/bNsot12nj9X D+8zjFgrO0N+TNJl/dzyN68ao/nEvU6xJ0p7veVrMPT28iPn58OAOjcds Wyu6Z2xEKW9P3x1kK8Gl4i2dVaoBq1LFc7HYxedHP9R5ewKamszzQpO6p Gua4CffRgV8aNayHIk37eiWGJPfGPZMd/t4lhK0/D+cZUIs52Cyp17h0o /C3uWu1QNN5S0g1DANZe8U/h1z0p/BKbDH61mdeRQ4SoRDXrfVfPoxVoq Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10441"; a="293710764" X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="293710764" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2022 01:14:21 -0700 X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="583668065" Received: from yhuang6-mobl1.sh.intel.com ([10.238.6.172]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2022 01:14:18 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Huang, Ying" , Baolin Wang , Zi Yan , Yang Shi , Oscar Salvador Subject: [PATCH -V3 0/8] migrate_pages(): fix several bugs in error path Date: Wed, 17 Aug 2022 16:14:00 +0800 Message-Id: <20220817081408.513338-1-ying.huang@intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=YLmXo494; spf=pass (imf03.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660724064; a=rsa-sha256; cv=none; b=TtUrTQ4P7hrserC7fMB1pP4mdToJRNcSJjmPy2Fj82+sH1ho3GgYpwvluksVUvthM6BrtT EpdYJG3EG3nEjK77GavqjfLmBPsaSfNtruAkL1f/G3dDznsLGEWXu+rbMB2DjMf6CZRMLP m2D3yGWYIqL5Eh6196qQ0WNbUPf9W7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660724064; 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=7MmZTUgstPfBAeG8Lzr8leKe1d5fpHbqnHQhGxDLCuU=; b=alujxXbdDxB8vD3JZWuPAkYEuhJrluA6S//qgI6gTey6NduJSdMaOj6nHXjERuIFCNBPXc 95a9MuRB2hCUXdTkRO8hfkjja4Lea1moi/CstHUyyeZ+ZYx6LWAkNFYylpcsGBuIs5T3qM lPHpF9ixjEuGttoAEM3H+tI6tqt24Iw= X-Stat-Signature: szpeccq6rmckb1gh5c3mx351ye96jnef X-Rspamd-Queue-Id: 5D63A201D4 X-Rspamd-Server: rspam08 Authentication-Results: imf03.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=YLmXo494; spf=pass (imf03.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: X-HE-Tag: 1660724063-49908 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: From: "Huang, Ying" During review the code of migrate_pages() and build a test program for it. Several bugs in error path are identified and fixed in this series. Most patches are tested via - Apply error-inject.patch in Linux kernel - Compile test-migrate.c (with -lnuma) - Test with test-migrate.sh error-inject.patch, test-migrate.c, and test-migrate.sh are as below. It turns out that error injection is an important tool to fix bugs in error path. Changes: v3: - Rebased on mm-unstable (20220816) - Added Baolin's patch to avoid retry 10 times for fail to migrate THP subpages v2: - Rebased on v5.19-rc5 - Addressed some comments from Baolin, Thanks! - Added reviewed-by tags Best Regards, Huang, Ying ------------------------- error-inject.patch ------------------------- From 295ea21204f3f025a041fe39c68a2eaec8313c68 Mon Sep 17 00:00:00 2001 From: Huang Ying Date: Tue, 21 Jun 2022 11:08:30 +0800 Subject: [PATCH] migrate_pages: error inject --- mm/migrate.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 399904015d23..87d47064ec6c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -337,6 +337,42 @@ void pmd_migration_entry_wait(struct mm_struct *mm, pmd_t *pmd) } #endif +#define EI_MP_ENOSYS 0x0001 +#define EI_MP_THP_ENOMEM 0x0002 +#define EI_MP_NP_ENOMEM 0x0004 +#define EI_MP_EAGAIN 0x0008 +#define EI_MP_EOTHER 0x0010 +#define EI_MP_NOSPLIT 0x0020 +#define EI_MP_SPLIT_FAIL 0x0040 +#define EI_MP_EAGAIN_PERM 0x0080 +#define EI_MP_EBUSY 0x0100 + +static unsigned int ei_migrate_pages; + +module_param(ei_migrate_pages, uint, 0644); + +static bool ei_thp_migration_supported(void) +{ + if (ei_migrate_pages & EI_MP_ENOSYS) + return false; + else + return thp_migration_supported(); +} + +static int ei_trylock_page(struct page *page) +{ + if (ei_migrate_pages & EI_MP_EAGAIN) + return 0; + return trylock_page(page); +} + +static int ei_split_huge_page_to_list(struct page *page, struct list_head *list) +{ + if (ei_migrate_pages & EI_MP_SPLIT_FAIL) + return -EBUSY; + return split_huge_page_to_list(page, list); +} + static int expected_page_refs(struct address_space *mapping, struct page *page) { int expected_count = 1; @@ -368,6 +404,9 @@ int folio_migrate_mapping(struct address_space *mapping, if (folio_ref_count(folio) != expected_count) return -EAGAIN; + if (ei_migrate_pages & EI_MP_EAGAIN_PERM) + return -EAGAIN; + /* No turning back from here */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; @@ -929,7 +968,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage, struct anon_vma *anon_vma = NULL; bool is_lru = !__PageMovable(page); - if (!trylock_page(page)) { + if (!ei_trylock_page(page)) { if (!force || mode == MIGRATE_ASYNC) goto out; @@ -952,6 +991,11 @@ static int __unmap_and_move(struct page *page, struct page *newpage, lock_page(page); } + if (ei_migrate_pages & EI_MP_EBUSY) { + rc = -EBUSY; + goto out_unlock; + } + if (PageWriteback(page)) { /* * Only in the case of a full synchronous migration is it @@ -1086,7 +1130,7 @@ static int unmap_and_move(new_page_t get_new_page, int rc = MIGRATEPAGE_SUCCESS; struct page *newpage = NULL; - if (!thp_migration_supported() && PageTransHuge(page)) + if (!ei_thp_migration_supported() && PageTransHuge(page)) return -ENOSYS; if (page_count(page) == 1) { @@ -1102,6 +1146,11 @@ static int unmap_and_move(new_page_t get_new_page, goto out; } + if ((ei_migrate_pages & EI_MP_THP_ENOMEM) && PageTransHuge(page)) + return -ENOMEM; + if ((ei_migrate_pages & EI_MP_NP_ENOMEM) && !PageTransHuge(page)) + return -ENOMEM; + newpage = get_new_page(page, private); if (!newpage) return -ENOMEM; @@ -1305,7 +1354,7 @@ static inline int try_split_thp(struct page *page, struct list_head *split_pages int rc; lock_page(page); - rc = split_huge_page_to_list(page, split_pages); + rc = ei_split_huge_page_to_list(page, split_pages); unlock_page(page); return rc; @@ -1358,6 +1407,9 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, bool nosplit = (reason == MR_NUMA_MISPLACED); bool no_subpage_counting = false; + if (ei_migrate_pages & EI_MP_NOSPLIT) + nosplit = true; + trace_mm_migrate_pages_start(mode, reason); thp_subpage_migration: