linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: task switching at Page Faults
       [not found] ` <1MNpu-7QI-35@gated-at.bofh.it>
@ 2004-04-19 21:52   ` Andi Kleen
  0 siblings, 0 replies; 7+ messages in thread
From: Andi Kleen @ 2004-04-19 21:52 UTC (permalink / raw)
  To: Fabiano Ramos; +Cc: linux-kernel

Fabiano Ramos <ramos_fabiano@yahoo.com.br> writes:
> kernel", about 2.4, and the authors: 
>     1)assure that there is no process switch during
> the execution of an eception handler (aka syscall).
> they emphasize it.

They're wrong. First the system call or exception can
block and then when kernel code returns to user space
it always checks if the time slice hasn't expired.

>     2) say that the execption handler may not generate
> exceptions, except for page faults.

That's also incorrect. e.g. it can generate GPFs
(e.g. when trying to load a segment register supplied
by the user and it is not correct)
and a few other exceptions in extreme cases. Usually
these exceptions are handled without sleeping though.

-Andi


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: task switching at Page Faults
  2004-04-19 18:32 Fabiano Ramos
  2004-04-19 19:49 ` Mikulas Patocka
  2004-04-20  1:32 ` Richard B. Johnson
@ 2004-04-20  8:16 ` Helge Hafting
  2 siblings, 0 replies; 7+ messages in thread
From: Helge Hafting @ 2004-04-20  8:16 UTC (permalink / raw)
  To: Fabiano Ramos; +Cc: linux-kernel

Fabiano Ramos wrote:
> Hi all.
> 
> 	I am in doubt about the linux kernel behaviour is this situation:
> supose a have the process A, with the highest realtime
> priority and SCHED_FIFO policy. The process then issues a syscall,
> say read():
> 
> 	1) Can I be sure that there will be no process switch during the
> syscall processing, even if the system call causes a page fault?

A page fault means your realtime process must wait, because the
data it wants isn't available yet. (Data have to be fetched
from disk/device which takes lots of time.)

There is nothing wrong with handing the cpu to some other
lower priority process unser such circumstances, because your realtime
process are stuck and can't use it anyway.

The realtime process wil grab the cpu as soon as it gets ready to run anyway,
I believe the scheduler looks for this sort of thing when the pagefault
eventually completes.

Helge Hafting


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: task switching at Page Faults
  2004-04-19 18:32 Fabiano Ramos
  2004-04-19 19:49 ` Mikulas Patocka
@ 2004-04-20  1:32 ` Richard B. Johnson
  2004-04-20  8:16 ` Helge Hafting
  2 siblings, 0 replies; 7+ messages in thread
From: Richard B. Johnson @ 2004-04-20  1:32 UTC (permalink / raw)
  To: Fabiano Ramos; +Cc: linux-kernel

On Mon, 19 Apr 2004, Fabiano Ramos wrote:

> Hi all.
>
> 	I am in doubt about the linux kernel behaviour is this situation:
> supose a have the process A, with the highest realtime
> priority and SCHED_FIFO policy. The process then issues a syscall,
> say read():
>
> 	1) Can I be sure that there will be no process switch during the
> syscall processing, even if the system call causes a page fault?
>
> 	2) What if the process was a non-realtime processes (ordinary
> one, SCHED_OTHER)?
>
>
> Thanks a lot.
> Fabiano


Read() from a device will probably sleep so you will certainly
end up losing the CPU while the data are being fetched. You can
prevent any of your processes pages from being faulted out.
See mlockall() and friends.

Normally, a system call does not cause a context switch. The kernel
handles the requirements of the caller in the context of the caller
just like a library. BUT.... If the kernel needs to wait for something,
it will always give the CPU to some runable task. That causes a
context-switch. The kernel does not busy-wait, i.e, spin.


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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: task switching at Page Faults
  2004-04-19 20:12   ` Fabiano Ramos
@ 2004-04-19 23:07     ` Mikulas Patocka
  0 siblings, 0 replies; 7+ messages in thread
From: Mikulas Patocka @ 2004-04-19 23:07 UTC (permalink / raw)
  To: Fabiano Ramos; +Cc: linux-kernel

> > > 	I am in doubt about the linux kernel behaviour is
> > this situation:
> > > supose a have the process A, with the highest
> > realtime
> > > priority and SCHED_FIFO policy. The process then
> > issues a syscall,
> > > say read():
> > >
> > > 	1) Can I be sure that there will be no process
> > switch during the
> > > syscall processing, even if the system call causes
> > a page fault?
> >
> > No. If the data read is not in cache and if read
> > operations causes page
> > fault there will be process switch.
> >
> > Additionally, if you don't mlock memory, there can
> > be process switch at
> > any place, because of page faults on code pages or
> > swapping of data pages.
>
>     I was reading the book "Understanding the Linux
> kernel", about 2.4, and the authors:
>     1)assure that there is no process switch during
> the execution of an eception handler (aka syscall).
> they emphasize it.

It is wrong. The process switch will occur, if the process blocks waiting
for some resource (disk IO, keyboard, net or similar). Moreover, on 2.6
kernels, if you turn on CONFIG_PREEMPT, process switch in kernel may occur
almost anywhere

>     2) say that the execption handler may not generate
> exceptions, except for page faults.

That's true. Kernel can generate only page fault.

>      So, if process switching occurs at page faults, I
> was wondering which statement is true of if I am
> missing sth.
>      You mentioned page faults due to code. Aren´t the
> syscall handlers located in mlocked?

Kernel is nonswappable, but when the syscalls returns from kernel, it can
generate page-fault because of its code or data were paged-out.

Mikulas

> Thanks again
> Fabiano

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: task switching at Page Faults
  2004-04-19 19:49 ` Mikulas Patocka
@ 2004-04-19 20:12   ` Fabiano Ramos
  2004-04-19 23:07     ` Mikulas Patocka
  0 siblings, 1 reply; 7+ messages in thread
From: Fabiano Ramos @ 2004-04-19 20:12 UTC (permalink / raw)
  To: Mikulas Patocka; +Cc: linux-kernel

 --- Mikulas Patocka
<mikulas@artax.karlin.mff.cuni.cz> escreveu: > > Hi
all.
> >
> > 	I am in doubt about the linux kernel behaviour is
> this situation:
> > supose a have the process A, with the highest
> realtime
> > priority and SCHED_FIFO policy. The process then
> issues a syscall,
> > say read():
> >
> > 	1) Can I be sure that there will be no process
> switch during the
> > syscall processing, even if the system call causes
> a page fault?
> 
> No. If the data read is not in cache and if read
> operations causes page
> fault there will be process switch.
> 
> Additionally, if you don't mlock memory, there can
> be process switch at
> any place, because of page faults on code pages or
> swapping of data pages.

    I was reading the book "Understanding the Linux
kernel", about 2.4, and the authors: 
    1)assure that there is no process switch during
the execution of an eception handler (aka syscall).
they emphasize it.
    2) say that the execption handler may not generate
exceptions, except for page faults.

     So, if process switching occurs at page faults, I
was wondering which statement is true of if I am
missing sth. 
     You mentioned page faults due to code. Aren´t the
syscall handlers located in mlocked?

Thanks again
Fabiano



> 
> > 	2) What if the process was a non-realtime
> processes (ordinary
> > one, SCHED_OTHER)?
> 
> There can be process switches too.
> 
> Mikulas
> 
>  

=====
Fabiano Ramos
Mestrando em Engenharia de Sistemas e Computação
COPPE / UFRJ
http://www.cos.ufrj.br/~ramosf
ramosf@cos.ufrj.br

______________________________________________________________________

Yahoo! Messenger - Fale com seus amigos online. Instale agora! 
http://br.download.yahoo.com/messenger/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: task switching at Page Faults
  2004-04-19 18:32 Fabiano Ramos
@ 2004-04-19 19:49 ` Mikulas Patocka
  2004-04-19 20:12   ` Fabiano Ramos
  2004-04-20  1:32 ` Richard B. Johnson
  2004-04-20  8:16 ` Helge Hafting
  2 siblings, 1 reply; 7+ messages in thread
From: Mikulas Patocka @ 2004-04-19 19:49 UTC (permalink / raw)
  To: Fabiano Ramos; +Cc: linux-kernel

> Hi all.
>
> 	I am in doubt about the linux kernel behaviour is this situation:
> supose a have the process A, with the highest realtime
> priority and SCHED_FIFO policy. The process then issues a syscall,
> say read():
>
> 	1) Can I be sure that there will be no process switch during the
> syscall processing, even if the system call causes a page fault?

No. If the data read is not in cache and if read operations causes page
fault there will be process switch.

Additionally, if you don't mlock memory, there can be process switch at
any place, because of page faults on code pages or swapping of data pages.

> 	2) What if the process was a non-realtime processes (ordinary
> one, SCHED_OTHER)?

There can be process switches too.

Mikulas

^ permalink raw reply	[flat|nested] 7+ messages in thread

* task switching at Page Faults
@ 2004-04-19 18:32 Fabiano Ramos
  2004-04-19 19:49 ` Mikulas Patocka
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Fabiano Ramos @ 2004-04-19 18:32 UTC (permalink / raw)
  To: linux-kernel

Hi all.

	I am in doubt about the linux kernel behaviour is this situation:
supose a have the process A, with the highest realtime
priority and SCHED_FIFO policy. The process then issues a syscall,
say read():

	1) Can I be sure that there will be no process switch during the
syscall processing, even if the system call causes a page fault?

	2) What if the process was a non-realtime processes (ordinary
one, SCHED_OTHER)?


Thanks a lot.
Fabiano


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-04-20  8:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1MN62-7wz-5@gated-at.bofh.it>
     [not found] ` <1MNpu-7QI-35@gated-at.bofh.it>
2004-04-19 21:52   ` task switching at Page Faults Andi Kleen
2004-04-19 18:32 Fabiano Ramos
2004-04-19 19:49 ` Mikulas Patocka
2004-04-19 20:12   ` Fabiano Ramos
2004-04-19 23:07     ` Mikulas Patocka
2004-04-20  1:32 ` Richard B. Johnson
2004-04-20  8:16 ` Helge Hafting

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).