OK, just a follow up on my question:
I'm developing a server which caches many small files in memory.
Suppose most files are about 4K in size, so I think the most efficient
way to cache them would be to mmap() a large segment of memory and
then divide it into 4K chunks. To reduce TLB misses, memory mapping
should be done with large pages, say 512K (Sparc).
I'm looking at chapter 13 (Working with multiple page sizes) of "Solaris
Internals" book. It seems to suggest that to get what I want I need to
do the following:
/* Align on 512K */
#define ALIGN_512K 1024*512
/* Request 1MB */
#define ADDR_LEN 1024*512*2
void *mem_ptr;
struct memcntl_mha mha;
/* Allocate 1MB via mmap() */
mem_ptr = mmap((caddr_t)ALIGN_512K, ADDR_LEN, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | MAP_ALIGN, -1, 0);
/* Use memcntl() to request 512K pages */
mha.mha_cmd = MHA_MAPSIZE_VA;
mha.mha_flags = 0;
mha.mha_pagesize = ALIGN_512K;
memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mha, 0, 0);
So in theory, when I access memory via mem_ptr the system will get a
page fault and should allocate 512K page.
What I'm not sure about is the following:
How do I make sure that memory is mapped with the page size I
requested? What if system decides to map with 8K pages instead, i.e. can
this happen even if memory address is aligned on 512K boundary?
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code