From: Jane Chu <jane.chu@oracle.com>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Miaohe Lin <linmiaohe@huawei.com>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH v2 07/11] mm/memory-failure: Convert memory_failure() to use a folio
Date: Mon, 8 Apr 2024 17:34:29 -0700 [thread overview]
Message-ID: <c514b97f-5924-4141-b60f-456023730432@oracle.com> (raw)
In-Reply-To: <20240408194232.118537-8-willy@infradead.org>
On 4/8/2024 12:42 PM, Matthew Wilcox (Oracle) wrote:
> Saves dozens of calls to compound_head().
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> 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)) {
At this stage, 'p' is not expected to be a large page since a _refcount
has been taken, right? So is it reasonable to replace the "if (retry)"
block with a VM_BUG_ON warning? otherwise, if 'p' became part of a
different large folio, how to recover from here ?
> 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;
thanks,
-jane
next prev parent reply other threads:[~2024-04-09 0:34 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-08 19:42 [PATCH v2 00/11] Some cleanups for memory-failure Matthew Wilcox (Oracle)
2024-04-08 19:42 ` [PATCH v2 01/11] mm/memory-failure: Remove fsdax_pgoff argument from __add_to_kill Matthew Wilcox (Oracle)
2024-04-10 9:09 ` Oscar Salvador
2024-04-08 19:42 ` [PATCH v2 02/11] mm/memory-failure: Pass addr to __add_to_kill() Matthew Wilcox (Oracle)
2024-04-08 22:32 ` Jane Chu
2024-04-10 9:11 ` Oscar Salvador
2024-04-08 19:42 ` [PATCH v2 03/11] mm: Return the address from page_mapped_in_vma() Matthew Wilcox (Oracle)
2024-04-08 22:38 ` Jane Chu
2024-04-10 9:38 ` Oscar Salvador
2024-04-11 2:56 ` Miaohe Lin
2024-04-11 17:37 ` Matthew Wilcox
2024-04-08 19:42 ` [PATCH v2 04/11] mm: Make page_mapped_in_vma conditional on CONFIG_MEMORY_FAILURE Matthew Wilcox (Oracle)
2024-04-08 22:45 ` Jane Chu
2024-04-08 22:52 ` Matthew Wilcox
2024-04-09 6:35 ` Jane Chu
2024-04-10 9:39 ` Oscar Salvador
2024-04-08 19:42 ` [PATCH v2 05/11] mm/memory-failure: Convert shake_page() to shake_folio() Matthew Wilcox (Oracle)
2024-04-08 22:53 ` Jane Chu
2024-04-08 19:42 ` [PATCH v2 06/11] mm: Convert hugetlb_page_mapping_lock_write to folio Matthew Wilcox (Oracle)
2024-04-08 23:09 ` Jane Chu
2024-04-10 9:52 ` Oscar Salvador
2024-04-08 19:42 ` [PATCH v2 07/11] mm/memory-failure: Convert memory_failure() to use a folio Matthew Wilcox (Oracle)
2024-04-09 0:34 ` Jane Chu [this message]
2024-04-10 10:21 ` Oscar Salvador
2024-04-10 14:23 ` Matthew Wilcox
2024-04-10 15:30 ` Oscar Salvador
2024-04-10 23:15 ` Jane Chu
2024-04-11 1:27 ` Jane Chu
2024-04-11 1:51 ` Matthew Wilcox
2024-04-11 9:00 ` Miaohe Lin
2024-04-11 11:23 ` Oscar Salvador
2024-04-11 12:17 ` Matthew Wilcox
2024-04-12 19:48 ` Matthew Wilcox
2024-04-12 22:09 ` Oscar Salvador
2024-04-15 18:47 ` Jane Chu
2024-04-16 9:13 ` Miaohe Lin
2024-04-08 19:42 ` [PATCH v2 08/11] mm/memory-failure: Convert hwpoison_user_mappings to take " Matthew Wilcox (Oracle)
2024-04-09 6:15 ` Jane Chu
2024-04-08 19:42 ` [PATCH v2 09/11] mm/memory-failure: Add some folio conversions to unpoison_memory Matthew Wilcox (Oracle)
2024-04-09 6:17 ` Jane Chu
2024-04-08 19:42 ` [PATCH v2 10/11] mm/memory-failure: Use folio functions throughout collect_procs() Matthew Wilcox (Oracle)
2024-04-09 6:19 ` Jane Chu
2024-04-08 19:42 ` [PATCH v2 11/11] mm/memory-failure: Pass the folio to collect_procs_ksm() Matthew Wilcox (Oracle)
2024-04-09 6:27 ` Jane Chu
2024-04-09 12:11 ` Matthew Wilcox
2024-04-09 15:15 ` Jane Chu
2024-04-09 6:28 ` [PATCH v2 00/11] Some cleanups for memory-failure Jane Chu
2024-04-09 12:12 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c514b97f-5924-4141-b60f-456023730432@oracle.com \
--to=jane.chu@oracle.com \
--cc=linmiaohe@huawei.com \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.