I encountered a problem while learning about the netty memory pool. In the newSizeClass method of the SizeClasses class, log2Group、log2Delta、nDelta、pageShifts, And how to calculate isSubpage and log2DeltaLookup, I’m a bit confused about this code. Can someone help me explain it? Thank you very much.🥺
private static short[] newSizeClass(int index, int log2Group, int log2Delta, int nDelta, int pageShifts) {
short isMultiPageSize;
if (log2Delta >= pageShifts) {
isMultiPageSize = yes;
} else {
int pageSize = 1 << pageShifts;
int size = calculateSize(log2Group, nDelta, log2Delta);
isMultiPageSize = size == size / pageSize * pageSize? yes : no;
}
int log2Ndelta = nDelta == 0? 0 : log2(nDelta);
byte remove = 1 << log2Ndelta < nDelta? yes : no;
int log2Size = log2Delta + log2Ndelta == log2Group? log2Group + 1 : log2Group;
if (log2Size == log2Group) {
remove = yes;
}
short isSubpage = log2Size < pageShifts + LOG2_SIZE_CLASS_GROUP? yes : no;
int log2DeltaLookup = log2Size < LOG2_MAX_LOOKUP_SIZE ||
log2Size == LOG2_MAX_LOOKUP_SIZE && remove == no
? log2Delta : no;
return new short[] {
(short) index, (short) log2Group, (short) log2Delta,
(short) nDelta, isMultiPageSize, isSubpage, (short) log2DeltaLookup
};
}
I have read the code many times, but I still haven’t understood it. I hope you can help me explain the meanings of these variables and how they are used.
wandou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.