[PATCH] nvmet-tcp: fix page fragment cache leak in error path
Christoph Hellwig
hch at lst.de
Tue May 26 00:12:01 PDT 2026
On Mon, May 25, 2026 at 05:50:19PM +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang at kylinos.cn>
>
> In nvmet_tcp_alloc_queue(), when a connection is closed during the
> allocation process (e.g., nvmet_tcp_set_queue_sock() returns -ENOTCONN),
> the error handling jumps to out_free_queue without draining the page
> fragment cache.
nvmet_tcp_set_queue_sock jumps to out_destroy_sq.
> Although nvmet_tcp_free_cmd() is called in some error paths to release
> individual page fragments, the underlying page cache reference held by
> queue->pf_cache is never released. This results in a page leak each time
> a connection fails during allocation, which could lead to memory
> exhaustion over time if connections are repeatedly opened and closed.
>
> Fix this by calling page_frag_cache_drain() before freeing the queue
> structure in the out_free_queue label.
The first allocation using pf_cache is the call to nvmet_tcp_alloc_cmd
after ida_alloc. So afaik this drain should at the out_ida_remove
label. And given how obscure this is, maybe a comment would not
hurt either?
Otherwise this looks good.
More information about the Linux-nvme
mailing list