From patchwork Thu Nov 21 18:52:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BF53E64004 for ; Thu, 21 Nov 2024 18:56:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAFD86B009B; Thu, 21 Nov 2024 13:56:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C85F16B009C; Thu, 21 Nov 2024 13:56:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD8B86B009D; Thu, 21 Nov 2024 13:56:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8A15F6B009B for ; Thu, 21 Nov 2024 13:56:19 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4F0A381277 for ; Thu, 21 Nov 2024 18:56:19 +0000 (UTC) X-FDA: 82811004948.01.4D5147B Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2045.outbound.protection.outlook.com [40.107.236.45]) by imf16.hostedemail.com (Postfix) with ESMTP id 9E271180013 for ; Thu, 21 Nov 2024 18:55:23 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=pflVSGV1; spf=pass (imf16.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.45 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732215192; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TLbs+IMXe9PXriC98Ps/VfSjdrTeu2gdIoj8pxpjo7M=; b=M1AwYzK6N4SZKHiK+eg3zyxMmbN3py2o4hda7TUVe01ZleVGtGeEwgqRm68YNREXbbE5Ec h/CSU2yR8C00Z9omLxflAZdnHuAJ///ch5eZFT4QwWtwIm+WgtevwkAeEjXGfaX9NqCFOc CjyvwmDvYYX8HrvQeFkXLGOQvL5lc3I= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=pflVSGV1; spf=pass (imf16.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.45 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732215192; a=rsa-sha256; cv=pass; b=a9PFComD5oBU05W8Td34yRCFQKnRmExeVuNSRgK/kzM+59QC3qG7KmaOyj5uIM0ocNoOZ1 FN+7T5IQEUttUEXfL9dxYIw+GKPH5JC+OZTWoNHH5gXa7mEQll1nh1bFqu6hZoZZM/6m6f RXWfov8WU7SMAk859w31JzsEVeX3Ssc= 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== 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> X-ClientProxiedBy: BL1PR13CA0232.namprd13.prod.outlook.com (2603:10b6:208:2bf::27) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) 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: rYZ7i/cqgg4ynwSmUbyx4bJMIuT4lp84HfHTRlogUhNfRMKy3F0WoWN5O0m0WanfgxEiqh5MksK12a9fKLHKvWBKtnz4cMEDmlz2/DqJmmwKpLe114iITtKfJe46NByLla3fvbuufpv3YWIMVgFzjVnyZMg8t1dzc0JlVVacjU6PM7JLgg/ugmL7PbafwSUDgdCBZx9m1cxszS4H6YipitTlOr70UsfkCT4cVuyle2hH/TxG1BbwTZu/S7CUMCUKBUtNFGxC2YiBCkbhHpCSvvO5HiMncIXmONFvLH6CnlqJPNRd1ute3myXFpC53ckfbEN7UJidDui+gR/6sNd50ZqIfVJmAlmvAu4hlytMMyzu22+wvXIhyOITiup4e2fGSuOA9bxlkwsGlAUCU4rYIlCU7kvS8rpU/FHRrZkgu2XoR2rWw+PETacdwfWyWbGSBbCsM0VkUCWEGAuPOkE07y1s6PXeLAnazaIbyEIOIEmZd1xJKrEzXx2zQuaoxVduUtzNUfpx37QydwYPeQ407o9HLCf5UjY5VFpOY07rLPxVWIeph0W9nIT7V3aCC/MV7fzpYzhStabd+PvbqCc3WSjRd+VSu74LKq7PP14lEC/NWzmHBOvwED3kYcBJR7LYMnM2ZsgAhuuBrbSNzis72zHCmuJvBXTxA7XaH0NWDmDVQ+tWe8Sr3XSuOg3H16W05LjXbQ/tcCMNezgFkikU0IiMO+wINGEo0UQN6UchPAyN0SK/0HOG9Fs9WTYjO5BuXDbU3ZPWXP/Lc7wJ1GL/UnITOQ8ZW6DVhPFEn08kmJRnMEE8NUA1hi2t2FkHCYIp+hgcYaWA1UwtIevIZ36smVu4FwkvSEbe26qtvuQUIaSOwK4apbs4MTvo9zdqFi9b5/0iFWhlmyxkAdCJ7oJJHAwwOadTsEBxV5FHC4DvydGKxBC7BecO2eBUpAvHfoma5DbQv68CGGn7A9Ko20cMNWgrKnugJYevM59OS+UYBvzAAdfAjco/jsrImJwynagbOflSofVByujtp8QVwPzJv/LOv8YPcnQNGcFrVtsL1dci77kAGdmBZ053sotaejoTUTC7xTqrdI9wbPvynVMDXeonlI5gTOo9JWXCySOZq1GlR+sFu/90KIO8qDW/W1D3pNn88CZnwbscTBplNURc0MMNBlK1L26pxbGL20519S9w/rRs+7q9HPkyMXpSeGrnd3PlHBZ4PNuo+0PyZsupC+jbwrokLqhbM5EWa8DJ07k7uZFXsz8cwcyc1XriRAL2MWKOEANTqpoNmsTkPLS+3dHUkQF7qR2kD1qAFxPYwBoJPRx6GXE5fEDIPL/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: lVNdXfh6XZvufwtUUGmoaX9YaTAIhz4ZZoMld6q3g9TKPym24QFc+3tlCF7MuHq76TJpvRIkF9Xqpdr6WuD5TJ5BPw4695lR7Wkui1lmBdoJkXLkmP0qvuXd0ENP/oAjPT5gsJ8NoT9B9j1vGDgFtahLkYTY5MjVO+DK6uSYVqgcW1SL54ppLOetngAqs0SN+qsurG+fCPWGuwH6YEMazZOOIfF+VJfNyonRinp7orIdXJjlOQrZ1Mkv2XiYPwSrbkJF1tEEDQn/V++JKnGx8Sykk51mL3wEdY0a5j0RddxQdL+qN8Gr6+B08BlJCg0+D5iimylvCfaclZw8MHmLu81VPr7JtG6hPrXw+0ighurYgfegUsFBztkb1hMtdXUm23keSMd7vCZZwA2JS7cgw+7Y7qjKJUdqDKykBls4L0Rsh2hcyQHXb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DYoy/xvlNpvYD0u8VxahItLl8S4L9bNvi0uLThgiHFIybmOBVsK6KGm+sI= 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 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9E271180013 X-Stat-Signature: chhras7jyoqorebwgr1supnb936q1j17 X-Rspam-User: X-HE-Tag: 1732215323-85483 X-HE-Meta: U2FsdGVkX1/7LLRd4ekOq/u2D2kB1aO3+N1t9yVtwH1tpc57zOjmGOmS6esQQGhZoUjvtA6FRHcj97geg7WZ5dujsSHScmIQW7zNtg+EQ2zYac+2ie6WwwifyoRbPdx3Mc8xTuWugL1D3ftWQd9P0vhv5lMXDib96x2uJEhCNR8rCXdP8oFgM883yMak3o0UHZ3ouGu4aT1B8NaOm4bW+ToZSATeGgNHjymtTNJoTSQr5Evwzqq9ZyFfi/vWhA4f9KcRsRHaRG9AgvlYT3IxRJcQ7TQt/QfjJw8rZwj5P9jBth1AZsI7noryCuAZmnVeo5x5vxaY8YJ3M7FN7uke3owbmCUK51/sX8o+6n2xhh6G3UJ0sI2bS2c/K66UpmrURC6LxY6b+x4VQFtOL7W2fOixC9KHJ1VqD+Lk08jbFr/iy121/OEcw/zu9guX+mpCKym0lSl1pO9fgC4ye2SMAge7NNpaJj3XnEmuURv8avFb0D3z056vlObuOip/X43ZqQwTBKmQ56prQmr5qCyrWJOMJt/hYAqqVz3piRe1BSH2R4xM5Z8OcMiB7/RNtHjLrstHT0nnpXO6LwUoJ3wJw4Sv+jRqIqZYPD91LoBCJzy+wikZKQjv+LJhw0qRlq0BdsWlr48z+q1Wp5ew+N4N5LERUJ7aM7AquZByZSdIkPEO0x9bI30M/q+Cb++lLcNprPK1dDzKuBx6lNswJKw+smHjQal9Ih8NO7ZCm2awAvGbkeR88gmBdcfPKzt1NsCvMMSvSrtxMejtlfVhMikl60QULbPhRcwW+3H5mA4ELZUhDYb3vtDYo4VeBQgCclTScPLSRccKK3cOoT+yqiGljyvL7H3dcGdxctAKeSj4BDqhMkN97tAoJS/fipOlMKG2ULmOwZLpHA0nsirEREuGLS+6arDjFVmIeDZGEMgD6uxDZ7BlOvuPKaIloC35iuC9ZtH9XvaS5Kahd7OakBV JSMe7SHm ucKR6iLvj+fQryW2LurNu+0DCoKkNkP8KI6abfAKymT2K8GCwJyiQOEgCkpO81TugDvBxo8cplmUbwjRv5y4A61950SrPuJ1jUM4ahu3LNacrmO4cHXDdC+2uQ+RKyFqRkZ8C5M1V0cPXtRlZdC05RBpP93dsoTv31kEfzcUjDAs8XP4JeZlAHI8QFnxqa/6ec9D337Ulgrsu3rmaW/6mCbupjWwJmSUhzAcAjoYwxyvqyvfobXUb2PjXrkV7Uh/A8x18TMUUYt9rtTmZurRc6ah/z69Sote/ZJM9U5Dl96KNTBo7GS3p618YORKW+sKJTTgyTBLLUwAX+568SSpuuXjir0ebpdkcO3+F1i/Zb/yK7j2VGVlQ32QDz3CTiLMKVankXLEhybjYJFY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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); @@ -3371,6 +3370,366 @@ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins) caller_pins; } +static long page_in_folio_offset(struct page *page, struct folio *folio) +{ + long nr_pages = folio_nr_pages(folio); + unsigned long pages_pfn = page_to_pfn(page); + unsigned long folios_pfn = folio_pfn(folio); + + if (pages_pfn >= 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 = folio_order(folio); + long nr_pages = folio_nr_pages(folio); + long new_nr_pages = 1 << new_order; + long index; + + if (curr_order <= 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 = new_nr_pages; index < nr_pages; index += new_nr_pages) { + struct page *head = &folio->page; + struct page *new_head = 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 = (struct folio *)new_head; + + VM_BUG_ON_PAGE(atomic_read(&new_head->_mapcount) != -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 &= ~PAGE_FLAGS_CHECK_AT_PREP; + new_head->flags |= (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 != TAIL_MAPPING, + new_head); + new_head->mapping = head->mapping; + new_head->index = 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 = 0; + } + + if (folio_test_swapcache(folio)) + new_folio->swap.val = 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 @folio'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 memory. + * @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 split) + * + * + * 1. uniform split: the given @folio into multiple @new_order small folios, + * 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_split 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 one by + * one in PFN ascending order and perform stats, unfreeze, adding to list, + * and file mapping index operations. + * 2. buddy allocator like split: in general, folio_order - @new_order calls to + * __split_folio_to_order() are called in the for loop to split the @folio + * to one lower order at a time. The resulting small folios are processed + * like what is done during the traversal in 1, except the one containing + * @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 mapped. + * + * 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 = NULL; + struct folio *origin_folio = folio; + struct folio *next_folio = folio_next(folio); + struct folio *new_folio; + struct folio *next; + int order = folio_order(folio); + int split_order; + int start_order = uniform_split ? new_order : order - 1; + int nr_dropped = 0; + int ret = 0; + bool stop_split = 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 != 0) + return -EINVAL; + + swap_cache = 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 = 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 = start_order; + split_order >= new_order && !stop_split; + split_order--) { + int old_order = folio_order(folio); + struct folio *release; + struct folio *end_folio = folio_next(folio); + int status; + + /* order-1 anonymous folio is not supported */ + if (folio_test_anon(folio) && split_order == 1) + continue; + if (uniform_split && split_order != 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 = true; + ret = -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 = __split_folio_to_order(folio, split_order); + + if (status < 0) { + stop_split = true; + ret = -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 = folio, next = folio_next(folio); + release != end_folio; + release = next, next = 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) >= 0) { + folio = release; + if (split_order != 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 != 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 >= 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 = origin_folio, next = folio_next(origin_folio); + new_folio != next_folio; + new_folio = next, next = folio_next(next)) { + if (uniform_split && new_folio == folio) + continue; + if (!uniform_split && new_folio == 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_order. * @page can point to any page of the large folio to split. The split operation From patchwork Thu Nov 21 18:52:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62D31E64004 for ; Thu, 21 Nov 2024 18:52:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C10A86B0085; Thu, 21 Nov 2024 13:52:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC02A6B0088; Thu, 21 Nov 2024 13:52:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3A436B0089; Thu, 21 Nov 2024 13:52:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 81DC86B0085 for ; Thu, 21 Nov 2024 13:52:52 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 46DFEC016B for ; Thu, 21 Nov 2024 18:52:52 +0000 (UTC) X-FDA: 82810996254.03.C197212 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2059.outbound.protection.outlook.com [40.107.244.59]) by imf13.hostedemail.com (Postfix) with ESMTP id D8F4A2000D for ; Thu, 21 Nov 2024 18:51:51 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="A3/06sLp"; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.59 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732215033; a=rsa-sha256; cv=pass; b=H2ihWe54HlIz0zfGqXOtikgOsamOung13NCYI5BNJQk8l12KkOnhVoQBoDyfyvUvLTnvr4 zkzIhqZMe1Mk0RX89AslFQcojVwm9DtAxSfHP4tN+o3HdLPqAaUPGP5BSLtN+aDcAAGoYB wlegucR1OpCk2LZIDJEVFh707THISgA= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="A3/06sLp"; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.59 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732215033; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=W0CJZaAm63MVG5+J1rG+OLe2VO73aCelqREx4pG3Mto=; b=2OyxhWpKK4bojSowcGySnZLAGvo4xCsrX27H/zmSvI2k0HfSusXkixmqf1clfeh6W7HLNt IE+UYBmu5dV3MocwdclGHNNxronq/seUx8+zNdsRPLw1cEexUTjclnnIFXAq39x6xHZfAp Uu0DmiSoc30Sl68LbioA8eKfu8S2jes= 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== 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> X-ClientProxiedBy: BL1PR13CA0223.namprd13.prod.outlook.com (2603:10b6:208:2bf::18) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) 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: IsXydhsNooxn9h5at1A1xmgeswTKANPPvUdk/r69MEhU7lyRShEWJPAPL9MIXRbM8/pFEhZYV4rBVz6O0gDwwGHhGmmXSrSeZBxRaK4JfTNp8uCPwQptOmqxfJVCLEPbwoZnrH9FLVky0aHMXafQB22uPQvp2aCIhEsnZ+dia3suSKaEQzboStNsoU56sMYif9X0wXsBPkTQ0KbmFNUuJLNwPM7kpkowDdfI1RFmFi+EZ3XxJ54tpSAoXH7q39JFQtZVs+HojuyuJmltS5CyFce8726vapaXiQ/aFU6zrIFP2WmbEecYMU8kFlv+hLYE0lKYjr6XdAsBHZDGOP4wEZB6Un+4PMzoeqnZ5SffOwR5n+arpQ00NyjufE9m2UsWtspaqg6UalobiaFXce+YiueATp/lFSB/0jeGfhmRbMz/9ZUtvF2aZJezbVIQdsQjQU7CJLaDg5R4c1xOTF7glbNp8U948T6RhkbOW7R+jidprcDiwYVHnxRutqt6rt3DIDvqFltwOcXQp6EVKJWW/WMDGKUSzSBUauwPdeyMpdjZk/qQ2ry3/czQ2U/tB/7PGwM9kFqMRMYHFEp5jYHykuE3tljTiIZezexb0JXVIZ9cElAHB49ankNON07cwCgiZ1Bd3dpbYaa/H9Cnv6Souyxu2u75cqfP/1lAeokjsR8WZ3hf+dHeNTr+pAwXl93I7ARGXbFo7/kXwJhMC6HIJdpjWNH8L0F6VdU5TsuBUERFGZsX26BL+O49W9Dcq9c5Qqv0b+4kdM+lJNontc4DQNdvpJCpvKCFOvEpeObqyfMCl8Lks0acFj64i+utZHOvFtC8CjROOb1NoATaDTL+spyZ1Uzk56km3z2EneDMJ+GrWSexqyjb/5uWLYb3C/fk2wJKBxBrtXHRoaX+6LpEsL6Oc05a42Vnd2slabY7nwGleteRNQ4m1MCiOALzkhBn8Gbf0phAil2SaRsfkT8ehKX28ig9nc8FWlsbn3mP2nfioxkMKtpj3anxNpVgtVdKKK0wiPmIYHgvKy30SRWBUwjFqJfqE/Zx2ZgMkQWhOYoNUWd7AYL1gXPo3/w68GAZaAB/ilBNdoYc05WA0NcMgeThxpgusLcwHOHR9l+42g+zWEcdkMXqB5CMPJBwL9OUXKbBLC3YRU6xWxuQu7soBlu+iHPkY6ksFoxGitDhD/L0IoCeG9dPjHm0mzzQi9cHNhMX3ktRHnUpdq8oX3/2l+8h6SDkwjkQH2oKN/6BKBAfd2CIH+4JAi4+V8mjEziuP20Jaqlb96gP98NzAEKnKPDSRHrhy38jdODI7o0e/2wZWwcX4BA+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: TLxyvPAbo0JHzTWkFI0Eut8ThgF0klLBl8Q7ymJ0EYGo+wEexjomTgidppq3/Xg/JHsyiAqS6QbhlDuBO07IedEaKOZe4a77G/Iq6GS3uI95hW9mevBy6mHYM5jxxCVXhTHGPKlYabdVmv5zc0ktx9CjYKn/RlESiRpX3fV4+i6kcIk2J6032BG0AKrI4aPpehK31uuEv5usnF2TACSxiNvFASpn9kmaNIklxh8wjFGU5ZF48bhV87ofxBQ2RImAaI+iV0xhWdjQHRMgGMDwvzlSrcuFrmm8/OHOxi7CgJwwaGJX9xdUfB+X06ZqBfRNAxDZpJJ3Le9/+3G6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zGDISrAHwpe6M26QD/1OTinY/6q1Lf+5cpxWx3bkKCaVZbflXIUMkTlu1Z51WFQcavoAK9TwP+We3MGusewqhK8H/d7cMaRnankNiKPzJHV6w8stnaCcmMrISnVBY7iGQy0rklZOE/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 X-Rspamd-Queue-Id: D8F4A2000D X-Stat-Signature: 31h9jg9bcdrdna9ydsh8iz8o9z8hpdcq X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732215111-855757 X-HE-Meta: U2FsdGVkX1/wfpKQ+8gK5Z7gfGtch0pVyz0+Xzvy3zHrMfapeontLsXtrb9+9PlmC3ENvfK8GGivxxqxCFbJpgDNObL1ZRvqsUtNbgiG4gkVq3vIiKX3vSm2++4rY5feAM4/Fq0E5+PAkL7jMAfjwS0rzR2A+b+cNpVWWMzPCuWaqTL1Zv3Q507cyqdzzMrSrIn8brIxENvJLOAm7PMk2Sb9hbzOLkzxejb3bszzGwOCUflTbQPnJLOU3I1EX38oAwUYSYfZAEbYae3S7pEuXfbfDi8ff3MP0KiAg/oXUpFjWUSiGTtCGR1J+cjoVIbybG6YvfMwq/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amicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 *folio, int new_order, return ret; } -/* - * This function splits a large folio into smaller folios of order @new_order. - * @page can point to any page of the large folio to split. The split operation - * does not change the position of @page. - * - * Prerequisites: - * - * 1) The caller must hold a reference on the @page's owning folio, also known - * as the large folio. - * - * 2) The large folio must be locked. - * - * 3) The folio must not be pinned. Any unexpected folio references, including - * GUP pins, will result in the folio not getting split; instead, the caller - * 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 order-1 - * folio only has subpages 0 and 1. File-backed order-1 folios are supported, - * since they do not use _deferred_list. - * - * After splitting, the caller's folio reference will be transferred to @page, - * resulting in a raised refcount of @page after this call. The other pages 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 disappeared, - * 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 = page_folio(page); struct deferred_split *ds_queue = 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 *page, struct list_head *list, return ret; } +/* + * This function splits a large folio into smaller folios of order @new_order. + * @page can point to any page of the large folio to split. The split operation + * does not change the position of @page. + * + * Prerequisites: + * + * 1) The caller must hold a reference on the @page's owning folio, also known + * as the large folio. + * + * 2) The large folio must be locked. + * + * 3) The folio must not be pinned. Any unexpected folio references, including + * GUP pins, will result in the folio not getting split; instead, the caller + * 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 order-1 + * folio only has subpages 0 and 1. File-backed order-1 folios are supported, + * since they do not use _deferred_list. + * + * After splitting, the caller's folio reference will be transferred to @page, + * resulting in a raised refcount of @page after this call. The other pages 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 disappeared, + * 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 = page_folio(page); + + return __folio_split(folio, new_order, page, list); +} + int min_order_for_split(struct folio *folio) { if (folio_test_anon(folio)) From patchwork Thu Nov 21 18:52:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71CFCE64002 for ; Thu, 21 Nov 2024 18:52:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0514E6B0088; Thu, 21 Nov 2024 13:52:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0013C6B0089; Thu, 21 Nov 2024 13:52:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D95416B008A; Thu, 21 Nov 2024 13:52:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BD54C6B0088 for ; Thu, 21 Nov 2024 13:52:54 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 68646141501 for ; Thu, 21 Nov 2024 18:52:54 +0000 (UTC) X-FDA: 82810998018.16.3034734 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2075.outbound.protection.outlook.com [40.107.220.75]) by imf07.hostedemail.com (Postfix) with ESMTP id 65CB640007 for ; Thu, 21 Nov 2024 18:51:38 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="s2bpx/VE"; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf07.hostedemail.com: domain of ziy@nvidia.com designates 40.107.220.75 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732214985; a=rsa-sha256; cv=pass; b=BuWx9RRhon9oqTN4EZOi9vZYyNGtcKtAwGJnG22Yc3kqTfkHGRIeWvIZzElFfQJGtsi6Bb IT6A6kAWX5OsKgNXgVVIAGnkLQIjuovq5re2jvOtc5FUAaEmvtQc7QeotutXZpnBqJr0S+ Z+8CG3JR0ZWDJgStx8cFzts6UngwLLA= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="s2bpx/VE"; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf07.hostedemail.com: domain of ziy@nvidia.com designates 40.107.220.75 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732214985; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ts7Qc9/C05pLsaXYWIu3CbN2/lxdspXHxDrSlMv5iU0=; b=GiwdcAfnze7gQHDb2CxDOiLTwpqFEhkxGFshB5FlSVFd9uaLIlPfMkxP81AcyEASyxzyc0 wqlT6bXPEB3DI2zzL57qdjhvnmwHmHoxJ07qvDdJyPZ4soAL1/EukiVS8yAjwuWGSaa97U KXrqG/bM21bOzdRYfVnDj1eXY8Gd+Ag= 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== 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> X-ClientProxiedBy: BL1PR13CA0231.namprd13.prod.outlook.com (2603:10b6:208:2bf::26) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) 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: RhqHIy1oK8JKs4lAjUjUkY//sTJ9NB5RDT5/nRwvy6QEh6d82MnWO14Pme+cA5aLcYOjV+fNO8nV24U9fGTIxBCq3sd8iLC/34WN2xWd9MezDTHNGmD9rkV+Xv0mLnfIQtGUbejpOONPLbwFDB2K1t+/OgpX2Ox7Y6vOYHgRSimTDALk3UgC9mRZ5xvqCZ+NRxck7fQHHdpFrnpU0xnRpeCPh0fCNOkgLT8g1TeDwgOPeie1YP72Bi1QIP0kRVhxSyRw5zsuW/XDsfIUTpL+MPz9VEW7ohKRZiC7ydU1Pn5dzE9LkjCj8UhuBoGWWfVyNKeoumO4ZgYEtGJNZjJ6rRGO4s6+SH7kqiFNmZR4GZlUUvldAAJq2D5j08O2aIzEXS2itXZaA0I1fperQVLJpi74aCqSx1fgbYCCya8GenNosF0BblHixL88mRNc8SCsWowqHx0xNIgHavUqTV1tlF0/iNBKiYbsH0ESd6z8vmnpWbtPmjrjHo51JshQ6qOU/hO/+6O+V+bKKUY13XKUsReIa5/9aAkafxgGik5E+Amy2BcGVSUpoLAMJ1TzdMJS9zEQ7GM5EFijkasSNM9Ta5fnTErO4pv3ghW0SGblFl96tWUYTQ7Lr3ZGHM0+pKTWGAWxtuzsmUydyuz6fAfV0cGKaauPFmV1BvPDi1lo6cHg1XWGtVMgRHc4LIlXRgvVMvh9xR2sK9vlYOT2nSp+Xb0Hx5Zz185ESXwi4nHX5T41ER1WlUnRIIjMkDoVfRfolLBc3LlpZ03B/o1oaeepjbjwmpdsDR4lwkh/lSlb+VYfiBYv4CBy3Sb8vvoEmla6Y/YQMyvuN9/d0ncKEfz+O+OoVFQ8y14PoKdXA332wbwchTJF2kwTsRmWRf2GiGt/6UkNCFCwiBN/39bRp4Yv/t96rEXbr903AJCErT9PYxoTSkFdaZh1Bsg3M75tg+YnqiiHMi6fO3R2CnaXNRRMoSomkbeduNjoFigGfFNlNmrr0EBZ9NYW/twEC7QEmpTqGd/X6PylPViD2YYNsTlIHLDfQwPTypNd8ivA2nh1cCHtmV0WmYyHxS5wJbaOym/CNMHl4vrUpDFHTDcerqrm0/0YWgesGRWwu0mJTOX87z2eXSTdAg2sO6ijiJvTNYMhs1Bs+InB5GkyC1lIiYy+1PC3CU7O8pT9D7OtAttV+jva4Y4MwPqSUyBfpJVmaXnBsV2RyXlMGj+rpUWaEpfCKxhgKIokFNGhy1N8Gsw5lxAHNfiT57/mRGOguQkkLCAdmCgF9R8vBhUX5Qyu3bOM84r+dgMJbSOcuRbbU/IAnkQQeXVBM643pjy3yWR8cjOM 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: MF7noa2DQX4uZPEfYUIBjyUSf3WZZI/IGvHOMFwF15TJzS40HUUQwwGnqZOUMNz0RSFWcjoyIPaNVf4qXH0bgtqSgQSeeUj/YHyfMotnCq0Fz+OwL0c5CvtvW9yE+o10lndYmr1bejaou+lecB3fAQ8cByZdm0Nl7rG/68ZCBNCf56LWUmPq4EvLLQIGn7MhovTXWRKD++BZauWpOgR/VhI8hJaX7ie201BlvQ3Kufqtvd5M285/tZ1FY4CQY6Dn+W3r0yET8eSzQMyR8wN/EGMMHV8ifAl3+zbFcTW7kY8kFQuWuMsSgl2W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mD7u+zvkJI4FfuXzqgCxdX2LJQB7N4kb1THP9TiVI+WxMOnuvPXo9d9TExWCHF9fr0u/jH0fE0z0MFUOPCc1w/caO6ODz8EkGjLjxMxDUe7glprJEmMADpIw8f7XsVQZ7fSdrbknCb1lejc/1uGc+Jv1ZMX96P0LaXS6o8OmYg5B0oGIms88Lgv8uVwtRE/dzWpcSw= 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 X-Stat-Signature: tg6kskcrj6as4y7yaotj644a5m7txk5j X-Rspamd-Queue-Id: 65CB640007 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1732215098-775708 X-HE-Meta: U2FsdGVkX1/cvolqVpvWlSfSeTnSC+306nQUl6dsT9AKFrfQ0two9EhMi+G8i/ED64ur0kMY4jnE1ySdbdRCqyVmkSM1ASgF10ZLlNVfNgLpDMwW3Jjsy9nWVr4PWgR77SuEAEJy4MSW7HVaAKDVUdSmqtoENs/3PW3ySGiADOy/Uhnyx1Kul3+u5Gv80zebp8N0l2wk/GmzwZuACPE/hLGy0jJVQcdjc5DSI9Gf+9cR9LpetUIYRDWDm0BfMNfH8nKUud57Oq4RoBAuiqg9YYmwLnEfLPkzdsl5+bNDoxYY8Aaj0F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nygxlA0MgnyqI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 *folio, int new_order, } 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 = 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 = folio_test_anon(folio); struct address_space *mapping = NULL; struct anon_vma *anon_vma = NULL; @@ -3756,9 +3755,10 @@ static int __folio_split(struct folio *folio, unsigned 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, unsigned 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, unsigned int new_order, } /* 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; is_hzp = is_huge_zero_folio(folio); @@ -3835,10 +3835,13 @@ static int __folio_split(struct folio *folio, unsigned int new_order, goto out; } - xas_split_alloc(&xas, folio, folio_order(folio), gfp); - if (xas_error(&xas)) { - ret = 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 = xas_error(&xas); + goto out; + } } anon_vma = NULL; @@ -3903,7 +3906,6 @@ static int __folio_split(struct folio *folio, unsigned int new_order, if (mapping) { int nr = folio_nr_pages(folio); - 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, unsigned 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 = 0; + ret = __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 *page, struct list_head *list, { struct folio *folio = page_folio(page); - 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 example, + * split an order-9 folio at its third order-3 subpages to an order-3 folio. + * There are 2^6=64 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); } int min_order_for_split(struct folio *folio) From patchwork Thu Nov 21 18:52:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 473B4E64004 for ; Thu, 21 Nov 2024 18:54:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D231B6B0083; Thu, 21 Nov 2024 13:54:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD28F6B0085; Thu, 21 Nov 2024 13:54:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B25906B0089; Thu, 21 Nov 2024 13:54:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8D86C6B0083 for ; Thu, 21 Nov 2024 13:54:38 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 48F231C8107 for ; Thu, 21 Nov 2024 18:54:38 +0000 (UTC) X-FDA: 82811001000.19.B9F1360 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2040.outbound.protection.outlook.com [40.107.223.40]) by imf06.hostedemail.com (Postfix) with ESMTP id C33F518000B for ; Thu, 21 Nov 2024 18:53:57 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=t2zOiWS9; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf06.hostedemail.com: domain of ziy@nvidia.com designates 40.107.223.40 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732215208; a=rsa-sha256; cv=pass; b=17HJ72bF5YKRqUb8IEvdz4wqTQh2KOhryb+PQysxxdn4hkF1NpH+h7ylY+44RATNrm7GA4 HlGQSx2g31hgfJCtjq24eA6VRx120yqEPJ4YQEz8Sa7vA1+DMkOPNjH7fgwlF1jjDnBPMT bvbh+7xX7P2YpbI0rXmDeA66+qbafnw= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=t2zOiWS9; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf06.hostedemail.com: domain of ziy@nvidia.com designates 40.107.223.40 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732215207; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vKlBDIl4xrdnKlrWfw8XLDZsIOdmGI3JDlSG+Z0iz/4=; b=nYyfr8ngnMgtoqxEbqhuabXmwL3Romrm1gRpblTyTqIEh3ejKHEd48NzU2REDY3JIl72ZG Q59B+PTAynWJpqgJK3KgRygR4njgdpebv8PsC69aiSSjnK56QS3Yjp+vEWhf4HlHrKjssd V+iDFyPz/b4wrIsAokAXv2Q4YaRPBsk= 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== 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> X-ClientProxiedBy: BL1PR13CA0213.namprd13.prod.outlook.com (2603:10b6:208:2bf::8) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) 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: l8nFepLP1LGeAaG9ZAdxhJ9ygX0qR6BmS+r4SX7YwBLRnNaZAfoH7FCC3JRSlTjfNWFYS8qS0e++rheL11fnPtv/MJ8L72wMX51E4Pt8KyhvWYhiWe8MOXKc4jwbvcocyS4mUErVAto5sKPyHP3nIDbNWwjC5lUweLrDcj1XaEjDpG9y91ZsyLtxGZkJ5SXXNReppA38e2drSP2G4UVqdz5fvehIgQUboWZXsFkUgvm+DIWpArIr1UombvMm5qyzkq2NF4dJ3H6xHt8Us4vh7ki90ptYYawqqUDoRNLi1F4geWeRhziBkygCPDbDCsY3h4RMFe66wpqJpJ3Zk/OKpv62OpSwhFnOCPsfY3xF7CMj9/OatPIfJ/9gOIjU5YGT6VQPuEKZiXkKeRNK76KyijAntUynQ5jeh8Mw2p6SVWDNLWi75JvtyUZ42Va5k1AkKmKezE5wp9/rumKsDMO/63B/tj/bZY2o7nMD9JdiJYd5Qawve1YyBgvj00CYJAdBGtqU/GCXI6r5Qveb80ipqMFzbNNdvHPo9kf1h7KN2TpPcqgNC0V51Sb7jBQh9aKRmskXvK1B0y4eZN9XNvkgauNUg1/zhVICXwfe42i8FDfhk9Y3jmjgWRstTDnu+BA4xU9xIpduMMQ0M0V2fASFrdzuUieSoxMl0tH0mDRblD44UvKZ/S1tAr0hK2FPb3xuciafTtf7DDGxRJidgRWRfViJU3q1aoSyjrUbg1xyf95zgPljwTqMTOS3+bYe5IO/NMIQodnd0IrFnwrdpnpMMopRfkNITzWJZiYK3PRasWBBPFU1BhL4frbPPkyU0H0DpWwRzLv2wOKEJ9PQHvqfgQTtR6zvQUkdLiCSWx1QDzALs8julDQgBK2APJ/mBrdywJi26Q5OyLAN+j47CEi4fUr7vKxb7p5PMNmrBRKHCbAYMCHaDlE3FSbBQx17hbIZ4ek2yScZkQKnlyCl+Yo244RK4iND7mHLC9/OTOx1ynEOnqYvzaZjcAYbUodkYq5ggJAjU1+eRsaiCcLq7VhCJkAPS8u+c8opBVMm2Zt/LUYZWrcy7I590TQp+pBmjqjHV3F9+l6tbPQmY68GUafpZjZZSAJq0uxNd0grbHWctC5REb4obcZRWiBxCHQVdpLf55b/ZTludc46J8iiYGZV+a0uclZeQO6RaHMuXG3KzIrsWYj3bEaxvR6F9OOlXZJBd/PmP++nFGkNINIET1a/7RiBrQ90hrB0rFHiL88YzuMP8ICo2wKxvPWN36J54VjoWLID2vq4kci1sP+wwGJng+xfY4u/7kQfExDIuDFqhv9SIgvERzqKKB3gPV+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: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19J7HxI7Wi7rd/kxYTU8Y1TBfVncWyCymHfrIAN2RxLqoe/UX3uQf/ShXY3j99iiJqkSOxu8lbZhe9I2yxO6VKW5kIgtDVpbpkQe2S4bVYS2uxQVc7rYaatrbSqHhBd4qYrd00sJrqw/wd8qyHadMBeAudzHXrTtFj4oB/+/h5SSnj8jKoQh5nmeMuVzySmjAlgN1FRoHCey9A1tvXkJN5G45x+nSBADB7UJ6r0FbLEIZv1RJeC59HIWyzP13FATACY/0wKfogzkhmQW4GTEFu/iSiwfywSgC2BwAsX+g62t7Fl+nNILRxY3DCWVNsyWYnhKkMXU3tEY7GsipppJsRbzm6HtnmgkLq/wlZuQa41CGoSMeaA++zog70rOYLo9G0q0AU0w7nRqKZsBz7Ax44ed4sc499/0kzZdq/sUoPW/dyqa82ufeyPqvXatGKvvf3IcZIowtaQZSVJVIvgf3cquD+REGf9BO+W2WW/8Db+3EWh1Nrzzl9BDCa47Hr7NLoQEmhwuKSlsmYMyVlHyIllbKoaX/4d0T6ts7K38qGTQ+R6LNro= 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 X-Rspam-User: X-Rspamd-Queue-Id: C33F518000B X-Rspamd-Server: rspam11 X-Stat-Signature: 3eqkc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oiB1P+HgRSBjO0Hit9hgDqOLLL0J81/4Gl3J5X/n5D0jQCQwiG0Qv12YajPOQAR7PSZKlWInrg5rRxqoPZ99j91NuUB5UlwpHTeHQbzwV4EfrFAPQTnpcD9EnRE04LDfK47CZ0LuOsybQTSUonkB0o4mZ8JKx7jpbuS6yzBIYBkujF6RfTsQ4Lh7Ezc5/T5hAbnDJ1Qq8GFy417WNscQAYAb7qxJi6L2KqEKORAHle+UNK8SXrrm/+Iid9U6ZGGdcq+lU+JLAmT9JjCTB1y7NIHm88Xx63NBY9Z+1FO3oeRPeZlx582kjWUdoxnWTumTcwaLhxdCuFnleoqKFHUoEq5NrKg7rSnsZzzmNOGPUwBc1X9NFW0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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, } } -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 = &folio->page; - struct page *page_tail = 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 = (struct folio *)page_tail; - - VM_BUG_ON_PAGE(atomic_read(&page_tail->_mapcount) != -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 &= ~PAGE_FLAGS_CHECK_AT_PREP; - page_tail->flags |= (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 != TAIL_MAPPING, - page_tail); - new_folio->mapping = folio->mapping; - new_folio->index = 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 = 0; - } - if (folio_test_swapcache(folio)) - new_folio->swap.val = 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 = page_folio(page); - struct page *head = &folio->page; - struct lruvec *lruvec; - struct address_space *swap_cache = NULL; - unsigned long offset = 0; - int i, nr_dropped = 0; - unsigned int new_nr = 1 << new_order; - int order = folio_order(folio); - unsigned int nr = 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 = swap_cache_index(folio->swap); - swap_cache = swap_address_space(folio->swap); - xa_lock(&swap_cache->i_pages); - } - - /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ - lruvec = folio_lruvec_lock(folio); - - ClearPageHasHWPoisoned(head); - - for (i = nr - new_nr; i >= new_nr; i -= new_nr) { - struct folio *tail; - __split_huge_page_tail(folio, i, lruvec, list, new_order); - tail = page_folio(head + i); - /* Some pages can be beyond EOF: drop them from page cache */ - if (tail->index >= 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 = (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 = compound_head(page); - - for (i = 0; i < nr; i += new_nr) { - struct page *subpage = head + i; - struct folio *new_folio = page_folio(subpage); - if (subpage == 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_pins) { From patchwork Thu Nov 21 18:52:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 140CAE64002 for ; Thu, 21 Nov 2024 18:54:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A0EC6B0093; Thu, 21 Nov 2024 13:54:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 95A306B0095; Thu, 21 Nov 2024 13:54:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77C416B0099; Thu, 21 Nov 2024 13:54:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 59A1E6B0093 for ; Thu, 21 Nov 2024 13:54:53 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 02661C14DF for ; Thu, 21 Nov 2024 18:54:51 +0000 (UTC) X-FDA: 82811002386.26.1820543 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2085.outbound.protection.outlook.com [40.107.220.85]) by imf05.hostedemail.com (Postfix) with ESMTP id 91AC1100005 for ; Thu, 21 Nov 2024 18:53:08 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RujNHeDS; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf05.hostedemail.com: domain of ziy@nvidia.com designates 40.107.220.85 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732215137; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0HGXumwoHzdRg37AsHGRuosvSDyN0mCdwuWzz5mHCIU=; b=xbyoBXjb3kPH5VPDUPifBwJ4yKEf+zNj8sS15HHiSSgBBH+nopVm6vKq5iRQv+jgnyhX73 TE7HdMTpYN/CKQCp4uNdA876gsU6ugYXx2LQpLmeMzMMqBhjcva9wMyE2/6kdhGg7ehBdD NWGE0OFyUHEGAvfaRSKMi6uh15vSmX8= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732215137; a=rsa-sha256; cv=pass; b=4E8MZB/Jb31nnTxBjgsrrz3Qy3y5wQ0Znd5PWajvy00WVDt1Ew14cVPCjXC891fB5+tXAF lfgl6O0+HMyJN8W4LM7ytLkmfme1w/TIXVmw0g1D/kRYSbDbp0JXxYAZFNJR3gUd9WIOph EYX8OGQLsV3h2g/jLc4nxEW5n2LT4Zs= ARC-Authentication-Results: i=2; imf05.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RujNHeDS; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf05.hostedemail.com: domain of ziy@nvidia.com designates 40.107.220.85 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com 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== 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> X-ClientProxiedBy: BL1PR13CA0234.namprd13.prod.outlook.com (2603:10b6:208:2bf::29) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) 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: vXnuoGP1qawLOa608c40GaFw2jPpUhH4xvp/3WjxceXrk2vidFz8bX8IUJTnGggqrZAbeU5S0cpflC6ybnElUGzoeHFzG4KOPjRkAGyKIuwToLBvOBvh7Hd+t97Kj3vh/EAHh2kjzLQEHuz+W0TqZAMStYUgvIFG9J9x8N+gCHaBXy/RbeWLiZGiDAuHc6ayvaOcnFducgixf5GTipvdr2LHfL0zuy9+mdZBR5BO1IiVVepLI/BHHspcdoDBOeeWfSLS7q8BFPpH0w0zQA7xgGAl3Bbk1f+wwKpnBsOc+HnA2uh8hP4HZm163OTe/bXnNhbFXivH0MYc45tM2HehsKwappIUIEYzUxiTozI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plYXZbFQD73/L/7caiOULdIZzLUMdJfYwSivnYJ+qi17smrddXf41uc45lOKtSU7LcmC974Y5fJX01VEpVbikBTjkCPgKE00sjgMMZrlzCyUQkQ6vqq+X7fJ+TKvvXyTWKDMMUW2SlTZdxqUdV3XRq1UgVuc2KX7kEPWegK3fSdjbebo2qzsClbUlENKqyeO56JelnaDMpuML/oJDvYapVgkC9/4S4s0kGIsa1gVDevMHA7w3N2KethlHPwDpeB/cWtYYL5DhzDqJjdqi2MbacylA5HEJJBjN7zGCinjORgUwbar/71zQGMNVbJsCtGX4BlKkNwnxdOK65clN2K0J6zB5DztPtZBqJQxqWjLMytr5+5nNkIOckkR9t8d680rBHlj8cB/WvN6g9su5KQE163nTsCSF4+FypCXa6q85Whv6L/MbFU9xySud0N3Nqo+pIiDKA0/xuAWIcrJD/i8A74ivYrIeyAY++a85p9IjsfDEfGr8Dei11ZOqf0ZPe2fue9e4/o2AeJk+t31gpGv/hMlWMe22RSQ1XVUqQ/wldvlAysq1/vDDQ9vOmOypWzHxzmQsgNiPocCrJ/ImTHMV4lcEzbUERZSuYsrbK0KMDGs= 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 X-Rspam-User: X-Rspamd-Server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96rno zV/RqZWjxn9K8qpkwS5jYPkaggwshDQsBHeYmu5ksC3szEZtO7i3360PC3S6LKN6LRnJD5A0RzNT5MNlc+MXRJWzFLmmLGElglqvfjEg2RVXTJeei+aHUpzk0gjvuTHIkXsX1ggTXeH8Uct1IWK5/EZzZQJAHaDPAVoiG1iLaJO5BLNfdPYCEwktaFbvP4xZc9IT2x2XgXD+Kyh65AKjb9RadAEsNYcQP6cXSD845n9U9oJjZaDw4dsvMEB6nT3/SFRfT9EGc4eX3BqfEZhkdCJ/4qcSLAFDQu6/YuyrEvhp0l7zIewok3+v+osmqa6iYG9MTRGko70AbQqzNPyQsC4DwkHM6pgC0l6KYAhxP0T/eK/OQhPB3c9qvJhKjCNK+2m7tRuDySrzoRSA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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(struct vm_area_struct *vma) } 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 = 0; struct task_struct *task; @@ -4225,8 +4226,16 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, if (!folio_test_anon(folio) && folio->mapping != mapping) goto unlock; - if (!split_folio_to_order(folio, target_order)) - split++; + if (in_folio_offset < 0 || + in_folio_offset >= folio_nr_pages(folio)) { + if (!split_folio_to_order(folio, target_order)) + split++; + } else { + struct page *split_at = folio_page(folio, + in_folio_offset); + if (!folio_split(folio, target_order, split_at, NULL)) + split++; + } unlock: @@ -4249,7 +4258,8 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, } static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, - 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 != mapping) goto unlock; - if (!split_folio_to_order(folio, target_order)) - split++; + if (in_folio_offset < 0 || in_folio_offset >= nr_pages) { + if (!split_folio_to_order(folio, target_order)) + split++; + } else { + struct page *split_at = folio_page(folio, + in_folio_offset); + if (!folio_split(folio, target_order, split_at, NULL)) + split++; + } unlock: folio_unlock(folio); @@ -4332,6 +4349,7 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, int pid; unsigned long vaddr_start, vaddr_end; unsigned int new_order = 0; + long in_folio_offset = -1; ret = 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; } - ret = sscanf(buf, "0x%lx,0x%lx,%d", &off_start, &off_end, &new_order); - if (ret != 2 && ret != 3) { + ret = sscanf(buf, "0x%lx,0x%lx,%d,%ld", &off_start, &off_end, + &new_order, &in_folio_offset); + if (ret != 2 && ret != 3 && ret != 4) { ret = -EINVAL; goto out; } - ret = split_huge_pages_in_file(file_path, off_start, off_end, new_order); + ret = split_huge_pages_in_file(file_path, off_start, off_end, + new_order, in_folio_offset); if (!ret) ret = input_len; goto out; } - ret = sscanf(input_buf, "%d,0x%lx,0x%lx,%d", &pid, &vaddr_start, &vaddr_end, &new_order); + ret = sscanf(input_buf, "%d,0x%lx,0x%lx,%d,%ld", &pid, &vaddr_start, + &vaddr_end, &new_order, &in_folio_offset); if (ret == 1 && pid == 1) { split_huge_pages_all(); ret = strlen(input_buf); goto out; - } else if (ret != 3 && ret != 4) { + } else if (ret != 3 && ret != 4 && ret != 5) { ret = -EINVAL; goto out; } - ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order); + ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order, + in_folio_offset); if (!ret) ret = strlen(input_buf); out: From patchwork Thu Nov 21 18:52:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FCE3E64002 for ; Thu, 21 Nov 2024 18:53:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 002526B0096; Thu, 21 Nov 2024 13:53:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EF5CC6B0098; Thu, 21 Nov 2024 13:53:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6E786B0099; Thu, 21 Nov 2024 13:53:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B935A6B0096 for ; Thu, 21 Nov 2024 13:53:24 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 80B9D1C8107 for ; Thu, 21 Nov 2024 18:53:24 +0000 (UTC) X-FDA: 82810999068.15.7615FD7 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2061.outbound.protection.outlook.com [40.107.236.61]) by imf12.hostedemail.com (Postfix) with ESMTP id D365440014 for ; Thu, 21 Nov 2024 18:52:56 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=FJ7Nz+xU; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf12.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.61 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732214954; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bCK0ahHP2aeqKyUHb8ITfSzvvy9IFw+4Pn/KCUxa/mU=; b=sUEWwYApw+PRrjCczV4ibD1EI0tj/nYvq2OMi+aFcQT+ndB7XACzXLBluBaU9AWUat5+uh 7OCswn9yetbFk9AOCoYhnyZh2p2OgkUrziRjKtpcJEHqeGyISSaXn4Yi5/6ETTa1v/ZV8z iu8FokkWA4RKJ0x7/FzGgyGUB0+uWv8= ARC-Authentication-Results: i=2; imf12.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=FJ7Nz+xU; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf12.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.61 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732214954; a=rsa-sha256; cv=pass; b=NmXyI/chSn+uHxaHi27lMpHilzDCQelrC72lt6JyaPZTmwZG5gqAIETR/J7FDjBjWGNllT emmShnNrd+mXiXuiums1xmP7zseQGTjZUlBl+oQNnx6/kqaWGEAUBoEdJHX58B9HAb+lVY hejc1kLMFWaoS7Z6hqxgPLmS6/VaMvU= 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== 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> X-ClientProxiedBy: BL1PR13CA0218.namprd13.prod.outlook.com (2603:10b6:208:2bf::13) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) 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: Edd1Sjel1NqMjTX5gjFo0dMqOeTyVVmQ8/u8jK2GpY+lSvxnI3g45RoGwi6Aq0DUh4IUpbOFymEB0zF/3HfXpWmiN7IjUdQnePkDddkHkVXo5ngTRfJCwImrtHUMsB11wIWZ09/jQDKXKvr2LEByu8hiK8WhnU0d2SmmFt1BCSz4K9W79tsDdigrcaK4V6luA1jy97PmTxWEZVndrc6qqSnKC9PohNgeoeikhRKgDf4/+nTPBuSRd+n6c75H5DGMgjaz/oVx4prK5WaSpixyFO5QAwR2Be6B8xIDZX8xPO29NYbZcTrk9vYPPA4b9HwzpTHyhSOWgDDroZjSAPJ/4BX+ECSacud3fWkrQbTVUNaI3P02hi7vE0eak6hF3f/OUFd6mOwiRHAuc//YidDe/LufjJQyDV4T1oMuxx9oJcisIAfdoz9phlNTEd5PauaNXZ8+mBBWnKZr4/qlRW4uRyv0haRFKbAY1w/oUsE0cVakHKqNRAATszDnztik4sEHMmbpC3Nj+ypox8KEl+J07x1lB2f1sRTVy9HW23E0fcCFPtlI2xSHSbZPHyz2k0938TT1W2EL+QiQxv3JLkLdU4gdSqchuW5YpmsTGBfCBnGFOIjJXZ+71zkcJV+QLfMSxO2AsJ8lqndZAoTf0h4wfywdbGbzfltF4mTqeRlFvj84XxaMHK/vLmUuRzj9HrEwEhGF/5Sn8mVlp6bayYTFl3bJFpsTgA+e/3nfHHapycqBGZSTbYKDNyqT0XRP1k4DVP0NzeqrirDCrqemY3jDWV5WjM263jMAbb8ctKKcFdmE/I4kNxFQOzpYdYB2wyItsl4WDsjNWxBoZxXv1sNPBDq4WGMx/pi/N6atCJwrGoe/CMZ34auTKRJWZXJjLow6byxM4YQRBrWlltTyoy6S8hM3cOU/mUVKFWvmXXvI8GCJZkwvXFn8EB2KDZyYeggygyDAMHHYUzLnJ1edwjBUPBIp9VRajv1PjAgY9u/YoU51RZA4SytkGd4UD4Ybp5lDe7dvUJxl+Xob8tszV1cZ4abvhlM4s7weMRLl/vDu/o0f+8qStEHwQlF+pPj9BlS82kwya5ihgTUb5PdhGRCL5p7IhLWANCiRX0uLcaoCY/NoXfAiGPXdt2YSR8JdYQdGNDC+R4nfYX3QQZOZQch8RjsYOqBKFR/HygBJbrZImjjDb1uirG6pgRpS5oC3cqcVU6vea0FkJfzzfRBL0yDGS4VRyq8IFULZYbamM8tvz5KDjBTphBstzrC/ERLyI5xyk1EUHcPiALZ9NZZtdHLTYMgPuPB9fZ6pArYI3+RgFQpW4QP+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: 0NoFIYX1dAlIuQMaEyOPzhf0ILAHlQZLzDtPx6ISrDqshcWvWsO2w43J317KPhKjVtcjL8BkYzl+7bi5PAjw3CuSMOeUuCGKcULBkTStHF1Q6Y1snp0QRgzMivnK1RMbWuFlXZRGaz3wEyN2Hw+8uzSxkryQzaPc5qalrOowuse+mmiF3lv046rd9NKkgCSRCeWJulDX+sWrJVgFs7V6P4vAqNyyCFvGlC+0Gwkclx53FOYKOaX4f/VVZGZ9Y0H5icUh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y88l0Czo5E6S03+kUB3s/vssTqfWlXaNdKObSurB/tp5YQvR74kg7tLNJV7t5Am007UP4Hn2gGR8EoAMNhQAsB0EUr6wjWCpqHMwE+JpWPbv2HUOwWVUHjiB0kx3WABcvaIS7NFVZQZmgkcvIcETus0qNBL1oTFu2YFhnULoD1+OEjVj5sjQiOtjCVkq+HqLokiqn51s6CiO4XyssTdwQ4BR0Kvym2l+yuMC1wxrpAkd+Vwb8UFQYbA1sHz8g5/UvvH4= 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 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D365440014 X-Stat-Signature: etryfk7jfmtkssox44k8ur518wuiystr X-Rspam-User: X-HE-Tag: 1732215176-891084 X-HE-Meta: U2FsdGVkX1+lOeZl73yRuXHNc4oBDmv5msTLT9BpUk0lNXNFzSSgCUTQMqgc4eYH/siLl4DipGGjG2pcCSGCyoWmbS6Y4N0QaabY/ME5wRMHQLEFeJKFcFHr4z1u2YIJfvL0iTzdCMvTjERnv/cTgg8MxmOs8WXIc5j8JnYHWZg3p5nWEl2xCy2QfcZPp7jekwkwlVLYFFBHn0kUJtokI2BTlXtQ4Q2mqhJhry4WLToYe7cfeS4Rh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WXal0vMtgikNvMLw18uYomafoANG1m12y8cX/D8JYVzb0PMaHh2HuG6uOPtI0UueSv+I= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 = 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 = page_folio(page); @@ -531,6 +543,12 @@ static inline int split_folio_to_list(struct folio *folio, struct list_head *lis return 0; } +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 partially_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 = folio_pos(folio); unsigned int offset, length; + long in_folio_offset; if (pos < start) offset = 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) == 0) + + in_folio_offset = PAGE_ALIGN_DOWN(offset) / PAGE_SIZE; + if (split_folio_at(folio, folio_page(folio, in_folio_offset), NULL) == 0) return true; if (folio_test_dirty(folio)) return false; From patchwork Thu Nov 21 18:52:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08FFBE64006 for ; Thu, 21 Nov 2024 18:53:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99F5A6B008C; Thu, 21 Nov 2024 13:53:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94F096B0092; Thu, 21 Nov 2024 13:53:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C95A6B0093; Thu, 21 Nov 2024 13:53:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5C67F6B008C for ; Thu, 21 Nov 2024 13:53:08 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 076A081458 for ; Thu, 21 Nov 2024 18:53:08 +0000 (UTC) X-FDA: 82810998396.05.16CB973 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2041.outbound.protection.outlook.com [40.107.223.41]) by imf21.hostedemail.com (Postfix) with ESMTP id 8FACF1C0006 for ; Thu, 21 Nov 2024 18:51:24 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=SH4eZC1U; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf21.hostedemail.com: domain of ziy@nvidia.com designates 40.107.223.41 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732215093; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1lwTVNAVLwi1gyG41osM9o7VeGen/aJvxEZw1mntkp0=; b=paYR5lCojM503lz1f8R+70z80O/4s/bAmfrwSfGgZsGuVU91y9AqoF5Pb0pRq3bjnJ31jT 7lLDWP9FvLL3Uo70arkqCHcKwO69JayPz4YA/DrML1zEMpLrJC0cWI8mNeovS9yDvmJqFp qjoGp0c2dLiwE2Uyd+GhSwAceooqe04= ARC-Authentication-Results: i=2; imf21.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=SH4eZC1U; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf21.hostedemail.com: domain of ziy@nvidia.com designates 40.107.223.41 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732215093; a=rsa-sha256; cv=pass; b=mPrtYtDtp/UwTT9GM5OUM42Li3ZiF2KhgTqLX6cvJmC4oEn5TwLr3z2IcrX/g+ntPwKo4Q ghnRnfBRwKevzMc3ZjkPHs3WYkrb08PuyjOgcmBDdVtFiKPwhr5qtaQhajUkJAaj+wwpXT 1bgW6P6BkhJIeTyajRgYry1r27I+1VY= 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== 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> X-ClientProxiedBy: BL1PR13CA0216.namprd13.prod.outlook.com (2603:10b6:208:2bf::11) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) 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: pB3ONJDs5zd60H8/xakzSjH5dZRXBpNR6cjS+uwRL5csa07lkVJ6BclVILoLvBc4tKdMDwLh35FObhdj3Qliw+gMbhdMRNt+9RHYEygJFrkMvc2sPRWfpr0/EDJSPfFT1yzoOlJBxgXwgUTI8pq+sHX4TBwDdkuX8OJufmRHh4B4vxmhXrIc4U/gJnGM+rGM8FIzhRUbaVpSAOpUvyMdpQ7pDzyx/WZX1o0fQKtKsXKgOxDc5rbzrhEgsG70EazuW3jt/FZdxRtiXlLTAtlINKj6fH3lasd+ImKMJURTxjbJkxo94XVSDObV3GLQwop7YQZJMnny8JmMsb8bHk/kLXORpRm6f61RRXnVpTg3VGq1OcMaHBpkyiDv43KUNXfbwaopPl4Wo92Gn6JNurr3ZssuC4Jpl1C4R1s5DfHPeZlhMRyS7RbE8cTI1/1mZIMlcPPIgrl03kRhNWuABwpT7xk4O01z16gCIJLIXQQ/6JBPdBogdyGUZ3PyRHTwCabE23oONb4ieg/Gi/Ak2O22Ztql2qyI5kqNte7TpPT8NLQXhBK5UoxRv1b/97edF4hKY4rWowicqgtT8HqdYeI4UhqIBZGumuAUJWH/MnIKiPRiLMkDhvNCEFTCCttjujvaztBy2YzvdeWtTQxhRv01Ea074M4U99MKJDurLRaF2ffzVf++08lGPZZWwPUTy2MpHcH4w0823ehI1wtj0s+yjYoH/ClNmQclm5owwa8BVnERRkm5yK3P/BMzkPRaw19vmSHx3ov7QahtUZ47vkQnwZuaMUp61lncmiJ95t/JxMs99H9ZjPFLea+aakyYt6dMSaPBlIIuWx7dUqAz9aj0CoDbtw9BiwHBwkbz/ypUymmDhB0vdTU8ikql4p7Hd6/mKRm0JisqLlR0ZHCW/2hqdUfWJsoarMOnvpDLyQZsYpDFbHX6tdMbVZ6aXz12se33JYRceeGCWtQt895AnfQqTJp6iz9f1kJXqZfPWJzM5bkK3uvBBRpNcQYi6i0JVIXECBXFAdS9wwRddGOY6uJhVY2ApuTHZsdUKkfum5mbJ3X1wEc3shrzl+9Zdtr1UEoL9bM9hyM9L6g6VtWMD4zR09iDpln4i8bzx+xPPbQwqBP0ut5jQBDhqjWwsrx8tbc0RF06ZevJSTThG6oLsZvZpB7qMBGxVgnF2xXQrLB1+M8ULhpnIYCJS9O7Rv2Na4EjCPv1z+197j/hG/HOJG4BF+/ZrrNw2Qoapf4iMEaRlY3L8XApAVNdHDTJqB8eb1dLlGfn6EWiDbs2JmW5Gp0CfLLaooozjI8U1mnEeiuRTlCeE7+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: 1nhxEJx3Wd0Ai6GJe/ZYf7yyDCQY4wsy1YFGLbRu4/8O6O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8VHwMfjvG0l+h7gQw54k9uU57sevc2f9ADRW4T0L/j0rLni709jjjnu98IWQJ37PUQ4XwxGRxpKc0KP8RCMBPgY32Ln1lzfF7a6lOEFYUKBxtpG2S2b8Ne38DRnf72FKBULQ5hsKy2MsubwVc7jERNtS5g6OhKk5yNOPUAdffDj2J1H8yNuc+0IsrNILR4XUWljjPfDkZRc3EirmE/PRsVYN85SzOz94ufH8Tl1iC136ys2JW/nLCsqeE4G/56wAyde+3yvjDd0PSX0brKG3sbCTn92EZJ4nYOZxTi292a10SN1Oee0Tq90B53HqeaC8z07hkkhvDL7t+WZdqn6i6/fFRBv8QzORxvf8a/Kp1xHqe92kz6ZSFF/7HZoWGdxrVEffKvLB3DWh1RcT0aUqApFZDISDAqmrfRjRH4BaDzevU48hUAnuM8+MN6X3WiQs= 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 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8FACF1C0006 X-Stat-Signature: uum7hro1n4nqayi9qg5s4rdpocnnrezu X-HE-Tag: 1732215084-157813 X-HE-Meta: U2FsdGVkX18TSMP9DnHc1eL8Sw0TVKf+2vQqxjsJZW08UJfjqrfxzkORyuQKd8md74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OmUeNnbrbIxhmfFwBIBBC4ZAHEtU1XMpMVBrulchqRmG8BGz6ai+Vhl2EhqVYcmFOqYBciekoVTzZqDzMsyht7QFlHz/0+T1ReRh1aog7Bzpr4yksmzsl4VHpEPoYK4Iq13GvzJrvvk6bbD4SjB5gJ2NGfsl5e0+BO9k+SWBhWrVtU6WwgK78bxRjmZr4m148QnlhqWQW9Q7iJnWcslVAA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Otherwise the number of tests does not match the reality. Fixes: 391e86971161 ("mm: selftest to verify zero-filled pages are mapped to 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/testing/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_zeroes(char *one_page, int nr_hp unsigned long rss_anon_before, rss_anon_after; size_t i; - 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"); rss_anon_before = 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"); /* split all THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)one_page, (uint64_t)one_page + len, 0); for (i = 0; i < len; i++) - if (one_page[i] != (char)0) { - printf("%ld byte corrupted\n", i); - exit(EXIT_FAILURE); - } + if (one_page[i] != (char)0) + ksft_exit_fail_msg("%ld byte corrupted\n", i); - 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"); rss_anon_after = rss_anon(); - if (rss_anon_after >= rss_anon_before) { - printf("Incorrect RssAnon value. Before: %ld After: %ld\n", + if (rss_anon_after >= rss_anon_before) + ksft_exit_fail_msg("Incorrect RssAnon value. Before: %ld After: %ld\n", rss_anon_before, rss_anon_after); - exit(EXIT_FAILURE); - } } void split_pmd_zero_pages(void) @@ -150,7 +140,7 @@ void split_pmd_zero_pages(void) one_page = 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); } @@ -491,7 +481,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1]; - ksft_set_plan(3+9); + ksft_set_plan(4+9); pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; From patchwork Thu Nov 21 18:52:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01C03E64002 for ; Thu, 21 Nov 2024 18:53:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88FA26B0092; Thu, 21 Nov 2024 13:53:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 818636B0093; Thu, 21 Nov 2024 13:53:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 669CA6B0095; Thu, 21 Nov 2024 13:53:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 466E26B0092 for ; Thu, 21 Nov 2024 13:53:10 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D760EA14BF for ; Thu, 21 Nov 2024 18:53:09 +0000 (UTC) X-FDA: 82810998774.11.E42C32D Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2049.outbound.protection.outlook.com [40.107.236.49]) by imf30.hostedemail.com (Postfix) with ESMTP id C744980021 for ; Thu, 21 Nov 2024 18:51:26 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=VvLW3z6D; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.49 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732215119; a=rsa-sha256; cv=pass; b=CWBj6feC/Fzkjvg2NDg1jhXzXzSm914QzvM2N4ajYQ5GjC2a1Nfpe1HcMBAO6rwtSb4QAD FTcdgNklFdIhEoDhp8b5XYbxWV0miv/sDSyCrjxQtlu8uLJEb7ezS3311b0O+QtC80/UpB sS00RqNAVpIuoNKm2RWdkm7hVMTaB7s= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=VvLW3z6D; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.49 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732215119; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FZxMul1WU308N00KYNlcxD/DyDEr6jnTyKBgAiwblKE=; b=4eic+zmSX2aqHTW6+hpN2FwN6PrFH1V9gTQRxWDz9SesP0EkdueRw6ZOHrp2/Y9HJT2Q8y sh+LORNkTL/bJ1VD5HPmCQTdnUeTn0P+fR6vXl9mmalMnf1QLJN4eI8XJidTUwUY8bwO4Z AYG1c9K63TWA5V/LQxX0/OTy8revexk= 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== 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> X-ClientProxiedBy: BL1PR13CA0219.namprd13.prod.outlook.com (2603:10b6:208:2bf::14) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) 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: 4UsN91yzlTcAIIPUjS+LxIcR1At9NZqa+nPI6BGO023zIam/2FCmeeSyFm7YsTaj/K6NCGWYEldkUxCmkxd2q02by1OMBCUYMlXYsoItQGGay+hgSXpZ4FRe9XOq88qYTyhWHavtdf22wBAec8zIq0fRPvMqjw6mDdtLscwm0oaZZ/K2rwNNg5cQuDixMwdCz21+w0v2kADM2414awntH2X9xbWE9xAYR/hV3upxF6Gg500hNPKqVAFI8XAEAWCLC9yMsWrFzGdIkasw/tLhFQyBL6iYKQuPqd71DdqxSyQRR+k9TQ7CiQ7jsBn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;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: alo0wEYHA4zfFcKYJaglvrWFwITA8oMBdAJna8Co3ZHko+l9TPOPS4yu4T4ymM9jg/jlx2bATKMOm4gW4rvRgFEWuR7Q8D44c4JUdJJjIEkhwC2hLaTbdjWNVAF11upmQFc+Ma7+25BcEArIenjAFuF/l4ZmQ+mheVcq7fLQhnaIu5GNXLsc2lA64JuUH1iLguMzAaw0MHiEXMjMqD8MIZ33Xh6JsclpLBI0LpWFRaeI1JayLA+Lx+ITAgiVjkZPoVOpDNJ31DOhsbjagNU51884MGw13IrrJSg1ytylLBW4bt0lK5u1vK9vCS37Et98Gu5r3ToaWQlw1SmIITQqJjPWsuxK8DYx4NvIy1YfSBEWdO5PhA0Q1ZGRdd2dzqakVvNn2ZuKib51QVtNQL422ZNWm/MSAm9N9pC9cdJnVoToebXYSn/lHPAJ80g1Y6UTYvOOExof/ET3iiz2AzfmwY0FZ64USH6qcBo6Jx7J9hLtNeSqGFHe/QR06u9ALjelPsLTCE4TyuP67IZKrYcBG+VdqL1YavazCDejQkrEoW3nTwFVRSVgvMZx+KRx/BTHzHPy/bxggBC67fwWNpK9fUUyuYafkhtm5gBIAC4TjVXxJCrm7lAEx09Oxnn04Pstha70L8f1Ez3/QzEOc3prfnMfpMk/sov4z98OrB5UhG4q/z/XjP3JJ1zKndXvbJcaz5kHDJd5AnAFXo8JyTp6ilmYzjAehPTPmoK02yyl2OnTXXhBzTqiRUOXfhuz6Lhtk7hGgazeXvu0JbIA97zlElgRiVhTOi/no70ZwBvZmV2+Jni/ZxQtb1y/g9KXsCLt37g6UjPEe+r0s9OqliYy5E6HxMTjV5VEUbnOE97nnS9RGM8EUV/Ck8XqQChhE7KRuzsWXy0/m7utuDZxFnQkMDj7Aw0Wph6Gkh7I2PBYZjbYZX0og52LzoxylH1CThAp/TAQOYPmHsr2FLzxw/p39pqT4jnZO1WrM/lLOoImEnOrCjN4l67fMqC2M99Heg6ttjpZr4ub27NJMwRhXPU981BeNYaWMeWLeWwP7dQbIm2HugeQMW6dQ4Ou1AppjN0qGZOhgDSC2F/s+uwPz7NHMgs3Ad6EUYR3Yftfz8+dHfMDwss4fkQAwR+N6p7FVdnqwzrFvLfbhj1V/g6Sv2q633/99RL2cCNgVRcr2qfomNhx4JoJx0HjKqDsBScB4zqtS7wGYH1ij7qFkm2ywAdX0St3kvyJUt4lkN/vh2IInbxyh7iw55WVTqb8KspYNoVxEoDW3P3ScEXrEUbhkXm1PErLSGvJNMjduz86BcvB0ksFJJE53kUU4EBuABYzMy3UvJuQ8K2SPs/cAbrrMsxZmAmtAVnAVGPl9CZDPg9Rf3vs2ha0Owz9Y4zzReVH0kXvNRdzF+snpNSZTR1/0lVkg9SRhD1K+lpmqyrQHkEXpknoGcBD4xGH5dSWjJ0njBhuECtGluLD6+JmTDyJOiyHZoOZ1RyblzKgBVn6coz79EjU+nsFKsx3wjwLXNjZvh7MteBoMoTR8NFRJpyVyXA9ZCa/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 X-Rspam-User: X-Rspamd-Queue-Id: C744980021 X-Rspamd-Server: rspam01 X-Stat-Signature: 9yj4q9pg9ube17ht3dj6g1gbee4iukcm X-HE-Tag: 1732215086-244069 X-HE-Meta: U2FsdGVkX1+5c7ed19SMt78Nv4V6slnOCvZPR3nsijFFY40loVO1ysTck9ZQTa5hDS5hoExPoOH7fi+KWKAaZTVaCUvS5j/HcDaWilil8FaxCODDD6R7P3HaFnyHJopRpMoVMBeexx73tnr/WbMlVXsvLeI3JcWvGdKWKdbsseivuB5FW/0yBnSf0mogXxPOEpP7oQa9tmMbJbh9eklxhALbBIwsfbywTLHB2fYi77fo/upniEZs/Jz+ZS8mlmJK74VO5w6p+lIDqn8/A5edUTU+VABT2H1dVP0YBsJYZnwoQLngJD6hT0hHX2P3rb7SVy8iFpgK80f3eOpSoayyASIs72RCeABYAX1g+VjWaWW3FVpbCSxjjQBy7nGOjfpRMTefPTG8Jl1hE79Cf6NBGk2ULE+dyrvA9Jz/YNdnkQHeSAtCE6cy1GLeWnvaskgWlOBEM1MJ0Des3AHSTsUqaWh2QnO85UuQHv1bNs1pUkUPQQko0+tsEUFrl8BojJQ/2U7lHHE60OGcn6uKBvs9Z0PCUClqponnpebLdNULlQvpHS1bOmujywocqVCyVnd5WegAHz/QQhuQT6O7EYWWmSHk70HXqjGbQL3DEKGlO9rv3TDbFX3qtuXDDKwW5mNydTagW5KPZetp17GCxe5HS892uGu60h+PS9A3zU7PNo70KaUDvwXT6eaCvtEOraXoKaETBTlBOBqA0GCf9MZ81KPEIECrPKD9lLfGlopf8iXEgX6MNCDgBbEVF5HWCyGS+Ge72WmaQ5tygsqoROoZW6Wfl7FI/JyWfomvLXAuT0eE6XiRwCTGY9dBTobWQDp0OZ+fwpzoqDZdgOCzX66kKu88WROLFLPqktmFO/iw1DbIxJwGLWva1y37q1/Uz3YSKR7TS0gwAeMAdLLETdH/hqowGTzflgfzMz9Q4q0G6eCFx2/jQwBrng/8sPhHf/b6n01yIXUP38LtrMfBTzR KYZ+sTQ0 1UlSQarLq6tBBvC9jEA6ICp469vwWBn3aZ3ZSZEjEnveKPxLjT8xovoLBNwHgxikiUjxegrGIHArm9AjzmWykh+NhA9KDRhha55xNhtSib8g/XwZ7aLaooYkLjnZCuEXLKh3sJ4O0v1uflYghWcsN6ZIAmzI7ml6AQ7Mcs3l7ZThQWLEs3SpvQ5MdPkLkBQ9SuUsZ8qG+rHFa8oLVR6yoWlUtIvW3lbDXnYAkV5lDcLsDSSWg24U2H27z99fJra3m6Ex/WRneu4k1rOZ0IM7uKdXkPx3t7WGlqUIYDV53keYKjfm73kQIdsBbY9RpJlXhY7uHSFMR1Cy5HDmZEWWQ/TJMJA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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/testing/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); } -void split_pmd_thp(void) +void split_pmd_thp_to_order(int order) { char *one_page; size_t len = 4 * pmd_pagesize; @@ -164,7 +164,7 @@ void split_pmd_thp(void) /* split all THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)one_page, - (uint64_t)one_page + len, 0); + (uint64_t)one_page + len, order); for (i = 0; i < len; i++) if (one_page[i] != (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"); - 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); } @@ -481,7 +481,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1]; - ksft_set_plan(4+9); + ksft_set_plan(1+9+2+9); pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; @@ -492,7 +492,10 @@ int main(int argc, char **argv) fd_size = 2 * pmd_pagesize; split_pmd_zero_pages(); - split_pmd_thp(); + + for (i = 0; i < 9; i++) + split_pmd_thp_to_order(i); + split_pte_mapped_thp(); split_file_backed_thp(); From patchwork Thu Nov 21 18:52:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB30CE64004 for ; Thu, 21 Nov 2024 18:56:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49AF46B0082; Thu, 21 Nov 2024 13:56:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 448B26B0099; Thu, 21 Nov 2024 13:56:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E9856B009A; Thu, 21 Nov 2024 13:56:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 103A36B0099 for ; Thu, 21 Nov 2024 13:56:06 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 86E4A1A14C3 for ; Thu, 21 Nov 2024 18:56:05 +0000 (UTC) X-FDA: 82811006586.29.683A32F Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2040.outbound.protection.outlook.com [40.107.223.40]) by imf28.hostedemail.com (Postfix) with ESMTP id 92D83C0003 for ; Thu, 21 Nov 2024 18:55:05 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=OAdKuTM1; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf28.hostedemail.com: domain of ziy@nvidia.com designates 40.107.223.40 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732215270; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7vfodItUcrcyLrOMU+QPVr1fQyMNwn6ddi+gcaz99x8=; b=lXD1uJ7kSq5FPD51nnPQLbuhHSV95lcOC+tDui7pFOcll81yWZ+7ZzvU1YLABPXPuJio/o wOuZxCfQdw9NlkmNXSK0vLUpnx22etIH0fDBpSqXxVcn4bwet5PMNw4xot654rONf+b/Oc 4ZcZ3aVX+bBBNzUUoFbfjcJZkUhM5es= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=OAdKuTM1; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf28.hostedemail.com: domain of ziy@nvidia.com designates 40.107.223.40 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732215270; a=rsa-sha256; cv=pass; b=1/h8k+pva9xCWUBQn49XQc3Mt4OKiV2WWxq8HxClfSe5jp4mvRHr+7uvt1CtLQY6HohOEP 5ul3dwtqhRKXGjN+vQGDp+nqGF0IWmqEm4uztkyLaePh1GSKH9kqtDhCyc21TtkoQP7mjV X+yNXJi0QsW/RgrWHK3L/l+0Ck9YvBM= 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== 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> X-ClientProxiedBy: BL1PR13CA0216.namprd13.prod.outlook.com (2603:10b6:208:2bf::11) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) 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: ao6xM8paWj8W1BV6BMlXhk3QhR/VThr8iEKeDACvc9Y7fOoBPjN2A2xfG6Px7mw//1i3mMpVEvRC48S1NBHGrCa1DyvjemfUPnNGSEkxZb/Vhscdb9ARX8ckRki5H2IWW+miJiyhvkAQC9VbmpLAMZuJM6E7BZJ4J40g7LHssvuTk8iWRdoKrlkMeqZTtkhSInBcQJJWTabZDW3kvzI7BxpTK7Xhi1FV/X+cGiZsTUbPIsbfxCOoHfgQTsAgmlrIbsC6vKUJFYH4dS57ICsa+4JpbOdmF6QHSvoptWHOElNZSK4IzNoyVZdPwkwaQ1u4ogkeWDOwwn/mLE0lkW2B8z80S1x728DyqvnhmeULoXnBtA1UPGk8Up8FgQYkyWJmaNrCtEjcYWsdoj+2sUw41Ujfps/8vtnmjgxlNVKoInzAwGSmZc7uqhWgje+29Q/gLRyBNBFVLgri+xQf0kMxAy9za9Xa6/HxDbzykji3pg+TfZztyeLeJV1l6FnIwlFZB8unuaORP9hZ6Re8HMT7OwhbGLXqcvgvQ1NobiS6lfVKXbA1TZzBuOTIqC2+pVMMTnM554A4slPPLjktX+rDg83cy+yG8eK9VEV/oZpr38PMoXDEFMdweFyx5MnSTefWbJJC57HQTaIebtOHvAihCEe3dfKO7ybiGXoZxpBl2XrtijBR3qFW8o575L3rD42CUf1Q7v6WmeCssIkhlj3bFSQKUgY/1itjZJin8algqvcIdTOrr0p2eDL0yJu0ETmoU6wAzxmAxbjYUv9je6cpAHZxNxCfyKTUxhDyCVI2apw423k+mz0ng4AuMfSGx0ZqJ72y6rys5NpT9XRfZK0I4q2cQLlBk+mrWhai1UWfsmTWjzwn/idXZYtUr/HAa5m/DYtZTh82Bi4jtd1ZP+4OVV7dH001va1t5MDk0VTyV3v6M5gB8HqCF1qf50eWUvnRLJTYX6Z6b6RUc6nwrLrR84N3zX0JJ/fo89Cyr87/oyNTKFbHOyHvV9Q2RCbrllZv7+Tp6ntMu/wAlS/0ylHKrzz9xHSWX1ctoe2unjXyr4qRom8klfPl3sHCSl31DruWDH78nBfjW+drshMnOja90GfTXU/P0SKzDgr3qwRG/nTO66n8+F9ev8gtH5Kp4TMNChV3Cql6TTHA3tRV4ge2c/vLvTV29lPz6sGU+DkGfGmKqW6arckT0QyadItX6KfcSqe9ENtnrOir9mf4b7FCNKuPEQuiiVKKN4H7ueidM7Qao6zyTgmyXkALj2xACtS3CFeyUFtXXXqpTlKhOqaeSzi35Cx2aSKJIyuObfMnliC22+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: S3AWpXHLvR8V8016XN5gZXJsu6xOaAvvlS5qjELxYLjsFR5JjRilojyEal2o+5UQ4O+fd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U1tsyOQENKWGMM5UUTaVv/9yWrpoSAalmffRTiEEeFcXo1nw1zlRPkZKLjJELYUTO+BCpDMreOjEBQg9zJJ5Pnd3cdiTlSmg1HEYIJkcE+7KCrbF1/X0kXbpgWkB0/f0b+s/V29xu5WIk6vGf72BahIi0bv51YjgPwfdqtOmIncEo2N+tVLHn65e1wYP5xaR7nSkX9Fe18I36iSb1jDK8Kkcj42yh6FD4zqkBNBcO9qRI1Dp5TCWN9rfR8/85ESbHVv+v4fz6y6hHibCntBdqhNSejSUj9kCvSNFRB0MbTv/KKQb8chvGMB3YHuKZyT0zUG95nwEVqQJnqJYzSkr4gTFRuFRuzLFgSOHsBC+PVaxBdCcORQictG4/vmoxzPRxyndDSbk6t7yk/rBKSE3BHS8ZtO5HN8tLWddhYk3mbvnERYvc0aermuqDNP3HSEHE1 X-OriginatorOrg: Nvidia.com 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 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 92D83C0003 X-Stat-Signature: zygtsii4n48egkmy1gdtq3z7bxwnoaip X-HE-Tag: 1732215305-143082 X-HE-Meta: U2FsdGVkX1//ew9twjRjVByqpXXlEQ3aZcRbw1gtJwDKiSG1W0xAAlQU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j6V+6QpJzztKL/EuaDEdfNxrnibbRHBoGXj7bV9gUxZzWrJrGeaftKgkoOuQuvA593O2Rf5pgpsal3ydsKDRfZLjdqKccHBdTTNyEG5C7OJUVwowZRxC4hyUPTIJ64FGCVRGSt/urHll/fXjtsakk/1LxC6u8H29qwkgQKilx68phoTO8TzUrY4oOl9CcRcxa1RRKKnxFUIzk7KKIdeFt14vu7vKgmdYRnmw+0huIAHPJuplWoQ5bS+KY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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/testing/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, size_t fd_size, int *fd, return -1; } -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, int order, const char *fs_l return; err = 0; - write_debugfs(PID_FMT, getpid(), (uint64_t)addr, (uint64_t)addr + fd_size, order); + if (offset == -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); for (i = 0; i < fd_size; i++) if (*(addr + i) != (char)i) { @@ -458,8 +465,8 @@ void split_thp_in_pagecache_to_order(size_t fd_size, int 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 passed\n", order); + ksft_exit_fail_msg("Split PMD-mapped pagecache folio to order %d at in-folio 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); } int main(int argc, char **argv) @@ -470,6 +477,7 @@ int main(int argc, char **argv) char fs_loc_template[] = "/tmp/thp_fs_XXXXXX"; const char *fs_loc; bool created_tmp; + int offset; ksft_print_header(); @@ -481,7 +489,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1]; - ksft_set_plan(1+9+2+9); + ksft_set_plan(1+8+2+9+8*4+2); pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; @@ -494,7 +502,8 @@ int main(int argc, char **argv) split_pmd_zero_pages(); for (i = 0; i < 9; i++) - split_pmd_thp_to_order(i); + if (i != 1) + split_pmd_thp_to_order(i); split_pte_mapped_thp(); split_file_backed_thp(); @@ -502,7 +511,13 @@ int main(int argc, char **argv) created_tmp = prepare_thp_fs(optional_xfs_path, fs_loc_template, &fs_loc); for (i = 8; i >= 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 = 0; i < 9; i++) + for (offset = 0; + offset < pmd_pagesize / pagesize; + offset += 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); ksft_finished();