From patchwork Mon Aug 26 06:58:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13777225 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 73797C5321D for ; Mon, 26 Aug 2024 06:58:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A12C66B03DD; Mon, 26 Aug 2024 02:58:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 999056B03D2; Mon, 26 Aug 2024 02:58:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F8646B03D2; Mon, 26 Aug 2024 02:58:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 50E386B03D1 for ; Mon, 26 Aug 2024 02:58:38 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E9D371A0C60 for ; Mon, 26 Aug 2024 06:58:37 +0000 (UTC) X-FDA: 82493493474.04.D9DD478 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf01.hostedemail.com (Postfix) with ESMTP id 8A4BC40005 for ; Mon, 26 Aug 2024 06:58:34 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724655448; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OJTdXtQ1TUXxF9kEmOSf5Y2MFDegpTKFciOTdciQMi0=; b=ZhqfJARBrurvCqEbwUjsi63f4RJuAJGJVf/Ovn4YILal25PBEzJcBwwax+S1yPb2go6EvO 96iAPIxPYSzvg84QwEzQVBNCP6YJ06Z4Uxc6AMBcyVZroYlSTczbDNM89b1DW7Ngb7mzXS UjPJbDdN7gHn72s3/goRuHrdJM2Z7TI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724655448; a=rsa-sha256; cv=none; b=WHMwT28iuXdcGqqTwW/MlevsPrJ3e+70U1kUFxH13CoktpfavuBXCccUcgSpNN5wrdwRfh hGlR8hXCEvy6BRxj4OuiMjkgzTu7UrL6S0zoxg0KGIGZJ+IMkPxpxPxBeEblEnUVCyvCdc sVrAIyeZsGD7uwhsN/k/X9ex7PoYbrU= Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WshGc0XNrz20mgl; Mon, 26 Aug 2024 14:53:44 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 1153C18002B; Mon, 26 Aug 2024 14:58:31 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 26 Aug 2024 14:58:30 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Matthew Wilcox , Baolin Wang , Zi Yan , Alistair Popple , Jonathan Corbet , , Kefeng Wang Subject: [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio() Date: Mon, 26 Aug 2024 14:58:09 +0800 Message-ID: <20240826065814.1336616-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240826065814.1336616-1-wangkefeng.wang@huawei.com> References: <20240826065814.1336616-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf100008.china.huawei.com (7.185.36.138) X-Stat-Signature: 5erwfa68ex71u5tz34saaychkbyya6ep X-Rspam-User: X-Rspamd-Queue-Id: 8A4BC40005 X-Rspamd-Server: rspam02 X-HE-Tag: 1724655514-544110 X-HE-Meta: U2FsdGVkX18wVOPbxWJdXpvBH8Rq5ByQxCm8cYFrtW5D1el0CjJn44EwMqHO4ZpE4Q+jSAoFviBicPJQVqLtFr43ByZXF2fT9pY/Uj6NcTXTyLZ2u+RRHdl0iLEpM6z1rK0XDTQlr5D53SV0znV9GBOJr5ySzlPgS9uXER9t0kVVQW1Qfj5FOa60jY7ZRRcm7btK4u3tzmZ77UzMZbQHW6o4HCwMkhea+vPuDRAiqXlWITdyEfhSliyWt4nSkvDFZ400FwUw51G4cCB2YQJNEOaUEUqrJVnZTxR2My3OZP2DXPLNGTYQ9aLWMwu3TUHvgGHAMxULxWLy8yKMg6Xk4x/E36bvjbq09/JDEHPul3eNdHJuXaI2g4JHF1k5V6BhyNzUxpyez/AtgRnA+OmvW8ETmn4RmIuBECLOSCT7XR/fCzS4avaQoSI8Jel+W49/7DpOdqx1pKX2r2Yh7c2JMz72ldxdRKK6+xEbDVlHt+xrWeheSvFFts8OwC5ZmvftwdRJcYvj2D7lDqj+0PNfITMy1wRO6Zz6V9PhDBRJJ9cZGkKvcXbZsxtBOGA79+IZg34MPB+UuZsJrkbfH1rZ8mtcpi/7TvveM57a3duuBpBl/isKi5Ok0I8xS2tAzJazZ8JnGagD7g935Fz9sUDe/BsisHY70cQPtT73jpVdFESSbPEobxzJnLDVyXby5GvtbyIh42BUhJKWggbsJ4BimN7pAzrvAB+qMdQqsMzrVD03Ib644VNbgpbJUMVIjgjNhqN+HNrePayn57nhOzoHB78QWUjIwqr6FbTVXYn226Y3NqKOw0O1xLNnEveE3qr3nUv5EjxMQg90fViwXoPl6PALrmD4yv5xG9mKE1mhZIHSqmOYZgx2mI70tessXDLtjf1Kj5bGY7qEscriLEq9Q9gGMUpDvb2a6gn2WxlWf/R5pL8w66DjK5j8xThIB/Aes/znV0wjx0IGAP9E0Uo qBmGJHQt w8UfSjPxR52qoMBVUu7/BN+tD6953DFD2mNPUs4menVQGVzqomgxriRfQJTMJ0CYsv1ItMziHM+mv8mQdz6TxVdl98K+qSdvS2+zMyXrjRgC1v1TTYVuIK5nWfCLkEQX/vmpvzeO8YnxMeqodT5m5xV6Uk9VOQEkTHr0F5n7qaGYIB0WL4FMk9GG/axtk2GzlR49f4quMW2nrFdQnjJvpXvLjisCqb62j+7JHIz+2u1c7JGGB0gvYm3VrvdmZyZBoFFpi9GXO9FC33qSHJ+u2k986nD+WlCXsj8p5XWoiaG1K6i7rPNmk8pG2Ug== 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: List-Subscribe: List-Unsubscribe: Save few calls to compound_head() and use folio throughout. Signed-off-by: Kefeng Wang Acked-by: David Hildenbrand Reviewed-by: Vishal Moola (Oracle) Reviewed-by: Alistair Popple --- mm/gup.c | 2 +- mm/internal.h | 2 +- mm/migrate_device.c | 30 +++++++++++++++--------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index d19884e097fd..5defd5e6d8f8 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2335,7 +2335,7 @@ static int migrate_longterm_unpinnable_folios( folio_get(folio); gup_put_folio(folio, 1, FOLL_PIN); - if (migrate_device_coherent_page(&folio->page)) { + if (migrate_device_coherent_folio(folio)) { ret = -EBUSY; goto err; } diff --git a/mm/internal.h b/mm/internal.h index e1e139e412d1..0f4750f77f59 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1209,7 +1209,7 @@ int numa_migrate_check(struct folio *folio, struct vm_fault *vmf, int *last_cpupid); void free_zone_device_folio(struct folio *folio); -int migrate_device_coherent_page(struct page *page); +int migrate_device_coherent_folio(struct folio *folio); /* * mm/gup.c diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 6d66dc1c6ffa..82d75205dda8 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -708,7 +708,7 @@ static void __migrate_device_pages(unsigned long *src_pfns, /* * The only time there is no vma is when called from - * migrate_device_coherent_page(). However this isn't + * migrate_device_coherent_folio(). However this isn't * called if the page could not be unmapped. */ VM_BUG_ON(!migrate); @@ -921,38 +921,38 @@ int migrate_device_range(unsigned long *src_pfns, unsigned long start, EXPORT_SYMBOL(migrate_device_range); /* - * Migrate a device coherent page back to normal memory. The caller should have - * a reference on page which will be copied to the new page if migration is + * Migrate a device coherent folio back to normal memory. The caller should have + * a reference on folio which will be copied to the new folio if migration is * successful or dropped on failure. */ -int migrate_device_coherent_page(struct page *page) +int migrate_device_coherent_folio(struct folio *folio) { unsigned long src_pfn, dst_pfn = 0; - struct page *dpage; + struct folio *dfolio; - WARN_ON_ONCE(PageCompound(page)); + WARN_ON_ONCE(folio_test_large(folio)); - lock_page(page); - src_pfn = migrate_pfn(page_to_pfn(page)) | MIGRATE_PFN_MIGRATE; + folio_lock(folio); + src_pfn = migrate_pfn(folio_pfn(folio)) | MIGRATE_PFN_MIGRATE; /* * We don't have a VMA and don't need to walk the page tables to find - * the source page. So call migrate_vma_unmap() directly to unmap the - * page as migrate_vma_setup() will fail if args.vma == NULL. + * the source folio. So call migrate_vma_unmap() directly to unmap the + * folio as migrate_vma_setup() will fail if args.vma == NULL. */ migrate_device_unmap(&src_pfn, 1, NULL); if (!(src_pfn & MIGRATE_PFN_MIGRATE)) return -EBUSY; - dpage = alloc_page(GFP_USER | __GFP_NOWARN); - if (dpage) { - lock_page(dpage); - dst_pfn = migrate_pfn(page_to_pfn(dpage)); + dfolio = folio_alloc(GFP_USER | __GFP_NOWARN, 0); + if (dfolio) { + folio_lock(dfolio); + dst_pfn = migrate_pfn(folio_pfn(dfolio)); } migrate_device_pages(&src_pfn, &dst_pfn, 1); if (src_pfn & MIGRATE_PFN_MIGRATE) - copy_highpage(dpage, page); + folio_copy(dfolio, folio); migrate_device_finalize(&src_pfn, &dst_pfn, 1); if (src_pfn & MIGRATE_PFN_MIGRATE)