Depending on the file offset, one more memory page may be allocated in the buffer cache than required to hold the size passed in a read request. The reason is that the buffer cache maps sectors to memory pages starting at logical sector 0, but there are file systems that start data blocks at file system offsets that are not a multiple of the page size.
One such file system is MSDOSFS, which consists of a meta data area consisting of any required number of sectors, followed by a data area consisting of clusters of sectors. This data area may start at a sector number that is not a multiple of the number of sectors per cluster. In this case, a request to read a cluster will put the first requested sector of a cluster into the buffer cache memory page at an offset > 0, and in case of 64KB clusters may need to allocate one more memory page than required for 64KB.
This lead to kernel panics when built with INVARIANTS (or internal data corruption without), see PR #277414 which was addressed in commit 7e4ac11b6076e6a9b by returning an error code instead.
This review remaps sectors read from a MSDOSFS to align the start of a cluster with offset 0 of a buffer cache memory page.
A cluster size of 128 will thus fit into 64KB worth of memory pages in the buffer cache.
The patch introduces a new macro (bntocbn) that adds a file system specific offset to the physical block number to obtain a logical block number for indexing of the block in the buffer cache. This offset is calculated when the file system is mounted, based on the first data block of the file system and the PAGE_SIZE.
Besides preventing a crash (or read error after commit 7e4ac11b6076e6a9b), this reduces the amount of pages allocated per cluster by 1 in the general case.