From patchwork Tue Jan 10 07:53:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13094784 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 E78A7C46467 for ; Tue, 10 Jan 2023 07:54:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 822B08E000C; Tue, 10 Jan 2023 02:54:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AB698E0001; Tue, 10 Jan 2023 02:54:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FE808E000C; Tue, 10 Jan 2023 02:54:05 -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 47F6A8E0001 for ; Tue, 10 Jan 2023 02:54:05 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1785FC02BB for ; Tue, 10 Jan 2023 07:54:05 +0000 (UTC) X-FDA: 80338126050.02.C108E75 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf22.hostedemail.com (Postfix) with ESMTP id 2B170C000C for ; Tue, 10 Jan 2023 07:54:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Ks2QbPWd; spf=pass (imf22.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 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=1673337243; 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=mTIu/ye9xgr8iuDmI1qF4Y4bUkFIxhLO9oLQsAT1aRw=; b=WFjjoM878fLkNaq+gU6nTe0voe3fM7oNR3jPJGEDCLrxySFCp0AlR3AZWJcCDB4rbfq3Sj WQTuyARaCUec0N21FthDVov378jkNxwq1zxtGcmQgwaaflgzVndaaNfOgRCmXNAcawNtFu gAn6qQaraLOmlsEqffz2j+6f0piOPsc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Ks2QbPWd; spf=pass (imf22.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 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=1673337243; a=rsa-sha256; cv=none; b=2As2Z5JaPZpiAutmRQ+hyHnrJP7WVsdwvAfmxZhm9L1vKBGu/mJtFkFW96roT6IoHRpslN 7onKmgD2hKnZhSbuLV0dnkcRuT6lj82y2EymrNOG07ntTGrMnQUEG7Dy8Ms6s4eJDhrXTp vXoYbPIreoJrc/7LP6Kd74jjn8oNBJQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673337243; x=1704873243; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=apP3JU34KkC4d0lE7LZcTXIY/rJds9BktgkJCe0SGdY=; b=Ks2QbPWdXY6BmhyGhcsJM+bdKieWYo/7gBahoVoYWwk/TdObDRsKstnt T4RoynyCRzKfm2BL1jPXmpV01xllkxQdaEJ9ihZxIDATOF+Yq+7MDA9j+ s3ITq0TVY9ra3Q7YTUgUrZrDxgSxPOYHSdYtSZvcLFZLBOY8GCQYM+vx4 8MJw8s85s2/UmtetbnMbuevdgMWxb5wrmXEBR/J7XHGLUXCXwqpNjTtRu aEsGOFoyAxvQ74I3ZmyaSI1jug2uCi8LHXw27Lydqnu1vK6xdVGljOhx/ UVAh1ViKqN1NMc3+CuS8fZOpVcQH+XRalmlZo8BjYv6ezlmZegMogUwo9 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="303449396" X-IronPort-AV: E=Sophos;i="5.96,314,1665471600"; d="scan'208";a="303449396" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2023 23:54:02 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="902287197" X-IronPort-AV: E=Sophos;i="5.96,314,1665471600"; d="scan'208";a="902287197" Received: from juxinli-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.254.214.35]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2023 23:53:59 -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 Subject: [PATCH -v2 9/9] migrate_pages: move THP/hugetlb migration support check to simplify code Date: Tue, 10 Jan 2023 15:53:27 +0800 Message-Id: <20230110075327.590514-10-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230110075327.590514-1-ying.huang@intel.com> References: <20230110075327.590514-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2B170C000C X-Stat-Signature: eqzz6ngtj7cde4uoxfjz3ydn8rfw464m X-HE-Tag: 1673337242-830097 X-HE-Meta: U2FsdGVkX1/erGbMYkC8GHpPc8YEjfM9EVh6NysZgdOxPndkLLhQeOqRJQNqm4YU47JIcCoYQOZ7/UHX8yvZ92LuZTF9MY2JMgp5E14i6f6urlQsCT8I/23tY4nkZG0NsdzBtv864T0/emoUdIty1URq9dIJ7C4G5vWHCkwVImBIMYjIxmLuSVZeJvx5qpa6zCdUVOH2ByykIp27FmCMwAHF9mvijdKhPoNgsrZ2Ui8nNJe1julgsJeO2vImY32fRUr9EcNIgzCZ18r94dnsQeOgwc7nY35gyMZZSsZY6VpZYChjp3kdiQsFRkCPP9mBDEZfYClT/PPHKE/+ESs+Np6M478r831W7QmqpPhyC6jyuEwGbzIDtYPBvKTownduNFF2HzNNFgWIGZKBzRRBdILU+vI3MgmJ4XdRe4x1weX0m3/xnfCdo6O0fyXrXJlyA1tAWdy63Xmuuw8WwWC+stUW1wB+ofL0DGkPqb5UFPbdTJK7je/b/iiHxWIvKVxx0auYxLhhGCsrI5Yt0TT+b7VO5fPizqEIHSlWVKsG9okGV6plqSXouxpVfvDcLMAiAck9YTqCC9R4o+FAqBPVjE2OhTe1DrwrmfFPHrIOhG/jMIbrT81hx3C6XkMY3aHwcU6atUAP15seO5qXCpgSdH1GzwFhV9lkY6AjIFzNhNhrsIiz9L+lEDqv59burn/ar/RKrehumOXmUzwkTJzygCs2L41hvxdk7RLFtiz7pU7WLCTGaAQlvsqBQklE7OfNh2DAsT9Bai/1m3vs3T2F2IdfgRuE6m3YNQiUVjvnaOZZawznvXUkQYmcm38r4LM8AYItbcON0JqRsdwRkG5BrH0L75sCoWW0VVzA+/YLhKEyIqPqZj2uYwGi4p/ndvrPAr8HU/k+odwQvBASkSJT4o5/iLMYyv+csyZAU33HoT092370p46Zwm0VLRi8z05V 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 --- mm/migrate.c | 83 +++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 6adaea05b80a..7d4047be5a4a 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); @@ -1351,16 +1348,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); @@ -1527,6 +1514,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, @@ -1536,16 +1537,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 @@ -1631,6 +1625,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); @@ -1642,36 +1658,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