88 lines
3.1 KiB
C
88 lines
3.1 KiB
C
// Kernel file-page cache declarations.
|
|
// Caches PAGE_SIZE file pages shared by reads, mmap faults, and writeback.
|
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <kernel/mm_phys.h>
|
|
#include <ntlite/status.h>
|
|
|
|
struct FILE_OBJECT;
|
|
typedef struct FILE_OBJECT FILE_OBJECT;
|
|
struct IO_VOLUME;
|
|
typedef struct IO_VOLUME IO_VOLUME;
|
|
|
|
typedef struct MM_FILE_CACHE_PAGE {
|
|
FILE_OBJECT* File;
|
|
uint64_t Offset;
|
|
PHYSICAL_ADDRESS Frame;
|
|
uint32_t ValidBytes;
|
|
uint8_t Dirty;
|
|
} MM_FILE_CACHE_PAGE;
|
|
|
|
typedef struct MM_FILE_CACHE_STATS {
|
|
uint64_t Lookups;
|
|
uint64_t Hits;
|
|
uint64_t Misses;
|
|
uint64_t Loads;
|
|
uint64_t LoadFailures;
|
|
uint64_t RaceDiscards;
|
|
uint64_t InflightWaits;
|
|
uint64_t Invalidations;
|
|
uint64_t DirtyPages;
|
|
uint64_t MaxDirtyPages;
|
|
uint64_t DirtyMarks;
|
|
uint64_t WritebackRequests;
|
|
uint64_t WritebackPages;
|
|
uint64_t WritebackBytes;
|
|
uint64_t WritebackFailures;
|
|
uint64_t FlushFileCalls;
|
|
uint64_t FlushFileFailures;
|
|
uint64_t MappedDirtySyncs;
|
|
uint64_t MappedDirtyPages;
|
|
uint64_t Drops;
|
|
uint64_t DropFailures;
|
|
uint64_t StandbyTransitions;
|
|
uint64_t StandbyHits;
|
|
uint64_t ResidentPages;
|
|
uint64_t ActivePages;
|
|
uint64_t StandbyPages;
|
|
uint64_t MaxResidentPages;
|
|
} MM_FILE_CACHE_STATS;
|
|
|
|
// Returns a retained physical frame containing the file page at page-aligned
|
|
// offset. The caller owns one PFN reference and must call
|
|
// MmFileCacheReleasePage(). Bytes beyond ValidBytes are zero-filled.
|
|
KSTATUS MmFileCacheGetPage(FILE_OBJECT* file, uint64_t offset, MM_FILE_CACHE_PAGE* outPage);
|
|
void MmFileCacheReleasePage(MM_FILE_CACHE_PAGE* page);
|
|
|
|
// Returns a retained coherent cache page suitable for a shared writable mapping.
|
|
KSTATUS MmFileCacheGetWritablePage(FILE_OBJECT* file, uint64_t offset,
|
|
uint64_t fileSizeBefore, bool needExistingBytes,
|
|
MM_FILE_CACHE_PAGE* outPage);
|
|
|
|
// Marks one coherent cache page dirty after a shared writable mapping is written.
|
|
void MmFileCacheMarkDirty(FILE_OBJECT* file, uint64_t offset, uint32_t validBytes);
|
|
|
|
// Writes into coherent cached file pages and marks them dirty.
|
|
KSTATUS MmFileCacheWrite(FILE_OBJECT* file, uint64_t offset, const void* buf,
|
|
size_t size, uint64_t fileSizeBefore, size_t* writtenOut);
|
|
|
|
// Flushes dirty cached pages for one file.
|
|
KSTATUS MmFileCacheFlushFile(FILE_OBJECT* file);
|
|
KSTATUS MmFileCacheFlushAll(void);
|
|
|
|
// Drops cached clean pages overlapping the byte range. Dirty pages are flushed
|
|
// by callers before destructive metadata operations.
|
|
void MmFileCacheInvalidate(FILE_OBJECT* file, uint64_t offset, size_t size);
|
|
void MmFileCacheInvalidateAll(FILE_OBJECT* file);
|
|
void MmFileCacheDiscardVolume(IO_VOLUME* volume);
|
|
|
|
// Reclaims one cache-owned page if possible. Safe to call under memory pressure;
|
|
// it never writes back because v1 stores only clean file data.
|
|
KSTATUS MmFileCacheDropOnePageForPressure(void);
|
|
|
|
void MmFileCacheQueryStats(MM_FILE_CACHE_STATS* out);
|