Skip to content

Commit 69a37a8

Browse files
author
Matthew Wilcox (Oracle)
committed
mm/huge_memory: Fix xarray node memory leak
If xas_split_alloc() fails to allocate the necessary nodes to complete the xarray entry split, it sets the xa_state to -ENOMEM, which xas_nomem() then interprets as "Please allocate more memory", not as "Please free any unnecessary memory" (which was the intended outcome). It's confusing to use xas_nomem() to free memory in this context, so call xas_destroy() instead. Reported-by: [email protected] Fixes: 6b24ca4 ("mm: Use multi-index entries in the page cache") Cc: [email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
1 parent dcfa24b commit 69a37a8

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

include/linux/xarray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,7 @@ void *xas_find_marked(struct xa_state *, unsigned long max, xa_mark_t);
15081508
void xas_init_marks(const struct xa_state *);
15091509

15101510
bool xas_nomem(struct xa_state *, gfp_t);
1511+
void xas_destroy(struct xa_state *);
15111512
void xas_pause(struct xa_state *);
15121513

15131514
void xas_create_range(struct xa_state *);

lib/xarray.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ static void xa_node_free(struct xa_node *node)
264264
* xas_destroy() - Free any resources allocated during the XArray operation.
265265
* @xas: XArray operation state.
266266
*
267-
* This function is now internal-only.
267+
* Most users will not need to call this function; it is called for you
268+
* by xas_nomem().
268269
*/
269-
static void xas_destroy(struct xa_state *xas)
270+
void xas_destroy(struct xa_state *xas)
270271
{
271272
struct xa_node *next, *node = xas->xa_alloc;
272273

mm/huge_memory.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,8 +2672,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
26722672
if (mapping)
26732673
i_mmap_unlock_read(mapping);
26742674
out:
2675-
/* Free any memory we didn't use */
2676-
xas_nomem(&xas, 0);
2675+
xas_destroy(&xas);
26772676
count_vm_event(!ret ? THP_SPLIT_PAGE : THP_SPLIT_PAGE_FAILED);
26782677
return ret;
26792678
}

0 commit comments

Comments
 (0)