Skip to content

Commit

Permalink
Revert "Enable page size autoconfiguration. (#566)"
Browse files Browse the repository at this point in the history
This reverts commit 6549acc.
  • Loading branch information
peter-lawrey authored and yevgenp committed Oct 31, 2023
1 parent 6549acc commit a02a79e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/openhft/chronicle/bytes/MappedBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static MappedBytes mappedBytes(@NotNull final File file,
@NonNegative final long overlapSize,
final boolean readOnly)
throws FileNotFoundException, ClosedIllegalStateException {
return mappedBytes(file, chunkSize, overlapSize, PageUtil.getPageSize(file.getAbsolutePath()), readOnly);
return mappedBytes(file, chunkSize, overlapSize, OS.defaultOsPageSize(), readOnly);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class MappedBytesStore extends NativeBytesStore<Void> {
@Deprecated(/* to be removed in x.26 */)
protected MappedBytesStore(ReferenceOwner owner, MappedFile mappedFile, @NonNegative long start, long address, @NonNegative long capacity, @NonNegative long safeCapacity)
throws ClosedIllegalStateException {
this(owner, mappedFile, start, address, capacity, safeCapacity, PageUtil.getPageSize(mappedFile.file().getAbsolutePath()));
this(owner, mappedFile, start, address, capacity, safeCapacity, (int) OS.pageSize());
}
/**
* Creates a new MappedBytesStore with the given parameters.
Expand Down Expand Up @@ -114,7 +114,7 @@ protected MappedBytesStore(ReferenceOwner owner, MappedFile mappedFile, @NonNega
@Deprecated(/* to be removed in x.26 */)
public static MappedBytesStore create(ReferenceOwner owner, MappedFile mappedFile, @NonNegative long start, long address, @NonNegative long capacity, @NonNegative long safeCapacity)
throws ClosedIllegalStateException {
return new MappedBytesStore(owner, mappedFile, start, address, capacity, safeCapacity, PageUtil.getPageSize(mappedFile.file().getAbsolutePath()));
return new MappedBytesStore(owner, mappedFile, start, address, capacity, safeCapacity, OS.defaultOsPageSize());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package net.openhft.chronicle.bytes;

import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.annotation.NonNegative;
import net.openhft.chronicle.core.annotation.Positive;
import net.openhft.chronicle.core.io.ClosedIllegalStateException;
Expand Down Expand Up @@ -47,7 +48,7 @@ public interface MappedBytesStoreFactory {
@NotNull
default MappedBytesStore create(ReferenceOwner owner, MappedFile mappedFile, @NonNegative long start, @NonNegative long address, @NonNegative long capacity, @NonNegative long safeCapacity)
throws ClosedIllegalStateException {
return create(owner, mappedFile, start, address, capacity, safeCapacity, PageUtil.getPageSize(mappedFile.file().getAbsolutePath()));
return create(owner, mappedFile, start, address, capacity, safeCapacity, OS.pageSize());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/openhft/chronicle/bytes/MappedFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static MappedFile of(@NotNull final File file,
@NonNegative final long overlapSize,
final boolean readOnly)
throws FileNotFoundException {
return of(file, chunkSize, overlapSize, PageUtil.getPageSize(file.getAbsolutePath()), readOnly);
return of(file, chunkSize, overlapSize, OS.defaultOsPageSize(), readOnly);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public enum MappedUniqueTimeProvider implements TimeProvider, ReferenceOwner {
String user = Jvm.getProperty("user.name", "unknown");
String timeStampDir = Jvm.getProperty("timestamp.dir", OS.TMP);
final File timeStampPath = new File(timeStampDir, ".time-stamp." + user + ".dat");
MappedFile file = MappedFile.ofSingle(timeStampPath, PageUtil.getPageSize(timeStampPath.getAbsolutePath()), false);
MappedFile file = MappedFile.ofSingle(timeStampPath, OS.pageSize(), false);
final Bytes<?> bytes = file.acquireBytesForWrite(this, 0);
bytes.append8bit("&TSF\nTime stamp file used for sharing a unique id\n");
this.bytesStore = bytes.bytesStore();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/openhft/chronicle/bytes/PageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public final class PageUtil {

public static final int DEFAULT_HUGE_PAGE_SIZE = 2 << 20;
public static final int DEFAULT_HUGE_PAGE_SIZE = 2 * 1024 * 1024;

private static final Pattern PAGE_SIZE_PATTERN = Pattern.compile("pagesize=([0-9])+([KkMmGg])");
private static final TrieNode root = new TrieNode();
Expand Down Expand Up @@ -80,13 +80,13 @@ static int parsePageSize(String mount) {
}

private static int mult(String s) {
int k = 1 << 10;
int k = 1024;
if (s.equalsIgnoreCase("K"))
return k;
if (s.equalsIgnoreCase("G"))
return k << 20;
return k * 1024 * 1024;

return k << 10;
return k * 1024;
}

static String parseMountPoint(String line) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ChunkedMappedFile(@NotNull final File file,
@NonNegative final long capacity,
final boolean readOnly)
throws IORuntimeException {
this(file, raf, chunkSize, overlapSize, PageUtil.getPageSize(file.getAbsolutePath()), capacity, readOnly);
this(file, raf, chunkSize, overlapSize, OS.defaultOsPageSize(), capacity, readOnly);
}

public ChunkedMappedFile(@NotNull final File file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public SingleMappedFile(@NotNull final File file,

this.raf = raf;
this.fileChannel = raf.getChannel();
this.capacity = OS.mapAlign(capacity, PageUtil.getPageSize(file.getAbsolutePath()));
this.capacity = capacity;

final MapMode mode = readOnly() ? MapMode.READ_ONLY : MapMode.READ_WRITE;

Expand All @@ -95,9 +95,9 @@ public SingleMappedFile(@NotNull final File file,
try {
Jvm.doNotCloseOnInterrupt(getClass(), this.fileChannel);

resizeRafIfTooSmall(this.capacity);
final long address = OS.map(fileChannel, mode, 0, this.capacity, pageSize);
final MappedBytesStore mbs2 = MappedBytesStore.create(this, this, 0, address, this.capacity, this.capacity, pageSize);
resizeRafIfTooSmall(capacity);
final long address = OS.map(fileChannel, mode, 0, capacity, pageSize);
final MappedBytesStore mbs2 = MappedBytesStore.create(this, this, 0, address, capacity, capacity, pageSize);
mbs2.syncMode(DEFAULT_SYNC_MODE);

final long elapsedNs = System.nanoTime() - beginNs;
Expand All @@ -124,7 +124,7 @@ public SingleMappedFile(@NotNull final File file,
@NonNegative final long capacity,
final boolean readOnly)
throws IORuntimeException {
this(file, raf, capacity, PageUtil.getPageSize(file.getAbsolutePath()),readOnly);
this(file, raf, capacity, OS.defaultOsPageSize(),readOnly);
}
/**
* Sets the synchronization mode for the underlying MappedBytesStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ public void disableThreadSafety() throws InterruptedException {
@Test
public void testEnsureCapacity() throws FileNotFoundException {
File file = IOTools.createTempFile("ensure");
final int chunkSize = 64 * PageUtil.getPageSize(file.getAbsolutePath());
final int chunkSize = 256 << 10;
try (MappedBytes mb = MappedBytes.mappedBytes(file, chunkSize, chunkSize / 4)) {
final int chunks3 = chunkSize * 3;
mb.writePosition(chunks3).writeByte((byte) 0);
Expand Down

0 comments on commit a02a79e

Please sign in to comment.