[haiku-development] Re: Implementing vm_page functions

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 24 Jul 2017 00:09:16 +0200

On 21.07.2017 00:21, Vivek Roy wrote:

Trying to implement linux/dma-mapping.h (dma == direct memory access), I
went on to implementing mm.h (mm == memory map), and hence to vm_page.h
The following vm_page functions have been used by FreeBSD's mm.h
implementation (not yet implemented at least directly in Haiku's
existing vm_page.h):

1. vm_page_dirty(page)
    flags the entire page as dirty.  It is expected that the page is not
currently on the cache queue

May be more or less equivalent to vm_page_set_state(PAGE_STATE_MODIFIED). You can't make that call in some situations, though.

2. vm_page_reference(page)
    mark the page as referenced from third-party kernel modules

Not sure what being referenced entails exactly, but this is probably a concept Haiku's VM subsystem doesn't implement.

3. vm_page_lock(page)
    locks the page

4. vm_page_unlock(page)
    unlocks a locked page

Again, not sure what that means exactly. If this is about serializing access to the page structure, this is done by locking the page's cache. If the page needs to be protected for a longer time (e.g. while paging its data from/to disk), it needs to be marked busy. This also means that anyone accessing a page needs to check the busy flag and possibly wait for it to be cleared again.

5. vm_page_hold(page)
    increases the hold count on a page. This prevents the page daemon
from freeing the page

6. vm_page_unhold(page)
    reduces the hold count on a page. If the hold count is zero it is
possible that the page will be    freed by the page daemon

No exact equivalent in Haiku's VM subsystem. The wired count has a somewhat similar effect. But the intention behind the wired count is that it represents the number of times the page is mapped via page tables without association to an area.

7. vm_page_wire(page)
    increments the wire count on a page, and removes it from whatever
queue it is on

8. vm_page_unwire(page, PQ_ACTIVE)
    releases one of the wirings on the page. When write_count reaches
zero the page is placed back onto either the active queue (if activate
is non-zero) or onto the inactive queue (if activate is zero).  If the
page is unmanaged (PG_UNMANAGED is set) then the page is left on PQ_NONE

That seems similar to the wired count in Haiku. However, Haiku's wired count is not completely orthogonal to the page ownership: when a page is removed from a cache and freed, its wired count must be 0.

CU, Ingo


Other related posts: