cancel
Showing results for 
Search instead for 
Did you mean: 

Queries for Used and Resident memory and comparison with Overview tab numbers

Former Member
0 Kudos

Hi,

I look at the overview tab of the HANA studio for DB used memory and DB resident memory.

When I use the queries 1 ,2 and unix command below, the results match with the numbers displayed in the overview tab.

SQL Query 1 for DB used memory: (Available in HANA documents)

SELECT ROUND(SUM(TOTAL_MEMORY_USED_SIZE/1024/1024/1024), 2) AS
"Used Memory GB" FROM SYS.M_SERVICE_MEMORY;

SQL Query 2 for DB Resident memory: (I created this by observing the table contents)

SELECT ROUND(SUM(PHYSICAL_MEMORY_SIZE/1024/1024/1024), 2) AS
"DB RESIDENT Memory GB" FROM SYS.M_SERVICE_MEMORY;

Unix command: Provides same value as SQL query 2.

cat `ps h -U qp4adm -o "/proc/%p/status" | tr -d ' '` | awk '/VmSize/ {v+=$2} /VmPeak/ {vp+=$2} /VmRSS/ {r+=$2;} /VmHWM/ {rp+=$2} END {printf("Virtual Size = %.2f GB (peak = %.2f), Resident size = %.2f GB (peak = %.2f)\n", v/1024/1024, vp/1024/1024, r/1024/1024, rp/1024/1024)}'

My Questions:

Question 1:Now when I use the query 3 below(just getting the above 2 together with the process name), I observe that used memory is more than the resident memory for some services.

I believe that this is wrong based on the below explanation which is in the official HANA docs.

Can anybody in this forum throw more light on this observation?

SQL Query 3:

SELECT SERVICE_NAME,ROUND(SUM(TOTAL_MEMORY_USED_SIZE/1024/1024/1024), 2) AS
"Used Memory GB", ROUND(SUM(PHYSICAL_MEMORY_SIZE/1024/1024/1024), 2) AS
"DB RESIDENT Memory GB" FROM SYS.M_SERVICE_MEMORY GROUP BY SERVICE_NAME

Explanation on Resident from HANA doc:

"

When memory is required for table growth or for temporary computations, the SAP HANA code obtains it from the existing memory pool. When the pool cannot satisfy the request, the HANA memory manager will request and reserve more memory from the operating system. At this point, the virtual memory size of the HANA processes grows.

Once a temporary computation completes or a table is dropped, the freed memory is returned to the memory manager, who recycles it to its pool, without informing Linux. Thus, from SAP HANA‟s perspective, the amount of Used Memory shrinks, but the process‟ virtual and resident sizes are not affected. This creates a situation where the Used Memory may even shrink to below the size of SAP HANA‟s resident memory, which is perfectly normal."

Question 2:

SQL Query 5: This query doesn't match with the resident memory value in overview tab. Should it? I mean if it doesn't then is it an issue in the studio?

SELECT ROUND((USED_PHYSICAL_MEMORY + FREE_PHYSICAL_MEMORY)/1024/1024/1024, 2) AS "Physical Memory GB", ROUND(USED_PHYSICAL_MEMORY/1024/1024/1024, 2) AS "Resident GB" FROM PUBLIC.M_HOST_RESOURCE_UTILIZATION

Question 3:

In some Studios(meaning different versions) I have used the result of SQL query 1 doesn't match with the studio number. Can we consider this as an issue in the studio?

Question 4:

From the explanation above, can we understand that the Resident size increases since the freed memory is not released to the OS but to the HANA memory pool?

How do we differentiate between DB used and DB Resident memory?

The definition for both are same-> Physical memory in use by the process.

Used memory=" Code+stack+HANA memory pool(Tables,temporary computations)

Resident memory=?

Regards,

Sandeep

Accepted Solutions (1)

Accepted Solutions (1)

rindia
Active Contributor
0 Kudos

Hi Sandeep,

First I ran your query 1, 2, and 3.

In my case Used memory is less than resident memory (Comparing Query 1 and 2).

For query 3, Used Memory is more than Resident memory only for the services: nameserver, preprocessor, xsengine and compileserver.

Lets have a look on the below image:

 

Coming to your Question1: Used memory should not be greater than resident memory.

From the above image, it is normal that Used memory fluctuates over resident memory and there is a chance that for some of the services, Used memory is more than resident memory.

For your remaining questions, I will try to respond later.

Regards

Raj

Former Member
0 Kudos

Hi Raj Kumar,

Thanks for the response.

My results are comparable with yours.

I want more info on Resident memory.

I am hoping to keep this discussion on and awaiting your response.

Regards,

Sandeep

rindia
Active Contributor
0 Kudos

Hi Sandeep,

Resident memory is the amount of physical memory that is actually being used from the perspective of the operating system.

Coming to your question 2: Query 5 does not match with overview tab.

In overview tab of Administration under Resident memory, it shows indicators Database Resident/Total Resident. In my case the result of query 5 matching with Database Resident indicator.

In your case it should match too. Make sure that query you are running and Administration overview belongs to same system.

Coming to your question 3: I not understood your question.

Regards

Raj

lbreddemann
Active Contributor
0 Kudos

Hey Sandeep

this is from the email you send me (please keep discussions here in the forum, so that others can benefit from it, thanks):

Since HANA doesn’t release the memory to Os after a temporary computation occurs or after a table is deleted, what happens to the memory which is released to the pool when it is not in use?

Should I understand that the process is just owning it without using it? This I believe is against the normal convention in Linux. Right?”

Well, the standard approach is to release resources that you don’t need any longer so that other processes/users/whatever could potentially use them instead.

It does not mean, to throw back resources the very moment you have no immediate use for them, regardless how much effort it takes to get these resources back!

Look, for HANA, there are no other processes running on the servers. By definition.

There is nobody else that could potentially use memory.

On the other hand, acquiring and releasing memory from and to the OS is a very costly task and even more so in a heavy  multi-threaded environment.

All in all, it’s much better to not use the OS memory management for our threads.

Instead SAP HANA grabs the most of the potential maximum RAM initially and keeps it (from OS point of view).

Internally SAP HANA runs its very own memory management that is optimized for the SAP HANA process/thread architecture.

Hope that helps,

Lars

Former Member
0 Kudos

Hi Lars,

Thank you very much for the response.

Regards,

Sandeep

Former Member
0 Kudos

Hi Lars,

I created a similar thread for some of my questions related to this , Can you please check 

http://scn.sap.com/message/15001744#15001744

Thanks,

Razal

sanjaysahita1
Explorer
0 Kudos

This message was moderated.

Answers (2)

Answers (2)

0 Kudos

This message was moderated.

lohitkumar_ap
Explorer
0 Kudos

Hi Lars,

There is still something i am not able to understand. Are HANA used Memory and HANA Resident Memory related?  Resident memory means the Physical memory being used by HANA processes.

so i would assume that HANA Used memory should not be more that Resident memory as HANA appliance has no swapping and is completely in-memory but the documents mention that HANA used memory can be more than HANA resident memory. How is this possible? Does HANA Used memory also account so some disk space which is not from Physical memory? or rather kindly explain the below situation and how that could happen.

At certain point HANA Resident memory is less that HANA Used Memory. What are the reasons for this to happen?

Best Regards,

Lohit

lbreddemann
Active Contributor
0 Kudos

Sorry,

but resurrecting this old thread I got the impression that you should read up on memory in SAP HANA (and maybe Linux in general) first:

https://hcp.sap.com/content/dam/website/saphana/en_us/Technology%20Documents/HANA_Memory_Usage_SPS8....

- Lars

lohitkumar_ap
Explorer
0 Kudos

Hi Lars,

thanks for the link. I had a look at it before i posted here.

Document explains Resident memory alongside Physical memory and  HANA used memory alongside Virtual memory but not Resident memory alongside HANA Used memory

From my understanding HANA used memory cannot be more than Resident memory conceptually but that isnt the case in reality. Please let me know if i'm missing something here? is the way HANA used memory is calculated which can make it sometimes be more than Resident memory?

Best Regards,

Lohit

lbreddemann
Active Contributor
0 Kudos

Lohit,

your understanding is a bit too simplistic here.

Who said there is no paging whatsoever for the processes on a SAP HANA box?

SAP HANA doesn't "pin" data into RAM. It just allocates it from the O/S. That's it.

When the O/S decides it's about time to page out some I/O buffers, shared objects or something like that, SAP HANA won't interfere with that.

"Used memory" is always the perspective from SAP HANA - what is currently belonging to our processes and reserved for some internal allocator.

Just check the document again, and see that the virtual memory of SAP HANA is always larger than the resident memory.

"Resident memory" is a O/S perspective. It's about how much of the memory belonging to a process is currently in the actual RAM.

Does that make it clearer now?

- Lars

lohitkumar_ap
Explorer
0 Kudos

Hi Lars,

I'm sorry. I still cant get the clear picture on how HANA used memory can be higher than Resident Memory. Lets assume this scenario.

- HANA Used memory is rightnow equal to Resident memory and HANA needs more memory.

- More memory is allocated from Virtual memory to HANA.

wouldnt this add up to both HANA Resident memory and HANA used Memory? Wouldnt this make HANA Resident memory a limit to HANA Used memory?

Unless HANA Used memory constitute more than just RAM(as Resident memory is actual RAM that has been assigned to HANA) used by HANA

Thanks,

Lohit

lbreddemann
Active Contributor
0 Kudos

> wouldnt this add up to both HANA Resident memory and HANA used Memory?

> Wouldnt this make HANA Resident memory a limit to HANA Used memory?

Allocating virtual memory doesn't need to force the O/S to physically use RAM for that.

The only thing that is required at that point is that the O/S makes sure it actually will be able to serve the memory demand once actually requested.

When SAP HANA then goes on and actually touches this newly reserved memory, it likely will also increase the resident size, yes. It could also be that even more other parts of SAP HANA related memory gets moved from RAM to disk - but this is really up to the O/S memory manager.

So, NO, resident memory is never a limit to the used memory. It's what is currently physically in memory.

That's all.

>> Unless HANA Used memory constitute more than just RAM(as Resident memory is actual RAM that >> has been assigned to HANA) used by HANA

You seem to assume that the virtual memory manager waits until the actual physical RAM is used up completely before paging out. It's not that simple.

lohitkumar_ap
Explorer
0 Kudos

Thanks Lars. That helps

Best Regards,

Lohit