From nobody Sun Nov 24 20:38:59 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B760E1C304F for ; Thu, 21 Nov 2024 18:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215161; cv=fail; b=HSYm5DSDduIuVIZridZ1OvBH/c7+lOumgrAT22T4ggYt6YKcJd1IEeRo6GFEOkgzZRuTidhVfc50R/JG3CKIpT3yXj71s44zONsAuNnDtWkVb/IjFxDGRflgs9CSciXIZ90cw4Y0B6yX/pCDqMA3rGt7+QKX2760JWF5Vhag7iw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215161; c=relaxed/simple; bh=52LeFe1st1CjZTP86MLhQxrEOecrFkd5PTHPk+LkTMQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=GEAhHX627Fk/xrT/d1gFJ2qCDFRa+IYfuuvEofGXTTj/LJY6yxPBD0EhbnOjD3nTX7e72R8HvMDy2ypgf6/r3RAX5ZO74t6sbvz9yllmDPCcAoKZyP4rWgMBvZfJQ9WfnVq+PsHBFkMqNIqL/+L4VLJGTcGMixnAYa4cwNJFuys= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=pflVSGV1; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="pflVSGV1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=V6Oiu/F5cUK7JWG1+aTiMYohtzUqc+yeC9X/vZ82CMyBPQYekC6ivD6u2c/PAxxNem+eB8X1eJn7Bz7uoSqYTz6Qbng+ISSkcotBynt4FYk6fpxVqE1flvW+skpEV4P24TRUTk5y4mcV36xIXwcE1VYmTqeDDfEi5lezxaoZhHTsx/1GdnMnR4D51lgMVpA2ghFI98XBNRH+40xyenhJSwzDqth6aJ5PYFPR5taBs2uXv/4M8o2y1oyTmb1HlPA5NYi/GvJXdWDAp9N81RC6hzR0dHO3Vi6PC4mXlYuV5hvaPlKcfkuug+Z1bMXrx/NARpRpCXJrxz92v339mrZAzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TLbs+IMXe9PXriC98Ps/VfSjdrTeu2gdIoj8pxpjo7M=; b=SElSr3IqMFQbSgNmtVTFOEz0ODGy0twFE2AuWh39/I75mBTz+3moEsy6uvZS3fFI49dR41sHT7QUQlTYEa2ksRRWOvNM558KBLDRHmwJEYuUjT8d5dfjDmaXRCJr4l9iPZhxW6ttAw92eauS/+UzcBW8oAG8hFXMX0YDPENiyQbQWzNvwZrS74v3B+NAr5Fgs/qgnbI1lze6mgIrFLlmkZvcUOQrt81Xwe9TlH/wF9SLGjTMZFKpDmdgrGRz/v1tUjwbFSbxanHqihT7t9Na2hJ+ipJkB2kbNRSZUeEG6WwcwLmjiEqlOSpn+6JaVQzFGVKXRSQv9w+dYc4JA4RGMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TLbs+IMXe9PXriC98Ps/VfSjdrTeu2gdIoj8pxpjo7M=; b=pflVSGV1ix9YBhxJmvE+Tb1I2wbP1XJAKL/crjfiE3ZFkzMK7046QvWwIgxqMAkME6SJGgW6xlZXMB+vorwX9sMyyPPUNB2kQGSIe1Z0uth/F5dOjVDb0dQ+CIKIXkci11+ycizbUntSzxr5aD8zL+qzEHEjCb2oCdXuYH6r45qoqLRhYsZJuMOETLM8bRI1dNCx09dpTxRWWmJZcMDpLqo4X1ZaZdioLgtqTWC0ybs8e7ZSHGp/8v1CpUX7rRRs//8FQVi9NSnVb37gdhqOnZs1KUX/+jsjp/bb9M6PJ27aC2RUzn6CKuEgrhHKwk0BQwoKP6bB2b4qmp6QoOxnjA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:33 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:33 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 1/9] mm/huge_memory: add two new (not yet used) functions for folio_split() Date: Thu, 21 Nov 2024 13:52:12 -0500 Message-ID: <20241121185220.2271520-2-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0232.namprd13.prod.outlook.com (2603:10b6:208:2bf::27) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b892ab1-fb77-494a-70f5-08dd0a5da85c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?rYZ7i/cqgg4ynwSmUbyx4bJMIuT4lp84HfHTRlogUhNfRMKy3F0WoWN5O0m0?= =?us-ascii?Q?WanfgxEiqh5MksK12a9fKLHKvWBKtnz4cMEDmlz2/DqJmmwKpLe114iITtKf?= =?us-ascii?Q?Je46NByLla3fvbuufpv3YWIMVgFzjVnyZMg8t1dzc0JlVVacjU6PM7JLgg/u?= =?us-ascii?Q?gmL7PbafwSUDgdCBZx9m1cxszS4H6YipitTlOr70UsfkCT4cVuyle2hH/TxG?= =?us-ascii?Q?1BbwTZu/S7CUMCUKBUtNFGxC2YiBCkbhHpCSvvO5HiMncIXmONFvLH6CnlqJ?= =?us-ascii?Q?PNRd1ute3myXFpC53ckfbEN7UJidDui+gR/6sNd50ZqIfVJmAlmvAu4hlytM?= =?us-ascii?Q?My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k7?= =?us-ascii?Q?uZFXsz8cwcyc1XriRAL2MWKOEANTqpoNmsTkPLS+3dHUkQF7qR2kD1qAFxPY?= =?us-ascii?Q?wBoJPRx6GXE5fEDIPL/csTos?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?lVNdXfh6XZvufwtUUGmoaX9YaTAIhz4ZZoMld6q3g9TKPym24QFc+3tlCF7M?= =?us-ascii?Q?uHq76TJpvRIkF9Xqpdr6WuD5TJ5BPw4695lR7Wkui1lmBdoJkXLkmP0qvuXd?= =?us-ascii?Q?0ENP/oAjPT5gsJ8NoT9B9j1vGDgFtahLkYTY5MjVO+DK6uSYVqgcW1SL54pp?= =?us-ascii?Q?LOetngAqs0SN+qsurG+fCPWGuwH6YEMazZOOIfF+VJfNyonRinp7orIdXJjl?= =?us-ascii?Q?OQrZ1Mkv2XiYPwSrbkJF1tEEDQn/V++JKnGx8Sykk51mL3wEdY0a5j0RddxQ?= =?us-ascii?Q?dL+qN8Gr6+B08BlJCg0+D5iimylvCfaclZw8MHmLu81VPr7JtG6hPrXw+0ig?= =?us-ascii?Q?hurYgfegUsFBztkb1hMtdXUm23keSMd7vCZZwA2JS7cgw+7Y7qjKJUdqDKyk?= =?us-ascii?Q?Bls4L0Rsh2hcyQHXbryb7rm0SahGhGHKlrYn0pz3CBjB4o+swqFTehsqUXbK?= =?us-ascii?Q?8k4xMmRY9v1gQwnduXpLNoX9h55ORhsEedE4v6x2D3hONxvu0f/PcI16MEsq?= =?us-ascii?Q?1j7w7hbV2clbLTUPhTodv7rsjVR/QuvH//YZVu3DSZraBAxGrxwbDQngRNTh?= =?us-ascii?Q?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6XUJeQ/Gf3QiGLEj4Uf?= =?us-ascii?Q?Il91PBgrG9TIvDjgSoYe9DYoy/xvlNpvYD0u8VxahItLl8S4L9bNvi0uLThg?= =?us-ascii?Q?iHFIybmOBVsK6KGm+sI=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b892ab1-fb77-494a-70f5-08dd0a5da85c X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:33.0529 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tHvUHztjdJcmMBUKz+ji9uXBQKJmv1NkE0sNflb1CYpFNrE/4ByLRzJQfbAsfegm X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 Content-Type: text/plain; charset="utf-8" This is a preparation patch, both added functions are not used yet. The added __split_unmapped_folio() is able to split a folio with its mapping removed in two manners: 1) uniform split (the existing way), and 2) buddy allocator like split. The added __split_folio_to_order() can split a folio into any lower order. For uniform split, __split_unmapped_folio() calls it once to split the given folio to the new order. For buddy allocator split, __split_unmapped_folio() calls it (folio_order - new_order) times and each time splits the folio containing the given page to one lower order. Signed-off-by: Zi Yan --- mm/huge_memory.c | 361 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 360 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ee335d96fc39..5ebacb08996c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3127,7 +3127,6 @@ static void remap_page(struct folio *folio, unsigned = long nr, int flags) static void lru_add_page_tail(struct folio *folio, struct page *tail, struct lruvec *lruvec, struct list_head *list) { - VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); VM_BUG_ON_FOLIO(PageLRU(tail), folio); lockdep_assert_held(&lruvec->lru_lock); =20 @@ -3371,6 +3370,366 @@ bool can_split_folio(struct folio *folio, int calle= r_pins, int *pextra_pins) caller_pins; } =20 +static long page_in_folio_offset(struct page *page, struct folio *folio) +{ + long nr_pages =3D folio_nr_pages(folio); + unsigned long pages_pfn =3D page_to_pfn(page); + unsigned long folios_pfn =3D folio_pfn(folio); + + if (pages_pfn >=3D folios_pfn && pages_pfn < (folios_pfn + nr_pages)) + return pages_pfn - folios_pfn; + + return -EINVAL; +} + +/* + * It splits @folio into @new_order folios and copies the @folio metadata = to + * all the resulting folios. + */ +static int __split_folio_to_order(struct folio *folio, int new_order) +{ + int curr_order =3D folio_order(folio); + long nr_pages =3D folio_nr_pages(folio); + long new_nr_pages =3D 1 << new_order; + long index; + + if (curr_order <=3D new_order) + return -EINVAL; + + /* + * Skip the first new_nr_pages, since the new folio from them have all + * the flags from the original folio. + */ + for (index =3D new_nr_pages; index < nr_pages; index +=3D new_nr_pages) { + struct page *head =3D &folio->page; + struct page *new_head =3D head + index; + + /* + * Careful: new_folio is not a "real" folio before we cleared PageTail. + * Don't pass it around before clear_compound_head(). + */ + struct folio *new_folio =3D (struct folio *)new_head; + + VM_BUG_ON_PAGE(atomic_read(&new_head->_mapcount) !=3D -1, new_head); + + /* + * Clone page flags before unfreezing refcount. + * + * After successful get_page_unless_zero() might follow flags change, + * for example lock_page() which set PG_waiters. + * + * Note that for mapped sub-pages of an anonymous THP, + * PG_anon_exclusive has been cleared in unmap_folio() and is stored in + * the migration entry instead from where remap_page() will restore it. + * We can still have PG_anon_exclusive set on effectively unmapped and + * unreferenced sub-pages of an anonymous THP: we can simply drop + * PG_anon_exclusive (-> PG_mappedtodisk) for these here. + */ + new_head->flags &=3D ~PAGE_FLAGS_CHECK_AT_PREP; + new_head->flags |=3D (head->flags & + ((1L << PG_referenced) | + (1L << PG_swapbacked) | + (1L << PG_swapcache) | + (1L << PG_mlocked) | + (1L << PG_uptodate) | + (1L << PG_active) | + (1L << PG_workingset) | + (1L << PG_locked) | + (1L << PG_unevictable) | +#ifdef CONFIG_ARCH_USES_PG_ARCH_2 + (1L << PG_arch_2) | +#endif +#ifdef CONFIG_ARCH_USES_PG_ARCH_3 + (1L << PG_arch_3) | +#endif + (1L << PG_dirty) | + LRU_GEN_MASK | LRU_REFS_MASK)); + + /* ->mapping in first and second tail page is replaced by other uses */ + VM_BUG_ON_PAGE(new_nr_pages > 2 && new_head->mapping !=3D TAIL_MAPPING, + new_head); + new_head->mapping =3D head->mapping; + new_head->index =3D head->index + index; + + /* + * page->private should not be set in tail pages. Fix up and warn once + * if private is unexpectedly set. + */ + if (unlikely(new_head->private)) { + VM_WARN_ON_ONCE_PAGE(true, new_head); + new_head->private =3D 0; + } + + if (folio_test_swapcache(folio)) + new_folio->swap.val =3D folio->swap.val + index; + + /* Page flags must be visible before we make the page non-compound. */ + smp_wmb(); + + /* + * Clear PageTail before unfreezing page refcount. + * + * After successful get_page_unless_zero() might follow put_page() + * which needs correct compound_head(). + */ + clear_compound_head(new_head); + if (new_order) { + prep_compound_page(new_head, new_order); + folio_set_large_rmappable(new_folio); + + folio_set_order(folio, new_order); + } + + if (folio_test_young(folio)) + folio_set_young(new_folio); + if (folio_test_idle(folio)) + folio_set_idle(new_folio); + + folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); + } + + if (!new_order) + ClearPageCompound(&folio->page); + + return 0; +} + +/* + * It splits an unmapped @folio to lower order smaller folios in two ways. + * @folio: the to-be-split folio + * @new_order: the smallest order of the after split folios (since buddy + * allocator like split generates folios with orders from @fol= io's + * order - 1 to new_order). + * @page: in buddy allocator like split, the folio containing @page will be + * split until its order becomes @new_order. + * @list: the after split folios will be added to @list if it is not NULL, + * otherwise to LRU lists. + * @end: the end of the file @folio maps to. -1 if @folio is anonymous mem= ory. + * @xas: xa_state pointing to folio->mapping->i_pages and locked by caller + * @mapping: @folio->mapping + * @uniform_split: if the split is uniform or not (buddy allocator like sp= lit) + * + * + * 1. uniform split: the given @folio into multiple @new_order small folio= s, + * where all small folios have the same order. This is done when + * uniform_split is true. + * 2. buddy allocator like split: the given @folio is split into half and = one + * of the half (containing the given page) is split into half until the + * given @page's order becomes @new_order. This is done when uniform_sp= lit is + * false. + * + * The high level flow for these two methods are: + * 1. uniform split: a single __split_folio_to_order() is called to split = the + * @folio into @new_order, then we traverse all the resulting folios on= e by + * one in PFN ascending order and perform stats, unfreeze, adding to li= st, + * and file mapping index operations. + * 2. buddy allocator like split: in general, folio_order - @new_order cal= ls to + * __split_folio_to_order() are called in the for loop to split the @fo= lio + * to one lower order at a time. The resulting small folios are process= ed + * like what is done during the traversal in 1, except the one containi= ng + * @page, which is split in next for loop. + * + * After splitting, the caller's folio reference will be transferred to the + * folio containing @page. The other folios may be freed if they are not m= apped. + * + * In terms of locking, after splitting, + * 1. uniform split leaves @page (or the folio contains it) locked; + * 2. buddy allocator like split leaves @folio locked. + * + * + * For !uniform_split, when -ENOMEM is returned, the original folio might = be + * split. The caller needs to check the input folio. + */ +static int __split_unmapped_folio(struct folio *folio, int new_order, + struct page *page, struct list_head *list, pgoff_t end, + struct xa_state *xas, struct address_space *mapping, + bool uniform_split) +{ + struct lruvec *lruvec; + struct address_space *swap_cache =3D NULL; + struct folio *origin_folio =3D folio; + struct folio *next_folio =3D folio_next(folio); + struct folio *new_folio; + struct folio *next; + int order =3D folio_order(folio); + int split_order; + int start_order =3D uniform_split ? new_order : order - 1; + int nr_dropped =3D 0; + int ret =3D 0; + bool stop_split =3D false; + + if (folio_test_anon(folio) && folio_test_swapcache(folio)) { + /* a swapcache folio can only be uniformly split to order-0 */ + if (!uniform_split || new_order !=3D 0) + return -EINVAL; + + swap_cache =3D swap_address_space(folio->swap); + xa_lock(&swap_cache->i_pages); + } + + if (folio_test_anon(folio)) + mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1); + + /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ + lruvec =3D folio_lruvec_lock(folio); + + /* + * split to new_order one order at a time. For uniform split, + * folio is split to new_order directly. + */ + for (split_order =3D start_order; + split_order >=3D new_order && !stop_split; + split_order--) { + int old_order =3D folio_order(folio); + struct folio *release; + struct folio *end_folio =3D folio_next(folio); + int status; + + /* order-1 anonymous folio is not supported */ + if (folio_test_anon(folio) && split_order =3D=3D 1) + continue; + if (uniform_split && split_order !=3D new_order) + continue; + + if (mapping) { + /* + * uniform split has xas_split_alloc() called before + * irq is disabled, since xas_nomem() might not be + * able to allocate enough memory. + */ + if (uniform_split) + xas_split(xas, folio, old_order); + else { + xas_set_order(xas, folio->index, split_order); + xas_set_err(xas, -ENOMEM); + if (xas_nomem(xas, GFP_NOWAIT)) + xas_split(xas, folio, old_order); + else { + stop_split =3D true; + ret =3D -ENOMEM; + goto after_split; + } + } + } + + /* complete memcg works before add pages to LRU */ + split_page_memcg(&folio->page, old_order, split_order); + split_page_owner(&folio->page, old_order, split_order); + pgalloc_tag_split(folio, old_order, split_order); + + status =3D __split_folio_to_order(folio, split_order); + + if (status < 0) { + stop_split =3D true; + ret =3D -EINVAL; + } + +after_split: + /* + * Iterate through after-split folios and perform related + * operations. But in buddy allocator like split, the folio + * containing the specified page is skipped until its order + * is new_order, since the folio will be worked on in next + * iteration. + */ + for (release =3D folio, next =3D folio_next(folio); + release !=3D end_folio; + release =3D next, next =3D folio_next(next)) { + /* + * for buddy allocator like split, the folio containing + * page will be split next and should not be released, + * until the folio's order is new_order or stop_split + * is set to true by the above xas_split() failure. + */ + if (page_in_folio_offset(page, release) >=3D 0) { + folio =3D release; + if (split_order !=3D new_order && !stop_split) + continue; + } + if (folio_test_anon(release)) { + mod_mthp_stat(folio_order(release), + MTHP_STAT_NR_ANON, 1); + } + + /* + * Unfreeze refcount first. Additional reference from + * page cache. + */ + folio_ref_unfreeze(release, + 1 + ((!folio_test_anon(origin_folio) || + folio_test_swapcache(origin_folio)) ? + folio_nr_pages(release) : 0)); + + if (release !=3D origin_folio) + lru_add_page_tail(origin_folio, &release->page, + lruvec, list); + + /* Some pages can be beyond EOF: drop them from page cache */ + if (release->index >=3D end) { + if (shmem_mapping(origin_folio->mapping)) + nr_dropped++; + else if (folio_test_clear_dirty(release)) + folio_account_cleaned(release, + inode_to_wb(origin_folio->mapping->host)); + __filemap_remove_folio(release, NULL); + folio_put(release); + } else if (!folio_test_anon(release)) { + __xa_store(&origin_folio->mapping->i_pages, + release->index, &release->page, 0); + } else if (swap_cache) { + __xa_store(&swap_cache->i_pages, + swap_cache_index(release->swap), + &release->page, 0); + } + } + xas_destroy(xas); + } + + unlock_page_lruvec(lruvec); + + if (folio_test_anon(origin_folio)) { + if (folio_test_swapcache(origin_folio)) + xa_unlock(&swap_cache->i_pages); + } else + xa_unlock(&mapping->i_pages); + + /* Caller disabled irqs, so they are still disabled here */ + local_irq_enable(); + + if (nr_dropped) + shmem_uncharge(mapping->host, nr_dropped); + + remap_page(origin_folio, 1 << order, + folio_test_anon(origin_folio) ? + RMP_USE_SHARED_ZEROPAGE : 0); + + /* + * At this point, folio should contain the specified page. + * For uniform split, it is left for caller to unlock. + * For buddy allocator like split, the first after-split folio is left + * for caller to unlock. + */ + for (new_folio =3D origin_folio, next =3D folio_next(origin_folio); + new_folio !=3D next_folio; + new_folio =3D next, next =3D folio_next(next)) { + if (uniform_split && new_folio =3D=3D folio) + continue; + if (!uniform_split && new_folio =3D=3D origin_folio) + continue; + + folio_unlock(new_folio); + /* + * Subpages may be freed if there wasn't any mapping + * like if add_to_swap() is running on a lru page that + * had its mapping zapped. And freeing these pages + * requires taking the lru_lock so we do the put_page + * of the tail pages after the split is complete. + */ + free_page_and_swap_cache(&new_folio->page); + } + return ret; +} + /* * This function splits a large folio into smaller folios of order @new_or= der. * @page can point to any page of the large folio to split. The split oper= ation --=20 2.45.2 From nobody Sun Nov 24 20:38:59 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1709D1D47A3 for ; Thu, 21 Nov 2024 18:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215163; cv=fail; b=DTdZWJWhJ/Bd9Uc8bSeP5jcA/2eC0dMu4a3eJMKdW7NgcmKgmm0WAI4v9vSe3TRyTfaCGxT6B7Rm4Dy3XL6Z3J5TpQDjmbc5oHC0/oTAOmuWH+xLOK2Yg/zSP0lraNKdHjolUPMlP/Dq+f4LSxSzP2RzgTqP2x8kVUTigrxyPvM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215163; c=relaxed/simple; bh=Yy+A9Yr+hnITc6YKDbfa/rAKJzyPwCc8S+VelwsesI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=jPm1suV2wqrOzBqAff1RHQmBg9UReollwri6TLBg6hm6oPfJp802LHsXlXgL2RvbevIOHQo25krxVchtflamqbs0/7GBGjwgj0VQ1IuV4KQlxoUaYxtcK6GL5aTo68UwGb5mNc7sYvHZzo96/OWmwhCSC3w1/u3to347R1Cb2lQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=A3/06sLp; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="A3/06sLp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AmALoBOBwuJXwFsYxXtrj73eSaJGhhqIl2AYd+2rgOzBP4h4IlOaHyzWAZn0nRciR06JQna9VourxylGHurVQG/iTkuG5OAc+NN5tV58WNt4fP7v8lq+m0af232zZc8B40Hd57cEKD1T06y4N4YBh5ZiUEDAXcyQ0mYwwKIArD1rCxSu9XEHmhekh11rubT1Wtyza7T/42LPBTIViamTwW6yX3PUnlyMYV++XjSeTkI9D/Fmjp5Hmfe2cMfvrHYxo2kJuM2JXyB9atmlRjq+ag1ziXuOf70rmfiMANFawEnwIxb+t8tF3UYaBdYCBOjsQhZdj/6RKCen2/oANTgE5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=W0CJZaAm63MVG5+J1rG+OLe2VO73aCelqREx4pG3Mto=; b=CyDgbN6NBjRA+3XW5/dxRMm9HxKHqPr1lL38M+W+u/0aUNia9sjn15dZQbXcIHP5sSCvoVrv5bz08hwBqaodTEMfPZLbYTulj5BhgK/Y9xLdV/Lbclw7GT9fKmHh2G2yp0Cj5CFwAXQykSf++FNv9zt5Y/quKertnsm9rkQzn5phpPNh2MxiJHfZzqEyWmALIXSu+PkzPf/7+5wNNR0TXP5QX2qKnr6QkJ51NE1VcpgjWnqVhSTyvHuphNs6yBXycaxnLc40Huugv+gkSMyNDNP3LpUb0PUgkPVgYO8yqKD9JyJPY3PKhBwNF17lmkljtRhVmOHYaHAFvNLPlC4AlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W0CJZaAm63MVG5+J1rG+OLe2VO73aCelqREx4pG3Mto=; b=A3/06sLpINui42nZaVyXDbXMQj/U/ejC4kqDlDn2M5x5nCq1a1GkhtQolfHg2vw7q7fvDQfIKlA+lJzfwrGpyLf4Z4ebhd0gvVJcfjDE32kPwgeXBd0DBhgcMed6khQT8K3FxhwfKXWFM4qFvJmFgQIggGcX9r6tuiEmZdC267MNaIjBDW/gZ58pUHJm243dYrnrSUnlcRTZAZX3IzX/s/OQNPdxl71CcNyeM9duiFbJYQOcAr5eUHrgEhO5jvgG5bXUHp9Esl/HdjrH9HaLc5RFSMOfTSLlDTDgj2/zrB9UH2UeC479sQQPO8xsHA9Fd6vIqOQtZqAF+TalWxIXaQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:34 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:34 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 2/9] mm/huge_memory: move folio split common code to __folio_split() Date: Thu, 21 Nov 2024 13:52:13 -0500 Message-ID: <20241121185220.2271520-3-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0223.namprd13.prod.outlook.com (2603:10b6:208:2bf::18) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: 270fb2ca-224e-4c6f-a130-08dd0a5da8ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?IsXydhsNooxn9h5at1A1xmgeswTKANPPvUdk/r69MEhU7lyRShEWJPAPL9MI?= =?us-ascii?Q?XRbM8/pFEhZYV4rBVz6O0gDwwGHhGmmXSrSeZBxRaK4JfTNp8uCPwQptOmqx?= =?us-ascii?Q?fJVCLEPbwoZnrH9FLVky0aHMXafQB22uPQvp2aCIhEsnZ+dia3suSKaEQzbo?= =?us-ascii?Q?StNsoU56sMYif9X0wXsBPkTQ0KbmFNUuJLNwPM7kpkowDdfI1RFmFi+EZ3Xx?= =?us-ascii?Q?J54tpSAoXH7q39JFQtZVs+HojuyuJmltS5CyFce8726vapaXiQ/aFU6zrIFP?= =?us-ascii?Q?2WmbEecYMU8kFlv+hLYE0lKYjr6XdAsBHZDGOP4wEZB6Un+4PMzoeqnZ5Sff?= =?us-ascii?Q?OwR5n+arpQ00NyjufE9m2UsWtspaqg6UalobiaFXce+YiueATp/lFSB/0jeG?= =?us-ascii?Q?fhmRbMz/9ZUtvF2aZJezbVIQdsQjQU7CJLaDg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BA+xpFF2A3qOKC2?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?TLxyvPAbo0JHzTWkFI0Eut8ThgF0klLBl8Q7ymJ0EYGo+wEexjomTgidppq3?= =?us-ascii?Q?/Xg/JHsyiAqS6QbhlDuBO07IedEaKOZe4a77G/Iq6GS3uI95hW9mevBy6mHY?= =?us-ascii?Q?M5jxxCVXhTHGPKlYabdVmv5zc0ktx9CjYKn/RlESiRpX3fV4+i6kcIk2J603?= =?us-ascii?Q?2BG0AKrI4aPpehK31uuEv5usnF2TACSxiNvFASpn9kmaNIklxh8wjFGU5ZF4?= =?us-ascii?Q?8bhV87ofxBQ2RImAaI+iV0xhWdjQHRMgGMDwvzlSrcuFrmm8/OHOxi7CgJww?= =?us-ascii?Q?aGJX9xdUfB+X06ZqBfRNAxDZpJJ3Le9/+3G6iy/X+mzJOmZjQxovt060Xm28?= =?us-ascii?Q?phIwoMr6eVZiG2c5Bf77fRysDDFwihX70UczFIXTIQNpBlHhibJuhQQ42bIh?= =?us-ascii?Q?CC8qQB4hkjoDUxx2RfvPKWk5j0vm3xpKQNbhux09sOBNfaV9II8mBkYzUucX?= =?us-ascii?Q?berPGM1xZbjGzTcHzt0xGVURDf2S6inhts55mObfb/TRYMBpggRJ0ro8TzlM?= =?us-ascii?Q?+znNpqXzlenH1C9q+NA6xUAnEroEeiSkHI+f9srzs+PLvXGaz5l1wk1L31er?= =?us-ascii?Q?wPlRQySI4rAUXiqoYlDHkc09cnoG9GaH/HQNyI3irZjMxRZ8kKaEd19puz2I?= =?us-ascii?Q?Ps2KUi/zw+RMqNk0Ip4TIjmWrruQdB3p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N+0RNFiOWsS6SwSI98PC2sIN/Y2xvt?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 270fb2ca-224e-4c6f-a130-08dd0a5da8ea X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:33.9765 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: owOOkHLeKAoXCOvfnwkVxHK6+w0sXl5ofZ28Ieg0zUKY54Nwr/UWzIkpfXfZ0w+c X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 Content-Type: text/plain; charset="utf-8" This is a preparation patch for folio_split(). In the upcoming patch folio_split() will share folio unmapping and remapping code with split_huge_page_to_list_to_order(), so move the code to a common function __folio_split() first. Signed-off-by: Zi Yan --- mm/huge_memory.c | 107 +++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 5ebacb08996c..65dd2a383e29 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3730,57 +3730,9 @@ static int __split_unmapped_folio(struct folio *foli= o, int new_order, return ret; } =20 -/* - * This function splits a large folio into smaller folios of order @new_or= der. - * @page can point to any page of the large folio to split. The split oper= ation - * does not change the position of @page. - * - * Prerequisites: - * - * 1) The caller must hold a reference on the @page's owning folio, also k= nown - * as the large folio. - * - * 2) The large folio must be locked. - * - * 3) The folio must not be pinned. Any unexpected folio references, inclu= ding - * GUP pins, will result in the folio not getting split; instead, the c= aller - * will receive an -EAGAIN. - * - * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not - * supported for non-file-backed folios, because folio->_deferred_list,= which - * is used by partially mapped folios, is stored in subpage 2, but an o= rder-1 - * folio only has subpages 0 and 1. File-backed order-1 folios are supp= orted, - * since they do not use _deferred_list. - * - * After splitting, the caller's folio reference will be transferred to @p= age, - * resulting in a raised refcount of @page after this call. The other page= s may - * be freed if they are not mapped. - * - * If @list is null, tail pages will be added to LRU list, otherwise, to @= list. - * - * Pages in @new_order will inherit the mapping, flags, and so on from the - * huge page. - * - * Returns 0 if the huge page was split successfully. - * - * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if - * the folio was concurrently removed from the page cache. - * - * Returns -EBUSY when trying to split the huge zeropage, if the folio is - * under writeback, if fs-specific folio metadata cannot currently be - * released, or if some unexpected race happened (e.g., anon VMA disappear= ed, - * truncation). - * - * Callers should ensure that the order respects the address space mapping - * min-order if one is set for non-anonymous folios. - * - * Returns -EINVAL when trying to split to an order that is incompatible - * with the folio. Splitting to order 0 is compatible with all folios. - */ -int split_huge_page_to_list_to_order(struct page *page, struct list_head *= list, - unsigned int new_order) +static int __folio_split(struct folio *folio, unsigned int new_order, + struct page *page, struct list_head *list) { - struct folio *folio =3D page_folio(page); struct deferred_split *ds_queue =3D get_deferred_split_queue(folio); /* reset xarray order to new order after split */ XA_STATE_ORDER(xas, &folio->mapping->i_pages, folio->index, new_order); @@ -3996,6 +3948,61 @@ int split_huge_page_to_list_to_order(struct page *pa= ge, struct list_head *list, return ret; } =20 +/* + * This function splits a large folio into smaller folios of order @new_or= der. + * @page can point to any page of the large folio to split. The split oper= ation + * does not change the position of @page. + * + * Prerequisites: + * + * 1) The caller must hold a reference on the @page's owning folio, also k= nown + * as the large folio. + * + * 2) The large folio must be locked. + * + * 3) The folio must not be pinned. Any unexpected folio references, inclu= ding + * GUP pins, will result in the folio not getting split; instead, the c= aller + * will receive an -EAGAIN. + * + * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not + * supported for non-file-backed folios, because folio->_deferred_list,= which + * is used by partially mapped folios, is stored in subpage 2, but an o= rder-1 + * folio only has subpages 0 and 1. File-backed order-1 folios are supp= orted, + * since they do not use _deferred_list. + * + * After splitting, the caller's folio reference will be transferred to @p= age, + * resulting in a raised refcount of @page after this call. The other page= s may + * be freed if they are not mapped. + * + * If @list is null, tail pages will be added to LRU list, otherwise, to @= list. + * + * Pages in @new_order will inherit the mapping, flags, and so on from the + * huge page. + * + * Returns 0 if the huge page was split successfully. + * + * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if + * the folio was concurrently removed from the page cache. + * + * Returns -EBUSY when trying to split the huge zeropage, if the folio is + * under writeback, if fs-specific folio metadata cannot currently be + * released, or if some unexpected race happened (e.g., anon VMA disappear= ed, + * truncation). + * + * Callers should ensure that the order respects the address space mapping + * min-order if one is set for non-anonymous folios. + * + * Returns -EINVAL when trying to split to an order that is incompatible + * with the folio. Splitting to order 0 is compatible with all folios. + */ +int split_huge_page_to_list_to_order(struct page *page, struct list_head *= list, + unsigned int new_order) +{ + struct folio *folio =3D page_folio(page); + + return __folio_split(folio, new_order, page, list); +} + int min_order_for_split(struct folio *folio) { if (folio_test_anon(folio)) --=20 2.45.2 From nobody Sun Nov 24 20:38:59 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11DE81D86EC for ; Thu, 21 Nov 2024 18:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215165; cv=fail; b=Rc/33KnpAtQBWOM4qDCVa6cFCplWUQAY9aPytAfUt/h6Gl4MJnKNS4K7O9gAnDuLxBs/hzF3H/KuScKvgsr65AuvX/Qi5DBIB+AAF4izDUU/y7p0y9dBdaiKbFdf39WzNQXPnieWMkZkSgaJteSJZ0aBZKlvHb3B/p9V2AdqTYM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215165; c=relaxed/simple; bh=3MQJz7ztXelZ/7Z8AyHLJa7KXq36Vn4IiZtpTiEns4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=OYwB5AgaRdYu71ZDVltY6fQRH7t3Rov3mrzsk2AbWyLntbHJltqi8DgdWzN8ntKoFFixw66Fq8TdBxf67uFER2lefHY9jhBo2vW1bClIHvtusctCNSzi0Gi+uSvBVYG883IYi2/SDDomHQFWSy19lp7RLjgnyHgSAh6sU/dw90Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=s2bpx/VE; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="s2bpx/VE" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CRIWmgE2MlO0UrKdo8G+8P2lSSwDRe6abG0imrtZFXqpGMFSlcE8lH4oOY4M9E+SNbuPqG2Z++0KPqHW3YoaSkdMCUU160Yq45tyogj1BGEeFT+zeutFA9Q7qyD0ken41euypr10R1ssRZ9E5LQlNLV+HXuE96WNiSgmtzN0IDHK8jZKqkqUroj0rS103+BmMXyc/faUZst9GTYgPlOeNz2PGqJdh+836rv30MDM7W+JJunTq7SA3hDuUYxZEIrm2/B9TCsxTqCtnH3pNJx4b2gjWP1eb7S5Q1op2MViE+bkoExoUpWW7yeFlzDYg4I86nHlHkD/bNc9VWcrfjTgdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ts7Qc9/C05pLsaXYWIu3CbN2/lxdspXHxDrSlMv5iU0=; b=rja76Xrl5iDNrn+XHZhknkXnBPgXIGT5QzvRzdrArlnUQ98bSrre2eHOAp//y/2OKiIwMt3gKuUW0l5UOSqclyrxRIx8+Xq8C525Yop9XGouFlyq/uOWZRriI1jL25AYsaTeVk5uRd4Y3wIyVuFIByVCcXL69dTs+RpP1vf1mWSpIz3XAwIonj6MSGt2Ud7cyY3OWP/MaCTYdp+1Hs56vb/jOEh71NGgSnLcwQp22s8R/M9Er1RuPrywmU5+Dkt5gMDiU/ATKAWuQPKhgAOF+2w3DKEe8ol20PaoEQB0beCv7/m+O2RrMdCeluv9bh9GJTjRoGLDU3kGX6+o3txA8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ts7Qc9/C05pLsaXYWIu3CbN2/lxdspXHxDrSlMv5iU0=; b=s2bpx/VENLghMTFsEFYu79KDdXfHc/BB8xPy3KAk8B8P4GNcenGgg9R/xkLPORDdfj7qnWl4kZ2tqRK/BnT7N7nFVpdBERGYQIHXnzVXyRIq4nLrBh+QT+H6nMuKBIrk5UtxnbRHtIe9TrwbIT59DbkAiqEBKZU/eBvmnElIzCdrIQUNvo3a6t91puAjcP2eCQgUUS8ckMlBW0ShNNh7AbLzTOtAvCwepotJ/xEz2y6uWOAIHB3HAWraAHAz5FT8xHe9fLlDg8sXu3AX3BIIhdswtTwMN0qpQnpdUrh9MuBYnDh7F2tGg9m5Yld3tsKDpRx7p5RiAlDvy2L6aEv04Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:35 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:35 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 3/9] mm/huge_memory: add buddy allocator like folio_split() Date: Thu, 21 Nov 2024 13:52:14 -0500 Message-ID: <20241121185220.2271520-4-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0231.namprd13.prod.outlook.com (2603:10b6:208:2bf::26) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: c8da9061-af52-4db3-a33f-08dd0a5da9ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?RhqHIy1oK8JKs4lAjUjUkY//sTJ9NB5RDT5/nRwvy6QEh6d82MnWO14Pme+c?= =?us-ascii?Q?A5aLcYOjV+fNO8nV24U9fGTIxBCq3sd8iLC/34WN2xWd9MezDTHNGmD9rkV+?= =?us-ascii?Q?Xv0mLnfIQtGUbejpOONPLbwFDB2K1t+/OgpX2Ox7Y6vOYHgRSimTDALk3UgC?= =?us-ascii?Q?9mRZ5xvqCZ+NRxck7fQHHdpFrnpU0xnRpeCPh0fCNOkgLT8g1TeDwgOPeie1?= =?us-ascii?Q?YP72Bi1QIP0kRVhxSyRw5zsuW/XDsfIUTpL+MPz9VEW7ohKRZiC7ydU1Pn5d?= =?us-ascii?Q?zE9LkjCj8UhuBoGWWfVyNKeoumO4ZgYEtGJNZjJ6rRGO4s6+SH7kqiFNmZR4?= =?us-ascii?Q?GZlUUvldAAJq2D5j08O2aIzEXS2itXZaA0I1fperQVLJpi74aCqSx1fgbYCC?= =?us-ascii?Q?ya8GenNosF0BblHixL88mRNc8SCsWowqHx0xNIgHavUqTV1tlF0/iNBKiYbs?= =?us-ascii?Q?H0ESd6z8vmnpWbtPmjrjHo51JshQ6qOU/hO/+6O+V+bKKUY13XKUsReIa5/9?= =?us-ascii?Q?aAkafxgGik5E+Amy2BcGVSUpoLAMJ1TzdMJS9zEQ7GM5EFijkasSNM9Ta5fn?= =?us-ascii?Q?TErO4pv3ghW0SGblFl96tWUYTQ7Lr3ZGHM0+pKTWGAWxtuzsmUydyuz6fAfV?= =?us-ascii?Q?0cGKaauPFmV1BvPDi1lo6cHg1XWGtVMgRHc4LIlXRgvVMvh9xR2sK9vlYOT2?= =?us-ascii?Q?nSp+Xb0Hx5Zz185ESXwi4nHX5T41ER1WlUnRIIjMkDoVfRfolLBc3LlpZ03B?= =?us-ascii?Q?/o1oaeepjbjwmpdsDR4lwkh/lSlb+VYfiBYv4CBy3Sb8vvoEmla6Y/YQMyvu?= =?us-ascii?Q?N9/d0ncKEfz+O+OoVFQ8y14PoKdXA332wbwchTJF2kwTsRmWRf2GiGt/6UkN?= =?us-ascii?Q?CFCwiBN/39bRp4Yv/t96rEXbr903AJCErT9PYxoTSkFdaZh1Bsg3M75tg+Yn?= =?us-ascii?Q?qiiHMi6fO3R2CnaXNRRMoSomkbeduNjoFigGfFNlNmrr0EBZ9NYW/twEC7QE?= =?us-ascii?Q?mpTqGd/X6PylPViD2YYNsTlIHLDfQwPTypNd8ivA2nh1cCHtmV0WmYyHxS5w?= =?us-ascii?Q?JbaOym/CNMHl4vrUpDFHTDcerqrm0/0YWgesGRWwu0mJTOX87z2eXSTdAg2s?= =?us-ascii?Q?O6ijiJvTNYMhs1Bs+InB5GkyC1lIiYy+1PC3CU7O8pT9D7OtAttV+jva4Y4M?= =?us-ascii?Q?wPqSUyBfpJVmaXnBsV2RyXlMGj+rpUWaEpfCKxhgKIokFNGhy1N8Gsw5lxAH?= =?us-ascii?Q?NfiT57/mRGOguQkkLCAdmCgF9R8vBhUX5Qyu3bOM84r+dgMJbSOcuRbbU/IA?= =?us-ascii?Q?nkQQeXVBM643pjy3yWR8cjOM?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?MF7noa2DQX4uZPEfYUIBjyUSf3WZZI/IGvHOMFwF15TJzS40HUUQwwGnqZOU?= =?us-ascii?Q?MNz0RSFWcjoyIPaNVf4qXH0bgtqSg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?Q?YqKx2sS2ISF2Mu/DBWxyOuYkHGOCkeF8SHiNogs3Miuvxkg8PS5Vv3C4NOdb?= =?us-ascii?Q?CWnRJqymp9bn5Q1J5WxDyuw/Kdr+Wrmyq8y1VE/4oj82ANKzQgdK6K2QJ2lr?= =?us-ascii?Q?QEwA4t7Z+1QZWTUv7LMnyOQfvysatV2UtoPjgza0v6uJgF8XvXhaXNLoVsyD?= =?us-ascii?Q?2dUuSzs17TzZWRFZXjXeaQnouWwu8iuVlfcQgLQIMwpOCYmJ8SpbQf/Fj+uM?= =?us-ascii?Q?R8bFqFkTemwYkv2wCXumicZLqKt35bK119fu3PGEg9IUqtBoxYiDyAESIdzp?= =?us-ascii?Q?gL9YDBSElT6KyYSxRni/KMvpQipFkbfPT0MbIKigj9inog8wp1puDeGavSPi?= =?us-ascii?Q?QBs2TSHBDfTcQb+JRVoX0kfYyrnpRV4lcrm2zVJCfx64zmRK0pMF1PNBYSkW?= =?us-ascii?Q?DmD7u+zvkJI4FfuXzqgCxdX2LJQB7N4kb1THP9TiVI+WxMOnuvPXo9d9TExW?= =?us-ascii?Q?CHF9fr0u/jH0fE0z0MFUOPCc1w/caO6ODz8EkGjLjxMxDUe7glprJEmMADpI?= =?us-ascii?Q?w8f7XsVQZ7fSdrbknCb1lejc/1uGc+Jv1ZMX96P0LaXS6o8OmYg5B0oGIms8?= =?us-ascii?Q?8Lgv8uVwtRE/dzWpcSw=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8da9061-af52-4db3-a33f-08dd0a5da9ae X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:35.2663 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: APSAXxENTHtEjwbNjSyST0vqdhAIrOtQ/3G33xuoxMb3B5awhI5dokoG0AGk6GQO X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 Content-Type: text/plain; charset="utf-8" folio_split() splits a large folio in the same way as buddy allocator splits a large free page for allocation. The purpose is to minimize the number of folios after the split. For example, if user wants to free the 3rd subpage in a order-9 folio, folio_split() will split the order-9 folio as: O-0, O-0, O-0, O-0, O-2, O-3, O-4, O-5, O-6, O-7, O-8 if it is anon O-1, O-0, O-0, O-2, O-3, O-4, O-5, O-6, O-7, O-9 if it is pagecache Since anon folio does not support order-1 yet. It generates fewer folios than existing page split approach, which splits the order-9 to 512 order-0 folios. folio_split() and existing split_huge_page_to_list_to_order() share the folio unmapping and remapping code in __folio_split() and the common backend split code in __split_unmapped_folio() using uniform_split variable to distinguish their operations. Signed-off-by: Zi Yan --- mm/huge_memory.c | 56 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 65dd2a383e29..3704e14b823a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3731,11 +3731,10 @@ static int __split_unmapped_folio(struct folio *fol= io, int new_order, } =20 static int __folio_split(struct folio *folio, unsigned int new_order, - struct page *page, struct list_head *list) + struct page *page, struct list_head *list, bool uniform_split) { struct deferred_split *ds_queue =3D get_deferred_split_queue(folio); - /* reset xarray order to new order after split */ - XA_STATE_ORDER(xas, &folio->mapping->i_pages, folio->index, new_order); + XA_STATE(xas, &folio->mapping->i_pages, folio->index); bool is_anon =3D folio_test_anon(folio); struct address_space *mapping =3D NULL; struct anon_vma *anon_vma =3D NULL; @@ -3756,9 +3755,10 @@ static int __folio_split(struct folio *folio, unsign= ed int new_order, VM_WARN_ONCE(1, "Cannot split to order-1 folio"); return -EINVAL; } - } else if (new_order) { + } else { /* Split shmem folio to non-zero order not supported */ - if (shmem_mapping(folio->mapping)) { + if ((!uniform_split || new_order) && + shmem_mapping(folio->mapping)) { VM_WARN_ONCE(1, "Cannot split shmem folio to non-0 order"); return -EINVAL; @@ -3769,7 +3769,7 @@ static int __folio_split(struct folio *folio, unsigne= d int new_order, * CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping * does not actually support large folios properly. */ - if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && + if (new_order && IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !mapping_large_folio_support(folio->mapping)) { VM_WARN_ONCE(1, "Cannot split file folio to non-0 order"); @@ -3778,7 +3778,7 @@ static int __folio_split(struct folio *folio, unsigne= d int new_order, } =20 /* Only swapping a whole PMD-mapped folio is supported */ - if (folio_test_swapcache(folio) && new_order) + if (folio_test_swapcache(folio) && (!uniform_split || new_order)) return -EINVAL; =20 is_hzp =3D is_huge_zero_folio(folio); @@ -3835,10 +3835,13 @@ static int __folio_split(struct folio *folio, unsig= ned int new_order, goto out; } =20 - xas_split_alloc(&xas, folio, folio_order(folio), gfp); - if (xas_error(&xas)) { - ret =3D xas_error(&xas); - goto out; + if (uniform_split) { + xas_set_order(&xas, folio->index, new_order); + xas_split_alloc(&xas, folio, folio_order(folio), gfp); + if (xas_error(&xas)) { + ret =3D xas_error(&xas); + goto out; + } } =20 anon_vma =3D NULL; @@ -3903,7 +3906,6 @@ static int __folio_split(struct folio *folio, unsigne= d int new_order, if (mapping) { int nr =3D folio_nr_pages(folio); =20 - xas_split(&xas, folio, folio_order(folio)); if (folio_test_pmd_mappable(folio) && new_order < HPAGE_PMD_ORDER) { if (folio_test_swapbacked(folio)) { @@ -3921,8 +3923,8 @@ static int __folio_split(struct folio *folio, unsigne= d int new_order, mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1); mod_mthp_stat(new_order, MTHP_STAT_NR_ANON, 1 << (order - new_order)); } - __split_huge_page(page, list, end, new_order); - ret =3D 0; + ret =3D __split_unmapped_folio(page_folio(page), new_order, + page, list, end, &xas, mapping, uniform_split); } else { spin_unlock(&ds_queue->split_queue_lock); fail: @@ -4000,7 +4002,31 @@ int split_huge_page_to_list_to_order(struct page *pa= ge, struct list_head *list, { struct folio *folio =3D page_folio(page); =20 - return __folio_split(folio, new_order, page, list); + return __folio_split(folio, new_order, page, list, true); +} + +/* + * folio_split: split a folio at offset_in_new_order to a new_order folio + * @folio: folio to split + * @new_order: the order of the new folio + * @page: a page within the new folio + * + * return: 0: successful, <0 failed (if -ENOMEM is returned, @folio might = be + * split but not to @new_order, the caller needs to check) + * + * Split a folio at offset_in_new_order to a new_order folio, leave the + * remaining subpages of the original folio as large as possible. For exam= ple, + * split an order-9 folio at its third order-3 subpages to an order-3 foli= o. + * There are 2^6=3D64 order-3 subpages in an order-9 folio and the result = will be + * a set of folios with different order and the new folio is in bracket: + * [order-4, {order-3}, order-3, order-5, order-6, order-7, order-8]. + * + * After split, folio is left locked for caller. + */ +int folio_split(struct folio *folio, unsigned int new_order, + struct page *page, struct list_head *list) +{ + return __folio_split(folio, new_order, page, list, false); } =20 int min_order_for_split(struct folio *folio) --=20 2.45.2 From nobody Sun Nov 24 20:38:59 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 217701D932F for ; Thu, 21 Nov 2024 18:52:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215168; cv=fail; b=W93efWXo5y49uWPsn/rkOh39rQ6S1HRsUtKL6mxCHx5BDOJxFz4YM4yT766zbiu7/HT7aT+p0KHebF9CEkD0Yt66So4x1EY9FKkOhiJ4vapGiPN2I2cfooIJnWEG/Lkj/XA0ktvzwTPQyyykEg9wc734Lhw5CEIyOVr74NNA5Wg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215168; c=relaxed/simple; bh=b9ZAjUbBuvGec6yMxeVYIW6fIsYIzdb8qo1Prkv6kLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=q91N9a5KKVh9bJYJTjg1Wzd8MMHVsgBSTd5+F24PuHYewz48SwTOSlNS+7EnNn+gx392CW9PhddjJqJuokEHW/DYNnQvnRovs+Qdm4sY8IjQY8xpGW4fbKVFwSP2oUyjulfKQwtpUgwBvCIZUbiTIuO5MmAD0jVblu3tUdcr8Ec= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=t2zOiWS9; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="t2zOiWS9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=odmP8xx/H2RJIEu7jJwDSB6G1nTlObgsoIZvlM+rQOfwQ+ARqhbltupXRnW98hVWdBVdVZSp4WqBrcxw1wkRQ2YvLH7Urr46lCIh67g83KZIxpn9JJd3Ln+s23RUVSs4296LhOTb3SkLWQ4IkMckIQUjTQcSbtNOahQvUZJw1UfKnJCLXj6bmXacJTUhu54WbImBDKA/S3mknHfUgMafgB7N4iJ24i3GUjXn3hhzydsBEvddKEE2p2zXTUd5jxhwuowaeyyAixY31F9m1Kbehbcofz/HHiW8YXM6uQBwEv/CPCie5HIJ7u4M6C7Fo84ax5DkJ3KcmcVNswBF05hzKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vKlBDIl4xrdnKlrWfw8XLDZsIOdmGI3JDlSG+Z0iz/4=; b=J5oHsDkZ352Jt5h4vaTtx0RyaH8hYvx/ZlxNupnRfK4Gu9zxcZERx7QC3QoDFLj1pkf+mfkMdmPchGgpzBsS0/EOWz7W6e5B19Q69XQex+WaQwc8XQPbiZqyXgpfZyjvow3Y+rpW6tsBGUg6D58Tu9LAsnuk1tPUIETN/Ocw/AljXd0L+y9gFLfpRsDr5EtD2cCvpQ6PRhO5deoiUd+sEi5DBdKymiXmE0bU4ZMTBcsUv2dFVrqfIy7dBfgyZCzCCO99CMlbndw79N20k4WMmkG783RRZX1SzYQ6f6gPF7xOykfmFRzrHv0lAqp2zRF6tD6DgXy7WNfQiAYq0idyUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vKlBDIl4xrdnKlrWfw8XLDZsIOdmGI3JDlSG+Z0iz/4=; b=t2zOiWS9BWppiTs1AWRAsyjBsxCObECUieKUf/z/SQ7aVIzdsgSx9UmJBArqJ+hQr84vqoi1J0RAMFZmcMucrnLO6WZnu7K7Fm8nYRkQfvAfvcvtHUV8H33a08J7Xa5UTbbxSc1lHibnuOkzulyjekFODtifUVvJirtfln/j3ZS5Zv7qoMGE9A0HWdiPkLHkhcBwuu5NUVIjZk+txIIaC5hBeC7YxoFXXZSYwA3Zl6aUJyfmbBmKXd1PMb5IK+yZXj50EG5k3Mn41A+qRfMaNx5lwpwLTqwfyI/OPrDLF0BB80tGPbFiyX3Fr/kA7niK4lB7pSlvNp10xTMjF88uHw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:36 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:36 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 4/9] mm/huge_memory: remove the old, unused __split_huge_page() Date: Thu, 21 Nov 2024 13:52:15 -0500 Message-ID: <20241121185220.2271520-5-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0213.namprd13.prod.outlook.com (2603:10b6:208:2bf::8) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a323e4a-f4eb-4661-b6ff-08dd0a5daa55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?l8nFepLP1LGeAaG9ZAdxhJ9ygX0qR6BmS+r4SX7YwBLRnNaZAfoH7FCC3JRS?= =?us-ascii?Q?lTjfNWFYS8qS0e++rheL11fnPtv/MJ8L72wMX51E4Pt8KyhvWYhiWe8MOXKc?= =?us-ascii?Q?4jwbvcocyS4mUErVAto5sKPyHP3nIDbNWwjC5lUweLrDcj1XaEjDpG9y91Zs?= =?us-ascii?Q?yLtxGZkJ5SXXNReppA38e2drSP2G4UVqdz5fvehIgQUboWZXsFkUgvm+DIWp?= =?us-ascii?Q?ArIr1UombvMm5qyzkq2NF4dJ3H6xHt8Us4vh7ki90ptYYawqqUDoRNLi1F4g?= =?us-ascii?Q?eWeRhziBkygCPDbDCsY3h4RMFe66wpqJpJ3Zk/OKpv62OpSwhFnOCPsfY3xF?= =?us-ascii?Q?7CMj9/OatPIfJ/9gOIjU5YGT6VQPuEKZiXkKeRNK76KyijAntUynQ5jeh8Mw?= =?us-ascii?Q?2p6SVWDNLWi75JvtyUZ42Va5k1AkKmKezE5wp9/rumKsDMO/63B/tj/bZY2o?= =?us-ascii?Q?7nMD9JdiJYd5Qawve1YyBgvj00CYJAdBGtqU/GCXI6r5Qveb80ipqMFzbNNd?= =?us-ascii?Q?vHPo9kf1h7KN2TpPcqgNC0V51Sb7jBQh9aKRmskXvK1B0y4eZN9XNvkgauNU?= =?us-ascii?Q?g1/zhVICXwfe42i8FDfhk9Y3jmjgWRstTDnu+BA4xU9xIpduMMQ0M0V2fASF?= =?us-ascii?Q?rdzuUieSoxMl0tH0mDRblD44UvKZ/S1tAr0hK2FPb3xuciafTtf7DDGxRJid?= =?us-ascii?Q?gRWRfViJU3q1aoSyjrUbg1xyf95zgPljwTqMTOS3+bYe5IO/NMIQodnd0IrF?= =?us-ascii?Q?nwrdpnpMMopRfkNITzWJZiYK3PRasWBBPFU1BhL4frbPPkyU0H0DpWwRzLv2?= =?us-ascii?Q?wOKEJ9PQHvqfgQTtR6zvQUkdLiCSWx1QDzALs8julDQgBK2APJ/mBrdywJi2?= =?us-ascii?Q?6Q5OyLAN+j47CEi4fUr7vKxb7p5PMNmrBRKHCbAYMCHaDlE3FSbBQx17hbIZ?= =?us-ascii?Q?4ek2yScZkQKnlyCl+Yo244RK4iND7mHLC9/OTOx1ynEOnqYvzaZjcAYbUodk?= =?us-ascii?Q?Yq5ggJAjU1+eRsaiCcLq7VhCJkAPS8u+c8opBVMm2Zt/LUYZWrcy7I590TQp?= =?us-ascii?Q?+pBmjqjHV3F9+l6tbPQmY68GUafpZjZZSAJq0uxNd0grbHWctC5REb4obcZR?= =?us-ascii?Q?WiBxCHQVdpLf55b/ZTludc46J8iiYGZV+a0uclZeQO6RaHMuXG3KzIrsWYj3?= =?us-ascii?Q?bEaxvR6F9OOlXZJBd/PmP++nFGkNINIET1a/7RiBrQ90hrB0rFHiL88YzuMP?= =?us-ascii?Q?8ICo2wKxvPWN36J54VjoWLID2vq4kci1sP+wwGJng+xfY4u/7kQfExDIuDFq?= =?us-ascii?Q?hv9SIgvERzqKKB3gPV+ddJit?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?KII3TseLC2jiAdvkGOMl6Lnkdj80sDHhwCyQ2gdBvg/yKgoZZJEA4v5HuI5m?= =?us-ascii?Q?LHYnFMppWClTk9z+VJSYRmDaPUag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ii?Q?Lpw421T786+eQzNLqS41CobL0siAJob8/Lr9CWYbxjDnf0lICqJu9SYX19J7?= =?us-ascii?Q?HxI7Wi7rd/kxYTU8Y1TBfVncWyCymHfrIAN2RxLqoe/UX3uQf/ShXY3j99ii?= =?us-ascii?Q?JqkSOxu8lbZhe9I2yxO6VKW5kIgtDVpbpkQe2S4bVYS2uxQVc7rYaatrbSqH?= =?us-ascii?Q?hBd4qYrd00sJrqw/wd8qyHadMBeAudzHXrTtFj4oB/+/h5SSnj8jKoQh5nme?= =?us-ascii?Q?MuVzySmjAlgN1FRoHCey9A1tvXkJN5G45x+nSBADB7UJ6r0FbLEIZv1RJeC5?= =?us-ascii?Q?9HIWyzP13FATACY/0wKfogzkhmQW4GTEFu/iSiwfywSgC2BwAsX+g62t7Fl+?= =?us-ascii?Q?nNILRxY3DCWVNsyWYnhKkMXU3tEY7GsipppJsRbzm6HtnmgkLq/wlZuQa41C?= =?us-ascii?Q?GoSMeaA++zog70rOYLo9G0q0AU0w7nRqKZsBz7Ax44ed4sc499/0kzZdq/sU?= =?us-ascii?Q?oPW/dyqa82ufeyPqvXatGKvvf3IcZIowtaQZSVJVIvgf3cquD+REGf9BO+W2?= =?us-ascii?Q?WW/8Db+3EWh1Nrzzl9BDCa47Hr7NLoQEmhwuKSlsmYMyVlHyIllbKoaX/4d0?= =?us-ascii?Q?T6ts7K38qGTQ+R6LNro=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a323e4a-f4eb-4661-b6ff-08dd0a5daa55 X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:36.3643 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RspBYy5LcZecZYwfVe26IbB8sTKIu4vAlfsnl7d3JHhSaEaLormmHJ8na+s0zWdc X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 Content-Type: text/plain; charset="utf-8" Now split_huge_page_to_list_to_order() uses the new backend split code in __folio_split_without_mapping(), the old __split_huge_page() and __split_huge_page_tail() can be removed. Signed-off-by: Zi Yan --- mm/huge_memory.c | 207 ----------------------------------------------- 1 file changed, 207 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 3704e14b823a..9b3688870a16 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3146,213 +3146,6 @@ static void lru_add_page_tail(struct folio *folio, = struct page *tail, } } =20 -static void __split_huge_page_tail(struct folio *folio, int tail, - struct lruvec *lruvec, struct list_head *list, - unsigned int new_order) -{ - struct page *head =3D &folio->page; - struct page *page_tail =3D head + tail; - /* - * Careful: new_folio is not a "real" folio before we cleared PageTail. - * Don't pass it around before clear_compound_head(). - */ - struct folio *new_folio =3D (struct folio *)page_tail; - - VM_BUG_ON_PAGE(atomic_read(&page_tail->_mapcount) !=3D -1, page_tail); - - /* - * Clone page flags before unfreezing refcount. - * - * After successful get_page_unless_zero() might follow flags change, - * for example lock_page() which set PG_waiters. - * - * Note that for mapped sub-pages of an anonymous THP, - * PG_anon_exclusive has been cleared in unmap_folio() and is stored in - * the migration entry instead from where remap_page() will restore it. - * We can still have PG_anon_exclusive set on effectively unmapped and - * unreferenced sub-pages of an anonymous THP: we can simply drop - * PG_anon_exclusive (-> PG_mappedtodisk) for these here. - */ - page_tail->flags &=3D ~PAGE_FLAGS_CHECK_AT_PREP; - page_tail->flags |=3D (head->flags & - ((1L << PG_referenced) | - (1L << PG_swapbacked) | - (1L << PG_swapcache) | - (1L << PG_mlocked) | - (1L << PG_uptodate) | - (1L << PG_active) | - (1L << PG_workingset) | - (1L << PG_locked) | - (1L << PG_unevictable) | -#ifdef CONFIG_ARCH_USES_PG_ARCH_2 - (1L << PG_arch_2) | -#endif -#ifdef CONFIG_ARCH_USES_PG_ARCH_3 - (1L << PG_arch_3) | -#endif - (1L << PG_dirty) | - LRU_GEN_MASK | LRU_REFS_MASK)); - - /* ->mapping in first and second tail page is replaced by other uses */ - VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping !=3D TAIL_MAPPING, - page_tail); - new_folio->mapping =3D folio->mapping; - new_folio->index =3D folio->index + tail; - - /* - * page->private should not be set in tail pages. Fix up and warn once - * if private is unexpectedly set. - */ - if (unlikely(page_tail->private)) { - VM_WARN_ON_ONCE_PAGE(true, page_tail); - page_tail->private =3D 0; - } - if (folio_test_swapcache(folio)) - new_folio->swap.val =3D folio->swap.val + tail; - - /* Page flags must be visible before we make the page non-compound. */ - smp_wmb(); - - /* - * Clear PageTail before unfreezing page refcount. - * - * After successful get_page_unless_zero() might follow put_page() - * which needs correct compound_head(). - */ - clear_compound_head(page_tail); - if (new_order) { - prep_compound_page(page_tail, new_order); - folio_set_large_rmappable(new_folio); - } - - /* Finally unfreeze refcount. Additional reference from page cache. */ - page_ref_unfreeze(page_tail, - 1 + ((!folio_test_anon(folio) || folio_test_swapcache(folio)) ? - folio_nr_pages(new_folio) : 0)); - - if (folio_test_young(folio)) - folio_set_young(new_folio); - if (folio_test_idle(folio)) - folio_set_idle(new_folio); - - folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); - - /* - * always add to the tail because some iterators expect new - * pages to show after the currently processed elements - e.g. - * migrate_pages - */ - lru_add_page_tail(folio, page_tail, lruvec, list); -} - -static void __split_huge_page(struct page *page, struct list_head *list, - pgoff_t end, unsigned int new_order) -{ - struct folio *folio =3D page_folio(page); - struct page *head =3D &folio->page; - struct lruvec *lruvec; - struct address_space *swap_cache =3D NULL; - unsigned long offset =3D 0; - int i, nr_dropped =3D 0; - unsigned int new_nr =3D 1 << new_order; - int order =3D folio_order(folio); - unsigned int nr =3D 1 << order; - - /* complete memcg works before add pages to LRU */ - split_page_memcg(head, order, new_order); - - if (folio_test_anon(folio) && folio_test_swapcache(folio)) { - offset =3D swap_cache_index(folio->swap); - swap_cache =3D swap_address_space(folio->swap); - xa_lock(&swap_cache->i_pages); - } - - /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ - lruvec =3D folio_lruvec_lock(folio); - - ClearPageHasHWPoisoned(head); - - for (i =3D nr - new_nr; i >=3D new_nr; i -=3D new_nr) { - struct folio *tail; - __split_huge_page_tail(folio, i, lruvec, list, new_order); - tail =3D page_folio(head + i); - /* Some pages can be beyond EOF: drop them from page cache */ - if (tail->index >=3D end) { - if (shmem_mapping(folio->mapping)) - nr_dropped++; - else if (folio_test_clear_dirty(tail)) - folio_account_cleaned(tail, - inode_to_wb(folio->mapping->host)); - __filemap_remove_folio(tail, NULL); - folio_put(tail); - } else if (!folio_test_anon(folio)) { - __xa_store(&folio->mapping->i_pages, tail->index, - tail, 0); - } else if (swap_cache) { - __xa_store(&swap_cache->i_pages, offset + i, - tail, 0); - } - } - - if (!new_order) - ClearPageCompound(head); - else { - struct folio *new_folio =3D (struct folio *)head; - - folio_set_order(new_folio, new_order); - } - unlock_page_lruvec(lruvec); - /* Caller disabled irqs, so they are still disabled here */ - - split_page_owner(head, order, new_order); - pgalloc_tag_split(folio, order, new_order); - - /* See comment in __split_huge_page_tail() */ - if (folio_test_anon(folio)) { - /* Additional pin to swap cache */ - if (folio_test_swapcache(folio)) { - folio_ref_add(folio, 1 + new_nr); - xa_unlock(&swap_cache->i_pages); - } else { - folio_ref_inc(folio); - } - } else { - /* Additional pin to page cache */ - folio_ref_add(folio, 1 + new_nr); - xa_unlock(&folio->mapping->i_pages); - } - local_irq_enable(); - - if (nr_dropped) - shmem_uncharge(folio->mapping->host, nr_dropped); - remap_page(folio, nr, PageAnon(head) ? RMP_USE_SHARED_ZEROPAGE : 0); - - /* - * set page to its compound_head when split to non order-0 pages, so - * we can skip unlocking it below, since PG_locked is transferred to - * the compound_head of the page and the caller will unlock it. - */ - if (new_order) - page =3D compound_head(page); - - for (i =3D 0; i < nr; i +=3D new_nr) { - struct page *subpage =3D head + i; - struct folio *new_folio =3D page_folio(subpage); - if (subpage =3D=3D page) - continue; - folio_unlock(new_folio); - - /* - * Subpages may be freed if there wasn't any mapping - * like if add_to_swap() is running on a lru page that - * had its mapping zapped. And freeing these pages - * requires taking the lru_lock so we do the put_page - * of the tail pages after the split is complete. - */ - free_page_and_swap_cache(subpage); - } -} - /* Racy check whether the huge page can be split */ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pin= s) { --=20 2.45.2 From nobody Sun Nov 24 20:38:59 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A5491DA2F1 for ; Thu, 21 Nov 2024 18:52:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215170; cv=fail; b=lPtbH4a02VdwX+3oQUx6PbN46NBrOiXRPL65W7yPfXOX7G7yzRhcjyObX1Cc8CE8kXvNFmpdwR114bdRVJT+27CR8DEA18849oy9Tg8/LAFisdwTqQDS9vh4nKKQuJd1nxcMEuy1VQ3RIGGLTacamQFvGC3XMQogLCS170ABTeQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215170; c=relaxed/simple; bh=4Zw1R0HtvnXeB7PudjwI1pYEqqIrKCiMLEQsNwehSDU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=s6YuRPjBiXcUH3ULTdGyg7c/etfuDnbLUnoHQCFCreMBwlPZK+87uuJX4hnsqeSXTKKB1yPG1fYJNhaVHUU44LMpI4kQMrF2aHBUcP8JRUfTBuifblRArBi2JcoiFL0BoB8iIWWdDa96NJOIUol1mk1ywUnajoVJgv92DiGh+EY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=RujNHeDS; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RujNHeDS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PSPv+fs9iJ2unUBNZipOgTdN4vfGnXEKz6RKMmQTP9x5SZ0ff/R8OnuTQ6SLqRTP/qQAZQrynSQ4pQicumnyKGiNTP8E6+piyttsKLQhK0SY/ENbSM2oBGfEcIA0t+Z3inZj5nnEuh1ISS3uBg5AdbuwFTlfkwBXhwvTUvTGNP+gsFT7iPdKbER4DMA1Joozd6cP5zu3uM01QFJPBJ5+mwqDwv7sbl4GJeyZTI6RRM3u2s6ndtgxLRnhVBTuu3pEMbDqbqBLLhc/d0buKYMgm7zu2jR2etplT0Nya8/x+IQnsTEnKAFji8xMUzvZ1iFNcLErYrf/w1JPE55BX2KPCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0HGXumwoHzdRg37AsHGRuosvSDyN0mCdwuWzz5mHCIU=; b=iR6XT8D/0/YK6PwhWF62hFU/08T0oN9NeHLLMPNP1kXE7MDxFRDoQCdINtmmFajzfaDaa5Fuj8RkzW0pNbHIvwh2fedZXBaIdj1QFHiTxiVhFHkViKc0m4RpootfTzsBLabxBokD8dD4nWSP6Q7AcPA1rDYLleLTSP05QqZkOZtl/WCcfK8Na5p/4fMnTb5tYrbGLzlgXkOVRADn+f8NHgysAsQwj8omGV1w+regJkvKIidsPo+s2t8v1eo9KUHNcoqfQ/xCx1VLDdIb2QNvl+FTEYbFTDa23l3L+y/xspHOOxrVcbhOYy4EDbzz/VlvnKa3pPB0oyxCgct/8Jct8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0HGXumwoHzdRg37AsHGRuosvSDyN0mCdwuWzz5mHCIU=; b=RujNHeDSdEzoxgjtTvnBnE04SwFeh15hhhyZBKLYsMsqInU3UYEaTp3eIaDqYCHP1G8TsFdRUVXOcUBQziGOljICzEXPshqyRimt3Oc7pRwMJE6d32tT0jyIKm8FOgihsLSNXt9PSmcUsxtouV8J+mVjsQ9sU9rH9EIPdn3hMVTfckcSPOQSjjC6pA8eMFtDxMVpojkanYpjTp1NUolE3O6/Cbta0rKox5bxJpu4DohqY2V5cAqH3UQJrE0C+dtJKP3sOkmfMWvML399ykXD06+93shWZHgQ7sP3Iahm4v7slRThEmGZOJfirDbHZzhWDvGHPt5ONia60FyZddKeiQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:37 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:37 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 5/9] mm/huge_memory: add folio_split() to debugfs testing interface. Date: Thu, 21 Nov 2024 13:52:16 -0500 Message-ID: <20241121185220.2271520-6-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0234.namprd13.prod.outlook.com (2603:10b6:208:2bf::29) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: c79adceb-998a-49b0-a5a1-08dd0a5dab0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?vXnuoGP1qawLOa608c40GaFw2jPpUhH4xvp/3WjxceXrk2vidFz8bX8IUJTn?= =?us-ascii?Q?GggqrZAbeU5S0cpflC6ybnElUGzoeHFzG4KOPjRkAGyKIuwToLBvOBvh7Hd+?= =?us-ascii?Q?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MAVQn8Ta?= =?us-ascii?Q?yCct5hjItpFa/tlwAnUBfVaGcXFPFENttVN9ujI3t4Blgqa8y1EqtmmX0HkM?= =?us-ascii?Q?lpxnYioXSJhn/kSthC2hILG0602svfW8uoPm+CK5FYGrQpgU4XsmzjH8JQlz?= =?us-ascii?Q?mnPXkDzZv86wloUlHkkiu6uN73RMkt03fIc7wFVkg23dhljb1F7HWmAC4rEF?= =?us-ascii?Q?YB0qfcIMehvWd+m1itsXqjcM14Lf7iNiwvCkde9Zlgf3coFWp0MFjD/3sO9h?= =?us-ascii?Q?1VW1vVPCKS4XJwKECmpsRfaJy3KYEPnq5VYjqptt2gdFvRwSklikGedXhxiP?= =?us-ascii?Q?suGPfj9ZQo569ROXzQ3ja3rO?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?gHTBYSsW0QqfK5I4Nse5wRvUlbX500dPo/0Ua7K8ySIszewKNJl4Y76UUoR0?= =?us-ascii?Q?M96anZ1vQ7aF5N/ajw6oUN2RoeCkqob0gyiV7xvWYZ+UfOL5P8wbpf4Q/vcE?= =?us-ascii?Q?fEmhT8lvo2zzctHe23ZgBl20DJ125cDCe5l4XOf9Cr/NlPdXhPXiDL/DrGEg?= =?us-ascii?Q?4L1KmUqx65Z9T2CLrxVPy+GygSH6AAs0ySfApkKecEjOFKxsA92cDPsD5IqZ?= =?us-ascii?Q?Go77K7WHcbqP9Lr63JOOsVIgctSBLwzlYkILYfB9adPdrd93G9V2/mTbip4L?= =?us-ascii?Q?jdboz0p6HWl70JAA1H9QpLfaZOKbceF7ai8JQd4eOMRlEH8kkoG/7EFhW+wL?= =?us-ascii?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jN7zGCinjORgUw?= =?us-ascii?Q?bar/71zQGMNVbJsCtGX4BlKkNwnxdOK65clN2K0J6zB5DztPtZBqJQxqWjLM?= =?us-ascii?Q?ytr5+5nNkIOckkR9t8d680rBHlj8cB/WvN6g9su5KQE163nTsCSF4+FypCXa?= =?us-ascii?Q?6q85Whv6L/MbFU9xySud0N3Nqo+pIiDKA0/xuAWIcrJD/i8A74ivYrIeyAY+?= =?us-ascii?Q?+a85p9IjsfDEfGr8Dei11ZOqf0ZPe2fue9e4/o2AeJk+t31gpGv/hMlWMe22?= =?us-ascii?Q?RSQ1XVUqQ/wldvlAysq1/vDDQ9vOmOypWzHxzmQsgNiPocCrJ/ImTHMV4lcE?= =?us-ascii?Q?zbUERZSuYsrbK0KMDGs=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c79adceb-998a-49b0-a5a1-08dd0a5dab0f X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:37.5676 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kOKdW++/Oivdqv9sxCtzhrb5sD1Z6Ax21qBrLEQhyb53LHoDT0sjAd0Yn6Ufksm6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 Content-Type: text/plain; charset="utf-8" This allows to test folio_split() by specifying an additional in folio page offset parameter to split_huge_page debugfs interface. Signed-off-by: Zi Yan --- mm/huge_memory.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9b3688870a16..9133a69c9245 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -4141,7 +4141,8 @@ static inline bool vma_not_suitable_for_thp_split(str= uct vm_area_struct *vma) } =20 static int split_huge_pages_pid(int pid, unsigned long vaddr_start, - unsigned long vaddr_end, unsigned int new_order) + unsigned long vaddr_end, unsigned int new_order, + long in_folio_offset) { int ret =3D 0; struct task_struct *task; @@ -4225,8 +4226,16 @@ static int split_huge_pages_pid(int pid, unsigned lo= ng vaddr_start, if (!folio_test_anon(folio) && folio->mapping !=3D mapping) goto unlock; =20 - if (!split_folio_to_order(folio, target_order)) - split++; + if (in_folio_offset < 0 || + in_folio_offset >=3D folio_nr_pages(folio)) { + if (!split_folio_to_order(folio, target_order)) + split++; + } else { + struct page *split_at =3D folio_page(folio, + in_folio_offset); + if (!folio_split(folio, target_order, split_at, NULL)) + split++; + } =20 unlock: =20 @@ -4249,7 +4258,8 @@ static int split_huge_pages_pid(int pid, unsigned lon= g vaddr_start, } =20 static int split_huge_pages_in_file(const char *file_path, pgoff_t off_sta= rt, - pgoff_t off_end, unsigned int new_order) + pgoff_t off_end, unsigned int new_order, + long in_folio_offset) { struct filename *file; struct file *candidate; @@ -4298,8 +4308,15 @@ static int split_huge_pages_in_file(const char *file= _path, pgoff_t off_start, if (folio->mapping !=3D mapping) goto unlock; =20 - if (!split_folio_to_order(folio, target_order)) - split++; + if (in_folio_offset < 0 || in_folio_offset >=3D nr_pages) { + if (!split_folio_to_order(folio, target_order)) + split++; + } else { + struct page *split_at =3D folio_page(folio, + in_folio_offset); + if (!folio_split(folio, target_order, split_at, NULL)) + split++; + } =20 unlock: folio_unlock(folio); @@ -4332,6 +4349,7 @@ static ssize_t split_huge_pages_write(struct file *fi= le, const char __user *buf, int pid; unsigned long vaddr_start, vaddr_end; unsigned int new_order =3D 0; + long in_folio_offset =3D -1; =20 ret =3D mutex_lock_interruptible(&split_debug_mutex); if (ret) @@ -4360,29 +4378,33 @@ static ssize_t split_huge_pages_write(struct file *= file, const char __user *buf, goto out; } =20 - ret =3D sscanf(buf, "0x%lx,0x%lx,%d", &off_start, &off_end, &new_order); - if (ret !=3D 2 && ret !=3D 3) { + ret =3D sscanf(buf, "0x%lx,0x%lx,%d,%ld", &off_start, &off_end, + &new_order, &in_folio_offset); + if (ret !=3D 2 && ret !=3D 3 && ret !=3D 4) { ret =3D -EINVAL; goto out; } - ret =3D split_huge_pages_in_file(file_path, off_start, off_end, new_orde= r); + ret =3D split_huge_pages_in_file(file_path, off_start, off_end, + new_order, in_folio_offset); if (!ret) ret =3D input_len; =20 goto out; } =20 - ret =3D sscanf(input_buf, "%d,0x%lx,0x%lx,%d", &pid, &vaddr_start, &vaddr= _end, &new_order); + ret =3D sscanf(input_buf, "%d,0x%lx,0x%lx,%d,%ld", &pid, &vaddr_start, + &vaddr_end, &new_order, &in_folio_offset); if (ret =3D=3D 1 && pid =3D=3D 1) { split_huge_pages_all(); ret =3D strlen(input_buf); goto out; - } else if (ret !=3D 3 && ret !=3D 4) { + } else if (ret !=3D 3 && ret !=3D 4 && ret !=3D 5) { ret =3D -EINVAL; goto out; } =20 - ret =3D split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order); + ret =3D split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order, + in_folio_offset); if (!ret) ret =3D strlen(input_buf); out: --=20 2.45.2 From nobody Sun Nov 24 20:38:59 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B0121DC198 for ; Thu, 21 Nov 2024 18:52:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215172; cv=fail; b=bXTkkLih1DWXBPX4ULL7XrvSWCo8nFLAKIM5h4Y7TOELWLfqwbP60YhYtFfV3Wj8AJFfC2V0X0uGGDyLMWMfpvz/TckOMrhWEXFkRIz80H0qmQ9X0rnV9GFOycbOJhhGEm2AqB/WiU1JKsyZGrkABSBKBL0CQ6EJDYIxQoHG5ok= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215172; c=relaxed/simple; bh=cW9a5BFaXQQLUR3sLPN73HGWNa8JFsuKtvliBlqoTU0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=CuLMifE6XXwG05RsWdwTpXbB8jOX33ggM1nbHurH3ulbzGRXcQ3dAHhHPB420KZ2PMUSHqhrbSemBQgF+zN3tYvcMEZ8CtaQos8gt2V4qg+h4WdCKkxkO/Rg1lQRDDoopxhyD+pPw+k0gYi/5MysIYn0cTQh6mNDuDiEAT46UyM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=FJ7Nz+xU; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="FJ7Nz+xU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GBYEWv1U6iriFRV53KtW7ek0eauOkf+ahrA1fbEHfMuDS2byVjfy/Qb43DD/6RqrTI6im6qyOnIoZJHUAXThZSaP+rkVYm+im6pg9XEKQ4vdTN0vS28ivjkCMBLEc+gMOC6pRt8c6fLxD2oPCOE6bYec3RW4UkGUxYKnNmC+wrGViiX9+kcGQH4AJSCAq15pfZjOxAhehpVa3/ntsI6xJ+6dwRHvWSVzmRTzop/E+WeLuf3MJfWDBGFlcvL4jHeXVnvEUawjfvBnr43uNxuQHJNlQNlljOJr2tIDphRIyj/AmhVt/l9q+C9x5lvfh9WuFomoHCIi9K5EDzHBvEmSAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bCK0ahHP2aeqKyUHb8ITfSzvvy9IFw+4Pn/KCUxa/mU=; b=MI3JA6yGoHixd6fPSmAkQ2zqFHDON+6oiqoQq1gzNh2mk7MWqDDoYKGRY/mEWPofn2P4JCVlLji31aFWGnX8jmt/WKqaan8l1n7uIC8/dPIQR3siFwvuqfiW7+kfIVvhfLy8geomgYp7ggCw7WYFh19cPYZRMevVMaVl9hwFlMlp8we7SKnagqPJLfHuVETpXPO3kX1WnLyH9qWtS3X3R8zT13bO2CMy2CKBoQ4W/gcYusx8c5120OD2HVMACcuFag5Pv5Ejx0ReaL/ufTLEqqH5X6N9Aaqi4TP+1Qx6b9wEAk6syS0KiOC6FDGYfLFL//los+d76GPMwTxAn0OHOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bCK0ahHP2aeqKyUHb8ITfSzvvy9IFw+4Pn/KCUxa/mU=; b=FJ7Nz+xUreBOOJl9EjB6lJR/DUGjcsN99GoAtjuABAK4TJ2sckkxpeNeWbkKlVK53N/gIiDmZ8cXWZ/xzLEg1b+b+ekIPI+8icVsBSIa+RdmCiX9ibZxmqw3hkIqR+ax+Hhk+SC1fx59J37lDaHUcv2YlLAG0QjpdhBVKU/iA/XTDN3Zjhg6YHx+sqbVRGLwljLLSHCYvbIgkwotG7kHvolkkwsloxWgNlHfcEVzQobrZcjIWkCc4VaIamXePujZWDKmhWjR6RCmGH3XpR5zxcl/jo7wqzJNLIwJlylP46ux7U3jwawsrPay+2eeOrOFkXlvMry8LYFsfwgs+TbFVg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:39 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:38 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 6/9] mm/truncate: use folio_split() for truncate operation. Date: Thu, 21 Nov 2024 13:52:17 -0500 Message-ID: <20241121185220.2271520-7-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0218.namprd13.prod.outlook.com (2603:10b6:208:2bf::13) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: e4a62e1d-4ab9-493a-619a-08dd0a5dab7f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Edd1Sjel1NqMjTX5gjFo0dMqOeTyVVmQ8/u8jK2GpY+lSvxnI3g45RoGwi6A?= =?us-ascii?Q?q0DUh4IUpbOFymEB0zF/3HfXpWmiN7IjUdQnePkDddkHkVXo5ngTRfJCwImr?= =?us-ascii?Q?tHUMsB11wIWZ09/jQDKXKvr2LEByu8hiK8WhnU0d2SmmFt1BCSz4K9W79tsD?= =?us-ascii?Q?digrcaK4V6luA1jy97PmTxWEZVndrc6qqSnKC9PohNgeoeikhRKgDf4/+nTP?= =?us-ascii?Q?BuSRd+n6c75H5DGMgjaz/oVx4prK5WaSpixyFO5QAwR2Be6B8xIDZX8xPO29?= =?us-ascii?Q?NYbZcTrk9vYPPA4b9HwzpTHyhSOWgDDroZjSAPJ/4BX+ECSacud3fWkrQbTV?= =?us-ascii?Q?UNaI3P02hi7vE0eak6hF3f/OUFd6mOwiRHAuc//YidDe/LufjJQyDV4T1oMu?= =?us-ascii?Q?xx9oJcisIAfdoz9phlNTEd5PauaNXZ8+mBBWnKZr4/qlRW4uRyv0haRFKbAY?= =?us-ascii?Q?1w/oUsE0cVakHKqNRAATszDnztik4sEHMmbpC3Nj+ypox8KEl+J07x1lB2f1?= =?us-ascii?Q?sRTVy9HW23E0fcCFPtlI2xSHSbZPHyz2k0938TT1W2EL+QiQxv3JLkLdU4gd?= =?us-ascii?Q?SqchuW5YpmsTGBfCBnGFOIjJXZ+71zkcJV+QLfMSxO2AsJ8lqndZAoTf0h4w?= =?us-ascii?Q?fywdbGbzfltF4mTqeRlFvj84XxaMHK/vLmUuRzj9HrEwEhGF/5Sn8mVlp6ba?= =?us-ascii?Q?yYTFl3bJFpsTgA+e/3nfHHapycqBGZSTbYKDNyqT0XRP1k4DVP0NzeqrirDC?= =?us-ascii?Q?rqemY3jDWV5WjM263jMAbb8ctKKcFdmE/I4kNxFQOzpYdYB2wyItsl4WDsjN?= =?us-ascii?Q?WxBoZxXv1sNPBDq4WGMx/pi/N6atCJwrGoe/CMZ34auTKRJWZXJjLow6byxM?= =?us-ascii?Q?4YQRBrWlltTyoy6S8hM3cOU/mUVKFWvmXXvI8GCJZkwvXFn8EB2KDZyYeggy?= =?us-ascii?Q?gyDAMHHYUzLnJ1edwjBUPBIp9VRajv1PjAgY9u/YoU51RZA4SytkGd4UD4Yb?= =?us-ascii?Q?p5lDe7dvUJxl+Xob8tszV1cZ4abvhlM4s7weMRLl/vDu/o0f+8qStEHwQlF+?= =?us-ascii?Q?pPj9BlS82kwya5ihgTUb5PdhGRCL5p7IhLWANCiRX0uLcaoCY/NoXfAiGPXd?= =?us-ascii?Q?t2YSR8JdYQdGNDC+R4nfYX3QQZOZQch8RjsYOqBKFR/HygBJbrZImjjDb1ui?= =?us-ascii?Q?rG6pgRpS5oC3cqcVU6vea0FkJfzzfRBL0yDGS4VRyq8IFULZYbamM8tvz5KD?= =?us-ascii?Q?jBTphBstzrC/ERLyI5xyk1EUHcPiALZ9NZZtdHLTYMgPuPB9fZ6pArYI3+Rg?= =?us-ascii?Q?FQpW4QP+bHDW57HrEINT8a1z?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0NoFIYX1dAlIuQMa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YUiurYI9w?= =?us-ascii?Q?N5+Eu5K6dkYnNbywxujD6ceBA1nXOfhvt/raKOCHRAg1G9XHr3una/sa+iIp?= =?us-ascii?Q?PnJjhDeOOy1qXwZp8nUlN5j1m5ZC/ynw61PS5oYOIRfiGgozeUvE7ivoZyhq?= =?us-ascii?Q?HB5D2k4imjyP+JwMuqCnl+Ol1sbY+lRMbCPYU3s8NEsPPg+SxJLZizbMoK9C?= =?us-ascii?Q?/K7/ZW/1y7i13I5t3Usm80wUnz1DOL8fAWh9xGOrR0B5UeQrTtF+Yxofj7UC?= =?us-ascii?Q?hPZj31apH/pDBToE95vnNqlXAkA92dNWQtMrGKs8cRGVNqvgEqpswMHUCgjE?= =?us-ascii?Q?kTdtY+bsNYbZiAAcXTnsDmVORRKUNLE778yIa0FTJ5ZWrQ+IpRQ4GSkiClXq?= =?us-ascii?Q?h/1YLb4MGNZ1HWRl9Gc+0VDs7Z89ZQh5r7eI9eMuZHpmxuNWQnm8l9X+BT2Y?= =?us-ascii?Q?88l0Czo5E6S03+kUB3s/vssTqfWlXaNdKObSurB/tp5YQvR74kg7tLNJV7t5?= =?us-ascii?Q?Am007UP4Hn2gGR8EoAMNhQAsB0EUr6wjWCpqHMwE+JpWPbv2HUOwWVUHjiB0?= =?us-ascii?Q?kx3WABcvaIS7NFVZQZmgkcvIcETus0qNBL1oTFu2YFhnULoD1+OEjVj5sjQi?= =?us-ascii?Q?OtjCVkq+HqLokiqn51s6CiO4XyssTdwQ4BR0Kvym2l+yuMC1wxrpAkd+Vwb8?= =?us-ascii?Q?UFQYbA1sHz8g5/UvvH4=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e4a62e1d-4ab9-493a-619a-08dd0a5dab7f X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:38.3127 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0Oxh8ANGuq3V2Z2UnNkciWxbMkuGLQRjbAGLlavFBY1yBWro59Awwo0yOl0qBNv4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 Content-Type: text/plain; charset="utf-8" Instead of splitting the large folio uniformly during truncation, use buddy allocator like split at the start of truncation range to minimize the number of resulting folios. For example, to truncate a order-4 folio [0, 1, 2, 3, 4, 5, ..., 15] between [3, 10] (inclusive), folio_split() splits the folio to [0,1], [2], [3], [4..7], [8..15] and [3], [4..7] can be dropped and [8..15] is kept with zeros in [8..10]. It is possible to further do a folio_split() at 10, so more resulting folios can be dropped. But it is left as future possible optimization if needed. Another possible optimization is to make folio_split() to split a folio based on a given range, like [3..10] above. But that complicates folio_split(), so it will investigated when necessary. Signed-off-by: Zi Yan --- include/linux/huge_mm.h | 18 ++++++++++++++++++ mm/truncate.c | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index b94c2e8ee918..29accb5d93b8 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -339,6 +339,18 @@ int split_huge_page_to_list_to_order(struct page *page= , struct list_head *list, unsigned int new_order); int min_order_for_split(struct folio *folio); int split_folio_to_list(struct folio *folio, struct list_head *list); +int folio_split(struct folio *folio, unsigned int new_order, struct page *= page, + struct list_head *list); +static inline int split_folio_at(struct folio *folio, struct page *page, + struct list_head *list) +{ + int ret =3D min_order_for_split(folio); + + if (ret < 0) + return ret; + + return folio_split(folio, ret, page, list); +} static inline int split_huge_page(struct page *page) { struct folio *folio =3D page_folio(page); @@ -531,6 +543,12 @@ static inline int split_folio_to_list(struct folio *fo= lio, struct list_head *lis return 0; } =20 +static inline int split_folio_at(struct folio *folio, struct page *page, + struct list_head *list) +{ + return 0; +} + static inline void deferred_split_folio(struct folio *folio, bool partiall= y_mapped) {} #define split_huge_pmd(__vma, __pmd, __address) \ do { } while (0) diff --git a/mm/truncate.c b/mm/truncate.c index e5151703ba04..dbd81c21b460 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -179,6 +179,7 @@ bool truncate_inode_partial_folio(struct folio *folio, = loff_t start, loff_t end) { loff_t pos =3D folio_pos(folio); unsigned int offset, length; + long in_folio_offset; =20 if (pos < start) offset =3D start - pos; @@ -208,7 +209,9 @@ bool truncate_inode_partial_folio(struct folio *folio, = loff_t start, loff_t end) folio_invalidate(folio, offset, length); if (!folio_test_large(folio)) return true; - if (split_folio(folio) =3D=3D 0) + + in_folio_offset =3D PAGE_ALIGN_DOWN(offset) / PAGE_SIZE; + if (split_folio_at(folio, folio_page(folio, in_folio_offset), NULL) =3D= =3D 0) return true; if (folio_test_dirty(folio)) return false; --=20 2.45.2 From nobody Sun Nov 24 20:38:59 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E5951DD0DC for ; Thu, 21 Nov 2024 18:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215174; cv=fail; b=EM3caPi6rT9k3+LyIjzmBwy4/NuVnJ6OhDLI6XrQjZ6Jw4jiRtcg4hOtPQjYrdqnbB5WlXiupKwAvQfKKcw3s99FCHI/BAIS2hJJ9l7oSuIF0sldSYgcVnWiwXV06CcZG9OXigdpb9Vns2yjiIgAc9YlETAJuD90clcMAjNBqWc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215174; c=relaxed/simple; bh=cSAUK/yZ/DwlhsMaY5PAROSuKyoT1axfD0PnzJDnsLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=s0u+lNrDWx/g2aKo+P7/3hNE6GmW+Z42da85uH93p0V7/52Yg/EAwnSbk3VvEzcqtJ7cIwIawAQY3o81II2GQNscpdwB4P+7fj6DShO7OyFs9aITjOQHMuzxVeMNJZbOXXzAj2gWSUwltCeLYkf5DVXa9RCXAnY4dxIPvJH7XH8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=SH4eZC1U; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="SH4eZC1U" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=s/Csw/p1X2djkp11x+DXYWz5U64lzS1pdBWgTZaB+kA8LF1KItXmpyG7vS6P5CsVM02QV0R6hcer/imF+VYQNB4svxj1AddlK7ZjxLOHEO7QIMtL0vFggL1pOSuk2UxvDcnKo/P8DpNSlrGRa3wDckFu1f5CsmVT5jMvs0PnPyXSSVj/+6sWcQJ/t1bh1fj2XHlsAVtnv66kjKqU2tTjjf2R0QCSfFJlk+v+qzf9l8PHHqLMUDL6iDToeIKtFm/75M/VFHF2CBVBgxeroq9yFryrImBfjPD2pjqayCFeCmWA0Wv002w3kjnshOIVCYppkRsV+G+oVGNleQ8FPLSzYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1lwTVNAVLwi1gyG41osM9o7VeGen/aJvxEZw1mntkp0=; b=GoMHTDNsokudkICn/molsWr9HuDYQ20jowzaWuorlfBfWgNtz88rtvB2AkNHeUgOoRQneh+1wsBqbvy8T92+K3kJTKLEtznRK6yy1/vfaTEMFoTYUOqLcPPw7jfKJNLUyV+UzA9UFiiPFmb1um8us62mPNNqdcjNpa4EONDC2YeKjyU52VDLXYeL45v35mkIOlpL/7wYAC9i9sMwN2iwkKjxfgnvlGstz72kCH/c2lF/kZglzOOkoVe75J0rqSE1LoaEEmTKRtwhU+BsCuObg4W+0cKhPNXi6zFYSHrjnUBtmtIN7nzekhJhzOLiMq60M62+2KpRVj+IQ8DFHKl84A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1lwTVNAVLwi1gyG41osM9o7VeGen/aJvxEZw1mntkp0=; b=SH4eZC1UK3CUgL+gw+idlVvaE9IgqnS0Y2Eet5ao7yPf7TLy2H5FRm1PJ0UoLTkSjJzJXDsMiUIZDOuZltnsm3Ezae6fgB8fVX/by5de30hnO1iIZR84eDU9XNSkT85DhnMiNT2HIU6eZwyzJoiTrdbms9uVkkXUXj8gfVdZWcaOqNpJxk3zsKcIakGx5nLJIuPCTZPPxEy6CYsX/H6Vn1cdRER8MIyKlFcqFICje68EhUmzHEPJEU31l5azCbZ6bGWdP317NBODZ27p7om9CPq8Wfqf6d/Z82lywQeCTd0uw/xy9XRseMz1i6Kx/ELIPlh2HSb1Kp9j43V/Q6sqSA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:43 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:43 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 7/9] selftests/mm: use selftests framework to print test result. Date: Thu, 21 Nov 2024 13:52:18 -0500 Message-ID: <20241121185220.2271520-8-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0216.namprd13.prod.outlook.com (2603:10b6:208:2bf::11) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: d48a6741-3745-4f7a-e94f-08dd0a5dac20 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pB3ONJDs5zd60H8/xakzSjH5dZRXBpNR6cjS+uwRL5csa07lkVJ6BclVILoL?= =?us-ascii?Q?vBc4tKdMDwLh35FObhdj3Qliw+gMbhdMRNt+9RHYEygJFrkMvc2sPRWfpr0/?= =?us-ascii?Q?EDJSPfFT1yzoOlJBxgXwgUTI8pq+sHX4TBwDdkuX8OJufmRHh4B4vxmhXrIc?= =?us-ascii?Q?4U/gJnGM+rGM8FIzhRUbaVpSAOpUvyMdpQ7pDzyx/WZX1o0fQKtKsXKgOxDc?= =?us-ascii?Q?5rbzrhEgsG70EazuW3jt/FZdxRtiXlLTAtlINKj6fH3lasd+ImKMJURTxjbJ?= =?us-ascii?Q?kxo94XVSDObV3GLQwop7YQZJMnny8JmMsb8bHk/kLXORpRm6f61RRXnVpTg3?= =?us-ascii?Q?VGq1OcMaHBpkyiDv43KUNXfbwaopPl4Wo92Gn6JNurr3ZssuC4Jpl1C4R1s5?= =?us-ascii?Q?DfHPeZlhMRyS7RbE8cTI1/1mZIMlcPPIgrl03kRhNWuABwpT7xk4O01z16gC?= =?us-ascii?Q?IJLIXQQ/6JBPdBogdyGUZ3PyRHTwCabE23oONb4ieg/Gi/Ak2O22Ztql2qyI?= =?us-ascii?Q?5kqNte7TpPT8NLQXhBK5UoxRv1b/97edF4hKY4rWowicqgtT8HqdYeI4UhqI?= =?us-ascii?Q?BZGumuAUJWH/MnIKiPRiLMkDhvNCEFTCCttjujvaztBy2YzvdeWtTQxhRv01?= =?us-ascii?Q?Ea074M4U99MKJDurLRaF2ffzVf++08lGPZZWwPUTy2MpHcH4w0823ehI1wtj?= =?us-ascii?Q?0s+yjYoH/ClNmQclm5owwa8BVnERRkm5yK3P/BMzkPRaw19vmSHx3ov7Qaht?= =?us-ascii?Q?UZ47vkQnwZuaMUp61lncmiJ95t/JxMs99H9ZjPFLea+aakyYt6dMSaPBlIIu?= =?us-ascii?Q?Wx7dUqAz9aj0CoDbtw9BiwHBwkbz/ypUymmDhB0vdTU8ikql4p7Hd6/mKRm0?= =?us-ascii?Q?JisqLlR0ZHCW/2hqdUfWJsoarMOnvpDLyQZsYpDFbHX6tdMbVZ6aXz12se33?= =?us-ascii?Q?JYRceeGCWtQt895AnfQqTJp6iz9f1kJXqZfPWJzM5bkK3uvBBRpNcQYi6i0J?= =?us-ascii?Q?VIXECBXFAdS9wwRddGOY6uJhVY2ApuTHZsdUKkfum5mbJ3X1wEc3shrzl+9Z?= =?us-ascii?Q?dtr1UEoL9bM9hyM9L6g6VtWMD4zR09iDpln4i8bzx+xPPbQwqBP0ut5jQBDh?= =?us-ascii?Q?qjWwsrx8tbc0RF06ZevJSTThG6oLsZvZpB7qMBGxVgnF2xXQrLB1+M8ULhpn?= =?us-ascii?Q?IYCJS9O7Rv2Na4EjCPv1z+197j/hG/HOJG4BF+/ZrrNw2Qoapf4iMEaRlY3L?= =?us-ascii?Q?8XApAVNdHDTJqB8eb1dLlGfn6EWiDbs2JmW5Gp0CfLLaooozjI8U1mnEeiuR?= =?us-ascii?Q?TlCeE7+ZHxYIFvRSpkf696Hz?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?1nhxEJx3Wd0Ai6GJe/ZYf7yyDCQY4wsy1YFGLbRu4/8O6OhuktHVG6Js4KM2?= =?us-ascii?Q?2HXNuoWon4g5PESCs/vOh/disjjdVr4tqiFFIVzkBpjNC249wFZ79YOq/zzn?= =?us-ascii?Q?/iTSsv0v/wk8YYNlc6nJBlwGr7zqbsyjwAXk38rlg5pE4f7BcWaOXG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wsYmgrCywyV2NzCvblR9uMKbg9BMI+YVz?= =?us-ascii?Q?iIUi4eZmFWKROL0IUwAX3n6JzCooPXpxlw8TjNnIwLxUgfVuimp8VHwMfjvG?= =?us-ascii?Q?0l+h7gQw54k9uU57sevc2f9ADRW4T0L/j0rLni709jjjnu98IWQJ37PUQ4Xw?= =?us-ascii?Q?xGRxpKc0KP8RCMBPgY32Ln1lzfF7a6lOEFYUKBxtpG2S2b8Ne38DRnf72FKB?= =?us-ascii?Q?ULQ5hsKy2MsubwVc7jERNtS5g6OhKk5yNOPUAdffDj2J1H8yNuc+0IsrNILR?= =?us-ascii?Q?4XUWljjPfDkZRc3EirmE/PRsVYN85SzOz94ufH8Tl1iC136ys2JW/nLCsqeE?= =?us-ascii?Q?4G/56wAyde+3yvjDd0PSX0brKG3sbCTn92EZJ4nYOZxTi292a10SN1Oee0Tq?= =?us-ascii?Q?90B53HqeaC8z07hkkhvDL7t+WZdqn6i6/fFRBv8QzORxvf8a/Kp1xHqe92kz?= =?us-ascii?Q?6ZSFF/7HZoWGdxrVEffKvLB3DWh1RcT0aUqApFZDISDAqmrfRjRH4BaDzevU?= =?us-ascii?Q?48hUAnuM8+MN6X3WiQs=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d48a6741-3745-4f7a-e94f-08dd0a5dac20 X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:39.3578 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iZIhmcfuYvT8fu46Ma7DfRlkkI1vlnm8bNek72lUnzJhd5sNKCsfdLhyqMAOv7LY X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 Content-Type: text/plain; charset="utf-8" Otherwise the number of tests does not match the reality. Fixes: 391e86971161 ("mm: selftest to verify zero-filled pages are mapped t= o zeropage") Signed-off-by: Zi Yan --- .../selftests/mm/split_huge_page_test.c | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/test= ing/selftests/mm/split_huge_page_test.c index eb6d1b9fc362..cd74ea9b1295 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -108,38 +108,28 @@ static void verify_rss_anon_split_huge_page_all_zeroe= s(char *one_page, int nr_hp unsigned long rss_anon_before, rss_anon_after; size_t i; =20 - if (!check_huge_anon(one_page, 4, pmd_pagesize)) { - printf("No THP is allocated\n"); - exit(EXIT_FAILURE); - } + if (!check_huge_anon(one_page, 4, pmd_pagesize)) + ksft_exit_fail_msg("No THP is allocated\n"); =20 rss_anon_before =3D rss_anon(); - if (!rss_anon_before) { - printf("No RssAnon is allocated before split\n"); - exit(EXIT_FAILURE); - } + if (!rss_anon_before) + ksft_exit_fail_msg("No RssAnon is allocated before split\n"); =20 /* split all THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)one_page, (uint64_t)one_page + len, 0); =20 for (i =3D 0; i < len; i++) - if (one_page[i] !=3D (char)0) { - printf("%ld byte corrupted\n", i); - exit(EXIT_FAILURE); - } + if (one_page[i] !=3D (char)0) + ksft_exit_fail_msg("%ld byte corrupted\n", i); =20 - if (!check_huge_anon(one_page, 0, pmd_pagesize)) { - printf("Still AnonHugePages not split\n"); - exit(EXIT_FAILURE); - } + if (!check_huge_anon(one_page, 0, pmd_pagesize)) + ksft_exit_fail_msg("Still AnonHugePages not split\n"); =20 rss_anon_after =3D rss_anon(); - if (rss_anon_after >=3D rss_anon_before) { - printf("Incorrect RssAnon value. Before: %ld After: %ld\n", + if (rss_anon_after >=3D rss_anon_before) + ksft_exit_fail_msg("Incorrect RssAnon value. Before: %ld After: %ld\n", rss_anon_before, rss_anon_after); - exit(EXIT_FAILURE); - } } =20 void split_pmd_zero_pages(void) @@ -150,7 +140,7 @@ void split_pmd_zero_pages(void) =20 one_page =3D allocate_zero_filled_hugepage(len); verify_rss_anon_split_huge_page_all_zeroes(one_page, nr_hpages, len); - printf("Split zero filled huge pages successful\n"); + ksft_test_result_pass("Split zero filled huge pages successful\n"); free(one_page); } =20 @@ -491,7 +481,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path =3D argv[1]; =20 - ksft_set_plan(3+9); + ksft_set_plan(4+9); =20 pagesize =3D getpagesize(); pageshift =3D ffs(pagesize) - 1; --=20 2.45.2 From nobody Sun Nov 24 20:38:59 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB5051DDA34 for ; Thu, 21 Nov 2024 18:52:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215176; cv=fail; b=IdDtfJflSS/Zq+9MJY6EdEQAoJdYl7Vugb3fgq1kXNMLSoyZlxG0MWkTeeHCOrdsfqU/qZpy4/PvJl/SeWU3szSdZNoIrz9v4IevPqnAKRPfyAqzhamnp5B24/KcFhOh9DJmAUE1tI3fMiIaOxtjrDis/ZqWxWDIIzJl06QC8AI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215176; c=relaxed/simple; bh=FNrXjigdhvkcFodLMCKqfeCb412QSIHMbfKubGSOS4M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=REMx4dYjZLsmw6DxXxZYGfPnULxKkAJfewj2/1IlQ1zNuYJ3Z3e2CN7C6Ql1E9LvzGyIGeUJZlbAFTLB4piJtmTc1pT7Mi5UV8yXSTck7c1K15RhvDwlOO6XO6JkXIyLy9nHCajHYGtKzIhFKkciYokfkG9aRyYwypnR+ukAi0Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=VvLW3z6D; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="VvLW3z6D" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=f6YGtIf913s95DqRdQ4qpMenjI7RaZEGcjzFL0BDpoHpXU5Us9fmNIAXVFlCOXkTE9jXao0w+oUNHuoFe+DMfxtl31yA2IxBPQQQDihaAbvAoLkV/5eXIkZ7lkCGUMxnSY88uhtJlqMo68Tp3pWEGc5JriVpe9W623SZycaTX6endfZM82zf+j+zC6Feyo27b5wJmrwroCSxarJp+xprZqAyPqV9Yl/Xy/yf2BeBOSg9/4ZX8jZ5rhBnbxxj9yau4j63LjqWsxfiYdlgRjZVRrashY9sh6lNPX5arocBQcgyt/wWlSir48vn5Jk4ufh7raOmojwCqFvqMG4XakxTpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FZxMul1WU308N00KYNlcxD/DyDEr6jnTyKBgAiwblKE=; b=IW12Km/Jev2dPiSdRCrrj1sQmX0RbqbaOPyXeD160FD/7SuSU+z3gk6SjRUfBP8QJTG1l8rASLSk6cYax2+GOBj/qhgIqsHAeiMU2Siv9tbEopF30NcChThM3GsUNIuIO+N+G3NGFcaO6NdmiCJQHpo02ve0cku+HSS58P/Ov3O1e+Sns62dvnNHE+d5qmHNEAjdTH3G56PwVPVRb2TQ2PEU+2JXmpVmzpKetOGM/pU/6bL6geKu4vxI/097/pp2J24oMAguyBoRjyy6P2f/LFrJKH+1Bh0UAy0iIgLPGxikzOJEoDbp1qZOHLwo6fIxqzJ9ns8RdgUa4GyS1w8LLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FZxMul1WU308N00KYNlcxD/DyDEr6jnTyKBgAiwblKE=; b=VvLW3z6D3np/o5BsQn9FpOQw8X7W1MDC+7R/1N/ClAtmpQBIrO2sz2lSYRVUIensqnfYIDRMcS8lW0xtlh/2lMvci2WVolq6vR1GxW2Vp+8bj/5syOHRqPkCqr6pK6kqnQ8laqVgaSKEsa7o9ccyFDH4aAuOvNnx3vwz23eQgUkF2I/t4jCkZaEiX2NIZKdc0xpsaqAjRwzzQe+KZTWaPLfIkmNI43p4m0GxiyYUgrtROrktkJCyE40vBz/+8Xx4Le+IGUkHQ8BzO95HdZhNnUZWnRjlJfh+pDUzeJI/hdvw1RHK0Hvq8fGAR+B53Q3Q1mF+bdzSIc9pAKwuAGblZw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:44 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:44 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 8/9] selftests/mm: add tests for splitting pmd THPs to all lower orders. Date: Thu, 21 Nov 2024 13:52:19 -0500 Message-ID: <20241121185220.2271520-9-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0219.namprd13.prod.outlook.com (2603:10b6:208:2bf::14) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: 55cd1dcd-20bf-4a0d-9a8d-08dd0a5dacb6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?4UsN91yzlTcAIIPUjS+LxIcR1At9NZqa+nPI6BGO023zI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eBeTQBvDhlFR8a2Lcd4TKwYgBLollOk52WDp5C6FLlR7jZod?= =?us-ascii?Q?qj1q6oY28MgdXlYe41bYuZ4+uuLjh1dZ75aZELSk34Hh0oQig0vYPMEHvEjx?= =?us-ascii?Q?G1YIgDZRpMg9xRWFNsR03NsN+/qCGxJfOkUKARa3ofb7LIxjx+DevT5y4GHt?= =?us-ascii?Q?T64tqXuHQnphID1z+VWLTsT2JkeXZ+De2vRrankqpbw/qMn2EzqUchkkgs3a?= =?us-ascii?Q?xwdPJYD+YPutHLie0rRz/KQb4KVtUJNwVkDAdvWzE+oq/BKBs3B4S2tEtK+l?= =?us-ascii?Q?vxrGeBrHIr4VLmwm3OcFsKE/u96LpBg6yg+coQrEs9SEpGmvS3aO0ygmLs2B?= =?us-ascii?Q?85Yzw6iAB4xNApim5lmQunZFxVsda0zk1SQ4stSO56Sd5tTZxuoEb9ZtHlDe?= =?us-ascii?Q?J1nakaYWMC12A4JTadwjvgLg?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?alo0wEYHA4zfFcKYJaglvrWFwITA8oMBdAJna8Co3ZHko+l9TPOPS4yu4T4y?= =?us-ascii?Q?mM9jg/jlx2bATKMOm4gW4rvRgFEWuR7Q8D44c4JUdJJjIEkhwC2hLaTbdjWN?= =?us-ascii?Q?VAF11upmQFc+Ma7+25BcEArIenjAFuF/l4ZmQ+mheVcq7fLQhnaIu5GNXLsc?= =?us-ascii?Q?2lA64JuUH1iLguMzAaw0MHiEXMjMqD8MIZ33Xh6JsclpLBI0LpWFRaeI1Jay?= =?us-ascii?Q?LA+Lx+ITAgiVjkZPoVOpDNJ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-ascii?Q?wR+N6p7FVdnqwzrFvLfbhj1V/g6Sv2q633/99RL2cCNgVRcr2qfomNhx4JoJ?= =?us-ascii?Q?x0HjKqDsBScB4zqtS7wGYH1ij7qFkm2ywAdX0St3kvyJUt4lkN/vh2IInbxy?= =?us-ascii?Q?h7iw55WVTqb8KspYNoVxEoDW3P3ScEXrEUbhkXm1PErLSGvJNMjduz86BcvB?= =?us-ascii?Q?0ksFJJE53kUU4EBuABYzMy3UvJuQ8K2SPs/cAbrrMsxZmAmtAVnAVGPl9CZD?= =?us-ascii?Q?Pg9Rf3vs2ha0Owz9Y4zzReVH0kXvNRdzF+snpNSZTR1/0lVkg9SRhD1K+lpm?= =?us-ascii?Q?qyrQHkEXpknoGcBD4xGH5dSWjJ0njBhuECtGluLD6+JmTDyJOiyHZoOZ1Ryb?= =?us-ascii?Q?lzKgBVn6coz79EjU+nsFKsx3wjwLXNjZvh7MteBoMoTR8NFRJpyVyXA9ZCa/?= =?us-ascii?Q?hZzLKg37vfCXrS0IaNOX+U6/XE4cUfEWPhxdcAx5?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55cd1dcd-20bf-4a0d-9a8d-08dd0a5dacb6 X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:40.3428 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VgdbY/S8zC9OIzXqtfBWCkGPO+SA/r8o7Wmabz5lEKYImm/C5/Z1aHSjHfFk78cJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 Content-Type: text/plain; charset="utf-8" Kernel already supports splitting a folio to any lower order. Test it. Signed-off-by: Zi Yan --- tools/testing/selftests/mm/split_huge_page_test.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/test= ing/selftests/mm/split_huge_page_test.c index cd74ea9b1295..5bb159ebc83d 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -144,7 +144,7 @@ void split_pmd_zero_pages(void) free(one_page); } =20 -void split_pmd_thp(void) +void split_pmd_thp_to_order(int order) { char *one_page; size_t len =3D 4 * pmd_pagesize; @@ -164,7 +164,7 @@ void split_pmd_thp(void) =20 /* split all THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)one_page, - (uint64_t)one_page + len, 0); + (uint64_t)one_page + len, order); =20 for (i =3D 0; i < len; i++) if (one_page[i] !=3D (char)i) @@ -174,7 +174,7 @@ void split_pmd_thp(void) if (!check_huge_anon(one_page, 0, pmd_pagesize)) ksft_exit_fail_msg("Still AnonHugePages not split\n"); =20 - ksft_test_result_pass("Split huge pages successful\n"); + ksft_test_result_pass("Split huge pages to order %d successful\n", order); free(one_page); } =20 @@ -481,7 +481,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path =3D argv[1]; =20 - ksft_set_plan(4+9); + ksft_set_plan(1+9+2+9); =20 pagesize =3D getpagesize(); pageshift =3D ffs(pagesize) - 1; @@ -492,7 +492,10 @@ int main(int argc, char **argv) fd_size =3D 2 * pmd_pagesize; =20 split_pmd_zero_pages(); - split_pmd_thp(); + + for (i =3D 0; i < 9; i++) + split_pmd_thp_to_order(i); + split_pte_mapped_thp(); split_file_backed_thp(); =20 --=20 2.45.2 From nobody Sun Nov 24 20:38:59 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 896571DE2A6 for ; Thu, 21 Nov 2024 18:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215178; cv=fail; b=crvbiSKd8M5IFAsOTTqpdfHda7yVqPBh2cOelMqXGj8344Rz0Q80weTnv7O3wf4YVA7wILU0na9xlW9+8KfOC1sT0EobmHkQblWaq300sxur/ken6Z1zOSMhyrTpaYlovHH2KdAyFP9avW4r2GRpmL913xfiUsM9Za7JpgouO/A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732215178; c=relaxed/simple; bh=zPGR7jKRPB6tJMDs2QTqlQCPHl5sLzjWxqmoVUkf1Co=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=D46/9FjqzjZwnAKVkccY1PbIEUMO5nFV2srzZdZ3RRq6UUZ6o0Y+itUekJxLFXvbviSbGiFM/lo4QgyLGSjxbOu3/Rlgxxgs3YpwlnUr05tGVrdPlVCtMnN87lwPrcEwuESKyAUWaSoS3yq11Z6K+NWpP0An694f+zUtxblp5lU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=OAdKuTM1; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="OAdKuTM1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DFHo8moea7rlV4/8uZlcbNdEjHwR57YXRxfF+RtCGWOQlOGeEcdpJ4rY2EH2XHhKjHEXJv5lAkRg2eNhl2G76j7GBCl7AUMwkXUjX99BjuPcN9LnmXDMIY39VanpfMCM82lfiqpJpUhyGF8lDAj77PNwE0AFA62bxi8ZuNy+ogtL6XVvN4wDvHqdN7U4WYMxTwdgrO81/uhHPWLSaqTNReyAZBg68ylM6BZJ+TZLKrQGKFzfWseaXNLrEoc4QyGeRNJiAvwC3cX7s/M/Wwv6TLrnvQ2fo0zuGw9hkihC4KidV8idj/pCjSE5iLCWUlglGHfLr/q7RubryQns5ykfCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7vfodItUcrcyLrOMU+QPVr1fQyMNwn6ddi+gcaz99x8=; b=sVt4O3NoNqV3IY+VnRRuMNM5/TGte3foB9mw5cauoXH4ahwvJonR44TaOkSLqOLHhqFyhN80QQKXzHTy+r5Isva5Sm0Z+oZsFhkIPC75XCgjnXtOHYEa6K16kc7/Fg9P7kjfE1BpjSmoZ4iEXldS9TkyuStYCQH/8MPOWgjF9sa8umE9dXTQShV3FWbMECq5fyj7oJJVucUHMyfsbxFbtYPRZpKbFrm9G/u09H+CWXE3cPb7gqGH91EcQVcCrHhepO+wBJR1WoneNMEFqkgOn/6OH5PQvM090oId/RbhUcualaZW9Xd1q7mLsTuwWUpI8E2CbmMfQsgmIoJu0FN3+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7vfodItUcrcyLrOMU+QPVr1fQyMNwn6ddi+gcaz99x8=; b=OAdKuTM1Ig4jZxUJ69RH0ro9okn4s52IRcJw7+HaNeIXFLfooXlmUJmCRGWaQyBcDNTCaEcbccSxFjyverIj9q6t86jEi3ueQXBAvT+SJxbbTsCnMzQqEA9425yOhFas0WOElaJJfhptsuKclxoJzDStHfoIeTYh5WJX1X40zb2tVbnqX+Or9kOnEB6uvUucDsFNCtGNna6EuiQjAEY/KpWatoc4doDlyYcT2KAJUI8E3v61hd4PkFDMz7PFBhoyuWJIX6HB4oBm59p0yGwHgPJKBEdbHKIIqjzztsOrWrGHiq+8mfo1RZssrgB42qUq+b//uj+KYkrlXwUfOehILQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:44 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:44 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 9/9] selftests/mm: add tests for folio_split(), buddy allocator like split. Date: Thu, 21 Nov 2024 13:52:20 -0500 Message-ID: <20241121185220.2271520-10-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0216.namprd13.prod.outlook.com (2603:10b6:208:2bf::11) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: 0634ce88-ba82-4fd0-13c7-08dd0a5dad2e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?ao6xM8paWj8W1BV6BMlXhk3QhR/VThr8iEKeDACvc9Y7fOoBPjN2A2xfG6Px?= =?us-ascii?Q?7mw//1i3mMpVEvRC48S1NBHGrCa1DyvjemfUPnNGSEkxZb/Vhscdb9ARX8ck?= =?us-ascii?Q?Rki5H2IWW+miJiyhvkAQC9VbmpLAMZuJM6E7BZJ4J40g7LHssvuTk8iWRdoK?= =?us-ascii?Q?rlkMeqZTtkhSInBcQJJWTabZDW3kvzI7BxpTK7Xhi1FV/X+cGiZsTUbPIsbf?= =?us-ascii?Q?xCOoHfgQTsAgmlrIbsC6vKUJFYH4dS57ICsa+4JpbOdmF6QHSvoptWHOElNZ?= =?us-ascii?Q?SK4IzNoyVZdPwkwaQ1u4ogkeWDOwwn/mLE0lkW2B8z80S1x728DyqvnhmeUL?= =?us-ascii?Q?oXnBtA1UPGk8Up8FgQYkyWJmaNrCtEjcYWsdoj+2sUw41Ujfps/8vtnmjgxl?= =?us-ascii?Q?NVKoInzAwGSmZc7uqhWgje+29Q/gLRyBNBFVLgri+xQf0kMxAy9za9Xa6/Hx?= =?us-ascii?Q?Dbzykji3pg+TfZztyeLeJV1l6FnIwlFZB8unuaORP9hZ6Re8HMT7OwhbGLXq?= =?us-ascii?Q?cvgvQ1NobiS6lfVKXbA1TZzBuOTIqC2+pVMMTnM554A4slPPLjktX+rDg83c?= =?us-ascii?Q?y+yG8eK9VEV/oZpr38PMoXDEFMdweFyx5MnSTefWbJJC57HQTaIebtOHvAih?= =?us-ascii?Q?CEe3dfKO7ybiGXoZxpBl2XrtijBR3qFW8o575L3rD42CUf1Q7v6WmeCssIkh?= =?us-ascii?Q?lj3bFSQKUgY/1itjZJin8algqvcIdTOrr0p2eDL0yJu0ETmoU6wAzxmAxbjY?= =?us-ascii?Q?Uv9je6cpAHZxNxCfyKTUxhDyCVI2apw423k+mz0ng4AuMfSGx0ZqJ72y6rys?= =?us-ascii?Q?5NpT9XRfZK0I4q2cQLlBk+mrWhai1UWfsmTWjzwn/idXZYtUr/HAa5m/DYtZ?= =?us-ascii?Q?Th82Bi4jtd1ZP+4OVV7dH001va1t5MDk0VTyV3v6M5gB8HqCF1qf50eWUvnR?= =?us-ascii?Q?LJTYX6Z6b6RUc6nwrLrR84N3zX0JJ/fo89Cyr87/oyNTKFbHOyHvV9Q2RCbr?= =?us-ascii?Q?llZv7+Tp6ntMu/wAlS/0ylHKrzz9xHSWX1ctoe2unjXyr4qRom8klfPl3sHC?= =?us-ascii?Q?Sl31DruWDH78nBfjW+drshMnOja90GfTXU/P0SKzDgr3qwRG/nTO66n8+F9e?= =?us-ascii?Q?v8gtH5Kp4TMNChV3Cql6TTHA3tRV4ge2c/vLvTV29lPz6sGU+DkGfGmKqW6a?= =?us-ascii?Q?rckT0QyadItX6KfcSqe9ENtnrOir9mf4b7FCNKuPEQuiiVKKN4H7ueidM7Qa?= =?us-ascii?Q?o6zyTgmyXkALj2xACtS3CFeyUFtXXXqpTlKhOqaeSzi35Cx2aSKJIyuObfMn?= =?us-ascii?Q?liC22+rlsYJidiiKy3efv2Ip?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?S3AWpXHLvR8V8016XN5gZXJsu6xOaAvvlS5qjELxYLjsFR5JjRilojyEal2o?= =?us-ascii?Q?+5UQ4O+fd4zTERhTPbm+/GBeblw5GOY6LtWtFNSttakcQL6rRWY5RhZFecK+?= =?us-ascii?Q?y7umaC0BoyjhemVXulbzxmo4HACzunrhMKjLPIAAeDX/rPdi0L8zXCDLU5rZ?= =?us-ascii?Q?KQ7fr+zcgj8d0yAj5NbBN2QlQayRyYlg7nOdOY695Jaa0YNE4VJftJVEn5/9?= =?us-ascii?Q?7NpbLDRCJiCUis0Wrghx83slWFOOh/RcHWM6a6YneX1HtY3AunNmtuAetQDC?= =?us-ascii?Q?478tlK2XVQc/FNKlODiYUt5ZAIttYom1U3NlcZuu/SeFsQ07C9Lkm8N47bey?= =?us-ascii?Q?FGH1W7/dKS2blT/4MBlEmV7IVq718RCjF+YsMRbGq+QisWveWWr9kB4YxZvR?= =?us-ascii?Q?KVtMsvG8FcgankrNKEZ/FzAMIqbH60EyDLS8wVX7kHqk1ZI98UIAlNwWgwR5?= =?us-ascii?Q?H6ytz3tNPdKEUWoYU7xLHOAbqhG1m+n1bmBHb3mzXGTRqN+mmV4tMAUwRecy?= =?us-ascii?Q?KIOIhJwm3+orC9b7OMYrIjJN3SFtzsRCWjaafra/xnuNYGzSObxqFi7bYdkh?= =?us-ascii?Q?5d4tTI1jLpYreMU6+Pgxh9Z0fGj2xBMy7NAy3eKfYN/qOr7aBkB0S9eJJ0o0?= =?us-ascii?Q?Fipiz5vYnmZ8FuY+6U0/CZSGnwOINqCt6KSiVm9ZZTLDLD2NQbPNpFBdgBZn?= =?us-ascii?Q?RyfCwEH8ECSIulo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X-MS-Exchange-CrossTenant-Network-Message-Id: 0634ce88-ba82-4fd0-13c7-08dd0a5dad2e X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:41.0986 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nQOjIULsQyyZeQzt+x8v5MCa/siBtpoh/RBWlZ+0crFxtyYE4wAd15VwwXj3/G6n X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 Content-Type: text/plain; charset="utf-8" It splits page cache folios to orders from 0 to 8 at different in-folio offset. Signed-off-by: Zi Yan --- .../selftests/mm/split_huge_page_test.c | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/test= ing/selftests/mm/split_huge_page_test.c index 5bb159ebc83d..1af8d6fa4465 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -420,7 +421,8 @@ int create_pagecache_thp_and_fd(const char *testfile, s= ize_t fd_size, int *fd, return -1; } =20 -void split_thp_in_pagecache_to_order(size_t fd_size, int order, const char= *fs_loc) +void split_thp_in_pagecache_to_order_at(size_t fd_size, const char *fs_loc, + int order, int offset) { int fd; char *addr; @@ -438,7 +440,12 @@ void split_thp_in_pagecache_to_order(size_t fd_size, i= nt order, const char *fs_l return; err =3D 0; =20 - write_debugfs(PID_FMT, getpid(), (uint64_t)addr, (uint64_t)addr + fd_size= , order); + if (offset =3D=3D -1) + write_debugfs(PID_FMT, getpid(), (uint64_t)addr, + (uint64_t)addr + fd_size, order); + else + write_debugfs(PID_FMT, getpid(), (uint64_t)addr, + (uint64_t)addr + fd_size, order, offset); =20 for (i =3D 0; i < fd_size; i++) if (*(addr + i) !=3D (char)i) { @@ -458,8 +465,8 @@ void split_thp_in_pagecache_to_order(size_t fd_size, in= t order, const char *fs_l close(fd); unlink(testfile); if (err) - ksft_exit_fail_msg("Split PMD-mapped pagecache folio to order %d failed\= n", order); - ksft_test_result_pass("Split PMD-mapped pagecache folio to order %d passe= d\n", order); + ksft_exit_fail_msg("Split PMD-mapped pagecache folio to order %d at in-f= olio offset %d failed\n", order, offset); + ksft_test_result_pass("Split PMD-mapped pagecache folio to order %d at in= -folio offset %d passed\n", order, offset); } =20 int main(int argc, char **argv) @@ -470,6 +477,7 @@ int main(int argc, char **argv) char fs_loc_template[] =3D "/tmp/thp_fs_XXXXXX"; const char *fs_loc; bool created_tmp; + int offset; =20 ksft_print_header(); =20 @@ -481,7 +489,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path =3D argv[1]; =20 - ksft_set_plan(1+9+2+9); + ksft_set_plan(1+8+2+9+8*4+2); =20 pagesize =3D getpagesize(); pageshift =3D ffs(pagesize) - 1; @@ -494,7 +502,8 @@ int main(int argc, char **argv) split_pmd_zero_pages(); =20 for (i =3D 0; i < 9; i++) - split_pmd_thp_to_order(i); + if (i !=3D 1) + split_pmd_thp_to_order(i); =20 split_pte_mapped_thp(); split_file_backed_thp(); @@ -502,7 +511,13 @@ int main(int argc, char **argv) created_tmp =3D prepare_thp_fs(optional_xfs_path, fs_loc_template, &fs_loc); for (i =3D 8; i >=3D 0; i--) - split_thp_in_pagecache_to_order(fd_size, i, fs_loc); + split_thp_in_pagecache_to_order_at(fd_size, fs_loc, i, -1); + + for (i =3D 0; i < 9; i++) + for (offset =3D 0; + offset < pmd_pagesize / pagesize; + offset +=3D MAX(pmd_pagesize / pagesize / 4, 1 << i)) + split_thp_in_pagecache_to_order_at(fd_size, fs_loc, i, offset); cleanup_thp_fs(fs_loc, created_tmp); =20 ksft_finished(); --=20 2.45.2