2010-01-14 06:26:12 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2002-2010, Haiku. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
* Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
|
|
|
#ifndef KERNEL_VM_VM_TRANSLATION_MAP_H
|
|
|
|
#define KERNEL_VM_VM_TRANSLATION_MAP_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <lock.h>
|
|
|
|
|
2010-05-02 01:33:12 +04:00
|
|
|
#include <vm/VMArea.h>
|
|
|
|
|
2010-01-14 06:26:12 +03:00
|
|
|
|
|
|
|
struct kernel_args;
|
* Removed useless return parameter from vm_remove_all_page_mappings().
* Added vm_clear_page_mapping_accessed_flags() and
vm_remove_all_page_mappings_if_unaccessed(), which combine the functionality
of vm_test_map_activation(), vm_clear_map_flags(), and
vm_remove_all_page_mappings(), thus saving lots of calls to translation map
methods. The backend is the new method
VMTranslationMap::ClearAccessedAndModified().
* Started to make use of the cached page queue and changed the meaning of the
other non-free queues slightly:
- Active queue: Contains mapped pages that have been used recently.
- Inactive queue: Contains mapped pages that have not been used recently. Also
contains unmapped temporary pages.
- Modified queue: Contains unmapped modified pages.
- Cached queue: Contains unmapped unmodified pages (LRU sorted).
Unless we're actually low on memory and actively do paging, modified and
cached queues only contain non-temporary pages. Cached pages are considered
quasi free. They still belong to a cache, but since they are unmodified and
unmapped, they can be freed immediately. And this is what
vm_page_[try_]reserve_pages() do now when there are no more actually free
pages at hand. Essentially this means that pages storing cached file data,
unless mmap()ped, no longer are considered used and don't contribute to page
pressure. Paging will not happen as long there are enough free + cached pages
available.
* Reimplemented the page daemon. It no longer scans all pages, but instead works
the page queues. As long as the free pages situation is harmless, it only
iterates through the active queue and deactivates pages that have not been
used recently. When paging occurs it additionally scans the inactive queue and
frees pages that have not been used recently.
* Changed the page reservation/allocation interface:
vm_page_[try_]reserve_pages(), vm_page_unreserve_pages(), and
vm_page_allocate_page() now take a vm_page_reservation structure pointer.
The reservation functions initialize the structure -- currently consisting
only of a count member for the number of still reserved pages.
vm_page_allocate_page() decrements the count and vm_page_unreserve_pages()
unreserves the remaining pages (if any). Advantages are that reservation/
unreservation mismatches cannot occur anymore, that vm_page_allocate_page()
can verify that the caller has indeed a reserved page left, and that there's
no unnecessary pressure on the free page pool anymore. The only disadvantage
is that the vm_page_reservation object needs to be passed around a bit.
* Reworked the page reservation implementation:
- Got rid of sSystemReservedPages and sPageDeficit. Instead
sUnreservedFreePages now actually contains the number of free pages that
have not yet been reserved (it cannot become negative anymore) and the new
sUnsatisfiedPageReservations contains the number of pages that are still
needed for reservation.
- Threads waiting for reservations do now add themselves to a waiter queue,
which is ordered by descending priority (VM priority and thread priority).
High priority waiters are served first when pages become available.
Fixes #5328.
* cache_prefetch_vnode(): Would reserve one less page than allocated later, if
the size wasn't page aligned.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35393 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-02-03 21:53:52 +03:00
|
|
|
struct vm_page_reservation;
|
2010-01-14 06:26:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
struct VMTranslationMap {
|
|
|
|
VMTranslationMap();
|
|
|
|
virtual ~VMTranslationMap();
|
|
|
|
|
2010-01-14 23:44:29 +03:00
|
|
|
virtual bool Lock() = 0;
|
|
|
|
virtual void Unlock() = 0;
|
2010-01-14 06:26:12 +03:00
|
|
|
|
|
|
|
virtual addr_t MappedSize() const = 0;
|
|
|
|
virtual size_t MaxPagesNeededToMap(addr_t start,
|
|
|
|
addr_t end) const = 0;
|
|
|
|
|
|
|
|
virtual status_t Map(addr_t virtualAddress,
|
2010-05-26 01:34:08 +04:00
|
|
|
phys_addr_t physicalAddress,
|
|
|
|
uint32 attributes, uint32 memoryType,
|
* Removed useless return parameter from vm_remove_all_page_mappings().
* Added vm_clear_page_mapping_accessed_flags() and
vm_remove_all_page_mappings_if_unaccessed(), which combine the functionality
of vm_test_map_activation(), vm_clear_map_flags(), and
vm_remove_all_page_mappings(), thus saving lots of calls to translation map
methods. The backend is the new method
VMTranslationMap::ClearAccessedAndModified().
* Started to make use of the cached page queue and changed the meaning of the
other non-free queues slightly:
- Active queue: Contains mapped pages that have been used recently.
- Inactive queue: Contains mapped pages that have not been used recently. Also
contains unmapped temporary pages.
- Modified queue: Contains unmapped modified pages.
- Cached queue: Contains unmapped unmodified pages (LRU sorted).
Unless we're actually low on memory and actively do paging, modified and
cached queues only contain non-temporary pages. Cached pages are considered
quasi free. They still belong to a cache, but since they are unmodified and
unmapped, they can be freed immediately. And this is what
vm_page_[try_]reserve_pages() do now when there are no more actually free
pages at hand. Essentially this means that pages storing cached file data,
unless mmap()ped, no longer are considered used and don't contribute to page
pressure. Paging will not happen as long there are enough free + cached pages
available.
* Reimplemented the page daemon. It no longer scans all pages, but instead works
the page queues. As long as the free pages situation is harmless, it only
iterates through the active queue and deactivates pages that have not been
used recently. When paging occurs it additionally scans the inactive queue and
frees pages that have not been used recently.
* Changed the page reservation/allocation interface:
vm_page_[try_]reserve_pages(), vm_page_unreserve_pages(), and
vm_page_allocate_page() now take a vm_page_reservation structure pointer.
The reservation functions initialize the structure -- currently consisting
only of a count member for the number of still reserved pages.
vm_page_allocate_page() decrements the count and vm_page_unreserve_pages()
unreserves the remaining pages (if any). Advantages are that reservation/
unreservation mismatches cannot occur anymore, that vm_page_allocate_page()
can verify that the caller has indeed a reserved page left, and that there's
no unnecessary pressure on the free page pool anymore. The only disadvantage
is that the vm_page_reservation object needs to be passed around a bit.
* Reworked the page reservation implementation:
- Got rid of sSystemReservedPages and sPageDeficit. Instead
sUnreservedFreePages now actually contains the number of free pages that
have not yet been reserved (it cannot become negative anymore) and the new
sUnsatisfiedPageReservations contains the number of pages that are still
needed for reservation.
- Threads waiting for reservations do now add themselves to a waiter queue,
which is ordered by descending priority (VM priority and thread priority).
High priority waiters are served first when pages become available.
Fixes #5328.
* cache_prefetch_vnode(): Would reserve one less page than allocated later, if
the size wasn't page aligned.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35393 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-02-03 21:53:52 +03:00
|
|
|
vm_page_reservation* reservation) = 0;
|
2010-01-14 06:26:12 +03:00
|
|
|
virtual status_t Unmap(addr_t start, addr_t end) = 0;
|
|
|
|
|
2010-01-16 01:32:51 +03:00
|
|
|
// map not locked
|
* Removed useless return parameter from vm_remove_all_page_mappings().
* Added vm_clear_page_mapping_accessed_flags() and
vm_remove_all_page_mappings_if_unaccessed(), which combine the functionality
of vm_test_map_activation(), vm_clear_map_flags(), and
vm_remove_all_page_mappings(), thus saving lots of calls to translation map
methods. The backend is the new method
VMTranslationMap::ClearAccessedAndModified().
* Started to make use of the cached page queue and changed the meaning of the
other non-free queues slightly:
- Active queue: Contains mapped pages that have been used recently.
- Inactive queue: Contains mapped pages that have not been used recently. Also
contains unmapped temporary pages.
- Modified queue: Contains unmapped modified pages.
- Cached queue: Contains unmapped unmodified pages (LRU sorted).
Unless we're actually low on memory and actively do paging, modified and
cached queues only contain non-temporary pages. Cached pages are considered
quasi free. They still belong to a cache, but since they are unmodified and
unmapped, they can be freed immediately. And this is what
vm_page_[try_]reserve_pages() do now when there are no more actually free
pages at hand. Essentially this means that pages storing cached file data,
unless mmap()ped, no longer are considered used and don't contribute to page
pressure. Paging will not happen as long there are enough free + cached pages
available.
* Reimplemented the page daemon. It no longer scans all pages, but instead works
the page queues. As long as the free pages situation is harmless, it only
iterates through the active queue and deactivates pages that have not been
used recently. When paging occurs it additionally scans the inactive queue and
frees pages that have not been used recently.
* Changed the page reservation/allocation interface:
vm_page_[try_]reserve_pages(), vm_page_unreserve_pages(), and
vm_page_allocate_page() now take a vm_page_reservation structure pointer.
The reservation functions initialize the structure -- currently consisting
only of a count member for the number of still reserved pages.
vm_page_allocate_page() decrements the count and vm_page_unreserve_pages()
unreserves the remaining pages (if any). Advantages are that reservation/
unreservation mismatches cannot occur anymore, that vm_page_allocate_page()
can verify that the caller has indeed a reserved page left, and that there's
no unnecessary pressure on the free page pool anymore. The only disadvantage
is that the vm_page_reservation object needs to be passed around a bit.
* Reworked the page reservation implementation:
- Got rid of sSystemReservedPages and sPageDeficit. Instead
sUnreservedFreePages now actually contains the number of free pages that
have not yet been reserved (it cannot become negative anymore) and the new
sUnsatisfiedPageReservations contains the number of pages that are still
needed for reservation.
- Threads waiting for reservations do now add themselves to a waiter queue,
which is ordered by descending priority (VM priority and thread priority).
High priority waiters are served first when pages become available.
Fixes #5328.
* cache_prefetch_vnode(): Would reserve one less page than allocated later, if
the size wasn't page aligned.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35393 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-02-03 21:53:52 +03:00
|
|
|
virtual status_t UnmapPage(VMArea* area, addr_t address,
|
|
|
|
bool updatePageQueue) = 0;
|
2010-01-16 01:32:51 +03:00
|
|
|
virtual void UnmapPages(VMArea* area, addr_t base,
|
* Removed useless return parameter from vm_remove_all_page_mappings().
* Added vm_clear_page_mapping_accessed_flags() and
vm_remove_all_page_mappings_if_unaccessed(), which combine the functionality
of vm_test_map_activation(), vm_clear_map_flags(), and
vm_remove_all_page_mappings(), thus saving lots of calls to translation map
methods. The backend is the new method
VMTranslationMap::ClearAccessedAndModified().
* Started to make use of the cached page queue and changed the meaning of the
other non-free queues slightly:
- Active queue: Contains mapped pages that have been used recently.
- Inactive queue: Contains mapped pages that have not been used recently. Also
contains unmapped temporary pages.
- Modified queue: Contains unmapped modified pages.
- Cached queue: Contains unmapped unmodified pages (LRU sorted).
Unless we're actually low on memory and actively do paging, modified and
cached queues only contain non-temporary pages. Cached pages are considered
quasi free. They still belong to a cache, but since they are unmodified and
unmapped, they can be freed immediately. And this is what
vm_page_[try_]reserve_pages() do now when there are no more actually free
pages at hand. Essentially this means that pages storing cached file data,
unless mmap()ped, no longer are considered used and don't contribute to page
pressure. Paging will not happen as long there are enough free + cached pages
available.
* Reimplemented the page daemon. It no longer scans all pages, but instead works
the page queues. As long as the free pages situation is harmless, it only
iterates through the active queue and deactivates pages that have not been
used recently. When paging occurs it additionally scans the inactive queue and
frees pages that have not been used recently.
* Changed the page reservation/allocation interface:
vm_page_[try_]reserve_pages(), vm_page_unreserve_pages(), and
vm_page_allocate_page() now take a vm_page_reservation structure pointer.
The reservation functions initialize the structure -- currently consisting
only of a count member for the number of still reserved pages.
vm_page_allocate_page() decrements the count and vm_page_unreserve_pages()
unreserves the remaining pages (if any). Advantages are that reservation/
unreservation mismatches cannot occur anymore, that vm_page_allocate_page()
can verify that the caller has indeed a reserved page left, and that there's
no unnecessary pressure on the free page pool anymore. The only disadvantage
is that the vm_page_reservation object needs to be passed around a bit.
* Reworked the page reservation implementation:
- Got rid of sSystemReservedPages and sPageDeficit. Instead
sUnreservedFreePages now actually contains the number of free pages that
have not yet been reserved (it cannot become negative anymore) and the new
sUnsatisfiedPageReservations contains the number of pages that are still
needed for reservation.
- Threads waiting for reservations do now add themselves to a waiter queue,
which is ordered by descending priority (VM priority and thread priority).
High priority waiters are served first when pages become available.
Fixes #5328.
* cache_prefetch_vnode(): Would reserve one less page than allocated later, if
the size wasn't page aligned.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35393 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-02-03 21:53:52 +03:00
|
|
|
size_t size, bool updatePageQueue);
|
2010-01-16 01:32:51 +03:00
|
|
|
virtual void UnmapArea(VMArea* area,
|
|
|
|
bool deletingAddressSpace,
|
|
|
|
bool ignoreTopCachePageFlags);
|
|
|
|
|
2010-01-14 06:26:12 +03:00
|
|
|
virtual status_t Query(addr_t virtualAddress,
|
2010-05-26 01:34:08 +04:00
|
|
|
phys_addr_t* _physicalAddress,
|
2010-01-14 06:26:12 +03:00
|
|
|
uint32* _flags) = 0;
|
|
|
|
virtual status_t QueryInterrupt(addr_t virtualAddress,
|
2010-05-26 01:34:08 +04:00
|
|
|
phys_addr_t* _physicalAddress,
|
2010-01-14 06:26:12 +03:00
|
|
|
uint32* _flags) = 0;
|
|
|
|
|
|
|
|
virtual status_t Protect(addr_t base, addr_t top,
|
2010-05-02 01:33:12 +04:00
|
|
|
uint32 attributes, uint32 memoryType) = 0;
|
2010-01-16 01:32:51 +03:00
|
|
|
status_t ProtectPage(VMArea* area, addr_t address,
|
|
|
|
uint32 attributes);
|
|
|
|
status_t ProtectArea(VMArea* area,
|
|
|
|
uint32 attributes);
|
|
|
|
|
2010-01-14 06:26:12 +03:00
|
|
|
virtual status_t ClearFlags(addr_t virtualAddress,
|
|
|
|
uint32 flags) = 0;
|
|
|
|
|
* Removed useless return parameter from vm_remove_all_page_mappings().
* Added vm_clear_page_mapping_accessed_flags() and
vm_remove_all_page_mappings_if_unaccessed(), which combine the functionality
of vm_test_map_activation(), vm_clear_map_flags(), and
vm_remove_all_page_mappings(), thus saving lots of calls to translation map
methods. The backend is the new method
VMTranslationMap::ClearAccessedAndModified().
* Started to make use of the cached page queue and changed the meaning of the
other non-free queues slightly:
- Active queue: Contains mapped pages that have been used recently.
- Inactive queue: Contains mapped pages that have not been used recently. Also
contains unmapped temporary pages.
- Modified queue: Contains unmapped modified pages.
- Cached queue: Contains unmapped unmodified pages (LRU sorted).
Unless we're actually low on memory and actively do paging, modified and
cached queues only contain non-temporary pages. Cached pages are considered
quasi free. They still belong to a cache, but since they are unmodified and
unmapped, they can be freed immediately. And this is what
vm_page_[try_]reserve_pages() do now when there are no more actually free
pages at hand. Essentially this means that pages storing cached file data,
unless mmap()ped, no longer are considered used and don't contribute to page
pressure. Paging will not happen as long there are enough free + cached pages
available.
* Reimplemented the page daemon. It no longer scans all pages, but instead works
the page queues. As long as the free pages situation is harmless, it only
iterates through the active queue and deactivates pages that have not been
used recently. When paging occurs it additionally scans the inactive queue and
frees pages that have not been used recently.
* Changed the page reservation/allocation interface:
vm_page_[try_]reserve_pages(), vm_page_unreserve_pages(), and
vm_page_allocate_page() now take a vm_page_reservation structure pointer.
The reservation functions initialize the structure -- currently consisting
only of a count member for the number of still reserved pages.
vm_page_allocate_page() decrements the count and vm_page_unreserve_pages()
unreserves the remaining pages (if any). Advantages are that reservation/
unreservation mismatches cannot occur anymore, that vm_page_allocate_page()
can verify that the caller has indeed a reserved page left, and that there's
no unnecessary pressure on the free page pool anymore. The only disadvantage
is that the vm_page_reservation object needs to be passed around a bit.
* Reworked the page reservation implementation:
- Got rid of sSystemReservedPages and sPageDeficit. Instead
sUnreservedFreePages now actually contains the number of free pages that
have not yet been reserved (it cannot become negative anymore) and the new
sUnsatisfiedPageReservations contains the number of pages that are still
needed for reservation.
- Threads waiting for reservations do now add themselves to a waiter queue,
which is ordered by descending priority (VM priority and thread priority).
High priority waiters are served first when pages become available.
Fixes #5328.
* cache_prefetch_vnode(): Would reserve one less page than allocated later, if
the size wasn't page aligned.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35393 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-02-03 21:53:52 +03:00
|
|
|
virtual bool ClearAccessedAndModified(
|
|
|
|
VMArea* area, addr_t address,
|
|
|
|
bool unmapIfUnaccessed,
|
|
|
|
bool& _modified) = 0;
|
|
|
|
|
2010-01-14 06:26:12 +03:00
|
|
|
virtual void Flush() = 0;
|
|
|
|
|
2010-06-21 17:32:33 +04:00
|
|
|
protected:
|
|
|
|
void PageUnmapped(VMArea* area,
|
|
|
|
page_num_t pageNumber, bool accessed,
|
|
|
|
bool modified, bool updatePageQueue);
|
|
|
|
void UnaccessedPageUnmapped(VMArea* area,
|
|
|
|
page_num_t pageNumber);
|
|
|
|
|
2010-01-14 06:26:12 +03:00
|
|
|
protected:
|
|
|
|
recursive_lock fLock;
|
|
|
|
int32 fMapCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct VMPhysicalPageMapper {
|
|
|
|
VMPhysicalPageMapper();
|
|
|
|
virtual ~VMPhysicalPageMapper();
|
|
|
|
|
|
|
|
// get/put virtual address for physical page -- will be usuable on all CPUs
|
|
|
|
// (usually more expensive than the *_current_cpu() versions)
|
2010-05-26 01:34:08 +04:00
|
|
|
virtual status_t GetPage(phys_addr_t physicalAddress,
|
2010-01-14 06:26:12 +03:00
|
|
|
addr_t* _virtualAddress,
|
|
|
|
void** _handle) = 0;
|
|
|
|
virtual status_t PutPage(addr_t virtualAddress,
|
|
|
|
void* handle) = 0;
|
|
|
|
|
|
|
|
// get/put virtual address for physical page -- thread must be pinned the
|
|
|
|
// whole time
|
|
|
|
virtual status_t GetPageCurrentCPU(
|
2010-05-26 01:34:08 +04:00
|
|
|
phys_addr_t physicalAddress,
|
2010-01-14 06:26:12 +03:00
|
|
|
addr_t* _virtualAddress,
|
|
|
|
void** _handle) = 0;
|
|
|
|
virtual status_t PutPageCurrentCPU(addr_t virtualAddress,
|
|
|
|
void* _handle) = 0;
|
|
|
|
|
|
|
|
// get/put virtual address for physical in KDL
|
2010-05-26 01:34:08 +04:00
|
|
|
virtual status_t GetPageDebug(phys_addr_t physicalAddress,
|
2010-01-14 06:26:12 +03:00
|
|
|
addr_t* _virtualAddress,
|
|
|
|
void** _handle) = 0;
|
|
|
|
virtual status_t PutPageDebug(addr_t virtualAddress,
|
|
|
|
void* handle) = 0;
|
|
|
|
|
|
|
|
// memory operations on pages
|
2010-05-26 01:34:08 +04:00
|
|
|
virtual status_t MemsetPhysical(phys_addr_t address, int value,
|
|
|
|
phys_size_t length) = 0;
|
|
|
|
virtual status_t MemcpyFromPhysical(void* to, phys_addr_t from,
|
2010-01-14 06:26:12 +03:00
|
|
|
size_t length, bool user) = 0;
|
2010-05-26 01:34:08 +04:00
|
|
|
virtual status_t MemcpyToPhysical(phys_addr_t to,
|
|
|
|
const void* from, size_t length,
|
|
|
|
bool user) = 0;
|
|
|
|
virtual void MemcpyPhysicalPage(phys_addr_t to,
|
|
|
|
phys_addr_t from) = 0;
|
2010-01-14 06:26:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-01-16 01:32:51 +03:00
|
|
|
|
|
|
|
inline status_t
|
|
|
|
VMTranslationMap::ProtectPage(VMArea* area, addr_t address, uint32 attributes)
|
|
|
|
{
|
2010-05-02 01:33:12 +04:00
|
|
|
return Protect(address, address + B_PAGE_SIZE - 1, attributes,
|
|
|
|
area->MemoryType());
|
2010-01-16 01:32:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <vm/VMArea.h>
|
|
|
|
inline status_t
|
|
|
|
VMTranslationMap::ProtectArea(VMArea* area, uint32 attributes)
|
|
|
|
{
|
2010-05-02 01:33:12 +04:00
|
|
|
return Protect(area->Base(), area->Base() + area->Size() - 1, attributes,
|
|
|
|
area->MemoryType());
|
2010-01-16 01:32:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 06:26:12 +03:00
|
|
|
#include <arch/vm_translation_map.h>
|
|
|
|
|
|
|
|
#endif /* KERNEL_VM_VM_TRANSLATION_MAP_H */
|