From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4496C2D0CD for ; Tue, 17 Dec 2019 19:02:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 55C1A2082E for ; Tue, 17 Dec 2019 19:02:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55C1A2082E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=stgolabs.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B715D8E00A0; Tue, 17 Dec 2019 14:02:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AFADD8E0079; Tue, 17 Dec 2019 14:02:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C3968E00A0; Tue, 17 Dec 2019 14:02:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0085.hostedemail.com [216.40.44.85]) by kanga.kvack.org (Postfix) with ESMTP id 8292E8E0079 for ; Tue, 17 Dec 2019 14:02:34 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 270FA4DC5 for ; Tue, 17 Dec 2019 19:02:34 +0000 (UTC) X-FDA: 76275554628.24.mask61_3376b4fdb864c X-HE-Tag: mask61_3376b4fdb864c X-Filterd-Recvd-Size: 3993 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Dec 2019 19:02:33 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4361EAD93; Tue, 17 Dec 2019 19:02:31 +0000 (UTC) Date: Tue, 17 Dec 2019 10:55:57 -0800 From: Davidlohr Bueso To: Waiman Long Cc: Mike Kravetz , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox , Andi Kleen , Michal Hocko , "Aneesh Kumar K.V" , Kirill Tkhai Subject: Re: [PATCH v3] mm/hugetlb: Defer freeing of huge pages if in non-task context Message-ID: <20191217185557.tgtsvaad24j745gf@linux-p48b> Mail-Followup-To: Waiman Long , Mike Kravetz , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox , Andi Kleen , Michal Hocko , "Aneesh Kumar K.V" , Kirill Tkhai References: <20191217170331.30893-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20191217170331.30893-1-longman@redhat.com> User-Agent: NeoMutt/20180716 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: 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 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 >Reported-by: Aneesh Kumar K.V >Signed-off-by: Waiman Long >--- > 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() >+ __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()? Thanks, Davidlohr