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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F463C433EF for ; Fri, 7 Jan 2022 18:23:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2911B6B0075; Fri, 7 Jan 2022 13:23:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 240BB6B007D; Fri, 7 Jan 2022 13:23:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E11B6B0082; Fri, 7 Jan 2022 13:23:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 002366B0075 for ; Fri, 7 Jan 2022 13:23:24 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B903296F3D for ; Fri, 7 Jan 2022 18:23:24 +0000 (UTC) X-FDA: 79004313528.26.EC32FC4 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by imf08.hostedemail.com (Postfix) with ESMTP id 2D4C416000F for ; Fri, 7 Jan 2022 18:23:23 +0000 (UTC) Received: by mail-qt1-f174.google.com with SMTP id y17so6303303qtx.9 for ; Fri, 07 Jan 2022 10:23:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=RQi4JhxDh8uWmyDJXKLNXKR3JO/+NQpv2jKa5YTPwjc=; b=J3ngUhpo0XlN4ggax2aqZTTdcpb6CfNC2n7ffAc0n1syvG/YyLm66dtOhYT3y3j4oG E2JyYmXThyT3pJbaPIJWmNM73S33i97ftAzAqieblvUmfSywlfly6beWoQIEMhyIg7Pt XERtW/K/Go9x4RE8ea7n0mqVN7t3G8WJZ11xoXbxp1vYYNLzGIf79oL9L9nMDHDiyAxL b1E/YZ0k5hqURsJwmyIiCpujTsM7GlokzdNYGjn7hVq19TjY42ooxb4yx57Tgv1ciKkw SmE3gm7UuT8yL4wHbuKi3ru7RAPX4/mTwAKtYO5c27cZFY2fXUOn+zjec3DbJV378H9m HSCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RQi4JhxDh8uWmyDJXKLNXKR3JO/+NQpv2jKa5YTPwjc=; b=EIPV1CYOqCKkPq/1ncd1dUyc4TetMvFstjdYwq2qcVR/pn1bonJ+2CU8VD9ZuUZK+t 0hpNl6DJPQqNjoeKvEAX27v+H1JMhZ5oneCp+AsQi7X/MsTEqlCnkr3y3dZce9fDNK9a tn6M5n34wzJFQkzeqDqi2hOb4ENOYRvhOZdTTsmNxbSJFzLaAid/YAzcIFi2ScENLase 6VU+m6LkelRsJJS4xbplBI8BIVJY/yjxjNydUe/SFU8vD/fmcS+tAV7DPIugx5HGf4Hc uuTSc4xZc2a/eCQxcloqUpMdW8Ae0fJGprQwlAY/hCRKneBl3QCh1do2NR/oc4Ax1kFy RHfQ== X-Gm-Message-State: AOAM531EW2h04yhmoePpUJswLrxB3Qwg2g77P6dEpAVqIwMxLPcfyobk GqkLwxCYHyRHWO45598Vm/w+lw== X-Google-Smtp-Source: ABdhPJyupw0oAizhFagqrtuXCy/Gi0xv2Fwhk0vUcH+rnoOwm+ynlZHRG6BSB+NtutBEfMNW661Q+g== X-Received: by 2002:a05:622a:1105:: with SMTP id e5mr58435565qty.407.1641579803382; Fri, 07 Jan 2022 10:23:23 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id p5sm1090302qtw.12.2022.01.07.10.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 10:23:22 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1n5ttZ-00Czxj-Id; Fri, 07 Jan 2022 14:23:21 -0400 Date: Fri, 7 Jan 2022 14:23:21 -0400 From: Jason Gunthorpe To: John Hubbard Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Andrew Morton Subject: Re: [PATCH 05/17] gup: Add try_get_folio() Message-ID: <20220107182321.GA6467@ziepe.ca> References: <20220102215729.2943705-1-willy@infradead.org> <20220102215729.2943705-6-willy@infradead.org> <3ac8af50-dff6-4a0f-dba6-8b8fe5f611d4@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3ac8af50-dff6-4a0f-dba6-8b8fe5f611d4@nvidia.com> X-Rspamd-Queue-Id: 2D4C416000F X-Stat-Signature: z7cc6wx5gjy5tfmp6xfbwcuzzieydxor Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=J3ngUhpo; spf=pass (imf08.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.160.174 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none X-Rspamd-Server: rspam10 X-HE-Tag: 1641579803-416527 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 Tue, Jan 04, 2022 at 05:25:07PM -0800, John Hubbard wrote: > > + folio = page_folio(page); > > + if (WARN_ON_ONCE(folio_ref_count(folio) < 0)) > > return NULL; > > - if (unlikely(!page_cache_add_speculative(head, refs))) > > + if (unlikely(!folio_ref_try_add_rcu(folio, refs))) > > I'm a little lost about the meaning and intended use of the _rcu aspects > of folio_ref_try_add_rcu() here. For example, try_get_folio() does not > require that callers are in an rcu read section, right? This is probably > just a documentation question, sorry if it's obvious--I wasn't able to > work it out on my own. Normally this is called under gup_fast, so it is operating under the quasi-rcu it uses. I have no idea about preempt kernels if this should be marked with rcu or if the local_irq_save is good enough.. The exceptional cases are get_gate_page() which I suppose relies on the mmap lock to ensure that the special gate page cannot be concurrently freed. Then there are the cases under slow GUP (eg follow_page_pte()) which don't need "try" at all because they hold the PTLs so it is guarenteed the refcount should be non-zero AFAIK.. It wouldn't be a bad idea to have a non-try version of this just for clarity, could it peform a bit better? /* * try_grab_page() should always succeed here, because: a) we * hold the pmd (ptl) lock, and b) we've just checked that the * huge pmd (head) page is present in the page tables. The ptl * prevents the head page and tail pages from being rearranged * in any way. So this page must be available at this point, * unless the page refcount overflowed: */ if (WARN_ON_ONCE(!try_grab_page(page, flags))) { Jason