linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Question regarding map count for compound pages
@ 2021-11-16  2:47 Harish Mara
  2021-11-16  3:31 ` John Donnelly
  2021-11-16  3:40 ` Matthew Wilcox
  0 siblings, 2 replies; 3+ messages in thread
From: Harish Mara @ 2021-11-16  2:47 UTC (permalink / raw)
  To: linux-mm; +Cc: Aniket Kulkarni, Pawan Powar, Rajshekar Iyer, ask

Background:
On older kernel?s, we could have our device driver create char devices and 
implement file_operations and vm_operations for open, release, mmap, fault 
etc. The driver allocates memory (128KB, order 5) as compound pages.
The user application would then map/mmap these device files to perform 
read/write operations.

On recent kernels, this creates problems when the user space maps multiple 
128KB chunks that exceed 2MB. This would sometime result in bad page 
getting mapped to the user space process. Almost always we see ?Bad page 
map? errors during munmap because the map count is going below 0.

It looks like the culprit is zap_pte_range(), which calls 
page_remove_rmap() with the compound_flag = false. As a result, instead of 
decrementing the compound_mapcount for the page the page->_mapcount is 
decremented causing a lot of bad page errors.

Questions:
Is this the right usage of compound pages? I.e can I allocate compound 
pages in my kernel driver to be mapped to char device file by a user 
process?
If yes, then why does it fail on latest kernel when the mmap-ed size 
exceeds 2MB?
If no, why was it working on the older kernels? If it worked then, 
shouldn?t it work now?
What is special about map size being greater than 2MB to trigger this?
Should compound pages be used for Anonymous purposes only?



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

* Re: Question regarding map count for compound pages
  2021-11-16  2:47 Question regarding map count for compound pages Harish Mara
@ 2021-11-16  3:31 ` John Donnelly
  2021-11-16  3:40 ` Matthew Wilcox
  1 sibling, 0 replies; 3+ messages in thread
From: John Donnelly @ 2021-11-16  3:31 UTC (permalink / raw)
  To: Harish Mara, linux-mm; +Cc: Aniket Kulkarni, Pawan Powar, Rajshekar Iyer, ask

On 11/15/21 20:47, Harish Mara wrote:
> Background:
> On older kernel?s, we could have our device driver create char devices and
> implement file_operations and vm_operations for open, release, mmap, fault
> etc. The driver allocates memory (128KB, order 5) as compound pages.
> The user application would then map/mmap these device files to perform
> read/write operations.
> 
> On recent kernels, this creates problems when the user space maps multiple
> 128KB chunks that exceed 2MB. This would sometime result in bad page
> getting mapped to the user space process. Almost always we see ?Bad page
> map? errors during munmap because the map count is going below 0.
> 
> It looks like the culprit is zap_pte_range(), which calls
> page_remove_rmap() with the compound_flag = false. As a result, instead of
> decrementing the compound_mapcount for the page the page->_mapcount is
> decremented causing a lot of bad page errors.
> 
> Questions:
> Is this the right usage of compound pages? I.e can I allocate compound
> pages in my kernel driver to be mapped to char device file by a user
> process?
> If yes, then why does it fail on latest kernel when the mmap-ed size
> exceeds 2MB?
> If no, why was it working on the older kernels? If it worked then,
> shouldn?t it work now?
> What is special about map size being greater than 2MB to trigger this?
> Should compound pages be used for Anonymous purposes only?
> 
> 
Hi.


It would certainly help if you could isolate when this behavior started 
. Which version x.y.z version works ? And which one fail ?


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

* Re: Question regarding map count for compound pages
  2021-11-16  2:47 Question regarding map count for compound pages Harish Mara
  2021-11-16  3:31 ` John Donnelly
@ 2021-11-16  3:40 ` Matthew Wilcox
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2021-11-16  3:40 UTC (permalink / raw)
  To: Harish Mara; +Cc: linux-mm, Aniket Kulkarni, Pawan Powar, Rajshekar Iyer, ask

On Mon, Nov 15, 2021 at 10:47:01PM -0400, Harish Mara wrote:
> Background:
> On older kernel?s, we could have our device driver create char devices and 

Which device driver is this?

> It looks like the culprit is zap_pte_range(), which calls 
> page_remove_rmap() with the compound_flag = false. As a result, instead of 
> decrementing the compound_mapcount for the page the page->_mapcount is 
> decremented causing a lot of bad page errors.

There is a lot of confusion in the core MM between 'compound page'
and 'PMD allocation'.  I'm trying to fix it; do you have time to help?


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

end of thread, other threads:[~2021-11-16  3:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-16  2:47 Question regarding map count for compound pages Harish Mara
2021-11-16  3:31 ` John Donnelly
2021-11-16  3:40 ` Matthew Wilcox

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