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=-5.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 731A1C2D0A8 for ; Wed, 23 Sep 2020 16:06:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E6F3B206A2 for ; Wed, 23 Sep 2020 16:06:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bsh6usdI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6F3B206A2 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 1D6146B0070; Wed, 23 Sep 2020 12:06:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 186856B0071; Wed, 23 Sep 2020 12:06:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04E8A6B0072; Wed, 23 Sep 2020 12:06:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id E3A816B0070 for ; Wed, 23 Sep 2020 12:06:22 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 85C6E8522736 for ; Wed, 23 Sep 2020 16:06:22 +0000 (UTC) X-FDA: 77294803404.16.suit10_2d0fc4627157 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id B21E21051E654 for ; Wed, 23 Sep 2020 15:44:24 +0000 (UTC) X-HE-Tag: suit10_2d0fc4627157 X-Filterd-Recvd-Size: 8098 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Sep 2020 15:44:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600875863; 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=+DuC7lq68It6bf8N8+4h/Du8Hn8l1j2ilbaVQGr77aw=; b=bsh6usdItJw8SQFaKmDwLJGihXLQe4g5z6tjnRKWtS7grVyd5gR3CTGOchIFaSykVVcq8M BypFP1353U0JmWUnDwVfK7/QGGPBjcGxV1ghXCalOTvHa7sR+HLjpn3zSN9+aEkfxo4v2c 5R4/GEMDOdmGHL46Iy0bv7+qEMU05rA= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-107-1R0tKLDPPgOABqw47QXP7A-1; Wed, 23 Sep 2020 11:44:21 -0400 X-MC-Unique: 1R0tKLDPPgOABqw47QXP7A-1 Received: by mail-qk1-f197.google.com with SMTP id y17so17031731qky.0 for ; Wed, 23 Sep 2020 08:44:21 -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=+DuC7lq68It6bf8N8+4h/Du8Hn8l1j2ilbaVQGr77aw=; b=PgykjIfL4ZyzjeQUrYFVbmBZco4tRf7qPXR6N5spzmMgPI1TD+D4Ep1ZoKX7Wt+UVi GhYVQvJ+0B0AcpmENKJJrqUMe9O2yRQEthJjCMIoIWrWa7abUGZ18b290MDmC2g203zu n2JOk9XA0sK6YvTlYiu0aguwcd1i0CYMF1t72C9pDp/DoZWCCQD6m+ia6Awkw4oB4M9Y vcxk8YTq1KtB5ciaODxnE6h1Bo3Gzck4NGZpBnA/O0oNWag2RGHqNsoXMKRx5xB0FxC1 D3rupuLE2wNsteJf/YujLOqQWGLgZTlkAyDKV1xb2K0pYnv7gFxtYkApz46dX5zf1qpX Gm1w== X-Gm-Message-State: AOAM530K4YXFJ+0xlm3TDxpsuktDIJIhb61Dcf8tzpFAM5jTQEUDRCvU q4vtqzbw7TpXo6RxxXlsszD6IzdtWf4vbNXBSnMqbCpKdaPHfaxJVJtNpOUnLIIzYL97LMSEGUM 8m7mCFrQQKic= X-Received: by 2002:ac8:5d14:: with SMTP id f20mr704332qtx.104.1600875861203; Wed, 23 Sep 2020 08:44:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEEQs77/sk/rd1u/Y6BbPbkBwZIyOk8AtTRRxaLQbazk8HtifvBJqlo82hUU4l21aLDgrX2Q== X-Received: by 2002:ac8:5d14:: with SMTP id f20mr704299qtx.104.1600875860896; Wed, 23 Sep 2020 08:44:20 -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 f64sm199019qkj.124.2020.09.23.08.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2020 08:44:20 -0700 (PDT) Date: Wed, 23 Sep 2020 11:44:18 -0400 From: Peter Xu To: Jan Kara Cc: John Hubbard , 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 , 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: <20200923154418.GE59978@xz-x1> References: <20200921211744.24758-1-peterx@redhat.com> <20200921212031.25233-1-peterx@redhat.com> <5e594e71-537f-3e9f-85b6-034b7f5fedbe@nvidia.com> <20200922103315.GD15112@quack2.suse.cz> <4a65586e-9282-beb0-1880-1ef8da03727c@nvidia.com> <20200923092205.GA6719@quack2.suse.cz> <20200923135004.GB59978@xz-x1> <20200923140114.GA15875@quack2.suse.cz> MIME-Version: 1.0 In-Reply-To: <20200923140114.GA15875@quack2.suse.cz> 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, Sep 23, 2020 at 04:01:14PM +0200, Jan Kara wrote: > On Wed 23-09-20 09:50:04, Peter Xu wrote: > > On Wed, Sep 23, 2020 at 11:22:05AM +0200, Jan Kara wrote: > > > On Tue 22-09-20 13:01:13, John Hubbard wrote: > > > > On 9/22/20 3:33 AM, Jan Kara wrote: > > > > > On Mon 21-09-20 23:41:16, John Hubbard wrote: > > > > > > On 9/21/20 2:20 PM, Peter Xu wrote: > > > > > > ... > > > > > > > + 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 > > > > > > > > The file-backed case doesn't really change anything, though: > > > > page_maybe_dma_pinned() is already a "fuzzy yes" in the same sense: you > > > > can get a false positive. Just like here, with an mm->has_pinned that > > > > could be a false positive for a process. > > > > > > > > And for that reason, I'm also not sure an "assert PageAnon(page)" is > > > > desirable. That assertion would prevent file-backed callers from being > > > > able to call a function that provides a fuzzy answer, but I don't see > > > > why you'd want or need to do that. The goal here is to make the fuzzy > > > > answer a little bit more definite, but it's not "broken" just because > > > > the result is still fuzzy, right? > > > > > > > > Apologies if I'm missing a huge point here... :) > > > > > > But the problem is that if you apply mm->has_pinned check on file pages, > > > you can get false negatives now. And that's not acceptable... > > > > Do you mean the case where proc A pinned page P from a file, then proc B > > mapped the same page P on the file, then fork() on proc B? > > Yes. > > > If proc B didn't explicitly pinned page P in B's address space too, > > shouldn't we return "false" for page_likely_dma_pinned(P)? Because if > > proc B didn't pin the page in its own address space, I'd think it's ok to > > get the page replaced at any time as long as the content keeps the same. > > Or couldn't we? > > So it depends on the reason why you call page_likely_dma_pinned(). For your > COW purposes the check is correct but e.g. for "can filesystem safely > writeback this page" the page_likely_dma_pinned() would be wrong. So I'm > not objecting to the mechanism as such. I'm mainly objecting to the generic > function name which suggests something else than what it really checks and > thus it could be used in wrong places in the future... That's why I'd > prefer to restrict the function to PageAnon pages where there's no risk of > confusion what the check actually does. How about I introduce the helper as John suggested, but rename it to page_maybe_dma_pinned_by_mm() ? Then we also don't need to judge on which is more likely to happen (between "maybe" and "likely", since that will confuse me if I only read these words..). I didn't use any extra suffix like "cow" because I think it might be useful for things besides cow. Fundamentally the new helper will be mm-based, so "by_mm" seems to suite better to me. Does that sound ok? -- Peter Xu