From patchwork Mon Apr 8 19:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13621543 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 B04FDC67861 for ; Mon, 8 Apr 2024 19:42:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C4966B0083; Mon, 8 Apr 2024 15:42:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 074976B0087; Mon, 8 Apr 2024 15:42:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA54F6B0088; Mon, 8 Apr 2024 15:42:40 -0400 (EDT) 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 CC2116B0083 for ; Mon, 8 Apr 2024 15:42:40 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 91B0AA0183 for ; Mon, 8 Apr 2024 19:42:40 +0000 (UTC) X-FDA: 81987386880.03.4BD82E1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 7D5C040008 for ; Mon, 8 Apr 2024 19:42:38 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=uCLosnWd; dmarc=none; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712605359; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BrEoYf31c2AVoc+eqLyqp3TFa+yeR2usS7I5e6WvwOY=; b=UwSwJsEPSDfTKHFrUGci5OikxbI0gF4LwQDFZmsen9s1U2OHxOYpeshYI+1b9tCdLMHJ6/ 2M+1dYnvv1x3P2eZcQ8pGMSwRugNn4MWtWw9TVO3ea3BrgCRs1dq2kFu15+TaaPEzkA8Ii QxLMh63fZ9tfMbQW3kGCpTky8DurYhk= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=uCLosnWd; dmarc=none; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712605359; a=rsa-sha256; cv=none; b=B5LZGXouLEj+4m4hggmOtGDc1w69LcKnBtNWp+UiomD0Rzh9yHtzqxkMwTjzniKsKcM/TR GSJH4kYwG2PpM1DVepNSo1xqPzE1Lnf+KjvP5Jpd9lBonoqq0JwJLYnWpn0W6GAJCdP3h9 ULNhJTBBj9caX09tQ8yQnIhZmt7Mr48= 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: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=BrEoYf31c2AVoc+eqLyqp3TFa+yeR2usS7I5e6WvwOY=; b=uCLosnWdbtTZCoYg60K7Zsl0h5 6YWieKYa6qfnD4T22QcV9aTAA6yBcWgJ73FUHUlTqewgNXH7IRJJearNUuIWd0adU+UaULUYKTaEl IjT+dbzEdyB6Z3J5k+6J1z4RFQ0BV9FQP+9y+JgVGppqfWY2q/+vR4/RzW2yMpzWZWl21+1e2CzRL 9++Wma3Z6Dh1YC5YHKQ6xxCP0bM3nu6KQtGMWKacNzWzw4i4S27niJHvySI1SIxN00o0Xt4yE+5il RtMW+Gz8V2hhYdZ9GSo88zjVLvaLsQgZlPwUXC3CWFrIvD77zw5g4Xxc8qEFvhRp6kM0lttzIPUaV 05QcoHcg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtut1-00000000UqL-137T; Mon, 08 Apr 2024 19:42:35 +0000 From: "Matthew Wilcox (Oracle)" To: Miaohe Lin Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v2 07/11] mm/memory-failure: Convert memory_failure() to use a folio Date: Mon, 8 Apr 2024 20:42:25 +0100 Message-ID: <20240408194232.118537-8-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408194232.118537-1-willy@infradead.org> References: <20240408194232.118537-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7D5C040008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: s31w8dey7krjnts4fc9aq8a746dahyng X-HE-Tag: 1712605358-443659 X-HE-Meta: U2FsdGVkX1/ghPO1myx6obG+wi6VMvZ+XrNpznv8o7/WHj+Kbg9ibmwhaWsVeM+TAAbCdZTZSjpGgzefI1V78YLjWQ+dPCYte3Lu9JiZzJSqtOWr07xvJtPhFTD9M5bWEQIzWtaQMU8QMsXPiMJHdQNfwYst3vulFBZ2r44JV53BFDf5PqJ4XmlRt6O7WT4iKvLzc3BxnD298/VPSeGjiBiw4a+KtExgw2ICvpKbSANHGpji97o1IFUZaXyXSWEPwVg4xfLKDp/Dr4SLnSiiznIbLhddR6s9tADu9nZyYrJHxrrtCTEkEZgksayiURvA3PIeDxJdtlwtK7fz5axsXen3DdWsnTLAkOcKocnj2EHTx3lmZvgP3KoUl/cmiOjN78JDfrNwWiuS0yGqyfS3+vgm3fW/Spi1r3+KucxHYtE8I98ERfPzBJw6KzPY/Wv+axsDO6+kb1I062y+9Z0CrqKQoJlcS70tUntmywUVxHZ/FYwyn7lvnETKPEhRawdsT8lVZJE/5JeG3Ot0CdBnE82Y8KnoLS7rOBC1E/qqaR9bi8PFu2GobQZGuyGYod6FXV/jJzLIQH9jRwns644gJ0GRqMXkauYffELCTT07X2plbppJBHWpQztLIOlJWtgx7WXt/AhSGowCJAJhVImilNUeI9lhpGHIdzQVtCmEOGu5VDhYnWUPT8/1AgoZkUxoaBEtZ3gorcg8akLWFKJujiBnKDBuoOlfC23jBAXPGNYEtX5ufoqyCQN2gygoNUQAjV7ZTQFc6Kpznpss1S8eeHrP0yUX78VpiQAsR7gxETdcjdk6AH85IOKxfJ7JjDylNdqivZwGL2+AHYR8LF68OjEDcWdiaBsrJD1dOaiyAoWjv+NFvuaA+vL1gdQ5RZKwlJw5IxsWMB74Tz2w8bF6+BZGXQW+OhdHvvmyDqRc2e5ASFsv8kMFcq7Vv1p74CWdcQ1PD+diwVmtNEViS9M KTKgSHj/ ax8Cr6a5PmsxkAbDmRqvQoHRriCqgYDHx5YfygznamQiYYxF5wy5Xq42Ax2Lcto1bplbIZryHF7xhV8taiiGr9FzE/Q0/TCoDYYSQYsaAa/huS1MV1EjKGMMQ9UBBra57WYlj2D7LWnT58bXwG4JaK81d7Lkc2ZW9diCzDoSFeVO9m5M7XW5P48qVguGKnzHVs0YTC+MNhnn7nnP446FatA7rIPv/fSoushbUule6L/1wsBZd1zoJGdHEc+DP5Yuh8b+EwLM1J4Mvmpx/uJX5VAPiqg== 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: Saves dozens of calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/memory-failure.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 0a45fb7fb055..1c7c73776604 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2173,7 +2173,7 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, int memory_failure(unsigned long pfn, int flags) { struct page *p; - struct page *hpage; + struct folio *folio; struct dev_pagemap *pgmap; int res = 0; unsigned long page_flags; @@ -2261,8 +2261,8 @@ int memory_failure(unsigned long pfn, int flags) } } - hpage = compound_head(p); - if (PageTransHuge(hpage)) { + folio = page_folio(p); + if (folio_test_large(folio)) { /* * The flag must be set after the refcount is bumped * otherwise it may race with THP split. @@ -2276,12 +2276,13 @@ int memory_failure(unsigned long pfn, int flags) * or unhandlable page. The refcount is bumped iff the * page is a valid handlable page. */ - SetPageHasHWPoisoned(hpage); + folio_set_has_hwpoisoned(folio); if (try_to_split_thp_page(p) < 0) { res = action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED); goto unlock_mutex; } VM_BUG_ON_PAGE(!page_count(p), p); + folio = page_folio(p); } /* @@ -2292,9 +2293,9 @@ int memory_failure(unsigned long pfn, int flags) * The check (unnecessarily) ignores LRU pages being isolated and * walked by the page reclaim code, however that's not a big loss. */ - shake_page(p); + shake_folio(folio); - lock_page(p); + folio_lock(folio); /* * We're only intended to deal with the non-Compound page here. @@ -2302,11 +2303,11 @@ int memory_failure(unsigned long pfn, int flags) * race window. If this happens, we could try again to hopefully * handle the page next round. */ - if (PageCompound(p)) { + if (folio_test_large(folio)) { if (retry) { ClearPageHWPoison(p); - unlock_page(p); - put_page(p); + folio_unlock(folio); + folio_put(folio); flags &= ~MF_COUNT_INCREASED; retry = false; goto try_again; @@ -2322,29 +2323,29 @@ int memory_failure(unsigned long pfn, int flags) * folio_remove_rmap_*() in try_to_unmap_one(). So to determine page * status correctly, we save a copy of the page flags at this time. */ - page_flags = p->flags; + page_flags = folio->flags; if (hwpoison_filter(p)) { ClearPageHWPoison(p); - unlock_page(p); - put_page(p); + folio_unlock(folio); + folio_put(folio); res = -EOPNOTSUPP; goto unlock_mutex; } /* - * __munlock_folio() may clear a writeback page's LRU flag without - * page_lock. We need wait writeback completion for this page or it - * may trigger vfs BUG while evict inode. + * __munlock_folio() may clear a writeback folio's LRU flag without + * the folio lock. We need to wait for writeback completion for this + * folio or it may trigger a vfs BUG while evicting inode. */ - if (!PageLRU(p) && !PageWriteback(p)) + if (!folio_test_lru(folio) && !folio_test_writeback(folio)) goto identify_page_state; /* * It's very difficult to mess with pages currently under IO * and in many cases impossible, so we just avoid it here. */ - wait_on_page_writeback(p); + folio_wait_writeback(folio); /* * Now take care of user space mappings. @@ -2358,7 +2359,8 @@ int memory_failure(unsigned long pfn, int flags) /* * Torn down by someone else? */ - if (PageLRU(p) && !PageSwapCache(p) && p->mapping == NULL) { + if (folio_test_lru(folio) && !folio_test_swapcache(folio) && + folio->mapping == NULL) { res = action_result(pfn, MF_MSG_TRUNCATED_LRU, MF_IGNORED); goto unlock_page; } @@ -2368,7 +2370,7 @@ int memory_failure(unsigned long pfn, int flags) mutex_unlock(&mf_mutex); return res; unlock_page: - unlock_page(p); + folio_unlock(folio); unlock_mutex: mutex_unlock(&mf_mutex); return res;