* [PATCH v1] mm/readahead: Do not allow order-1 folio
@ 2023-12-01 16:10 Ryan Roberts
2023-12-01 16:32 ` Matthew Wilcox
0 siblings, 1 reply; 2+ messages in thread
From: Ryan Roberts @ 2023-12-01 16:10 UTC (permalink / raw)
To: Matthew Wilcox (Oracle), Andrew Morton
Cc: Ryan Roberts, linux-fsdevel, linux-mm
The THP machinery does not support order-1 folios because it requires
meta data spanning the first 3 `struct page`s. So order-2 is the
smallest large folio that we can safely create.
There was a theoretical bug whereby if ra->size was 2 or 3 pages (due to
the device-specific bdi->ra_pages being set that way), we could end up
with order = 1. Fix this by unconditionally checking if the preferred
order is 1 and if so, set it to 0. Previously this was done in a few
specific places, but with this refactoring it is done just once,
unconditionally, at the end of the calculation.
This is a theoretical bug found during review of the code; I have no
evidence to suggest this manifests in the real world (I expect all
device-specific ra_pages values are much bigger than 3).
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
mm/readahead.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/mm/readahead.c b/mm/readahead.c
index 6925e6959fd3..23620c57c122 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -511,16 +511,14 @@ void page_cache_ra_order(struct readahead_control *ractl,
unsigned int order = new_order;
/* Align with smaller pages if needed */
- if (index & ((1UL << order) - 1)) {
+ if (index & ((1UL << order) - 1))
order = __ffs(index);
- if (order == 1)
- order = 0;
- }
/* Don't allocate pages past EOF */
- while (index + (1UL << order) - 1 > limit) {
- if (--order == 1)
- order = 0;
- }
+ while (index + (1UL << order) - 1 > limit)
+ order--;
+ /* THP machinery does not support order-1 */
+ if (order == 1)
+ order = 0;
err = ra_alloc_folio(ractl, index, mark, order, gfp);
if (err)
break;
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v1] mm/readahead: Do not allow order-1 folio
2023-12-01 16:10 [PATCH v1] mm/readahead: Do not allow order-1 folio Ryan Roberts
@ 2023-12-01 16:32 ` Matthew Wilcox
0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2023-12-01 16:32 UTC (permalink / raw)
To: Ryan Roberts; +Cc: Andrew Morton, linux-fsdevel, linux-mm
On Fri, Dec 01, 2023 at 04:10:45PM +0000, Ryan Roberts wrote:
> The THP machinery does not support order-1 folios because it requires
> meta data spanning the first 3 `struct page`s. So order-2 is the
> smallest large folio that we can safely create.
>
> There was a theoretical bug whereby if ra->size was 2 or 3 pages (due to
> the device-specific bdi->ra_pages being set that way), we could end up
> with order = 1. Fix this by unconditionally checking if the preferred
> order is 1 and if so, set it to 0. Previously this was done in a few
> specific places, but with this refactoring it is done just once,
> unconditionally, at the end of the calculation.
>
> This is a theoretical bug found during review of the code; I have no
> evidence to suggest this manifests in the real world (I expect all
> device-specific ra_pages values are much bigger than 3).
>
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
It's better code anyway!
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-01 16:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-01 16:10 [PATCH v1] mm/readahead: Do not allow order-1 folio Ryan Roberts
2023-12-01 16:32 ` Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox