From patchwork Mon Feb 6 06:33:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13129349 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 3B499C636D3 for ; Mon, 6 Feb 2023 06:33:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDD136B0075; Mon, 6 Feb 2023 01:33:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C65846B0078; Mon, 6 Feb 2023 01:33:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B06526B007B; Mon, 6 Feb 2023 01:33:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A22946B0075 for ; Mon, 6 Feb 2023 01:33:36 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7436FC0ACF for ; Mon, 6 Feb 2023 06:33:36 +0000 (UTC) X-FDA: 80435900832.12.1D98AE4 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf25.hostedemail.com (Postfix) with ESMTP id 5D6CFA0013 for ; Mon, 6 Feb 2023 06:33:34 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=eT9fUBcz; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675665214; 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:dkim-signature; bh=6K6EPnmkM3a5UOufl46/EB5E1x0OF9PgE2F47wj3TE0=; b=fjjfZVdv9vYtc4rhQatWFyhykQFUN/Pc2XQBWRHgQv18lcCXu3BkNKgeDrJvz/1l+ouT6y wOW7lrFyWsV04y/yRVe0LZvcCjGWTwWPzniu3pXVd+ImsE8CuI/1nzeOP+Axd+XxLk1MbJ rTkJn5OqiXZRvLGWcbgmoEpsmOFRJcI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=eT9fUBcz; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 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=1675665214; a=rsa-sha256; cv=none; b=NKoQ3sIqJxh5DYMsHFduF8TDGv0swnq9fW/se+u8aZzLExV46kfK7uKUSjBMlgzLeBgY4z PJtfskT6hzsXsPBTWh9+eFAak1z5TDLlCQQ5MR2BOCrhzD30dJD4H1+href0hs4FamTnkH QrOilzHBPRVHwqjBsTtZC4dxU0kVoBs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675665214; x=1707201214; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fpqcNpPynLsFmyeQ5s3gi4KQwt0xUU5cyFiW/AFXtXc=; b=eT9fUBcz4XDC3HJtixkuvmX4IYI5z87tJpJV50zOug95yGIUkmPUfoMU JeQAYDZO1I0OB66i0FjpqORBF6eIhmbQ/RtD8k5XtBJrWstHTPzQngdFg YsApcXm0N5/wiPY8oYoM9mA8reObSypdjhJVJgfmEBiSPuAiHjAJi+/k9 sKcXlUiF+YacDc8nP6+JDa8xi8HddqnD0hW5JMBr3XXfhzVElh3X2vIvR 6xLg4U7AehexXEugEH9WvjOzOBBHYB027KY9CWa0Dp+3AuVJJjqWt7g/6 gIlM3RnI0g+ju+gOhD0Ar7XTRM3Gkd2/SnhAnPTkQRXgteeJzEMXGETsN g==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330432625" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330432625" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:33 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="659744625" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="659744625" Received: from baoyumen-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.smartont.net) ([10.255.30.227]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:28 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Alistair Popple , Zi Yan , Baolin Wang , Yang Shi , Oscar Salvador , Matthew Wilcox , Bharata B Rao , haoxin , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH -v4 1/9] migrate_pages: organize stats with struct migrate_pages_stats Date: Mon, 6 Feb 2023 14:33:05 +0800 Message-Id: <20230206063313.635011-2-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> References: <20230206063313.635011-1-ying.huang@intel.com> MIME-Version: 1.0 X-Stat-Signature: s45fgu4765d97it47obszqdsogpafa54 X-Rspam-User: X-Rspamd-Queue-Id: 5D6CFA0013 X-Rspamd-Server: rspam06 X-HE-Tag: 1675665214-188836 X-HE-Meta: U2FsdGVkX18BZH0H66lBJ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9+wfs0b+JkO2Fp3Zyv7NasssJjxr1bKePXm0Bg/zxSACi+ML2tRC4l235iXe8TG0xjUred4NoSqr9hsXFZZcQGZVn3lTcnnPdWcKLNmk5ejncKh2WCTuQFtZhzmVc6W2zsZ5JL8vxbG8JXHNH/ea+RQmrPYfWQORiYGH+kCctPm6LnChFmhCI6EvFK9nRLD0z/y/XJPKVZmBLvlILr+ZVEdv6l4CeXLSKnZ08cRqTOKgHs5GGT52znIs8pIKvlEm+JM1F9obOeafYB41NasP3GxGvO3/8xlTbJE8emBCo7djmaNhhC2iShCPnR4C8LJYTTLxEyipru2nINc0vzdJyRdLpisvTOu2lKEaP8RQy74bjL9Uxi62QdPjxOmuCDoBuUVVC+vymSwfQeZGxox+nbQfulwrm7WCRSi69sqfCeB6vS1nAH179RJk2+nrTjkIuEyyZ2YNY2iqY35fRxu0w+itQ/C/TFI0UObyMVSt9+efjRdcfjKz50dPeOvDiaXtmXk9aowdmucvxSgNTCsEHLFcOlnUublakfnHRJQOHAmMwccpubnOwPAbtQ== 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: Define struct migrate_pages_stats to organize the various statistics in migrate_pages(). This makes it easier to collect and consume the statistics in multiple functions. This will be needed in the following patches in the series. Signed-off-by: "Huang, Ying" Reviewed-by: Alistair Popple Reviewed-by: Zi Yan Reviewed-by: Baolin Wang Cc: Yang Shi Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: haoxin Cc: Minchan Kim Cc: Mike Kravetz Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Xin Hao --- mm/migrate.c | 60 +++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index a4d3fc65085f..ef388a9e4747 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1396,6 +1396,16 @@ static inline int try_split_folio(struct folio *folio, struct list_head *split_f return rc; } +struct migrate_pages_stats { + int nr_succeeded; /* Normal and large folios migrated successfully, in + units of base pages */ + int nr_failed_pages; /* Normal and large folios failed to be migrated, in + units of base pages. Untried folios aren't counted */ + int nr_thp_succeeded; /* THP migrated successfully */ + int nr_thp_failed; /* THP failed to be migrated */ + int nr_thp_split; /* THP split before migrating */ +}; + /* * migrate_pages - migrate the folios specified in a list, to the free folios * supplied as the target for the page migration @@ -1430,13 +1440,8 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, int large_retry = 1; int thp_retry = 1; int nr_failed = 0; - int nr_failed_pages = 0; int nr_retry_pages = 0; - int nr_succeeded = 0; - int nr_thp_succeeded = 0; int nr_large_failed = 0; - int nr_thp_failed = 0; - int nr_thp_split = 0; int pass = 0; bool is_large = false; bool is_thp = false; @@ -1446,9 +1451,11 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, LIST_HEAD(split_folios); bool nosplit = (reason == MR_NUMA_MISPLACED); bool no_split_folio_counting = false; + struct migrate_pages_stats stats; trace_mm_migrate_pages_start(mode, reason); + memset(&stats, 0, sizeof(stats)); split_folio_migration: for (pass = 0; pass < 10 && (retry || large_retry); pass++) { retry = 0; @@ -1502,9 +1509,9 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, /* Large folio migration is unsupported */ if (is_large) { nr_large_failed++; - nr_thp_failed += is_thp; + stats.nr_thp_failed += is_thp; if (!try_split_folio(folio, &split_folios)) { - nr_thp_split += is_thp; + stats.nr_thp_split += is_thp; break; } /* Hugetlb migration is unsupported */ @@ -1512,7 +1519,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, nr_failed++; } - nr_failed_pages += nr_pages; + stats.nr_failed_pages += nr_pages; list_move_tail(&folio->lru, &ret_folios); break; case -ENOMEM: @@ -1522,13 +1529,13 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, */ if (is_large) { nr_large_failed++; - nr_thp_failed += is_thp; + stats.nr_thp_failed += is_thp; /* Large folio NUMA faulting doesn't split to retry. */ if (!nosplit) { int ret = try_split_folio(folio, &split_folios); if (!ret) { - nr_thp_split += is_thp; + stats.nr_thp_split += is_thp; break; } else if (reason == MR_LONGTERM_PIN && ret == -EAGAIN) { @@ -1546,7 +1553,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, nr_failed++; } - nr_failed_pages += nr_pages + nr_retry_pages; + stats.nr_failed_pages += nr_pages + nr_retry_pages; /* * There might be some split folios of fail-to-migrate large * folios left in split_folios list. Move them back to migration @@ -1556,7 +1563,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, list_splice_init(&split_folios, from); /* nr_failed isn't updated for not used */ nr_large_failed += large_retry; - nr_thp_failed += thp_retry; + stats.nr_thp_failed += thp_retry; goto out; case -EAGAIN: if (is_large) { @@ -1568,8 +1575,8 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, nr_retry_pages += nr_pages; break; case MIGRATEPAGE_SUCCESS: - nr_succeeded += nr_pages; - nr_thp_succeeded += is_thp; + stats.nr_succeeded += nr_pages; + stats.nr_thp_succeeded += is_thp; break; default: /* @@ -1580,20 +1587,20 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, */ if (is_large) { nr_large_failed++; - nr_thp_failed += is_thp; + stats.nr_thp_failed += is_thp; } else if (!no_split_folio_counting) { nr_failed++; } - nr_failed_pages += nr_pages; + stats.nr_failed_pages += nr_pages; break; } } } nr_failed += retry; nr_large_failed += large_retry; - nr_thp_failed += thp_retry; - nr_failed_pages += nr_retry_pages; + stats.nr_thp_failed += thp_retry; + stats.nr_failed_pages += nr_retry_pages; /* * Try to migrate split folios of fail-to-migrate large folios, no * nr_failed counting in this round, since all split folios of a @@ -1626,16 +1633,17 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, if (list_empty(from)) rc = 0; - count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded); - count_vm_events(PGMIGRATE_FAIL, nr_failed_pages); - count_vm_events(THP_MIGRATION_SUCCESS, nr_thp_succeeded); - count_vm_events(THP_MIGRATION_FAIL, nr_thp_failed); - count_vm_events(THP_MIGRATION_SPLIT, nr_thp_split); - trace_mm_migrate_pages(nr_succeeded, nr_failed_pages, nr_thp_succeeded, - nr_thp_failed, nr_thp_split, mode, reason); + count_vm_events(PGMIGRATE_SUCCESS, stats.nr_succeeded); + count_vm_events(PGMIGRATE_FAIL, stats.nr_failed_pages); + count_vm_events(THP_MIGRATION_SUCCESS, stats.nr_thp_succeeded); + count_vm_events(THP_MIGRATION_FAIL, stats.nr_thp_failed); + count_vm_events(THP_MIGRATION_SPLIT, stats.nr_thp_split); + trace_mm_migrate_pages(stats.nr_succeeded, stats.nr_failed_pages, + stats.nr_thp_succeeded, stats.nr_thp_failed, + stats.nr_thp_split, mode, reason); if (ret_succeeded) - *ret_succeeded = nr_succeeded; + *ret_succeeded = stats.nr_succeeded; return rc; } From patchwork Mon Feb 6 06:33:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13129350 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 7E830C61DA4 for ; Mon, 6 Feb 2023 06:33:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 207996B0078; Mon, 6 Feb 2023 01:33:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B6A26B007B; Mon, 6 Feb 2023 01:33:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07EB06B007D; Mon, 6 Feb 2023 01:33:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EF3CC6B0078 for ; Mon, 6 Feb 2023 01:33:41 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BD546A0B28 for ; Mon, 6 Feb 2023 06:33:41 +0000 (UTC) X-FDA: 80435901042.11.921B3D5 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf11.hostedemail.com (Postfix) with ESMTP id B70EF4000F for ; Mon, 6 Feb 2023 06:33:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=klqjbF7D; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675665220; 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:dkim-signature; bh=02JKGbEaGFAGY6s9QDlNdYBEm6eKLQIiyyUvNtu5xDY=; b=COttKayBHBP4tav5g3ukbhyt/sICA7rmJkN4BTSS8cEP9P3v+XhRs09nAX6ZestAr8dCN4 c/MDw08F+VqWRrpNiQwUjXn3K9N4RtIm+uqEOoxFPnnWlGhYQ0AB41so2PpsTU0KIJNofn zEpao2FT/u3ij2kA3AnNvaM6FqKhCi4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=klqjbF7D; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675665220; a=rsa-sha256; cv=none; b=SJhCcuRtIQ5iPD22PLMMnjSMST8F2a6WWuBS5Tt05gQVDLIevsXKKakLsp+/nOHEGbWEED JosxwciHH90N7Jw6sWlBZVg4GeWU8EzH1GrJCApmILUNY0n8AkE85mfC412EoKMzl9pPZE baAEsgrRsO0Sfd/Kat6y5266yfcG6Vc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675665219; x=1707201219; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w1FXftS5jBdzB2pFVikf3bBSxICJXTUbCvcdqa4yc7Q=; b=klqjbF7D31Zz38xcjeUGQ56HVQ/4RebHebcfyTwAw00MAy1prOglUAxE mHSeTlPnv4bKla+N1Ea+g7CejpAbSUtTH75/DfaT2trXs8j5++R0wFLLj 804xSpkaWghB8hN2a9m7VHeZ5y3NY1Rc8jEW9ykLuEOF+4x2Y7klSqE8O ueIQazSPGANTrYpNEuecMppr80v/IBSF9ePJcoqZezJ+Ai6Au63Ei/wOT UqOg4K1vEI8MNTsmMQ8oEpJ8xG4kHIa3mULjLuvZGjFt725rc83BqPIDi FYcXjj7lj5lLDGg9RmEc/DaAdM299hnMOpUMpPemYQ/y6w3OPbsr1fIHq Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330432642" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330432642" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:38 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="659744640" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="659744640" Received: from baoyumen-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.smartont.net) ([10.255.30.227]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:33 -0800 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 , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH -v4 2/9] migrate_pages: separate hugetlb folios migration Date: Mon, 6 Feb 2023 14:33:06 +0800 Message-Id: <20230206063313.635011-3-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> References: <20230206063313.635011-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B70EF4000F X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 3t7uch867sjiq6z4ppjr9c349w8ikzkq X-HE-Tag: 1675665219-644946 X-HE-Meta: U2FsdGVkX1+YlVB8vlyYPF0wsYSpeInenanUxdFAd5hNY0p8cUL7xrxrTQ+h7KnbOIF/W/GZmWbVQKnCauKslzn148Th0BMLS2kg8avPTIiiPS9TGtsKOmWcscmv0a2htetDm14EwkPKFmd7YuKAQdpSr/QYatR8cQ08UKxGyzwtSqlL0FPIUutCm6MfxksU00Y+H2z82/SIsTbu7lzXip6FQ3tLterUnsanaOOojUtMoS5fC7vFuJri+0+s9kBQ0vEMLfBijz1kchxROkKbC/XYrsizUIJtvcC7rH3lAQK7LqM+XUhJ20mFHNQRICjwptHkImdnskF4vXqzR9g2ruYTHaqeolZN2z79Z41iJpmtw89f39avbe/NhJJSAcxhhHn8r5tjyWJce6qkL+1ojN/+dNV66uDwPt4tQQI+YuxHyBGsnKePhX7Z5AFvNsDPc98RAFq0OWTVSKMEiPvYHzHYG2sHcpvC9D10PtRzeMtTpdGtOlaz+uX1I7359TPR5A3bLjnJgm+KQXfyYp2iNBTuxnPwAHIcmOoxnyCeFZjXvhoPT9E/t7de2ELxWh6JQcRbdqv0tAhQsdEmmX1CLTNcwCdjXeAnok3iMA/RFmikQcI4EJmFNJWysakB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.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is a preparation patch to batch the folio unmapping and moving for the non-hugetlb folios. Based on that we can batch the TLB shootdown during the folio migration and make it possible to use some hardware accelerator for the folio copying. In this patch the hugetlb folios and non-hugetlb folios migration is separated in migrate_pages() to make it easy to change the non-hugetlb folios migration implementation. Signed-off-by: "Huang, Ying" Reviewed-by: Baolin Wang Cc: Zi Yan Cc: Yang Shi Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: Alistair Popple Cc: haoxin Cc: Minchan Kim Cc: Mike Kravetz Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Xin Hao --- mm/migrate.c | 141 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 119 insertions(+), 22 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index ef388a9e4747..be7f37523463 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1396,6 +1396,8 @@ static inline int try_split_folio(struct folio *folio, struct list_head *split_f return rc; } +#define NR_MAX_MIGRATE_PAGES_RETRY 10 + struct migrate_pages_stats { int nr_succeeded; /* Normal and large folios migrated successfully, in units of base pages */ @@ -1406,6 +1408,95 @@ struct migrate_pages_stats { int nr_thp_split; /* THP split before migrating */ }; +/* + * Returns the number of hugetlb folios that were not migrated, or an error code + * after NR_MAX_MIGRATE_PAGES_RETRY attempts or if no hugetlb folios are movable + * any more because the list has become empty or no retryable hugetlb folios + * exist any more. It is caller's responsibility to call putback_movable_pages() + * only if ret != 0. + */ +static int migrate_hugetlbs(struct list_head *from, new_page_t get_new_page, + free_page_t put_new_page, unsigned long private, + enum migrate_mode mode, int reason, + struct migrate_pages_stats *stats, + struct list_head *ret_folios) +{ + int retry = 1; + int nr_failed = 0; + int nr_retry_pages = 0; + int pass = 0; + struct folio *folio, *folio2; + int rc, nr_pages; + + for (pass = 0; pass < NR_MAX_MIGRATE_PAGES_RETRY && retry; pass++) { + retry = 0; + nr_retry_pages = 0; + + list_for_each_entry_safe(folio, folio2, from, lru) { + if (!folio_test_hugetlb(folio)) + continue; + + nr_pages = folio_nr_pages(folio); + + cond_resched(); + + rc = unmap_and_move_huge_page(get_new_page, + put_new_page, private, + &folio->page, pass > 2, mode, + reason, ret_folios); + /* + * The rules are: + * Success: hugetlb folio will be put back + * -EAGAIN: stay on the from list + * -ENOMEM: stay on the from list + * -ENOSYS: stay on the from list + * Other errno: put on ret_folios list + */ + switch(rc) { + case -ENOSYS: + /* Hugetlb migration is unsupported */ + nr_failed++; + stats->nr_failed_pages += nr_pages; + list_move_tail(&folio->lru, ret_folios); + break; + case -ENOMEM: + /* + * When memory is low, don't bother to try to migrate + * other folios, just exit. + */ + stats->nr_failed_pages += nr_pages + nr_retry_pages; + return -ENOMEM; + case -EAGAIN: + retry++; + nr_retry_pages += nr_pages; + break; + case MIGRATEPAGE_SUCCESS: + stats->nr_succeeded += nr_pages; + break; + default: + /* + * Permanent failure (-EBUSY, etc.): + * unlike -EAGAIN case, the failed folio is + * removed from migration folio list and not + * retried in the next outer loop. + */ + nr_failed++; + stats->nr_failed_pages += nr_pages; + break; + } + } + } + /* + * nr_failed is number of hugetlb folios failed to be migrated. After + * NR_MAX_MIGRATE_PAGES_RETRY attempts, give up and count retried hugetlb + * folios as failed. + */ + nr_failed += retry; + stats->nr_failed_pages += nr_retry_pages; + + return nr_failed; +} + /* * migrate_pages - migrate the folios specified in a list, to the free folios * supplied as the target for the page migration @@ -1422,10 +1513,10 @@ struct migrate_pages_stats { * @ret_succeeded: Set to the number of folios migrated successfully if * the caller passes a non-NULL pointer. * - * The function returns after 10 attempts or if no folios are movable any more - * because the list has become empty or no retryable folios exist any more. - * It is caller's responsibility to call putback_movable_pages() to return folios - * to the LRU or free list only if ret != 0. + * The function returns after NR_MAX_MIGRATE_PAGES_RETRY attempts or if no folios + * are movable any more because the list has become empty or no retryable folios + * exist any more. It is caller's responsibility to call putback_movable_pages() + * only if ret != 0. * * Returns the number of {normal folio, large folio, hugetlb} that were not * migrated, or an error code. The number of large folio splits will be @@ -1439,7 +1530,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, int retry = 1; int large_retry = 1; int thp_retry = 1; - int nr_failed = 0; + int nr_failed; int nr_retry_pages = 0; int nr_large_failed = 0; int pass = 0; @@ -1456,38 +1547,45 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, trace_mm_migrate_pages_start(mode, reason); memset(&stats, 0, sizeof(stats)); + rc = migrate_hugetlbs(from, get_new_page, put_new_page, private, mode, reason, + &stats, &ret_folios); + if (rc < 0) + goto out; + nr_failed = rc; + split_folio_migration: - for (pass = 0; pass < 10 && (retry || large_retry); pass++) { + for (pass = 0; + pass < NR_MAX_MIGRATE_PAGES_RETRY && (retry || large_retry); + pass++) { retry = 0; large_retry = 0; thp_retry = 0; nr_retry_pages = 0; list_for_each_entry_safe(folio, folio2, from, lru) { + /* Retried hugetlb folios will be kept in list */ + if (folio_test_hugetlb(folio)) { + list_move_tail(&folio->lru, &ret_folios); + continue; + } + /* * Large folio statistics is based on the source large * folio. Capture required information that might get * lost during migration. */ - is_large = folio_test_large(folio) && !folio_test_hugetlb(folio); + is_large = folio_test_large(folio); is_thp = is_large && folio_test_pmd_mappable(folio); nr_pages = folio_nr_pages(folio); + cond_resched(); - if (folio_test_hugetlb(folio)) - rc = unmap_and_move_huge_page(get_new_page, - put_new_page, private, - &folio->page, pass > 2, mode, - reason, - &ret_folios); - else - rc = unmap_and_move(get_new_page, put_new_page, - private, folio, pass > 2, mode, - reason, &ret_folios); + rc = unmap_and_move(get_new_page, put_new_page, + private, folio, pass > 2, mode, + reason, &ret_folios); /* * The rules are: - * Success: non hugetlb folio will be freed, hugetlb - * folio will be put back + * Success: folio will be freed * -EAGAIN: stay on the from list * -ENOMEM: stay on the from list * -ENOSYS: stay on the from list @@ -1514,7 +1612,6 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, stats.nr_thp_split += is_thp; break; } - /* Hugetlb migration is unsupported */ } else if (!no_split_folio_counting) { nr_failed++; } @@ -1608,8 +1705,8 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, */ if (!list_empty(&split_folios)) { /* - * Move non-migrated folios (after 10 retries) to ret_folios - * to avoid migrating them again. + * Move non-migrated folios (after NR_MAX_MIGRATE_PAGES_RETRY + * retries) to ret_folios to avoid migrating them again. */ list_splice_init(from, &ret_folios); list_splice_init(&split_folios, from); From patchwork Mon Feb 6 06:33:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13129353 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 692C8C61DA4 for ; Mon, 6 Feb 2023 06:33:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 058B96B007B; Mon, 6 Feb 2023 01:33:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 009576B007D; Mon, 6 Feb 2023 01:33:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E13346B007E; Mon, 6 Feb 2023 01:33:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D208C6B007B for ; Mon, 6 Feb 2023 01:33:46 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A8C08120B45 for ; Mon, 6 Feb 2023 06:33:46 +0000 (UTC) X-FDA: 80435901252.19.4E01E0C Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf11.hostedemail.com (Postfix) with ESMTP id 8DB0640007 for ; Mon, 6 Feb 2023 06:33:44 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=OmygnWGC; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675665224; 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:dkim-signature; bh=IHHfelv6rK82PGXo2GlZw0b94js0SQCXvYQmoU8xQ1c=; b=ODHqTUKOfQ2fMu/oOgmovaZN9U8q6uwTv5ENlDjtbrHsrNTEkwHbiHRAOx0u2PM/cCk/H6 mt6Gqo7nolbYO6k3In9wSO+ykziODZZIlMdYPyBgyWQzxCJsD/hmTxSFlqwhRwIZ2r80Im Vvu8HEqYjnjUX7vYA9GGDkeuBiRcASo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=OmygnWGC; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675665224; a=rsa-sha256; cv=none; b=n+CwbnVZKJuQxzBISTuPPcP284VF92h9EX8jmMW7fggBecUiY/J+WRiM2XmvbwI4nBe3gp 9AdymQv0CKkXRKtmDTTn5vgphV667UGGJkRQfYaPeBhwKgjbCYUZVYgG4q9mKQqjjG9njR pMw2iPVQ4bERcX7k84VB5hL/WWJvZ7c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675665224; x=1707201224; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E+ufcmCoz9FarLVwteZ2cUHMggV+b5Nv4b96FC4hzk8=; b=OmygnWGCHz2iRjFJp66fUvGEJ3x5LguCuMSlLk+CNiCs4/a4Dgalo0OB T/BVT078FsGdyRN+a/hLIh1FqLTNJBGwSyJF3D9MDsNG45jCcFfGeCQ9Q ukW+GumWSMVT7VmyuWx1jkdRsN+Le9h4k0RfAKF7dKMFoQqAU71Ui75F5 Jtr2NtQD/cGlTOk8gqoDntpTlARVokGpQshiPvWZQFANPbTlfZ0XJwGaV JeaJSIUigV2aPcnRep0lZA9OW8xT5NUI3/P/yI4wS8HJJWFbkKV0Ey2Kx iH87Z8XxHshBcM12yQnmSU/evK5HnV77fnLKdY9NLQDu9topcRuyCH7u3 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330432664" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330432664" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:43 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="659744666" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="659744666" Received: from baoyumen-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.smartont.net) ([10.255.30.227]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:38 -0800 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 , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH -v4 3/9] migrate_pages: restrict number of pages to migrate in batch Date: Mon, 6 Feb 2023 14:33:07 +0800 Message-Id: <20230206063313.635011-4-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> References: <20230206063313.635011-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8DB0640007 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: etcjonq9yt6jodq9zwua6zsxcreeu7zq X-HE-Tag: 1675665224-904278 X-HE-Meta: U2FsdGVkX18G4RKyvIbeSQkHQmYcIyoydZdsdzVZg4YS74tDvmH04gUWN9TjZkm8ikk5Oqp6TumMiiQiNxGed5FQXekMezCK6peW/QW8AqWVd3sTao2pO+62JfenG20zY310LIlUnj/RqsEriaOG4YKzL/+zqV7QPtymS6syUCsJOzN+sPvZLB8ZSrgigWEuK9aGfBuefRoFV9GEqaGoZ5vO/IUinPmg0gZQ77lUHNeWgxn9xXkJNJ+1KI8WbCwNvLJhm2n/CDyaEDVHbWfaQ12flzF8MnLazb67a4VmQ1OwOi7JZvu6xfvM8Z+VNBSASVDhKZ/mLrF5W84mCccC2jWmqDDAzjIkFLlkNKWwhT7q5e/uqMu93i2ZMVu6PtLjRUcSwKnRBj68pax2BFTsj9wn9+/XyjkaWmuXhzi68xoBsPDg2fnbuR8E/WcnsJTmpBVHoI2H5dJF2sFb34DZy3+3uD2qjpjbz468eNLpBg8RV6i3d63MvRPr5Z0YL+hWtg/fHjBVR0bwl0eL5sO+JRC7dWASaIfHu1OFVMCPN0NbJ+KiS4AgYeUNBgu9jdlM+V553nFYnhS7L7mRaDNCptrzDTjH9BxxDvyZujpvXvpMWwMIoc/bEQzII4bThG8kQAZo4t5OwYq7oGKuUE1i67x4Ok5tpswycKUI8Bioft57uNSynR0lyiuaU0yD5Dxlb5oKmeiGXQq5YVdLC30BrxipJdOLAr156xgt+KhwvQxC1MNRhFZgdp0VePw9KI/8Tl53YYSX/xhbYy077Z5KYCu69ER5QpEvLdmPC6Vpnrm0HZn5Jb+ViQrpQU5Jhtdwc3W3OAxy02hQDU3gS5rzg1CUG+VQxo037n/p4YFj646xu0TLRNsWSHNlP337uk1q07zdKiey2PqADL7lF0bXGdjrVpMNZLDvQGhb5n37z1Fxc3PRVySRF/joL16RCRprraHbN2cQHaogFCA27qb URsniqI9 L5s+7wMDmFTLflp5iegXhpmRA9ee7/7ODmNvhzoTFcK8quLT0pS73pU7O64HtgS15RRBwWhj9h33jgD4mYntj1Ic9+Iu8MpF1On3HQhhTUvekdYi2y4i3I7fyOsJInLwplDK+fC1BCXWShTvZiakkZrPQmjzVs8/X4wrD4b/MVT7PiQm3+vn71SrWdBAHXhBx0xcfT0rUxiT4SVipVJNhVbcJueWMWAsUv3lFMaQouKizDkOdRukkckQODvqDoy/TiCNniGfcI32kMm3FrE3TfTfoMtmizdpryPY1CQQYmXDt2/QmqJSTpWGu9fUDx3luS2WFLf1Fz54/6rO/e2M60kSBmLNIrIQzXNHuo8CzEjUe1Imp/qKba1k0jgduvjAnm3DsJWbWUCICCLpqzn3ThRUdBQKf9WVqMjNPAkFmM2IGkB8gLp3mqdc/0BhFbK5KmOyl/YXW3Ei3FQ4isf4E9E0VDhQbVMhFngFAwedWm9Vcx0Lhrx854pxvQdNb28PHTBzsCldjKx2BAzvQWJAV1qrqWBaq7KtbdFged4+7BN8BlfB0tB1EqzNyuLHBQ+XvHKyUcNcEi8pvj0ljRFpz+UGRK2BRBJMMIh5wqjM8i8c9C8O6glnkQUwvhbJ8EF+SjFE4SDygx7/tqu5dcy1PzMjlI8NRcNAVvQoG 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: This is a preparation patch to batch the folio unmapping and moving for non-hugetlb folios. If we had batched the folio unmapping, all folios to be migrated would be unmapped before copying the contents and flags of the folios. If the folios that were passed to migrate_pages() were too many in unit of pages, the execution of the processes would be stopped for too long time, thus too long latency. For example, migrate_pages() syscall will call migrate_pages() with all folios of a process. To avoid this possible issue, in this patch, we restrict the number of pages to be migrated to be no more than HPAGE_PMD_NR. That is, the influence is at the same level of THP migration. Signed-off-by: "Huang, Ying" Reviewed-by: Baolin Wang Cc: Zi Yan Cc: Yang Shi Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: Alistair Popple Cc: haoxin Cc: Minchan Kim Cc: Mike Kravetz Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Xin Hao --- mm/migrate.c | 174 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 106 insertions(+), 68 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index be7f37523463..9a667039c34c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1396,6 +1396,11 @@ static inline int try_split_folio(struct folio *folio, struct list_head *split_f return rc; } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#define NR_MAX_BATCHED_MIGRATION HPAGE_PMD_NR +#else +#define NR_MAX_BATCHED_MIGRATION 512 +#endif #define NR_MAX_MIGRATE_PAGES_RETRY 10 struct migrate_pages_stats { @@ -1497,40 +1502,15 @@ static int migrate_hugetlbs(struct list_head *from, new_page_t get_new_page, return nr_failed; } -/* - * migrate_pages - migrate the folios specified in a list, to the free folios - * supplied as the target for the page migration - * - * @from: The list of folios to be migrated. - * @get_new_page: The function used to allocate free folios to be used - * as the target of the folio migration. - * @put_new_page: The function used to free target folios if migration - * fails, or NULL if no special handling is necessary. - * @private: Private data to be passed on to get_new_page() - * @mode: The migration mode that specifies the constraints for - * folio migration, if any. - * @reason: The reason for folio migration. - * @ret_succeeded: Set to the number of folios migrated successfully if - * the caller passes a non-NULL pointer. - * - * The function returns after NR_MAX_MIGRATE_PAGES_RETRY attempts or if no folios - * are movable any more because the list has become empty or no retryable folios - * exist any more. It is caller's responsibility to call putback_movable_pages() - * only if ret != 0. - * - * Returns the number of {normal folio, large folio, hugetlb} that were not - * migrated, or an error code. The number of large folio splits will be - * considered as the number of non-migrated large folio, no matter how many - * split folios of the large folio are migrated successfully. - */ -int migrate_pages(struct list_head *from, new_page_t get_new_page, +static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, free_page_t put_new_page, unsigned long private, - enum migrate_mode mode, int reason, unsigned int *ret_succeeded) + enum migrate_mode mode, int reason, struct list_head *ret_folios, + struct migrate_pages_stats *stats) { int retry = 1; int large_retry = 1; int thp_retry = 1; - int nr_failed; + int nr_failed = 0; int nr_retry_pages = 0; int nr_large_failed = 0; int pass = 0; @@ -1538,20 +1518,9 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, bool is_thp = false; struct folio *folio, *folio2; int rc, nr_pages; - LIST_HEAD(ret_folios); LIST_HEAD(split_folios); bool nosplit = (reason == MR_NUMA_MISPLACED); bool no_split_folio_counting = false; - struct migrate_pages_stats stats; - - trace_mm_migrate_pages_start(mode, reason); - - memset(&stats, 0, sizeof(stats)); - rc = migrate_hugetlbs(from, get_new_page, put_new_page, private, mode, reason, - &stats, &ret_folios); - if (rc < 0) - goto out; - nr_failed = rc; split_folio_migration: for (pass = 0; @@ -1563,12 +1532,6 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, nr_retry_pages = 0; list_for_each_entry_safe(folio, folio2, from, lru) { - /* Retried hugetlb folios will be kept in list */ - if (folio_test_hugetlb(folio)) { - list_move_tail(&folio->lru, &ret_folios); - continue; - } - /* * Large folio statistics is based on the source large * folio. Capture required information that might get @@ -1582,15 +1545,14 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, rc = unmap_and_move(get_new_page, put_new_page, private, folio, pass > 2, mode, - reason, &ret_folios); + reason, ret_folios); /* * The rules are: * Success: folio will be freed * -EAGAIN: stay on the from list * -ENOMEM: stay on the from list * -ENOSYS: stay on the from list - * Other errno: put on ret_folios list then splice to - * from list + * Other errno: put on ret_folios list */ switch(rc) { /* @@ -1607,17 +1569,17 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, /* Large folio migration is unsupported */ if (is_large) { nr_large_failed++; - stats.nr_thp_failed += is_thp; + stats->nr_thp_failed += is_thp; if (!try_split_folio(folio, &split_folios)) { - stats.nr_thp_split += is_thp; + stats->nr_thp_split += is_thp; break; } } else if (!no_split_folio_counting) { nr_failed++; } - stats.nr_failed_pages += nr_pages; - list_move_tail(&folio->lru, &ret_folios); + stats->nr_failed_pages += nr_pages; + list_move_tail(&folio->lru, ret_folios); break; case -ENOMEM: /* @@ -1626,13 +1588,13 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, */ if (is_large) { nr_large_failed++; - stats.nr_thp_failed += is_thp; + stats->nr_thp_failed += is_thp; /* Large folio NUMA faulting doesn't split to retry. */ if (!nosplit) { int ret = try_split_folio(folio, &split_folios); if (!ret) { - stats.nr_thp_split += is_thp; + stats->nr_thp_split += is_thp; break; } else if (reason == MR_LONGTERM_PIN && ret == -EAGAIN) { @@ -1650,17 +1612,17 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, nr_failed++; } - stats.nr_failed_pages += nr_pages + nr_retry_pages; + stats->nr_failed_pages += nr_pages + nr_retry_pages; /* * There might be some split folios of fail-to-migrate large - * folios left in split_folios list. Move them back to migration + * folios left in split_folios list. Move them to ret_folios * list so that they could be put back to the right list by * the caller otherwise the folio refcnt will be leaked. */ - list_splice_init(&split_folios, from); + list_splice_init(&split_folios, ret_folios); /* nr_failed isn't updated for not used */ nr_large_failed += large_retry; - stats.nr_thp_failed += thp_retry; + stats->nr_thp_failed += thp_retry; goto out; case -EAGAIN: if (is_large) { @@ -1672,8 +1634,8 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, nr_retry_pages += nr_pages; break; case MIGRATEPAGE_SUCCESS: - stats.nr_succeeded += nr_pages; - stats.nr_thp_succeeded += is_thp; + stats->nr_succeeded += nr_pages; + stats->nr_thp_succeeded += is_thp; break; default: /* @@ -1684,20 +1646,20 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, */ if (is_large) { nr_large_failed++; - stats.nr_thp_failed += is_thp; + stats->nr_thp_failed += is_thp; } else if (!no_split_folio_counting) { nr_failed++; } - stats.nr_failed_pages += nr_pages; + stats->nr_failed_pages += nr_pages; break; } } } nr_failed += retry; nr_large_failed += large_retry; - stats.nr_thp_failed += thp_retry; - stats.nr_failed_pages += nr_retry_pages; + stats->nr_thp_failed += thp_retry; + stats->nr_failed_pages += nr_retry_pages; /* * Try to migrate split folios of fail-to-migrate large folios, no * nr_failed counting in this round, since all split folios of a @@ -1708,7 +1670,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, * Move non-migrated folios (after NR_MAX_MIGRATE_PAGES_RETRY * retries) to ret_folios to avoid migrating them again. */ - list_splice_init(from, &ret_folios); + list_splice_init(from, ret_folios); list_splice_init(&split_folios, from); no_split_folio_counting = true; retry = 1; @@ -1716,6 +1678,82 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, } rc = nr_failed + nr_large_failed; +out: + return rc; +} + +/* + * migrate_pages - migrate the folios specified in a list, to the free folios + * supplied as the target for the page migration + * + * @from: The list of folios to be migrated. + * @get_new_page: The function used to allocate free folios to be used + * as the target of the folio migration. + * @put_new_page: The function used to free target folios if migration + * fails, or NULL if no special handling is necessary. + * @private: Private data to be passed on to get_new_page() + * @mode: The migration mode that specifies the constraints for + * folio migration, if any. + * @reason: The reason for folio migration. + * @ret_succeeded: Set to the number of folios migrated successfully if + * the caller passes a non-NULL pointer. + * + * The function returns after NR_MAX_MIGRATE_PAGES_RETRY attempts or if no folios + * are movable any more because the list has become empty or no retryable folios + * exist any more. It is caller's responsibility to call putback_movable_pages() + * only if ret != 0. + * + * Returns the number of {normal folio, large folio, hugetlb} that were not + * migrated, or an error code. The number of large folio splits will be + * considered as the number of non-migrated large folio, no matter how many + * split folios of the large folio are migrated successfully. + */ +int migrate_pages(struct list_head *from, new_page_t get_new_page, + free_page_t put_new_page, unsigned long private, + enum migrate_mode mode, int reason, unsigned int *ret_succeeded) +{ + int rc, rc_gather; + int nr_pages; + struct folio *folio, *folio2; + LIST_HEAD(folios); + LIST_HEAD(ret_folios); + struct migrate_pages_stats stats; + + trace_mm_migrate_pages_start(mode, reason); + + memset(&stats, 0, sizeof(stats)); + + rc_gather = migrate_hugetlbs(from, get_new_page, put_new_page, private, + mode, reason, &stats, &ret_folios); + if (rc_gather < 0) + goto out; +again: + nr_pages = 0; + list_for_each_entry_safe(folio, folio2, from, lru) { + /* Retried hugetlb folios will be kept in list */ + if (folio_test_hugetlb(folio)) { + list_move_tail(&folio->lru, &ret_folios); + continue; + } + + nr_pages += folio_nr_pages(folio); + if (nr_pages > NR_MAX_BATCHED_MIGRATION) + break; + } + if (nr_pages > NR_MAX_BATCHED_MIGRATION) + list_cut_before(&folios, from, &folio->lru); + else + list_splice_init(from, &folios); + rc = migrate_pages_batch(&folios, get_new_page, put_new_page, private, + mode, reason, &ret_folios, &stats); + list_splice_tail_init(&folios, &ret_folios); + if (rc < 0) { + rc_gather = rc; + goto out; + } + rc_gather += rc; + if (!list_empty(from)) + goto again; out: /* * Put the permanent failure folio back to migration list, they @@ -1728,7 +1766,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, * are migrated successfully. */ if (list_empty(from)) - rc = 0; + rc_gather = 0; count_vm_events(PGMIGRATE_SUCCESS, stats.nr_succeeded); count_vm_events(PGMIGRATE_FAIL, stats.nr_failed_pages); @@ -1742,7 +1780,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, if (ret_succeeded) *ret_succeeded = stats.nr_succeeded; - return rc; + return rc_gather; } struct page *alloc_migration_target(struct page *page, unsigned long private) From patchwork Mon Feb 6 06:33:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13129354 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 414E4C636D3 for ; Mon, 6 Feb 2023 06:33:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D513F6B007D; Mon, 6 Feb 2023 01:33:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D01426B007E; Mon, 6 Feb 2023 01:33:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC93F6B0080; Mon, 6 Feb 2023 01:33:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id AEC476B007D for ; Mon, 6 Feb 2023 01:33:51 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 87B961C61EE for ; Mon, 6 Feb 2023 06:33:51 +0000 (UTC) X-FDA: 80435901462.16.6353180 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf11.hostedemail.com (Postfix) with ESMTP id 5616240009 for ; Mon, 6 Feb 2023 06:33:49 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="c/eRc4e5"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675665229; 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:dkim-signature; bh=6zVVJXnpq/vW46SiufXNLdBJlTQFDfAZrTjpW/WPTas=; b=2mYaiNZR2/cP34qiGHyiuXbFF3PwUJw3z5hNNephSfy0nSOP3UKPwStg+6bydQIVzQDOcN QKKDRgzOJh/vX3NZhVMw10yClcX0v4r9lUMy4kwXhiaRB/BgND9iuTFDGH4gHAMhSBqm58 ij+lqdIQk2RMUGCGRJ8z7UjVpDnGbxU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="c/eRc4e5"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675665229; a=rsa-sha256; cv=none; b=OG1g1zZTxngl22J7kHkAksDIhmE/mSMjm+jU2Ojyz/WHp1ga0/j6GKNh5jBtVOxffHpiLk RGUOH4OiNaaL+lvWE2paNcH5yFjMQHu+l6eJnXtHA3KNGaKTjPOLI18iQqOJVHuwCF6J+3 HxnZ9WGTXfH3oiRNFimSsSNSxHWebnI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675665229; x=1707201229; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G5ZfaUuXgSxehPG875BTf4HRHOPcGYUMTs8SwIYJqho=; b=c/eRc4e5U0Hp/1Rj7FSmCbHUEVuByAQufYHuCKuKcCqtvsN2uuTSS64D xt1FAiOdaQGOiLD67hceC/WBOzJJQdroOqpONukjLNxsq/QutPYhhZMuN ZCbiCBuzT04MKkcZk+rHZrKrjQQUOwfdGesy61sGKanLzxi9l9mbKn5tS K1dBeNcsCRzlPZKav+nD3ODXbb5vPAQ4fo2d5nnngK5hy6NLuYws8dNxP uzFlmsptSE4ESzMTyHT8EpgyM1pCBrRPsVkXA5I64MvNa1OlHQg7zezO/ ZdZ9UR9Kspst3M+VSxYRAfEmvRDI6zEXNPgDi48GvQRs+vdSjwEMZ9awE A==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330432684" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330432684" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:48 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="659744706" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="659744706" Received: from baoyumen-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.smartont.net) ([10.255.30.227]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:43 -0800 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 , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH -v4 4/9] migrate_pages: split unmap_and_move() to _unmap() and _move() Date: Mon, 6 Feb 2023 14:33:08 +0800 Message-Id: <20230206063313.635011-5-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> References: <20230206063313.635011-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5616240009 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: g54nbwyhefffnaabmt4fg9fqu5xj4b1e X-HE-Tag: 1675665229-311703 X-HE-Meta: U2FsdGVkX18knrBZWX61sJSAv3+io8UV59cbFdwK1uUamWXDXxpWCN9dwdtsgMCiLtIiGsfupaVOGWCzcO7sAS9YPNRYywxntQQdoDUKIxjwW6l1Cvay+igO96HHWOQff8SHWddDaIMZh08IN4ZLUYMnK/mWt194vgHWHwWhtxFCdfl1tlKJzta3HcSSenHPcadNX/Q8lXLX2GYcBNPv7pdclKlnSvr9sdgBDByrXEhWHd/RBJRYhi6ET/TvvVqfh8lEZldUXhcRZ1EQJ57cddnFS0CrF4drfPXARBrqBxsFWHl3h+Tjv/9JzFKGs846TNBlWjXWfEfn+O3F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4WPourWS80ejI9SdpfJj7TJ7OJeDzD3Bci6PSwi83X+07ogW83iPrtcFd2izvzY4tBqFLS8wSquCAX72D0EqX6YvWrWoE0/CiUslpzGU6sofjKM9nO+DunHlc4d0QBs0BH2RjyNgqC61WPVRG7vuWv2xnbkilj5oaQbi1/JAmogiIHB22tOEnSflC5OvtDrdZ+Wt/dvhm3qhgc7o+wunhnnIS7QJp8LuuECqnTndNJJ7GicRKuiuz98 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: This is a preparation patch to batch the folio unmapping and moving. In this patch, unmap_and_move() is split to migrate_folio_unmap() and migrate_folio_move(). So, we can batch _unmap() and _move() in different loops later. To pass some information between unmap and move, the original unused dst->mapping and dst->private are used. Signed-off-by: "Huang, Ying" Reviewed-by: Baolin Wang Cc: Zi Yan Cc: Yang Shi Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: Alistair Popple Cc: haoxin Cc: Minchan Kim Cc: Mike Kravetz Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Xin Hao --- include/linux/migrate.h | 1 + mm/migrate.c | 170 ++++++++++++++++++++++++++++++---------- 2 files changed, 130 insertions(+), 41 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 3ef77f52a4f0..7376074f2e1e 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -18,6 +18,7 @@ struct migration_target_control; * - zero on page migration success; */ #define MIGRATEPAGE_SUCCESS 0 +#define MIGRATEPAGE_UNMAP 1 /** * struct movable_operations - Driver page migration diff --git a/mm/migrate.c b/mm/migrate.c index 9a667039c34c..0428449149f4 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1009,11 +1009,53 @@ static int move_to_new_folio(struct folio *dst, struct folio *src, return rc; } -static int __unmap_and_move(struct folio *src, struct folio *dst, +/* + * To record some information during migration, we uses some unused + * fields (mapping and private) of struct folio of the newly allocated + * destination folio. This is safe because nobody is using them + * except us. + */ +static void __migrate_folio_record(struct folio *dst, + unsigned long page_was_mapped, + struct anon_vma *anon_vma) +{ + dst->mapping = (void *)anon_vma; + dst->private = (void *)page_was_mapped; +} + +static void __migrate_folio_extract(struct folio *dst, + int *page_was_mappedp, + struct anon_vma **anon_vmap) +{ + *anon_vmap = (void *)dst->mapping; + *page_was_mappedp = (unsigned long)dst->private; + dst->mapping = NULL; + dst->private = NULL; +} + +/* Cleanup src folio upon migration success */ +static void migrate_folio_done(struct folio *src, + enum migrate_reason reason) +{ + /* + * Compaction can migrate also non-LRU pages which are + * not accounted to NR_ISOLATED_*. They can be recognized + * as __PageMovable + */ + if (likely(!__folio_test_movable(src))) + mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON + + folio_is_file_lru(src), -folio_nr_pages(src)); + + if (reason != MR_MEMORY_FAILURE) + /* We release the page in page_handle_poison. */ + folio_put(src); +} + +static int __migrate_folio_unmap(struct folio *src, struct folio *dst, int force, enum migrate_mode mode) { int rc = -EAGAIN; - bool page_was_mapped = false; + int page_was_mapped = 0; struct anon_vma *anon_vma = NULL; bool is_lru = !__PageMovable(&src->page); @@ -1089,8 +1131,8 @@ static int __unmap_and_move(struct folio *src, struct folio *dst, goto out_unlock; if (unlikely(!is_lru)) { - rc = move_to_new_folio(dst, src, mode); - goto out_unlock_both; + __migrate_folio_record(dst, page_was_mapped, anon_vma); + return MIGRATEPAGE_UNMAP; } /* @@ -1115,11 +1157,42 @@ static int __unmap_and_move(struct folio *src, struct folio *dst, VM_BUG_ON_FOLIO(folio_test_anon(src) && !folio_test_ksm(src) && !anon_vma, src); try_to_migrate(src, 0); - page_was_mapped = true; + page_was_mapped = 1; } - if (!folio_mapped(src)) - rc = move_to_new_folio(dst, src, mode); + if (!folio_mapped(src)) { + __migrate_folio_record(dst, page_was_mapped, anon_vma); + return MIGRATEPAGE_UNMAP; + } + + if (page_was_mapped) + remove_migration_ptes(src, src, false); + +out_unlock_both: + folio_unlock(dst); +out_unlock: + /* Drop an anon_vma reference if we took one */ + if (anon_vma) + put_anon_vma(anon_vma); + folio_unlock(src); +out: + + return rc; +} + +static int __migrate_folio_move(struct folio *src, struct folio *dst, + enum migrate_mode mode) +{ + int rc; + int page_was_mapped = 0; + struct anon_vma *anon_vma = NULL; + bool is_lru = !__PageMovable(&src->page); + + __migrate_folio_extract(dst, &page_was_mapped, &anon_vma); + + rc = move_to_new_folio(dst, src, mode); + if (unlikely(!is_lru)) + goto out_unlock_both; /* * When successful, push dst to LRU immediately: so that if it @@ -1142,12 +1215,10 @@ static int __unmap_and_move(struct folio *src, struct folio *dst, out_unlock_both: folio_unlock(dst); -out_unlock: /* Drop an anon_vma reference if we took one */ if (anon_vma) put_anon_vma(anon_vma); folio_unlock(src); -out: /* * If migration is successful, decrease refcount of dst, * which will not free the page because new page owner increased @@ -1159,19 +1230,15 @@ static int __unmap_and_move(struct folio *src, struct folio *dst, return rc; } -/* - * Obtain the lock on folio, remove all ptes and migrate the folio - * to the newly allocated folio in dst. - */ -static int unmap_and_move(new_page_t get_new_page, - free_page_t put_new_page, - unsigned long private, struct folio *src, - int force, enum migrate_mode mode, - enum migrate_reason reason, - struct list_head *ret) +/* Obtain the lock on page, remove all ptes. */ +static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page, + unsigned long private, struct folio *src, + struct folio **dstp, int force, + enum migrate_mode mode, enum migrate_reason reason, + struct list_head *ret) { struct folio *dst; - int rc = MIGRATEPAGE_SUCCESS; + int rc = MIGRATEPAGE_UNMAP; struct page *newpage = NULL; if (!thp_migration_supported() && folio_test_transhuge(src)) @@ -1182,20 +1249,50 @@ static int unmap_and_move(new_page_t get_new_page, folio_clear_active(src); folio_clear_unevictable(src); /* free_pages_prepare() will clear PG_isolated. */ - goto out; + list_del(&src->lru); + migrate_folio_done(src, reason); + return MIGRATEPAGE_SUCCESS; } newpage = get_new_page(&src->page, private); if (!newpage) return -ENOMEM; dst = page_folio(newpage); + *dstp = dst; dst->private = NULL; - rc = __unmap_and_move(src, dst, force, mode); + rc = __migrate_folio_unmap(src, dst, force, mode); + if (rc == MIGRATEPAGE_UNMAP) + return rc; + + /* + * A page that has not been migrated will have kept its + * references and be restored. + */ + /* restore the folio to right list. */ + if (rc != -EAGAIN) + list_move_tail(&src->lru, ret); + + if (put_new_page) + put_new_page(&dst->page, private); + else + folio_put(dst); + + return rc; +} + +/* Migrate the folio to the newly allocated folio in dst. */ +static int migrate_folio_move(free_page_t put_new_page, unsigned long private, + struct folio *src, struct folio *dst, + enum migrate_mode mode, enum migrate_reason reason, + struct list_head *ret) +{ + int rc; + + rc = __migrate_folio_move(src, dst, mode); if (rc == MIGRATEPAGE_SUCCESS) set_page_owner_migrate_reason(&dst->page, reason); -out: if (rc != -EAGAIN) { /* * A folio that has been migrated has all references @@ -1211,20 +1308,7 @@ static int unmap_and_move(new_page_t get_new_page, * we want to retry. */ if (rc == MIGRATEPAGE_SUCCESS) { - /* - * Compaction can migrate also non-LRU folios which are - * not accounted to NR_ISOLATED_*. They can be recognized - * as __folio_test_movable - */ - if (likely(!__folio_test_movable(src))) - mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON + - folio_is_file_lru(src), -folio_nr_pages(src)); - - if (reason != MR_MEMORY_FAILURE) - /* - * We release the folio in page_handle_poison. - */ - folio_put(src); + migrate_folio_done(src, reason); } else { if (rc != -EAGAIN) list_add_tail(&src->lru, ret); @@ -1516,7 +1600,7 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, int pass = 0; bool is_large = false; bool is_thp = false; - struct folio *folio, *folio2; + struct folio *folio, *folio2, *dst = NULL; int rc, nr_pages; LIST_HEAD(split_folios); bool nosplit = (reason == MR_NUMA_MISPLACED); @@ -1543,9 +1627,13 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, cond_resched(); - rc = unmap_and_move(get_new_page, put_new_page, - private, folio, pass > 2, mode, - reason, ret_folios); + rc = migrate_folio_unmap(get_new_page, put_new_page, private, + folio, &dst, pass > 2, mode, + reason, ret_folios); + if (rc == MIGRATEPAGE_UNMAP) + rc = migrate_folio_move(put_new_page, private, + folio, dst, mode, + reason, ret_folios); /* * The rules are: * Success: folio will be freed From patchwork Mon Feb 6 06:33:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13129355 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 C365CC05027 for ; Mon, 6 Feb 2023 06:33:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64D956B0074; Mon, 6 Feb 2023 01:33:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FD1F6B0078; Mon, 6 Feb 2023 01:33:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49D7B6B007E; Mon, 6 Feb 2023 01:33:57 -0500 (EST) 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 3C5A26B0074 for ; Mon, 6 Feb 2023 01:33:57 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 185D380ACD for ; Mon, 6 Feb 2023 06:33:57 +0000 (UTC) X-FDA: 80435901714.10.3618E5E Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf11.hostedemail.com (Postfix) with ESMTP id ECCD340005 for ; Mon, 6 Feb 2023 06:33:54 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=HPz3qUw1; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675665235; 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:dkim-signature; bh=mbmQLJ1/0WDHTi7CDhgdIm+aQmLddU6deyPoGnL37qI=; b=lHMLXMBdz2+36NWxQ5QCube0Lyf/E9IjZwxpQ48IOpi8OaDpOA61CrEjkJpYIQeg+kBQEV EMIMdoN82e0bI4KrDowFVKukdB/ka+DiEv6kiY24IKVIvk8JYNc0aaxazA0fmTBV0erzQn k1yYMOiQUdBKfGCdn4bHNpUaZiW01WQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=HPz3qUw1; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675665235; a=rsa-sha256; cv=none; b=pWgTxlLEO+jOIMvZjWtydoC60SoJizPKEKHdOjgUZEXWjqObpiMz+nvwobTs6p7m3rsb8y KvHJ0RkouXIOWoanxhd5mEpn7nlZsV4mDJqas9OTTsWEoNEZbpb8wvf7T976hs1w5kI8eQ E5kehYjnfdS6MqMC3JLytOSQSqNm8LU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675665235; x=1707201235; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5DhuqTDUtxiYMMe7r09ZIVnr3TsjyvBnwnKzcD7MQTk=; b=HPz3qUw1xklF4nwZjlo2lMXvYAFpcyCbhwz7yO34m5XglCsnDIdzk9CW YLFIrEZACzVxQh/TrLw1wjfMX7n+hn+yK3cxoF8EmvPC47W2uOglt4iuW Sz9i8KoiymjVu8FdC4EzX3DPMoOhe8/0ylro2HgH+yI/+kTEDaDve0jo4 pD+0QE+4/9NyZQlz/fUbNYgL3nK9AafePs7UaTIZFjrRKyJ9ToyKhKd5s tvLNuo298mlnGOtuqnfYG3jE5qrnJFB8SAIe1VUfWOJ0sogE9FXmExl6R qgf3xSqiHfT5IxJ/4kVr1tsN12/vyPYjEsDpKt2hpgEL9gfPE5Kh3x56v w==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330432699" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330432699" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:54 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="659744733" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="659744733" Received: from baoyumen-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.smartont.net) ([10.255.30.227]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:48 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin , Minchan Kim , Mike Kravetz Subject: [PATCH -v4 5/9] migrate_pages: batch _unmap and _move Date: Mon, 6 Feb 2023 14:33:09 +0800 Message-Id: <20230206063313.635011-6-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> References: <20230206063313.635011-1-ying.huang@intel.com> MIME-Version: 1.0 X-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d5kfV55y3TxIdgt4P KpTI2Mme +7Jw7keo8mJAqFQtxAvBaTTXOKWw/M0edJQwxhhKm6o//uPWJl8+QR0FRAWr6E5GbApsoyrlTVywaECDtxziMep8KeUaeOuPAkHudz7Uyxnlf0y0p92aIPAQ2cdlNZKVty6kQbLVAbJIRph4VXl3vxdzcwOATb9kKA45VEk0BuF7PwzbvlyJ9RvImKIZN7EhIN5bhufTw+CT7qPDCeugp6d/6kdcf3aLoN4sUfjV6dDSbPJJMcvSf7QYVmhVw/NAh4Qos1IvqEYO2hTogCRwhmzyzALOtp8KK4UkmTxpYdiwQSVeAbfvPaKWoAoZ5bA7D0DhoNehgXslcGHEn0S0dPens8ugsbhBqFMIcedtjiVjBVQfQgmnY2AdUxGewYNETDrnq7KwGsdpVeS49Bi0Tfo4WC7dMG6XKzjnb80ZAFku1TawOJbztsl+P08PsD8DJCtKu9/K2wuK7WvF927GWuJLRbajPMDLJrQfbyey7Nr6UYWm3dWN1E2f+lyZMEyQ3z38c4O4K7L49zdxWoYCAA0tXhRBeZiRpign5ER2nkD+egtAlh1WvBuJxp2TJ7C6WBmmgAxueFielF64uCoT9OmFnxyRjDwRUlFQ9jCgabHPOfcN/lyRP3xRR0+RPJNHUaNp8YTsFc3xrEP/q38otWweIoQ== 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: In this patch the _unmap and _move stage of the folio migration is batched. That for, previously, it is, for each folio _unmap() _move() Now, it is, for each folio _unmap() for each folio _move() Based on this, we can batch the TLB flushing and use some hardware accelerator to copy folios between batched _unmap and batched _move stages. Signed-off-by: "Huang, Ying" Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Zi Yan Cc: Yang Shi Cc: Baolin Wang Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: Alistair Popple Cc: haoxin Cc: Minchan Kim Cc: Mike Kravetz --- mm/migrate.c | 208 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 184 insertions(+), 24 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 0428449149f4..fa7212330cb6 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1033,6 +1033,33 @@ static void __migrate_folio_extract(struct folio *dst, dst->private = NULL; } +/* Restore the source folio to the original state upon failure */ +static void migrate_folio_undo_src(struct folio *src, + int page_was_mapped, + struct anon_vma *anon_vma, + struct list_head *ret) +{ + if (page_was_mapped) + remove_migration_ptes(src, src, false); + /* Drop an anon_vma reference if we took one */ + if (anon_vma) + put_anon_vma(anon_vma); + folio_unlock(src); + list_move_tail(&src->lru, ret); +} + +/* Restore the destination folio to the original state upon failure */ +static void migrate_folio_undo_dst(struct folio *dst, + free_page_t put_new_page, + unsigned long private) +{ + folio_unlock(dst); + if (put_new_page) + put_new_page(&dst->page, private); + else + folio_put(dst); +} + /* Cleanup src folio upon migration success */ static void migrate_folio_done(struct folio *src, enum migrate_reason reason) @@ -1052,7 +1079,7 @@ static void migrate_folio_done(struct folio *src, } static int __migrate_folio_unmap(struct folio *src, struct folio *dst, - int force, enum migrate_mode mode) + int force, bool force_lock, enum migrate_mode mode) { int rc = -EAGAIN; int page_was_mapped = 0; @@ -1079,6 +1106,17 @@ static int __migrate_folio_unmap(struct folio *src, struct folio *dst, if (current->flags & PF_MEMALLOC) goto out; + /* + * We have locked some folios, to avoid deadlock, we cannot + * lock the folio synchronously. Go out to process (and + * unlock) all the locked folios. Then we can lock the folio + * synchronously. + */ + if (!force_lock) { + rc = -EDEADLOCK; + goto out; + } + folio_lock(src); } @@ -1187,10 +1225,20 @@ static int __migrate_folio_move(struct folio *src, struct folio *dst, int page_was_mapped = 0; struct anon_vma *anon_vma = NULL; bool is_lru = !__PageMovable(&src->page); + struct list_head *prev; __migrate_folio_extract(dst, &page_was_mapped, &anon_vma); + prev = dst->lru.prev; + list_del(&dst->lru); rc = move_to_new_folio(dst, src, mode); + + if (rc == -EAGAIN) { + list_add(&dst->lru, prev); + __migrate_folio_record(dst, page_was_mapped, anon_vma); + return rc; + } + if (unlikely(!is_lru)) goto out_unlock_both; @@ -1233,7 +1281,7 @@ static int __migrate_folio_move(struct folio *src, struct folio *dst, /* Obtain the lock on page, remove all ptes. */ static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page, unsigned long private, struct folio *src, - struct folio **dstp, int force, + struct folio **dstp, int force, bool force_lock, enum migrate_mode mode, enum migrate_reason reason, struct list_head *ret) { @@ -1261,7 +1309,7 @@ static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page *dstp = dst; dst->private = NULL; - rc = __migrate_folio_unmap(src, dst, force, mode); + rc = __migrate_folio_unmap(src, dst, force, force_lock, mode); if (rc == MIGRATEPAGE_UNMAP) return rc; @@ -1270,7 +1318,7 @@ static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page * references and be restored. */ /* restore the folio to right list. */ - if (rc != -EAGAIN) + if (rc != -EAGAIN && rc != -EDEADLOCK) list_move_tail(&src->lru, ret); if (put_new_page) @@ -1309,9 +1357,8 @@ static int migrate_folio_move(free_page_t put_new_page, unsigned long private, */ if (rc == MIGRATEPAGE_SUCCESS) { migrate_folio_done(src, reason); - } else { - if (rc != -EAGAIN) - list_add_tail(&src->lru, ret); + } else if (rc != -EAGAIN) { + list_add_tail(&src->lru, ret); if (put_new_page) put_new_page(&dst->page, private); @@ -1591,7 +1638,7 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, enum migrate_mode mode, int reason, struct list_head *ret_folios, struct migrate_pages_stats *stats) { - int retry = 1; + int retry; int large_retry = 1; int thp_retry = 1; int nr_failed = 0; @@ -1600,13 +1647,19 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, int pass = 0; bool is_large = false; bool is_thp = false; - struct folio *folio, *folio2, *dst = NULL; - int rc, nr_pages; + struct folio *folio, *folio2, *dst = NULL, *dst2; + int rc, rc_saved, nr_pages; LIST_HEAD(split_folios); + LIST_HEAD(unmap_folios); + LIST_HEAD(dst_folios); bool nosplit = (reason == MR_NUMA_MISPLACED); bool no_split_folio_counting = false; + bool force_lock; -split_folio_migration: +retry: + rc_saved = 0; + force_lock = true; + retry = 1; for (pass = 0; pass < NR_MAX_MIGRATE_PAGES_RETRY && (retry || large_retry); pass++) { @@ -1628,16 +1681,15 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, cond_resched(); rc = migrate_folio_unmap(get_new_page, put_new_page, private, - folio, &dst, pass > 2, mode, - reason, ret_folios); - if (rc == MIGRATEPAGE_UNMAP) - rc = migrate_folio_move(put_new_page, private, - folio, dst, mode, - reason, ret_folios); + folio, &dst, pass > 2, force_lock, + mode, reason, ret_folios); /* * The rules are: * Success: folio will be freed + * Unmap: folio will be put on unmap_folios list, + * dst folio put on dst_folios list * -EAGAIN: stay on the from list + * -EDEADLOCK: stay on the from list * -ENOMEM: stay on the from list * -ENOSYS: stay on the from list * Other errno: put on ret_folios list @@ -1672,7 +1724,7 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, case -ENOMEM: /* * When memory is low, don't bother to try to migrate - * other folios, just exit. + * other folios, move unmapped folios, then exit. */ if (is_large) { nr_large_failed++; @@ -1711,7 +1763,19 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, /* nr_failed isn't updated for not used */ nr_large_failed += large_retry; stats->nr_thp_failed += thp_retry; - goto out; + rc_saved = rc; + if (list_empty(&unmap_folios)) + goto out; + else + goto move; + case -EDEADLOCK: + /* + * The folio cannot be locked for potential deadlock. + * Go move (and unlock) all locked folios. Then we can + * try again. + */ + rc_saved = rc; + goto move; case -EAGAIN: if (is_large) { large_retry++; @@ -1725,6 +1789,15 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, stats->nr_succeeded += nr_pages; stats->nr_thp_succeeded += is_thp; break; + case MIGRATEPAGE_UNMAP: + /* + * We have locked some folios, don't force lock + * to avoid deadlock. + */ + force_lock = false; + list_move_tail(&folio->lru, &unmap_folios); + list_add_tail(&dst->lru, &dst_folios); + break; default: /* * Permanent failure (-EBUSY, etc.): @@ -1748,12 +1821,95 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, nr_large_failed += large_retry; stats->nr_thp_failed += thp_retry; stats->nr_failed_pages += nr_retry_pages; +move: + retry = 1; + for (pass = 0; + pass < NR_MAX_MIGRATE_PAGES_RETRY && (retry || large_retry); + pass++) { + retry = 0; + large_retry = 0; + thp_retry = 0; + nr_retry_pages = 0; + + dst = list_first_entry(&dst_folios, struct folio, lru); + dst2 = list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { + is_large = folio_test_large(folio); + is_thp = is_large && folio_test_pmd_mappable(folio); + nr_pages = folio_nr_pages(folio); + + cond_resched(); + + rc = migrate_folio_move(put_new_page, private, + folio, dst, mode, + reason, ret_folios); + /* + * The rules are: + * Success: folio will be freed + * -EAGAIN: stay on the unmap_folios list + * Other errno: put on ret_folios list + */ + switch(rc) { + case -EAGAIN: + if (is_large) { + large_retry++; + thp_retry += is_thp; + } else if (!no_split_folio_counting) { + retry++; + } + nr_retry_pages += nr_pages; + break; + case MIGRATEPAGE_SUCCESS: + stats->nr_succeeded += nr_pages; + stats->nr_thp_succeeded += is_thp; + break; + default: + if (is_large) { + nr_large_failed++; + stats->nr_thp_failed += is_thp; + } else if (!no_split_folio_counting) { + nr_failed++; + } + + stats->nr_failed_pages += nr_pages; + break; + } + dst = dst2; + dst2 = list_next_entry(dst, lru); + } + } + nr_failed += retry; + nr_large_failed += large_retry; + stats->nr_thp_failed += thp_retry; + stats->nr_failed_pages += nr_retry_pages; + + if (rc_saved) + rc = rc_saved; + else + rc = nr_failed + nr_large_failed; +out: + /* Cleanup remaining folios */ + dst = list_first_entry(&dst_folios, struct folio, lru); + dst2 = list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { + int page_was_mapped = 0; + struct anon_vma *anon_vma = NULL; + + __migrate_folio_extract(dst, &page_was_mapped, &anon_vma); + migrate_folio_undo_src(folio, page_was_mapped, anon_vma, + ret_folios); + list_del(&dst->lru); + migrate_folio_undo_dst(dst, put_new_page, private); + dst = dst2; + dst2 = list_next_entry(dst, lru); + } + /* * Try to migrate split folios of fail-to-migrate large folios, no * nr_failed counting in this round, since all split folios of a * large folio is counted as 1 failure in the first round. */ - if (!list_empty(&split_folios)) { + if (rc >= 0 && !list_empty(&split_folios)) { /* * Move non-migrated folios (after NR_MAX_MIGRATE_PAGES_RETRY * retries) to ret_folios to avoid migrating them again. @@ -1761,12 +1917,16 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, list_splice_init(from, ret_folios); list_splice_init(&split_folios, from); no_split_folio_counting = true; - retry = 1; - goto split_folio_migration; + goto retry; } - rc = nr_failed + nr_large_failed; -out: + /* + * We have unlocked all locked folios, so we can force lock now, let's + * try again. + */ + if (rc == -EDEADLOCK) + goto retry; + return rc; } From patchwork Mon Feb 6 06:33:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13129356 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 6B45DC05027 for ; Mon, 6 Feb 2023 06:34:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07FCA6B0078; Mon, 6 Feb 2023 01:34:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 02FA36B007E; Mon, 6 Feb 2023 01:34:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E611E6B0080; Mon, 6 Feb 2023 01:34:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D768C6B0078 for ; Mon, 6 Feb 2023 01:34:02 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8B6491403F1 for ; Mon, 6 Feb 2023 06:34:02 +0000 (UTC) X-FDA: 80435901924.15.CDB2292 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf11.hostedemail.com (Postfix) with ESMTP id 862024000F for ; Mon, 6 Feb 2023 06:34:00 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=krZ70lgX; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675665240; 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:dkim-signature; bh=2CRGX/4cvOKQOeDObEC2cncEGX4sAo+G97rWZFVQ56Q=; b=W3UxHLjgOaxWjFFgpkGP3kuUMEL7wye+WUNO8KAYFnEiN7o+fCtHl4bJNLg+Cv27oMvWXL QSQhCgVa1P9a2Jo0eUXdKsY6dPgPEZ17BlPXPeHx/1fNPzaXwbNh6j0Vl6KjtgEvPJUEr6 nTJGs3Ui3SHPK/6bz5coytMXjYyyo5o= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=krZ70lgX; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675665240; a=rsa-sha256; cv=none; b=Nmi4+m+/KuZxrv0AgZKI7rdVigsmrpaTT7tu/WnTOT21Ynx6rlf59x2y3sG1AtYR9WbXl5 p+ulwRvblUwot5Ql+evxWmaWJV++TcEhpfh5fDm7AFUDySbceT8y9Y5FvDh4pjqCYzTeXr nzY0OWBWR0AsJeZVHRpgxRWEBeTX2VA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675665240; x=1707201240; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vDGXAlWxo4PDOnmZT5tL3p2VWp/8kRlkez6JFp7l83o=; b=krZ70lgX3H4P4anNtK2hNV1QRmhqOsDpVn+uhkY7LYTz2jRqXH35/Fuw MVJYVK2vNQ2Jw0BokYIcD0UT+H7eax/HY5G1eryzSgGbNL32Z2Hm1OJPF sn+FMowoq5xYLYnKY2ffLVQvwoBr5CrY7JjLSvOWNOEJ26pPcI+vX7SkJ fuu6vcHis+2IfIc7LHhrb4qkwAOHuXO6skYjNZ+EzOFedHzG8sLyun/5h fExA014/jpiSeogGQD5Lgh7SdO5x5FMm6awpYSFkB7PIHRBONiGNxcdWk dXizeD9OqeEvc5FjqWGdB44GuKXZo9t9ZaH5kcCz3Io7Y+Gj1X2Wd6X8P g==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330432727" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330432727" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:34:00 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="659744756" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="659744756" Received: from baoyumen-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.smartont.net) ([10.255.30.227]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:33:54 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH -v4 6/9] migrate_pages: move migrate_folio_unmap() Date: Mon, 6 Feb 2023 14:33:10 +0800 Message-Id: <20230206063313.635011-7-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> References: <20230206063313.635011-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 862024000F X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: sz1wum5zenqpzqzzop37do9ardp9naii X-HE-Tag: 1675665240-310358 X-HE-Meta: U2FsdGVkX1/h9h7tXBvPuYgsHz/nM03eJyLNS0fjd5UHaeWqZdfP2RFF4Z0pUMItKbdshWTNmWPgrv/DokmI66LmZFzxeW112b0ZNDXFMSFv/564cjcYgLuwM6m1n+f4pvA7FQ4pe2iT8mT1PLGMpEKg/UqB8BSXn7fPOXKopgNahPNE0WRpoA7eETxsWr/lXndxPnCDYmZAafFMJ97hzk/AIxTqzPS2EFMLq5wLaGtojjNJ5cJ1Sj/M2PECa72+PIGKHTA8AFb/pZY2Oomh7+xh28qz73fm0vfwW/BlwTkhBg2tFv0//IMZSH1fakR9U418g1QuZT7nkS1ltfiyj+T+YLMufDL+ZbK2wWGERb8qgTUBwn5iWJMWSVJeSt7JcOjPn7aoG1sOmD4017uhEKisDgUIx6BITLWst3iwUFic7+e77AxPuNylP/W4x6cPcVsbQiAZtCUcX1Gyu3lTOVN/ikH/Pj8Q/HrWbSKtKLiYxqguu/3uEnLFlOr2cBdkhHPUT7THuFx/2//3ZpvX6Pl0ydVe0t/AjQMPq2HgabZQPTEea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ovNsTBp5uJRseg== 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: Just move the position of the functions. There's no any functionality change. This is to make it easier to review the next patch via putting code near its position in the next patch. Signed-off-by: "Huang, Ying" Cc: Zi Yan Cc: Yang Shi Cc: Baolin Wang Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: Alistair Popple Cc: haoxin Cc: Minchan Kim Cc: Mike Kravetz Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/migrate.c | 102 +++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index fa7212330cb6..23eb01cfae4c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1218,6 +1218,57 @@ static int __migrate_folio_unmap(struct folio *src, struct folio *dst, return rc; } +/* Obtain the lock on page, remove all ptes. */ +static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page, + unsigned long private, struct folio *src, + struct folio **dstp, int force, bool force_lock, + enum migrate_mode mode, enum migrate_reason reason, + struct list_head *ret) +{ + struct folio *dst; + int rc = MIGRATEPAGE_UNMAP; + struct page *newpage = NULL; + + if (!thp_migration_supported() && folio_test_transhuge(src)) + return -ENOSYS; + + if (folio_ref_count(src) == 1) { + /* Folio was freed from under us. So we are done. */ + folio_clear_active(src); + folio_clear_unevictable(src); + /* free_pages_prepare() will clear PG_isolated. */ + list_del(&src->lru); + migrate_folio_done(src, reason); + return MIGRATEPAGE_SUCCESS; + } + + newpage = get_new_page(&src->page, private); + if (!newpage) + return -ENOMEM; + dst = page_folio(newpage); + *dstp = dst; + + dst->private = NULL; + rc = __migrate_folio_unmap(src, dst, force, force_lock, mode); + if (rc == MIGRATEPAGE_UNMAP) + return rc; + + /* + * A page that has not been migrated will have kept its + * references and be restored. + */ + /* restore the folio to right list. */ + if (rc != -EAGAIN && rc != -EDEADLOCK) + list_move_tail(&src->lru, ret); + + if (put_new_page) + put_new_page(&dst->page, private); + else + folio_put(dst); + + return rc; +} + static int __migrate_folio_move(struct folio *src, struct folio *dst, enum migrate_mode mode) { @@ -1278,57 +1329,6 @@ static int __migrate_folio_move(struct folio *src, struct folio *dst, return rc; } -/* Obtain the lock on page, remove all ptes. */ -static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page, - unsigned long private, struct folio *src, - struct folio **dstp, int force, bool force_lock, - enum migrate_mode mode, enum migrate_reason reason, - struct list_head *ret) -{ - struct folio *dst; - int rc = MIGRATEPAGE_UNMAP; - struct page *newpage = NULL; - - if (!thp_migration_supported() && folio_test_transhuge(src)) - return -ENOSYS; - - if (folio_ref_count(src) == 1) { - /* Folio was freed from under us. So we are done. */ - folio_clear_active(src); - folio_clear_unevictable(src); - /* free_pages_prepare() will clear PG_isolated. */ - list_del(&src->lru); - migrate_folio_done(src, reason); - return MIGRATEPAGE_SUCCESS; - } - - newpage = get_new_page(&src->page, private); - if (!newpage) - return -ENOMEM; - dst = page_folio(newpage); - *dstp = dst; - - dst->private = NULL; - rc = __migrate_folio_unmap(src, dst, force, force_lock, mode); - if (rc == MIGRATEPAGE_UNMAP) - return rc; - - /* - * A page that has not been migrated will have kept its - * references and be restored. - */ - /* restore the folio to right list. */ - if (rc != -EAGAIN && rc != -EDEADLOCK) - list_move_tail(&src->lru, ret); - - if (put_new_page) - put_new_page(&dst->page, private); - else - folio_put(dst); - - return rc; -} - /* Migrate the folio to the newly allocated folio in dst. */ static int migrate_folio_move(free_page_t put_new_page, unsigned long private, struct folio *src, struct folio *dst, From patchwork Mon Feb 6 06:33:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13129357 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 A1801C61DA4 for ; Mon, 6 Feb 2023 06:34:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42AC06B007D; Mon, 6 Feb 2023 01:34:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D97E6B007E; Mon, 6 Feb 2023 01:34:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A1BE6B0080; Mon, 6 Feb 2023 01:34:08 -0500 (EST) 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 1D5336B007D for ; Mon, 6 Feb 2023 01:34:08 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E972E120B4C for ; Mon, 6 Feb 2023 06:34:07 +0000 (UTC) X-FDA: 80435902134.15.66C8E13 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf11.hostedemail.com (Postfix) with ESMTP id D6D7440005 for ; Mon, 6 Feb 2023 06:34:05 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=I3uXuJve; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675665246; 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:dkim-signature; bh=CfOZxZhQh8vQmdTck0nZFv1+sFy7RYIre0T7zyrtQIw=; b=icxkRsJKLrMAXh72NU9Usz8YbDX5Y9PAdJecrF/R43U1Bp0GP0ilA830IEkwdtBzotOTNM c58b0e5lnF00/U2jDgvkv41MkcfHihbUSUE4k0UqFuXIHpFWorVYuJEZjqkPoNJLN0LTVc uIGeHqoPulqEiCMR5wXkHkw4IbE3rfo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=I3uXuJve; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675665246; a=rsa-sha256; cv=none; b=4FFqM7z3eAQCYw8XPOM7blg/Ae9ORRKhUzcLWOdg9aM9BWPfQz1lMJ+85NewAMnLMOkOBa vQ3d4iuf5g+oF4REsIk0rdgBz808ki6wMS/J/ObfiIVotJSirHTRaSpQzIomg8E/f+4l3E mCHEbXoSwV+leLVurV6cH+bGR6fBj2o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675665245; x=1707201245; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xnyyIG4eBpTGks53Pu5vU49x/7nhh4tAaQ/5pqQLi1A=; b=I3uXuJveX7UUuW3N+IIw571/JYoI/dI/QMZVwVjqFalUDjl6P3vIdGpl c5N6DhWMv1ETM62PxUgEq5tDsbMax9pULhx0ZnpykP2mCb2mDbOx4eMjf LWZLAJO9/SI3gUwxQYEpJ8xil1Cw4fEWsNLRsTK0Kgp5oLztuzzVQOfu7 +RK8Ky7yB47VY/jPzpykce6e1rhxcXDpfhGECogwHzWAMnc77BkzvuQLI r0Z3q10ZkA8SnrLoj1OkKE75IJ+mh+4f8JWB+1gBfA5xJtSvCAKwUVuSn q04poOAdQBMZhSUzcAwaTp3gqEwtCQKQEQmhBng/1ZmKW4tCREw0oQnxY Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330432749" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330432749" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:34:05 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="659744775" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="659744775" Received: from baoyumen-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.smartont.net) ([10.255.30.227]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:34:00 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH -v4 7/9] migrate_pages: share more code between _unmap and _move Date: Mon, 6 Feb 2023 14:33:11 +0800 Message-Id: <20230206063313.635011-8-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> References: <20230206063313.635011-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D6D7440005 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: x8jaot4otq3hnz9k679r7ay6ek1cfghc X-HE-Tag: 1675665245-68139 X-HE-Meta: U2FsdGVkX1/FNGFiULWeSJaknvwrn4uPahUzNzqejr7XD3B5pyJPNJlDubv06DjbVp6pGiJ/GvV7H/oO6U+lwz3EQEkPQfuRXuS3l4APIcFNCfRHNPOKqnCgmLJxwMedI0yXfm2xeFnAjrsmYaUZ+s88MVQ64QNKFUFW168r4bgVqbzuC1J/lywl7Ewv2cGbbUXFG1w2mHZfpz2RLHT8IX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AdB6tEAFtxtPIW4sflchAh5oUKv/PHqOK8xZ2YxnAIyBOV3b/jCKYGCFJzmwHI9WyrsClA0moK5qKA4MAPVXdyH5iMx/VG/Ij3owecFkNBtG9QOFLacvmY/yPIL9yLa/FNVPwPTKYyZvOXnRYA6FmAEb5j3nbG5IkjxENwmPiZGMd5QkrT20hyNOqMD3VSFnm4O/qn7o54Lhqik1DPUrcamFlMcZfYF/sO8KiPijqhP82Dwa5EtY+5Iz2QTOR+4YZC8XhYmNieTdgRDvmKSjr7GyYyD4UFsbnAmeOAXtaN9TY4t8to6jLbBnmI4xyBHnl2ss1sTVrLzlJG5USDhq6SZGNynwtGb4oOVfZOG4ovVw== 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: This is a code cleanup patch to reduce the duplicated code between the _unmap and _move stages of migrate_pages(). No functionality change is expected. Signed-off-by: "Huang, Ying" Cc: Zi Yan Cc: Yang Shi Cc: Baolin Wang Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: Alistair Popple Cc: haoxin Cc: Minchan Kim Cc: Mike Kravetz Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Zi Yan --- mm/migrate.c | 203 ++++++++++++++++++++------------------------------- 1 file changed, 81 insertions(+), 122 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 23eb01cfae4c..9378fa2ad4a5 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1037,6 +1037,7 @@ static void __migrate_folio_extract(struct folio *dst, static void migrate_folio_undo_src(struct folio *src, int page_was_mapped, struct anon_vma *anon_vma, + bool locked, struct list_head *ret) { if (page_was_mapped) @@ -1044,16 +1045,20 @@ static void migrate_folio_undo_src(struct folio *src, /* Drop an anon_vma reference if we took one */ if (anon_vma) put_anon_vma(anon_vma); - folio_unlock(src); - list_move_tail(&src->lru, ret); + if (locked) + folio_unlock(src); + if (ret) + list_move_tail(&src->lru, ret); } /* Restore the destination folio to the original state upon failure */ static void migrate_folio_undo_dst(struct folio *dst, + bool locked, free_page_t put_new_page, unsigned long private) { - folio_unlock(dst); + if (locked) + folio_unlock(dst); if (put_new_page) put_new_page(&dst->page, private); else @@ -1078,13 +1083,42 @@ static void migrate_folio_done(struct folio *src, folio_put(src); } -static int __migrate_folio_unmap(struct folio *src, struct folio *dst, - int force, bool force_lock, enum migrate_mode mode) +/* Obtain the lock on page, remove all ptes. */ +static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page, + unsigned long private, struct folio *src, + struct folio **dstp, int force, bool force_lock, + enum migrate_mode mode, enum migrate_reason reason, + struct list_head *ret) { + struct folio *dst; int rc = -EAGAIN; + struct page *newpage = NULL; int page_was_mapped = 0; struct anon_vma *anon_vma = NULL; bool is_lru = !__PageMovable(&src->page); + bool locked = false; + bool dst_locked = false; + + if (!thp_migration_supported() && folio_test_transhuge(src)) + return -ENOSYS; + + if (folio_ref_count(src) == 1) { + /* Folio was freed from under us. So we are done. */ + folio_clear_active(src); + folio_clear_unevictable(src); + /* free_pages_prepare() will clear PG_isolated. */ + list_del(&src->lru); + migrate_folio_done(src, reason); + return MIGRATEPAGE_SUCCESS; + } + + newpage = get_new_page(&src->page, private); + if (!newpage) + return -ENOMEM; + dst = page_folio(newpage); + *dstp = dst; + + dst->private = NULL; if (!folio_trylock(src)) { if (!force || mode == MIGRATE_ASYNC) @@ -1119,6 +1153,7 @@ static int __migrate_folio_unmap(struct folio *src, struct folio *dst, folio_lock(src); } + locked = true; if (folio_test_writeback(src)) { /* @@ -1133,10 +1168,10 @@ static int __migrate_folio_unmap(struct folio *src, struct folio *dst, break; default: rc = -EBUSY; - goto out_unlock; + goto out; } if (!force) - goto out_unlock; + goto out; folio_wait_writeback(src); } @@ -1166,7 +1201,8 @@ static int __migrate_folio_unmap(struct folio *src, struct folio *dst, * This is much like races on refcount of oldpage: just don't BUG(). */ if (unlikely(!folio_trylock(dst))) - goto out_unlock; + goto out; + dst_locked = true; if (unlikely(!is_lru)) { __migrate_folio_record(dst, page_was_mapped, anon_vma); @@ -1188,7 +1224,7 @@ static int __migrate_folio_unmap(struct folio *src, struct folio *dst, if (!src->mapping) { if (folio_test_private(src)) { try_to_free_buffers(src); - goto out_unlock_both; + goto out; } } else if (folio_mapped(src)) { /* Establish migration ptes */ @@ -1203,74 +1239,26 @@ static int __migrate_folio_unmap(struct folio *src, struct folio *dst, return MIGRATEPAGE_UNMAP; } - if (page_was_mapped) - remove_migration_ptes(src, src, false); - -out_unlock_both: - folio_unlock(dst); -out_unlock: - /* Drop an anon_vma reference if we took one */ - if (anon_vma) - put_anon_vma(anon_vma); - folio_unlock(src); out: - - return rc; -} - -/* Obtain the lock on page, remove all ptes. */ -static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page, - unsigned long private, struct folio *src, - struct folio **dstp, int force, bool force_lock, - enum migrate_mode mode, enum migrate_reason reason, - struct list_head *ret) -{ - struct folio *dst; - int rc = MIGRATEPAGE_UNMAP; - struct page *newpage = NULL; - - if (!thp_migration_supported() && folio_test_transhuge(src)) - return -ENOSYS; - - if (folio_ref_count(src) == 1) { - /* Folio was freed from under us. So we are done. */ - folio_clear_active(src); - folio_clear_unevictable(src); - /* free_pages_prepare() will clear PG_isolated. */ - list_del(&src->lru); - migrate_folio_done(src, reason); - return MIGRATEPAGE_SUCCESS; - } - - newpage = get_new_page(&src->page, private); - if (!newpage) - return -ENOMEM; - dst = page_folio(newpage); - *dstp = dst; - - dst->private = NULL; - rc = __migrate_folio_unmap(src, dst, force, force_lock, mode); - if (rc == MIGRATEPAGE_UNMAP) - return rc; - /* * A page that has not been migrated will have kept its * references and be restored. */ /* restore the folio to right list. */ - if (rc != -EAGAIN && rc != -EDEADLOCK) - list_move_tail(&src->lru, ret); + if (rc == -EAGAIN || rc == -EDEADLOCK) + ret = NULL; - if (put_new_page) - put_new_page(&dst->page, private); - else - folio_put(dst); + migrate_folio_undo_src(src, page_was_mapped, anon_vma, locked, ret); + migrate_folio_undo_dst(dst, dst_locked, put_new_page, private); return rc; } -static int __migrate_folio_move(struct folio *src, struct folio *dst, - enum migrate_mode mode) +/* Migrate the folio to the newly allocated folio in dst. */ +static int migrate_folio_move(free_page_t put_new_page, unsigned long private, + struct folio *src, struct folio *dst, + enum migrate_mode mode, enum migrate_reason reason, + struct list_head *ret) { int rc; int page_was_mapped = 0; @@ -1283,12 +1271,8 @@ static int __migrate_folio_move(struct folio *src, struct folio *dst, list_del(&dst->lru); rc = move_to_new_folio(dst, src, mode); - - if (rc == -EAGAIN) { - list_add(&dst->lru, prev); - __migrate_folio_record(dst, page_was_mapped, anon_vma); - return rc; - } + if (rc) + goto out; if (unlikely(!is_lru)) goto out_unlock_both; @@ -1302,70 +1286,45 @@ static int __migrate_folio_move(struct folio *src, struct folio *dst, * unsuccessful, and other cases when a page has been temporarily * isolated from the unevictable LRU: but this case is the easiest. */ - if (rc == MIGRATEPAGE_SUCCESS) { - folio_add_lru(dst); - if (page_was_mapped) - lru_add_drain(); - } + folio_add_lru(dst); + if (page_was_mapped) + lru_add_drain(); if (page_was_mapped) - remove_migration_ptes(src, - rc == MIGRATEPAGE_SUCCESS ? dst : src, false); + remove_migration_ptes(src, dst, false); out_unlock_both: folio_unlock(dst); - /* Drop an anon_vma reference if we took one */ - if (anon_vma) - put_anon_vma(anon_vma); - folio_unlock(src); + set_page_owner_migrate_reason(&dst->page, reason); /* * If migration is successful, decrease refcount of dst, * which will not free the page because new page owner increased * refcounter. */ - if (rc == MIGRATEPAGE_SUCCESS) - folio_put(dst); - - return rc; -} - -/* Migrate the folio to the newly allocated folio in dst. */ -static int migrate_folio_move(free_page_t put_new_page, unsigned long private, - struct folio *src, struct folio *dst, - enum migrate_mode mode, enum migrate_reason reason, - struct list_head *ret) -{ - int rc; - - rc = __migrate_folio_move(src, dst, mode); - if (rc == MIGRATEPAGE_SUCCESS) - set_page_owner_migrate_reason(&dst->page, reason); - - if (rc != -EAGAIN) { - /* - * A folio that has been migrated has all references - * removed and will be freed. A folio that has not been - * migrated will have kept its references and be restored. - */ - list_del(&src->lru); - } + folio_put(dst); /* - * If migration is successful, releases reference grabbed during - * isolation. Otherwise, restore the folio to right list unless - * we want to retry. + * A page that has been migrated has all references removed + * and will be freed. */ - if (rc == MIGRATEPAGE_SUCCESS) { - migrate_folio_done(src, reason); - } else if (rc != -EAGAIN) { - list_add_tail(&src->lru, ret); + list_del(&src->lru); + /* Drop an anon_vma reference if we took one */ + if (anon_vma) + put_anon_vma(anon_vma); + folio_unlock(src); + migrate_folio_done(src, reason); - if (put_new_page) - put_new_page(&dst->page, private); - else - folio_put(dst); + return rc; +out: + if (rc == -EAGAIN) { + list_add(&dst->lru, prev); + __migrate_folio_record(dst, page_was_mapped, anon_vma); + return rc; } + migrate_folio_undo_src(src, page_was_mapped, anon_vma, true, ret); + migrate_folio_undo_dst(dst, true, put_new_page, private); + return rc; } @@ -1897,9 +1856,9 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, __migrate_folio_extract(dst, &page_was_mapped, &anon_vma); migrate_folio_undo_src(folio, page_was_mapped, anon_vma, - ret_folios); + true, ret_folios); list_del(&dst->lru); - migrate_folio_undo_dst(dst, put_new_page, private); + migrate_folio_undo_dst(dst, true, put_new_page, private); dst = dst2; dst2 = list_next_entry(dst, lru); } From patchwork Mon Feb 6 06:33:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13129358 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 627F9C05027 for ; Mon, 6 Feb 2023 06:34:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00B7B6B007E; Mon, 6 Feb 2023 01:34:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EFC8D6B0080; Mon, 6 Feb 2023 01:34:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC4886B0081; Mon, 6 Feb 2023 01:34:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CD7856B007E for ; Mon, 6 Feb 2023 01:34:13 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AC975120807 for ; Mon, 6 Feb 2023 06:34:13 +0000 (UTC) X-FDA: 80435902386.15.5DB939E Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf11.hostedemail.com (Postfix) with ESMTP id A3F5440005 for ; Mon, 6 Feb 2023 06:34:11 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=K25BflN2; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675665251; 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:dkim-signature; bh=UH9aUpK4brvbUaQ61RpzxwNgcTTe1J3JqNYarO9pDJg=; b=AW6cX8fhyJrxjEKweLiHWHGx5VPfMkFyY2z49sWTsYv0cwWkY2mujImoMO31Xx5kGg83Rh 2lym9elGVoGAjJnhy6VULQ3LFZWI5Lkj6Li7HVV9DaTLSP9LFBIlBG3/C+ji0Rr446k7qA CV5uuVsbHw152hWDMGsTnZ46evg4Yrk= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=K25BflN2; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675665251; a=rsa-sha256; cv=none; b=RJn5ltpAWLHqE0wTKM8A4+HeHBEgiT5IUQG0z9OxheK0iBzI88+1CQWu2ScFTKGgLr2Ix7 5X1vux/eMTi0HCIDsA2lV0V+1idtFXc1GPoefHa0SP6DFT5Z8tMQUxKt1Tu48nyMJ3o/ZU mA4VEfHoAGDXg6J5AGsokZvQp+jP6T8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675665251; x=1707201251; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b/06ZIkmccm+2w2sDb3OOn+m3OxExo5G5C0UlpBP/5Y=; b=K25BflN2u0RMpFsXTdqj/qar/MOLc3KnoJWsm4ebL9FPAWOJucD07Cu0 TfkttA0fBOATYFPGF+HejBH+AA6ZpM2y/9E9L/ZE2WFBF1+QefYJG2yGD j94rxiyU5MgcssY/JXbhskNszTKmtQsAa5zusTcZ6JyrDUfj5i/lG9YOW Umv61/P5B5aP2VpNQMaTD4oUeZpDCspJCHnLD3DN76Ear8W8Z+SMP7O/V gAZvlj27Dybc4rxl0U3+bj1qhvNx5jCivujU6Umjt6f6TNnikuET91IGu YvsDVE39KZPEJnsAq0v6dnoxTXJBLHdzO4/VZnVDrCfVxElZHOSxZH1fB w==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330432774" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330432774" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:34:11 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="659744793" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="659744793" Received: from baoyumen-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.smartont.net) ([10.255.30.227]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:34:05 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH -v4 8/9] migrate_pages: batch flushing TLB Date: Mon, 6 Feb 2023 14:33:12 +0800 Message-Id: <20230206063313.635011-9-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> References: <20230206063313.635011-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A3F5440005 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: kdbm9p8wk6mb4n7uyckmk3bgas64mdnb X-HE-Tag: 1675665251-814808 X-HE-Meta: U2FsdGVkX19NnAS5SRf/kT2DzuUIe6PQzBRpaHCZvIrlS7WAkUaTwy8Pwv4Nh40OlG+bKCk82N3KG37Z5inNe2wy1KJmkSlIyEWQhdobx1RE08LmivYGESTYa9ZG7sa7sghcjW+3/pNhegzetukvMcOcZk9rZUyJJIUuUSCpHeRLGDqmwfvpbw8NF7AwKyyJNB/uHN9c8RTansIEkPHW9YfTUhDUj1vtRJRlNN4p1MzH/kVQA2BmoC9xNFnwSNj33OtsShSIRq+5ayEt6LXGCy+8ZbX8x4ZVXIjfM16rQor6ktrjd2s27A6l1ia2vp3HgiBPrxBL1ooVmO/uPUHIXgfR6L2MgmIwVL5eM3cVgGWjRN8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JQGqQ4u+lnli6pOIDuwI559SfI+5RDViZgc9LziuogrJ421wraVJq1WkGJPys5mXKydOU0OSieTqiSTv1inmayNeENWfOLcXl6LRfMQUf165kJJwOklG2fUAJD52xAib3LRY6XyGD/Wk1FT9hU3sJkHkajSpKzajPjnnswwrd/69IHsBFychkp2BLtiUkod1QlXT/vdiqKD2E7pXJcY0jpi5Q== 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: The TLB flushing will cost quite some CPU cycles during the folio migration in some situations. For example, when migrate a folio of a process with multiple active threads that run on multiple CPUs. After batching the _unmap and _move in migrate_pages(), the TLB flushing can be batched easily with the existing TLB flush batching mechanism. This patch implements that. We use the following test case to test the patch. On a 2-socket Intel server, - Run pmbench memory accessing benchmark - Run `migratepages` to migrate pages of pmbench between node 0 and node 1 back and forth. With the patch, the TLB flushing IPI reduces 99.1% during the test and the number of pages migrated successfully per second increases 291.7%. NOTE: TLB flushing is batched only for normal folios, not for THP folios. Because the overhead of TLB flushing for THP folios is much lower than that for normal folios (about 1/512 on x86 platform). Signed-off-by: "Huang, Ying" Cc: Zi Yan Cc: Yang Shi Cc: Baolin Wang Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: Alistair Popple Cc: haoxin Cc: Minchan Kim Cc: Mike Kravetz Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/migrate.c | 4 +++- mm/rmap.c | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 9378fa2ad4a5..ca6e2ff02a09 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1230,7 +1230,7 @@ static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page /* Establish migration ptes */ VM_BUG_ON_FOLIO(folio_test_anon(src) && !folio_test_ksm(src) && !anon_vma, src); - try_to_migrate(src, 0); + try_to_migrate(src, TTU_BATCH_FLUSH); page_was_mapped = 1; } @@ -1781,6 +1781,8 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, stats->nr_thp_failed += thp_retry; stats->nr_failed_pages += nr_retry_pages; move: + try_to_unmap_flush(); + retry = 1; for (pass = 0; pass < NR_MAX_MIGRATE_PAGES_RETRY && (retry || large_retry); diff --git a/mm/rmap.c b/mm/rmap.c index b616870a09be..2e125f3e462e 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1976,7 +1976,21 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, } else { flush_cache_page(vma, address, pte_pfn(*pvmw.pte)); /* Nuke the page table entry. */ - pteval = ptep_clear_flush(vma, address, pvmw.pte); + if (should_defer_flush(mm, flags)) { + /* + * We clear the PTE but do not flush so potentially + * a remote CPU could still be writing to the folio. + * If the entry was previously clean then the + * architecture must guarantee that a clear->dirty + * transition on a cached TLB entry is written through + * and traps if the PTE is unmapped. + */ + pteval = ptep_get_and_clear(mm, address, pvmw.pte); + + set_tlb_ubc_flush_pending(mm, pte_dirty(pteval)); + } else { + pteval = ptep_clear_flush(vma, address, pvmw.pte); + } } /* Set the dirty flag on the folio now the pte is gone. */ @@ -2148,10 +2162,10 @@ void try_to_migrate(struct folio *folio, enum ttu_flags flags) /* * Migration always ignores mlock and only supports TTU_RMAP_LOCKED and - * TTU_SPLIT_HUGE_PMD and TTU_SYNC flags. + * TTU_SPLIT_HUGE_PMD, TTU_SYNC, and TTU_BATCH_FLUSH flags. */ if (WARN_ON_ONCE(flags & ~(TTU_RMAP_LOCKED | TTU_SPLIT_HUGE_PMD | - TTU_SYNC))) + TTU_SYNC | TTU_BATCH_FLUSH))) return; if (folio_is_zone_device(folio) && From patchwork Mon Feb 6 06:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13129359 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 9C60DC05027 for ; Mon, 6 Feb 2023 06:34:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B5516B0080; Mon, 6 Feb 2023 01:34:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 363A06B0081; Mon, 6 Feb 2023 01:34:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 253A86B0082; Mon, 6 Feb 2023 01:34:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1827B6B0080 for ; Mon, 6 Feb 2023 01:34:19 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D78E8A0B2A for ; Mon, 6 Feb 2023 06:34:18 +0000 (UTC) X-FDA: 80435902596.17.5E676B6 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf11.hostedemail.com (Postfix) with ESMTP id BD5B140004 for ; Mon, 6 Feb 2023 06:34:16 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MnB4WDqj; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675665257; 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:dkim-signature; bh=W1e2A+EMS/OuzA6fH+/0VR0gikiUbJ6gqtwKjant+Ik=; b=qATazPh87UY0BAH5umc6Do9rlaANCPjw24kyCQzJM72Q6nLzf77QeWPnrjE4ZNJLZg3SxW 7FB0GSM1b2MwZ8MfqY7d82HGvfLffuxYy4RcZcTJFZz7cCHpB2abD5B4uN2gXajymKkStO MXDoAGm3BzpZHXPwTDEBc6kgMJCdoBs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MnB4WDqj; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675665257; a=rsa-sha256; cv=none; b=iicO/uI1cMvo/pornG5oT5ySCGFijH1ayyVAIGzW2N+RCyzpWqyQlynaM0MfIBxrCKO3kl 9DjkPhNpLGXNYeLHdu2JfPCU++0LfVzziO2VjVBZVnGWRvjXQLHEd5K/jMmapMAWGxwLS4 bZneS3SKDOPrLGY98Tx5wcs9792SSKc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675665256; x=1707201256; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+KR6MAogWT7k7pvOt7gIOQt6fuAqtcKUncYjRIY0PcU=; b=MnB4WDqjr72NjMpei60l3ykdg0Iy6vi55NrM1STO3VFF67qn4m0Et/W/ FVG8TAeOzAxLPDF88mBPLa/CmIZRJ2mB9Lsqk6TRdtiwqlSjLiBH/MOuy pPAf1957o2eacEoAeH81Hu9WoJlXO0youBs/PwRhhI6SpxQiYmXPE6stp z6Aw9HrYREjyFeSrdGdiof38ZYcgu5ZoVuLWyvME0pXDPL87Dhy/EOyFP SwU0ucQjimhr6aqPnrGWNXKKSz693V91N7aZ3+fEo/SPHinH/Fjzb4I8y MYB+Bbd3zwhw1GuwM97SzRrdWAxwFImWjM/4HdyZ2L3vnSCSKrYQLXnBi g==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330432797" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330432797" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:34:16 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="659744803" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="659744803" Received: from baoyumen-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.smartont.net) ([10.255.30.227]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 22:34:10 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Alistair Popple , Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , haoxin , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH -v4 9/9] migrate_pages: move THP/hugetlb migration support check to simplify code Date: Mon, 6 Feb 2023 14:33:13 +0800 Message-Id: <20230206063313.635011-10-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> References: <20230206063313.635011-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BD5B140004 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: ux7inkbhytp6hrnsdb56b6ingtmjh8wp X-HE-Tag: 1675665256-787791 X-HE-Meta: U2FsdGVkX19t+McI9We+G4EPND5NH8IGzBingLuMznjRbTSDNkP7hQTlNHVKDmu6mh9vkzN7VYK+H+Qplt3/U7Sm5jFpbXG7C9CU81WO8utLWH8Czg2At/q1HIwC8Zi25TrNIT4iBqF8DKAhUbN8t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Oo8YOdPGFTCYDB+KX3t6uJFq3fPbpMHyAHC5g8t3LDeCaatJyQNWju8pYCs0yh9t0yUaS+EQB84FC5CDbDuidbn/XbypYolXR4wMdiLkMKJOHM13Wc4xoaRNHAEQAStJEE2hHQj+fDQphYANij3ugmOLtPGRwwXhV7Ojr433+JRaEdLFjmjJoTvOYJwQd/LbcwtS9nS7aHKBkbkz/brV70Xv7yjyIubJn2CbxPLGExNqhI7Qej+nG/KMfW3Nsm9JdjX3ZjN/B44JgDqZb21vvCUaWmxF0BYOyuNVgocSP9L5faDzb9TnL5PwrFMsV8P3HS5cgi6hDlQVmjvpSrwiNNcXZi+dZeelCxTEkk9m4cA+RxXzY8DK5BF2675qDj0IwM1fFgM+O9s4UFMUDd4NSe1NESMwxPVzMMgEkgIPEcFrv2fnGVw== 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: This is a code cleanup patch, no functionality change is expected. After the change, the line number reduces especially in the long migrate_pages_batch(). Signed-off-by: "Huang, Ying" Suggested-by: Alistair Popple Cc: Zi Yan Cc: Yang Shi Cc: Baolin Wang Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: haoxin Cc: Minchan Kim Cc: Mike Kravetz Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/migrate.c | 83 +++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index ca6e2ff02a09..83d7ec8dfa66 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1099,9 +1099,6 @@ static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page bool locked = false; bool dst_locked = false; - if (!thp_migration_supported() && folio_test_transhuge(src)) - return -ENOSYS; - if (folio_ref_count(src) == 1) { /* Folio was freed from under us. So we are done. */ folio_clear_active(src); @@ -1359,16 +1356,6 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, struct anon_vma *anon_vma = NULL; struct address_space *mapping = NULL; - /* - * Migratability of hugepages depends on architectures and their size. - * This check is necessary because some callers of hugepage migration - * like soft offline and memory hotremove don't walk through page - * tables or check whether the hugepage is pmd-based or not before - * kicking migration. - */ - if (!hugepage_migration_supported(page_hstate(hpage))) - return -ENOSYS; - if (folio_ref_count(src) == 1) { /* page was freed from under us. So we are done. */ putback_active_hugepage(hpage); @@ -1535,6 +1522,20 @@ static int migrate_hugetlbs(struct list_head *from, new_page_t get_new_page, cond_resched(); + /* + * Migratability of hugepages depends on architectures and + * their size. This check is necessary because some callers + * of hugepage migration like soft offline and memory + * hotremove don't walk through page tables or check whether + * the hugepage is pmd-based or not before kicking migration. + */ + if (!hugepage_migration_supported(folio_hstate(folio))) { + nr_failed++; + stats->nr_failed_pages += nr_pages; + list_move_tail(&folio->lru, ret_folios); + continue; + } + rc = unmap_and_move_huge_page(get_new_page, put_new_page, private, &folio->page, pass > 2, mode, @@ -1544,16 +1545,9 @@ static int migrate_hugetlbs(struct list_head *from, new_page_t get_new_page, * Success: hugetlb folio will be put back * -EAGAIN: stay on the from list * -ENOMEM: stay on the from list - * -ENOSYS: stay on the from list * Other errno: put on ret_folios list */ switch(rc) { - case -ENOSYS: - /* Hugetlb migration is unsupported */ - nr_failed++; - stats->nr_failed_pages += nr_pages; - list_move_tail(&folio->lru, ret_folios); - break; case -ENOMEM: /* * When memory is low, don't bother to try to migrate @@ -1639,6 +1633,28 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, cond_resched(); + /* + * Large folio migration might be unsupported or + * the allocation might be failed so we should retry + * on the same folio with the large folio split + * to normal folios. + * + * Split folios are put in split_folios, and + * we will migrate them after the rest of the + * list is processed. + */ + if (!thp_migration_supported() && is_thp) { + nr_large_failed++; + stats->nr_thp_failed++; + if (!try_split_folio(folio, &split_folios)) { + stats->nr_thp_split++; + continue; + } + stats->nr_failed_pages += nr_pages; + list_move_tail(&folio->lru, ret_folios); + continue; + } + rc = migrate_folio_unmap(get_new_page, put_new_page, private, folio, &dst, pass > 2, force_lock, mode, reason, ret_folios); @@ -1650,36 +1666,9 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, * -EAGAIN: stay on the from list * -EDEADLOCK: stay on the from list * -ENOMEM: stay on the from list - * -ENOSYS: stay on the from list * Other errno: put on ret_folios list */ switch(rc) { - /* - * Large folio migration might be unsupported or - * the allocation could've failed so we should retry - * on the same folio with the large folio split - * to normal folios. - * - * Split folios are put in split_folios, and - * we will migrate them after the rest of the - * list is processed. - */ - case -ENOSYS: - /* Large folio migration is unsupported */ - if (is_large) { - nr_large_failed++; - stats->nr_thp_failed += is_thp; - if (!try_split_folio(folio, &split_folios)) { - stats->nr_thp_split += is_thp; - break; - } - } else if (!no_split_folio_counting) { - nr_failed++; - } - - stats->nr_failed_pages += nr_pages; - list_move_tail(&folio->lru, ret_folios); - break; case -ENOMEM: /* * When memory is low, don't bother to try to migrate