Alternative to sysconf(_SC_AVPHYS_PAGES) to get available memory?

Hi all,

I'm just trying to compile osm2rdf (osm map data to GeoSPARQL), and found that
they use sysconf(_SC_AVPHYS_PAGES) to get available memory:

C++:
int64_t available() {
 return sysconf(_SC_AVPHYS_PAGES) * sysconf(_SC_PAGE_SIZE);
}

Looking at sysconf(3) I can see that we do not have _SC_AVPHYS_PAGES. I searched
for alternatives, but did not find any. I also did not find anything like
"available" memory in sysconf(3).

So, can anyone tell me a FreeBSD alternative to sysconf(_SC_AVPHYS_PAGES)?

Thanks,

Mathias
 
I usually replace such mechanisms with an environment variable.

It is a really bad idea to question the system for memory at some point in time not knowing what additional memory demand will come along from other software.
 
My apologies for necro-posting. I ran into a similar issue with `_SC_AVPHYS_PAGES` not being defined in sysconf(3). Whilst grepping around in the ports tree I found this solution, which is a patch in the graphics/igt-gpu-tools port to solve this issue.

It is strange that this sysconf call is not supported by FreeBSD as both OpenBSD and NetBSD do support this sysconf call.
 
It's also strange that OpenBSD doesn't provide POSIX interval timers (timer_create(2)) while FreeBSD and NetBSD do ... ? (edit: just a random portability issue I ran into recently ... I'm sure you find lots of other similar examples, after all, we're talking about different operating systems)

But as cracauer@ stated, it's a bad idea to base any decisions on that anyways. I'd argue it would be better to patch out the entire logic instead of finding another way to obtain this data. It's only useful for monitoring purposes.
 
Back
Top