From patchwork Wed Feb 28 16:42:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13575770 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 C8D80C47DD9 for ; Wed, 28 Feb 2024 16:43:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CE6C6B0075; Wed, 28 Feb 2024 11:43:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 47E516B0082; Wed, 28 Feb 2024 11:43:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36DD16B0078; Wed, 28 Feb 2024 11:43:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2556A6B0082 for ; Wed, 28 Feb 2024 11:43:36 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D064A140C22 for ; Wed, 28 Feb 2024 16:43:35 +0000 (UTC) X-FDA: 81841783590.12.0D4CF5A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf21.hostedemail.com (Postfix) with ESMTP id 993621C0012 for ; Wed, 28 Feb 2024 16:43:31 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=vhD9I0NR; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709138614; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=u95dZY67T6MJ4YRi4qNslP7XHlCmVrTaY0voAJGTxsw=; b=U8uxwckiyvh4gJr1BMkffw77wjRyAktyrwa7AQ1Skxo0jkA+S4uLxhppMkHZAZ7+3UsxIW INnab4Nz3r4QaMVpsng48v5gwwe5nmzrndOtwq5gJK5UhUiSCH36TYxRIlPpl/lutmnsUI bIJnZ7wYTkx4NQKXL7kEmM73OXWgd1w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709138614; a=rsa-sha256; cv=none; b=1vkTXhTNcbM09TFZs3yizy7DL+2Yggvf0qCHdPzdwN3eBaWkXGiqQvJNOvyqRQ6S2MAcLr 4KUYHsA6SaOayjvIJdL2x2DRqA/yoejerfi/DY62/QZpTna1vgRwSdJcMMMzkfRYUZTc6c 6vWyhOFWIj4x/yHa5WQAsGfDqhCe/G8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=vhD9I0NR; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=u95dZY67T6MJ4YRi4qNslP7XHlCmVrTaY0voAJGTxsw=; b=vhD9I0NR6pRPymVmbCnRmHfuel 6lK0Hd1dspGrT/FEdXdqJQxGgN2rbJBPqi19tOFIzQUigyJWmwteZD+Dj6cPSF+tvj/FTVT5zPuYn Jus4dU5X4DSsKPgGqN4C0NGBkdbj8WXZg3TkwQwQ8x3WavCtX2uqmCegC2AE2+F1sYhJT9txY6PoP ZXDOv1aWmyBPBJQ792RqWJ3A1mlTX07V1KppjGObzvWinaaOzAhulaaw1M96c+mxdjqfAF6h3/mjj GBAn63ogwSueoLSqBO/GQFz1YKy2xyrpXBukhsCfpibxQXHsV6JR9XRDu8CTGjPV0ypKZ682Hm8YR AtaY+vcg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfN1k-00000005gZv-1L61; Wed, 28 Feb 2024 16:43:28 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton , linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Sidhartha Kumar Subject: [PATCH] mm: Use folio more widely in __split_huge_page Date: Wed, 28 Feb 2024 16:42:36 +0000 Message-ID: <20240228164326.1355045-1-willy@infradead.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 993621C0012 X-Rspam-User: X-Stat-Signature: h564yeiru4hjwebt3pbcys1oo6em46d1 X-Rspamd-Server: rspam03 X-HE-Tag: 1709138611-363400 X-HE-Meta: U2FsdGVkX1/BS7PI9ajYUwPqZ1P2Y5RQ100RPET4UEJcGgNWlK1qmgNaLFtbxYbHqyJjhLIUnjlbN+MkHSN7e+9gLjGcW234rawQvQkS0sQv+YQ0qp4KMOHx6qnQZo8n4inMYkpJLFWMn4uBw2PgFYojx0c+skmtmrHVZlF3iK3wPBczCgHAQeb4lVEYUCNzXc3MmRMIXMXPzMk2zVjN3Yiv5tN3xpfAm+4oabjsyHiqKpMjIuHYsak15qxSkqR79kl/nUssVAt3M3V6o1YCVfkiEK20N58RpcH3iINQinY7pNm5hsuPdvzTX8LhT1c/nMsKk7q1/loOo3/G2VrdaxyOp5Az3r42MSTIBTu1w4ioAiSClUEyfKHzeMc24qAWidsnaTj1iQKu/9VBNPaEGG8OI1JFciXdM2yzKWVoAAQTMiuaBbXULqkm4VE+jHmb0BHE4uROeTDJFgzdoB0/t1jTaU/IPviYvpp73CL693LLxlQ8ZBkXM044S0FKf8GZ3Z81zO5kSMGtsl4JKUKcaV04mpYyJIswRPWeU8PSG7/XmVgE1QXlQgjF0NSRxH0lYIL+73DWZ1MyHqXtj0tFVmF1qTSL6UrStEfMSNM2XbuBYhkiN2odOSWoeeor6QWu+VAdIAYcJ8ezmFAu1HW2ONVSXiYnLVdFd57U4/pPR4P93Og8pJcyPc2bBGx0AYC/Y26rruxj+bQEUTe/xKL5s9hsuBshLQcF1xRcjAA0rFziehWe0nMNxWACg3ieBe4gvmXnrNzoyAvRSAKW/viKqN0wsZ7YcNzFLOT39emAbLZNyalMAo66Ba77WBMePqyY6U6CsX/IYeR2XhcBxfzHhyHvIXU1yOneJSljaUTdRYBUgMAIEODWxtqGRXx25ENll4gKA8JjCpAVzbg9/dQfXW3W2HL8KOuo 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: We already have a folio; use it instead of the head page where reasonable. Saves a couple of calls to compound_head() and elimimnates a few references to page->mapping. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Sidhartha Kumar --- mm/huge_memory.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 50d146eb248f..110730e855c2 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2919,7 +2919,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, if (head[i].index >= end) { struct folio *tail = page_folio(head + i); - if (shmem_mapping(head->mapping)) + if (shmem_mapping(folio->mapping)) nr_dropped++; else if (folio_test_clear_dirty(tail)) folio_account_cleaned(tail, @@ -2927,7 +2927,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, __filemap_remove_folio(tail, NULL); folio_put(tail); } else if (!PageAnon(page)) { - __xa_store(&head->mapping->i_pages, head[i].index, + __xa_store(&folio->mapping->i_pages, head[i].index, head + i, 0); } else if (swap_cache) { __xa_store(&swap_cache->i_pages, offset + i, @@ -2948,23 +2948,23 @@ static void __split_huge_page(struct page *page, struct list_head *list, split_page_owner(head, order, new_order); /* See comment in __split_huge_page_tail() */ - if (PageAnon(head)) { + if (folio_test_anon(folio)) { /* Additional pin to swap cache */ - if (PageSwapCache(head)) { - page_ref_add(head, 1 + new_nr); + if (folio_test_swapcache(folio)) { + folio_ref_add(folio, 1 + new_nr); xa_unlock(&swap_cache->i_pages); } else { - page_ref_inc(head); + folio_ref_inc(folio); } } else { /* Additional pin to page cache */ - page_ref_add(head, 1 + new_nr); - xa_unlock(&head->mapping->i_pages); + folio_ref_add(folio, 1 + new_nr); + xa_unlock(&folio->mapping->i_pages); } local_irq_enable(); if (nr_dropped) - shmem_uncharge(head->mapping->host, nr_dropped); + shmem_uncharge(folio->mapping->host, nr_dropped); remap_page(folio, nr); if (folio_test_swapcache(folio)) @@ -2980,9 +2980,10 @@ static void __split_huge_page(struct page *page, struct list_head *list, for (i = 0; i < nr; i += new_nr) { struct page *subpage = head + i; + struct folio *new_folio = page_folio(subpage); if (subpage == page) continue; - unlock_page(subpage); + folio_unlock(new_folio); /* * Subpages may be freed if there wasn't any mapping