From patchwork Wed Jan 18 09:43:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13105977 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 4F625C004D4 for ; Wed, 18 Jan 2023 09:44:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C817E6B007E; Wed, 18 Jan 2023 04:44:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C326B6B0080; Wed, 18 Jan 2023 04:44:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD2B06B0081; Wed, 18 Jan 2023 04:44:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9D93F6B007E for ; Wed, 18 Jan 2023 04:44:08 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 78483A07F9 for ; Wed, 18 Jan 2023 09:44:08 +0000 (UTC) X-FDA: 80367433776.27.54C8187 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id 0F9D240017 for ; Wed, 18 Jan 2023 09:44:06 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UfEL4nxo; spf=none (imf07.hostedemail.com: domain of BATV+aec3eaf5b774c69d00f8+7087+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aec3eaf5b774c69d00f8+7087+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674035047; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pFy30vhWl9l9ZgLMa817B3/6WEg0wrb2z/Np7E/EF8c=; b=Kzc/NOCoGsZfC4F6VDOiEcBFbNoXm11ox7e6sECzlF02JRh0EKU5XyWTC9WKnqGoZsfoGE U2b5H5Wes3I0uJxbCK3YdeM1v5g6YVKXYBndFd8rs1oxT0vU9cxHrBcxdxlduABbkv/kyd mGfHhpTfxjdVrXKy0hf6Zp075tYyNrI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UfEL4nxo; spf=none (imf07.hostedemail.com: domain of BATV+aec3eaf5b774c69d00f8+7087+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aec3eaf5b774c69d00f8+7087+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674035047; a=rsa-sha256; cv=none; b=TOfWv2lzu1WNojX3tCa7eayURNVwVhB0Y4T74S9Q+5LeidHnPI54zodsyxIjk2HwofnJUz YBt44DKK/TaTfBjY3A/FnshRr+95390CfqDRx6OXo9H9IuwiRd8WzkdzxRDXtBG4pCP6PO 516ZM8+TGXtFCtfFtqNWJCB2AROP41g= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=pFy30vhWl9l9ZgLMa817B3/6WEg0wrb2z/Np7E/EF8c=; b=UfEL4nxoIkflPHGo7FW/goZ6Ae xIpR/d0qI5IJrraY/1iGKXWGHdji2iuHKy5HnLQI8g45xl0egjQwt440BkyDBzLOtbS3WTE77JRoB YVbEr2AoQ50WmGx37VByiYGoCLP0d5MCV4wzb6443KaglnqflCP6aueRjRXiu9loX+HJZJVZbLoYZ 7L8+14Vq+wI6LGjevGMbFYs4iFg/sLVFkhIO9VUWEW0VoKzm/xPjwyPDaa3qLJ2urhMKmMYcXaer+ mXjsx+091criZqeGU7fbDpZee25pjlDMItJhPegKjbf5a4mRmpe2UFeAd60n54qiLHBmIq6wh9a1Q m2aDbOQw==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4z7-000A13-OH; Wed, 18 Jan 2023 09:43:59 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 5/9] shmem: open code the page cache lookup in shmem_get_folio_gfp Date: Wed, 18 Jan 2023 10:43:25 +0100 Message-Id: <20230118094329.9553-6-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 4ecjfxenftbfiprfdwn3beaped6gm1f8 X-Rspamd-Queue-Id: 0F9D240017 X-HE-Tag: 1674035046-13909 X-HE-Meta: U2FsdGVkX1/Zzvqp3pvTE656Z6wyn9SeNKxPT7VZD2UJrWi5CCA5Hyw9Zvj9LWYsuotRt6+Wx8S4lG1TRve2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zf8+OTtKcaZ8t0pWZO8966u9ELMBOECWCbb/9GX+noHi1wCMPxOkSoXYGjKnnyGQ4sH1qpQxY= 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: Use the very low level filemap_get_entry helper to look up the entry in the xarray, and then: - don't bother locking the folio if only doing a userfault notification - open code locking the page and checking for truncation in a related code block This will allow to eventually remove the FGP_ENTRY flag. Signed-off-by: Christoph Hellwig --- mm/shmem.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index e9500fea43a8dc..769107f376562f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1856,12 +1856,10 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, sbinfo = SHMEM_SB(inode->i_sb); charge_mm = vma ? vma->vm_mm : NULL; - folio = __filemap_get_folio(mapping, index, FGP_ENTRY | FGP_LOCK, 0); + folio = filemap_get_entry(mapping, index); if (folio && vma && userfaultfd_minor(vma)) { - if (!xa_is_value(folio)) { - folio_unlock(folio); + if (!xa_is_value(folio)) folio_put(folio); - } *fault_type = handle_userfault(vmf, VM_UFFD_MINOR); return 0; } @@ -1877,6 +1875,14 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, } if (folio) { + folio_lock(folio); + + /* Has the page been truncated? */ + if (unlikely(folio->mapping != mapping)) { + folio_unlock(folio); + folio_put(folio); + goto repeat; + } if (sgp == SGP_WRITE) folio_mark_accessed(folio); if (folio_test_uptodate(folio))