From e76856a4a5d2d03d6bf6bc21362de534a1e774a0 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 26 Apr 2010 16:56:37 +0000 Subject: [PATCH] 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 --- .../drivers/disk/scsi/scsi_cd/scsi_cd.cpp | 26 ++++++++++++------- .../drivers/disk/scsi/scsi_cd/scsi_cd.h | 8 +----- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp b/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp index eae1bd2692..bfc2e148a8 100644 --- a/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp +++ b/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp @@ -19,6 +19,7 @@ #include #include +#include #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; } diff --git a/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.h b/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.h index 632f2bd952..b683e79f44 100644 --- a/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.h +++ b/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.h @@ -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;