Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp445773ybl; Wed, 11 Dec 2019 22:14:12 -0800 (PST) X-Google-Smtp-Source: APXvYqzlKrKH88osg/P5X4JOLkJhzvC1+HmLtmfASxtJDlNRR4QK3TT6cWeC3V4bQcVYizBHGqou X-Received: by 2002:a9d:32e:: with SMTP id 43mr6270302otv.301.1576131252229; Wed, 11 Dec 2019 22:14:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576131252; cv=none; d=google.com; s=arc-20160816; b=qkp9OdqrOmtmXzPljRJnX9P8aLeGGQEilxDqH0thSRzW6pAKd8uTxPm7XsG9/Jrp08 k7kk+666vPIXqNRW2+pspdi01wDternF41uEGDSHpJU63G0LWmCQiGxYFEqznPoiIPw7 q/739rsXGnfzbDP3akHV+n/DlLPf+OL9hbZFIsBon+x4NrG2s/3zbBc37x/8R5znP81j U3eHd3b578K3Fxs13O60yHnaDiJqRU4tkpFEDzta5tU7woQ1fQ5YoH3q9RsacIfwK63D 9TgZCYT2aUIelricBSG3ywYF52jtRu8fJ9cDhOeXgscp0/XhID+JLt7uEJ5P0ecjanij AXfQ== 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=PpWVIHXeUqN+wmSJewauU7+NvRqq81fIqtGwXn/X3GI=; b=0Roc9ecA3gXdKLFkpqus7SpgOYGjqwKq4+Gh/ilxeQHY9F7sslfSFaQbJE/zUPWfKc +GQaS7KBINCvJTLmxvgj4eb5NXjtXdupuQybpLYmNwWTsODixu/6kh9MyCS7P0PC9m05 oGWt7hyFCvCmLou5fTVBgK9XI22dJg4V82umbCExN2zGb4s5Cpm7+xl8hR+86tUJFpP2 OZGBDsfE161oArMWAVHsJJjnuus0gecCApQeKey3FIJrABNRL+5hnoPG9ebItSFWuVKO Uvb8kZZhcXtjFrqkP5ORdGBumVBQcGaqWmzS8wnI4p3lL1jwEDYxxUclaQx+wwjg0PGH 92gg== 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 o128si2550843oih.66.2019.12.11.22.13.59; Wed, 11 Dec 2019 22:14:12 -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 S1727900AbfLLGNT convert rfc822-to-8bit (ORCPT + 99 others); Thu, 12 Dec 2019 01:13:19 -0500 Received: from mx2.suse.de ([195.135.220.15]:35182 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726784AbfLLGNS (ORCPT ); Thu, 12 Dec 2019 01:13:18 -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 D00DEB2E3; Thu, 12 Dec 2019 06:13:16 +0000 (UTC) Date: Wed, 11 Dec 2019 22:06:50 -0800 From: Davidlohr Bueso To: Mike Kravetz Cc: Waiman Long , Matthew Wilcox , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko Subject: Re: [PATCH v2] hugetlbfs: Disable softIRQ when taking hugetlb_lock Message-ID: <20191212060650.ftqq27ftutxpc5hq@linux-p48b> Mail-Followup-To: Mike Kravetz , Waiman Long , Matthew Wilcox , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <0fcce71f-bc20-0ea3-b075-46592c8d533d@oracle.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 11 Dec 2019, Mike Kravetz wrote: >The workqueue approach would address both soft and hard irq context issues. >As a result, I too think this is the approach we should explore. Since there >is more than one lock involved, this also is reason for a work queue approach. > >I'll take a look at initial workqueue implementation. However, I have not >dealt with workqueues in some time so it may take few days to evaluate. I'm thinking of something like the following; it at least passes all ltp hugetlb related testcases. Thanks, Davidlohr ----8<------------------------------------------------------------------ [PATCH] mm/hugetlb: defer free_huge_page() to a workqueue 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/ Signed-off-by: Davidlohr Bueso --- mm/hugetlb.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ac65bb5e38ac..737108d8d637 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1136,8 +1136,17 @@ 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_workfn(struct work_struct *work) { + struct page *page = container_of(work, + struct hugetlb_free_page_work, + work)->page; /* * Can't pass hstate in here because it is called from the * compound page destructor. @@ -1197,6 +1206,27 @@ void free_huge_page(struct page *page) enqueue_huge_page(h, page); } spin_unlock(&hugetlb_lock); + +} + +/* + * While unlikely, 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. + */ +void free_huge_page(struct page *page) +{ + 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 free_huge_page is done. + */ + flush_work(&work.work); + destroy_work_on_stack(&work.work); } static void prep_new_huge_page(struct hstate *h, struct page *page, int nid) @@ -2816,6 +2846,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