Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1201080ybl; Thu, 12 Dec 2019 11:12:09 -0800 (PST) X-Google-Smtp-Source: APXvYqx4aU+2vC7j+YQcUvujicYXrDVnYxW5L0J957A48vE30okx9+Ubn4UeA4h/xfXFAuzvglIb X-Received: by 2002:a9d:3677:: with SMTP id w110mr3119606otb.139.1576177929058; Thu, 12 Dec 2019 11:12:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576177929; cv=none; d=google.com; s=arc-20160816; b=oYDRj7sGi6HBNEmInfbrY9Oh2V6q9c0xCGOrsJt7gipLPM4KbKJsW21WUacVJT5Rtr Cj2HBQW9uoptgLfRSAc4AvPfldher2zSMUkGuc/iB7d4wspatujBJjYCAAmuFy5bgi9Y QgYz4BM7J8p1/9j3IbrvWwvZjRLS97DB6xpAhhJNuR97CFmnrSPYLmUIQLl1k+ZIP6ti sRe12UL5el2KIk9inn+hE773UVo5J1LBilt01srf7kOrMuZcQjbHh8U8FRzB++zGBhvg GKdO9dqhx1DX2+MG0qvscKLC7RQu0ZcEPYca84z+q0jFYlL6bB6Ghe8JxZwm/1zsVl2L 4PMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date; bh=K6geOGpTVU5Rhp/JFQ+8fLcqeRKPKs+rbEJnNerKvDM=; b=QXSwoaBM9ig2zzcd8CnbzjyEShAKWgZADH7axKNC0/qqxR7T2goLzy031EN8qMmRIx 5t0jBE71VvJe2XIK0l1q/y7CTVXRv8wZ/Khjt1UvaoggAwGYADZfRSxRg9JAaPXRHnJE C1MN3VwJLZdzODoG7q2bn9kMcUZcuRQXbZILk/ClbMOqwLd1yPBNvVhV4Ghg1zJfd9pJ cBAWDNCLbBgvX1GBzIRqILfjRG7dHsVccNt5sw1Ot19nion0eTuxdjOJkDMhYdENO4LO MI3Kx5K0xPTf5GSap0gem82x6UBeWAQGArI0eriG5/lH+0tdTxyD4Jmr9Z95MROwZnEq x+/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q6si3625137oti.173.2019.12.12.11.11.55; Thu, 12 Dec 2019 11:12:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730618AbfLLTK5 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 12 Dec 2019 14:10:57 -0500 Received: from mx2.suse.de ([195.135.220.15]:55346 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730355AbfLLTK4 (ORCPT ); Thu, 12 Dec 2019 14:10:56 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C6396B182; Thu, 12 Dec 2019 19:10:53 +0000 (UTC) Date: Thu, 12 Dec 2019 11:04:27 -0800 From: Davidlohr Bueso To: Andrew Morton Cc: Mike Kravetz , Waiman Long , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , aneesh.kumar@linux.ibm.com Subject: [PATCH v2] mm/hugetlb: defer free_huge_page() to a workqueue Message-ID: <20191212190427.ouyohviijf5inhur@linux-p48b> Mail-Followup-To: Andrew Morton , Mike Kravetz , Waiman Long , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , aneesh.kumar@linux.ibm.com References: <20191211194615.18502-1-longman@redhat.com> <4fbc39a9-2c9c-4c2c-2b13-a548afe6083c@oracle.com> <32d2d4f2-83b9-2e40-05e2-71cd07e01b80@redhat.com> <0fcce71f-bc20-0ea3-b075-46592c8d533d@oracle.com> <20191212060650.ftqq27ftutxpc5hq@linux-p48b> <20191212063050.ufrpij6s6jkv7g7j@linux-p48b> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <20191212063050.ufrpij6s6jkv7g7j@linux-p48b> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There have been deadlock reports[1, 2] where put_page is called from softirq context and this causes trouble with the hugetlb_lock, as well as potentially the subpool lock. For such an unlikely scenario, lets not add irq dancing overhead to the lock+unlock operations, which could incur in expensive instruction dependencies, particularly when considering hard-irq safety. For example PUSHF+POPF on x86. Instead, just use a workqueue and do the free_huge_page() in regular task context. [1] https://lore.kernel.org/lkml/20191211194615.18502-1-longman@redhat.com/ [2] https://lore.kernel.org/lkml/20180905112341.21355-1-aneesh.kumar@linux.ibm.com/ Reported-by: Waiman Long Reported-by: Aneesh Kumar K.V Signed-off-by: Davidlohr Bueso --- - Changes from v1: Only use wq when in_interrupt(), otherwise business as usual. Also include the proper header file. - While I have not reproduced this issue, the v1 using wq passes all hugetlb related tests in ltp. mm/hugetlb.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ac65bb5e38ac..f28cf601938d 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -1136,7 +1137,13 @@ static inline void ClearPageHugeTemporary(struct page *page) page[2].mapping = NULL; } -void free_huge_page(struct page *page) +static struct workqueue_struct *hugetlb_free_page_wq; +struct hugetlb_free_page_work { + struct page *page; + struct work_struct work; +}; + +static void __free_huge_page(struct page *page) { /* * Can't pass hstate in here because it is called from the @@ -1199,6 +1206,36 @@ void free_huge_page(struct page *page) spin_unlock(&hugetlb_lock); } +static void free_huge_page_workfn(struct work_struct *work) +{ + struct page *page; + + page = container_of(work, struct hugetlb_free_page_work, work)->page; + __free_huge_page(page); +} + +void free_huge_page(struct page *page) +{ + if (unlikely(in_interrupt())) { + /* + * While uncommon, free_huge_page() can be at least + * called from softirq context, defer freeing such + * that the hugetlb_lock and spool->lock need not have + * to deal with irq dances just for this. + */ + struct hugetlb_free_page_work work; + + work.page = page; + INIT_WORK_ONSTACK(&work.work, free_huge_page_workfn); + queue_work(hugetlb_free_page_wq, &work.work); + + /* wait until the huge page freeing is done */ + flush_work(&work.work); + destroy_work_on_stack(&work.work); + } else + __free_huge_page(page); +} + static void prep_new_huge_page(struct hstate *h, struct page *page, int nid) { INIT_LIST_HEAD(&page->lru); @@ -2816,6 +2853,12 @@ static int __init hugetlb_init(void) for (i = 0; i < num_fault_mutexes; i++) mutex_init(&hugetlb_fault_mutex_table[i]); + + hugetlb_free_page_wq = alloc_workqueue("hugetlb_free_page_wq", + WQ_MEM_RECLAIM, 0); + if (!hugetlb_free_page_wq) + return -ENOMEM; + return 0; } subsys_initcall(hugetlb_init); -- 2.16.4