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.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 C88C2C2D0E2 for ; Tue, 22 Sep 2020 10:33:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 18957239A1 for ; Tue, 22 Sep 2020 10:33:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18957239A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 43384900058; Tue, 22 Sep 2020 06:33:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BF1C900036; Tue, 22 Sep 2020 06:33:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AB22900058; Tue, 22 Sep 2020 06:33:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0194.hostedemail.com [216.40.44.194]) by kanga.kvack.org (Postfix) with ESMTP id 0E2B3900036 for ; Tue, 22 Sep 2020 06:33:18 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C3C283625 for ; Tue, 22 Sep 2020 10:33:17 +0000 (UTC) X-FDA: 77290335234.20.sink02_5e14cea2714d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id A03A5180C07AB for ; Tue, 22 Sep 2020 10:33:17 +0000 (UTC) X-HE-Tag: sink02_5e14cea2714d X-Filterd-Recvd-Size: 3351 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 10:33:17 +0000 (UTC) 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) 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 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