Exemplo n.º 1
0
        protected internal override PagerState AllocateMorePages(long newLength)
        {
            if (DisposeOnceRunner.Disposed)
            {
                ThrowAlreadyDisposedException();
            }

            var newLengthAfterAdjustment = NearestSizeToAllocationGranularity(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize)
            {
                return(null);
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            Win32NativeFileMethods.SetFileLength(_handle, _totalAllocationSize + allocationSize);

            PagerState newPagerState = CreatePagerState();

            newPagerState.CopyPrefetchState(this._pagerState);

            SetPagerState(newPagerState);

            PagerState.DebugVerify(newLengthAfterAdjustment);

            _totalAllocationSize  += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / Constants.Storage.PageSize;

            return(newPagerState);
        }
        protected override PagerState AllocateMorePages(long newLength)
        {
            if (Disposed)
            {
                ThrowAlreadyDisposedException();
            }

            var newLengthAfterAdjustment = NearestSizeToAllocationGranularity(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize)
            {
                return(null);
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            Win32NativeFileMethods.SetFileLength(_handle, _totalAllocationSize + allocationSize);
            PagerState newPagerState = null;

            if (TryAllocateMoreContinuousPages(allocationSize) == false)
            {
                newPagerState = CreatePagerState();

                var tmp = PagerState;
                PagerState = newPagerState;
                tmp.Release(); //replacing the pager state --> so one less reference for it
                PagerState.DebugVerify(newLengthAfterAdjustment);
            }

            _totalAllocationSize  += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / _pageSize;

            return(newPagerState);
        }
Exemplo n.º 3
0
        public override void AllocateMorePages(Transaction tx, long newLength)
        {
            ThrowObjectDisposedIfNeeded();

            var newLengthAfterAdjustment = NearestSizeToAllocationGranularity(newLength);

            if (newLengthAfterAdjustment < _totalAllocationSize)
            {
                throw new ArgumentException("Cannot set the legnth to less than the current length");
            }

            if (newLengthAfterAdjustment == _totalAllocationSize)
            {
                return;
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            if (_totalAllocationSize + allocationSize >= long.MaxValue)             //probably would never be true, but just in case
            {
                throw new OutOfMemoryException("failed to allocated more pages - reached maximum allowed space usage");
            }

            _fileStream.SetLength(_totalAllocationSize + allocationSize);
            if (TryAllocateMoreContinuousPages(allocationSize) == false)
            {
                PagerState newPagerState = CreatePagerState();
                if (newPagerState == null)
                {
                    var errorMessage = string.Format(
                        "Unable to allocate more pages - unsucsessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
                        (_totalAllocationSize + allocationSize));

                    throw new OutOfMemoryException(errorMessage);
                }

                newPagerState.DebugVerify(newLengthAfterAdjustment);

                if (tx != null)
                {
                    newPagerState.AddRef();
                    tx.AddPagerState(newPagerState);
                }

                var tmp = PagerState;
                PagerState = newPagerState;
                tmp.Release();                 //replacing the pager state --> so one less reference for it
            }

            _totalAllocationSize  += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
        }
Exemplo n.º 4
0
        public override void AllocateMorePages(Transaction tx, long newLength)
        {
            ThrowObjectDisposedIfNeeded();
            var newLengthAfterAdjustment = NearestSizeToPageSize(newLength);

            if (newLengthAfterAdjustment < _totalAllocationSize)
            {
                throw new ArgumentException("Cannot set the length to less than the current length");
            }

            if (newLengthAfterAdjustment == _totalAllocationSize)
            {
                return;
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            Syscall.ftruncate(_fd, (_totalAllocationSize + allocationSize));

            if (TryAllocateMoreContinuousPages(allocationSize) == false)
            {
                PagerState newPagerState = CreatePagerState();
                if (newPagerState == null)
                {
                    var errorMessage = string.Format(
                        "Unable to allocate more pages - unsuccessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
                        (_totalAllocationSize + allocationSize));

                    throw new OutOfMemoryException(errorMessage);
                }

                newPagerState.DebugVerify(newLengthAfterAdjustment);

                if (tx != null)
                {
                    newPagerState.AddRef();
                    tx.AddPagerState(newPagerState);
                }

                var tmp = PagerState;
                PagerState = newPagerState;
                tmp.Release();                 //replacing the pager state --> so one less reference for it
            }

            _totalAllocationSize  += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
        }
Exemplo n.º 5
0
        protected override PagerState AllocateMorePages(long newLength)
        {
            if (Disposed)
            {
                ThrowAlreadyDisposedException();
            }
            var newLengthAfterAdjustment = NearestSizeToPageSize(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize)
            {
                return(null);
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            PosixHelper.AllocateFileSpace(_fd, (ulong)(_totalAllocationSize + allocationSize));

            if (_isSyncDirAllowed && PosixHelper.SyncDirectory(_file) == -1)
            {
                var err = Marshal.GetLastWin32Error();
                PosixHelper.ThrowLastError(err);
            }

            PagerState newPagerState = CreatePagerState();

            if (newPagerState == null)
            {
                var errorMessage = string.Format(
                    "Unable to allocate more pages - unsuccessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
                    (_totalAllocationSize + allocationSize));

                throw new OutOfMemoryException(errorMessage);
            }

            newPagerState.DebugVerify(newLengthAfterAdjustment);

            var tmp = PagerState;

            PagerState = newPagerState;
            tmp.Release(); //replacing the pager state --> so one less reference for it

            _totalAllocationSize  += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / _pageSize;

            return(newPagerState);
        }
Exemplo n.º 6
0
        protected internal override PagerState AllocateMorePages(long newLength)
        {
            if (DisposeOnceRunner.Disposed)
            {
                ThrowAlreadyDisposedException();
            }
            var newLengthAfterAdjustment = NearestSizeToPageSize(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize)
            {
                return(null);
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            PosixHelper.AllocateFileSpace(_options, _fd, _totalAllocationSize + allocationSize, FileName.FullPath);

            if (DeleteOnClose == false && _isSyncDirAllowed && Syscall.SyncDirectory(FileName.FullPath) == -1)
            {
                var err = Marshal.GetLastWin32Error();
                Syscall.ThrowLastError(err);
            }

            PagerState newPagerState = CreatePagerState();

            if (newPagerState == null)
            {
                var errorMessage = string.Format(
                    "Unable to allocate more pages - unsuccessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
                    (_totalAllocationSize + allocationSize));

                throw new OutOfMemoryException(errorMessage);
            }

            newPagerState.DebugVerify(newLengthAfterAdjustment);

            newPagerState.CopyPrefetchState(this._pagerState);
            SetPagerState(newPagerState);

            _totalAllocationSize  += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / Constants.Storage.PageSize;

            return(newPagerState);
        }
Exemplo n.º 7
0
        protected override PagerState AllocateMorePages(long newLength)
        {
            if (Disposed)
            {
                ThrowAlreadyDisposedException();
            }

            var newLengthAfterAdjustment = NearestSizeToAllocationGranularity(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize)
            {
                return(null);
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            Win32NativeFileMethods.SetFileLength(_handle, _totalAllocationSize + allocationSize);
            PagerState newPagerState = null;

#if VALIDATE
            // If we're on validate more, we don't want to allocate continuous pages because this
            // introduces weird conditions on the protection and unprotection routines (we have to
            // track boundaries, which is more complex than we're willing to do)
            newPagerState = CreatePagerState();

            SetPagerState(newPagerState);

            PagerState.DebugVerify(newLengthAfterAdjustment);
#else
            if (TryAllocateMoreContinuousPages(allocationSize) == false)
            {
                newPagerState = CreatePagerState();

                SetPagerState(newPagerState);

                PagerState.DebugVerify(newLengthAfterAdjustment);
            }
#endif

            _totalAllocationSize  += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / PageSize;

            return(newPagerState);
        }
Exemplo n.º 8
0
        public override void AllocateMorePages(Transaction tx, long newLength)
        {
            ThrowObjectDisposedIfNeeded();

            var newLengthAfterAdjustment = NearestSizeToAllocationGranularity(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize)
            {
                return;
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            Win32NativeFileMethods.SetFileLength(_handle, _totalAllocationSize + allocationSize);
            if (TryAllocateMoreContinuousPages(allocationSize) == false)
            {
                PagerState newPagerState = CreatePagerState();
                if (newPagerState == null)
                {
                    var errorMessage = string.Format(
                        "Unable to allocate more pages - unsuccessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
                        (_totalAllocationSize + allocationSize));

                    throw new OutOfMemoryException(errorMessage);
                }

                newPagerState.DebugVerify(newLengthAfterAdjustment);

                if (tx != null)
                {
                    newPagerState.AddRef();
                    tx.AddPagerState(newPagerState);
                }

                var tmp = PagerState;
                PagerState = newPagerState;
                tmp.Release();                 //replacing the pager state --> so one less reference for it
            }

            _totalAllocationSize  += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
        }
Exemplo n.º 9
0
        public override void AllocateMorePages(Transaction tx, long newLength)
        {
            ThrowObjectDisposedIfNeeded();

            var newLengthAfterAdjustment = NearestSizeToPageSize(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize)             //nothing to do
            {
                return;
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            PosixHelper.AllocateFileSpace(_fd, (ulong)(_totalAllocationSize + allocationSize));
            _totalAllocationSize += allocationSize;

            PagerState newPagerState = CreatePagerState();

            if (newPagerState == null)
            {
                var errorMessage = string.Format(
                    "Unable to allocate more pages - unsuccessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
                    (_totalAllocationSize + allocationSize));

                throw new OutOfMemoryException(errorMessage);
            }

            newPagerState.DebugVerify(newLengthAfterAdjustment);

            if (tx != null)
            {
                newPagerState.AddRef();
                tx.AddPagerState(newPagerState);
            }

            var tmp = PagerState;

            PagerState = newPagerState;
            tmp.Release();             //replacing the pager state --> so one less reference for it

            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
        }
Exemplo n.º 10
0
        protected internal override PagerState AllocateMorePages(long newLength)
        {
            if (DisposeOnceRunner.Disposed)
            {
                ThrowAlreadyDisposedException();
            }

            var newLengthAfterAdjustment = NearestSizeToPageSize(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize)
            {
                return(null);
            }

            var rc = rvn_allocate_more_space(newLengthAfterAdjustment, _handle, out var newAddress, out var errorCode);

            if (rc != FailCodes.Success)
            {
                PalHelper.ThrowLastError(rc, errorCode, $"can't allocate more pages (rc={rc}) for '{FileName.FullPath}'. Requested {newLength} (adjusted to {newLengthAfterAdjustment})");
            }

            // TODO : Get rid of allocation info
            var allocationInfo = new PagerState.AllocationInfo
            {
                BaseAddress = (byte *)newAddress,
                Size        = newLengthAfterAdjustment,
                MappedFile  = null
            };

            var newPagerState = new PagerState(this, Options.PrefetchSegmentSize, Options.PrefetchResetThreshold, allocationInfo);

            newPagerState.DebugVerify(newLengthAfterAdjustment);

            newPagerState.CopyPrefetchState(_pagerState);
            SetPagerState(newPagerState);

            _totalAllocationSize   = newLengthAfterAdjustment;
            NumberOfAllocatedPages = _totalAllocationSize / Constants.Storage.PageSize;

            return(newPagerState);
        }
Exemplo n.º 11
0
        protected internal override PagerState AllocateMorePages(long newLength)
        {
            if (DisposeOnceRunner.Disposed)
            {
                ThrowAlreadyDisposedException();
            }

            var newLengthAfterAdjustment = NearestSizeToPageSize(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize) //nothing to do
            {
                return(null);
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            PosixHelper.AllocateFileSpace(_options, _fd, _totalAllocationSize + allocationSize, FileName.FullPath);

            _totalAllocationSize += allocationSize;

            PagerState newPagerState = CreatePagerState();

            if (newPagerState == null)
            {
                var errorMessage = string.Format(
                    "Unable to allocate more pages - unsuccessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
                    (_totalAllocationSize + allocationSize));

                throw new OutOfMemoryException(errorMessage);
            }

            newPagerState.DebugVerify(newLengthAfterAdjustment);

            SetPagerState(newPagerState);

            NumberOfAllocatedPages = _totalAllocationSize / Constants.Storage.PageSize;

            return(newPagerState);
        }
Exemplo n.º 12
0
        public override void AllocateMorePages(Transaction tx, long newLength)
        {
            ThrowObjectDisposedIfNeeded();

            var newLengthAfterAdjustment = NearestSizeToAllocationGranularity(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize)
            {
                return;
            }

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            Win32NativeFileMethods.SetFileLength(_handle, _totalAllocationSize + allocationSize);
            if (TryAllocateMoreContinuousPages(allocationSize) == false)
            {
                RefreshMappedView(tx);
                PagerState.DebugVerify(newLengthAfterAdjustment);
            }

            _totalAllocationSize  += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
        }