From fb52b1f8b4be971f708d17b2ad2454120cd46d81 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 25 Nov 2013 12:40:58 +0100 Subject: [PATCH] VFS FIFO: Enlarge FIFO buffer sizes * Increase FIFO buffer capacity from 32 to 64 KiB and the FIFO atomic write size ({BUF_SIZE}) from 512 bytes to 4 KiB (both like Linux). * Fix *pathconf(..., _PC_PIPE_BUF). It was returning 4 KiB although the implemented atomic write size was 512 bytes only. Now both *pathconf() and the FIFO implementation refer to the same constant. --- headers/private/system/vfs_defs.h | 21 +++++++++++++++++++-- src/system/kernel/fs/fifo.cpp | 12 ++++-------- src/system/libroot/posix/unistd/conf.cpp | 3 ++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/headers/private/system/vfs_defs.h b/headers/private/system/vfs_defs.h index 9462ccd3b3..adf098a23f 100644 --- a/headers/private/system/vfs_defs.h +++ b/headers/private/system/vfs_defs.h @@ -1,6 +1,7 @@ /* - * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. - * Distributed under the terms of the MIT License. + * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de. + * 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. @@ -8,6 +9,8 @@ #ifndef _SYSTEM_VFS_DEFS_H #define _SYSTEM_VFS_DEFS_H + +#include #include #include @@ -20,4 +23,18 @@ struct fd_info { ino_t node; }; + +/* maximum write size to a pipe/FIFO that is guaranteed not to be interleaved + with other writes (aka {PIPE_BUF}; must be >= _POSIX_PIPE_BUF) */ +#define VFS_FIFO_ATOMIC_WRITE_SIZE (4 * 1024) + +/* pipe/FIFO buffer capacity */ +#define VFS_FIFO_BUFFER_CAPACITY (64 * 1024) + +// make sure the constant values are sane +#if VFS_FIFO_ATOMIC_WRITE_SIZE < _POSIX_PIPE_BUF +# error VFS_FIFO_ATOMIC_WRITE_SIZE < _POSIX_PIPE_BUF! +#endif + + #endif /* _SYSTEM_VFS_DEFS_H */ diff --git a/src/system/kernel/fs/fifo.cpp b/src/system/kernel/fs/fifo.cpp index 1735c269b3..0e385177b8 100644 --- a/src/system/kernel/fs/fifo.cpp +++ b/src/system/kernel/fs/fifo.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -42,11 +43,6 @@ #define PIPEFS_HASH_SIZE 16 -#define PIPEFS_MAX_BUFFER_SIZE 32768 - - -// TODO: PIPE_BUF is supposed to be defined somewhere else. -#define PIPE_BUF _POSIX_PIPE_BUF namespace fifo { @@ -252,7 +248,7 @@ RingBuffer::CreateBuffer() if (fBuffer != NULL) return B_OK; - fBuffer = create_ring_buffer(PIPEFS_MAX_BUFFER_SIZE); + fBuffer = create_ring_buffer(VFS_FIFO_BUFFER_CAPACITY); return fBuffer != NULL ? B_OK : B_NO_MEMORY; } @@ -376,10 +372,10 @@ Inode::WriteDataToBuffer(const void* _data, size_t* _length, bool nonBlocking) TRACE("Inode %p::WriteDataToBuffer(data = %p, bytes = %zu)\n", this, data, dataSize); - // According to the standard, request up to PIPE_BUF bytes shall not be + // A request up to VFS_FIFO_ATOMIC_WRITE_SIZE bytes shall not be // interleaved with other writer's data. size_t minToWrite = 1; - if (dataSize <= PIPE_BUF) + if (dataSize <= VFS_FIFO_ATOMIC_WRITE_SIZE) minToWrite = dataSize; while (dataSize > 0) { diff --git a/src/system/libroot/posix/unistd/conf.cpp b/src/system/libroot/posix/unistd/conf.cpp index 6693fbe15d..50f09b8c5e 100644 --- a/src/system/libroot/posix/unistd/conf.cpp +++ b/src/system/libroot/posix/unistd/conf.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -257,7 +258,7 @@ __pathconf_common(struct statvfs *fs, struct stat *st, return PATH_MAX; case _PC_PIPE_BUF: - return 4096; + return VFS_FIFO_ATOMIC_WRITE_SIZE; case _PC_LINK_MAX: return LINK_MAX;