amachanic / sp_whoisactive

sp_whoisactive
GNU General Public License v3.0
1.13k stars 281 forks source link

Should new memory columns be divided by 8? #98

Closed erikdarlingdata closed 3 weeks ago

erikdarlingdata commented 1 year ago

Looking at the new columns for @get_memory_info, they seem to account for memory grants a big strangely. There may be a good reason for this that I can't find reference to.

For a particular query, the columns return these values:

used_memory max_used_memory requested_memory    granted_memory
1,148,928   1,148,928       1,335,888           1,335,888

But the XML column returns values that look like this:

<requested_memory_kb>10687104</requested_memory_kb>
<granted_memory_kb>10687104</granted_memory_kb>
<used_memory_kb>9191424</used_memory_kb>
<max_used_memory_kb>9191424</max_used_memory_kb>
<ideal_memory_kb>28144264</ideal_memory_kb>
<required_memory_kb>1480</required_memory_kb>

They're different because all of the memory columns divide values by 8: 'x.max_used_memory_kb / 8 ' Is this the correct way to account for query memory grants?

There's also a minor documentation issue here. All of the other notes about this column say (Requires @get_memory_info = 1).

Formatted/Non:    [memory_info] [xml] NULL
    (Requires @get_memory_info)
mfuller333 commented 1 year ago

@erikdarlingdata I agree it should be consistent, but believe we should be looking at this in the other direction. I think we should be counting memory in kilobytes not pages. My reasoning for this is people think of memory in the term’s kilobyte, megabyte, and gigabyte. We purchase memory this way. Windows, and SQL memory usage and configurations are measured the same. So why are we measuring a query’s memory usage in pages?

erikdarlingdata commented 1 year ago

Yeah, it would save them having to convert it from pages back to another unit that makes more sense for most observations of query memory grants.