Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return allocated memory with malloc_trim when queue is empty #960

Closed
Closed
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions common/notificationconsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <iostream>
#include <deque>
#include <malloc.h>
#include "redisapi.h"

#define NOTIFICATION_SUBSCRIBE_TIMEOUT (1000)
Expand Down Expand Up @@ -154,6 +155,27 @@ void swss::NotificationConsumer::pop(std::string &op, std::string &data, std::ve
std::string msg = m_queue.front();
m_queue.pop();

if (m_queue.empty())
{
/***
* If there is a burst of notifications that causes the queue to grow in size,
* memory allocated by the queue will not be released even after the all items
* have been popped.
*
* Force the memory to be released by destroying existing queue and creating a new one.
*/
SWSS_LOG_DEBUG("%s queue is empty, calling malloc_trim()", m_channel.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to INFO level?

int rv = malloc_trim(0);
if (rv == 1)
{
SWSS_LOG_DEBUG("Memory released successfully");
}
else
{
SWSS_LOG_DEBUG("No memory released by malloc_trim");
}
}

values.clear();
JSon::readJson(msg, values);

Expand Down
Loading