Kernel Newbies Archive on lore.kernel.org
 help / color / Atom feed
* How to free a page table page
@ 2021-04-05 15:39 Wonkyo Choe
  2021-04-05 22:12 ` linux lover
  2021-04-06  2:42 ` Rik van Riel
  0 siblings, 2 replies; 4+ messages in thread
From: Wonkyo Choe @ 2021-04-05 15:39 UTC (permalink / raw)
  To: kernelnewbies

Hello there,

I'm trying to manage a custom page table list for my toy project.
A basic process of the custom list is to allocate few pages (struct page)
to the list from the buddy allocator and the list will give some pages
when a user process needs page table pages. In contrast, when this
process terminates,
page table pages will return to the list. Finally, when the list is
not needed, all pages will be
delivered to the buddy allocator.

This relationship can be described as:
    process - custom list - buddy allocator

My problem is that a user process' page table pages (pud, pmd, pte)
seem to free their
page to the buddy allocator instead of to the custom list. (allocation
works. I've checked it)
I put my custom functions in release_pages / free_unref_page /
free_unref_page_list,
but somehow the functions do not work as I intended. (Actually the
functions are not
called so I may choose the wrong functions.)

So, I was wondering whether I intercepted the right functions (three
functions above).
Also, I have a question about freeing a page-table page.

1. In x86, are all page-table pages released at the end of termination
by using free_pgtables()?
2. In x86, a page-table page can be freed when there is no entry? In
other words, does the Linux kernel
release a page-table page on runtime? If so, what function would do
this kind of task?
I'm trying to find freeing functions, but I can't find them and I'm
not sure when this kind of function is called.
(I'm pretty sure that pte_free / pmd_free / pud_free functions are not
for this case.)

Any help would be greatly appreciated.

Regards,
Wonkyo

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

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

* Re: How to free a page table page
  2021-04-05 15:39 How to free a page table page Wonkyo Choe
@ 2021-04-05 22:12 ` linux lover
  2021-04-06  2:42 ` Rik van Riel
  1 sibling, 0 replies; 4+ messages in thread
From: linux lover @ 2021-04-05 22:12 UTC (permalink / raw)
  To: Wonkyo Choe; +Cc: kernelnewbies

I really appreciate it!

Sent from my iPhone

> On Apr 5, 2021, at 11:39 PM, Wonkyo Choe <heysid3@gmail.com> wrote:
> 
> Hello there,
> 
> I'm trying to manage a custom page table list for my toy project.
> A basic process of the custom list is to allocate few pages (struct page)
> to the list from the buddy allocator and the list will give some pages
> when a user process needs page table pages. In contrast, when this
> process terminates,
> page table pages will return to the list. Finally, when the list is
> not needed, all pages will be
> delivered to the buddy allocator.
> 
> This relationship can be described as:
>    process - custom list - buddy allocator
> 
> My problem is that a user process' page table pages (pud, pmd, pte)
> seem to free their
> page to the buddy allocator instead of to the custom list. (allocation
> works. I've checked it)
> I put my custom functions in release_pages / free_unref_page /
> free_unref_page_list,
> but somehow the functions do not work as I intended. (Actually the
> functions are not
> called so I may choose the wrong functions.)
> 
> So, I was wondering whether I intercepted the right functions (three
> functions above).
> Also, I have a question about freeing a page-table page.
> 
> 1. In x86, are all page-table pages released at the end of termination
> by using free_pgtables()?
> 2. In x86, a page-table page can be freed when there is no entry? In
> other words, does the Linux kernel
> release a page-table page on runtime? If so, what function would do
> this kind of task?
> I'm trying to find freeing functions, but I can't find them and I'm
> not sure when this kind of function is called.
> (I'm pretty sure that pte_free / pmd_free / pud_free functions are not
> for this case.)
> 
> Any help would be greatly appreciated.
> 
> Regards,
> Wonkyo
> 
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

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

* Re: How to free a page table page
  2021-04-05 15:39 How to free a page table page Wonkyo Choe
  2021-04-05 22:12 ` linux lover
@ 2021-04-06  2:42 ` Rik van Riel
  2021-04-06  6:30   ` Wonkyo Choe
  1 sibling, 1 reply; 4+ messages in thread
From: Rik van Riel @ 2021-04-06  2:42 UTC (permalink / raw)
  To: Wonkyo Choe, kernelnewbies

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

On Tue, 2021-04-06 at 00:39 +0900, Wonkyo Choe wrote:

> 1. In x86, are all page-table pages released at the end of
> termination
> by using free_pgtables()?
> 2. In x86, a page-table page can be freed when there is no entry? In
> other words, does the Linux kernel
> release a page-table page on runtime? If so, what function would do
> this kind of task?

At munmap time, as well as exit and execve time, page
tables can get freed. Look at the code between sys_munmap()
and zap_page_range().

-- 
All Rights Reversed.

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 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

* Re: How to free a page table page
  2021-04-06  2:42 ` Rik van Riel
@ 2021-04-06  6:30   ` Wonkyo Choe
  0 siblings, 0 replies; 4+ messages in thread
From: Wonkyo Choe @ 2021-04-06  6:30 UTC (permalink / raw)
  To: Rik van Riel; +Cc: kernelnewbies

I really appreciate it! I really needed to know when exactly page
tables get freed.
As I looked at your functions, I ended up figuring out that my kernel (v5.3)
defines HAVE_RCU_TABLE_FREE (I assume this is the default option)
and uses __tlb_remove_table(), which frees pages. Finally, my functions
work on these functions.

Thanks again.

2021년 4월 6일 (화) 오전 11:42, Rik van Riel <riel@surriel.com>님이 작성:
>
> On Tue, 2021-04-06 at 00:39 +0900, Wonkyo Choe wrote:
>
> > 1. In x86, are all page-table pages released at the end of
> > termination
> > by using free_pgtables()?
> > 2. In x86, a page-table page can be freed when there is no entry? In
> > other words, does the Linux kernel
> > release a page-table page on runtime? If so, what function would do
> > this kind of task?
>
> At munmap time, as well as exit and execve time, page
> tables can get freed. Look at the code between sys_munmap()
> and zap_page_range().
>
> --
> All Rights Reversed.



-- 
=======================
최원교 / Wonkyo Choe
Phone. +82 10-5755-4519
=======================

_______________________________________________
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 --
2021-04-05 15:39 How to free a page table page Wonkyo Choe
2021-04-05 22:12 ` linux lover
2021-04-06  2:42 ` Rik van Riel
2021-04-06  6:30   ` Wonkyo Choe

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
	public-inbox-index kernelnewbies

Example config snippet for mirrors

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.git