From patchwork Tue Aug 22 00:53:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13360020 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 1DFA4EE4996 for ; Tue, 22 Aug 2023 00:54:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 843FF940008; Mon, 21 Aug 2023 20:54:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F45B940016; Mon, 21 Aug 2023 20:54:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E8B5940008; Mon, 21 Aug 2023 20:54:15 -0400 (EDT) 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 40598940016 for ; Mon, 21 Aug 2023 20:54:15 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 029D2160141 for ; Tue, 22 Aug 2023 00:54:14 +0000 (UTC) X-FDA: 81149919270.14.DB41BBA Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf16.hostedemail.com (Postfix) with ESMTP id 1554E18000D for ; Tue, 22 Aug 2023 00:54:12 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692665653; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1TrGZO3wr5saKYv6Q1F9WzGr6uTMiFtX/tOe2G0ZEm0=; b=avtFU7PxYmIItn+TVUKJPqCPxa8ssppXd/z1yS66Pf8qYJHzr6aUXOFOllIA0rKlFc2/3Y q9s+hcAKmLVt3QOMt/WSKUWlJJhY6FnkoKL2JayNKPV91aqu5mVjFimIjHm2s0yIY0IV1o 7h6F3jwQYd+B1+q3ZiqiRZKAtvKfGso= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692665653; a=rsa-sha256; cv=none; b=UmnuaWv7yQwOLh/itUJS5De+TnaZQrQa8mEHit+gLJ/I0Z1jWcPChz6uXSpCG85w7AvJrF pMLgny96szqy0IVE0u1bV/SgYV6pW/WJNhjMUG0m9Jp2i02IQO9jyEBvFHTX7YwTxKpqcT AjmBgkusv1SU4HorVKeVZkFDGPnrw+E= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R601e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VqK0DP4_1692665648; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VqK0DP4_1692665648) by smtp.aliyun-inc.com; Tue, 22 Aug 2023 08:54:08 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, shy828301@gmail.com, david@redhat.com, ying.huang@intel.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] mm: migrate: factor out migration validation into numa_page_can_migrate() Date: Tue, 22 Aug 2023 08:53:49 +0800 Message-Id: <6e1c5a86b8d960294582a1221a1a20eb66e53b37.1692665449.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 1554E18000D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pyy7hkpcoppn1rka6w43umaxs4geyqkw X-HE-Tag: 1692665652-655924 X-HE-Meta: U2FsdGVkX19/XUIX+ORwQhlKbbKYuVueQrGzhwK+eRY7stvjTDtTirGopiT2jHaEMMIDwsqtCFf8tV68e8WKxM0nvHbHhIKXhaYwZ2H9xkehKymRxyi6bUraMC9x6kqKtwb5H3JbCsiJrymq+nkAxac+JIk6BTyJm7SKIwdNE+IrCvzXAAAnXjYb43cGkp4lcSb9kzLLESoqgExJR5TWOGYwBYxkS1k6kGSAJdpABP+435a/WjWn0Q+EzmQeD4Rcyz807647xG8GLsranhZBBro/7gNYPoalTnpYBk6o/FRJeUphqTnS1NBuuTq8vatng2gF69BbbBw4Rrwc76qzpngHeLbSdnpkAYemHiTTP3yDajaVmFYyXs5NUEuvkBIKi2NJSbxqgmLX3tutIH8YrZOBrhq3ij1hnhiEZpKghZgDZpaljEsEmbFduhee7cDsW9SKfO6j/+/MauygfLEul5GCbo5sXcIDlkiAf03JpUyu6wzGp/IPqMcmIELRqMP8NyP8Aj559LWhKRyeA5+NyZwC9Hrz+knaRZpWxNcrXPBnKIBacptyAGa2J7OhpCsDCoAiSis9VpGr1P0rH3l+2lhesEPwFvGEgq61jYwAo8zYCvt3eWcOULmIC8UFT7x7I+jnPFEV/2jvXzPq+rsUscQdKNzBdauOPILD3vYNblHHtNh5NL6BJvDvYviM+DJALGAmXnEnM1nbxUQIoI+zKx7TybQ63P/GIPibk1uadBmVam5erUXMjdehx5soEKhCDNm/02BkX+LnENgiw554bv7sppN83w0s8ufV4NGUL69wwlhkrJQL1UFnsAvTOkFluLMkG5ShvgThH0qX+VLsRNM65iebEPmzyxCUL2u9ZcfRP7CeMHio8P9gDt7eL8msxwPIE+ZJOAb2ObRw9Dw/EJKjLS1GOS3wYqZ49CtclcSIyqe0KAsQMharq0kkrTkYUCYzoSjDgMRKuJJE7R5 ItxE/+kl 1a01x3+U4AwmZigl5OIje3emfyKjBm/CTlqIpd5ZjoLdgPIpm7W3j7n8n4qN6GY4ai4mIujT2syrYpCjFn/67vQWyn+HEDYRSqYgu+p2XxUosaxHElL+uneIBOKzPY043anrA+5i8phDWtiQ= 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: Now there are several places will validate if a page can migrate or not, so factoring out these validation into a new function to make them more maintainable. Signed-off-by: Baolin Wang --- mm/huge_memory.c | 6 ++++++ mm/internal.h | 1 + mm/memory.c | 30 ++++++++++++++++++++++++++++++ mm/migrate.c | 19 ------------------- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 4465915711c3..4a9b34a89854 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1540,11 +1540,17 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) spin_unlock(vmf->ptl); writable = false; + if (!numa_page_can_migrate(vma, page)) { + put_page(page); + goto migrate_fail; + } + migrated = migrate_misplaced_page(page, vma, target_nid); if (migrated) { flags |= TNF_MIGRATED; page_nid = target_nid; } else { +migrate_fail: flags |= TNF_MIGRATE_FAIL; vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); if (unlikely(!pmd_same(oldpmd, *vmf->pmd))) { diff --git a/mm/internal.h b/mm/internal.h index f59a53111817..1e00b8a30910 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -933,6 +933,7 @@ void __vunmap_range_noflush(unsigned long start, unsigned long end); int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, unsigned long addr, int page_nid, int *flags); +bool numa_page_can_migrate(struct vm_area_struct *vma, struct page *page); void free_zone_device_page(struct page *page); int migrate_device_coherent_page(struct page *page); diff --git a/mm/memory.c b/mm/memory.c index 12647d139a13..fc6f6b7a70e1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4735,6 +4735,30 @@ int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, return mpol_misplaced(page, vma, addr); } +bool numa_page_can_migrate(struct vm_area_struct *vma, struct page *page) +{ + /* + * Don't migrate file pages that are mapped in multiple processes + * with execute permissions as they are probably shared libraries. + */ + if (page_mapcount(page) != 1 && page_is_file_lru(page) && + (vma->vm_flags & VM_EXEC)) + return false; + + /* + * Also do not migrate dirty pages as not all filesystems can move + * dirty pages in MIGRATE_ASYNC mode which is a waste of cycles. + */ + if (page_is_file_lru(page) && PageDirty(page)) + return false; + + /* Do not migrate THP mapped by multiple processes */ + if (PageTransHuge(page) && total_mapcount(page) > 1) + return false; + + return true; +} + static vm_fault_t do_numa_page(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; @@ -4815,11 +4839,17 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); writable = false; + if (!numa_page_can_migrate(vma, page)) { + put_page(page); + goto migrate_fail; + } + /* Migrate to the requested node */ if (migrate_misplaced_page(page, vma, target_nid)) { page_nid = target_nid; flags |= TNF_MIGRATED; } else { +migrate_fail: flags |= TNF_MIGRATE_FAIL; vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); diff --git a/mm/migrate.c b/mm/migrate.c index e21d5a7e7447..9cc98fb1d6ec 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2485,10 +2485,6 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) VM_BUG_ON_PAGE(order && !PageTransHuge(page), page); - /* Do not migrate THP mapped by multiple processes */ - if (PageTransHuge(page) && total_mapcount(page) > 1) - return 0; - /* Avoid migrating to a node that is nearly full */ if (!migrate_balanced_pgdat(pgdat, nr_pages)) { int z; @@ -2533,21 +2529,6 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, LIST_HEAD(migratepages); int nr_pages = thp_nr_pages(page); - /* - * Don't migrate file pages that are mapped in multiple processes - * with execute permissions as they are probably shared libraries. - */ - if (page_mapcount(page) != 1 && page_is_file_lru(page) && - (vma->vm_flags & VM_EXEC)) - goto out; - - /* - * Also do not migrate dirty pages as not all filesystems can move - * dirty pages in MIGRATE_ASYNC mode which is a waste of cycles. - */ - if (page_is_file_lru(page) && PageDirty(page)) - goto out; - isolated = numamigrate_isolate_page(pgdat, page); if (!isolated) goto out;