cachestat, one of the novelties that will be presented in Linux 6.5

Tux, the mascot of the Linux Kernel

The Linux kernel is the backbone of Linux operating systems (OS), and is the fundamental interface between a computer's hardware and its processes.

Last week work began on what will be the next version of the Linux Kernel 6.5 and since then some of the most relevant changes that will be presented in this next Kernel release have already begun to be revealed .

For example, a large number of improvements and changes have already been integrated, such as parallel CPU boot support with the aim of significantly reducing kernel boot times. Also, regarding the changes at AMD, it is mentioned that they have been diligently addressing system suspend/resume issues. In addition, improvements to file systems, virtualization, and more are also highlighted.

Of the announced changes, we will discuss one of them in this article, which is mentioned as having already been included in the codebase being built from the Linux 6.5 kernel and has been integrated with the implementation of a new system call "cachestat".

This patch series introduces a new system call, cachestat, which summarizes cache page statistics (number of cached pages, pages marked for rewriting, pages evicted, etc.) for a file within a specified byte range. It also includes a self-test suite that tests for some typical usage.

About cachestat

Cachestat is a new syscall that allows user-space programs to query more detailed statistics of the kernel-side page cache. As such, it aims to extend the existing "mincore" system call used to determine if pages are present in memory. The "cachestat" call allows for querying more detailed page cache statistics and aims for greater scalability.

It is mentioned that currently the page cache is usually the largest consumer of memory , and therefore the kernel methods that manage it have a significant impact on performance. As such, there is a rich interface to augment these methods with fadvise and the synchronization family.

The "cachestat()" system call sends information about the number of cached pages, dirty pages, evicted pages, recently evicted pages, and pages marked for rewriting.

The statistics provided for the files allow for more accurate decisions regarding I/O work that goes through the VFS, based not only on an abstract algorithm, but also taking into account the characteristics of a particular system at a given time.

There is currently no good way to query the state of the large cache page file sets and directory trees. There is mincore(), but it scales badly:
the kernel writes a large amount of bitmap data that userspace has to add it, when the user doesn't really care about the information per page
then. The user also needs to mmmap and deallocate each file as it goes throughout, which can also be quite slow.

The following are some possible use cases for cachestat() in applications :

  • The query scheduler in the DBMS will be able to decide whether to perform an index scan or directly read the data from the table based on the state of the table's index in the page cache.
  • Granular and load dependent handling of page cache fill and I/O (for example, dirty pages/pages marked for rewrite), changing the sync frequency, from very frequent under light load to bursty during bursts of load.
  • Possibility of a more visual presentation and convenient display of memory usage information on large files/directories, similar to how the "du" utility allows you to display disk space usage.
  • Easier troubleshooting and debugging of lazy writes for performance issues.

Finally, if you are interested in learning more about this , you can find the details at the following link.


Add as preferred source in Google