From patchwork Mon Jan 16 06:30:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13102659 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 1083DC54EBE for ; Mon, 16 Jan 2023 06:31:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A126B6B0080; Mon, 16 Jan 2023 01:31:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C2866B0081; Mon, 16 Jan 2023 01:31:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88AD66B0082; Mon, 16 Jan 2023 01:31:44 -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 7C1676B0080 for ; Mon, 16 Jan 2023 01:31:44 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8ED87C0661 for ; Mon, 16 Jan 2023 06:31:43 +0000 (UTC) X-FDA: 80359691286.12.B4FA095 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf04.hostedemail.com (Postfix) with ESMTP id 9AA5040018 for ; Mon, 16 Jan 2023 06:31:41 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UOZiXzIF; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 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=1673850701; 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=vdsTK1bdcdezS1W6DaCq42k2ayF2YQCiNcKK08kjjLM=; b=kumpo0tfmPrYFQKxCJWIl1ylJE3jdIz4RgJOx1EmwU06pzjUYtMdtP1nd0RPpxQEtCJTbW TmhynylmZwedcD043/WXkopAsPcshwlrHQp67GUUEgh3isRMxc34/LU3pfx2h6fmvQnW35 3V/O1HYxNmvJcYpy4R6msjybpgvamM0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UOZiXzIF; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673850701; a=rsa-sha256; cv=none; b=BbUVfIHxZ2dGygkMpFfluh05f7NyPouk5x/qV59KlA78wZkMjUsUnBrqXpD+0bdQM3cyeQ OieBzYuR1U72Fa7Ymeic47Wso1EggkMLBs20HTVS5xlJkoZRReWaqFmNg9Phhs7wzlwmoR SZ1y/jOqa2BHF3pLr4NzIjCHOUFK0l0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673850701; x=1705386701; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3J9a3YKiHmKyIA98tevHEicLgJhEATSgMLt7yTqcfnY=; b=UOZiXzIFZmarHiv1iwJrS7zikIqIYdQmT34BJQx3BBhU92M59ZG99/ns MF8YB7fhQmh5xePrEqaBzb6QrZ4JAc4KqDdubkQ6pIjPeniw2K+n7kHij Ezam8xh8Ry0FfYgs40xN97bnTI8NxPVv9MT74x/PGcXBGwwDuSpsQVknv 5okv4ehJHuiPmmyi6C2wVqdrK2yTGnqRDKnG6hwQEDQWhEs/SjsRax2+x vnWeHC8Wq/O14f74aWBE81kthdVbxL0FFyQ0nKe+rthU+MtWwQFcGk4rV 4xO5Ujujvpf7NYfX4rdbP6PzfSvThv1aTslKtOcvgNeRz/Kl8MqeLTJIn w==; X-IronPort-AV: E=McAfee;i="6500,9779,10591"; a="388892245" X-IronPort-AV: E=Sophos;i="5.97,220,1669104000"; d="scan'208";a="388892245" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2023 22:31:40 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10591"; a="801286715" X-IronPort-AV: E=Sophos;i="5.97,220,1669104000"; d="scan'208";a="801286715" Received: from tiangeng-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.220]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2023 22:31:37 -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 Subject: [PATCH -v3 9/9] migrate_pages: move THP/hugetlb migration support check to simplify code Date: Mon, 16 Jan 2023 14:30:57 +0800 Message-Id: <20230116063057.653862-10-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230116063057.653862-1-ying.huang@intel.com> References: <20230116063057.653862-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9AA5040018 X-Stat-Signature: cj5q88w1qwbhbmgfh4wwfwnz386w6gz1 X-HE-Tag: 1673850701-730699 X-HE-Meta: U2FsdGVkX1/fNZd6q/6wwWwt+NtN100vf8kKOEUcgcGdgG/iJe/1h48Rmj22RMazTcIEHd5Nf+Q1mjjfZc0WmL1uQFkkHuPTUYwV8/kfzLphWwF0vKSKB7DgMpIUjmOJFELwZeRyFJ4ILY4zlvM8YBq8K8rPY2j2XcNugewoKfxnflEUgpusqOJMR6ZMxoFv2KI9CN525izpBFV8ICTJ8G3Sq5O3FfdHh9bd9q1RFVORep0mpxcZy18/vas2t3LCZB9ouwaV/pFai583XKmhlXsRwmV5KLOrDltDU+7/E99iUhGG02yngCx8ntUXeTh5vW+QY4tlcoYRUYX9YEKxw1M0h4nvXTVIxGS7c1yeLSS7eIsq0UpyN6c4c8j02N0ku7H3jctfT/qWzaxZu0HsWwpKWIXXSbMs1MW3t900+9KLB/mATaRWLcKEXEBrV8bi8VQ/h+r36/auxSs2PfCET34BzGta1Wlf0TWZqKuQO+cx/TyN7CYXTCt8R4Y7qhTRknKimXGEQw4F9pNOGhjMVu0ZJPm7gCpt0Wzz/BitCurHcg3O9223h5Uaz2hnbL03RHi8z1JGsyfhHK06I7rv1A7F3KTFvmbY7567b58W3MDb0GORPGd4zUPLJWdIMXsSe5dle9+sheW7wf9qD07BWK9Hop05KNFXdimekkR3h/1CUEWUrFkltaHGnKfjHj1uDQwgv3PFU5G/HlOyGpxBJfpY02GmKC4ktqcqAOEuHehfRDmEYWb+bAMIVPMWYeKI7ffIYhaXvbcaS7hYj9eFpKe7RSVz9uKqKSpH8GvUxfUEBZCYtXQ9AB0w8rfbsL5oKkPmuesiiqqFbDgihmWNAa9MKeOlXE+yy/SUgCU2EPsXhevjA51VBd37a7Y/BHrWEeeP/yCW/sufT7Oda5jqOBx2USvFQr2vvr8ZTxahICN+afbFni5Zbn66thRx0Ks2lvk5wPLuGxE= 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 --- mm/migrate.c | 83 +++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 8ccb61c49188..9d390368cf3f 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); @@ -1358,16 +1355,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); @@ -1534,6 +1521,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, @@ -1543,16 +1544,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 @@ -1638,6 +1632,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); @@ -1649,36 +1665,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