From patchwork Thu Feb 29 21:20:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13577665 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 5F0E1C54798 for ; Thu, 29 Feb 2024 21:21:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E994F6B009D; Thu, 29 Feb 2024 16:21:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E49AB6B009E; Thu, 29 Feb 2024 16:21:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC4796B009F; Thu, 29 Feb 2024 16:21:03 -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 BEC626B009D for ; Thu, 29 Feb 2024 16:21:03 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 95619C1288 for ; Thu, 29 Feb 2024 21:21:03 +0000 (UTC) X-FDA: 81846111606.21.7883678 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id EDC671C0012 for ; Thu, 29 Feb 2024 21:21:01 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=MSjTbsdl; dmarc=none; spf=none (imf18.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=1709241662; 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=/i71mU/Nb6V1/CjZzsouaX83RdxNI3t6oNpGN2+bQb4=; b=Pq0sdgftD6Q81xJ7SbmHKpxyvKZ6rO0F+ZLuvWC4qO/mccn4yA81zuiHmS8FHXrPjVkiZf 7EVhk3/5KJcMvqbDTVNvoACWGT4zHSfq35XTX+C912YWhM0Gvro1gVKSIHurY5P+kiVpCC rKb2phe7Bh4tF8fa1xNvfxFMy8BSbtI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=MSjTbsdl; dmarc=none; spf=none (imf18.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=1709241662; a=rsa-sha256; cv=none; b=bJ2iHdfMQ/LnD2GssospmxWTbj4qCmTBfsZnx16skSCI7R1AFR680WavBf2c6eIxtkG2Zn bdlHH0NOezYFsVC0pFoCysHE1bFArXxRDUzFSA6idPy7Get6Dw+4c+GmJpdjFHqfvjhfUm woBpN0vC+uJp/2vFn3tia0jYKKA8qfQ= 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=/i71mU/Nb6V1/CjZzsouaX83RdxNI3t6oNpGN2+bQb4=; b=MSjTbsdlr7itHtwt4nNYs7P+8a Thur/GPX90wKNCZ2Adr2PAyESlBuegZhRHzEhSB/Mz6JnriuBCM/EmTRB2aqPrKJ2n0jD2oauVfXb Cm868XtxNk9OfpleZWJh3pUBLjetug1/LuWsCRTP/kc8qH4lF63XSEm69IaQVRmj2IoOMw7Q/jHZt vFv/nmEBbRtFU6KEr9VClFOQboFuieg5kOnFd22FtutnqVzkjKjNm8eirWUkHakFX1axnHQK3qBQ2 5/dnQMmdlAraaqnTfR3tuVsDjF3Av6IBz1tOL/wtxVui1Ut90NkTwkGJZJ35t/eGQixFBEzZ0piIw QWODfbQA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfnpW-0000000949i-06Ms; Thu, 29 Feb 2024 21:20:38 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Miaohe Lin , Naoya Horiguchi Subject: [PATCH 7/8] mm/memory-failure: Convert hwpoison_user_mappings to take a folio Date: Thu, 29 Feb 2024 21:20:33 +0000 Message-ID: <20240229212036.2160900-8-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: EDC671C0012 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: uyn86xc5wd9rea6ybf1omn6s3dj1q63u X-HE-Tag: 1709241661-323851 X-HE-Meta: U2FsdGVkX18lip4f11tkwMsDYQvqPcKbqo/DbX9lU7E8W0cm6REOOFGsNdgPnF8mdTkhqndepaSIzSc9ozXbreT/IJRrakAPPb0He+70/0J1F7gYjSKt59T8uBBdBJ5/trnJwutt6WHfa5joWbMjNrclijmuTDrAJrQdSka7AYp/l6jkzqQPuG/LrUusqtjR+g9RFq140TLkVXfMlVkIs8fPfqhFDdtB6cQ+5hmozKtDWoHIacpMIwUHCrb9YTrKEhwpxmlX+nbPqvn+dXGYPRdUMUovkh9qAUUVXfv8eXSnhJ0lQ5dnjeqB++cVf90YQEIyt9I+njw8npRuT/LGDu1U/hsIzcAG6IzJ2TH7xKpQ/8J3Dw3vAQPBiVJD+iCq185+03OUK68IrbiEbeTZ0Rge1aosGF4xdET6GTSwWd0VLQ9geiuPqNcgCPqs4Zj/L2mMY4u1evgoHmPf2U9ufeO+vVs0H3x/NlTh1xUEjTxVfeobU/WaspdG6t7XjclBJfuDfaq2LWbmLAQJlpvGaVdJeofZSkAVg4BYuJhXHqoyOmt+wX7Ytl6ymCIk3SiMpaQqYyu15+az2fsrQL0Anpv+ELHU19snWKFhj6VuXFc5kX2oWg9Dj5xWKGhVVfuYvONmoBa7u2R7SmhiYUjEVWuL38jHF38Ezu1S2pBPVNUJNz7VYpQ388iKhLysQ/vlO1VgSj9XZ8mnWsjP87qb17UUf1NgJFr7feqCINzP/8X/JgCBAez1QLnDHA6PkUwHKR7fM4mPuylsUcknXMjkgeoL3NxJGNO+dJ/y3GVTwHDrkrVBQ47cf19Xe2/IzbU8GsYacLsncd+knhAzyjCI5xuosyF6FKZDZvcFaK1PxreL+iHe0n3iQ4on5B0cYAlRhwSwz2QmIrTjxIYWGxZxvW7FguxBkX+5o7hT04ni1C1Rn9DRhL56w++nur3aR883IaLzEgvKveY4BS//XA3 w0bKfTGJ Y8nAYPpqnBCSeK55JM3KTdDdvOSs5slxkeAA17wERoL2bn9aobiAVkaXSHFptEFwm/pH5k8DP6kmiDi2JBwRrN4N+arn4DqMWkbfTZaS+n44TIfAgEJI4hPxH+SHd3cWqUiXQS0W6GbRqO83nFC/PbJ5wg5nBSR+4acyF 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: Pass the folio from the callers, and use it throughout instead of hpage. Saves dozens of calls to compound_head(). Acked-by: Miaohe Lin --- mm/memory-failure.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 74e87a0a792c..56bc83372e30 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1559,24 +1559,24 @@ static int get_hwpoison_page(struct page *p, unsigned long flags) * Do all that is necessary to remove user space mappings. Unmap * the pages and send SIGBUS to the processes if the data was dirty. */ -static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, - int flags, struct page *hpage) +static bool hwpoison_user_mappings(struct folio *folio, struct page *p, + unsigned long pfn, int flags) { - struct folio *folio = page_folio(hpage); enum ttu_flags ttu = TTU_IGNORE_MLOCK | TTU_SYNC | TTU_HWPOISON; struct address_space *mapping; LIST_HEAD(tokill); bool unmap_success; int forcekill; - bool mlocked = PageMlocked(hpage); + bool mlocked = folio_test_mlocked(folio); /* * Here we are interested only in user-mapped pages, so skip any * other types of pages. */ - if (PageReserved(p) || PageSlab(p) || PageTable(p) || PageOffline(p)) + if (folio_test_reserved(folio) || folio_test_slab(folio) || + folio_test_pgtable(folio) || folio_test_offline(folio)) return true; - if (!(PageLRU(hpage) || PageHuge(p))) + if (!(folio_test_lru(folio) || folio_test_hugetlb(folio))) return true; /* @@ -1586,7 +1586,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, if (!page_mapped(p)) return true; - if (PageSwapCache(p)) { + if (folio_test_swapcache(folio)) { pr_err("%#lx: keeping poisoned page in swap cache\n", pfn); ttu &= ~TTU_HWPOISON; } @@ -1597,11 +1597,11 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, * XXX: the dirty test could be racy: set_page_dirty() may not always * be called inside page lock (it's recommended but not enforced). */ - mapping = page_mapping(hpage); - if (!(flags & MF_MUST_KILL) && !PageDirty(hpage) && mapping && + mapping = folio_mapping(folio); + if (!(flags & MF_MUST_KILL) && !folio_test_dirty(folio) && mapping && mapping_can_writeback(mapping)) { - if (page_mkclean(hpage)) { - SetPageDirty(hpage); + if (folio_mkclean(folio)) { + folio_set_dirty(folio); } else { ttu &= ~TTU_HWPOISON; pr_info("%#lx: corrupted page was clean: dropped without side effects\n", @@ -1616,7 +1616,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, */ collect_procs(folio, p, &tokill, flags & MF_ACTION_REQUIRED); - if (PageHuge(hpage) && !PageAnon(hpage)) { + if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) { /* * For hugetlb pages in shared mappings, try_to_unmap * could potentially call huge_pmd_unshare. Because of @@ -1656,7 +1656,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, * use a more force-full uncatchable kill to prevent * any accesses to the poisoned memory. */ - forcekill = PageDirty(hpage) || (flags & MF_MUST_KILL) || + forcekill = folio_test_dirty(folio) || (flags & MF_MUST_KILL) || !unmap_success; kill_procs(&tokill, forcekill, !unmap_success, pfn, flags); @@ -2100,7 +2100,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb page_flags = folio->flags; - if (!hwpoison_user_mappings(p, pfn, flags, &folio->page)) { + if (!hwpoison_user_mappings(folio, p, pfn, flags)) { folio_unlock(folio); return action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED); } @@ -2367,7 +2367,7 @@ int memory_failure(unsigned long pfn, int flags) * Now take care of user space mappings. * Abort on fail: __filemap_remove_folio() assumes unmapped page. */ - if (!hwpoison_user_mappings(p, pfn, flags, p)) { + if (!hwpoison_user_mappings(folio, p, pfn, flags)) { res = action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED); goto unlock_page; }