- last_contig = False
- for i in range(self.max_mem_pg):
- element = PageStruct(self._pm_list[i].address)
- bucket += int(element.ref > 0)
- if last_contig:
- last_contig = element.ref > 0
- non_contig += int(not last_contig)
- else:
- last_contig = element.ref > 0
-
- if (i + 1) % page_per_granule == 0:
+ contig_state = LEAVE_CONTIG
+ new_state = LEAVE_CONTIG
+
+ i = 0
+ while i < self.max_mem_pg:
+ element = PageStruct(pplist[i].address)
+
+ nr_pgs = 1
+ if element.lead_page():
+ nr_pgs = 1 << element.order
+ if element.busy():
+ bucket += nr_pgs
+ new_state = ENTER_CONTIG
+ else:
+ new_state = LEAVE_CONTIG
+
+ i += nr_pgs
+
+ if contig_state != new_state:
+ non_contig += int(new_state == LEAVE_CONTIG)
+ contig_state = new_state
+
+ if i % page_per_granule == 0: