Exemplo n.º 1
0
        public void Initialize(long startAddress)
        {
            readBufferPool = new NativeSectorAlignedBufferPool(1, sectorSize);
            long tailPage      = startAddress >> LogPageSizeBits;
            int  tailPageIndex = (int)(tailPage % BufferSize);

            AllocatePage(tailPageIndex);

            SafeReadOnlyAddress = startAddress;
            ReadOnlyAddress     = startAddress;
            SafeHeadAddress     = startAddress;
            HeadAddress         = startAddress;
            FlushedUntilAddress = startAddress;
            BeginAddress        = startAddress;

            TailPageOffset.Page   = (int)(startAddress >> LogPageSizeBits);
            TailPageOffset.Offset = (int)(startAddress & PageSizeMask);

            TailPageIndex = -1;

            //Handle the case when startAddress + pageSize overflows
            //onto the next pageIndex in our buffer pages array
            if (0 != (startAddress & PageSizeMask))
            {
                // Update write cache to point to current level.
                TailPageIndex = tailPageIndex;
                Interlocked.MemoryBarrier();

                // Allocate for next page
                int newPageIndex = (tailPageIndex + 1) % BufferSize;
                AllocatePage(newPageIndex);
            }
        }
Exemplo n.º 2
0
        public PersistentMemoryMalloc(IDevice device, IDevice objectLogDevice, long startAddress)
        {
            if (BufferSize < 16)
            {
                throw new Exception("HLOG buffer must be at least 16 pages");
            }

            this.device = device;

            this.objectLogDevice = objectLogDevice;

            if (Key.HasObjectsToSerialize() || Value.HasObjectsToSerialize())
            {
                if (objectLogDevice == null)
                {
                    throw new Exception("Objects in key/value, but object log not provided during creation of FASTER instance");
                }
            }

            sectorSize           = (int)device.SectorSize;
            epoch                = LightEpoch.Instance;
            ioBufferPool         = new NativeSectorAlignedBufferPool(1, sectorSize);
            AlignedPageSizeBytes = ((PageSize + (sectorSize - 1)) & ~(sectorSize - 1));

            ptrHandle      = GCHandle.Alloc(pointers, GCHandleType.Pinned);
            nativePointers = (long *)ptrHandle.AddrOfPinnedObject();

            Initialize(startAddress);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create instance of PMM
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="startAddress"></param>
        /// <param name="pageHandlers"></param>
        internal PersistentMemoryMalloc(LogSettings settings, long startAddress, IPageHandlers pageHandlers)
        {
            // Segment size
            LogSegmentSizeBits = settings.SegmentSizeBits;
            SegmentSize        = 1 << LogSegmentSizeBits;
            SegmentSizeMask    = SegmentSize - 1;
            SegmentBufferSize  = 1 +
                                 (LogTotalSizeBytes / SegmentSize < 1 ? 1 : (int)(LogTotalSizeBytes / SegmentSize));

            // Total HLOG size
            LogTotalSizeBits  = settings.MemorySizeBits;
            LogTotalSizeBytes = 1L << LogTotalSizeBits;
            BufferSize        = (int)(LogTotalSizeBytes / (1L << LogPageSizeBits));

            // HeadOffset lag (from tail)
            HeadOffsetLagSize    = BufferSize - HeadOffsetLagNumPages;
            HeadOffsetLagAddress = (long)HeadOffsetLagSize << LogPageSizeBits;

            // ReadOnlyOffset lag (from tail)
            LogMutableFraction = settings.MutableFraction;
            ReadOnlyLagAddress = (long)(LogMutableFraction * BufferSize) << LogPageSizeBits;

            values              = new byte[BufferSize][];
            handles             = new GCHandle[BufferSize];
            pointers            = new long[BufferSize];
            PageStatusIndicator = new FullPageStatus[BufferSize];
            segmentOffsets      = new long[SegmentBufferSize];


            if (BufferSize < 16)
            {
                throw new Exception("HLOG buffer must be at least 16 pages");
            }

            device          = settings.LogDevice;
            objectLogDevice = settings.ObjectLogDevice;

            if (pageHandlers.HasObjects())
            {
                if (objectLogDevice == null)
                {
                    throw new Exception("Objects in key/value, but object log not provided during creation of FASTER instance");
                }
            }

            sectorSize           = (int)device.SectorSize;
            epoch                = LightEpoch.Instance;
            ioBufferPool         = NativeSectorAlignedBufferPool.GetPool(1, sectorSize);
            AlignedPageSizeBytes = ((PageSize + (sectorSize - 1)) & ~(sectorSize - 1));

            ptrHandle      = GCHandle.Alloc(pointers, GCHandleType.Pinned);
            nativePointers = (long *)ptrHandle.AddrOfPinnedObject();

            Initialize(startAddress);
        }
Exemplo n.º 4
0
        public PersistentMemoryMalloc(IDevice device, long startAddress)
        {
            // Console.WriteLine("Total memory (GB) = " + totalSize/1000000000);
            // Console.WriteLine("BufferSize = " + BufferSize);
            // Console.WriteLine("ReadOnlyLag = " + (ReadOnlyLagAddress >> PageSizeBits));

            if (BufferSize < 16)
            {
                throw new Exception("HLOG buffer must be at least 16 pages");
            }

            this.device = device;

            objlogDevice = CreateObjectLogDevice(device);

            sectorSize   = (int)device.GetSectorSize();
            epoch        = LightEpoch.Instance;
            ioBufferPool = new NativeSectorAlignedBufferPool(1, sectorSize);

            if (ForceUnpinnedAllocation)
            {
                IsPinned = false;
            }
            else
            {
                IsPinned = true;
                try
                {
                    var tmp = new T[1];
                    var h   = GCHandle.Alloc(tmp, GCHandleType.Pinned);
                    var p   = h.AddrOfPinnedObject();
                    //PrivateRecordSize = Marshal.SizeOf(tmp[0]);
                    AlignedPageSizeBytes = (((PrivateRecordSize * PageSize) + (sectorSize - 1)) & ~(sectorSize - 1));
                }
                catch (Exception)
                {
                    IsPinned = false;
                }
            }

            ptrHandle      = GCHandle.Alloc(pointers, GCHandleType.Pinned);
            nativePointers = (long *)ptrHandle.AddrOfPinnedObject();

            Initialize(startAddress);
        }
Exemplo n.º 5
0
        public ManagedLocalStorageDevice(
            string filename, long segmentSize = -1,
            bool preallocateSegment           = false, bool singleSegment = true, bool deleteOnClose = false)
            : base(filename, segmentSize, GetSectorSize(filename))
        {
            pool = new NativeSectorAlignedBufferPool(1, 1);

            this.preallocateSegment = preallocateSegment;
            this.deleteOnClose      = deleteOnClose;

            if (singleSegment)
            {
                singleLogHandle = CreateHandle(0);
            }
            else
            {
                logHandles = new ConcurrentDictionary <int, Stream>();
            }
        }
Exemplo n.º 6
0
        public PersistentMemoryMalloc(IDevice device, long startAddress)
        {
            if (BufferSize < 16)
            {
                throw new Exception("HLOG buffer must be at least 16 pages");
            }

            this.device = device;

            objlogDevice = CreateObjectLogDevice(device);

            sectorSize           = (int)device.GetSectorSize();
            epoch                = LightEpoch.Instance;
            ioBufferPool         = new NativeSectorAlignedBufferPool(1, sectorSize);
            AlignedPageSizeBytes = ((PageSize + (sectorSize - 1)) & ~(sectorSize - 1));

            ptrHandle      = GCHandle.Alloc(pointers, GCHandleType.Pinned);
            nativePointers = (long *)ptrHandle.AddrOfPinnedObject();

            Initialize(startAddress);
        }