Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5467212rwd; Wed, 24 May 2023 02:06:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4tpb7KJE8BJ4S37tNk/EG+w5SLgTMsUKRJMiukN944Mbfi3iZgK2CoCZIntimH4hWD+8tX X-Received: by 2002:a05:6a21:3395:b0:10c:663c:31c3 with SMTP id yy21-20020a056a21339500b0010c663c31c3mr5994106pzb.29.1684919191857; Wed, 24 May 2023 02:06:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684919191; cv=none; d=google.com; s=arc-20160816; b=oU4oCejkoU0ISnzMzbS9Z1+SCD9aK1Lg6RmNNnkHXv2NEVaZoPhc+UCmAtHuEuY5/C Xt/SRCbwwVGqmCZN+Qk+JcUOu913yDGUEnfihluJQPqrzDu91bimC7nQhqnjQyx0Vzz9 SvjWFYi4zlmS3upW4CF3jtqowrRx6MLEuDWpC3N27nclRd+L4/SwuTkynjDwT636lLZz gJ60pq0X3S6QW0BLEAkeCkrwkbrJ1h8U+68QuSITbMWFu9MzT5omPF3me1+5eW5w1+QL UoP/uqE6ACIVmUsdz7fRJ4K1J7QFjcxPuGkkeJ5LL5RJ0aLezu/ooadaldIrEplQbRqP G3fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:dkim-signature; bh=CDhpK8+26Y4l0U6FHR/UwNa7pZESmpTlQt8dJppAy50=; b=xQtKNimU5KERo5s2z/Z0nQOYpkE4cT16juo5prpEGpS+2CcR0Nrwq7zo91KM13bHLq DUqf/VS8Xt0DoOL6nGY0rBPIQrT2utXH+8T3AWoL9ZNThWBbPzc6LuhB8F21OqIfGZZx ZX12gY8uSyEi91wcRalg43iiihbDtcTm35dw1Jp5AqpLY3o4oskWpESGmJiv+g125j4N ORDS6GaazM+RpI7G1JA+j9F8WdqO6fn3L76HKv98iFgtWp6DtTnh6uea1JlFT73xrHWE 61qxTPvt8sFwdbXSNjM6npBd6LHzuiIwiOpPK33U0cBxm8LU6o0CxNV+BYALUMsAcIOb FSrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PWU6n06f; 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 a186-20020a6390c3000000b005308fb9619asi1711166pge.54.2023.05.24.02.06.16; Wed, 24 May 2023 02:06:31 -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=PWU6n06f; 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 S229484AbjEXIsK (ORCPT + 99 others); Wed, 24 May 2023 04:48:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239229AbjEXIsJ (ORCPT ); Wed, 24 May 2023 04:48:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D3AA97 for ; Wed, 24 May 2023 01:47:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684918041; 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=CDhpK8+26Y4l0U6FHR/UwNa7pZESmpTlQt8dJppAy50=; b=PWU6n06f07jGqHbgC1X3bSsaG0hcL/MQocaDiN8T2TXwa26kWJXtlMQqrVS8AYhnAJJUtg Yp5xnPPvMo8kpCkaRZ/Q6XJ6pKlG/79SuGD3y2ILHNtKQhvj6q9STyg78F4pGrJoxKeqQQ /LDghhJ42fKqGJrtpQqKo0XXoVLAYDA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-345-V0pDKK8rM169n3tqu65WWQ-1; Wed, 24 May 2023 04:47:14 -0400 X-MC-Unique: V0pDKK8rM169n3tqu65WWQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 08EC385A5AA; Wed, 24 May 2023 08:47:14 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CDA840CFD45; Wed, 24 May 2023 08:47:11 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: References: <20230522205744.2825689-1-dhowells@redhat.com> <3068545.1684872971@warthog.procyon.org.uk> To: Christoph Hellwig Cc: dhowells@redhat.com, Jens Axboe , Al Viro , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , 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 Subject: Re: Extending page pinning into fs/direct-io.c MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3215176.1684918030.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Wed, 24 May 2023 09:47:10 +0100 Message-ID: <3215177.1684918030@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 Christoph Hellwig wrote: > > What I'd like to do is to make the GUP code not take a ref on the zero= _page > > if, say, FOLL_DONT_PIN_ZEROPAGE is passed in, and then make the bio cl= eanup > > code always ignore the zero_page. > = > I don't think that'll work, as we can't mix different pin vs get types > in a bio. And that's really a good thing. True - but I was thinking of just treating the zero_page specially and nev= er hold a pin or a ref on it. It can be checked by address, e.g.: static inline void bio_release_page(struct bio *bio, struct page *page= ) { if (page =3D=3D ZERO_PAGE(0)) return; if (bio_flagged(bio, BIO_PAGE_PINNED)) unpin_user_page(page); else if (bio_flagged(bio, BIO_PAGE_REFFED)) put_page(page); } I'm slightly concerned about the possibility of overflowing the refcount. = The problem is that it only takes about 2 million pins to do that (because the zero_page isn't a large folio) - which is within reach of userspace. Crea= te an 8GiB anon mmap and do a bunch of async DIO writes from it. You won't h= it ENOMEM because it will stick ~2 million pointers to zero_page into the pag= e tables. > > Something that I noticed is that the dio code seems to wangle to page = bits on > > the target pages for a DIO-read, which seems odd, but I'm not sure I f= ully > > understand the code yet. > = > I don't understand this sentence. I was looking at this: static inline void dio_bio_submit(struct dio *dio, struct dio_submit *= sdio) { ... if (dio->is_async && dio_op =3D=3D REQ_OP_READ && dio->should_dirty) bio_set_pages_dirty(bio); ... } but looking again, the lock is taken briefly and the dirty bit is set - wh= ich is reasonable. However, should we be doing it before starting the I/O? David