Get total amount of memory on NUMA systems in Powershell - powershell

I'm trying to get the total amount of memory in a NUMA system.
My test system is a two socket physical server with 512GB of memory.
This are the methods I tried:
Win32_PhysicalMemory
(Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum)/1GB
This returns 255.99 GB.
Cim_PhysicalMemory
$MaxRam = 0
$RamPool = (Get-CimInstance -Class "Cim_PhysicalMemory" | % {$_.Capacity})
foreach ($RamBank in $RamPool) {
$MaxRam += $RamBank/1024/1024
}
This returns 255.99 GB.
As you can see I always get 256 GB as result. In the BIOS I see that each socket has 256 GB assigned to it.
How can I get the memory for all NUMA-nodes?
A solution I thought of was take the amount of memory, found with above methods, and multiply it with the number of sockets.
Is this a correct assumption?

Related

How to use PowerShell to detect unallocated space on a MBR disk?

I am currently facing an issue with one of my MBR disks on a Windows server. The disk is supposed to have a maximum size of 2048GB, but I have noticed that there is additional space allocated to it from the storage end. After checking the disk, I found out that there is about 152GB of unallocated space on the disk.
It is worth noting that if the allocated size was less than 2048GB, it would be easy to detect the unallocated space using the diskpart command. However, in this case, the allocated size is more than the maximum size, which makes it difficult to detect the unallocated space.
I have tried to detect this issue using various methods, such as the diskpart command, but I was unable to find any information about this unallocated space. I also tried using the procmon tool and opening the diskmgmt snap-in, but the log was too huge and I couldn't find any useful information.
I am now seeking help from the community to come up with a PowerShell script or command that can detect this unallocated space on the MBR disk. I have been searching online but haven't found any solutions that work for me. If anyone has any experience with this issue or know of a PowerShell script that can detect unallocated space on an MBR disk, please share it with me. I would greatly appreciate any help or guidance on this matter.
I'm not sure how accurate this is, but you can try and count the total amount of allocated space and subtract that number from the total underlying disk size to get the maximum unallocated space:
# Query the Win32_DiskDrive instance representing the physical disk
$disk = Get-CimInstance Win32_DiskDrive -Filter 'Index = 2'
# Find all associated partitions
$partitions = $disk |Get-CimAssociatedInstance -ResultClassName Win32_DiskPartition
# Calculate total allocation for configured partitions
$allocated = $partitions |Measure-Object -Sum Size |Select-Object -Expand Sum
# Calculate the remaining void
$unallocated = $disk.Size - $allocated
Write-Host ("There is {0}GB of disk space unallocated" -f $($unallocated/1GB))

PowerShell: Sorting CPU usage to display process taking 2% and above

What cmdlet can you use in PowerShell to sort CPU usage to 2% and above. I need the output to display only processes with CPU usage 2% and above
I will use Get-Counter:
(Get-Counter '\Process(*)\% Processor Time').CounterSamples | ? {$_.CookedValue -ge 2}

avg. disk write queue length performance counter for individual disk in powershell

I am trying to extract the disk realted perf counters. Below is the query that I am using now.
get-counter -counter '\PhysicalDisk(*)\Avg. Disk Write Queue Length'| select -ExpandProperty countersamples
The above returns an expected result for each physical disk separately as shown below.
However, when we execute the same query on a cluster based env, the drive details cannot be obtained individually.
I need to extract the perf counter values for the disk individually on clustered env as well.

How segmentation works and how the physical memory address is calculated from segment table

I was going through the topic of segmentation in operating systems.
I have learnt that the concept of segmentation came into existence because of the free spaces which might exist in the address space of the process loaded in the memory.
I will try to first explain few things which I understood from my study.Please correct me if anything is wrong.
Lets say for example where the segmentation is not used which might not be the ideal case
I have a process with small address space which was loaded in the memory.As the process address space might not be placed at the start of the physical memory.We need some mechanism to convert the addresses of the program code(code segment,from where the instruction to which the PC is pointed gets executed) to the actual physical memory addresses. So we use hardware registers(MMU) for this purpose which maintain base and bound values for the running process.Base value being the starting address of the physical memory from where the process is placed and bound being the total size of the running process or the last address of the running process.As MMU is global,we need to save base/bound values during context switching.
So here physical memory address = virtual memory address + base;
Now lets say we have process with large address space.We need some mechanism like segmentation for better utilization of free space as the process address space may contain large amount free spaces in between heap and stack or code and heap.
For segmentation we maintain a segment table for each process(need to store the table in PCB during context switching).
In segmentation we maintain base/bound values for each logical segment of the running process address space.So ideally we maintain base/bound values for each of code,stack and heap segments and store these values in segment table.
So the segment table should look somewhat like this..
Segment | Base | Bounds
---------------------------
Code | 16K | 1K
Heap | 28K | 1K
Stack | 20K | 2K
and the physical memory might look some what like this..
0 |---------------------|
| OS |
| |
....
| |
| |
| |
16K |---------------------|
| (program code) |
| |
17K |---------------------|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxx free xxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
20K |---------------------|
| |
| |
| (stack) |
| |
22K |---------------------|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxx free xxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
28K |---------------------|
| |
| (heap) |
29K |---------------------|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxx free xxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxx|
32K |---------------------|
So now if the processor needs to convert the virtual memory address to physical memory address while executing the code instruction,How will it get to know which base value to pick as there may be many base values in the segment table?
Suppose lets say the instruction is to update some stack variable..How will it pick the base value of the stack in this case?
So that the physical memory address = stack's base address + virtual memory address from the instruction?
And What are the disadvantages of segmentation apart from external fragmentation.
Any external links with detailed explaination to the concepts of segmentation//paging/virtualization would be really helpful.
In processors that support segmentation, there should be an internal or external registers the processor will use to select the right segment depending on the context. It something that depends on the processor architecture. The only processors I know of that support segmentation are Intel processors.
With x86 (see Intel 8086 : Segmentation) segment registers/selectors there is cs, ds, ss. The processor uses the code cs segment while executing instructions, data segment ds with memory, unless you state otherwise, or stack segment ss with stack instructions.
Most modern processors, apart from x86, only support paging. So to unify memory management, x86 segmentation effect is disabled in most modern operating systems, and rely on paging to manage the virtual memory.

Get a break down of partitions and total diskdrive size using get-wmiobject -class win32_diskdrive

I can return the total size of the disk drive and number of partitions quite easily using
get-wmiobject -class win32_diskdrive | select size, partitions
but how do I return the breakdown of partitions and the total disk drive?
Thanks
Take a look at the Win32_DiskPartition class. It gives more information about each partition.