On Tue, Nov 5, 2024 at 12:21 PM Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote: > > On Tue, Nov 05, 2024 at 11:01:01AM +0800, Yafang Shao wrote: > > Upon further analysis, it appears that the behavior depends on the > > /sys/block/*/queue/read_ahead_kb setting. On my test server, this > > parameter is set to 128KB. For the current approach to work without > > modification, it would need to be 2MB-aligned. > > > > However, I believe MADV_HUGEPAGE behavior should not be dependent on > > the value of read_ahead_kb. It would be more robust if the kernel > > automatically aligned it to 2MB when MADV_HUGEPAGE is enabled. The > > following changes ensure compatibility with non-2MB-aligned > > read_ahead_kb values: > > or maybe: > > static unsigned long get_next_ra_size(struct file_ra_state *ra, > unsigned long max) > { > unsigned long cur = ra->size; > > if (cur < max / 16) > return 4 * cur; > if (cur <= max / 2) > return 2 * cur; > + if (cur > max) > + return cur; > return max; > } > It is better. Thanks for your suggestion. -- Regards Yafang