From patchwork Tue Feb 13 09:37:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554783 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 9321BC4829A for ; Tue, 13 Feb 2024 09:37:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DC7A6B007D; Tue, 13 Feb 2024 04:37:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 265246B0080; Tue, 13 Feb 2024 04:37:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DDF06B0081; Tue, 13 Feb 2024 04:37:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id F27616B007D for ; Tue, 13 Feb 2024 04:37:32 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4570AA093A for ; Tue, 13 Feb 2024 09:37:32 +0000 (UTC) X-FDA: 81786277944.24.BC7B92E Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf17.hostedemail.com (Postfix) with ESMTP id 7457240011 for ; Tue, 13 Feb 2024 09:37:30 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=aXtgjhd1; dmarc=none; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817050; 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=D1pKcMbFRFRAPVwFIcuNop7Fe4l/PLjOYcOBcxoLFyo=; b=vDOeC8MbOiAbsa0sjYWEDa3CY0mI/ZLzo5nc9S2cPM/ttHNbLksLuXqCh066Xjsxu/s/LC jt7b8oSPnwHiv0XHc8uNhjmWbrpak/+aC3Ml4xMeorHUkfQ/67WiVuLAVhlkbYxtxOpW6F cXKnRXqGjGZihTOkosCXCbo70c/Atn8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=aXtgjhd1; dmarc=none; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817050; a=rsa-sha256; cv=none; b=FALosbmJyDCkjBm8LdBMkElFddbzz1BRvyg74IJeD/WKUMAg3xYbkw9QdHXGBSM/HkoI2N WxzlnmO5oFkYVP/xDEFMsbCmiGkv7I7YxIShUXkL7tkTg/zZ5dzPoakw8KjeM/vb0x8iOR QQ+0Q9234FbTVIOQKN7e6aDxWfDzdzk= Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4TYx7V3jchz9smV; Tue, 13 Feb 2024 10:37:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D1pKcMbFRFRAPVwFIcuNop7Fe4l/PLjOYcOBcxoLFyo=; b=aXtgjhd1b//XRwpHD3/R1kk0mMTstSjUb1ouVBf6fckgb8rZuNI8zTh5DEfERSatuEP7pk 8r5YZ81b978D/uP1iocDT3hJ0DAMvsePx0hbDmXJc9fXVhf/Umqd3qoeywBTAMUWEkLzBc vtPR/X4NoIYAa+boy6TQjlTNfkn8RNxra5BUp+2y9fcjIv/1CtJ/6sZEPGCZgSCQqAxIvE 3thP6Rsg48Qm50MXNeztGsGj45DAUmbTwN4x4ViCWqPcJT8qc7mVogI7IwJNiQjIzN9/1H Z+3XDCrnf0weMSLu5URLoEZIWi8/LyMh3ZET8GObGX6Kn0hq/Rz6GqEnzMZ0iw== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 02/14] filemap: align the index to mapping_min_order in the page cache Date: Tue, 13 Feb 2024 10:37:01 +0100 Message-ID: <20240213093713.1753368-3-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7457240011 X-Stat-Signature: ofhogf57gbjh3gaw5b1dcijkwq43njgx X-Rspam-User: X-HE-Tag: 1707817050-19110 X-HE-Meta: U2FsdGVkX19PH4+l4YqNjUhj2o/d+95jYIOQjZwBF/TgFIauPFOQBCvKp2Xn6sKUPLZpZsNJjgaYUZNXpYfufjDlWGB30AkuCOo1Z8MynUBrvBBOWgTiubTbW6kvbH6v8SfMwFSN4CvowTVD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2EZbQyOGJclhEti2D7K7Tu+u4VRtoOGZaVBY3F+k5L0uJ2uY4Ar+d8Ji513gNWm1jh135eYR6xN4BEdZmSiqQEDnkSG9ivTEOiYfOOUib4LFpV/PYjPIHqZGdcMImuPLJNhF1eCYElgVmjDOV/R7gXgxktGI4eF/CgizhpXm8lF5wwmsCST2cGnXnn+xk4XEHW0DtQ== 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: List-Subscribe: List-Unsubscribe: From: Luis Chamberlain Supporting mapping_min_order implies that we guarantee each folio in the page cache has at least an order of mapping_min_order. So when adding new folios to the page cache we must ensure the index used is aligned to the mapping_min_order as the page cache requires the index to be aligned to the order of the folio. A higher order folio than min_order by definition is a multiple of the min_order. If an index is aligned to an order higher than a min_order, it will also be aligned to the min order. This effectively introduces no new functional changes when min order is not set other than a few rounding computations that should result in the same value. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- mm/filemap.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 750e779c23db..323a8e169581 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2479,14 +2479,16 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, { struct file *filp = iocb->ki_filp; struct address_space *mapping = filp->f_mapping; + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); struct file_ra_state *ra = &filp->f_ra; - pgoff_t index = iocb->ki_pos >> PAGE_SHIFT; + pgoff_t index = round_down(iocb->ki_pos >> PAGE_SHIFT, min_nrpages); pgoff_t last_index; struct folio *folio; int err = 0; /* "last_index" is the index of the page beyond the end of the read */ last_index = DIV_ROUND_UP(iocb->ki_pos + count, PAGE_SIZE); + last_index = round_up(last_index, min_nrpages); retry: if (fatal_signal_pending(current)) return -EINTR; @@ -2502,8 +2504,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, if (!folio_batch_count(fbatch)) { if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) return -EAGAIN; - err = filemap_create_folio(filp, mapping, - iocb->ki_pos >> PAGE_SHIFT, fbatch); + err = filemap_create_folio(filp, mapping, index, fbatch); if (err == AOP_TRUNCATED_PAGE) goto retry; return err; @@ -3095,7 +3096,10 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) struct file *file = vmf->vma->vm_file; struct file_ra_state *ra = &file->f_ra; struct address_space *mapping = file->f_mapping; - DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff); + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int min_nrpages = mapping_min_folio_nrpages(file->f_mapping); + pgoff_t index = round_down(vmf->pgoff, min_nrpages); + DEFINE_READAHEAD(ractl, file, ra, mapping, index); struct file *fpin = NULL; unsigned long vm_flags = vmf->vma->vm_flags; unsigned int mmap_miss; @@ -3147,10 +3151,11 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) */ fpin = maybe_unlock_mmap_for_io(vmf, fpin); ra->start = max_t(long, 0, vmf->pgoff - ra->ra_pages / 2); + ra->start = round_down(ra->start, min_nrpages); ra->size = ra->ra_pages; ra->async_size = ra->ra_pages / 4; ractl._index = ra->start; - page_cache_ra_order(&ractl, ra, 0); + page_cache_ra_order(&ractl, ra, min_order); return fpin; } @@ -3164,7 +3169,9 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf, { struct file *file = vmf->vma->vm_file; struct file_ra_state *ra = &file->f_ra; - DEFINE_READAHEAD(ractl, file, ra, file->f_mapping, vmf->pgoff); + unsigned int min_nrpages = mapping_min_folio_nrpages(file->f_mapping); + pgoff_t index = round_down(vmf->pgoff, min_nrpages); + DEFINE_READAHEAD(ractl, file, ra, file->f_mapping, index); struct file *fpin = NULL; unsigned int mmap_miss; @@ -3212,13 +3219,17 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) struct file *file = vmf->vma->vm_file; struct file *fpin = NULL; struct address_space *mapping = file->f_mapping; + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int nrpages = 1UL << min_order; struct inode *inode = mapping->host; - pgoff_t max_idx, index = vmf->pgoff; + pgoff_t max_idx, index = round_down(vmf->pgoff, nrpages); struct folio *folio; vm_fault_t ret = 0; bool mapping_locked = false; max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); + max_idx = round_up(max_idx, nrpages); + if (unlikely(index >= max_idx)) return VM_FAULT_SIGBUS; @@ -3317,13 +3328,17 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) * We must recheck i_size under page lock. */ max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); + max_idx = round_up(max_idx, nrpages); + if (unlikely(index >= max_idx)) { folio_unlock(folio); folio_put(folio); return VM_FAULT_SIGBUS; } - vmf->page = folio_file_page(folio, index); + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); + + vmf->page = folio_file_page(folio, vmf->pgoff); return ret | VM_FAULT_LOCKED; page_not_uptodate: @@ -3658,6 +3673,9 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, { struct folio *folio; int err; + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); + + index = round_down(index, min_nrpages); if (!filler) filler = mapping->a_ops->read_folio;