From patchwork Wed Aug 21 00:30:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11105111 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 910D41395 for ; Wed, 21 Aug 2019 00:31:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5DEB222DA7 for ; Wed, 21 Aug 2019 00:31:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="hfuFvEaE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DEB222DA7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E53886B0266; Tue, 20 Aug 2019 20:30:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D8E726B0269; Tue, 20 Aug 2019 20:30:58 -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 C0E8B6B026B; Tue, 20 Aug 2019 20:30:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id 8C5DE6B0266 for ; Tue, 20 Aug 2019 20:30:58 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 3FB8A181AC9BF for ; Wed, 21 Aug 2019 00:30:58 +0000 (UTC) X-FDA: 75844554996.04.bone62_429b8406c4c24 X-Spam-Summary: 2,0,0,b764bc18f7d7f016,d41d8cd98f00b204,willy@infradead.org,:linux-fsdevel@vger.kernel.org:willy@infradead.org:hch@lst.de:linux-xfs@vger.kernel.org:,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2393:2507:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3868:3870:3871:3872:4250:4321:5007:6261:6653:7576:7875:8660:10004:11026:11658:11914:12043:12291:12296:12297:12438:12555:12663:12895:12986:13069:13148:13161:13229:13230:13311:13357:13894:14096:14181:14384:14394:14721:21080:21433:21451:21627:21740:30029:30054,0,RBL:198.137.202.133:@infradead.org:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:42,LUA_SUMMARY:none X-HE-Tag: bone62_429b8406c4c24 X-Filterd-Recvd-Size: 3714 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 21 Aug 2019 00:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; 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: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=8+LFRgysFm6l7b1EmI740QXkofLUbCuDM+A6qLMp9ww=; b=hfuFvEaEQut5AVQb1YlZ91uQkZ cQCCd+XL0ZBjSfW+iVu6x/ii9yjABmkxM578Y1ifxD7MMwjomQLoKGn5k4MLo2FX/86BoXjOGYx+m st3+ToZCILpSW/kqCpeT1dtRTADo/0xMsbEK3LKhk9WhVc8eDvpYi0Sg0B/CLMkYomJKnt44gkhFd 4QqRaGzT/xJhc6sVKdddPDG4H6ktFrxuEeyvAJ1O71FUL4NKpe0v0gJNYXfogtiSI3fi5iLUrGIRa 8WF1zrkQ0+YMlL9tT+cBEyyUoucubTbfdFEgqghr9OeVk1kAfYxAmOblCehYf/ZXd0//Z8EABbvof y4pJ4swA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1i0EWQ-0003HW-A3; Wed, 21 Aug 2019 00:30:42 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , hch@lst.de, linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 2/5] mm: Add file_offset_of_ helpers Date: Tue, 20 Aug 2019 17:30:36 -0700 Message-Id: <20190821003039.12555-3-willy@infradead.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190821003039.12555-1-willy@infradead.org> References: <20190821003039.12555-1-willy@infradead.org> MIME-Version: 1.0 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: From: "Matthew Wilcox (Oracle)" The page_offset function is badly named for people reading the functions which call it. The natural meaning of a function with this name would be 'offset within a page', not 'page offset in bytes within a file'. Dave Chinner suggests file_offset_of_page() as a replacement function name and I'm also adding file_offset_of_next_page() as a helper for the large page work. Also add kernel-doc for these functions so they show up in the kernel API book. page_offset() is retained as a compatibility define for now. --- include/linux/pagemap.h | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2728f20fbc49..84f341109710 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -436,14 +436,33 @@ static inline pgoff_t page_to_pgoff(struct page *page) return page_to_index(page); } -/* - * Return byte-offset into filesystem object for page. +/** + * file_offset_of_page - File offset of this page. + * @page: Page cache page. + * + * Context: Any context. + * Return: The offset of the first byte of this page. */ -static inline loff_t page_offset(struct page *page) +static inline loff_t file_offset_of_page(struct page *page) { return ((loff_t)page->index) << PAGE_SHIFT; } +/* Legacy; please convert callers */ +#define page_offset(page) file_offset_of_page(page) + +/** + * file_offset_of_next_page - File offset of the next page. + * @page: Page cache page. + * + * Context: Any context. + * Return: The offset of the first byte after this page. + */ +static inline loff_t file_offset_of_next_page(struct page *page) +{ + return ((loff_t)page->index + compound_nr(page)) << PAGE_SHIFT; +} + static inline loff_t page_file_offset(struct page *page) { return ((loff_t)page_index(page)) << PAGE_SHIFT;