8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 18:43:02 +01:00
firebird-mirror/doc/README.DiskSpaceAllocation

60 lines
3.2 KiB
Plaintext
Raw Normal View History

2007-12-27 21:39:13 +01:00
2007-12-28 01:14:00 +01:00
Since the beginning, Firebird have no rules of how to allocate disk space
2007-12-27 21:39:13 +01:00
for database file(s). It just writes new allocated pages in not determined
order (because of dependencies between pages to serve "careful write" strategy).
This approach is very simple but have some drawbacks :
2007-12-28 01:14:00 +01:00
- because of not determined order of writes, there may be such situation when
2007-12-27 21:39:13 +01:00
page cache contain many dirty pages at time when new allocated page must be
written but can't because of out of disk space. In such cases often all other
dirty pages are lost because of administrators prefer to shutdown database
before making some space on disk available. This leads to serious corruptions.
- allocating disk space by relatively small chunks may lead to significant file
fragmentation at file system level and reduce performance of large scans (for
example during backup).
2007-12-28 01:14:00 +01:00
Using new ODS 11.1, Firebird changes its disk space allocation algorithm to
2007-12-27 21:39:13 +01:00
avoid corruptions in out of disk space conditions and to get file system a
2007-12-28 01:14:00 +01:00
chance to avoid fragmentation. These changes are described below.
2007-12-27 21:39:13 +01:00
a) Every newly allocated page writes on disk immediately before returning to
2007-12-28 01:14:00 +01:00
the engine. If page can't be written then allocation not happens, PIP bit
2007-12-27 21:39:13 +01:00
is not cleared and appropriate IO error is raised. This error can't lead to
corruptions as we have a guarantee that all dirty pages in cache have disk
space allocated and can be written safely.
This change make one additional write of every newly allocated page comparing
with old behavior. So performance penalty is expected during the database file
growth. To reduce this penalty Firebird groups writes of newly allocated pages
up to 128KB at time and tracks number of "initialized" pages at PIP header.
Note : newly allocated page will be written to disk twice only if this page
allocated first time. I.e. if page was allocated, freed and allocated again
it will not be written twice on second allocation.
2007-12-28 01:14:00 +01:00
b) To avoid file fragmentation, Firebird used appropriate file system's API to
2007-12-27 21:39:13 +01:00
preallocate disk space by relatively large chunks. Currently such API have
only Windows but it was recently added into Linux API and may be implemented
in such popular file system's as ext2, etc in the future. So this feature
currently implemented only in Windows builds of Firebird and may be implemented
in Linux builds in the future.
2007-12-28 01:14:00 +01:00
For better control of disk space preallocation, new setting in Firebird.conf
2007-12-27 21:39:13 +01:00
was introduced : DatabaseGrowthIncrement. This is upper bound of preallocation
chunk size in bytes. Default value is 128MB. When engine needs more disk space
it allocates 1/16th of already allocated space but no less than 128KB and no more
2007-12-28 01:14:00 +01:00
than DatabaseGrowthIncrement value. If DatabaseGrowthIncrement is set to zero then
2007-12-27 21:39:13 +01:00
preallocation is disabled. Space for database shadow files are not preallocated.
Also preallocation is disabled if "No reserve" option is set for database.
Note : preallocation also allows to avoid corruptions in out of disk space
condition - in such case there is a big chance that database have enough space
preallocated to operate until administrator make some disk space available.
Author: Vlad Khorsun, <hvlad at users sourceforge net>