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.5 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 4BA97C49ED6 for ; Wed, 11 Sep 2019 16:34:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 074602085B for ; Wed, 11 Sep 2019 16:34:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 074602085B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8CF036B0007; Wed, 11 Sep 2019 12:34:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87EBD6B0008; Wed, 11 Sep 2019 12:34:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 747046B000C; Wed, 11 Sep 2019 12:34:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id 4F6876B0007 for ; Wed, 11 Sep 2019 12:34:44 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id BBFB81B65F for ; Wed, 11 Sep 2019 16:34:43 +0000 (UTC) X-FDA: 75923188446.21.ants62_636f8021d701c X-HE-Tag: ants62_636f8021d701c X-Filterd-Recvd-Size: 5720 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Sep 2019 16:34:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C20FC8A218D; Wed, 11 Sep 2019 16:34:41 +0000 (UTC) Received: from llong.remote.csb (ovpn-123-234.rdu2.redhat.com [10.10.123.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80D705C207; Wed, 11 Sep 2019 16:34:38 +0000 (UTC) Subject: Re: [PATCH 5/5] hugetlbfs: Limit wait time when trying to share huge PMD To: Qian Cai Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , Alexander Viro , Mike Kravetz , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Davidlohr Bueso References: <20190911150537.19527-1-longman@redhat.com> <20190911150537.19527-6-longman@redhat.com> From: Waiman Long Organization: Red Hat Message-ID: <1a8e6c0a-6ba6-d71f-974e-f8a9c623c25b@redhat.com> Date: Wed, 11 Sep 2019 17:34:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Wed, 11 Sep 2019 16:34:41 +0000 (UTC) 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 9/11/19 5:01 PM, Qian Cai wrote: > >> On Sep 11, 2019, at 11:05 AM, Waiman Long wrote: >> >> When allocating a large amount of static hugepages (~500-1500GB) on a >> system with large number of CPUs (4, 8 or even 16 sockets), performance >> degradation (random multi-second delays) was observed when thousands >> of processes are trying to fault in the data into the huge pages. The >> likelihood of the delay increases with the number of sockets and hence >> the CPUs a system has. This only happens in the initial setup phase >> and will be gone after all the necessary data are faulted in. >> >> These random delays, however, are deemed unacceptable. The cause of >> that delay is the long wait time in acquiring the mmap_sem when trying >> to share the huge PMDs. >> >> To remove the unacceptable delays, we have to limit the amount of wait >> time on the mmap_sem. So the new down_write_timedlock() function is >> used to acquire the write lock on the mmap_sem with a timeout value of >> 10ms which should not cause a perceivable delay. If timeout happens, >> the task will abandon its effort to share the PMD and allocate its own >> copy instead. >> >> When too many timeouts happens (threshold currently set at 256), the >> system may be too large for PMD sharing to be useful without undue delay. >> So the sharing will be disabled in this case. >> >> Signed-off-by: Waiman Long >> --- >> include/linux/fs.h | 7 +++++++ >> mm/hugetlb.c | 24 +++++++++++++++++++++--- >> 2 files changed, 28 insertions(+), 3 deletions(-) >> >> diff --git a/include/linux/fs.h b/include/linux/fs.h >> index 997a530ff4e9..e9d3ad465a6b 100644 >> --- a/include/linux/fs.h >> +++ b/include/linux/fs.h >> @@ -40,6 +40,7 @@ >> #include >> #include >> #include >> +#include >> >> #include >> #include >> @@ -519,6 +520,12 @@ static inline void i_mmap_lock_write(struct address_space *mapping) >> down_write(&mapping->i_mmap_rwsem); >> } >> >> +static inline bool i_mmap_timedlock_write(struct address_space *mapping, >> + ktime_t timeout) >> +{ >> + return down_write_timedlock(&mapping->i_mmap_rwsem, timeout); >> +} >> + >> static inline void i_mmap_unlock_write(struct address_space *mapping) >> { >> up_write(&mapping->i_mmap_rwsem); >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >> index 6d7296dd11b8..445af661ae29 100644 >> --- a/mm/hugetlb.c >> +++ b/mm/hugetlb.c >> @@ -4750,6 +4750,8 @@ void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma, >> } >> } >> >> +#define PMD_SHARE_DISABLE_THRESHOLD (1 << 8) >> + >> /* >> * Search for a shareable pmd page for hugetlb. In any case calls pmd_alloc() >> * and returns the corresponding pte. While this is not necessary for the >> @@ -4770,11 +4772,24 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) >> pte_t *spte = NULL; >> pte_t *pte; >> spinlock_t *ptl; >> + static atomic_t timeout_cnt; >> >> - if (!vma_shareable(vma, addr)) >> - return (pte_t *)pmd_alloc(mm, pud, addr); >> + /* >> + * Don't share if it is not sharable or locking attempt timed out >> + * after 10ms. After 256 timeouts, PMD sharing will be permanently >> + * disabled as it is just too slow. > It looks like this kind of policy interacts with kernel debug options like KASAN (which is going to slow the system down > anyway) could introduce tricky issues due to different timings on a debug kernel. With respect to lockdep, down_write_timedlock() works like a trylock. So a lot of checking will be skipped. Also the lockdep code won't be run until the lock is acquired. So its execution time has no effect on the timeout. Cheers, Longman