Skip to contentSkip to conversation

question about ramdisk

DISCUSSION [email protected] 4 participants 9 messages Jul 12, 2004 – Jul 14, 2004 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hi all,

I am learning linux kernel and have a question about ramdisk. When loading an executable in ramdisk, is the kernel loading the code all at a time to memory and then execute, or is it loading only a page at one time and generating a page fault to fetch another page?

Thanks for any comments! Waiting desprately for your help.

Lei

_________________________________________________________
This message was sent through the NU ECE webmail gateway.

#1 lore raw
Followup to:  <[email protected]>
By author:    [email protected]
In newsgroup: linux.dev.kernel
Quoted 10 lines

Hi all,

I am learning linux kernel and have a question about ramdisk. When loading an executable in ramdisk, is the kernel loading the code all at a time to memory and then execute, or is it loading only a page at one time and generating a page fault to fetch another page?

Thanks for any comments! Waiting desprately for your help.

Neither. The code is already in RAM. It's mapped into the process address space and run in place.

-hpa

#2 lore raw

Thank you! Can you pls tell me where I can find related references? I've been looking into several books about kernel and part of the kernel code, but no luck so far..

Thanks for any comments!

Quoting "H. Peter Anvin" <[email protected]>:

Quoted 20 lines
Followup to:  <[email protected]>
By author:    [email protected]
In newsgroup: linux.dev.kernel
Quoted 4 lines

Hi all,

I am learning linux kernel and have a question about ramdisk. When loading

an

Quoted 1 line

executable in ramdisk, is the kernel loading the code all at a time to

memory

Quoted 6 lines

and then execute, or is it loading only a page at one time and generating a

page fault to fetch another page?

Thanks for any comments! Waiting desprately for your help.

Neither. The code is already in RAM. It's mapped into the process address space and run in place.

Quoted 7 lines

-hpa
-
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/

_________________________________________________________
This message was sent through the NU ECE webmail gateway.

#3 lore raw

"Unix Internals", by Uresh Vahalia (sp?). This book went everywhere I did for a year. I cannot praise it highly enough. Read that, then get Robert Love's 'Linux Kernel Programming'.

Lee

Quoted 46 lines · On Tue, 2004-07-13 at 10:01, [email protected] wrote:

Thank you! Can you pls tell me where I can find related references? I've been looking into several books about kernel and part of the kernel code, but no luck so far..

Thanks for any comments!

Quoting "H. Peter Anvin" <[email protected]>:

Quoted 20 lines
Followup to:  <[email protected]>
By author:    [email protected]
In newsgroup: linux.dev.kernel
Quoted 4 lines

Hi all,

I am learning linux kernel and have a question about ramdisk. When loading

an

Quoted 1 line

executable in ramdisk, is the kernel loading the code all at a time to

memory

Quoted 6 lines

and then execute, or is it loading only a page at one time and generating a

page fault to fetch another page?

Thanks for any comments! Waiting desprately for your help.

Neither. The code is already in RAM. It's mapped into the process address space and run in place.

Quoted 7 lines

-hpa
-
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/

_________________________________________________________
This message was sent through the NU ECE webmail gateway.
-
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/

#4 lore raw

Sorry, Robert Love's book is 'Linux Kernel Development'.

http://www.amazon.com/exec/obidos/tg/detail/-/0672325128/ref=pd_sim_books_2/002-8634838-0327232?v=glance&s=books

Lee

Quoted 60 lines · Lee Revell

"Unix Internals", by Uresh Vahalia (sp?). This book went everywhere I did for a year. I cannot praise it highly enough. Read that, then get Robert Love's 'Linux Kernel Programming'.

Lee

Quoted 38 lines · On Tue, 2004-07-13 at 10:01, [email protected] wrote:

Thank you! Can you pls tell me where I can find related references? I've been looking into several books about kernel and part of the kernel code, but no luck so far..

Thanks for any comments!

Quoting "H. Peter Anvin" <[email protected]>:

Quoted 20 lines
Followup to:  <[email protected]>
By author:    [email protected]
In newsgroup: linux.dev.kernel
Quoted 4 lines

Hi all,

I am learning linux kernel and have a question about ramdisk. When loading

an

Quoted 1 line

executable in ramdisk, is the kernel loading the code all at a time to

memory

Quoted 6 lines

and then execute, or is it loading only a page at one time and generating a

page fault to fetch another page?

Thanks for any comments! Waiting desprately for your help.

Neither. The code is already in RAM. It's mapped into the process address space and run in place.

Quoted 7 lines

-hpa
-
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/

Quoted 8 lines

_________________________________________________________
This message was sent through the NU ECE webmail gateway.
-
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/

-
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/

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 1089753955.22175.8.camel@mindpipe

#7 lore raw

Hello,

I am now thinking of a way to verify what H. Peter Anvin says about the ramdisk, so that I can watch what is going on when the executable is running. Is there any way to achieve that besides kernel debugging? I don't really want to debug the kernel for now.

Can I get the physical address of the text section with it's virtual address? If I can know the physical address of the code in ramdisk and can know the physical address of the text section of process address space, maybe this can be done.

Any suggestions?

Lei

Quoting Lee Revell <[email protected]>:

Quoted 3 lines

Sorry, wrong book, s/Programming/Development/.

http://www.amazon.com/exec/obidos/tg/detail/-

/0672325128/ref=pd_sim_books_2/002-8634838-0327232?v=glance&s=books

Quoted 67 lines

Lee

Quoted 3 lines · On Tue, 2004-07-13 at 17:10, [email protected] wrote:

BTW, is the second book you mentioned this one?

http://www.amazon.com/exec/obidos/tg/detail/-/0201719754/102-1381649-9278501?

Quoted 13 lines

v=glance

Quoting Lee Revell <[email protected]>:

Quoted 8 lines

"Unix Internals", by Uresh Vahalia (sp?). This book went everywhere I did for a year. I cannot praise it highly enough. Read that, then get Robert Love's 'Linux Kernel Programming'.

Lee

Quoted 1 line · On Tue, 2004-07-13 at 10:01, [email protected] wrote:

Thank you! Can you pls tell me where I can find related references?

I've

Quoted 2 lines
Quoted 2 lines

been

Quoted 1 line

looking into several books about kernel and part of the kernel code,

but no

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

luck so far..

Thanks for any comments!

Quoting "H. Peter Anvin" <[email protected]>:

Quoted 4 lines
Followup to:  <[email protected]>
By author:    [email protected]
In newsgroup: linux.dev.kernel
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi all,

I am learning linux kernel and have a question about ramdisk. When

loading

Quoted 2 lines
Quoted 2 lines

an

Quoted 1 line

executable in ramdisk, is the kernel loading the code all at a time

to

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

memory

Quoted 1 line

and then execute, or is it loading only a page at one time and

generating a

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

page fault to fetch another page?

Thanks for any comments! Waiting desprately for your help.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Neither. The code is already in RAM. It's mapped into the process address space and run in place.

-hpa
-
To unsubscribe from this list: send the line "unsubscribe

linux-kernel"

Quoted 8 lines
Quoted 8 lines

in

Quoted 7 lines
Quoted 4 lines

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/

Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_________________________________________________________
This message was sent through the NU ECE webmail gateway.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel"

in

Quoted 11 lines
Quoted 5 lines
Quoted 4 lines

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/

_________________________________________________________
This message was sent through the NU ECE webmail gateway.

_________________________________________________________
This message was sent through the NU ECE webmail gateway.

#8 lore raw
Quoted 7 lines · On Wed, 14 Jul 2004 [email protected] wrote:

Hello,

I am now thinking of a way to verify what H. Peter Anvin says about the ramdisk, so that I can watch what is going on when the executable is running. Is there any way to achieve that besides kernel debugging? I don't really want to debug the kernel for now.

Quoted 9 lines

Can I get the physical address of the text section with it's virtual address? If I can know the physical address of the code in ramdisk and can know the physical address of the text section of process address space, maybe this can be done.

Any suggestions?

Lei

The physical address will do you no good because your process uses the virtual address to access everything.

Do cat /proc/PID/maps where PID is a process ID number. You will see the virtual address of the executable and runtime shared libraries that the task is using. These are memory-mapped into the tasks address-space.

If your code is ANYWHERE, including on a RAM-Disk, it will be memory-mapped into your address-space just like what you see. This allows everybody to share all the executables and all the run-time libraries so they don't need separate copies.

For instance, here's somebody running the bash shell:

08048000-0808c000 r-xp 00000000 08:11 1440929 /usr/bin/bash
0808c000-08092000 rw-p 00043000 08:11 1440929 /usr/bin/bash
08092000-080a2000 rwxp 00000000 00:00 0
40000000-4000a000 r-xp 00000000 08:11 475506 /usr/lib/ld-2.0.5.so
4000a000-4000b000 rw-p 00009000 08:11 475506 /usr/lib/ld-2.0.5.so
4000b000-4000c000 rwxp 00000000 00:00 0

4000c000-40010000 r--p 00000000 08:11 163651     /etc/ld.so.cache
40010000-40012000 rwxp 00000000 08:11 1030227    /lib/libtermcap.so.2.0.8
40012000-40014000 rw-p 00001000 08:11 1030227    /lib/libtermcap.so.2.0.8
40014000-4009f000 r-xp 00000000 08:11 475508     /usr/lib/libc-2.0.6.so
4009f000-400a5000 rw-p 0008b000 08:11 475508     /usr/lib/libc-2.0.6.so

[SNIPPED...]

You can see the virtual address of your own stuff by compiling and executing this:

#include <stdio.h>
extern char _start;
extern char _end;
char dat;
const char x[]="x";

int main()

{
    char foo;
    printf("start = %p\n", &_start);
    printf(" main = %p\n", main);
    printf(" data = %p\n", &dat);
    printf("const = %p\n", x);
    printf("stack = %p\n", &foo);
    printf("  end = %p\n", &_end);
    return 0;
}

The physical address in RAM could be anywhere. The kernel takes pages of RAM from anywhere and makes them look contiguous for each task. So what looks like linear address-space is made up of (on ix86 0x1000 byte) pages of RAM.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.

#9 lore raw

Thanks so much for the hint! Really appreciate it. I'll try out your suggestions.

I am still a bit confused, though. If the code is in ramdisk, then it will be mapped to the process address space, which as I understand, does not involve any actual data copy and transfer. This sounds very reasonable. But what if the code is in hard disk? Would the kernel copy it to memory (somewhere allocated) then map this region as the text section for the address space, and then run the instructions from ram? That's the way I understand it, but I don't know whether that is correct.

Thanks!
Lei

Quoting "Richard B. Johnson" <[email protected]>:

Quoted 83 lines · On Wed, 14 Jul 2004 [email protected] wrote:
Quoted 5 lines

Hello,

I am now thinking of a way to verify what H. Peter Anvin says about the ramdisk, so that I can watch what is going on when the executable is

running.

Quoted 1 line

Is there any way to achieve that besides kernel debugging? I don't really

want

Quoted 3 lines

to debug the kernel for now.

Can I get the physical address of the text section with it's virtual

address?

Quoted 2 lines

If I can know the physical address of the code in ramdisk and can know the physical address of the text section of process address space, maybe this

can

Quoted 6 lines

be done.

Any suggestions?

Lei

The physical address will do you no good because your process uses the virtual address to access everything.

Do cat /proc/PID/maps where PID is a process ID number. You will see the virtual address of the executable and runtime shared libraries that the task is using. These are memory-mapped into the tasks address-space.

If your code is ANYWHERE, including on a RAM-Disk, it will be memory-mapped into your address-space just like what you see. This allows everybody to share all the executables and all the run-time libraries so they don't need separate copies.

For instance, here's somebody running the bash shell:

08048000-0808c000 r-xp 00000000 08:11 1440929 /usr/bin/bash
0808c000-08092000 rw-p 00043000 08:11 1440929 /usr/bin/bash
08092000-080a2000 rwxp 00000000 00:00 0
40000000-4000a000 r-xp 00000000 08:11 475506 /usr/lib/ld-2.0.5.so
4000a000-4000b000 rw-p 00009000 08:11 475506 /usr/lib/ld-2.0.5.so
4000b000-4000c000 rwxp 00000000 00:00 0

4000c000-40010000 r--p 00000000 08:11 163651     /etc/ld.so.cache
40010000-40012000 rwxp 00000000 08:11 1030227    /lib/libtermcap.so.2.0.8
40012000-40014000 rw-p 00001000 08:11 1030227    /lib/libtermcap.so.2.0.8
40014000-4009f000 r-xp 00000000 08:11 475508     /usr/lib/libc-2.0.6.so
4009f000-400a5000 rw-p 0008b000 08:11 475508     /usr/lib/libc-2.0.6.so

[SNIPPED...]

You can see the virtual address of your own stuff by compiling and executing this:

#include <stdio.h>
extern char _start;
extern char _end;
char dat;
const char x[]="x";

int main()

{
    char foo;
    printf("start = %p\n", &_start);
    printf(" main = %p\n", main);
    printf(" data = %p\n", &dat);
    printf("const = %p\n", x);
    printf("stack = %p\n", &foo);
    printf("  end = %p\n", &_end);
    return 0;
}

The physical address in RAM could be anywhere. The kernel takes pages of RAM from anywhere and makes them look contiguous for each task. So what looks like linear address-space is made up of (on ix86 0x1000 byte) pages of RAM.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.

Quoted 6 lines

-
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/

_________________________________________________________
This message was sent through the NU ECE webmail gateway.

#10 lore raw
Quoted 11 lines · On Wed, 14 Jul 2004 [email protected] wrote:

Thanks so much for the hint! Really appreciate it. I'll try out your suggestions.

I am still a bit confused, though. If the code is in ramdisk, then it will be mapped to the process address space, which as I understand, does not involve any actual data copy and transfer. This sounds very reasonable. But what if the code is in hard disk? Would the kernel copy it to memory (somewhere allocated) then map this region as the text section for the address space, and then run the instructions from ram? That's the way I understand it, but I don't know whether that is correct.

Quoted 2 lines

Thanks!
Lei

The instructions are always executed from RAM even if the executable file is on a physical disk. The file is memory-mapped. Execute man mmap. One of the parameters is MAP_FILE. The whole file is mapped, however, only that which is necessary at a particular time is actually read from the disk, one page at a time.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.