From patchwork Mon Feb 26 09:49:26 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: 13571761 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 C1809C54E49 for ; Mon, 26 Feb 2024 09:49:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4569594001D; Mon, 26 Feb 2024 04:49:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 405ED940014; Mon, 26 Feb 2024 04:49:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A7CD94001D; Mon, 26 Feb 2024 04:49:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 11995940014 for ; Mon, 26 Feb 2024 04:49:59 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D2443140715 for ; Mon, 26 Feb 2024 09:49:58 +0000 (UTC) X-FDA: 81833483676.10.C116D82 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf21.hostedemail.com (Postfix) with ESMTP id 392641C000C for ; Mon, 26 Feb 2024 09:49:56 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=bRv8Wx5c; dmarc=none; spf=pass (imf21.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=1708940997; a=rsa-sha256; cv=none; b=3BYN1nQvdnwY0phuamoVwxxAEQVCpXAjCW6q0Z8K2airBfCdMP1gyMyYLgSVwViwOc/Zp4 6Al/h4ukiSe2vIIjOWrSzGqEeZoNG7Uaw13+reOldr0gK9s16LIBp6qP/OQdHi+VkUQTtb 7+B+5+3zqQrGcm2UWe7fqWB2vJZbY0k= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=bRv8Wx5c; dmarc=none; spf=pass (imf21.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=1708940997; 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=UE/+ngzUW37ueqbuDmtoyKLgw47SUrAWwA7DBQ7fmXA=; b=YaRUBEv6REhv9BcHQuBe3easafMA/q2Lp1JPw1PFgeLkcCuwfZHvLhEa+A2E3p+dLMh35y BkXQapnsGQ/XF9E3/ZLzT4SjLuZAFHE3RlGmxUlU+8GaiiaJ/0nTZ2dF207GDCLM/t6YGU PvGSlQcdzfZZ1mGsrTOUPvchRE+FGXk= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4Tjwnt1tBzz9sTM; Mon, 26 Feb 2024 10:49:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1708940994; 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=UE/+ngzUW37ueqbuDmtoyKLgw47SUrAWwA7DBQ7fmXA=; b=bRv8Wx5cvk1xd9wVeRlOtaJZztEuuuk3hMBOtenVjKOEhVioQUed98THwPiUUu1f9r9DH7 wVd6ZXgT96T6EnmbVf914Uc1jQ24dL54EHczA3owM2IwVEsCOd+na63QUB+HW4d9qUx1k4 bp9FGTWx3r3Ga4N411mN/gefo51B/cN3YxgI8XUjBXEjt1A0bW5GTLmIo6bAvCkwJmSYZr yCwDty8PFIfD+eTzomhQEytKQGuLbLueIt3c2sw5+totLREcGF7IRnsOPc6FjNyCRSOSsq lnNJkHsVkyCXiILF76ixMcjR7kuA4Zp24E1MDjwHFSTRTXs+gDEU8TW1r1YJXQ== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org, mcgrof@kernel.org, ziy@nvidia.com, hare@suse.de, djwong@kernel.org, gost.dev@samsung.com, linux-mm@kvack.org, willy@infradead.org, Pankaj Raghav Subject: [PATCH 03/13] filemap: align the index to mapping_min_order in the page cache Date: Mon, 26 Feb 2024 10:49:26 +0100 Message-ID: <20240226094936.2677493-4-kernel@pankajraghav.com> In-Reply-To: <20240226094936.2677493-1-kernel@pankajraghav.com> References: <20240226094936.2677493-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 392641C000C X-Stat-Signature: ay7mwzhhccd48na75n87z7fq1ceb8hx7 X-HE-Tag: 1708940996-452034 X-HE-Meta: U2FsdGVkX1/D5oEWrgk1tJGlOn/hf6L+K2mtl86a5Lzup6faDvkQ+c6rISqYve9LnNPa7JvEVP7JP42knd3RdPyTW3BuQvubRm8icoHvaNARQbBLReVHPrGXGXznJWBLtXPy/MRhUO1Z8ZfdsrMlvLI3MoC1tSiP3WDpqj5n825PmLZSyCH5FFGFUE3nNwZqt9GBTkLiVSlEPcw2B6lkOYgst4ZLp/nmi/uZ+16y8wiIsUfNx4V0TPpEfB/ZVSh1B/b1hOOSpieJ50TqtLZHtrIab7myYixfMOZIbbRVwtgWWRJCrEWnPo7A3Obo5DhED0EdwIIQKCHq8KEOc7eCumr1G4GUg7e7AQoF34Vp9ytsX6blr++YGhG2K18u2/DloQWP5bQfGxDw9UwYhpwGL5TqJ96SwgONEXhL+hXdLlUyZDwvf04jwtG4fmnwSqzLY3nybOa11NqUXEbahDQ+xVzOJoYZh0epVd1uegW8eiQqA4Zz1hSzKIk2DrzyB/Km9MvwqNSvEXXcd3oiIqJEgpAx6iVcr+n6nn6cUE9GkefjvviPlVdmTHXnTQuiiOL/YkoTBIDkDr6j9YnRHu+V888mlgnIqiagug4biiSpMEgLz2oRUuZwUA09LXLC+ZUujaX9qgL+myDGIKf5GcapUZ6JpmUPOKLU71+e7PPb0Fic2AUMvYdIks91h5Nz4tCoiMb2HS5C+92FzjZ0CMTtKbLTRUgXv5VkLM69vRoeuhZSt2658rQG9tL4oFyE9RPwM/55jzlHKHtw2+1In1qmicbnDPCr3GhbVkAqnzoLeeCkWZk+zGnLBQxtxYskVIQ80+Kt/ZQqhhcqHq/1FHck+XpYZ5V3RnyYFWw1zQqeqxZTLiftlKGeiMqLJNYsFhS/62Y4UcB/6ph2srl8mM22Hw/ht4ibhLNjmYUiGMPVMaPasAeIqKsrrEph3G3crY6pcO3497MYizxmOt4lVnp D4ucP12Y 5+KMVB5LYcZC5dJOF6aQ/rOi0i+54MYGGSf9pdyTOWUVbzVUf+VeF3m4/zoe80v0G1lKWf3eVr5MwWNw4BNrp1zW5V10lqJ9ejSjjo6bSvUAgpL0= 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 --- include/linux/pagemap.h | 8 ++++++++ mm/filemap.c | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index fc8eb9c94e9c..fe8e1fbb667d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1328,6 +1328,14 @@ struct readahead_control { ._index = i, \ } +#define DEFINE_READAHEAD_ALIGNED(ractl, f, r, m, i) \ + struct readahead_control ractl = { \ + .file = f, \ + .mapping = m, \ + .ra = r, \ + ._index = mapping_align_start_index(m, i), \ + } + #define VM_READAHEAD_PAGES (SZ_128K / PAGE_SIZE) void page_cache_ra_unbounded(struct readahead_control *, diff --git a/mm/filemap.c b/mm/filemap.c index 2b00442b9d19..bdf4f65f597c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2478,11 +2478,11 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, struct file *filp = iocb->ki_filp; struct address_space *mapping = filp->f_mapping; struct file_ra_state *ra = &filp->f_ra; - pgoff_t index = iocb->ki_pos >> PAGE_SHIFT; - pgoff_t last_index; + pgoff_t index, last_index; struct folio *folio; int err = 0; + index = mapping_align_start_index(mapping, iocb->ki_pos >> PAGE_SHIFT); /* "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); retry: @@ -2500,8 +2500,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; @@ -3093,7 +3092,7 @@ 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); + DEFINE_READAHEAD_ALIGNED(ractl, file, ra, mapping, vmf->pgoff); struct file *fpin = NULL; unsigned long vm_flags = vmf->vma->vm_flags; unsigned int mmap_miss; @@ -3147,7 +3146,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) ra->start = max_t(long, 0, vmf->pgoff - ra->ra_pages / 2); ra->size = ra->ra_pages; ra->async_size = ra->ra_pages / 4; - ractl._index = ra->start; + ractl._index = mapping_align_start_index(mapping, ra->start); page_cache_ra_order(&ractl, ra, 0); return fpin; } @@ -3162,7 +3161,7 @@ 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); + DEFINE_READAHEAD_ALIGNED(ractl, file, ra, file->f_mapping, vmf->pgoff); struct file *fpin = NULL; unsigned int mmap_miss; @@ -3211,11 +3210,12 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) struct file *fpin = NULL; struct address_space *mapping = file->f_mapping; struct inode *inode = mapping->host; - pgoff_t max_idx, index = vmf->pgoff; + pgoff_t max_idx, index; struct folio *folio; vm_fault_t ret = 0; bool mapping_locked = false; + index = mapping_align_start_index(mapping, vmf->pgoff); max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); if (unlikely(index >= max_idx)) return VM_FAULT_SIGBUS; @@ -3321,7 +3321,10 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) return VM_FAULT_SIGBUS; } - vmf->page = folio_file_page(folio, index); + VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping), + folio); + + vmf->page = folio_file_page(folio, vmf->pgoff); return ret | VM_FAULT_LOCKED; page_not_uptodate: @@ -3657,6 +3660,7 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, struct folio *folio; int err; + index = mapping_align_start_index(mapping, index); if (!filler) filler = mapping->a_ops->read_folio; repeat: