Skip to content

Commit b5a2157

Browse files
author
gitlab
committed
Merge branch 'feature-5.1.0-memory-reclamation@@3' into '5.1.0'
<fix>[prometheus]: keep ksm metric use /sys/kernel/mm/ksm/pages_shared See merge request zstackio/zstack-utility!4648
2 parents 5aa5f0a + 372c75f commit b5a2157

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

baremetalpxeserver/baremetalpxeserver/pxeserveragent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,12 @@ def init(self, req):
315315
f.write(grub_cfg)
316316

317317
# remove symlink if exists
318-
if os.path.exists(self.UEFI_BOOT_GRUB_CFG):
318+
if os.path.exists(self.UEFI_BOOT_GRUB_CFG) and os.path.islink(self.UEFI_BOOT_GRUB_CFG):
319319
os.remove(self.UEFI_BOOT_GRUB_CFG)
320320

321321
# create link for grub.cfg (for get baremetal hardinfo)
322322
rel_path = os.path.relpath(self.UEFI_DEFAULT_GRUB_CFG, os.path.dirname(self.UEFI_BOOT_GRUB_CFG))
323+
323324
os.symlink(rel_path, self.UEFI_BOOT_GRUB_CFG)
324325

325326
# init inspector_ks.cfg
@@ -532,7 +533,7 @@ def _create_pxelinux_cfg(self, cmd):
532533
grub_link_cfg_file = os.path.join(self.TFTPBOOT_PATH, "grub.cfg-01-" + ks_cfg_name)
533534

534535
# remove symlink if exists
535-
if os.path.exists(grub_link_cfg_file):
536+
if os.path.exists(grub_link_cfg_file) and os.path.islink(grub_link_cfg_file):
536537
os.remove(grub_link_cfg_file)
537538

538539
rel_path = os.path.relpath(grub_cfg_file, os.path.dirname(grub_link_cfg_file))

kvmagent/kvmagent/plugins/prometheus.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ def collect_memory_overcommit_statistics():
11631163
metrics = {
11641164
'host_ksm_pages_shared_in_bytes': GaugeMetricFamily('host_ksm_pages_shared_in_bytes',
11651165
'host ksm shared pages', None, []),
1166-
'host_ksm_pages_shareing_in_bytes': GaugeMetricFamily('host_ksm_pages_shareing_in_bytes',
1166+
'host_ksm_pages_sharing_in_bytes': GaugeMetricFamily('host_ksm_pages_sharing_in_bytes',
11671167
'host ksm sharing pages', None, []),
11681168
'host_ksm_pages_unshared_in_bytes': GaugeMetricFamily('host_ksm_pages_unshared_in_bytes',
11691169
'host ksm unshared pages', None, []),
@@ -1181,18 +1181,11 @@ def collect_memory_overcommit_statistics():
11811181
# read metric from /sys/kernel/mm/ksm
11821182
value = linux.read_file("/sys/kernel/mm/ksm/pages_shared")
11831183
if value:
1184-
shared_pages = value
1185-
sharing_pages = linux.read_file("/sys/kernel/mm/ksm/pages_sharing")
1186-
pages_num = float(sharing_pages.strip()) - float(shared_pages.strip())
1187-
1188-
if (pages_num < 0):
1189-
pages_num = 0
1190-
1191-
metrics['host_ksm_pages_shared_in_bytes'].add_metric([], pages_num * PAGE_SIZE)
1184+
metrics['host_ksm_pages_shared_in_bytes'].add_metric([], float(value.strip()) * PAGE_SIZE)
11921185

11931186
value = linux.read_file("/sys/kernel/mm/ksm/pages_sharing")
11941187
if value:
1195-
metrics['host_ksm_pages_shareing_in_bytes'].add_metric([], float(value.strip()) * PAGE_SIZE)
1188+
metrics['host_ksm_pages_sharing_in_bytes'].add_metric([], float(value.strip()) * PAGE_SIZE)
11961189

11971190
value = linux.read_file("/sys/kernel/mm/ksm/pages_unshared")
11981191
if value:

kvmagent/kvmagent/plugins/vm_plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4694,8 +4694,11 @@ def make_memory_backing():
46944694
backing = e(root, 'memoryBacking')
46954695
if cmd.useHugePage:
46964696
e(backing, "hugepages")
4697-
e(backing, "nosharepages")
46984697
e(backing, "allocation", attrib={'mode': 'immediate'})
4698+
4699+
if cmd.noSharePages or cmd.useHugePage:
4700+
e(backing, "nosharepages")
4701+
46994702
if cmd.MemAccess in "shared":
47004703
# <access mode="shared|private"/>
47014704
e(backing, "access", attrib={'mode': 'shared'})

0 commit comments

Comments
 (0)