Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3820606pxk; Tue, 22 Sep 2020 03:35:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTmwUIRc7vWn/zIuu8DHZ6bcalNt/dMnKbxbhgnyFgj7fip7iOen6T3+5/J/fSSzlhAeqV X-Received: by 2002:a50:f69a:: with SMTP id d26mr3096229edn.21.1600770914117; Tue, 22 Sep 2020 03:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600770914; cv=none; d=google.com; s=arc-20160816; b=pH4hXpJ049R9g/ECDvEQrqeQK3GSXQpx6qsx7db0Sbdpv3Dnzy3KeeJEL1KBw1//Qx vCHpQUqPVmj2A5E2Ve43mZ3zUskSfUdVupvYpJo56Do8i4dZBHGDfN8dioTEYJFviGkP nbziXaGJ11xDILZUgUMx5RjA+HRJFDMZveqDrTtezL0vieuO0JG8czKyA2pAwziY7DzJ 1iQVPQT8b2jfk2BqJiKRxLNS1c9h8pyig6suaPajT3X6I/JVJcnVC1oblZiCmQuL95Xn TEmbw7h2d7KDs3Ma4SyXZAChpUOMRRcDgGSRjqDx2bgFcfJAr8A90hq5vzrVtrbwPFrZ 4XrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=RN5p78cAKGJnEBEf+QoUkDMn55B2P7eNBNv58r3t6F8=; b=jZ9ls5KzOtMZG+CA6mkZwJDa5NFTq6QMyYxAhY/+iV70YSb0k3zR8QSHf/c73pfGLp 6bwrY2r0+JvfKJfK3MZLq+CxUWR48gghpYbitcQDuhYVi+WN6/EOazra1n98W803Fj8l Ftbg9vleqSEySASifs3ikbJZap2mNFX83dUux4AoO00q9bWOuSyTCjYTO4WI43gJEHxy P1fQ8DGpDQpLGm4vqq3eCWPlKxln4m3QJw+Tcf2SdzOnAyY24e3Ozdt1kOWt+k8JMe74 ZcQPdN3MlmQq6/4c8qxT/U2UA3A0e6aphkPg6s2FU/JQ0Z2VE6acwE4I9hsJ6uq3RrUi n7sA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rn21si5395815ejb.69.2020.09.22.03.34.50; Tue, 22 Sep 2020 03:35:14 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726494AbgIVKdS (ORCPT + 99 others); Tue, 22 Sep 2020 06:33:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:54308 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726454AbgIVKdS (ORCPT ); Tue, 22 Sep 2020 06:33:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B32F2B226; Tue, 22 Sep 2020 10:33:52 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id A8F771E12E3; Tue, 22 Sep 2020 12:33:15 +0200 (CEST) Date: Tue, 22 Sep 2020 12:33:15 +0200 From: Jan Kara To: John Hubbard Cc: Peter Xu , 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: <20200922103315.GD15112@quack2.suse.cz> References: <20200921211744.24758-1-peterx@redhat.com> <20200921212031.25233-1-peterx@redhat.com> <5e594e71-537f-3e9f-85b6-034b7f5fedbe@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5e594e71-537f-3e9f-85b6-034b7f5fedbe@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 21-09-20 23:41:16, 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))) { > > This condition would make a good static inline function. It's used in 3 > places, and the condition is quite special and worth documenting, and > having a separate function helps with that, because the function name > adds to the story. I'd suggest approximately: > > page_likely_dma_pinned() > > for the name. Well, but we should also capture that this really only works for anonymous pages. For file pages mm->has_pinned does not work because the page may be still pinned by completely unrelated process as Jann already properly pointed out earlier in the thread. So maybe anon_page_likely_pinned()? Possibly also assert PageAnon(page) in it if we want to be paranoid... Honza -- Jan Kara SUSE Labs, CR