All of lore.kernel.org
 help / color / mirror / Atom feed
* ipc/mqueue: release spinlock before freeing node_cache in mqueue_evict_inode()
@ 2025-06-27 12:46 ritu pal
  0 siblings, 0 replies; 4+ messages in thread
From: ritu pal @ 2025-06-27 12:46 UTC (permalink / raw)
  To: linux-kernel, Christian Brauner, Al Viro, Ritu Pal, NeilBrown,
	Chen Ni

Currently, mqueue_evict_inode() holds info->lock while freeing info->node_cache
with kfree(). Although kfree() does not sleep, it may take a non-trivial amount
of time, increasing the duration the spinlock is held and potentially impacting
concurrency.

This change moves the kfree(info->node_cache) call outside the critical section,
releasing the spinlock before freeing memory. This reduces lock contention and
follows kernel best practices of minimising the time spent holding spinlocks,
especially around potentially slow operations.

No functional change intended.
Signed-off-by: Ritu Pal <ritupal888@gmail.com>
---
 ipc/mqueue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 82ed2d3c9846..897caf55e217 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -526,8 +526,8 @@ static void mqueue_evict_inode(struct inode *inode)
  spin_lock(&info->lock);
  while ((msg = msg_get(info)) != NULL)
  list_add_tail(&msg->m_list, &tmp_msg);
- kfree(info->node_cache);
  spin_unlock(&info->lock);
+ kfree(info->node_cache);

  list_for_each_entry_safe(msg, nmsg, &tmp_msg, m_list) {
  list_del(&msg->m_list);
--
2.39.5 (Apple Git-154)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-03  8:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAEy91+YpzU5tKEfsjt1_Hh0fsiCfVVK099EztXOPFGHFYyA1KQ@mail.gmail.com>
2025-06-27 16:37 ` ipc/mqueue: release spinlock before freeing node_cache in mqueue_evict_inode() Al Viro
2025-07-03  8:04   ` ritu pal
2025-07-03  8:10     ` Al Viro
2025-06-27 12:46 ritu pal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.