Search in sources :

Example 1 with DirectMemoryRegion

use of org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion in project ignite-3 by apache.

the class PageMemoryNoStoreImpl method addSegment.

/**
 * Attempts to add a new memory segment.
 *
 * @param oldRef Old segments array. If this method observes another segments array, it will allocate a new
 *      segment (if possible). If the array has already been updated, it will return the last element in the
 *      new array.
 * @return Added segment, if successfull, {@code null} if failed to add.
 */
private synchronized Segment addSegment(Segment[] oldRef) {
    if (segments == oldRef) {
        DirectMemoryRegion region = directMemoryProvider.nextRegion();
        // No more memory is available.
        if (region == null) {
            return null;
        }
        if (oldRef != null) {
            if (LOG.isInfoEnabled()) {
                LOG.info("Allocated next memory segment [plcName=" + dataRegionCfg.name() + ", chunkSize=" + IgniteUtils.readableSize(region.size(), true) + ']');
            }
        }
        Segment[] newRef = new Segment[oldRef == null ? 1 : oldRef.length + 1];
        if (oldRef != null) {
            System.arraycopy(oldRef, 0, newRef, 0, oldRef.length);
        }
        Segment lastSeg = oldRef == null ? null : oldRef[oldRef.length - 1];
        Segment allocated = new Segment(newRef.length - 1, region, lastSeg == null ? 0 : lastSeg.sumPages());
        allocated.init();
        newRef[newRef.length - 1] = allocated;
        segments = newRef;
    }
    // Only this synchronized method writes to segments, so it is safe to read twice.
    return segments[segments.length - 1];
}
Also used : DirectMemoryRegion(org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion)

Example 2 with DirectMemoryRegion

use of org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion in project ignite-3 by apache.

the class UnsafeMemoryProvider method nextRegion.

/**
 * {@inheritDoc}
 */
@Override
public DirectMemoryRegion nextRegion() {
    if (used == sizes.length) {
        return null;
    }
    if (used < regions.size()) {
        return regions.get(used++);
    }
    long chunkSize = sizes[regions.size()];
    long ptr;
    try {
        ptr = allocator.allocateMemory(chunkSize);
    } catch (IllegalArgumentException e) {
        String msg = "Failed to allocate next memory chunk: " + IgniteUtils.readableSize(chunkSize, true) + ". Check if chunkSize is too large and 32-bit JVM is used.";
        if (regions.isEmpty()) {
            throw new IgniteInternalException(msg, e);
        }
        LOG.error(msg);
        return null;
    }
    if (ptr <= 0) {
        LOG.error("Failed to allocate next memory chunk: " + IgniteUtils.readableSize(chunkSize, true));
        return null;
    }
    DirectMemoryRegion region = new UnsafeChunk(ptr, chunkSize);
    regions.add(region);
    used++;
    return region;
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) DirectMemoryRegion(org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion)

Example 3 with DirectMemoryRegion

use of org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion in project ignite-3 by apache.

the class UnsafeMemoryProvider method shutdown.

/**
 * {@inheritDoc}
 */
@Override
public void shutdown(boolean deallocate) {
    if (!deallocate) {
        used = 0;
        return;
    }
    if (regions != null) {
        for (Iterator<DirectMemoryRegion> it = regions.iterator(); it.hasNext(); ) {
            DirectMemoryRegion chunk = it.next();
            allocator.freeMemory(chunk.address());
            // Safety.
            it.remove();
        }
    }
}
Also used : DirectMemoryRegion(org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion)

Example 4 with DirectMemoryRegion

use of org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion in project ignite-3 by apache.

the class PageMemoryImpl method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteInternalException {
    synchronized (segmentsLock) {
        if (started) {
            return;
        }
        started = true;
        directMemoryProvider.initialize(sizes);
        List<DirectMemoryRegion> regions = new ArrayList<>(sizes.length);
        while (true) {
            DirectMemoryRegion reg = directMemoryProvider.nextRegion();
            if (reg == null) {
                break;
            }
            regions.add(reg);
        }
        int regs = regions.size();
        Segment[] segments = new Segment[regs - 1];
        DirectMemoryRegion cpReg = regions.get(regs - 1);
        long checkpointBuf = cpReg.size();
        long totalAllocated = 0;
        int pages = 0;
        long totalTblSize = 0;
        long totalReplSize = 0;
        for (int i = 0; i < regs - 1; i++) {
            assert i < segments.length;
            DirectMemoryRegion reg = regions.get(i);
            totalAllocated += reg.size();
            segments[i] = new Segment(i, regions.get(i));
            pages += segments[i].pages();
            totalTblSize += segments[i].tableSize();
            totalReplSize += segments[i].replacementSize();
        }
        this.segments = segments;
        if (LOG.isInfoEnabled()) {
            LOG.info("Started page memory [memoryAllocated=" + readableSize(totalAllocated, false) + ", pages=" + pages + ", tableSize=" + readableSize(totalTblSize, false) + ", replacementSize=" + readableSize(totalReplSize, false) + ", checkpointBuffer=" + readableSize(checkpointBuf, false) + ']');
        }
    }
}
Also used : ArrayList(java.util.ArrayList) DirectMemoryRegion(org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion)

Aggregations

DirectMemoryRegion (org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion)4 ArrayList (java.util.ArrayList)1 IgniteInternalException (org.apache.ignite.lang.IgniteInternalException)1