Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp532524rwd; Thu, 1 Jun 2023 03:39:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4GLL4roz0Y6maexc4hnfjgAb/5qRqK1l85n9e1A018xeNMFO92Bc5JHc9QA6OhN5fffXkS X-Received: by 2002:a05:6870:d452:b0:177:dfdb:63 with SMTP id j18-20020a056870d45200b00177dfdb0063mr4913600oag.44.1685615955670; Thu, 01 Jun 2023 03:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685615955; cv=none; d=google.com; s=arc-20160816; b=l6UYGB4qXeE6O7dOyeOltyui1hslRHwdXufOpDVHDxQAqua/GdHiUid/ih8+blgp03 5efXci4gBt6i9xwU82lfqHd2xBrkWPHCh7gBGhMWyOEYWepr8q2653awNzsEVbzMijf5 bcbsRPgit6unEB1MXyKydVWS8esqkXJsc7c9Z4MXM3DgQiEN/P4T7cS4fX9jWvnK1+KQ v7Gan/jS6iYh3Nfi83edSgO1aYfzujf+QmMQHCLC8Jww7c6R38YyAOn2fR81ieX7l6xR h3Aq2nYdjbrhskY6khhmak/QbmT/iBTchER9fwpuQcHNushi8H47ZWCj72RdfkGthkpF K5Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=NYR/VkMk/voOznqHepF47pBoY++iUIp7AId3uEofiiU=; b=LZmasxw/fDGsUiW3YiJHgrQAQ+m9M8WQWkdrtbNF4uNonXGNHkdX3ZdDycosJnWdwA xI2SRqNYe0UDJk27URHLoDAAAtHfwHQtullZ4CmKW9L2129y3sh+m9v9sk4jhL48nYo8 +rv/uOmVHZ7NHh7df4g0n5DUOADAGuWwrmj99qXXbADRXWb86RU+aOPY8StAIqvOlcVI GZxhfDH+C7IRZHehM+4pmCq4RGGAhx4ufhDGp/PWqZpO/lkG7vzJeyVJkIb6dFHZy67F PUR8igyByKLnpw3Q/QsdefoVrQJPPVKzmXxt4ipbomp2OVlFVaYoNWAM69LFUUm4hJGk 0n5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dQ13meQ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s17-20020a639251000000b00524ea64ba6esi1877105pgn.530.2023.06.01.03.39.01; Thu, 01 Jun 2023 03:39:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dQ13meQ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233490AbjFAKVI (ORCPT + 99 others); Thu, 1 Jun 2023 06:21:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233615AbjFAKTR (ORCPT ); Thu, 1 Jun 2023 06:19:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7057171B for ; Thu, 1 Jun 2023 03:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685614464; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NYR/VkMk/voOznqHepF47pBoY++iUIp7AId3uEofiiU=; b=dQ13meQ+T7sQL3wVuwWT2ZUA3kKoLFA6bHqrGSYSSRor7sVCOs7zpdc0jroU60vwMpiHP0 I1Elb1O7UTu25UN3oShWFT0lKS0vwu9Ak9S9jx+ICwmEYkYO1r36GYCdgtvkswjmqKioBM kHt6qcAsTqij3glOsP/ubFiknpdJP/k= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-ytuUihfwPVqZ3Hv7Vw7bag-1; Thu, 01 Jun 2023 06:14:22 -0400 X-MC-Unique: ytuUihfwPVqZ3Hv7Vw7bag-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3f6f58e269eso4276605e9.1 for ; Thu, 01 Jun 2023 03:14:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685614462; x=1688206462; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NYR/VkMk/voOznqHepF47pBoY++iUIp7AId3uEofiiU=; b=gNWwK9bAnfGKFHwAdZ+PGB4BojO5pmGFqNi95rBkgzhNKXnlj0rpXpZzBl4dQpVA1q SKurp+qFn1OBGwWqGY9xn2fEdy/ywr3wvlOaHUFnbhzVqHDnRRA3q9jG8YLJbpfMAxzx 7QB1b03EoUfce1C+jdFE91gFdB5Ba2WxRRT0XehGMTGOq5CnL0i38H4C25H/kjCg7pi0 jEs2Ix3IO0rYe9mH4AA3MF1Czlsgk3M/NKoIriMIMbNVsFKM8xdPB/kwLIbl41hWdVRx GUxDjz3rZ9zNgsbJQ/q/wt+LbZ0I+o7VA+FpF6mybJs25rONfCCbXEWNpEUVZmrN0agz 94aQ== X-Gm-Message-State: AC+VfDzdgCqAG2BDfyUAU4VqD/oJ9afa/m9XO6YQ1rK+y2z+XyuZtX6g ZeJhXlrqUZLRfrBATfFJShqJOPuxZ0PphcyyC2jnIc8v+ax1glGohS6PRmDK72dfnjllcbotM2v e2fWOCMEWJ0HxpNU9PPDC2O5F X-Received: by 2002:a1c:4b04:0:b0:3f6:1508:950d with SMTP id y4-20020a1c4b04000000b003f61508950dmr1560164wma.8.1685614461792; Thu, 01 Jun 2023 03:14:21 -0700 (PDT) X-Received: by 2002:a1c:4b04:0:b0:3f6:1508:950d with SMTP id y4-20020a1c4b04000000b003f61508950dmr1560131wma.8.1685614461274; Thu, 01 Jun 2023 03:14:21 -0700 (PDT) Received: from ?IPV6:2a09:80c0:192:0:5dac:bf3d:c41:c3e7? ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with ESMTPSA id e25-20020a05600c219900b003f42314832fsm1766220wme.18.2023.06.01.03.14.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Jun 2023 03:14:20 -0700 (PDT) Message-ID: <73befe4b-b9cc-72ee-872e-29efc16539ca@redhat.com> Date: Thu, 1 Jun 2023 12:14:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Content-Language: en-US To: David Howells Cc: Christoph Hellwig , Lorenzo Stoakes , Jens Axboe , Al Viro , Matthew Wilcox , Jan Kara , Jeff Layton , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton References: <492558dc-1377-fc4b-126f-c358bb000ff7@redhat.com> <20230526214142.958751-1-dhowells@redhat.com> <20230526214142.958751-2-dhowells@redhat.com> <510965.1685522152@warthog.procyon.org.uk> <703628.1685541335@warthog.procyon.org.uk> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v4 1/3] mm: Don't pin ZERO_PAGE in pin_user_pages() In-Reply-To: <703628.1685541335@warthog.procyon.org.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31.05.23 15:55, David Howells wrote: > David Hildenbrand wrote: > >> Yes, it would be clearer if we would be using "pinned" now only for FOLL_PIN > > You're not likely to get that. "To pin" is too useful a verb that gets used > in other contexts too. For that reason, I think FOLL_PIN was a poor choice of > name:-/. I guess the English language has got somewhat overloaded. Maybe > FOLL_PEG? ;-) You're probably right. FOLL_PIN and all around that is "get me an additional reference on the page and make sure I can DMA it without any undesired side-effects". FOLL_PIN_DMA would have been clearer (and matches folio_maybe_dma_pinned() ) ... but then, there are some use cases where want the same semantics but not actually perform DMA, but simply read/write via the directmap (e.g., vmsplice, some io_uring cases). Sure, one could say that they behave like DMA: access page content at any time. Saying a page is pinned (additional refcount) and having a pincount of 0 or does indeed cause confusion. ... but once we start renaming FOLL_PIN, pincount, ... we also have to rename pin_user_pages() and friends, and things get nasty. > >> and everything else is simply "taking a temporary reference on the page". > > Excluding refs taken with pins, many refs are more permanent than pins as, so > far as I'm aware, pins only last for the duration of an I/O operation. I was more thinking along the lines of FOLL_GET vs. FOLL_PIN. Once we consider any references we might have on a page, things get more tricky indeed. > >>>> "Note that the refcount of any zero_pages returned among the pinned pages will >>>> not be incremented, and unpin_user_page() will similarly not decrement it." >>> That's not really right (although it happens to be true), because we're >>> talking primarily about the pin counter, not the refcount - and they may be >>> separate. >> >> In any case (FOLL_PIN/FOLL_GET) you increment/decrement the refcount. If we >> have a separate pincount, we increment/decrement the refcount by 1 when >> (un)pinning. > > FOLL_GET isn't relevant here - only FOLL_PIN. Yes, as it happens, we count a > ref if we count a pin, but that's kind of irrelevant; what matters is that the > effect must be undone with un-PUP. The point I was trying to make is that we always modify the refcount, and in some cases (FOLL_PIN on order > 0) also the pincount. But if you define "pins" as "additional reference", we're on the same page. > > It would be nice not to get a ref on the zero page in FOLL_GET, but I don't > think we can do that yet. Too many places assume that GUP will give them a > ref they can release later via ordinary methods. No we can't I'm afraid. -- Thanks, David / dhildenb