* Added new(vip_io_alloc) operators allocating memory from the VIP I/O

heap.
* Allocate IOBuffers, IORequests, and cookies on the VIP I/O heap, if
  necessary.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26969 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2008-08-14 01:38:08 +00:00
parent 749facf1eb
commit 4141741265
3 changed files with 53 additions and 10 deletions

View File

@ -53,14 +53,22 @@ IORequestChunk::~IORequestChunk()
}
void
IORequestChunk::operator delete(void* address, size_t size)
{
io_request_free(address);
}
// #pragma mark -
IOBuffer*
IOBuffer::Create(size_t count)
IOBuffer::Create(uint32 count, bool vip)
{
IOBuffer* buffer = (IOBuffer*)malloc(
sizeof(IOBuffer) + sizeof(iovec) * (count - 1));
size_t size = sizeof(IOBuffer) + sizeof(iovec) * (count - 1);
IOBuffer* buffer
= (IOBuffer*)(vip ? vip_io_request_malloc(size) : malloc(size));
if (buffer == NULL)
return NULL;
@ -68,6 +76,7 @@ IOBuffer::Create(size_t count)
buffer->fVecCount = 0;
buffer->fUser = false;
buffer->fPhysical = false;
buffer->fVIP = vip;
return buffer;
}
@ -76,7 +85,10 @@ IOBuffer::Create(size_t count)
void
IOBuffer::Delete()
{
free(this);
if (fVIP)
vip_io_request_free(this);
else
free(this);
}
@ -589,7 +601,7 @@ status_t
IORequest::Init(off_t offset, size_t firstVecOffset, const iovec* vecs,
size_t count, size_t length, bool write, uint32 flags)
{
fBuffer = IOBuffer::Create(count);
fBuffer = IOBuffer::Create(count, (flags & B_VIP_IO_REQUEST) != 0);
if (fBuffer == NULL)
return B_NO_MEMORY;
@ -651,8 +663,8 @@ IORequest::CreateSubRequest(off_t parentOffset, off_t offset, size_t length,
}
// create subrequest
IORequest* subRequest = new(std::nothrow) IORequest;
// TODO: Heed B_VIP_IO_REQUEST!
IORequest* subRequest = (fFlags & B_VIP_IO_REQUEST) != 0
? new(vip_io_alloc) IORequest : new(std::nothrow) IORequest;
if (subRequest == NULL)
return B_NO_MEMORY;
@ -1205,6 +1217,9 @@ vip_io_request_allocator_init()
"heap\n");
return;
}
dprintf("vip_io_request_allocator_init(): created VIP I/O heap: %p\n",
sVIPHeap);
}

View File

@ -8,6 +8,8 @@
#include <sys/uio.h>
#include <new>
#include <SupportDefs.h>
#include <condition_variable.h>
@ -28,7 +30,7 @@ typedef struct IOOperation io_operation;
class IOBuffer : public DoublyLinkedListLinkImpl<IOBuffer> {
public:
static IOBuffer* Create(size_t count);
static IOBuffer* Create(uint32 count, bool vip);
void Delete();
bool IsVirtual() const { return !fPhysical; }
@ -66,6 +68,7 @@ private:
bool fUser;
bool fPhysical;
bool fVIP;
size_t fLength;
size_t fVecCount;
size_t fCapacity;
@ -90,6 +93,8 @@ public:
DoublyLinkedListLink<IORequestChunk>*
ListLink() { return &fListLink; }
void operator delete(void* address, size_t size);
protected:
void SetStatus(status_t status)
{ fStatus = status; }
@ -249,6 +254,7 @@ struct IORequest : IORequestChunk, DoublyLinkedListLinkImpl<IORequest> {
bool IsWrite() const { return fIsWrite; }
bool IsRead() const { return !fIsWrite; }
team_id Team() const { return fTeam; }
uint32 Flags() const { return fFlags; }
IOBuffer* Buffer() const { return fBuffer; }
off_t Offset() const { return fOffset; }
@ -331,4 +337,22 @@ void io_request_free(void* address);
void vip_io_request_allocator_init();
static const struct vip_io_alloc_t {
} vip_io_alloc = {};
inline void*
operator new(size_t size, const vip_io_alloc_t& vip_io_alloc) throw ()
{
return vip_io_request_malloc(size);
}
inline void*
operator new[](size_t size, const vip_io_alloc_t& vip_io_alloc) throw ()
{
return vip_io_request_malloc(size);
}
#endif // IO_REQUESTS_H

View File

@ -23,6 +23,9 @@ struct iterative_io_cookie {
off_t request_offset;
io_request_finished_callback next_finished_callback;
void* next_finished_cookie;
void operator delete(void* address, size_t size)
{ io_request_free(address); }
};
@ -420,8 +423,9 @@ do_iterative_fd_io(int fd, io_request* request, iterative_io_get_vecs getVecs,
}
iterative_io_cookie* iterationCookie
= new(std::nothrow) iterative_io_cookie;
// TODO: Heed B_VIP_IO_REQUEST!
= (request->Flags() & B_VIP_IO_REQUEST) != 0
? new(vip_io_alloc) iterative_io_cookie
: new(std::nothrow) iterative_io_cookie;
if (iterationCookie == NULL) {
// no memory -- fall back to synchronous I/O
return do_synchronous_iterative_vnode_io(vnode, descriptor->cookie,