* Re: Environment variables inside the kernel?
2005-08-18 15:44 Environment variables inside the kernel? Guillermo López Alejos
@ 2005-08-18 16:02 ` linux-os (Dick Johnson)
2005-08-18 16:03 ` jerome lacoste
` (2 subsequent siblings)
3 siblings, 0 replies; 17+ messages in thread
From: linux-os (Dick Johnson) @ 2005-08-18 16:02 UTC (permalink / raw)
To: Guillermo López Alejos; +Cc: Linux Kernel mailing list
On Thu, 18 Aug 2005, [iso-8859-1] Guillermo López Alejos wrote:
> Hi,
>
> I have a piece of code which uses environment variables. I have been
> told that it is not going to work in kernel space because the concept
> of environment is not applicable inside the kernel.
>
> I belive that, but I need to demonstrate it. I do not know how to
> proof this, perhaps referring to a solid reference about Linux design
> that points to the idea that it has no sense to use environment
> variables in kernel space.
>
> Do anyone knows about the existence of such document?
>
> Thank you,
>
> --
> Guillermo
You have to ask yourself, "What environment?". And, what it would
be used for.
Environment variables are some strings that exist in a processes'
name-space. The kernel is not a process. There are some strings
in the kernel, mostly relating to error messages, but there is
no conceptual use for an 'environment'. Since the kernel performs
functions on behalf of calling tasks, at that time, its environment
is the environment of the caller.
Now, there are environment strings set up for the very first
task by the kernel. This environment normally becomes the
environment of 'init'. (/usr/src/linux-`uname -r`/init/main.c)
This is just a "place-holder" and currently contains "HOME=/"
and "TERM=linux".
Cheers,
Dick Johnson
Penguin : Linux version 2.6.12.5 on an i686 machine (5537.79 BogoMips).
Warning : 98.36% of all statistics are fiction.
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: Environment variables inside the kernel?
2005-08-18 15:44 Environment variables inside the kernel? Guillermo López Alejos
2005-08-18 16:02 ` linux-os (Dick Johnson)
@ 2005-08-18 16:03 ` jerome lacoste
2005-08-18 16:12 ` Ingo Oeser
2005-08-18 16:37 ` Douglas McNaught
3 siblings, 0 replies; 17+ messages in thread
From: jerome lacoste @ 2005-08-18 16:03 UTC (permalink / raw)
To: Guillermo López Alejos; +Cc: Linux Kernel mailing list
[I doubt this is the right list to ask this question.]
On 8/18/05, Guillermo López Alejos <glalejos@gmail.com> wrote:
> Hi,
>
> I have a piece of code which uses environment variables. I have been
> told that it is not going to work in kernel space because the concept
> of environment is not applicable inside the kernel.
>
> I belive that, but I need to demonstrate it.
Is it me or does that sound like a school assignment? :)
> I do not know how to
> proof this, perhaps referring to a solid reference about Linux design
> that points to the idea that it has no sense to use environment
> variables in kernel space.
>
> Do anyone knows about the existence of such document?
No.
But you should be able to answer your question by wondering:
- where environment variables come from? see "man sh" or "man bash"
(in particular ENVIRONMENT section)
- how processes are handled. "man init" (in particular BOOTING section)
- where your kernel space is...
Cheers,
Jerome
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-18 15:44 Environment variables inside the kernel? Guillermo López Alejos
2005-08-18 16:02 ` linux-os (Dick Johnson)
2005-08-18 16:03 ` jerome lacoste
@ 2005-08-18 16:12 ` Ingo Oeser
2005-08-18 17:27 ` Christoph Lameter
2005-08-18 16:37 ` Douglas McNaught
3 siblings, 1 reply; 17+ messages in thread
From: Ingo Oeser @ 2005-08-18 16:12 UTC (permalink / raw)
To: Guillermo López Alejos; +Cc: Linux Kernel mailing list
[-- Attachment #1: Type: text/plain, Size: 948 bytes --]
Hi Guillermo,
On Thursday 18 August 2005 17:44, Guillermo López Alejos wrote:
> I have a piece of code which uses environment variables. I have been
> told that it is not going to work in kernel space because the concept
> of environment is not applicable inside the kernel.
>
> I belive that, but I need to demonstrate it. I do not know how to
> proof this, perhaps referring to a solid reference about Linux design
> that points to the idea that it has no sense to use environment
> variables in kernel space.
The Linux kernel is technically one big process with lots of threads.
An environment variable is per process and is usally to be threated
read only within it.
Also the Linux kernel is the first "process" ever.
Who should set up it's environment variables?
That's why there are none.
These arguments are no real proof in a mathematical sense,
but should help you argumenting.
Regards
Ingo Oeser
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-18 16:12 ` Ingo Oeser
@ 2005-08-18 17:27 ` Christoph Lameter
0 siblings, 0 replies; 17+ messages in thread
From: Christoph Lameter @ 2005-08-18 17:27 UTC (permalink / raw)
To: Ingo Oeser; +Cc: Guillermo López Alejos, Linux Kernel mailing list
On Thu, 18 Aug 2005, Ingo Oeser wrote:
> Also the Linux kernel is the first "process" ever.
The first process is init.
> Who should set up it's environment variables?
The kernel command line and the boot loader set up the environment
variables for the kernel.
> These arguments are no real proof in a mathematical sense,
> but should help you argumenting.
Mathematical proofs are accomplished within a framework of mathematical
models.
In the postmodern time period and we gave up belief that the mathematical
models are an accurate representation of reality. We only expect that
they are sufficiently accurate for the purposes at hand.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-18 15:44 Environment variables inside the kernel? Guillermo López Alejos
` (2 preceding siblings ...)
2005-08-18 16:12 ` Ingo Oeser
@ 2005-08-18 16:37 ` Douglas McNaught
2005-08-18 18:23 ` Linh Dang
3 siblings, 1 reply; 17+ messages in thread
From: Douglas McNaught @ 2005-08-18 16:37 UTC (permalink / raw)
To: Guillermo López Alejos; +Cc: Linux Kernel mailing list
Guillermo López Alejos <glalejos@gmail.com> writes:
> Hi,
>
> I have a piece of code which uses environment variables. I have been
> told that it is not going to work in kernel space because the concept
> of environment is not applicable inside the kernel.
Correct.
> I belive that, but I need to demonstrate it. I do not know how to
> proof this, perhaps referring to a solid reference about Linux design
> that points to the idea that it has no sense to use environment
> variables in kernel space.
Environment variables are a part of the API that Unix supplies to
userspace programs. The kernel is not a userspace program, and as far
as I know it doesn't even do most of the work of maintaining the
environment for a process--that's done by the C library and the
userspace program loader.
> Do anyone knows about the existence of such document?
No, probably because it's such an obvious concept. You might get hold
of one of the several books on Linux kernel programming and see if
they mention it.
If someone is insisting you use environment varaiables in kernel code,
challenge them to show you where they are implemented in the kernel. :)
-Doug
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: Environment variables inside the kernel?
2005-08-18 16:37 ` Douglas McNaught
@ 2005-08-18 18:23 ` Linh Dang
2005-08-18 18:48 ` Guillermo López Alejos
2005-08-18 23:12 ` Alan Cox
0 siblings, 2 replies; 17+ messages in thread
From: Linh Dang @ 2005-08-18 18:23 UTC (permalink / raw)
To: linux-kernel
Douglas McNaught <doug@mcnaught.org> wrote:
>
> If someone is insisting you use environment varaiables in kernel
> code, challenge them to show you where they are implemented in the
> kernel. :)
>
> -Doug
They're in current process's vm. You just have to parse it yourself.
something along the (untested) lines:
struct mm_struct *mm = current ? get_task_mm(current) : NULL;
if (mm) {
unsigned env_len = mm->env_end - mm->env_start;
char* env = kmalloc(env_len, GFP_KERNEL);
access_process_vm(current, mm->env_start, env,
env_len, 0);
/* env is now a big buffer containing null-terminated
strings representing evironment variables */
mmput(mm);
}
--
Linh Dang
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: Environment variables inside the kernel?
2005-08-18 18:23 ` Linh Dang
@ 2005-08-18 18:48 ` Guillermo López Alejos
2005-08-18 19:43 ` Emilio Jesús Gallego Arias
` (2 more replies)
2005-08-18 23:12 ` Alan Cox
1 sibling, 3 replies; 17+ messages in thread
From: Guillermo López Alejos @ 2005-08-18 18:48 UTC (permalink / raw)
To: Linh Dang; +Cc: linux-kernel
Whoa!, I did not expect so many replies. Thank you for your answers.
The thing is that the Computer Architecture area of the University I
am studying at is developing a parallel filesystem. Currently it works
as a stand-alone program (this is why it uses resources like
environment variables), and I have been told to integrate it in the
Linux kernel.
I have to justify changes on this filesystem code (like avoiding the
use of environment variables) to my tutor. In this case I needed to
find why it is not possible to use environment variables in kernel
space.
I was looking for a reference documentation which give a definition of
environment variables that exclude their use inside the kernel, or,
simply, I expected to find a design decision to justify this. But I
think I have enough information with your answers, I will be able to
elaborate a satisfactory conclusion.
Excuse me if the topic was so obvious (it was not to me) and thank you again,
On 8/18/05, Linh Dang <linhd@nortel.com> wrote:
> Douglas McNaught <doug@mcnaught.org> wrote:
>
> >
> > If someone is insisting you use environment varaiables in kernel
> > code, challenge them to show you where they are implemented in the
> > kernel. :)
> >
> > -Doug
>
> They're in current process's vm. You just have to parse it yourself.
>
> something along the (untested) lines:
>
> struct mm_struct *mm = current ? get_task_mm(current) : NULL;
>
> if (mm) {
> unsigned env_len = mm->env_end - mm->env_start;
> char* env = kmalloc(env_len, GFP_KERNEL);
> access_process_vm(current, mm->env_start, env,
> env_len, 0);
>
> /* env is now a big buffer containing null-terminated
> strings representing evironment variables */
>
> mmput(mm);
> }
--
Guillermo
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: Environment variables inside the kernel?
2005-08-18 18:48 ` Guillermo López Alejos
@ 2005-08-18 19:43 ` Emilio Jesús Gallego Arias
2005-08-21 22:12 ` Eric W. Biederman
2005-08-22 20:38 ` Helge Hafting
2 siblings, 0 replies; 17+ messages in thread
From: Emilio Jesús Gallego Arias @ 2005-08-18 19:43 UTC (permalink / raw)
To: linux-kernel; +Cc: glalejos
Guillermo López Alejos <glalejos@gmail.com> writes:
> Whoa!, I did not expect so many replies. Thank you for your answers.
>
> The thing is that the Computer Architecture area of the University I
> am studying at is developing a parallel filesystem. Currently it works
> as a stand-alone program (this is why it uses resources like
> environment variables), and I have been told to integrate it in the
> Linux kernel.
>
> I have to justify changes on this filesystem code (like avoiding the
> use of environment variables) to my tutor. In this case I needed to
> find why it is not possible to use environment variables in kernel
> space.
>
> I was looking for a reference documentation which give a definition of
> environment variables that exclude their use inside the kernel, or,
> simply, I expected to find a design decision to justify this. But I
> think I have enough information with your answers, I will be able to
> elaborate a satisfactory conclusion.
A good reference is in Debian Policy Section 9.9, where it is stated:
A program must not depend on environment variables to get reasonable
defaults. (That's because these environment variables would have to be
set in a system-wide configuration file like /etc/profile, which is
not supported by all shells.)
Although this is not applicable to the kernel, goggling about this
section of the Debian Policy will give you some arguments against
environment variables in general.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-18 18:48 ` Guillermo López Alejos
2005-08-18 19:43 ` Emilio Jesús Gallego Arias
@ 2005-08-21 22:12 ` Eric W. Biederman
2005-08-22 9:05 ` Guillermo López Alejos
2005-08-22 20:38 ` Helge Hafting
2 siblings, 1 reply; 17+ messages in thread
From: Eric W. Biederman @ 2005-08-21 22:12 UTC (permalink / raw)
To: Guillermo López Alejos; +Cc: Linh Dang, linux-kernel
Guillermo López Alejos <glalejos@gmail.com> writes:
> Whoa!, I did not expect so many replies. Thank you for your answers.
>
> The thing is that the Computer Architecture area of the University I
> am studying at is developing a parallel filesystem. Currently it works
> as a stand-alone program (this is why it uses resources like
> environment variables), and I have been told to integrate it in the
> Linux kernel.
??
Usually when I hear stand-alone program I think of program that runs
without the need of a kernel. You have an environment in that context?
> I have to justify changes on this filesystem code (like avoiding the
> use of environment variables) to my tutor. In this case I needed to
> find why it is not possible to use environment variables in kernel
> space.
Be very careful. Generally I think at least until the filesystem
is very stable running your filesystem server in the kernel is a mistake.
And the concept of a parallel filesystem with just one server just
sounds wrong from any context.
Eric
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-21 22:12 ` Eric W. Biederman
@ 2005-08-22 9:05 ` Guillermo López Alejos
2005-08-22 9:18 ` Eric W. Biederman
0 siblings, 1 reply; 17+ messages in thread
From: Guillermo López Alejos @ 2005-08-22 9:05 UTC (permalink / raw)
To: Eric W. Biederman; +Cc: Linh Dang, linux-kernel
On 8/22/05, Eric W. Biederman <ebiederm@xmission.com> wrote:
> ??
> Usually when I hear stand-alone program I think of program that runs
> without the need of a kernel. You have an environment in that context?
Without the need of a kernel? Perhaps I did not explain myself
correctly... I meant a user space program, is that better?
And yes, there is a environment in this context, but it is feasible to
provide the information it contains through module parameters.
> Be very careful. Generally I think at least until the filesystem
> is very stable running your filesystem server in the kernel is a mistake.
>
> And the concept of a parallel filesystem with just one server just
> sounds wrong from any context.
Thanks for the advise, but do not worry, the servers run outside the
kernel (preferably outside the host :). It is the client side what is
to be integrated into the kernel.
Regards,
--
Guillermo
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-22 9:05 ` Guillermo López Alejos
@ 2005-08-22 9:18 ` Eric W. Biederman
2005-08-25 8:59 ` Guillermo López Alejos
0 siblings, 1 reply; 17+ messages in thread
From: Eric W. Biederman @ 2005-08-22 9:18 UTC (permalink / raw)
To: Guillermo López Alejos; +Cc: Linh Dang, linux-kernel
Guillermo López Alejos <glalejos@gmail.com> writes:
> On 8/22/05, Eric W. Biederman <ebiederm@xmission.com> wrote:
>> ??
>> Usually when I hear stand-alone program I think of program that runs
>> without the need of a kernel. You have an environment in that context?
>
> Without the need of a kernel?
Yep I think of programs like memtest86 when I think of stand-alone
programs.
> Perhaps I did not explain myself correctly... I meant a user space
> program, is that better?
Yes, thanks.
> And yes, there is a environment in this context, but it is feasible to
> provide the information it contains through module parameters.
>
>> Be very careful. Generally I think at least until the filesystem
>> is very stable running your filesystem server in the kernel is a mistake.
>>
>> And the concept of a parallel filesystem with just one server just
>> sounds wrong from any context.
>
> Thanks for the advise, but do not worry, the servers run outside the
> kernel (preferably outside the host :). It is the client side what is
> to be integrated into the kernel.
Ok. As for parameters I would expect most of them to be mount options.
Just a bit of food for thought. There seem to be two different kinds
of workloads for non-local filesystems. Bandwidth intensive workloads
where files are read and written. Cache intensive workloads (like
kernel compiles) where performance directly relates to how
efficiently you can make use of the page cache, and not get buried
in cache contention.
Eric
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-22 9:18 ` Eric W. Biederman
@ 2005-08-25 8:59 ` Guillermo López Alejos
0 siblings, 0 replies; 17+ messages in thread
From: Guillermo López Alejos @ 2005-08-25 8:59 UTC (permalink / raw)
To: Eric W. Biederman; +Cc: Linh Dang, linux-kernel
> Just a bit of food for thought. There seem to be two different kinds
> of workloads for non-local filesystems. Bandwidth intensive workloads
> where files are read and written. Cache intensive workloads (like
> kernel compiles) where performance directly relates to how
> efficiently you can make use of the page cache, and not get buried
> in cache contention.
Yes, those performance factors have to been taken in account. The
bandwith intensive workloads depends on the implementation of the
filesystem. Note that I am not involved in the internal details of
this filesystem, my goal is to integrate it in the Linux kernel.
The usage of cache memory in this distributed schemas is complicated.
Probably it will be necessary to implement protocols to ensure cache
coherency and consistency.
Hum... it seems that we are going away from environment variables :)
--
Guillermo
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-18 18:48 ` Guillermo López Alejos
2005-08-18 19:43 ` Emilio Jesús Gallego Arias
2005-08-21 22:12 ` Eric W. Biederman
@ 2005-08-22 20:38 ` Helge Hafting
2 siblings, 0 replies; 17+ messages in thread
From: Helge Hafting @ 2005-08-22 20:38 UTC (permalink / raw)
To: Guillermo López Alejos; +Cc: Linh Dang, linux-kernel
On Thu, Aug 18, 2005 at 08:48:04PM +0200, Guillermo López Alejos wrote:
> Whoa!, I did not expect so many replies. Thank you for your answers.
>
> The thing is that the Computer Architecture area of the University I
> am studying at is developing a parallel filesystem. Currently it works
> as a stand-alone program (this is why it uses resources like
> environment variables), and I have been told to integrate it in the
> Linux kernel.
>
> I have to justify changes on this filesystem code (like avoiding the
> use of environment variables) to my tutor. In this case I needed to
> find why it is not possible to use environment variables in kernel
> space.
>
> I was looking for a reference documentation which give a definition of
> environment variables that exclude their use inside the kernel, or,
> simply, I expected to find a design decision to justify this. But I
> think I have enough information with your answers, I will be able to
> elaborate a satisfactory conclusion.
>
> Excuse me if the topic was so obvious (it was not to me) and thank you again,
It is obvious to someone who knows what the kernel is. A kernel and
a process is very different things. A comparison to something
different:
A book always have a "page 1". It is usually only the title, so it
is a nice place for writing some notes as well.
(similiar to how a process have an environment.)
A library is a big collection of books, (similiar to how the kernel
manages a collection of processes.) Still, it does not make sense
at all to talk about "page 1 of the library!" Even if it _is_ useful
to write some library-specific notes somewhere.
The kernel does not have an environment of its own. It manages all
the processes, and jave equal access all of the environmnts
(albeit in a hackish way only) for process envirnments are _not_
part of the kernel/process communication interface.
|1
Helge Hafting
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-18 18:23 ` Linh Dang
2005-08-18 18:48 ` Guillermo López Alejos
@ 2005-08-18 23:12 ` Alan Cox
2005-08-18 22:55 ` Peter M. Groen
1 sibling, 1 reply; 17+ messages in thread
From: Alan Cox @ 2005-08-18 23:12 UTC (permalink / raw)
To: Linh Dang; +Cc: linux-kernel
On Iau, 2005-08-18 at 14:23 -0400, Linh Dang wrote:
> They're in current process's vm. You just have to parse it yourself.
>
> something along the (untested) lines:
>
> struct mm_struct *mm = current ? get_task_mm(current) : NULL;
>
> if (mm) {
> unsigned env_len = mm->env_end - mm->env_start;
> char* env = kmalloc(env_len, GFP_KERNEL);
That is the environment passed to the application, not the environment
it is running with. Only the application knows where that is, and once
you do things like putenv() it becomes rather relevant.
Essentially environment is user space business and you can't get at it
from the kernel.
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: Environment variables inside the kernel?
2005-08-18 23:12 ` Alan Cox
@ 2005-08-18 22:55 ` Peter M. Groen
2005-08-19 10:28 ` Guillermo López Alejos
0 siblings, 1 reply; 17+ messages in thread
From: Peter M. Groen @ 2005-08-18 22:55 UTC (permalink / raw)
To: linux-kernel
On Friday 19 August 2005 01:12, Alan Cox wrote:
---------------[ 8< ]-------------
> Essentially environment is user space business and you can't get at it
> from the kernel.
-[ 8< ]------------
I think the OP has his answer here. If someone knows what he is talking about,
it's Alan or Linus. And if a teacher or manager doesn't believe those two...
Let *him* prove that AC and LT are wrong, and not the other way around..
--
Peter M. Groen
Open Systems Development
Klipperwerf 12
2317 DZ Leiden
T: +31-(0)-71-5216317 M: +31-(0)6-29563390
E: info@osdev.xs4all.nl
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Environment variables inside the kernel?
2005-08-18 22:55 ` Peter M. Groen
@ 2005-08-19 10:28 ` Guillermo López Alejos
0 siblings, 0 replies; 17+ messages in thread
From: Guillermo López Alejos @ 2005-08-19 10:28 UTC (permalink / raw)
To: Peter M. Groen; +Cc: linux-kernel
> On Friday 19 August 2005 01:12, Alan Cox wrote:
> ---------------[ 8< ]-------------
> > Essentially environment is user space business and you can't get at it
> > from the kernel.
> -[ 8< ]------------
>
> I think the OP has his answer here. If someone knows what he is talking about,
> it's Alan or Linus. And if a teacher or manager doesn't believe those two...
> Let *him* prove that AC and LT are wrong, and not the other way around..
This definition given by Alan Cox is enough for me, and I think that
it will be enough for my tutor too.
Thanks again,
--
Guillermo
^ permalink raw reply [flat|nested] 17+ messages in thread