Environment variables inside the kernel?
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,
Signature · 1 line
Guillermo
[I doubt this is the right list to ask this question.]
Quoted 7 lines · Guillermo López Alejos
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? :)
Quoted 6 lines
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
Quoted 11 lines · 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.
Quoted 6 lines
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 [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
Hi Guillermo,
Quoted 8 lines · Guillermo López Alejos
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
Quoted 1 line · Ingo Oeser
Also the Linux kernel is the first "process" ever.
The first process is init.
Quoted 1 line
Who should set up it's environment variables?
The kernel command line and the boot loader set up the environment variables for the kernel.
Quoted 2 lines
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.
Quoted 5 lines · Guillermo López Alejos
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.
Quoted 4 lines
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.
Quoted 1 line
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
Quoted 6 lines · Douglas McNaught
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);
}Signature · 1 line
Linh Dang
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,
Quoted 26 lines · Linh Dang
Quoted 6 lines · Douglas McNaught
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); }
Signature · 1 line
Guillermo
Quoted 13 lines · Guillermo López Alejos
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.
Quoted 5 lines
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.
Quoted 7 lines · Guillermo López Alejos
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?
Quoted 4 lines
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
Quoted 3 lines · Eric W. Biederman
??
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.
Quoted 5 lines
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,
Signature · 1 line
Guillermo
Quoted 6 lines · Guillermo López Alejos
Quoted 3 lines · Eric W. Biederman
??
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.
Quoted 2 lines
Perhaps I did not explain myself correctly... I meant a user space program, is that better?
Yes, thanks.
Quoted 6 lines
And yes, there is a environment in this context, but it is feasible to provide the information it contains through module parameters.
Quoted 3 lines
Be very careful. Generally I think at least until the filesystem is very stable running your filesystem server in the kernel is a mistake.
Quoted 6 lines
Quoted 2 lines
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
Quoted 6 lines
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 :)
Signature · 1 line
Guillermo
Quoted 13 lines · Guillermo López Alejos
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.
Quoted 7 lines
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
Quoted 9 lines · Linh Dang
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.
On Friday 19 August 2005 01:12, Alan Cox wrote:
---------------[ 8< ]-------------
Quoted 2 lines
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..
Signature · 6 lines
Peter M. Groen Open Systems Development Klipperwerf 12 2317 DZ Leiden T: +31-(0)-71-5216317 M: +31-(0)6-29563390 E: [email protected]
Quoted 9 lines · Alan Cox
---------------[ 8< ]-------------
Quoted 2 lines
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,
Signature · 1 line
Guillermo