Skip to content

Commit

Permalink
small changes to display, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
FRex committed Jul 1, 2019
1 parent 6a0b6ca commit 69f84b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A small C program to try keep a single file in Windows RAM cache.

Takes a single filename as argument, opens the file as read only and memory
maps it whole, then accesses each 4 KiB page of it to bring the file into memory
and then sleeps for 10 seconds and accesses them again to keep them in memory.
and then sleeps for 30 seconds and accesses them again to keep them in memory.

**It never quits so you'll have to somehow kill it once you are done.**

Expand Down
25 changes: 21 additions & 4 deletions rampin.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,38 @@ static void * memorymapfile(const wchar_t * fname, s64 * fsize)
return ptr;
}

static double mytime(void)
{
LARGE_INTEGER freq, ret;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&ret);
return ((double)ret.QuadPart) / ((double)freq.QuadPart);
}

static void touchbytes(void * ptr, s64 size, const wchar_t * fname)
{
unsigned char * p = ptr;
s64 i;
double starttime;
unsigned ret = 0u;
int firstrun = 1;

starttime = mytime();
while(1)
{
for(i = 0; i < size; i += 0x0100)
for(i = 0; i < size; i += 0x1000)
ret += p[i];

if(firstrun)
wprintf(L"%ls: touched all %lld pages once, sleeping 9999ms and looping...\n", fname, i / 0x0100);
{
const double elapsedtime = mytime() - starttime;
wprintf(L"%ls: touched, %lld bytes, %.3f MiB, 0x%p, %.3fs, %.3f MiB/s\n",
fname, size, size / (1024.0 * 1024.0), ptr,
elapsedtime, size / (elapsedtime * 1024.0 * 1024.0)
);
} /* if firstrun */

Sleep(9999);
Sleep(30 * 1000);
firstrun = 0;
}
}
Expand All @@ -61,7 +77,8 @@ int wmain(int argc, wchar_t ** argv)
ptr = memorymapfile(argv[1], &s);
if(ptr)
{
wprintf(L"%ls: mapped %lld bytes (%lld MiB) at 0x%p, touching all pages...\n", argv[1], s, s / (1024 * 1024), ptr);
wprintf(L"%ls: mapped, %lld bytes, %.3f MiB, 0x%p, touching all pages...\n",
argv[1], s, s / (1024.0 * 1024.0), ptr);
touchbytes(ptr, s, argv[1]);
}
else
Expand Down

0 comments on commit 69f84b7

Please sign in to comment.