lkml.org 
[lkml]   [2000]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Adaptive thread creation by the kernel
On Wed, 2 Feb 2000, Jamie Lokier wrote:
> Chuck Lever wrote:
> > this is exactly what an interface like mincore() is designed for. the
> > application, or an underlying threads library, can use it to avoid page
> > faults that would block all the threads running in an address space.
>
> You want to read part of one of your mmap()ed files. How do you check
> if it's going to fault?

usually like this:

int fd;
void * map;
char vec[VEC_SIZE];

fd = open("/your/file, O_RDONLY);
if (fd == -1) {
perror("open");
exit(-1);
}

map = mmap(0, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
if (!map) {
perror("mmap");
close(fd);
exit(-1);
}

if (mincore(map, readlength, vec))
perror("mincore");

the vec[] contains a byte for each page you queried. each byte has value
"1" if the page is already in memory, otherwise "0".

- Chuck Lever
--
corporate: <chuckl@netscape.com>
personal: <chucklever@netscape.net> or <cel@monkey.org>

The Linux Scalability project:
http://www.citi.umich.edu/projects/linux-scalability/


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:56    [W:0.081 / U:0.896 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site