Skip to contentSkip to conversation

Implications of PG_locked and reference count in page structures....

DISCUSSION Michael Heinz 3 participants 3 messages Aug 15, 2001

lore
Share & tools
lore
#0 lore raw

I'm in the process of porting a driver to Linux. The author of the driver conveniently broke it into os-dependent and independent sections.

One of the things in the "OS" dependent section is a routine to lock a section of memory presumably to be used for DMA.

So, what I want to do is this: given a pointer to a previously kmalloc'ed block, and the length of that block, I want to (a) identify each page associated with the block and (b) lock each page. It appears that I can lock the page either by incrementing it's reference count, or by setting the PG_locked flag for the page.

Which method is preferred? Is there another method I should be using instead?

#1 lore raw
Quoted 6 lines · Michael Heinz

I'm in the process of porting a driver to Linux. The author of the driver conveniently broke it into os-dependent and independent sections.

One of the things in the "OS" dependent section is a routine to lock a section of memory presumably to be used for DMA.

Quoted 8 lines

So, what I want to do is this: given a pointer to a previously kmalloc'ed block, and the length of that block, I want to (a) identify each page associated with the block and (b) lock each page. It appears that I can lock the page either by incrementing it's reference count, or by setting the PG_locked flag for the page.

Which method is preferred? Is there another method I should be using instead?

Linux has seperate functionality for DMA transfers so you don't neccesarily have to do all that. If you're _certain_ that the memory is going to be used for DMA, then have a look at http://www.xml.com/ldd/chapter/book/ch13.html and scroll down to the part that talks about DMA. In fact, if you're fairly new to Linux drivers then I would suggest that you take a look at
http://www.xml.com/ldd/chapter/book/index.html.

Signature · 1 line
Ignacio Vazquez-Abrams  <[email protected]>
#2 lore raw
In reply to Michael Heinz
Quoted 6 lines · Michael Heinz

I'm in the process of porting a driver to Linux. The author of the driver conveniently broke it into os-dependent and independent sections.

One of the things in the "OS" dependent section is a routine to lock a section of memory presumably to be used for DMA.

Quoted 8 lines

So, what I want to do is this: given a pointer to a previously kmalloc'ed block, and the length of that block, I want to (a) identify each page associated with the block and (b) lock each page. It appears that I can lock the page either by incrementing it's reference count, or by setting the PG_locked flag for the page.

Which method is preferred? Is there another method I should be using instead?

See the other replies - you do not need to memlock your pages because you will be allocating non-pageable kernel memory.

But for future reference, PG_locked is for serializing IO/cache operations. You use the page reference count to prevent a page from being freed, i.e., to memlock it. You'll see such object ref-counting schemes showing up all through the kernel in slight variations.

--
Daniel