From patchwork Mon Apr 8 19:42:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13621551 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 6E3A4CD1292 for ; Mon, 8 Apr 2024 19:42:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BDF16B0095; Mon, 8 Apr 2024 15:42:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46EAE6B0096; Mon, 8 Apr 2024 15:42:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2727A6B0098; Mon, 8 Apr 2024 15:42:57 -0400 (EDT) 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 07B046B0095 for ; Mon, 8 Apr 2024 15:42:57 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9912880152 for ; Mon, 8 Apr 2024 19:42:56 +0000 (UTC) X-FDA: 81987387552.06.602438D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id F1509A0013 for ; Mon, 8 Apr 2024 19:42:54 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=RpL1PRDc; dmarc=none; spf=none (imf15.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=1712605375; 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=B4hnryhcXkSp4iS7rv9BaRyeZuX8K6Kk9RX8X9f3irE=; b=7sNeY4fPWR7Z0+D5j9Qk1b4Y4IKerreD77b8ONvBQnnssRW40VP+n9MGPhWrfPr8Vcu3M5 +gZUSB8CpSYtdqMK3782FbIrdOwh/7yb9uwXCPqSm+N7oxRCpxqWVD/AdDRbqJWSqE0LdR ev11DnQmFsyz8Vnls5wIFgpzRJwrwf0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=RpL1PRDc; dmarc=none; spf=none (imf15.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=1712605375; a=rsa-sha256; cv=none; b=quYqDTD9PIV15GEWWbnKUKTFC30/t4+1MGu9yoztRel0WHEIuNSDNO0fy7lSL0XuRHVYkn O0V8vTjIDQj0wwaW2ogf/EG0vpU3q6eGelCWze6zxhXwRH5XxbNyoCstlcQuKke6IHhLLN fEc4W/3w+xp81nK43Eninh0nl/XCaZI= 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=B4hnryhcXkSp4iS7rv9BaRyeZuX8K6Kk9RX8X9f3irE=; b=RpL1PRDcZ6XUEPlUVVVuIQY5H8 9Qg27XzCwO6OzAwddPhO8cq4Riu77Wt3isZ+zuAJ0ee8/Z/03NgHyOCMrczBc9uw7wTmSprW+mhV0 NdSfJ1DxqvSX2j38cJ/dm0htn1OFP/j3wtrZLfgtDeOmW4WHAcCqU4yskoifKm4AZrhNmCkotnZ5C ZpusMVCYS5vG3anXQMPk/40QDidEUzEjEyrShs/h7HB4lksXOSvF9y7/Xhkmrf//5KsIx7sS+gA9V XZseW/hfk9r7hG4ldIS1PR++X5E4T7KSmQFoSp9sRUUiXB35TbAlZcNRDGkGGklGOJz4oU8c2ObTs zQwuFD1w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtut1-00000000UqN-1PSx; 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 08/11] mm/memory-failure: Convert hwpoison_user_mappings to take a folio Date: Mon, 8 Apr 2024 20:42:26 +0100 Message-ID: <20240408194232.118537-9-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-Rspam-User: X-Stat-Signature: 1nmhamyi6q1oza8qeewe9szp86s4jr73 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: F1509A0013 X-HE-Tag: 1712605374-190031 X-HE-Meta: U2FsdGVkX1+UUJ8rf5IxWqPF/1QZDrhRdoqiBJYtAmX9mrZJeOetDMpqQzkzNDWwgfu0hhIRvw21LPhUVHBQbv8lTEntOVKHLeMULt9cku/6xLG8mq3aZSBGj+FN+1l4GU6Bhgq9YLVaJJ6nO5KgKMedZZJvJT4lXDew32Q4K+aa6c8FVn6JJZhJXk5UTLuXqObu+22f5F+DnA07MzxQK1sTwISEVUzB1J75q4JPkZvfuIw/LGJD4KhoqaPma/bjjuWcEahOpwNuYbxszZb33Fly8TOT1SJCuIkdbNuGfCll1mxH14vZGbKd2J6FQnYkJNUb+Waq+U2ouLrw9tEEbu70S7mUjjGaBHQwIHRXNkDAbXh+/Qkd0bX0pRJMG7PvMjs1n7Zf+EZBuCy30WVBlSOfvCPcsHtFzgblTzHFD7ckO5HN81QsPBRZc33A4dDw+w5Cs6mIZHpLIxxtPKBXoIxuUIkrTg9L/7yTle5K57sOdrnKkmPTwCm/cpj9QY8/Ig1ukf3RhHSIVO2hqaZCT8EXGKJznrOJrW7/Q5kEZMXMQfunAD6XcVAwzpvqKjP4oHiDPyUzWCPuVG6yZ0GcSWQexdlkLh2sOEM8XAWBxb028R/eH2M94Pzme4MHPUGvYnWXNHK6Vt6dT4H+TOSEf7lf/GRTzmBsXyx6tuMvTSIVJd+mLTLyCWkNrp23aBitxGF8r2G0u69cFDPirSb7IT4UPajKLat8YY9ppESNbzK0y2jj3WWCW9oWE72hvO5h9LZdBxF1jyxqL+azJzcXnRgEYFZpW1RA3RdfECJi6hEsjTYr1V/0AozkYfATmmuXG40UsgUF2WPJQHP2n49CJDwMfGAqY29G1zT+M7OMHR1F9/t1KsGiTtjHdEK3QHc/UZLzJvONpb5ZfGICkYWI5QGaO4bsl2kAfF5zg6MUjO5GNE51P0PMVIQS6bG2kIX57bBlrj9z5SLlf/VGbSy A0t8zRv9 ngu8nUJdaJNUz3JRnSn0lSFYgQqWTBKMQoWurBlZ9PF+GewPL8snxGHk28TWBLcju06/aWcmRjPrlc1xmGLiNKAJlY1ipHbKB8das6C+4KvPK5p/uaX9TzAwhxsu6iD/hNBd+k9uRuuGlQ9r5rGYAFxdFmAnGvjgKJWIMIaUImZGeMstBcLFvnKN86BBu6Gxn418JKNAxg9UAUoSINFi0Zf45nFjfo2hUWn5aCNSt+rLW2asWnqRwbKuxKQ== 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 Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Jane Chu --- 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 1c7c73776604..fae0b42f0aaf 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1543,24 +1543,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; /* @@ -1570,7 +1570,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; } @@ -1581,11 +1581,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", @@ -1600,7 +1600,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 @@ -1640,7 +1640,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); @@ -2084,7 +2084,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); } @@ -2351,7 +2351,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; }