* kiobuf interface / PG_locked flag
@ 2002-09-12 8:48 Martin Maletinsky
2002-09-12 15:24 ` Joseph A. Knapka
0 siblings, 1 reply; 6+ messages in thread
From: Martin Maletinsky @ 2002-09-12 8:48 UTC (permalink / raw)
To: linux-mm, kernelnewbies
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: maletinsky@scs.ch
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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: kiobuf interface / PG_locked flag
2002-09-12 8:48 kiobuf interface / PG_locked flag Martin Maletinsky
@ 2002-09-12 15:24 ` Joseph A. Knapka
2002-09-12 15:33 ` Stephen C. Tweedie
0 siblings, 1 reply; 6+ messages in thread
From: Joseph A. Knapka @ 2002-09-12 15:24 UTC (permalink / raw)
To: Martin Maletinsky; +Cc: linux-mm, kernelnewbies
Martin Maletinsky wrote:
>
> 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.
> - 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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: kiobuf interface / PG_locked flag
2002-09-12 15:24 ` Joseph A. Knapka
@ 2002-09-12 15:33 ` Stephen C. Tweedie
2002-09-13 12:41 ` Jan Hudec
0 siblings, 1 reply; 6+ messages in thread
From: Stephen C. Tweedie @ 2002-09-12 15:33 UTC (permalink / raw)
To: Joseph A. Knapka; +Cc: Martin Maletinsky, linux-mm, kernelnewbies
Hi,
On Thu, Sep 12, 2002 at 09:24:56AM -0600, Joseph A. Knapka wrote:
> > 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.
> > - 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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: kiobuf interface / PG_locked flag
2002-09-12 15:33 ` Stephen C. Tweedie
@ 2002-09-13 12:41 ` Jan Hudec
2002-09-13 14:45 ` Stephen C. Tweedie
0 siblings, 1 reply; 6+ messages in thread
From: Jan Hudec @ 2002-09-13 12:41 UTC (permalink / raw)
To: Stephen C. Tweedie
Cc: Joseph A. Knapka, Martin Maletinsky, linux-mm, kernelnewbies
On Thu, Sep 12, 2002 at 04:33:08PM +0100, Stephen C. Tweedie wrote:
> Hi,
>
> On Thu, Sep 12, 2002 at 09:24:56AM -0600, Joseph A. Knapka wrote:
>
> > > 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.
>
> > > - 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.
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' <bulb@ucw.cz>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: kiobuf interface / PG_locked flag
2002-09-13 12:41 ` Jan Hudec
@ 2002-09-13 14:45 ` Stephen C. Tweedie
2002-09-15 15:54 ` Jan Hudec
0 siblings, 1 reply; 6+ messages in thread
From: Stephen C. Tweedie @ 2002-09-13 14:45 UTC (permalink / raw)
To: Jan Hudec, Stephen C. Tweedie, Joseph A. Knapka,
Martin Maletinsky, linux-mm, kernelnewbies
Hi,
On Fri, Sep 13, 2002 at 02:41:27PM +0200, Jan Hudec wrote:
> 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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: kiobuf interface / PG_locked flag
2002-09-13 14:45 ` Stephen C. Tweedie
@ 2002-09-15 15:54 ` Jan Hudec
0 siblings, 0 replies; 6+ messages in thread
From: Jan Hudec @ 2002-09-15 15:54 UTC (permalink / raw)
To: Stephen C. Tweedie
Cc: Joseph A. Knapka, Martin Maletinsky, linux-mm, kernelnewbies
On Fri, Sep 13, 2002 at 03:45:41PM +0100, Stephen C. Tweedie wrote:
> Hi,
>
> On Fri, Sep 13, 2002 at 02:41:27PM +0200, Jan Hudec wrote:
>
> > 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.
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 <bulb@ucw.cz>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-09-15 15:54 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-12 8:48 kiobuf interface / PG_locked flag Martin Maletinsky
2002-09-12 15:24 ` Joseph A. Knapka
2002-09-12 15:33 ` Stephen C. Tweedie
2002-09-13 12:41 ` Jan Hudec
2002-09-13 14:45 ` Stephen C. Tweedie
2002-09-15 15:54 ` Jan Hudec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox