From: Waiman Long <longman@redhat.com>
To: Mike Kravetz <mike.kravetz@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Matthew Wilcox <willy@infradead.org>,
Andi Kleen <ak@linux.intel.com>, Michal Hocko <mhocko@kernel.org>,
"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
Kirill Tkhai <ktkhai@virtuozzo.com>,
Davidlohr Bueso <dave@stgolabs.net>
Subject: Re: [PATCH v3] mm/hugetlb: Defer freeing of huge pages if in non-task context
Date: Tue, 17 Dec 2019 14:09:12 -0500 [thread overview]
Message-ID: <4f7b23c9-6e05-3b71-9a94-f8d494d8b0e1@redhat.com> (raw)
In-Reply-To: <20191217185557.tgtsvaad24j745gf@linux-p48b>
On 12/17/19 1:55 PM, Davidlohr Bueso wrote:
> On Tue, 17 Dec 2019, Waiman Long wrote:
>> Both the hugetbl_lock and the subpool lock can be acquired in
>> free_huge_page(). One way to solve the problem is to make both locks
>> irq-safe. However, Mike Kravetz had learned that the hugetlb_lock is
>> held for a linear scan of ALL hugetlb pages during a cgroup reparentling
>> operation. So it is just too long to have irq disabled unless we can
>> break hugetbl_lock down into finer-grained locks with shorter lock
>> hold times.
>>
>> Another alternative is to defer the freeing to a workqueue job. This
>> patch implements the deferred freeing by adding a free_hpage_workfn()
>> work function to do the actual freeing. The free_huge_page() call in
>> a non-task context saves the page to be freed in the hpage_freelist
>> linked list in a lockless manner using the llist APIs.
>>
>> The generic workqueue is used to process the work, but a dedicated
>> workqueue can be used instead if it is desirable to have the huge page
>> freed ASAP.
>>
>> Thanks to Kirill Tkhai <ktkhai@virtuozzo.com> for suggesting the use
>> of llist APIs which simplfy the code.
>>
>> [v2: Add more comment & remove unneeded racing check]
>> [v3: Update commit log, remove pr_debug & use llist APIs]
>
> Very creative reusing the mapping pointer, along with the llist api,
> this solves the problem nicely (temporarily at least).
>
> Two small nits below.
>
> Acked-by: Davidlohr Bueso <dbueso@suse.de>
>
>> Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
>> Signed-off-by: Waiman Long <longman@redhat.com>
>> ---
>> mm/hugetlb.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 50 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> +static LLIST_HEAD(hpage_freelist);
>> +
>> +static void free_hpage_workfn(struct work_struct *work)
>> +{
>> + struct llist_node *node;
>> + struct page *page;
>> +
>> + node = llist_del_all(&hpage_freelist);
>> +
>> + while (node) {
>> + page = container_of((struct address_space **)node,
>> + struct page, mapping);
>> + node = node->next;
>
> llist_next()
I could use this helper, but the statement is simple enough to understand.
>
>> + __free_huge_page(page);
>> + }
>> +}
>> +static DECLARE_WORK(free_hpage_work, free_hpage_workfn);
>> +
>> +void free_huge_page(struct page *page)
>> +{
>> + /*
>> + * Defer freeing if in non-task context to avoid hugetlb_lock
>> deadlock.
>> + */
>> + if (!in_task()) {
>
> unlikely()?
Yes, I could use that too. For now, I am not going to post a v4 with
these changes unless that are other substantial changes that require a
respin.
Thanks,
Longman
next prev parent reply other threads:[~2019-12-17 19:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-17 17:03 Waiman Long
2019-12-17 18:55 ` Davidlohr Bueso
2019-12-17 19:09 ` Waiman Long [this message]
2019-12-17 19:08 ` Davidlohr Bueso
2019-12-17 19:38 ` Waiman Long
2019-12-18 1:01 ` Mike Kravetz
2019-12-18 8:33 ` Kirill Tkhai
2019-12-18 8:40 ` Michal Hocko
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=4f7b23c9-6e05-3b71-9a94-f8d494d8b0e1@redhat.com \
--to=longman@redhat.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.ibm.com \
--cc=dave@stgolabs.net \
--cc=ktkhai@virtuozzo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mike.kravetz@oracle.com \
--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