Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1390382ybx; Thu, 7 Nov 2019 11:14:46 -0800 (PST) X-Google-Smtp-Source: APXvYqwQ7s9yeI78gU7RsbXYKw+a5d+6WuHGYyS+5Gm589O5Vk0IIQAbjlzxsYwPU/p8i7ute7Dv X-Received: by 2002:a17:906:3396:: with SMTP id v22mr4552444eja.169.1573154086003; Thu, 07 Nov 2019 11:14:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573154085; cv=none; d=google.com; s=arc-20160816; b=DgpU6FB7Hv3MJiiAWpU/nSA7x/Dui3Uq2tIU3E5DvSvx4fAE3NbvF9GPc2zSa9l4Y4 v7eDJj95dr3FkVpGur6xR4PJ3E/yLdjc5Q0PTWfFRvNjvFt8Khi86Me12jKqCZ2yDb9z CywLsWn++xDZVSNoAT4/AuzwJrfbsClLDe92pjBjl6cQp88oOaQFlVY8CfKZsS/yMZ+S lXNbSUIkUifx5ArmwKmW2C1i817V/qMNkv1UdpS0gLfvencugXjX680BEopasd6sMiWR hzbhWZN9XfGpHsxTQmQ/J8SzRcWjBaTpraO8WMJJlA2ZGZTMzE0jhEl12BqmsD99b4bX IacQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :dkim-signature; bh=HgNhIjZI4iddcLSwbahuDC1ASugf6AydFI8zhHAyaP8=; b=YTAf6rC2vFEXfiOU1Tbz3/rbSarSw4irjROTzADXyoJhdcgW6FqUBk8MU9xQjTLv7z yc0w8ac63JF6GJfjvyzDjY9O68cFY1fd92/4KNx5ynGeJpC5TIys9G+5wr1MGRTQOdDz 6YTiaSHnZnFd9TDoZkbfe98kiJxMLrJDsn8fJDFYZhAMhf9c7Kt6qsC/GeDCseiBkJL3 Ui4yTTUCm+1DP6QDAbRB7+iRfB5/BmIy4/AfzZgnCO0+kpj3jNJRiC7EqDdPYDbYPWkA Ubo2Plb/MT72qx0iL0FkLhvkgAHYHNGdHZduUrOt8/mEMpavMoaCOT2E7+8Y2cGmI+1y UQxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dCuEcUO4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q24si2074784ejr.128.2019.11.07.11.14.22; Thu, 07 Nov 2019 11:14:45 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dCuEcUO4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726917AbfKGTNw (ORCPT + 99 others); Thu, 7 Nov 2019 14:13:52 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:42710 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725851AbfKGTNw (ORCPT ); Thu, 7 Nov 2019 14:13:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573154030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HgNhIjZI4iddcLSwbahuDC1ASugf6AydFI8zhHAyaP8=; b=dCuEcUO4hNMa5G56Op7z1oxJTY6XLKG6olagqyNcoHQWiVEYUBLpjftKDuaLGO2+Hy2Gt+ VE94XiIOlwKJgmCFOPGfMgK2EbKrlqOUNAtegAEjal4RgUZbOez6xUllHcbj2ctbAVtGEo qCn+OTNdmeoja3WolkyDbhTmqRONYpE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-222-AMmkt8STMOuG5w0S6f0kqA-1; Thu, 07 Nov 2019 14:13:26 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 235F91800D7B; Thu, 7 Nov 2019 19:13:25 +0000 (UTC) Received: from llong.remote.csb (dhcp-17-59.bos.redhat.com [10.18.17.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B312600D3; Thu, 7 Nov 2019 19:13:24 +0000 (UTC) Subject: Re: [PATCH] hugetlbfs: Take read_lock on i_mmap for PMD sharing To: Mike Kravetz , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Davidlohr Bueso , Peter Zijlstra , Ingo Molnar , Will Deacon References: <20191107190628.22667-1-longman@redhat.com> From: Waiman Long Organization: Red Hat Message-ID: Date: Thu, 7 Nov 2019 14:13:23 -0500 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: <20191107190628.22667-1-longman@redhat.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: AMmkt8STMOuG5w0S6f0kqA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/7/19 2:06 PM, Waiman Long wrote: > A customer with large SMP systems (up to 16 sockets) with application > that uses large amount of static hugepages (~500-1500GB) are experiencing > random multisecond delays. These delays was caused by the long time it > took to scan the VMA interval tree with mmap_sem held. > > The sharing of huge PMD does not require changes to the i_mmap at all. > As a result, we can just take the read lock and let other threads > searching for the right VMA to share in parallel. Once the right > VMA is found, either the PMD lock (2M huge page for x86-64) or the > mm->page_table_lock will be acquired to perform the actual PMD sharing. > > Lock contention, if present, will happen in the spinlock. That is much > better than contention in the rwsem where the time needed to scan the > the interval tree is indeterminate. > > With this patch applied, the customer is seeing significant improvements > over the unpatched kernel. > > Signed-off-by: Waiman Long > --- > mm/hugetlb.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index b45a95363a84..087e7ff00137 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -4842,7 +4842,11 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsign= ed long addr, pud_t *pud) > =09if (!vma_shareable(vma, addr)) > =09=09return (pte_t *)pmd_alloc(mm, pud, addr); > =20 > -=09i_mmap_lock_write(mapping); > +=09/* > +=09 * PMD sharing does not require changes to i_mmap. So a read lock > +=09 * is enuogh. > +=09 */ > +=09i_mmap_lock_read(mapping); > =09vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) { > =09=09if (svma =3D=3D vma) > =09=09=09continue; > @@ -4872,7 +4876,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigne= d long addr, pud_t *pud) > =09spin_unlock(ptl); > out: > =09pte =3D (pte_t *)pmd_alloc(mm, pud, addr); > -=09i_mmap_unlock_write(mapping); > +=09i_mmap_unlock_read(mapping); > =09return pte; > } > =20 This is a follow-up of my previous patch to disable PMD sharing for large system. https://lore.kernel.org/lkml/20190911150537.19527-1-longman@redhat.com/ This patch is simpler and has lower risk while still solve the customer problem. It supersedes the previous patch. Cheers, Longman