From patchwork Wed May 23 14:43:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10421481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F398A6032A for ; Wed, 23 May 2018 14:44:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3C9F26E82 for ; Wed, 23 May 2018 14:44:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D850728733; Wed, 23 May 2018 14:44:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52ECF26E82 for ; Wed, 23 May 2018 14:44:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCD8D6B0266; Wed, 23 May 2018 10:44:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B7E726B0269; Wed, 23 May 2018 10:44:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6D336B026A; Wed, 23 May 2018 10:44:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 670016B0266 for ; Wed, 23 May 2018 10:44:20 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id 89-v6so14152545plb.18 for ; Wed, 23 May 2018 07:44:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=baOP/7rrxltggZTUkzsfi+HYBLNGsz0Q528W03aI5V4=; b=joZAgzzPE6oKJDEczI3Ue1lco4+u/XzBt6EAYMlz0a4OX28NTVTXemfMxL/VAz4/NM uXm/vocSt2O5uiIMKkTTLd9iUZb1KMV+T2v85uvPq1a5t0UpvR3kAuC5vVXN3G/ySXEj CXcDmQXpMcG5Vs2LLSLAqq0on0YSwHTGedWeiQRCkV+6FUjvxduqSd2IGPWYLEC+L4Eg /92gzVD0yHSWv65hTy9TgnFiXgbjUF7a9+jqPDvX7/gpyy+Dxl5A+K+eI1/WNYRcsqHx T2BAZ6+ocn+98xPpSZUWrYvjHqndr6mNB9YWFyfSk6QsY7U7xOdJbxsQaN1l58gEuCV1 oMJQ== X-Gm-Message-State: ALKqPwcTprkCNphKqr2GQBOsMkDgeDf3j/+6pVAqGuNvsHNX5LJBLno2 /2Kvpqqt1OTTMwaOPXUjEUVLBsJElU+JuRDN8rtnO8Q5p3ZdFJFKZA14jdghjZS73hylkdc5mBD YyznDnXGHeKAwI6u7acr5Z7X0Pqu0Zqszi99H1oBSMduExf4uKPkCtWDGkQ5Ssgk= X-Received: by 2002:a17:902:a986:: with SMTP id bh6-v6mr3295483plb.245.1527086660113; Wed, 23 May 2018 07:44:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoPpY8ln9nL9wtXzcrH6CWN0MtoRILNL5fXHb55n3i/pEbWVcQcp5JWXCIGhKBaCwjQZrNi X-Received: by 2002:a17:902:a986:: with SMTP id bh6-v6mr3295433plb.245.1527086659305; Wed, 23 May 2018 07:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527086659; cv=none; d=google.com; s=arc-20160816; b=fqLFcdWMxz3OKei2cXJigeWAiQhFrPub+K0tLo6HBR9mDeBGseFMaDhIFFphwpotRf QLZuWwL2dv7PYG51I2ATpgaeheQPi4SFpEikEGAsFgCNUidDAIxIU9mV1CzdW28fWLYo OlKA54+Q5c+6jfNxY6NQk58Q3Ux3i0QDBbSD+mxaHNm+byHwAefko2jRxjN6rniUpHPz g/+Kb8LqJOhA9+9Fw22QPinhozW+xtgsT093P2ZMTYeEeP2WfKtUKN9zbyyjNLbM1Buo YVUIfxOb/6AEvHrs6cm2/Lxs6W/2xyHTz4gYI2HK1bZ0kxePyveFMBKW1hLnFVPXhtT1 7dwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=baOP/7rrxltggZTUkzsfi+HYBLNGsz0Q528W03aI5V4=; b=y7EuSTsi8UY5m4SHRjBjmVyj2iYSZMt+Lc4yJ8tXIOnBIjEdRbfjPcC55ttoAWLxjc p5bVRaYCl9updq7ix4rQom8RZogpdrEHVatNWAbW5FuRMU3edPhH2YBQc7jmSeTa4i1k YKwES0biNR7Lm5kAztgTyvcCXur9QzOH9AWUIF4CR7E1oCSRgEkIBA4xH3d4EDI+gyHG p+TNn7q+r7Pu/trJnMsZoiVmCRwIsm0Eg+MItTYxNCecHsG+Wbi8HBZ9OkxstmfyD1xv 9vOhTkndDEYZOW49J9z5TICzU1rgr1UFFa2+kTp47s9nxIygt4Va8dNkCkmPEmZghFxH u65w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=H9qNOjWS; spf=pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id d12-v6si19415109plo.551.2018.05.23.07.44.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 07:44:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=H9qNOjWS; spf=pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=baOP/7rrxltggZTUkzsfi+HYBLNGsz0Q528W03aI5V4=; b=H9qNOjWSo7rd9E1/ljO/JsEW+ oklFfWbCW9dqMlyt8KrVod+Ru3kVYaD2YHCuRk4OP/UDEYHjjyGjKRxrCIUVOW6CRUMH/8+qwyxzm Q7BimUfAKRjp/vczUpgfKbQNPkGGvedH0EQBBmRE8bCozlz7L8Qzz+9MetWMoUcjtKauILmW0uKkP hDkRZ913zTLYndPDXcfIqgIV32ZK9uXMZdnQRVqQaaceGuIuFm+Mi0Cad+b5zYXlM4y31NhJe1JtA aeKd1RaLUGLunNovt7C79zSUocaAcKypZWSPgxD68nHbgzHi79fudy78ZXml/6j1G6IVPkszZoBXn O7wJ8DW/w==; Received: from 089144199016.atnat0008.highway.a1.net ([89.144.199.16] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLUzw-0000Du-LG; Wed, 23 May 2018 14:44:17 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 05/34] fs: use ->is_partially_uptodate in page_cache_seek_hole_data Date: Wed, 23 May 2018 16:43:28 +0200 Message-Id: <20180523144357.18985-6-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523144357.18985-1-hch@lst.de> References: <20180523144357.18985-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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: X-Virus-Scanned: ClamAV using ClamSMTP This way the implementation doesn't depend on buffer_head internals. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/iomap.c | 85 +++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/fs/iomap.c b/fs/iomap.c index bef5e91d40bf..0900da23172c 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -589,36 +589,51 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, } EXPORT_SYMBOL_GPL(iomap_fiemap); -/* - * Seek for SEEK_DATA / SEEK_HOLE within @page, starting at @lastoff. - * - * Returns the offset within the file on success, and -ENOENT otherwise. - */ -static loff_t -page_seek_hole_data(struct page *page, loff_t lastoff, int whence) +static bool +page_seek_hole_data(struct inode *inode, struct page *page, loff_t *lastoff, + int whence) { - loff_t offset = page_offset(page); - struct buffer_head *bh, *head; + const struct address_space_operations *ops = inode->i_mapping->a_ops; + unsigned int bsize = i_blocksize(inode), off; bool seek_data = whence == SEEK_DATA; + loff_t poff = page_offset(page); - if (lastoff < offset) - lastoff = offset; - - bh = head = page_buffers(page); - do { - offset += bh->b_size; - if (lastoff >= offset) - continue; + if (WARN_ON_ONCE(*lastoff >= poff + PAGE_SIZE)) + return false; + if (*lastoff < poff) { /* - * Any buffer with valid data in it should have BH_Uptodate set. + * Last offset smaller than the start of the page means we found + * a hole: */ - if (buffer_uptodate(bh) == seek_data) - return lastoff; + if (whence == SEEK_HOLE) + return true; + *lastoff = poff; + } + + /* + * Just check the page unless we can and should check block ranges: + */ + if (bsize == PAGE_SIZE || !ops->is_partially_uptodate) + return PageUptodate(page) == seek_data; - lastoff = offset; - } while ((bh = bh->b_this_page) != head); - return -ENOENT; + lock_page(page); + if (unlikely(page->mapping != inode->i_mapping)) + goto out_unlock_not_found; + + for (off = 0; off < PAGE_SIZE; off += bsize) { + if ((*lastoff & ~PAGE_MASK) >= off + bsize) + continue; + if (ops->is_partially_uptodate(page, off, bsize) == seek_data) { + unlock_page(page); + return true; + } + *lastoff = poff + off + bsize; + } + +out_unlock_not_found: + unlock_page(page); + return false; } /* @@ -655,30 +670,8 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length, for (i = 0; i < nr_pages; i++) { struct page *page = pvec.pages[i]; - /* - * At this point, the page may be truncated or - * invalidated (changing page->mapping to NULL), or - * even swizzled back from swapper_space to tmpfs file - * mapping. However, page->index will not change - * because we have a reference on the page. - * - * If current page offset is beyond where we've ended, - * we've found a hole. - */ - if (whence == SEEK_HOLE && - lastoff < page_offset(page)) + if (page_seek_hole_data(inode, page, &lastoff, whence)) goto check_range; - - lock_page(page); - if (likely(page->mapping == inode->i_mapping) && - page_has_buffers(page)) { - lastoff = page_seek_hole_data(page, lastoff, whence); - if (lastoff >= 0) { - unlock_page(page); - goto check_range; - } - } - unlock_page(page); lastoff = page_offset(page) + PAGE_SIZE; } pagevec_release(&pvec);