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.
This commit is contained in:
Ingo Weinhold
2013-11-25 12:45:37 +01:00
parent 334ae3c73b
commit fb52b1f8b4
3 changed files with 25 additions and 11 deletions
+19 -2
View File
@@ -1,6 +1,7 @@
/* /*
* Copyright 2002-2008, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2002-2008, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Copyright 2013, Ingo Weinhold, [email protected]e.
* All rights reserved. Distributed under the terms of the MIT License.
* *
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
* Distributed under the terms of the NewOS License. * Distributed under the terms of the NewOS License.
@@ -8,6 +9,8 @@
#ifndef _SYSTEM_VFS_DEFS_H #ifndef _SYSTEM_VFS_DEFS_H
#define _SYSTEM_VFS_DEFS_H #define _SYSTEM_VFS_DEFS_H
#include <limits.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <SupportDefs.h> #include <SupportDefs.h>
@@ -20,4 +23,18 @@ struct fd_info {
ino_t node; 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 */ #endif /* _SYSTEM_VFS_DEFS_H */
+4 -8
View File
@@ -30,6 +30,7 @@
#include <util/AutoLock.h> #include <util/AutoLock.h>
#include <util/ring_buffer.h> #include <util/ring_buffer.h>
#include <vfs.h> #include <vfs.h>
#include <vfs_defs.h>
#include <vm/vm.h> #include <vm/vm.h>
@@ -42,11 +43,6 @@
#define PIPEFS_HASH_SIZE 16 #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 { namespace fifo {
@@ -252,7 +248,7 @@ RingBuffer::CreateBuffer()
if (fBuffer != NULL) if (fBuffer != NULL)
return B_OK; 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; 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, TRACE("Inode %p::WriteDataToBuffer(data = %p, bytes = %zu)\n", this, data,
dataSize); 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. // interleaved with other writer's data.
size_t minToWrite = 1; size_t minToWrite = 1;
if (dataSize <= PIPE_BUF) if (dataSize <= VFS_FIFO_ATOMIC_WRITE_SIZE)
minToWrite = dataSize; minToWrite = dataSize;
while (dataSize > 0) { while (dataSize > 0) {
+2 -1
View File
@@ -24,6 +24,7 @@
#include <thread_defs.h> #include <thread_defs.h>
#include <user_group.h> #include <user_group.h>
#include <user_timer_defs.h> #include <user_timer_defs.h>
#include <vfs_defs.h>
#include <errno_private.h> #include <errno_private.h>
#include <libroot_private.h> #include <libroot_private.h>
@@ -257,7 +258,7 @@ __pathconf_common(struct statvfs *fs, struct stat *st,
return PATH_MAX; return PATH_MAX;
case _PC_PIPE_BUF: case _PC_PIPE_BUF:
return 4096; return VFS_FIFO_ATOMIC_WRITE_SIZE;
case _PC_LINK_MAX: case _PC_LINK_MAX:
return LINK_MAX; return LINK_MAX;