Kernel Newbies archive on lore.kernel.org
 help / Atom feed
* a question on mapping from PTE to swap entry
@ 2018-11-15 15:53 losemyheaven
  2018-11-15 15:53 ` Larry
  2018-11-15 17:59 ` valdis.kletnieks
  0 siblings, 2 replies; 4+ messages in thread
From: losemyheaven @ 2018-11-15 15:53 UTC (permalink / raw)
  To: kernelnewbies

Hi all,

It's quoted that "When a page is swapped out, Linux uses the correspondingPTE to store enough 
information to locate the page on disk again".

I'm curious when multiple process has the same PTE which points to the samepage, 
how can kernel differenciate which page from swap space should be swappedin?

For example, there are 3 processes, each of them has a virtual page that is mapped to a 
phyisical page PAGE_A, that means the same PTE is mapped to same PAGE

Process 1 runs out of its  timeslice
Process 2 get scheduled, PAGE_A was from Process 1, so it should be swapped out
Process 3 get scheduled, PAGE_A was from Process 2, so it should be swapped out
Process 1 now comes back, 

when he use PTE to look for its PAGE_A, it will get two PAGE_A,
one is from itself, and the other from Process 2

How does kernel handle this situation?

Thanks

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

* a question on mapping from PTE to swap entry
  2018-11-15 15:53 a question on mapping from PTE to swap entry losemyheaven
@ 2018-11-15 15:53 ` Larry
  2018-11-15 17:59 ` valdis.kletnieks
  1 sibling, 0 replies; 4+ messages in thread
From: Larry @ 2018-11-15 15:53 UTC (permalink / raw)
  To: kernelnewbies

Hi all,

It's quoted that "When a page is swapped out, Linux uses the correspondingPTE to store enough 
information to locate the page on disk again".

I'm curious when multiple process has the same PTE which points to the samepage, 
how can kernel differenciate which page from swap space should be swappedin?

For example, there are 3 processes, each of them has a virtual page that is mapped to a 
phyisical page PAGE_A, that means the same PTE is mapped to same PAGE

Process 1 runs out of its  timeslice
Process 2 get scheduled, PAGE_A was from Process 1, so it should be swapped out
Process 3 get scheduled, PAGE_A was from Process 2, so it should be swapped out
Process 1 now comes back, 

when he use PTE to look for its PAGE_A, it will get two PAGE_A,
one is from itself, and the other from Process 2

How does kernel handle this situation?

Thanks
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* a question on mapping from PTE to swap entry
  2018-11-15 15:53 a question on mapping from PTE to swap entry losemyheaven
  2018-11-15 15:53 ` Larry
@ 2018-11-15 17:59 ` valdis.kletnieks
  2018-11-15 17:59   ` valdis.kletnieks
  1 sibling, 1 reply; 4+ messages in thread
From: valdis.kletnieks @ 2018-11-15 17:59 UTC (permalink / raw)
  To: kernelnewbies

On Thu, 15 Nov 2018 23:53:56 +0800, "Larry" said:

> I'm curious when multiple process has the same PTE which points to the samepage,
> how can kernel differenciate which page from swap space should be swappedin?

The PTE tells where in /dev/swap to find the page.  If it's a shared page, the
references all point at the same place, so "process 1's PAGE_A info" is the
same as "process 2's PAGE_A" info.  They may have different addresses in the
two processes, but they're both referencing the same swap page.

> Process 2 get scheduled, PAGE_A was from Process 1, so it should be swapped out

Why? In general, there's no need to do so - and if it's shared, it's probably a hot page
so it won't be chosen for swapout.

(Remember - the kernel doesn't do swapin/swapout decisions in schedule(), it
only takes action once Process 2 starts running and references a page that requires
something be done.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 486 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20181115/dd74e597/attachment.sig>

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

* Re: a question on mapping from PTE to swap entry
  2018-11-15 17:59 ` valdis.kletnieks
@ 2018-11-15 17:59   ` valdis.kletnieks
  0 siblings, 0 replies; 4+ messages in thread
From: valdis.kletnieks @ 2018-11-15 17:59 UTC (permalink / raw)
  To: Larry; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 899 bytes --]

On Thu, 15 Nov 2018 23:53:56 +0800, "Larry" said:

> I'm curious when multiple process has the same PTE which points to the samepage,
> how can kernel differenciate which page from swap space should be swappedin?

The PTE tells where in /dev/swap to find the page.  If it's a shared page, the
references all point at the same place, so "process 1's PAGE_A info" is the
same as "process 2's PAGE_A" info.  They may have different addresses in the
two processes, but they're both referencing the same swap page.

> Process 2 get scheduled, PAGE_A was from Process 1, so it should be swapped out

Why? In general, there's no need to do so - and if it's shared, it's probably a hot page
so it won't be chosen for swapout.

(Remember - the kernel doesn't do swapin/swapout decisions in schedule(), it
only takes action once Process 2 starts running and references a page that requires
something be done.

[-- Attachment #1.2: Type: application/pgp-signature, Size: 486 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-15 15:53 a question on mapping from PTE to swap entry losemyheaven
2018-11-15 15:53 ` Larry
2018-11-15 17:59 ` valdis.kletnieks
2018-11-15 17:59   ` valdis.kletnieks

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org kernelnewbies@archiver.kernel.org
	public-inbox-index kernelnewbies


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/ public-inbox