Enabled the IOCache depending on the amount of free pages. Currently the

limit is 180 MB.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36495 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2010-04-26 16:56:37 +00:00
parent 5060d7980f
commit e76856a4a5
2 changed files with 18 additions and 16 deletions

View File

@ -19,6 +19,7 @@
#include <string.h>
#include <io_requests.h>
#include <vm/vm_page.h>
#include "IOCache.h"
#include "IOSchedulerSimple.h"
@ -887,13 +888,22 @@ cd_set_capacity(cd_driver_info* info, uint64 capacity, uint32 blockSize)
if (status != B_OK)
panic("initializing DMAResource failed: %s", strerror(status));
#if USE_IO_CACHE
info->io_scheduler = new(std::nothrow) IOCache(info->dma_resource,
1024 * 1024);
#else
info->io_scheduler = new(std::nothrow) IOSchedulerSimple(
info->dma_resource);
#endif
// Allocate the I/O scheduler. If there seems to be sufficient memory
// we use an IOCache, since that adds caching at the lowest I/O layer
// and thus dramatically reduces I/O operations and seeks. The
// disadvantage is that it increases free memory (physical pages)
// fragmentation, which makes large contiguous allocations more likely
// to fail.
size_t freeMemory = vm_page_num_free_pages();
if (freeMemory > 180 * 1024 * 1024 / B_PAGE_SIZE) {
info->io_scheduler = new(std::nothrow) IOCache(info->dma_resource,
1024 * 1024);
} else {
dprintf("scsi_cd: Using IOSchedulerSimple instead of IOCache to "
"avoid memory allocation issues.\n");
info->io_scheduler = new(std::nothrow) IOSchedulerSimple(
info->dma_resource);
}
if (info->io_scheduler == NULL)
panic("allocating IOScheduler failed.");
@ -906,10 +916,8 @@ cd_set_capacity(cd_driver_info* info, uint64 capacity, uint32 blockSize)
info->io_scheduler->SetCallback(do_io, info);
}
#if USE_IO_CACHE
if (info->io_scheduler != NULL)
info->io_scheduler->SetDeviceCapacity(capacity * blockSize);
#endif
info->block_size = blockSize;
}

View File

@ -14,6 +14,7 @@
#include "dma_resources.h"
#include "IORequest.h"
struct IOCache;
struct IOScheduler;
@ -21,20 +22,13 @@ struct IOScheduler;
#define SCSI_CD_DRIVER_MODULE_NAME "drivers/disk/scsi/scsi_cd/driver_v1"
#define SCSI_CD_DEVICE_MODULE_NAME "drivers/disk/scsi/scsi_cd/device_v1"
// enables using the IOCache instead of the IOScheduler
#define USE_IO_CACHE 0
struct cd_driver_info {
device_node* node;
::scsi_periph_device scsi_periph_device;
::scsi_device scsi_device;
scsi_device_interface* scsi;
#if USE_IO_CACHE
IOCache* io_scheduler;
#else
IOScheduler* io_scheduler;
#endif
DMAResource* dma_resource;
uint64 capacity;