linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <song@kernel.org>
To: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>
Cc: <akpm@linux-foundation.org>, <x86@kernel.org>,
	<peterz@infradead.org>, <hch@lst.de>, <kernel-team@fb.com>,
	<rick.p.edgecombe@intel.com>, <mcgrof@kernel.org>,
	<dave.hansen@intel.com>, Song Liu <song@kernel.org>
Subject: [RFC 5/5] vmalloc: vfree_exec: free unused vm_struct
Date: Thu, 18 Aug 2022 15:42:18 -0700	[thread overview]
Message-ID: <20220818224218.2399791-6-song@kernel.org> (raw)
In-Reply-To: <20220818224218.2399791-1-song@kernel.org>

This is clearly not done yet, but it won't be too hard.

I would like to highlight that, we need both subtree_max_size and vm for
vmap_area in free_text tree. Therefore, we cannot keep the union in
vmam_area.
---
 include/linux/vmalloc.h | 12 ++----------
 mm/vmalloc.c            | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 691c02ffe3db..de7731caadc0 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -68,16 +68,8 @@ struct vmap_area {
 	struct rb_node rb_node;         /* address sorted rbtree */
 	struct list_head list;          /* address sorted list */
 
-	/*
-	 * The following two variables can be packed, because
-	 * a vmap_area object can be either:
-	 *    1) in "free" tree (root is free_vmap_area_root)
-	 *    2) or "busy" tree (root is vmap_area_root)
-	 */
-	union {
-		unsigned long subtree_max_size; /* in "free" tree */
-		struct vm_struct *vm;           /* in "busy" tree */
-	};
+	unsigned long subtree_max_size;
+	struct vm_struct *vm;
 };
 
 /* archs that select HAVE_ARCH_HUGE_VMAP should override one or more of these */
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 5f3b5df9313f..57dd18882d37 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1428,6 +1428,7 @@ adjust_va_to_fit_type(struct rb_root *root, struct list_head *head,
 		 */
 		lva->va_start = va->va_start;
 		lva->va_end = nva_start_addr;
+		lva->vm = va->vm;
 
 		/*
 		 * Shrink this VA to remaining size.
@@ -3394,10 +3395,19 @@ void vfree_exec(const void *addr)
 	spin_unlock(&vmap_area_lock);
 
 	spin_lock(&free_text_area_lock);
-	merge_or_add_vmap_area_augment(va,
+	va = merge_or_add_vmap_area_augment(va,
 		&free_text_area_root, &free_text_area_list);
+	if (va) {
+		struct vm_struct *vm = va->vm;
+
+		if (vm != &text_tail_vm) {
+			va = __find_vmap_area((unsigned long)vm->addr,
+					      free_text_area_root.rb_node);
+			if (va->va_start == (unsigned long)vm->addr)
+				pr_info("%s TODO: free vm->addr %px\n", __func__, vm->addr);
+		}
+	}
 	spin_unlock(&free_text_area_lock);
-	/* TODO: when the whole vm_struct is not in use, free it */
 }
 
 /**
-- 
2.30.2



  parent reply	other threads:[~2022-08-18 23:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18 22:42 [RFC 0/5] vmalloc_exec for modules and BPF programs Song Liu
2022-08-18 22:42 ` [RFC 1/5] vmalloc: introduce vmalloc_exec and vfree_exec Song Liu
2022-10-06 23:15   ` Luis Chamberlain
2022-10-07  6:39     ` Song Liu
2022-08-18 22:42 ` [RFC 2/5] bpf: use vmalloc_exec Song Liu
2022-08-18 22:42 ` [RFC 3/5] modules, x86: use vmalloc_exec for module core Song Liu
2022-10-06 23:38   ` Luis Chamberlain
2022-10-07  6:46     ` Song Liu
2022-08-18 22:42 ` [RFC 4/5] vmalloc_exec: share a huge page with kernel text Song Liu
2022-10-06 23:44   ` Luis Chamberlain
2022-10-07  6:53     ` Song Liu
2022-08-18 22:42 ` Song Liu [this message]
2022-08-22 15:46 ` [RFC 0/5] vmalloc_exec for modules and BPF programs Song Liu
2022-08-22 16:34   ` Peter Zijlstra
2022-08-22 16:56     ` Song Liu
2022-08-23  5:42       ` Peter Zijlstra
2022-08-23  6:39         ` Christophe Leroy
2022-08-23  6:57           ` Song Liu
2022-08-23  6:55         ` Song Liu
2022-08-24 17:06       ` Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220818224218.2399791-6-song@kernel.org \
    --to=song@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@intel.com \
    --cc=hch@lst.de \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mcgrof@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).