From: Muchun Song <songmuchun@bytedance.com>
To: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Linux Memory Management List <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
Michal Hocko <mhocko@suse.com>,
Oscar Salvador <osalvador@suse.de>,
David Hildenbrand <david@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Naoya Horiguchi <naoya.horiguchi@linux.dev>,
Mina Almasry <almasrymina@google.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [External] [PATCH 1/3] hugetlb: simplify prep_compound_gigantic_page ref count racing code
Date: Tue, 13 Jul 2021 14:31:08 +0800 [thread overview]
Message-ID: <CAMZfGtU0LzeVE-mXY7-mEAWZcu-q7K_Lp+HL4+VuDDOnxFkkNQ@mail.gmail.com> (raw)
In-Reply-To: <20210710002441.167759-2-mike.kravetz@oracle.com>
On Sat, Jul 10, 2021 at 8:25 AM Mike Kravetz <mike.kravetz@oracle.com> wrote:
>
> Code in prep_compound_gigantic_page waits for a rcu grace period if it
> notices a temporarily inflated ref count on a tail page. This was due
> to the identified potential race with speculative page cache references
> which could only last for a rcu grace period. This is overly complicated
> as this situation is VERY unlikely to ever happen. Instead, just quickly
> return an error.
Right. The race is very very small. IMHO, that does not complicate
the code is the right thing to do.
>
> Also, only print a warning in prep_compound_gigantic_page instead of
> multiple callers.
>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
> mm/hugetlb.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 924553aa8f78..e59ebba63da7 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1657,16 +1657,12 @@ static bool prep_compound_gigantic_page(struct page *page, unsigned int order)
> * cache adding could take a ref on a 'to be' tail page.
> * We need to respect any increased ref count, and only set
> * the ref count to zero if count is currently 1. If count
> - * is not 1, we call synchronize_rcu in the hope that a rcu
> - * grace period will cause ref count to drop and then retry.
> - * If count is still inflated on retry we return an error and
> - * must discard the pages.
> + * is not 1, we return an error and caller must discard the
> + * pages.
Shall we add more details about why we discard the pages?
Thanks.
> */
> if (!page_ref_freeze(p, 1)) {
> - pr_info("HugeTLB unexpected inflated ref count on freshly allocated page\n");
> - synchronize_rcu();
> - if (!page_ref_freeze(p, 1))
> - goto out_error;
> + pr_warn("HugeTLB page can not be used due to unexpected inflated ref count\n");
> + goto out_error;
> }
> set_page_count(p, 0);
> set_compound_head(p, page);
> @@ -1830,7 +1826,6 @@ static struct page *alloc_fresh_huge_page(struct hstate *h,
> retry = true;
> goto retry;
> }
> - pr_warn("HugeTLB page can not be used due to unexpected inflated ref count\n");
> return NULL;
> }
> }
> @@ -2828,8 +2823,8 @@ static void __init gather_bootmem_prealloc(void)
> prep_new_huge_page(h, page, page_to_nid(page));
> put_page(page); /* add to the hugepage allocator */
> } else {
> + /* VERY unlikely inflated ref count on a tail page */
> free_gigantic_page(page, huge_page_order(h));
> - pr_warn("HugeTLB page can not be used due to unexpected inflated ref count\n");
> }
>
> /*
> --
> 2.31.1
>
next prev parent reply other threads:[~2021-07-13 6:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-10 0:24 [PATCH 0/3] hugetlb: fix potential ref counting races Mike Kravetz
2021-07-10 0:24 ` [PATCH 1/3] hugetlb: simplify prep_compound_gigantic_page ref count racing code Mike Kravetz
2021-07-13 6:31 ` Muchun Song [this message]
2021-07-10 0:24 ` [PATCH 2/3] hugetlb: drop ref count earlier after page allocation Mike Kravetz
2021-07-10 0:24 ` [PATCH 3/3] hugetlb: before freeing hugetlb page set dtor to appropriate value Mike Kravetz
2021-07-14 10:57 ` [External] " Muchun Song
2021-07-14 17:39 ` Mike Kravetz
2021-07-15 3:14 ` Muchun Song
2021-07-27 23:41 ` [PATCH 0/3] hugetlb: fix potential ref counting races Mike Kravetz
2021-07-28 4:03 ` Muchun Song
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=CAMZfGtU0LzeVE-mXY7-mEAWZcu-q7K_Lp+HL4+VuDDOnxFkkNQ@mail.gmail.com \
--to=songmuchun@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=almasrymina@google.com \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=mike.kravetz@oracle.com \
--cc=naoya.horiguchi@linux.dev \
--cc=osalvador@suse.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).