[systemd-devel] [PATCH] Detect page size runtime

Lennart Poettering lennart at poettering.net
Fri Mar 18 19:10:28 PDT 2011


On Fri, 18.03.11 03:44, fykcee1 at gmail.com (fykcee1 at gmail.com) wrote:

> Hi all,
> 
> Systemd hardcode page size as 4096(in macro.h), this is not always correct:
> """ Some architectures support multiple machine types with diffenent
> page sizes, and some machine types even support multiple page sizes
> themselves. """
> 
> This patch tries to detect page size runtime by sysconf(_SC_PAGESIZE),
> and uses 4096 as a failsafe value. Note we need memset vec to zero
> before call mincore(src/readahead-collect.c, 129) -- if the pagesize
> is not correct, we may randomly record wider range or more ranges to
> readahead.

Hmm, interesting. Which architecture are you using that has a page size
!= 4K?

Please move the definition of ALIGN and page_size() and friends into
util.[ch], rather the the .c files using them.

"size_t get_pagesize();" is not a valid C99 function prototype. Please
use "(void)" for an empty parameter list, not "()".

I think it would be a really bad idea to warn each time
sysconf(_SC_PAGESIZE) might fail. Also, I'd prefer not having two
indirections here, so please cache the result in a function-internal
static variable, so that we don't have to call sysconf() all the
time. Use __tls on the variable, since clients might end up using
threads and I'd prefer if we never have to think much about
thread-safety of these calls if they cache stuff in static variables.

Otherwise looks fine!

Thanks,

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list