From patchwork Wed Jan 24 18:09:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 13529521 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 6B3D5C47E49 for ; Wed, 24 Jan 2024 18:09:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2C648D0002; Wed, 24 Jan 2024 13:09:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EDCA18D0001; Wed, 24 Jan 2024 13:09:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA46F8D0002; Wed, 24 Jan 2024 13:09:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CA5AA8D0001 for ; Wed, 24 Jan 2024 13:09:27 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8F5E3C0B5B for ; Wed, 24 Jan 2024 18:09:27 +0000 (UTC) X-FDA: 81714991974.22.7B41A37 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by imf10.hostedemail.com (Postfix) with ESMTP id BB74BC0034 for ; Wed, 24 Jan 2024 18:09:25 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="WUZ/imfW"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706119765; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=EdyPrU/kftC7g2TetwPRn8BZd+pMyQ31/waG2MZ70eg=; b=yBJx2CsCvvl6LhrOM6rUJ4PfXCBavK7NSzDUqmzlMm5O8N6g3WomYZkGbfNjHnxjpVSYH0 FRPBcsGmvVoHVdvLS0EoLGIVh8DLZKLea/7yQo/AOuVavXxuf5lAIEbZ8UqYwZbcxcWHb+ WFZKdQVm9gCBMi5vJSONJ2VRM6qnYMk= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="WUZ/imfW"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706119765; a=rsa-sha256; cv=none; b=lhZfbGTXKudtxuIafAQmU4rvbhqpYY5SD0ykYS/G3xeDBjlGlHhP3sNbfG8IPv0ZcD7G+4 xCBFwJDvRlSjp784vnmELjjxbuqneuKk8Ku6Qcrp2YXZiuMlbHWP4e9M/JqYt0kFgcdvcR Ck14cTR9xcpYnEpdWu9Gu5RAcfHvwmw= Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-50ed808db11so6497823e87.2 for ; Wed, 24 Jan 2024 10:09:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706119764; x=1706724564; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EdyPrU/kftC7g2TetwPRn8BZd+pMyQ31/waG2MZ70eg=; b=WUZ/imfWPcLqHsmhfX1YnUHoRfINejJ/IYsM5+oe/pKbDVs16T07Tdk1UOqG7BlDNx TjAGnjp03Ex1lrKMtLepQZy7SXwsIpGzs4HFEMjltANgGdus2fzwiYzFK+4x7o1E4gkk cPT/rgw6CFlkiV6jSrv8rtjX3T/PsQBMntTYWeqjCT1u/mLHx26WeaPJhjIkJcSf979d Ro99T76+FxLAfAlVMWaI86vNJWBeD6GsGNdagGeBaa4ILJc4aXnNnDAX3WyFJMgCeOaU fRprctQy0GKqJuJ2p4sWDM5FyLScOYDgEMQiDQ6icqvtrbggJngnfVQ9XEzM/4X48CDA dT4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706119764; x=1706724564; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EdyPrU/kftC7g2TetwPRn8BZd+pMyQ31/waG2MZ70eg=; b=YmXh1AjzRmNSMjcPxsr2UBDmTVhOG421xrM13Yp9ZZsGDtHnDeH4EcgxKmEIgq7Hl/ 4ZqF4gT3WbjiJ3YuQ2ahQQubhgry629eRNVvCjXEda0H86QIdXkzpk8F36EdEv5+0mfk RwB7+khywY4yn/+3Dx9HXJp/USeOYfoXwtI7IFsgKi2UlZGqDgW7+83xLxHEepjUL1rw 92aMBcnWvJ0fF1kD/7yET1K9sYWuO0iS5f9HuBM3/VvagshTnLo70oaU2goHJAd6ilYp eipSFfoiCfSMjagqUbV1YdjTZPuM+UXPYpFKH7KO0q/lCiDFEixjaHsYqpEB4vb9jQFr Cidw== X-Gm-Message-State: AOJu0YxhMK2wqIItrzChZjBaOcVCqP+pmKAbGNP4LVurKaU1h513c2+z /DG3zTp7dd5F/uI97WlEmCkMQSZvHu0E/Kx2xeSmPKwh73D4iTkbRL8+ZwlE X-Google-Smtp-Source: AGHT+IGkK18t89+7YQVmHl4m0O5voMg4iJZPus7HbZc07bHDSR04jyOEsVNs5kZm+nCJmsSsbw2r8g== X-Received: by 2002:a05:6512:10c5:b0:50e:b1b1:430c with SMTP id k5-20020a05651210c500b0050eb1b1430cmr4238981lfg.116.1706119763525; Wed, 24 Jan 2024 10:09:23 -0800 (PST) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id k16-20020a05651239d000b0050eaec14596sm2656667lfu.39.2024.01.24.10.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 10:09:23 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: LKML , Baoquan He , Lorenzo Stoakes , Christoph Hellwig , Matthew Wilcox , Dave Chinner , Uladzislau Rezki , Oleksiy Avramchenko Subject: [PATCH 1/2] mm: vmalloc: Improve description of vmap node layer Date: Wed, 24 Jan 2024 19:09:19 +0100 Message-Id: <20240124180920.50725-1-urezki@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 8u5h7tswcg4w1uhxjjadd8ukww69gfjw X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BB74BC0034 X-HE-Tag: 1706119765-372518 X-HE-Meta: U2FsdGVkX19cRzu6PD3HjLYK8f1uqMbutsclFBPoLL1DDl5tQEKyV3nUqA+/8kkMqVZJ4Z2R9DjypAsBu+MR6e3uMHDBvu70WrHpPTdBHMmDwrSfpC+qRvrEJGPI5HNWez0dGO/Fnrbwry3qgKonBOaUetbFnsjpW156f+mB+WH59/UMi1Rhw+VUPplSo6hFhZQMI8vnZtVCu+/oOEqJ+glZdFoTwrbdT95QGNTi1xYSm7Qb5b142K3qTQJi9z/zXauOdc945btyvynjzv7p3Pw7NNZuibm3eirm3x2no5KISwwqKrEZIcTksT240G3UL8JxR5JREdCflNhdH4B/bDK5lKnqbNVVIglon5MGMDSLEHSnWNazram9UGZDOgCP8aO7m1oVbKPQ6zcPkTTus3QzQnxOShKaly3vxuOdOiANqn+KR++nFe9R9oyPM8RguF6npoJR0/gWSRPnEEc2A34SFzPdpICuY9Q1yLlwuGi5JIzks+E/Yp9VKDqHOSj+2V1YG0ooBJdwlT3Fufr6IU0CobYteoU4r119TA59HqA/QC97gVEp1u8Kyxdv4S57y34pBPrOGTCLWIN3++F/fFMg9Ut5woNBSDH1udsS9Oo1IKsvDNtPtujwO3LK/3hPRNKRW7RBUP1oyHpnD9jFUbvlbCWqyWz2nJVbLxwpiFsfyCWAQ/P1a2c5P+AZMUFd+rlp9logSSHsdJ0LPjzBkeqsKF9h0RpVa9SVd3eXlylWl4yILSkiKkdHYXXUWIGJbdtkR6NR20PGUAL/V+yHPk9ITAAVhvtrZ4/g7JNc69lceHOSUNi6Nv7d6dWMWDx2sN8OUVSTzEsvPksei4NOPKEZjRoeEVHEc/x3Ugq6LHG8fFJwbai7D+6YiIqaT3Fn/Ih1NnhMkHdt7gqRo2aL7TohtVIKWq8m5wavx/QH0tXgO5ln3lgAyp5YWM4okbmilSmrBief4gqAuElebiI CtMEmAGN ccBYlw6vEUMNimrgykVsU2MZYwxZOR6NTQY6m1rEPsP4orsXMd/r01nnMC0sXPQZDPac1x7OegkvjWkXGov8l0OAC8ccAE1i+Th6B5HJiUF/k/z2Ry5cfG8rwkeYYEseg4r3puoTfPmGxvl+RdoxEvLVeGIwS/pq6mOtjRmqWAD2Ss/yRB+d5UWMnz4ogAkyKKYcrMeFCs7QcjA7R0UnRpHJ7gxvM/9OVD3wcyEELTVlSiZ7JydcekfJK75Z1DbM1lutf3JvGnoeS+2nDolO971t1EJZyYWqCugW+aWys0WuvnbfuCS/QgWMJV4NnUyXcBTA8mlTcQL1TGrPyK828c/KZXa0wAFjHAVMBLit3lRmLGmq1ahY4yKylPYyYPYNZ8pmakbZcTBTn/zunGU2GIFFwXbyfsHa2b//yyY6wZOKRLAkNFnmN68tk97UUuV8iKnRy 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: List-Subscribe: List-Unsubscribe: This patch adds extra explanation of recently added vmap node layer based on community feedback. No functional change. Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Lorenzo Stoakes --- mm/vmalloc.c | 60 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 257981e37936..b8be601b056d 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -765,9 +765,10 @@ static struct rb_root free_vmap_area_root = RB_ROOT; static DEFINE_PER_CPU(struct vmap_area *, ne_fit_preload_node); /* - * An effective vmap-node logic. Users make use of nodes instead - * of a global heap. It allows to balance an access and mitigate - * contention. + * This structure defines a single, solid model where a list and + * rb-tree are part of one entity protected by the lock. Nodes are + * sorted in ascending order, thus for O(1) access to left/right + * neighbors a list is used as well as for sequential traversal. */ struct rb_list { struct rb_root root; @@ -775,16 +776,23 @@ struct rb_list { spinlock_t lock; }; +/* + * A fast size storage contains VAs up to 1M size. A pool consists + * of linked between each other ready to go VAs of certain sizes. + * An index in the pool-array corresponds to number of pages + 1. + */ +#define MAX_VA_SIZE_PAGES 256 + struct vmap_pool { struct list_head head; unsigned long len; }; /* - * A fast size storage contains VAs up to 1M size. + * An effective vmap-node logic. Users make use of nodes instead + * of a global heap. It allows to balance an access and mitigate + * contention. */ -#define MAX_VA_SIZE_PAGES 256 - static struct vmap_node { /* Simple size segregated storage. */ struct vmap_pool pool[MAX_VA_SIZE_PAGES]; @@ -803,6 +811,11 @@ static struct vmap_node { unsigned long nr_purged; } single; +/* + * Initial setup consists of one single node, i.e. a balancing + * is fully disabled. Later on, after vmap is initialized these + * parameters are updated based on a system capacity. + */ static struct vmap_node *vmap_nodes = &single; static __read_mostly unsigned int nr_vmap_nodes = 1; static __read_mostly unsigned int vmap_zone_size = 1; @@ -2048,7 +2061,12 @@ decay_va_pool_node(struct vmap_node *vn, bool full_decay) } } - /* Attach the pool back if it has been partly decayed. */ + /* + * Attach the pool back if it has been partly decayed. + * Please note, it is supposed that nobody(other contexts) + * can populate the pool therefore a simple list replace + * operation takes place here. + */ if (!full_decay && !list_empty(&tmp_list)) { spin_lock(&vn->pool_lock); list_replace_init(&tmp_list, &vn->pool[i].head); @@ -2257,16 +2275,14 @@ struct vmap_area *find_vmap_area(unsigned long addr) * An addr_to_node_id(addr) converts an address to a node index * where a VA is located. If VA spans several zones and passed * addr is not the same as va->va_start, what is not common, we - * may need to scan an extra nodes. See an example: + * may need to scan extra nodes. See an example: * - * <--va--> + * <----va----> * -|-----|-----|-----|-----|- * 1 2 0 1 * - * VA resides in node 1 whereas it spans 1 and 2. If passed - * addr is within a second node we should do extra work. We - * should mention that it is rare and is a corner case from - * the other hand it has to be covered. + * VA resides in node 1 whereas it spans 1, 2 an 0. If passed + * addr is within 2 or 0 nodes we should do extra work. */ i = j = addr_to_node_id(addr); do { @@ -2289,6 +2305,9 @@ static struct vmap_area *find_unlink_vmap_area(unsigned long addr) struct vmap_area *va; int i, j; + /* + * Check the comment in the find_vmap_area() about the loop. + */ i = j = addr_to_node_id(addr); do { vn = &vmap_nodes[i]; @@ -4882,7 +4901,20 @@ static void vmap_init_nodes(void) int i, n; #if BITS_PER_LONG == 64 - /* A high threshold of max nodes is fixed and bound to 128. */ + /* + * A high threshold of max nodes is fixed and bound to 128, + * thus a scale factor is 1 for systems where number of cores + * are less or equal to specified threshold. + * + * As for NUMA-aware notes. For bigger systems, for example + * NUMA with multi-sockets, where we can end-up with thousands + * of cores in total, a "sub-numa-clustering" should be added. + * + * In this case a NUMA domain is considered as a single entity + * with dedicated sub-nodes in it which describe one group or + * set of cores. Therefore a per-domain purging is supposed to + * be added as well as a per-domain balancing. + */ n = clamp_t(unsigned int, num_possible_cpus(), 1, 128); if (n > 1) { From patchwork Wed Jan 24 18:09:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 13529522 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 C7A62C48260 for ; Wed, 24 Jan 2024 18:09:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84F9D8D000A; Wed, 24 Jan 2024 13:09:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FE878D0001; Wed, 24 Jan 2024 13:09:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C6AC8D000A; Wed, 24 Jan 2024 13:09:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5C1478D0001 for ; Wed, 24 Jan 2024 13:09:28 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2B281140418 for ; Wed, 24 Jan 2024 18:09:28 +0000 (UTC) X-FDA: 81714992016.12.30BADAC Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by imf13.hostedemail.com (Postfix) with ESMTP id 21BE720024 for ; Wed, 24 Jan 2024 18:09:25 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Hp/EjpjW"; spf=pass (imf13.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.50 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706119766; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NTk+QOHhuV0ddu1f13MxSI+SyTG7OrguLkgzhrD1Zbc=; b=lF/oI1nrdMl8UzzWjPz5FFHdYFlbcsqR2hD1URHQHDq5RMpGzneBYD8RuKg03L915Sl3A/ vjc3XzgRbOZJfiOtySW0PDiSbxVdAkc+AZxskOIouEIdVNAOsuKDjHQ0Q849+b5Zpu/MyD TpDYxMfTUX8LGicJQPW4YQiZbaBHzwU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706119766; a=rsa-sha256; cv=none; b=M/UWOIX5oeoENO3MBlFEjFUP9yD+DFwMJ7gqx8F+SyACkn4PbIYtMNbkYJumJt3GrWCR/U siJ221FhSJmafFqU5vRLx1E11o60Wye+4czLCvp49Uj2aFcU7gfNP9DvrLqkIRKN9uR/G3 GvOma17G24m690tULQo1XdzQYO2hgj8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Hp/EjpjW"; spf=pass (imf13.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.50 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-50e7d6565b5so7275432e87.0 for ; Wed, 24 Jan 2024 10:09:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706119764; x=1706724564; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NTk+QOHhuV0ddu1f13MxSI+SyTG7OrguLkgzhrD1Zbc=; b=Hp/EjpjWFZw+Lb6idXYW/37ycLJLpGsBgTXSnRVnrSnGUCKul9eIOOLc1VEWfph0iK 5WWoU2hBBf2XB3xdqG34KC+b6S9nta3OhjuWdMlSeKl5cZPPm4fyqmu5EbEttKdFCjmy 1kUQA48+MunxlHA1tGT6c3Q7pPCFu3pgcnxYQRM2H4zCD64wPPBEfAPncwtBrzVXxnga UcH70CwOLlHoGEDQzPQUB9ob2ky2einxtCyBJSa6/1ffXNacHkEmtOX+Y1rFTG+l37RT 2FptcP+I/p35ImJmV9G7tb3uEOChm5s08xgSuVcCYp8hbd6pj+dodJwFsLu41VAvnbFp xR4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706119764; x=1706724564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NTk+QOHhuV0ddu1f13MxSI+SyTG7OrguLkgzhrD1Zbc=; b=w22bfliJog1gEg3oZ7vlWKRXFgwD13W1WZiZcxjdaNM55HobLHsYNioIJUbZRmOQOf mkxF3BZ7I+Vg+UFUa4DvoY/Shc0oWHTXvagva/hhBZk4WGMrH2fP0DS8MjdUc6vAtH1x kxDTQrEfkdUvVtFAXGlWXXS90to52dZKWnfKyJHurFUhtYisW/zSRRpV6hI0Yq8NDWPm DQKGYtIoRAlmLVp8pwIjNKt/nxM2nEJ4/9EmusZ36EyAf4GlswmIAvrplZ6XOZzzcIHd +a1fvgtshKxbFnai5D+x9C23ZCMpa1ZWo9uqPw7QkpM6UOPnzsKuW2szemptbn92vqqn xPJw== X-Gm-Message-State: AOJu0YyBuxM9YpA9uLOPy2BWfkNWP6YOFGOGr8XX3bIkw+yBZVUJACMZ 1bKyRNr/Ry1ogxmjZGYJtzJA2TXfHiq+f1seM4DvzxgW7gterJ/19scJuz5E X-Google-Smtp-Source: AGHT+IGHrDb2JJILi44pZF1bRFKMJXwjxb22K3MOoBAwdNnQSWTxUg4T9nOIRqxBVMxOQ1FEBZ0Gag== X-Received: by 2002:a05:6512:3991:b0:50e:b3bb:1292 with SMTP id j17-20020a056512399100b0050eb3bb1292mr4221934lfu.74.1706119764350; Wed, 24 Jan 2024 10:09:24 -0800 (PST) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id k16-20020a05651239d000b0050eaec14596sm2656667lfu.39.2024.01.24.10.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 10:09:24 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: LKML , Baoquan He , Lorenzo Stoakes , Christoph Hellwig , Matthew Wilcox , Dave Chinner , Uladzislau Rezki , Oleksiy Avramchenko Subject: [PATCH 2/2] mm: vmalloc: Refactor vmalloc_dump_obj() function Date: Wed, 24 Jan 2024 19:09:20 +0100 Message-Id: <20240124180920.50725-2-urezki@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240124180920.50725-1-urezki@gmail.com> References: <20240124180920.50725-1-urezki@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 21BE720024 X-Rspam-User: X-Stat-Signature: xbhe5z9rmmuy7pzxc9ihbyd1fs1wtw7g X-Rspamd-Server: rspam03 X-HE-Tag: 1706119765-52767 X-HE-Meta: U2FsdGVkX18BcKqCXaGHpAmKRB8pyNlKrrLYIJNV0xghyEE/x2K9yNE56QIg4aGbdF/Lvr+rRIBcefuo4DM5RHf34TSm+GvA/UvpNk7XNmK0J69Yc7czB8R4treUwgLbO3V2Np2j3gRnqLpojI2K3lDnzdAmmoehhwWhAhch1JQEuFRNrcZF7yVbSj0ggE0POp+Z/LD4jt9P4vwolK2pGKKMYjbs6cXISXHtVpy0lgV7iB9LtIefG2REqHO55nF6lP+rPqpJhyhJT21OisiiE/AMtfsaCckK4l//cNM6tSsX/A3gCvLH1Ul/xF0BzK4QgY8QI+SnKucRTNeoV8kwET8uPn5Tf2R7hwkV5S0N5B8s4jNRkesvNtg7usJiMQBk2pIYFfgbjjY+PCEwaXWUhT9NlLzS5//RLHMQTVlMkfNRtz8hA0pU07SB0gg81GsNBqtCEz5t5nocQHPI1KK0uywBkcfgYaL1nYE369G9voumTYborLTH7gSYNHXimis6QeU2WC/5EpRt5pSAb/7IZ6Dyz/HninjtXY8c/sXrOLGD37nQOXYctCOmUPyP9PUoogYYC8MVSbnOQLlC+/P4cVGM+ORTRFqcBT3qHQnjXalVDu3DfiPlxXHqGtN86oNjDFzh43FTPaFAeGqLk4dFB22awDvAfgWo5mcf4PFS9ZKGe05WGU4cj1uz46xAofi2GMjQurVkjnLJj6A0L4E9WrmBIa63Irska7+C057bCuPWL8ZdkxObHOFAQAbfus0KBGl3uHiQMCIHfhyUvziEClqUs5raVQaJ/XU8oTa1DAaAN+kgSAAAT8QYWLxLuWwlr5gfI2BsNLEdlrJ4W+QddoQ9NwyrGgKtQAfwXQCR4bY69awiIuiROuAzi+OFrl1Yq2srYRfFnuiQYpvRwp+7XQWxTa85jGOBrIUFfPEAAeLjyZzSCfl5WyW5woPBORvtE0v1GR0BLVg+f3M2+Gw O+asdi0D yQ3v/luf+ASaP9SZ5i6a0FhEu5INzAeREq8RNYg8trgEcyzefAHpXp5ixDyhc0A7dm205nQ0ugbzUFsefJU2bXCajcM4lxryaXUKkY76w6GgILXFZiLvhEeQ0PKNRQeTFMYn8qBntgFqj8o406ot9JJPD372Hzxy5Ektt0XQy428cbRwKvcnUXZThwU3dfKG8Xw3BYqShN7DD/7BIhqgW3bsYIXA5Ad3oz1C64Tb4h/0gNkQv6aK2ZBLF6iYlWAiVne3B729do1aY74BJ5D12AAJuzP2WaXo1PJxXpH+UPdgDMk7Ca/uEmNJkcuQjPJp//ieHBVlMREZpO8JBPAIopvd66w9272sAa5XMJ1eYSrp3/VMRSf9x38B4+y93YaMrdIayRcFiNOfvw/Yx5ax4XxQaxOA1Z7+JNK8fAeuZg1MjDsPHl0CPYzhd1aB0GHZ4v5wgi8vUyYAlZrz/qAjks+W7+KUHQNWzgcW3fk4XB9BEtJU= 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: List-Subscribe: List-Unsubscribe: This patch tends to simplify the function in question, by removing an extra stack "objp" variable, returning back to an early exit approach if spin_trylock() fails or VA was not found. Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Lorenzo Stoakes --- mm/vmalloc.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index b8be601b056d..449f45b0e474 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4696,34 +4696,35 @@ void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) #ifdef CONFIG_PRINTK bool vmalloc_dump_obj(void *object) { - void *objp = (void *)PAGE_ALIGN((unsigned long)object); const void *caller; + struct vm_struct *vm; struct vmap_area *va; struct vmap_node *vn; unsigned long addr; unsigned int nr_pages; - bool success = false; - - vn = addr_to_node((unsigned long)objp); - if (spin_trylock(&vn->busy.lock)) { - va = __find_vmap_area((unsigned long)objp, &vn->busy.root); + addr = PAGE_ALIGN((unsigned long) object); + vn = addr_to_node(addr); - if (va && va->vm) { - addr = (unsigned long)va->vm->addr; - caller = va->vm->caller; - nr_pages = va->vm->nr_pages; - success = true; - } + if (!spin_trylock(&vn->busy.lock)) + return false; + va = __find_vmap_area(addr, &vn->busy.root); + if (!va || !va->vm) { spin_unlock(&vn->busy.lock); + return false; } - if (success) - pr_cont(" %u-page vmalloc region starting at %#lx allocated at %pS\n", - nr_pages, addr, caller); + vm = va->vm; + addr = (unsigned long) vm->addr; + caller = vm->caller; + nr_pages = vm->nr_pages; + spin_unlock(&vn->busy.lock); - return success; + pr_cont(" %u-page vmalloc region starting at %#lx allocated at %pS\n", + nr_pages, addr, caller); + + return true; } #endif