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=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 6BF63C433DB for ; Wed, 3 Feb 2021 22:30:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0B0D264E4D for ; Wed, 3 Feb 2021 22:30:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B0D264E4D 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 95E066B007B; Wed, 3 Feb 2021 17:30:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 90E378D0006; Wed, 3 Feb 2021 17:30:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FD138D0001; Wed, 3 Feb 2021 17:30:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id 694F66B007B for ; Wed, 3 Feb 2021 17:30:25 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 31B223633 for ; Wed, 3 Feb 2021 22:30:25 +0000 (UTC) X-FDA: 77778401610.24.arch62_34026f4275d7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 15E091A4A0 for ; Wed, 3 Feb 2021 22:30:25 +0000 (UTC) X-HE-Tag: arch62_34026f4275d7 X-Filterd-Recvd-Size: 5808 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Feb 2021 22:30:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612391423; 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: in-reply-to:in-reply-to:references:references; bh=nS4bwQpjG/2qNM4NYd+hfWbJiuPcAKvoaI0hut8n+YY=; b=iFB1T74pD8g2ugQwoO+RQ6/V63AYsmadylO69yATMR/xXq7GcP/ZAMx0JMYNDAtamKpMto Mj9oqS4ntVRgzkKUG/yf9DIrqdun4/WLyWv3aielH0OLvPZyyXnYkS2e/cw+UNr/fILEQ4 4MZQBK1yC1W4Ry8JN6qpnNq4VqJsjWs= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-ySUtvA7oOoyri-Rm9XgXww-1; Wed, 03 Feb 2021 17:30:20 -0500 X-MC-Unique: ySUtvA7oOoyri-Rm9XgXww-1 Received: by mail-qt1-f198.google.com with SMTP id v65so1087907qtd.0 for ; Wed, 03 Feb 2021 14:30:20 -0800 (PST) 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:message-id:references :mime-version:content-disposition:in-reply-to; bh=nS4bwQpjG/2qNM4NYd+hfWbJiuPcAKvoaI0hut8n+YY=; b=Av0ANTqrCF362uZCVe3ZUYuYWMDlPMPWyiwb5T63qJdsXrPVuCeKxsao1fp0Hz8PWb e535wnBRH7LHHPHhucz8t9nKe1koLPlN6kdzuedX+5G0gBKRQcWx8+Z3TdLvunn2aGEL g81bdNgLQbDJw5iSGx5XcGkKMW9qcH6ItguovmwImYSAihv86n3FgaMMFpfK9SOM/Fdi kxvRbpsSHabB+68D55AucAZV5CFtc7og4cLMKzkMALhhvc0cfVkC/tLug30bsmfgQfR9 BNd6pwqF0QTr1h5+bGdOGtW2+Owb1rRDiGmGNzrAznpYBbfM8rkYP0DeOMwkkLeNPxXL xS/w== X-Gm-Message-State: AOAM5319BgELLLs5zltr0onRSQzHiWISKTqFzZTqtH68qzl+fH3H/3hB KzItttTKobin6fAUG2UHiHxx/SMlnvvy/QkT4CGkuti0AHRtbVvMyZaMOXhSHqjod7xLbqVZ0/L 6ZCyam8rurEE= X-Received: by 2002:ad4:4e8c:: with SMTP id dy12mr5136397qvb.12.1612391419909; Wed, 03 Feb 2021 14:30:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwW62BAPMAnI9h3ciqdw6astnvPCbIY7pkEJ6Geu64NZ8XVFa6IvU6x4qbKXf20SwgSi4TiHw== X-Received: by 2002:ad4:4e8c:: with SMTP id dy12mr5136377qvb.12.1612391419707; Wed, 03 Feb 2021 14:30:19 -0800 (PST) Received: from xz-x1 (bras-vprn-toroon474qw-lp130-20-174-93-89-182.dsl.bell.ca. [174.93.89.182]) by smtp.gmail.com with ESMTPSA id c127sm3233607qkd.87.2021.02.03.14.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 14:30:19 -0800 (PST) Date: Wed, 3 Feb 2021 17:30:17 -0500 From: Peter Xu To: Mike Kravetz Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Wei Zhang , Matthew Wilcox , Linus Torvalds , Jason Gunthorpe , Gal Pressman , Christoph Hellwig , Andrea Arcangeli , Jan Kara , Kirill Shutemov , David Gibson , Mike Rapoport , Kirill Tkhai , Jann Horn , Andrew Morton Subject: Re: [PATCH 4/4] hugetlb: Do early cow when page pinned on src mm Message-ID: <20210203223017.GK6468@xz-x1> References: <20210203210832.113685-1-peterx@redhat.com> <20210203210832.113685-5-peterx@redhat.com> <2038a69e-8c2d-c959-4bdc-9d2ddf093061@oracle.com> MIME-Version: 1.0 In-Reply-To: <2038a69e-8c2d-c959-4bdc-9d2ddf093061@oracle.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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 Wed, Feb 03, 2021 at 02:04:30PM -0800, Mike Kravetz wrote: > > @@ -3816,6 +3832,54 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, > > } > > set_huge_swap_pte_at(dst, addr, dst_pte, entry, sz); > > } else { > > + entry = huge_ptep_get(src_pte); > > + ptepage = pte_page(entry); > > + get_page(ptepage); > > + > > + if (unlikely(page_needs_cow_for_dma(vma, ptepage))) { > > + /* This is very possibly a pinned huge page */ > > + if (!prealloc) { > > + /* > > + * Preallocate the huge page without > > + * tons of locks since we could sleep. > > + * Note: we can't use any reservation > > + * because the page will be exclusively > > + * owned by the child later. > > + */ > > + put_page(ptepage); > > + spin_unlock(src_ptl); > > + spin_unlock(dst_ptl); > > + prealloc = alloc_huge_page(vma, addr, 0); > > One quick question: > > The comment says we can't use any reservation, and I agree. However, the > alloc_huge_page call has 0 as the avoid_reserve argument. Shouldn't that > be !0 to avoid reserves? Good point.. so I obviously wanted to skip reservation check but successfully got cheated by the inverted name. :) Though I do checked the reservation, so it seems not extremely important - when we fork and copy the vma, we have already dropped the vma resv map: if (is_vm_hugetlb_page(tmp)) reset_vma_resv_huge_pages(tmp); Then in alloc_huge_page() we checked vma_resv_map() mostly everywhere we'd check avoid_reserve too (either in vma_needs_reservation, or calculating deferred_reserve). It seems to be mostly useful when vma_resv_map() existed. But I completely agree I should pass in "1" here in v2. Thanks, -- Peter Xu