Skip to content

Commit

Permalink
Support allocate buffer pool based on ratio (sonic-net#3201)
Browse files Browse the repository at this point in the history
Support allocate buffer pool size based on percentage of available memory by percentage field in BUFFER_POOL table.
It is used in the dynamic buffer model only and represents the percentage of a buffer pool's size compared to the available memory size.
On Nvidia devices, if the percentage is defined, the buffer pool size is available memory * percentage.
  • Loading branch information
stephenxs authored Jul 25, 2024
1 parent 2367bca commit 3c9d6b3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cfgmgr/buffer_pool_mellanox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,12 @@ local pool_size
if shp_size then
accumulative_occupied_buffer = accumulative_occupied_buffer + shp_size
end

local available_buffer = mmu_size - accumulative_occupied_buffer
if ingress_pool_count == 1 then
pool_size = mmu_size - accumulative_occupied_buffer
pool_size = available_buffer
else
pool_size = (mmu_size - accumulative_occupied_buffer) / 2
pool_size = available_buffer / 2
end

if pool_size > ceiling_mmu_size then
Expand All @@ -429,12 +431,19 @@ end

local shp_deployed = false
for i = 1, #pools_need_update, 1 do
local percentage = tonumber(redis.call('HGET', pools_need_update[i], 'percentage'))
local effective_pool_size
if percentage ~= nil and percentage >= 0 then
effective_pool_size = available_buffer * percentage / 100
else
effective_pool_size = pool_size
end
local pool_name = string.match(pools_need_update[i], "BUFFER_POOL|([^%s]+)$")
if shp_size ~= 0 and pool_name == "ingress_lossless_pool" then
table.insert(result, pool_name .. ":" .. math.ceil(pool_size) .. ":" .. math.ceil(shp_size))
table.insert(result, pool_name .. ":" .. math.ceil(effective_pool_size) .. ":" .. math.ceil(shp_size))
shp_deployed = true
else
table.insert(result, pool_name .. ":" .. math.ceil(pool_size))
table.insert(result, pool_name .. ":" .. math.ceil(effective_pool_size))
end
end

Expand Down
31 changes: 31 additions & 0 deletions tests/test_buffer_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,3 +903,34 @@ def test_bufferPoolInitWithSHP(self, dvs, testlog):
self.config_db.delete_entry('DEFAULT_LOSSLESS_BUFFER_PARAMETER', 'AZURE')
self.app_db.delete_entry("BUFFER_PG_TABLE_SET", "")
dvs.runcmd("kill -s SIGCONT {}".format(oa_pid))


def test_bufferPoolPercentage(self, dvs, testlog):
self.setup_db(dvs)

try:
self.config_db.delete_field('BUFFER_POOL', 'ingress_lossless_pool', 'size')
except Exception as e:
pass

try:
percentage = 75
margin = 1

re_pool_size = "ingress_lossless_pool:([0-9]+)"
_, original_output = dvs.runcmd("redis-cli --eval /usr/share/swss/buffer_pool_vs.lua")
original_size = int(re.match(re_pool_size, original_output).group(1))

original_ingress_lossless_pool = self.config_db.get_entry('BUFFER_POOL', 'ingress_lossless_pool')
ingress_lossless_pool = original_ingress_lossless_pool
ingress_lossless_pool['percentage'] = str(percentage)
self.config_db.update_entry('BUFFER_POOL', 'ingress_lossless_pool', ingress_lossless_pool)

_, percentage_output = dvs.runcmd("redis-cli --eval /usr/share/swss/buffer_pool_vs.lua")
percentage_size = int(re.match(re_pool_size, percentage_output).group(1))

real_percentage = percentage_size * 100 / original_size
assert abs(percentage - real_percentage) < margin
finally:
self.config_db.delete_entry('BUFFER_POOL', 'ingress_lossless_pool')
self.config_db.update_entry('BUFFER_POOL', 'ingress_lossless_pool', original_ingress_lossless_pool)

0 comments on commit 3c9d6b3

Please sign in to comment.