Skip to contentSkip to conversation

kiobuf interface / PG_locked flag

DISCUSSION Martin Maletinsky 4 participants 6 messages Sep 12, 2002 – Sep 15, 2002 Memory management

lore
Share & tools
lore
#0 lore raw

Hello,

I just read about the kiobuf interface in the Linux Device Driver book from Rubini/Corbet, and there is one point, which I don't understand:
- map_user_kiobuf() forces the pages within a user space address range into physical memory, and increments their usage count, which subsequently prevents the pages from being swapped out.
- lock_kiovec() sets the PG_locked flag for the pages in the kiobufs of a kiovec. The PG_locked flag prevents the pages from being swapped out, which is however already ensured by map_user_kiobuf().
(1) What is the reason to call lock_kiovec()?
(2) Are there any additional effects (other than prevent the page from being swapped out) resulting from a set PG_locked flag?
(3) Does anyone know a more detailed documentation of the kiobuf interface, than the book mentioned above?

P.S. please put me on CC in your reply, since I am not in the mailing list.

Thanks for any help,
best regards
Martin Maletinsky

--

Supercomputing System AG          email: [email protected]
Martin Maletinsky                 phone: +41 (0)1 445 16 05
Technoparkstrasse 1               fax:   +41 (0)1 445 16 10

CH-8005 Zurich

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/

#1 lore raw
Quoted 6 lines · Martin Maletinsky

Hello,

I just read about the kiobuf interface in the Linux Device Driver book from Rubini/Corbet, and there is one point, which I don't understand:
- map_user_kiobuf() forces the pages within a user space address range into physical memory, and increments their usage count, which subsequently prevents the pages from being swapped out.

While it's true that having a non-zero reference count will prevent a page from being swapped out, such a page is still subject to all normal VM operations. In particular, the VM might unmap the page from your process, *decrement its reference count*, and then swap it out.

Quoted 2 lines

- lock_kiovec() sets the PG_locked flag for the pages in the kiobufs of a kiovec. The PG_locked flag prevents the pages from being swapped out, which is however already ensured by map_user_kiobuf().

I believe PG_locked will prevent the VM from unmapping the page, which does, in fact, gaurantee that it won't be swapped out.

Cheers,

-- Joe
"I'd rather chew my leg off than maintain Java code, which
sucks, 'cause I have a lot of Java code to maintain and the leg surgery is starting to get expensive." - Me
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/

#2 lore raw

Hi,

Quoted 9 lines · Joseph A. Knapka
Quoted 3 lines

I just read about the kiobuf interface in the Linux Device Driver book from Rubini/Corbet, and there is one point, which I don't understand:
- map_user_kiobuf() forces the pages within a user space address range into physical memory, and increments their usage count, which subsequently prevents the pages from being swapped out.

While it's true that having a non-zero reference count will prevent a page from being swapped out, such a page is still subject to all normal VM operations. In particular, the VM might unmap the page from your process, *decrement its reference count*, and then swap it out.

No. The VM may unmap the page, and it may allocate a swap entry for it, and it may decrement the reference count associated with any mmap of the page, but it will NOT decrement the refcount associated with the kiobuf itself, and will not evict the page from memory.

Quoted 6 lines
Quoted 2 lines

- lock_kiovec() sets the PG_locked flag for the pages in the kiobufs of a kiovec. The PG_locked flag prevents the pages from being swapped out, which is however already ensured by map_user_kiobuf().

I believe PG_locked will prevent the VM from unmapping the page, which does, in fact, gaurantee that it won't be swapped out.

The page will not be swapped out anyway. You don't need to lock it to prevent that. Locking may be useful if you want to serialise IO on a particular page, but if you don't need that, there's just no point in locking the pages.

Cheers,
Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/

#3 lore raw
Quoted 22 lines · Stephen C. Tweedie

Hi,

Quoted 9 lines · Joseph A. Knapka
Quoted 3 lines

I just read about the kiobuf interface in the Linux Device Driver book from Rubini/Corbet, and there is one point, which I don't understand:
- map_user_kiobuf() forces the pages within a user space address range into physical memory, and increments their usage count, which subsequently prevents the pages from being swapped out.

While it's true that having a non-zero reference count will prevent a page from being swapped out, such a page is still subject to all normal VM operations. In particular, the VM might unmap the page from your process, *decrement its reference count*, and then swap it out.

No. The VM may unmap the page, and it may allocate a swap entry for it, and it may decrement the reference count associated with any mmap of the page, but it will NOT decrement the refcount associated with the kiobuf itself, and will not evict the page from memory.

Quoted 3 lines
Quoted 2 lines

- lock_kiovec() sets the PG_locked flag for the pages in the kiobufs of a kiovec. The PG_locked flag prevents the pages from being swapped out, which is however already ensured by map_user_kiobuf().

Quoted 8 lines
Quoted 3 lines

I believe PG_locked will prevent the VM from unmapping the page, which does, in fact, gaurantee that it won't be swapped out.

The page will not be swapped out anyway. You don't need to lock it to prevent that. Locking may be useful if you want to serialise IO on a particular page, but if you don't need that, there's just no point in locking the pages.

Ref-counts protect from swapping out. But it's the PG_locked flag, that protects from starting other IO. If you are writing, read must not happen. If you are reading, nothing else at all must happen. So that's the difference. map_use_kiobuf fault the pages in. lock_kiovec make sure, that noone (else) is doing ANU IO on the pages.

--------------------------------------------------------------------------------
- Jan Hudec `Bulb' <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/

#4 lore raw

Hi,

Quoted 5 lines · Jan Hudec

Ref-counts protect from swapping out. But it's the PG_locked flag, that protects from starting other IO. If you are writing, read must not happen. If you are reading, nothing else at all must happen. So that's the difference. map_use_kiobuf fault the pages in. lock_kiovec make sure, that noone (else) is doing ANU IO on the pages.

Depends on what semantics you want. There's nothing to stop a kiobuf from being modified in flight. All the app has to do is create a thread and modify the buffer from within that thread.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/

#5 lore raw
Quoted 10 lines · Stephen C. Tweedie

Hi,

Quoted 5 lines · Jan Hudec

Ref-counts protect from swapping out. But it's the PG_locked flag, that protects from starting other IO. If you are writing, read must not happen. If you are reading, nothing else at all must happen. So that's the difference. map_use_kiobuf fault the pages in. lock_kiovec make sure, that noone (else) is doing ANU IO on the pages.

Quoted 3 lines

Depends on what semantics you want. There's nothing to stop a kiobuf from being modified in flight. All the app has to do is create a thread and modify the buffer from within that thread.

Well, if a multithread application writes to a buffer in one buffer while doing IO in another, it's asking for trouble. But kernel must make sure it does not start parallel IO on the same page, so the application does not get garbage when it behaves correctly (btw, share read-write mmap will probably get you in trouble anyway - or does kernel modify PTEs on locking a page?).

-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/