Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Assistance to calculate number of hugepages Post 303046210 by sand1234 on Tuesday 28th of April 2020 01:34:09 AM
Old 04-28-2020
Assistance to calculate number of hugepages

Hi,

I am trying to count the number of hugepages & total usage being used by applications..

INPUT FILE
==========

Code:
[root@xxx~]# grep huge /proc/*/numa_maps 2>/dev/null
/proc/47173/numa_maps:140000000 default file=/anon_hugepage\040(deleted) huge anon=1 dirty=1 N0=1 kernelpagesize_kB=1048576
/proc/47173/numa_maps:1000000000 default file=/buffers-numa-0 huge dirty=313 N0=313 kernelpagesize_kB=2048
/proc/47173/numa_maps:1027200000 default file=/buffers-numa-1 huge dirty=313 N1=313 kernelpagesize_kB=2048
/proc/47173/numa_maps:2d00000000 default file=/anon_hugepage\040(deleted) huge anon=1 dirty=1 N1=1 kernelpagesize_kB=1048576
/proc/47173/numa_maps:4dc0200000 default file=/anon_hugepage\040(deleted) huge anon=1 dirty=1 N0=1 kernelpagesize_kB=2048
/proc/47173/numa_maps:4dc0400000 default file=/anon_hugepage\040(deleted) huge anon=1 dirty=1 N0=1 kernelpagesize_kB=2048
/proc/47173/numa_maps:4dc0600000 default file=/anon_hugepage\040(deleted) huge anon=1 dirty=1 N0=1 kernelpagesize_kB=2048
/proc/47173/numa_maps:2aaac0000000 default file=/mnt/hugepages1G/libvirt/qemu/2-instance-0000001f/qemu_back_mem._objects_ram-node0.su05tD\040(deleted) huge dirty=2 mapmax=2 N0=2 kernelpagesize_kB=1048576
/proc/488519/numa_maps:7f6e80000000 bind:0 file=/mnt/hugepages1G/libvirt/qemu/2-instance-0000001f/qemu_back_mem._objects_ram-node0.su05tD\040(deleted) huge dirty=2 mapmax=2 N0=2 kernelpagesize_kB=1048576

SCRIPT
==========

Code:
#!/bin/bash

total_num_hugepages=0

for id in $(grep huge /proc/*/numa_maps 2>/dev/null | awk -F'/' '{proc[$3]=1} END {for (i in proc) print i}'); do
        for hugepagesize in $(find /sys/devices/system/node/node[0-9]*/hugepages/ -type d -name "hugepages-*" | sed 's/.*hugepages-\([0-9]\+\).*/\1/'| sort | uniq);
        do
        ps $id;
        total_num_hugepages+=$(grep huge /proc/$id/numa_maps 2>/dev/null | grep "kernelpagesize.*=$hugepagesize" | sed 's/.*dirty=\([0-9]\+\).*/\1/')
        echo $total_num_hugepages
        done
done

Code:
[root@xxx ~]# ./hugepage_usage.sh
    PID TTY      STAT   TIME COMMAND
  47173 ?        SLl  333416:10 /usr/bin/vpp -c /etc/vpp/vpp.conf
01 1 2
    PID TTY      STAT   TIME COMMAND
  47173 ?        SLl  333416:10 /usr/bin/vpp -c /etc/vpp/vpp.conf
01 1 2313 313 1 1 1
    PID TTY      STAT   TIME COMMAND
 488519 ?        Sl    27:46 /usr/libexec/qemu-kvm -name guest=instance-0000001f,debug-threads=on -S -ob
01 1 2313 313 1 1 12
    PID TTY      STAT   TIME COMMAND
 488519 ?        Sl    27:46 /usr/libexec/qemu-kvm -name guest=instance-0000001f,debug-threads=on -S -ob
01 1 2313 313 1 1 12

Expected sample output
======================
PID TTY STAT TIME COMMAND
47173 ? SLl 333416:10 /usr/bin/vpp -c /etc/vpp/vpp.conf

/usr/bin/vpp
10 hugepages x 1048576 kB = xx kB
2 hugepages x 2048 kB = xx kB
Total hugepage usage = xx kB

Please give me some pointers on how I can improve my code, and achieve the output.

Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calculate the number of days left in a month

does any one have any ideas how i would go about calculating the number of days left in the month from a bash script ?. I want to do some operations on a csv file according to the result (8 Replies)
Discussion started by: dunryc
8 Replies

2. Shell Programming and Scripting

calculate number of strings in a variable

Hi all I have a variable called "variable" and is of the form variable ="AAA BBB CCC DDD" {basically it has values separated by spaces} What is the simplest way to check if "variable" has more that one value in its list? Thanks. (9 Replies)
Discussion started by: felixmat1
9 Replies

3. Solaris

Calculate Network Number in /etc/netmasks file.

Hi All, I have an issue with calculating the network number that needs to be put in /etc/netmasks file in my Sol-9 server. The IP of my server in 10.164.114.135 Default Gateway - 10.164.114.130 Netmask - 255.255.255.240 If I set "10.164.114.130 255.255.255.240" in netmask file, after... (2 Replies)
Discussion started by: Hari_Ganesh
2 Replies

4. Programming

perl - calculate the number of lines from particular files

Hi, plz see the below code. here my aim is to calculate the number of lines in unprocessedData.out if this file contains 40 lines then lastly $linenum should print 40.(except blank lines) i have tried below code but it giving me the output only one. can anyone help me how to do ? ... (9 Replies)
Discussion started by: pspriyanka
9 Replies

5. Web Development

Calculate the number of days between 2 dates - PHP

Is this code good for this purpose? <?php $date1 = mktime(0,0,0,01,01,1991); $date2 = mktime(0,0,0,03,22,2012); $diff = $date2 - $date1; $days = $diff / (60*60*24); echo ($days . "<br />"); ?> (3 Replies)
Discussion started by: kovacsakos
3 Replies

6. Shell Programming and Scripting

Calculate the number of days between 2 dates - bash script

I wrote the day calculator also in bash. I would like to now, that is it good so? #!/bin/bash datum1=`date -d "1991/1/1" "+%s"` datum2=`date "+%s"` diff=$(($datum2-$datum1)) days=$(($diff/(60*60*24))) echo $days Thanks in advance for your help! (3 Replies)
Discussion started by: kovacsakos
3 Replies

7. Shell Programming and Scripting

How to calculate the total number of weeks from a specify year?

Hi anyone can help? How to calculate total number of weeks from a specify date, for example, 01 Jan 2012. Thx! (2 Replies)
Discussion started by: rayray2013
2 Replies

8. Solaris

How to calculate the number of TPS on Solaris server?

Hi, Please help me to find how to calculate the number of TPS supported by any solaris server for example one server with below configuration . Sun Blade X6270 with two 4-core processors 2 x 300 GB internal disk drives (2 Replies)
Discussion started by: manojkakkar
2 Replies

9. Shell Programming and Scripting

Sum and calculate number in table

Hello everyone, I have some problem in calculation number using awk. input file format : S1 1 : 0.003 0.031 S2 1 : 0.020 0.095 S3 4 : 0.088 0.012 S4 2 : 0.010 0.090 S5 2 : 0.244 0.066 S6 3 : 0.249 0.751 S7 3 : 0.010 0.990 S8 3 : 0.230... (4 Replies)
Discussion started by: awil
4 Replies

10. Solaris

How to calculate total number of cores on my servers ?

Hi, I want to get total number of cores on my all non-global zones on Solaris 10. I got two methods and both are giving different results. Below link is a script, which tells me that total cores are 8 Mandalika's scratchpad: Oracle Solaris: Show Me the CPU, vCPU, Core Counts and the... (4 Replies)
Discussion started by: ron323232
4 Replies
LOGPROF.CONF(5) 						     AppArmor							   LOGPROF.CONF(5)

NAME
logprof.conf - configuration file for expert options that modify the behavior of the AppArmor logprof(1) program. DESCRIPTION
The logprof(1) program can be configured to have certain default behavior by the contents of logprof.conf. The [qualifiers] section lists specific programs that should have a subset of the full ix/px/ux list when asking what mode to execute it using. Since creating a separate profile for /bin/bash is dangerous, we can specify that for /bin/bash, only (I)nherit, (U)nconstrained, and (D)eny should be allowed options and only those will show up in the prompt when we're asking about adding that to a profile. Likewise, if someone currently exec's /bin/mount in ix or px mode, things won't work, so we can provide only (U)nconstrained and (D)eny as options. And certain apps like grep, awk, sed, cp, and mkdir should always inherit the parent profile rather than having their own profile or running unconfined, so for them we can specify that only (I)nherit and (D)eny are the allowed options. Any programs that are not listed in the qualifiers section get the full (I)nherit / (P)rofile / (U)nconstrained / (D)eny option set. If the user is doing something tricky and wants different behavior, they can tweak or remove the corresponding line in the conf file. The [defaulthat] section lists changehat-aware programs and what hat logprof(1) will collapse the entries to for that program if the user specifies that the access should be allowed, but should not have it's own hat. The [globs] section allows modification of the logprof rule engine with respect to globbing suggestions that the user will be prompted with. The format of each line is-- "<perl glob> = <apparmor glob>". When logprof(1) asks about a specific path, if the perl glob matches the path, it replaces the part of the path that matched with the corresponding apparmor glob and adds it to the list of globbing suggestions. Lines starting with # are comments and are ignored. EXAMPLE
[qualifiers] # things will very likely be painfully broken if bash has it's own profile /bin/bash = iu # mount doesn't work if it's confined /bin/mount = u # these helper utilities should inherit the parent profile and # shouldn't have their own profiles /bin/awk = i /bin/grep = i /bin/sed = i [defaulthat] /usr/sbin/sshd = EXEC /usr/sbin/httpd2 = DEFAULT_URI /usr/sbin/httpd2-prefork = DEFAULT_URI [globs] # /foo/bar/lib/libbaz.so -> /foo/bar/lib/lib* /lib/lib[^/]+so[^/]*$ = /lib/lib*so* # strip kernel version numbers from kernel module accesses ^/lib/modules/[^/]+/ = /lib/modules/*/ # strip pid numbers from /proc accesses ^/proc/d+/ = /proc/*/ BUGS
None. Please report any you find to bugzilla at <http://bugzilla.novell.com>. SEE ALSO
apparmor(7), apparmor.d(5), enforce(1), change_hat(2), complain(1), logprof(1), genprof(1), and <http://forge.novell.com/modules/xfmod/project/?apparmor>. NOVELL
/SUSE 2007-04-03 LOGPROF.CONF(5)
All times are GMT -4. The time now is 02:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy