Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1920937pxk; Tue, 1 Sep 2020 10:53:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpst5WOnh8sSc9vVf09IyowR8V/xyyqNxc5WSTNZn0klcXpWZ6k/PrFg3zRMQUBpPwSU2s X-Received: by 2002:a17:906:80d3:: with SMTP id a19mr2775180ejx.217.1598982789782; Tue, 01 Sep 2020 10:53:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598982789; cv=none; d=google.com; s=arc-20160816; b=OQTzM9KHoN8oO7YxerPzeYA+5byqmdVwwZUQjev+I6kz9Oh47r5BRfAFLNT7liv9Jr P/gzHlOCYZjWp/E7nlPk2M8aRtffYvwq3V5tZNV2vkDEqFD8U8NWEOtzLT7QQ6v4q103 hgC4R55mxHutie/hb3LAexKloHrzimKsdtQpcktczfBz8FXyS65xgm6RHe5GzKSe4rP4 ADQ0HQ+qFgV4SdtSiR5NaIvWqY89cXIG8WmG2S+wg8/LsdcKgCE1atExkUnt/ye/1UGZ 05OBcoWV+F5k7zUtxYdARYUJE/nXkioa6SN4O4v2etthwMQ+spdLwJ07DJjvWlggj8Dx sEiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=LM/90lickBJaNMACbOvycyEGn6a9FzKJ0U/uO72EduU=; b=WarkNCmc96qQbjpAFCen3BsIhwkOn6QbLSvFcj/DWe2jhYM5UB76mcXByDM90sPHG9 woRJpItrcPgsRq8Qi5v0GX+i0E6eirBj8nGs9HaEkF9fbxfLiv3Cx9sHKFtd+qu0tWEW TVCX0UvwzgnpfwuLpnUe1HqgzPi/GX/FE4seVLR6CxalURWx9SiWIPN1LGBOFvXACy/X B8uK4CbW2dBRUGmRSYvLtLmsjEMjlIo3Sto1jKMwSo75bLJUy8r4ARJTUUhSRF4GlZAs DLaaVakTpsfpLjme7xD2jAzGSpqvcoFNqsytLDa0EBxbcJ8QjbyysrZKF39CufK9Iu9/ 2cJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hju9hXEy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i7si986633edg.600.2020.09.01.10.52.46; Tue, 01 Sep 2020 10:53:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hju9hXEy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728258AbgIARwE (ORCPT + 99 others); Tue, 1 Sep 2020 13:52:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726928AbgIARwB (ORCPT ); Tue, 1 Sep 2020 13:52:01 -0400 Received: from mail-ua1-x941.google.com (mail-ua1-x941.google.com [IPv6:2607:f8b0:4864:20::941]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D63EC061245 for ; Tue, 1 Sep 2020 10:52:01 -0700 (PDT) Received: by mail-ua1-x941.google.com with SMTP id v20so701257ual.4 for ; Tue, 01 Sep 2020 10:52:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=LM/90lickBJaNMACbOvycyEGn6a9FzKJ0U/uO72EduU=; b=hju9hXEyZJ9W7EcArFXRkj//GhdBJx9t9WVyBsS5qVUMOPxI0SZi60FdZXd9DNc3/C S273aVy9mrHuTApmUBWlWClB5O1A52+eO4vMMVNKleLtw+3LtnOSi1YNNS56WBHf3VYe QDLb3WmoD2qGaP6w2RMuhDS75IjOokRPl9kWzfiKW2LoVixLj52+4FtQDVBupYZw3rp+ tctiPNIlTvR1Y+MbRfmljBqzIEFH/K0tjpopvEbxUiWQq1Fyw0dCDOEwp5hKgYfW8aPy qUc22zx7ZSF3D4RlmvRYnFUgbqPz0l9KEmQoOSD7Ol59hMYh9qdzbEtk6EmTxiEnKoNa L4nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=LM/90lickBJaNMACbOvycyEGn6a9FzKJ0U/uO72EduU=; b=B74UXjvJNxb8tGQQO9mw1xYGojKkYFSbHFBIsrOYi1fwj0Dch4Xd9pN/h+crs47BkK Fjb+EzFOT5VJi0h9qNupV9dasZZmZkUmdkXOXFMD0S/v0mG0f5yCRSJMeBP/vSg+ZARL REJZs/tE71j23CjzrWo1HWvwVR3nvxAsbdW9duP/JCNbQHX6P2zhyr4A7k7jPv05/Y6O uYwI5GKzrIrTfSAJTvdeuepa16RSIf3jLnvRXU4eOPcjV5OQ6rDGw5GEzhPCbjyxVKYb hGKgYEa1AkyRi+KXwIGvqfoIc7vAmQGc3FpOqI1bQYSyiSmPOioBk8PK1aaXFwHPeQ88 P2oQ== X-Gm-Message-State: AOAM532vGag8wu1xfUrQ2b+gZ5GpJpC5v+fBF9fiC6Umh+2ncWVFmvws mLxsTeBCMsJDLs2Go5XHhgmZSw== X-Received: by 2002:ab0:754d:: with SMTP id k13mr2444657uaq.75.1598982720150; Tue, 01 Sep 2020 10:52:00 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 67sm242644vsl.13.2020.09.01.10.51.57 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Tue, 01 Sep 2020 10:51:59 -0700 (PDT) Date: Tue, 1 Sep 2020 10:51:55 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: "Maoming (maoming, Cloud Infrastructure Service Product Dept.)" cc: Hugh Dickins , Matthew Wilcox , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "alex.williamson@redhat.com" , "cohuck@redhat.com" , "Zhoujian (jay)" , "Huangweidong (C)" , "peterx@redhat.com" , "aarcange@redhat.com" , wangyunjian Subject: =?UTF-8?Q?Re=3A_=E7=AD=94=E5=A4=8D=3A_=5BPATCH_V3=5D_vfio_dma=5Fmap=2Funmap=3A_optimized_for_hugetlbfs_pages?= In-Reply-To: <8B561EC9A4D13649A62CF60D3A8E8CB28C2DC466@dggeml524-mbx.china.huawei.com> Message-ID: References: <20200828092649.853-1-maoming.maoming@huawei.com> <8B561EC9A4D13649A62CF60D3A8E8CB28C2DC466@dggeml524-mbx.china.huawei.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 1 Sep 2020, Maoming (maoming, Cloud Infrastructure Service Product Dept.) wrote: > > > > > In the original process of dma_map/unmap pages for VFIO-devices, to > > > make sure the pages are contiguous, we have to check them one by one. > > > As a result, dma_map/unmap could spend a long time. > > > Using the hugetlb pages, we can avoid this problem. > > > All pages in hugetlb pages are contiguous.And the hugetlb page should > > > not be split.So we can delete the for loops. > > > > I know nothing about VFIO, but I'm surprised that you're paying such attention > > to PageHuge hugetlbfs pages, rather than to PageCompound > > pages: which would also include Transparent Huge Pages, of the traditional > > anonymous kind, or the huge tmpfs kind, or the more general (not necessarily > > pmd-sized) kind that Matthew Wilcox is currently working on. > > > > It's true that hugetlbfs is peculiar enough that whatever you write for it may > > need some tweaks to cover the THP case too, or vice versa; but wouldn't your > > patch be a lot better for covering all cases? > > > > You mention above that "the hugetlb page should not be split": > > perhaps you have been worried that a THP could be split beneath you? > > That used to be a possibility some years ago, but nowadays a THP cannot be > > split while anyone is pinning it with an extra reference. > > > > Hugh > > > > > Thanks for your suggestions. > You mention that a THP cannot be split while anyone is pinning it. > Do you mean the check of can_split_huge_page()(in split_huge_page_to_list())? Partly, yes: but that's just a racy check to avoid doing wasted work in common cases; the more important check comes later in page_ref_freeze(), which either fails, or prevents anyone else taking a new reference to the THP (head or tails) while all the work on splitting is being done. > When we want to pin pages, vfio_pin_pages_remote() always gets a normal page first. > In this case, a THP cannot be split because of the increased reference. > Is this right? Yes. > > Maybe I can optimize for hugetlb pages as a first step, > and then cover all compound pages. Okay. That's definitely a good way to start out - but you may find that the second step leads you to rewrite every line you wrote before! Hugh