Is it possible to know in advance which pages of a mapped file are already in RAM? In Linux there is mincore for this question. It returns a small map, where the page corresponds to one byte, and the least significant bit indicates residency. The map seems to be a convenient prediction of the next read: one means ready, zero means future delay. But in this retelling, the observation quietly turned into a promise. The state of the page can change, the mapping’s permissions can change, and the disclosure mechanism itself has limitations. To read a map correctly, you need to preserve the exact meaning of its question.
Let’s start with scale. A page is not equal to one program object, one file, or one array row. This is a unit of virtual memory whose size should be obtained from the system. For regular pages, you can’t just permanently write a familiar number from your own machine into portable code. mincore(2) manual suggests sysconf with the _SC_PAGESIZE parameter. Next, the program matches virtual addresses with pages of this size. The explanation below assumes regular mappings and regular pages; huge pages have additional implementation details that the short byte picture itself does not reveal.
The address of the start of the range must be aligned to the page size. The length may not be evenly divided by it: the affected last page still gets its place in the result. Therefore, the number of map bytes needed is determined by rounding the length up to the number of pages. This rounding applies to the scope of observation, not the volume of user data. If the range ends in the middle of the page, mincore does not begin to distinguish between its left and right halves. One entry still reports the state of the entire page containing the last byte of the range.
Let’s take a hypothetical system with a page size of 4096 bytes. For an aligned range of 9000 bytes in length, three bytes of result are needed. The last entry refers to a page that is only partially occupied by the range. If the least significant bits are 1, 0, 1, it cannot be concluded that exactly two-thirds of the 9000 user bytes are in RAM. We know of two resident pages out of three affected. Moving from page observation to useful content counting requires taking into account the intersection of the range with each page. Even such a neat sum does not say anything about memory ownership.
The expression vec[i] & 1 should be read. The interface does not define the remaining bits of the byte for this purpose. Comparing an entire byte to one may occasionally work on a given implementation, but introduces unnecessary assumptions. This is a small detail with great methodological significance: the program should extract the flag promised by the interface, and not guess the internal format based on a successful output. A successful call returns zero as function status; a zero least significant bit of an individual map element means something else. Mixing these zeros in the result processing is especially easy when you first get acquainted with the API.
A failed call returns minus one and sets errno. For example, an unaligned address would result in EINVAL, while a range with unmapped memory would result in ENOMEM. This is not a measurement of the percentage of cold pages. The program did not receive a successful map and should not fill in missing responses with zeros as if the kernel had confirmed non-residence. It is also important to correctly allocate the buffer of the result itself: it must accommodate the calculated number of bytes. No amount of precision in subsequent analysis corrects the error in which an observation was initially recorded in the wrong region.
The file page may be closer than it seems
Now the interesting part: the file data may already be in the page cache, although the particular process has not yet read the page in its mapping. They may have been recently read by another process. For a suitable file mapping, mincore is able to report this residency. But the local page table of the calling process may still require processing of the first access. Therefore, one is not a universal proof of the absence of any page fault. Some faults can be serviced without reading data from the drive: you need to set the mapping to an existing page or perform other memory management work.
It is useful to distinguish these events in words. Major fault is usually associated with the need to load data; minor fault can be handled without such I/O operation. However, the mincore map is not a complete model of future major and minor faults and does not return their measured quantities. In particular, writing to a private mapping can cause copy-on-write. The original page was resident, but the write needed its own copy. The question “is the required content in RAM now?” is narrower than the question “what work will my next request of a given type cause?”
Linux source code mm/mincore.c, reviewed November 2, 2026, helps to see this gap. The implementation considers different types of page table entries and the state of the file cache, rather than reducing the response to a single present bit for each virtual address. You cannot generalize details of the current master branch to any installed kernel without checking the version. But the code itself is useful as a primary source that keeps the explanation from being too simple a "one means the process has already touched bytes" picture. The interface does not promise such information.
The private mapping of a file after writing has one more difference. The modified page can become its own anonymous copy of the process, while the original file retains the same content. The residency of a virtual range and the residency of specific source file pages are no longer automatically the same. To interpret a map, you need to know what mapping is actually being examined and what was done with it. This is not a requirement to remember the entire program biography for every byte; this is the need to not pass off one observation type as another when the MAP_PRIVATE semantics have already changed the origin of the data.
Anonymous memory also does not turn mincore into a chip-quality tester. The map describes the state of the virtual range as reported by the operating system. It does not test DRAM charge retention, measure controller read latency, or check ECC. Two set bits for different pages may correspond to significantly different behavior of the next computation due to CPU caches, NUMA layout, and other reasons. The access time cannot be reconstructed from the presence of content alone. Residency is useful precisely as a specific property, and not as a shorthand for all the characteristics of memory.

The file map also has a deliberate observation limitation. In the tested Linux source, the can_do_mincore function allows disclosure for anonymous mappings and checks the corresponding permissions for file ones. If the process fails the intended check for ownership, authority, or writability of the file, the implementation may fill the result with ones instead of revealing the actual state of the page cache. The reason is stated in the comment: otherwise, shared file mappings allow the construction of an observation side channel. This means that apparently full residency sometimes speaks about the disclosure policy, and not about the actual presence of all data in memory.
This is a significant caveat for a utility that shows an attractive warm-up percentage. A successful return of mincore alone is not enough to accept all ones as a valid cache measurement in any context. You need to know file permissions, kernel version behavior, and mapping conditions. Moreover, reading such a rule does not give grounds to declare any complete map artificial. For your own suitable file, the information can be quite meaningful. Interpretation requires establishing a specific branch of behavior, rather than replacing overconfidence with an equally excessive rejection of the entire interface.
The snapshot continues to age
Even with full disclosure, the map does not freeze the pages. While traversing the first and last sections of the range, the system can continue to operate; after the call returns, reclaim is able to free unpinned pages, and reads by other processes can fill the cache. The manual explicitly states that the result may be out of date by the time it is returned. Therefore, the expression “the state of all memory exactly at this nanosecond” promises more than what the caller got. It is especially important to understand the large range as an observation made, and not as a general atomic portrait of all its pages.
If a program wants to compare two snapshots, it should store the time, range, page size, and mapping properties along with the map. Otherwise, a change in the length of a file or a study area will easily turn into an apparent change in residency. The sequence 1 → 0 → 1 in the stored results shows different observations, but does not tell how many times the state changed between them. You cannot recover the number of evictions or the volume of disk reads by simply counting switches. During the interval, additional events could have occurred that none of the snapshots had time to see.
Even stable ones do not mean that the contents are unchanged. Another process is able to write to a shared file or shared memory while maintaining page residency. The conditions for consistent data reading are specified by a separate protocol. Mincore is not a file lock, file snapshot, or thread synchronization mechanism. Description of mmap(2) is important here specifically for understanding mapping and access. The presence map does not replace the agreement about who has the right to change the observed bytes and when.
Another common question is: is it possible to go through the range in advance and make all the pages warm? Accessing the range in advance can change the state of memory, but this is an action, not a mincore observation. It itself consumes resources and can crowd out other useful data. Moreover, after warming up, the system has the right to change the state of unpinned pages again. If a task requires a special retention guarantee, it must be formulated in terms of suitable mechanisms and their limitations. The byte map does not provide such a guarantee even when it shows the desired set of ones.
For studying application behavior, mincore is still valuable. It allows you to ask a narrow question about a selected mapped range and repeat the observation under known conditions. For example, you can compare maps before and after a hypothetical phase of work, without passing off the resulting difference as a complete memory-access trace. The editors did not conduct such an experiment here. A possible setup of the experiment is described in order to separate the measured characteristic from the invented conclusions about it. A real report would have to indicate the kernel, the file, the permissions, the range size, the sequence of actions and the observed results.
Observation itself also has a cost. Traversing a large range, allocating and filling the result buffer, saving maps and analyzing them are not free. Mincore is not designed to predict the fate of every call in an application’s hot loop. The more often a program requires snapshots, the more work it adds to the process it is trying to understand. This is not a universal argument for ditching the tool; this is part of choosing the scale. A useful question is asked at such a range and with such frequency that the answer helps explain the work rather than creating a noticeably new part of it.
Returning to the original question about RAM, we can now read the map without unnecessary promises. It refers to an aligned virtual range, uses a specific result bit, and depends on the mapping properties and permissible information disclosure. A useful snapshot reports residency during observation. The next access belongs to the future state of the system. It is this time distance that should be preserved in the name of the indicator, the caption of the chart and the decisions of the program that expects to use it to guess the cost of a future read.



