From patchwork Thu Feb 29 21:20:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13577662 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 4FF15C54798 for ; Thu, 29 Feb 2024 21:20:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D87E26B0099; Thu, 29 Feb 2024 16:20:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D10826B009B; Thu, 29 Feb 2024 16:20:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB0796B009C; Thu, 29 Feb 2024 16:20:54 -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 A317D6B0099 for ; Thu, 29 Feb 2024 16:20:54 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 74DEF403E0 for ; Thu, 29 Feb 2024 21:20:54 +0000 (UTC) X-FDA: 81846111228.02.33268A7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id D7EEE8000E for ; Thu, 29 Feb 2024 21:20:52 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=kUTN5A2g; spf=none (imf30.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=1709241653; 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=7K7R34AzynDik/x15OMejoZCMXKzS4+bK4IM3eHNHto=; b=KCoAmUh8Sy+/wpNb3RYrN8S1YMYD7qM9Pmg+N/hMDXuuqKpFnPwsRW5DVpzCnXCygjiL3r OaH5IPjCVRvEe4Up4Fm1AlCCBfGVYE7/qh84A5KQOyZuzCph0DuLVdlh492aZyF7bq0giK TQn8634/WZ5Uril8NJmRewGRACMtneA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709241653; a=rsa-sha256; cv=none; b=qfiQAmtSvnT6xDLUptsq07c1OLFmdI4tZxIx/t/qfF7suQfVEmZrPpaYQ3037qd3LrOE9M Fu7+Neq0g5fJSeI4nsTsBwC6cDwiEeXNGDO16kaZDJd1jssRvn9fpbTQEXQhxWGMvNp0TN L2UsrX2ggZW/uv+jhmi6Pv8xWqF/0a4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=kUTN5A2g; spf=none (imf30.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: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=7K7R34AzynDik/x15OMejoZCMXKzS4+bK4IM3eHNHto=; b=kUTN5A2g8s7z43+33YIZAeIFwo reKWV+BkjPLOcJL1kYk+G7Y3721poRlQm4ATybo5DnSv4Q/tGHVp8ehglKJIlYKXJUcoaCtfNJXb5 +e9eIpjR1YX8j85Bcb94GBRMoQczEkmwNjyIQl2CNfmmMk6yxwYvag+bHOx7V7XVxwFEaBCYn61rM nJYNsQkZlRv09wyw7TGdPPp9KgrkiBd94dMGibMjtdwPR2Zid2zz49W8xDv3sP2bNnYjUwjlHxyEv FoiejWSUS3s5FlrqpGboNsD3KcrKMhuuCIEoZqzcJY/KQc7Yhx15xXlTewiT9KzqfTk1V2Tdu8AMI me/CiPdQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfnpV-0000000949g-3wsf; Thu, 29 Feb 2024 21:20:37 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Miaohe Lin , Naoya Horiguchi Subject: [PATCH 6/8] mm/memory-failure: Convert memory_failure() to use a folio Date: Thu, 29 Feb 2024 21:20:32 +0000 Message-ID: <20240229212036.2160900-7-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229212036.2160900-1-willy@infradead.org> References: <20240229212036.2160900-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: D7EEE8000E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: xhk89bpznne7gzrd79dkhky1yzde4343 X-HE-Tag: 1709241652-676661 X-HE-Meta: U2FsdGVkX1+4mwXkYSB/Y9yR9HR1xJIZRAHu++lxfLgEQUBjOqis5XVUmpXuVVz8a3Zgqgl9KG20U8DtBRJ2fg3MWAsr9i463IsFdLtG55ma7q8W6uR7e5WGeB3abcOH7lpRnEBPIsj9w5DJDa5p7dLjw587fan88Sv4aeyXbTd9tbEd1RE4DOXdJqwdm9HSVsEsXUSjk7Qc7RmfdIQ1+gJDU/bNtO7aXFrdRvLRM2ak6itsV4DggFJcRmBmgaN0f2/jCTzEBmXzzh81l1fCHz0SNX41ahgtr+vXV+ng68NMYSK8QLNZl4bQJCkeJGeRxkMTHMRyACQRVMBUr+l03NFeW0G9Of06uxhFqm25nITgPze+t/xUmBlRotrdokveSUDQke9y1vPGgioXIjWuGL/NBRIHiZUvx0xAWu9xWUaQ9jI5q5SP6OGVlIgKOJfQ3AQh1fjHMlo752eF/EEUDR5awRYVOk0Kk6tIR2TQjk+kHIa60pXa8YWkoAvhSggs7gFcVMNffrjceOuTE3FawB1D3nAUZAeIXF5ZgfJvxEa1a1Ic64Hc2qnQs43EPgPM9xdHGWuFLH/w0qrU7FRe18RO8oWyqP7ZNiatdGn8l6q5S2X2dW7fxrpWLaw7TaiDE7iAwb1krPZbbSWFPURhs3+LAPwE7XPJAWNCJrHQN116FZT+6E34a5g7dCT/3CWxF9mj0BZH2wCoIsbqDvJQwCtbXvcUd7s7g1fWbuwyVHjfj7McdpwAcDxt7+RwknK5ELSXLqWUG/P5hOXsXZLlPcDCPueHiqqJneXRx2d1bjDND1PKpbnsTnT/8NabZ2qzY4wZreAtoPqsPn03mSFPE5OZkHANHuW12LYVYa/WcNANF72lnvEEzCXU6Wd36MAI/TSCBYGoRhdgv3FlqHgF7Vl5qCYkt47DejlVq7LwTKShqlfYdw2hc96iWH1PFAjx+lFhbVULHZV2/bbJXjb Z8RrVMCs V6U0gfIhgIoXPlgIURg2k7CAiA7dYkouvNilFpH3YQRICIi03aZNPwt8ym+tjX4TyRN1LPEAii/18dRW5QwqfvE1yRKHC4xx8JyBhPhLmlNfHoQpFRrFhTZprtu4otmg2ti3s+9ziT24e2D3ULXCgUVPuLEhODRvDqHV3kC6QPt1/ISQHyVr9qAqzF8LEcfYtSBTMoM6xzs7KKDWu6hRidd0trcauFmTtnrGcbeMjvzp11yW4fb+FLkRZndd3dLnl23vFRJ9FoAaQbwHB3avhCC3AOg== 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 fe4959e994d0..74e87a0a792c 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2189,7 +2189,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; @@ -2277,8 +2277,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. @@ -2292,12 +2292,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); } /* @@ -2308,9 +2309,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. @@ -2318,11 +2319,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; @@ -2338,29 +2339,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. @@ -2374,7 +2375,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; } @@ -2384,7 +2386,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;