2001-03-03 18:45:07

by Denis Perchine

[permalink] [raw]
Subject: Q: How to get physical memory size from user space without proc fs

Hello,

actually the question is in subj.
Problem is that there is a program which needs to know physical memory
size. This information is used to justify memory consumption as after some
swapping performance is drops dramatically, and it is better to finish.

I know that this is not the best idea, but it is assumed that this program
is the only one running on the machine.

I do not want to use proc as some people can just do not mount it.

Any comments, suggestions?

Thanks in advance.

Denis Perchine.




2001-03-03 18:55:07

by Michael Rothwell

[permalink] [raw]
Subject: Re: Q: How to get physical memory size from user space without proc fs

pyhsmem = `free | grep Mem | tr -s "/ / /" | cut -f2 -d" "`


On 03 Mar 2001 13:37:42 -0500, Denis Perchine wrote:
> Hello,
>
> actually the question is in subj.
> Problem is that there is a program which needs to know physical memory
> size. This information is used to justify memory consumption as after some
> swapping performance is drops dramatically, and it is better to finish.
>
> I know that this is not the best idea, but it is assumed that this program
> is the only one running on the machine.
>
> I do not want to use proc as some people can just do not mount it.
>
> Any comments, suggestions?
>
> Thanks in advance.
>
> Denis Perchine.
>
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

2001-03-03 19:14:07

by Alexander Viro

[permalink] [raw]
Subject: Re: Q: How to get physical memory size from user space without proc fs



On Sat, 3 Mar 2001, Denis Perchine wrote:

> Hello,
>
> actually the question is in subj.
> Problem is that there is a program which needs to know physical memory
> size. This information is used to justify memory consumption as after some
> swapping performance is drops dramatically, and it is better to finish.
>
> I know that this is not the best idea, but it is assumed that this program
> is the only one running on the machine.
>
> I do not want to use proc as some people can just do not mount it.
>
> Any comments, suggestions?

In initscripts create a directory with mode=700. Create a subdirectory there.
Mount procfs on it. Get the information. umount. rmdir. rmdir. Put that
information into /etc. Let your program use that as config file.

If attacker is able to traverse root-owned directory with rwx------ when
initscripts are run he won't gain anything new from accessing procfs, since
he already can do whatever he bloody wants.

Besides, that way it's easy to port to non-Linux boxen - all system
dependencies are in the way to have /etc/memsize set by the time when
your program is run. Which can be done by echo/ed/vi/whatever.
Cheers,
Al

2001-03-03 19:18:18

by Alexander Viro

[permalink] [raw]
Subject: Re: Q: How to get physical memory size from user space without proc fs



On 3 Mar 2001, Michael Rothwell wrote:

> pyhsmem = `free | grep Mem | tr -s "/ / /" | cut -f2 -d" "`

% strace free 2>&1 |grep /proc
open("/proc/cpuinfo", O_RDONLY) = 3
open("/proc/uptime", O_RDONLY) = 3
open("/proc/stat", O_RDONLY) = 4
open("/proc/meminfo", O_RDONLY) = 5

I.e. it still uses procfs. Which is perfectly fine, just encapsulate
it in initscripts so that information would be obtained when system
is booted. Should work for people who don't want procfs around after
that.
Cheers,
Al