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.1 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=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 6D34CC4727F for ; Wed, 23 Sep 2020 16:12:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CBCDC20936 for ; Wed, 23 Sep 2020 16:12:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EysOPTdU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBCDC20936 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 45F446B0070; Wed, 23 Sep 2020 12:12:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F3576B0071; Wed, 23 Sep 2020 12:12:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AFCB6B0072; Wed, 23 Sep 2020 12:12:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 10F476B0070 for ; Wed, 23 Sep 2020 12:12:36 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id BD09C84CD4A2 for ; Wed, 23 Sep 2020 16:12:35 +0000 (UTC) X-FDA: 77294819070.04.paper16_370b32a27157 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 6AB638032BF8 for ; Wed, 23 Sep 2020 16:06:42 +0000 (UTC) X-HE-Tag: paper16_370b32a27157 X-Filterd-Recvd-Size: 5642 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Sep 2020 16:06:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600877201; 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=g9MGzjQTQMPnRUsSx/lmVQbkvLVRsS27fhyulwST0XU=; b=EysOPTdUMgZ7Oc1JtW0AtnBMXHRO6LDfO7ERdiaqH7Isd5shbj1DJJCZM+vCvepbjeXp9E Tb/O7hsLvqfecd//A6Tz+kvIwREtwBRZedSvOuevYaSjuezdvXtVY0P/j+DFgP9crVEmWZ 9rbiPNPDdtovRQqM2QgB/wiSzw62cOE= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-370--4scmRh6Oeek2CVrKy4RsA-1; Wed, 23 Sep 2020 12:06:37 -0400 X-MC-Unique: -4scmRh6Oeek2CVrKy4RsA-1 Received: by mail-qv1-f72.google.com with SMTP id f21so353010qve.9 for ; Wed, 23 Sep 2020 09:06:37 -0700 (PDT) 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=g9MGzjQTQMPnRUsSx/lmVQbkvLVRsS27fhyulwST0XU=; b=qHKOa8KLjqFB9+b2FM2+VDrB8ywRSXShydUfwbtV3mLw8+HhrdAJc8Vpy0x4Amholj HXE5tQN2p+llnPhLuwRha50RHxixN7qRqShcGuEiRoBZdFBq+gLspXhWOT4RGXK+Clrh pSRVLP0aEDCvhj9dE41b1JC0UV9GH1ihQlZE+gKqf4J87PhIxc0YxLNMWd+VK0ZAgsb6 C31GJc94bOm/Gy5DFFDCRQYje0SpOB0doeYFi9tJTklDkogc+7ntIQOGEY10pCaacdmU 3PidtoIRjh/v7xuG3tx9UmayWzgGBO/CHEZTdnEBJvSAuZBAEY0crdXRbCdFrWKez8XI 84tA== X-Gm-Message-State: AOAM532PIGBPdWf9dSmquKKRWpx/rCuLN00Cw4DrVhCEdE2bA023uO0L 3V/gMoa4OLldyWXr5S8q0q555NBh6jY+r6MTAwFvWLXSTQHkcCCTS9S9j2S7CXcKCLSKHiT7u+m 9RBPLrQYrr1s= X-Received: by 2002:a37:6786:: with SMTP id b128mr597725qkc.396.1600877196925; Wed, 23 Sep 2020 09:06:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMhpSDZv71ipNi3jgBBqCnCadJV34DOqLzVrH9WYRv604yXJamPJEKzMb/swh825Lz8wGJVw== X-Received: by 2002:a37:6786:: with SMTP id b128mr597698qkc.396.1600877196646; Wed, 23 Sep 2020 09:06:36 -0700 (PDT) Received: from xz-x1 (bras-vprn-toroon474qw-lp130-11-70-53-122-15.dsl.bell.ca. [70.53.122.15]) by smtp.gmail.com with ESMTPSA id e13sm108882qtr.85.2020.09.23.09.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2020 09:06:35 -0700 (PDT) Date: Wed, 23 Sep 2020 12:06:34 -0400 From: Peter Xu To: John Hubbard Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Linus Torvalds , Michal Hocko , Kirill Shutemov , Jann Horn , Oleg Nesterov , Kirill Tkhai , Hugh Dickins , Leon Romanovsky , Jan Kara , Christoph Hellwig , Andrew Morton , Jason Gunthorpe , Andrea Arcangeli Subject: Re: [PATCH 5/5] mm/thp: Split huge pmds/puds if they're pinned when fork() Message-ID: <20200923160634.GB79898@xz-x1> References: <20200921211744.24758-1-peterx@redhat.com> <20200921212031.25233-1-peterx@redhat.com> <5e594e71-537f-3e9f-85b6-034b7f5fedbe@nvidia.com> MIME-Version: 1.0 In-Reply-To: <5e594e71-537f-3e9f-85b6-034b7f5fedbe@nvidia.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 Mon, Sep 21, 2020 at 11:41:16PM -0700, John Hubbard wrote: > On 9/21/20 2:20 PM, Peter Xu wrote: > ... > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index 7ff29cc3d55c..c40aac0ad87e 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -1074,6 +1074,23 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, > > src_page = pmd_page(pmd); > > VM_BUG_ON_PAGE(!PageHead(src_page), src_page); > > + > > + /* > > + * If this page is a potentially pinned page, split and retry the fault > > + * with smaller page size. Normally this should not happen because the > > + * userspace should use MADV_DONTFORK upon pinned regions. This is a > > + * best effort that the pinned pages won't be replaced by another > > + * random page during the coming copy-on-write. > > + */ > > + if (unlikely(READ_ONCE(src_mm->has_pinned) && > > + page_maybe_dma_pinned(src_page))) { [...] > > + pte_free(dst_mm, pgtable); > > + spin_unlock(src_ptl); > > + spin_unlock(dst_ptl); > > + __split_huge_pmd(vma, src_pmd, addr, false, NULL); > > + return -EAGAIN; > > + } > > > Why wait until we are so deep into this routine to detect this and unwind? > It seems like if you could do a check near the beginning of this routine, and > handle it there, with less unwinding? In fact, after taking only the src_ptl, > the check could be made, right? Because that's where we've fetched the page from the pmd so I can directly reference src_page. Also I think at least I need to check against swp entries? So it seems still easier to keep it here, considering it's an unlikely path. Thanks, -- Peter Xu