jaypipes / ghw

Go HardWare discovery/inspection library
Apache License 2.0
1.62k stars 174 forks source link

ARM: failed to determine memory area for node: open /sys/devices/system/memory/block_size_bytes: no such file or directory #336

Closed wanyaoqi closed 10 months ago

wanyaoqi commented 1 year ago

topology.New() will report: WARNING: failed to determine memory area for node: open /sys/devices/system/memory/block_size_bytes: no such file or directory

ARM no /sys/devices/system/memory directory. As the this comment: https://github.com/kata-containers/runtime/issues/796#issuecomment-425393743 ARM not support memory hotplug,and i can't get physical memory from sysfs.

Is there any way around this problem

jaypipes commented 1 year ago

Hi @wanyaoqi thanks for submitting this issue. You can turn off these warnings. For ARM, topology memory information may not be available due to platform limitations.

wanyaoqi commented 1 year ago

Hi @jaypipes , thanks for your reply. The problem is get numa node physical memory size, others topo info is works. And i don't need numa node physical memory size actually, so i just paste usable size to physical size to workaround this problem. https://github.com/wanyaoqi/ghw/pull/1 Can we check /sys/devices/system/memory/block_size_bytes file exists, if not exist return a inaccuracy value( usable size) or return -1 rather than return a error, because other numa topo infomation is work.

jaypipes commented 1 year ago

Hi @jaypipes , thanks for your reply. The problem is get numa node physical memory size, others topo info is works. And i don't need numa node physical memory size actually, so i just paste usable size to physical size to workaround this problem. wanyaoqi#1 Can we check /sys/devices/system/memory/block_size_bytes file exists, if not exist return a inaccuracy value( usable size) or return -1 rather than return a error, because other numa topo infomation is work.

@wanyaoqi we already do that :)

https://github.com/jaypipes/ghw/blob/227643e14380812d61b941f7aa52d1156b6d900a/pkg/memory/memory_linux.go#L113-L119

wanyaoqi commented 1 year ago

Hi @jaypipes , thanks for your reply. The problem is get numa node physical memory size, others topo info is works. And i don't need numa node physical memory size actually, so i just paste usable size to physical size to workaround this problem. wanyaoqi#1 Can we check /sys/devices/system/memory/block_size_bytes file exists, if not exist return a inaccuracy value( usable size) or return -1 rather than return a error, because other numa topo infomation is work.

@wanyaoqi we already do that :)

https://github.com/jaypipes/ghw/blob/227643e14380812d61b941f7aa52d1156b6d900a/pkg/memory/memory_linux.go#L113-L119

@jaypipes Okay, but function AreaForNode seems like not fixed ? https://github.com/jaypipes/ghw/blob/227643e14380812d61b941f7aa52d1156b6d900a/pkg/memory/memory_linux.go#L60-L71

wanyaoqi commented 1 year ago

AreaForNode should call memTotalPhysicalBytes like this:

func AreaForNode(ctx *context.Context, nodeID int) (*Area, error) {
    paths := linuxpath.New(ctx)
    path := filepath.Join(
        paths.SysDevicesSystemNode,
        fmt.Sprintf("node%d", nodeID),
    )

    totPhys := memTotalPhysicalBytes(paths)
    totUsable, err := memoryTotalUsableBytesFromPath(filepath.Join(path, "meminfo"))
    if err != nil {
        return nil, err
    }

    supportedHP, err := memorySupportedPageSizes(filepath.Join(path, "hugepages"))
    if err != nil {
        return nil, err
    }

    return &Area{
        TotalPhysicalBytes: totPhys,
        TotalUsableBytes:   totUsable,
        SupportedPageSizes: supportedHP,
    }, nil
}
jaypipes commented 1 year ago

@wanyaoqi gotcha. I will push a fix shortly. :) thank you!

mogren commented 10 months ago

I guess this issue can be closed? 😄