From patchwork Thu Aug 18 22:42:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 12948193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E26FCC00140 for ; Thu, 18 Aug 2022 23:49:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7599D8D0002; Thu, 18 Aug 2022 19:49:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 708478D0001; Thu, 18 Aug 2022 19:49:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D15F8D0002; Thu, 18 Aug 2022 19:49:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 401A38D0001 for ; Thu, 18 Aug 2022 19:49:34 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F2E7B1A0152 for ; Thu, 18 Aug 2022 23:49:33 +0000 (UTC) X-FDA: 79814357868.21.2C3DC8E Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf31.hostedemail.com (Postfix) with ESMTP id 3118321437 for ; Thu, 18 Aug 2022 23:21:17 +0000 (UTC) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27IKhi4c016409 for ; Thu, 18 Aug 2022 15:54:20 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3j1d1dpr6u-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 18 Aug 2022 15:54:19 -0700 Received: from twshared7570.37.frc1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 18 Aug 2022 15:54:13 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id 28C05BBF66E3; Thu, 18 Aug 2022 15:42:46 -0700 (PDT) From: Song Liu To: , CC: , , , , , , , , Song Liu Subject: [RFC 5/5] vmalloc: vfree_exec: free unused vm_struct Date: Thu, 18 Aug 2022 15:42:18 -0700 Message-ID: <20220818224218.2399791-6-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220818224218.2399791-1-song@kernel.org> References: <20220818224218.2399791-1-song@kernel.org> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: pKyqVr9L__8qhxUToW_taDNxsTojsbZq X-Proofpoint-GUID: pKyqVr9L__8qhxUToW_taDNxsTojsbZq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-18_16,2022-08-18_01,2022-06-22_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660864879; a=rsa-sha256; cv=none; b=bcFm8PrkzGo9Zwl7T/FNMZlf3sHDLKYypAzKLmDtawerhlUUfa/vKEIiMWt69mT2U60A8w ya9cdl6IbfIBMr0F0D0zuDI0UwTIYWb8eDZ/8uoeBEgEPUE3vU5C09qKk81A95/02BbEwU +LrBdtkGt/+X2vJjZvYEKLX/Fa0wCso= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf31.hostedemail.com: domain of "prvs=9229e92ca3=songliubraving@fb.com" designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=9229e92ca3=songliubraving@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660864879; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cfxk5IpxpBr5oFfQgYxTLNpH3zMv0ldk1OTQ1M6swNU=; b=HeuJQJfVdDK2xw/GP5QZFpTziF6Mqyx+3GTdQO3OwBkteZ2w0y2nYoOwTbrsrARONorx06 HVDPzmLxRAJoBb762JDasEfBmQQ8ieB4Jp7a/IdeAfy7gMzpGfdD6zzJJMbf79G/PkarMh MwldIo2X4A6N1wnhVNLq+jKInH1mjg4= X-Stat-Signature: 65jmdf89fzs6xq1dtpy9974r8eqa74xu X-Rspamd-Queue-Id: 3118321437 Authentication-Results: imf31.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf31.hostedemail.com: domain of "prvs=9229e92ca3=songliubraving@fb.com" designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=9229e92ca3=songliubraving@fb.com" X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1660864877-998968 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 */ } /**