Skip to content

Commit

Permalink
added shm-hugepages.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
jkstill committed Feb 16, 2021
1 parent 8a835b1 commit 6812970
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,56 @@ Note that even with HugePages enabled and used, there is shared memory that is n
This database instance was started with `use_large_pages = ONLY`, so we know that all SGA memory is in HugePages.


## Test HugePages

The script `shm-hugepages.pl` can be used to see if HugePages are working:

```text
perldoc shm-hugepages.pl
shm-hugepages.pl
This script attempts create shared memory segments using HugePages
[oracle]$ perl shm.pl
waiting for input
In another session
[root@boc-solver ~]# ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 4 oracle 700 4294967296 0
[root@boc-solver ~]# grep Huge /proc/meminfo
AnonHugePages: 0 kB
HugePages_Total: 2048
HugePages_Free: 2047
HugePages_Rsvd: 2047
HugePages_Surp: 0
Hugepagesize: 2048 kB
Now release the memory by pressing ENTER
[oracle]$ perl shm.pl
waiting for input
[oracle]
Check Memory again
[root]# ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
[root]# grep Huge /proc/meminfo
AnonHugePages: 0 kB
HugePages_Total: 2048
HugePages_Free: 2048
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
```



73 changes: 73 additions & 0 deletions shm-hugepages.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env perl

use warnings;
use strict;
#use Data::Dumper;

=head1 shm-hugepages.pl
This script attempts create shared memory segments using HugePages
[oracle]$ perl shm.pl
waiting for input
In another session
[root@boc-solver ~]# ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 4 oracle 700 4294967296 0
[root@boc-solver ~]# grep Huge /proc/meminfo
AnonHugePages: 0 kB
HugePages_Total: 2048
HugePages_Free: 2047
HugePages_Rsvd: 2047
HugePages_Surp: 0
Hugepagesize: 2048 kB
Now release the memory by pressing ENTER
[oracle]$ perl shm.pl
waiting for input
[oracle]
Check Memory again
[root]# ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
[root]# grep Huge /proc/meminfo
AnonHugePages: 0 kB
HugePages_Total: 2048
HugePages_Free: 2048
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
=cut

my $gigs=4;
my $shmSize = $gigs * 1024 * 2**20;

use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR S_IRWXU SHM_HUGETLB S_IXUSR);
use IPC::SharedMem;
#my $shm = IPC::SharedMem->new(IPC_PRIVATE , 2048 * 2**20, S_IRWXU | SHM_HUGETLB);

my $shm = IPC::SharedMem->new(IPC_PRIVATE , $shmSize, (S_IRUSR | S_IWUSR | S_IXUSR) | SHM_HUGETLB)
or die "cannot allocate shared memory\n";

$shm->write(pack("S", 4711), 2, 2);
my $data = $shm->read(0, 2);
my $ds = $shm->stat;

#print Dumper($ds);

print "waiting for input\n";

my $input=<>;

$shm->remove;

0 comments on commit 6812970

Please sign in to comment.