From patchwork Fri Apr 12 19:35:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13628283 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 BD728C04FF9 for ; Fri, 12 Apr 2024 19:35:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C5DC6B0095; Fri, 12 Apr 2024 15:35:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 313B16B0096; Fri, 12 Apr 2024 15:35:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18D066B0098; Fri, 12 Apr 2024 15:35:22 -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 E52996B0095 for ; Fri, 12 Apr 2024 15:35:21 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B418EA1B80 for ; Fri, 12 Apr 2024 19:35:21 +0000 (UTC) X-FDA: 82001883642.09.F345EF5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP id 78F7A180018 for ; Fri, 12 Apr 2024 19:35:18 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cow5mePQ; spf=none (imf16.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=1712950518; 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=FFGXNTBBagGzWfpmBcZ/z9lP6hkxmXG0SQeH9eRIjBE=; b=LKqcikznkcbpSz+Ra7HRPYHcH0t6NbQqkQM6QsS9mB2Kx0W/P71a5iD/EER/b/haU3dJvo yl2K7r2XAZWmfBOjQhRH4+0+p/aBg3IHbYJxJRfYBUYLULAgRzqtvO7P5Z9EcM5O4HapHW uaooRrTmm495BREoFN294to9iZvB0i8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712950518; a=rsa-sha256; cv=none; b=Wo4u9w/wle/3rutQ8sjY+IXxyJakDfAcieyWNg6HRC12wNgbqcHdWx97N4OlOuQ1UD9Hcw WBTIPvhuQodFu/Hm+S6YlVIz8pcKFn3UcRrWNx3igB4QrDBnq81aNujIq0Ve+B0x3/vF1R 6y5uZy92+GyIbZ0E87du3IiVf7Rbfao= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cow5mePQ; spf=none (imf16.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=FFGXNTBBagGzWfpmBcZ/z9lP6hkxmXG0SQeH9eRIjBE=; b=cow5mePQuOdv5dM2sOWOspFXVk LYAKpbnU4BDicGdOSh20irRXwDImImuLgqzVJsZn9h3894oeK9YKZ+4QqM3hLsv3E0mDyOFj4Hf8h S61pfX7VStAExMNIEXCGOv30KE2mVJ7PP0q+bwvuFOR5osPxPmLYMsB7bUt97m2gLP0BAgpDGxGtE rnoKhJLNFtBWZoyegpMA0HRM53HWuY1cFoTbJwaJSWR/K40hK0reaOKxJkCff+zv3DEk5cVAQhkmv sgNpgJRGA7X+Mni4Zd8IWRaeuQakWykWliLpKgOQVdux1FzK+XTWGP55SdyHXtpQr+5tx0rR2IGpf U9EQRZ8w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvMg4-00000009t9q-0KxR; Fri, 12 Apr 2024 19:35:12 +0000 From: "Matthew Wilcox (Oracle)" To: Miaohe Lin Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v3 07/11] mm/memory-failure: Convert memory_failure() to use a folio Date: Fri, 12 Apr 2024 20:35:04 +0100 Message-ID: <20240412193510.2356957-8-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412193510.2356957-1-willy@infradead.org> References: <20240412193510.2356957-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 78F7A180018 X-Rspam-User: X-Stat-Signature: f41s71637grms76asst1rmmr8cyjkipe X-Rspamd-Server: rspam03 X-HE-Tag: 1712950518-501801 X-HE-Meta: U2FsdGVkX1/TbZVqokmXJQT0KG6gWT3ZFwZzmFfHBzReGKsFmaEna97RkwgAbvoka+ngbVd2xsZLxLNH/iFAARmVW8cbFMWM8oV/j2hOJRLV4X3G0cQ7ReUd0Nb+0hylRB585zCIRfQ17sdF/n3ts4zjcqXfsasdwK2MsSRcNbqP+/NM7MtBwbr9my3FeZnanZwMQwG1GqZvuyA25YiFccZZrpzaiVMhOwrLDaJF9em+lKnTuBhNeOZxs9GelVcimL9i6ep/evPFxS3Sbs2f9yQ8Ctl+DoApTBb5iB+SX1Jz3NwfdPcIyNUul4qGoNSc69Nmr6S/bHp1rR07p/jK0a7D0b7tUebflNiD6F7PUyeL8ZDgPBm6x52lnJcOLMRDcQe0FeDfZ98dsqgYk1gbgERgDPSkuDx/g9BwjQ1hFuRvoR3fyEawqyBDZqGAr2PVwVwGXWFoYmW6C+Z2Vo/Mo4x+PIIryVWXp0nqm00YeS7nxw5zDoefXQ9Z5LBU069QGLr8mdkreJugTolNNulz8FS1jQSyXPm5Sg3aRAeT/1CzTNC/g0JJdYWxQKsdBgzF+EWt+Q4AkpyRVqCT4k3VFYyUOKJFyNoWW+RPKxmg2w+rNtuV7PubewgHGX0ibq4tZufYAp6rFrTwnNxx6JiTvvsslGP9Wr61xQGdReMoEdLWdXEgeSnZdx4pIIcza16l+KvidszSW1QWZQhov7y6cNiqjBPvKVBm9cZtfxvwpa3CK/MLQKTIk7xuAUMPSZRpGTheSanla+P+YkvSUcIcX/O9WaOZGABLc7i34/kGw9p0/PJXQ9gHBfYgaBfYL9CP5UkIRfKlug48t62bpUrFB9mZwJAa31wxbqi7NOXYe8vx+0e7/Ki7yMeIE0uS2fRSaJwIya6+2v3YT6fxllKKQSJ2dUPeVRSMYfPrcOkucfgI6cVvGlSrIi6kjWHJJgyKkTEFGUnjsilHlZ52XX3 TCN2e6eq Yz8myBPweZtOX618juxIy+8sJL6d9UnLVpRgTev0ZyCCY/gpOqMB4Rnlwz4KanqYo+iuMZ0E7VfsHK8Wy+Ilh4VqhEHd0KOKdUtnaf97xNMh/fZhEBNWX3utj0ofTa+MDmbDOGbn61PAjBCYSIT43mt4VDLVng4qL12Jelj/ZCWrGcyoZgOCXlD46ZPQzX2pFQvbzoq7oNrM6beuVcm2ZVJug+LY+d9PYA1H8 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) Acked-by: Miaohe Lin --- 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 52feaa9de9b4..2c12bcc9c550 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2183,7 +2183,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; @@ -2271,8 +2271,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. @@ -2286,12 +2286,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); } /* @@ -2302,9 +2303,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. @@ -2312,11 +2313,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; @@ -2332,29 +2333,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. @@ -2368,7 +2369,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; } @@ -2378,7 +2380,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;