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: 191711 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1187349dyi; Wed, 24 Jan 2024 10:48:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1AHZ74bHY708BTfM6xS9oTrbi6fEl9hozPXIIKo5W6z0iTwk+tRC51ZAvkuRs15k4Kbh4 X-Received: by 2002:a17:902:8c84:b0:1d7:601f:a09b with SMTP id t4-20020a1709028c8400b001d7601fa09bmr1105344plo.89.1706122130634; Wed, 24 Jan 2024 10:48:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706122130; cv=pass; d=google.com; s=arc-20160816; b=siJCB5fCVip66FqDEG3kQu7iv7OpHn0M+RFZMQRrgeGmySegCdAPBTcj424amXGSPy LUVNGl/PvCx3PCjKrDnplMQNUfOJ2XPMuZdU3vBMFw+YwWgfu8A8qJo5rk9wyUOGRNck dwuy9i5weGTTIoJyGGgN5jFkgCALjNzrS3cmVxw8Daz+Pcg6Btnkte8H4aUB/x7w79fE veIulgMlciAwOIr2QtXOVeNucQ7n1RG6E0oQ652oENH2ivPlmFggc6XhXDM+dmMl2JGH Q4QvMYP4k1XRwLbPvURUxlOJGDoYoLP27WX6FgKy8w8rOwyByU2RrzLgFmNDVcuw/9ZO quvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=EdyPrU/kftC7g2TetwPRn8BZd+pMyQ31/waG2MZ70eg=; fh=//5dA86WBdnCv7og0in5q2yYUR5lF94gp6vKTG7Ux18=; b=hz2Oeghj53LrEM6wRHci3gOuRmYlQOma7HqvY/oJsCHzmN5KV5DjZ8q8tdagfXiQF1 n4c/9mLOg7P41TzMCXKLhvrkXQDGtEI40dBG6kgTlRfKaDiig+ysNoLSZKs7jH8gBSP5 0NRYlli1yOs7NjnH7m+O7hKZi87uYmHcdLr/jPK+cprfP28JitCLyg0sG0oPC9mS6hLg Qc+MincMyp8Y60xxCMPs7xUacjObGKyerDou0omLkQZNdJW/fBaqouH4RZ4T7ivXP37Z Dsv3Vs8pu9zmUuu34kZTq4xN72usLZ6a93jnShsFMYUST6vBK2BPSHgrsHqfj09IsdFN i/Cg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=V3AUQSOO; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37485-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37485-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q15-20020a170902eb8f00b001d6f7bf6c9fsi12464406plg.617.2024.01.24.10.48.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 10:48:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37485-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=V3AUQSOO; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37485-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37485-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 28F74B2F9BE for ; Wed, 24 Jan 2024 18:09:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D845712AACB; Wed, 24 Jan 2024 18:09:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V3AUQSOO" Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4A927765D for ; Wed, 24 Jan 2024 18:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706119767; cv=none; b=JsUqHxOGqW8lPGdMucainFZ1xuT+B+5ccRRhhZfoVUTDMzpSZhQozvDj5vYlrPKizz/OsbmIIwDwSeTpjH5WKmAIlDEsGm330JNTaBL2gXUO/uLf1I5y+winibIcxHKPm29WKrwfNfZkVzoqRob7fPOO6/GOx8o/259+nBBMIrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706119767; c=relaxed/simple; bh=ZV+YkJZfjWL//Vz4cZuqrA+67OhgqysL4TH4AfPrKGk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=e+sPN/yZU7sIn14w9YQ6X+QpSzWNOuB1sGejpnsVE6YqzFc0cT61rZa/LtSmxcBBM4RNtWzjz5YtCLH2rVzfbe/tLjV6N51SfojHzZgyf1HzFefoAe5RfCr8lyAdLBnub8mA+7ZB1iM5O1NPhcnkAsuekW3fwZ6rVjV08fa7fK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V3AUQSOO; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5100cb238bcso2573286e87.3 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=vger.kernel.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=V3AUQSOOmevtPkDIBWn7kKNUuDhYr4wXbMp/2eXHEV5s+t3SbblyYv5dX4iOUB25i8 r/Q9hhT6o7P3Os979n3ZRgOLsZVoFAGIp8rGS0zhzrjrlFweYUqwOHQkSyH6c3XKIn8k psKp8G7385JXa6YKoxGqO/8QqRVzl09nHWPa3NSfWhZfzeASnYEMnaCn2GYwv+lxdKO5 RQVdS7J7yoqGKVNLLqVDjo85QMUSlmIz9C9qtgkZ+WdOQCP/M2lVXgLwDHAbFTfBC60r vFVBjb9YPMYsv2XgfxFnC0YCC/qxXYYRDg1nplhq7HmaYHlssIz0C1iYUEETsQSaLWao ZZGA== 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=A007ypdQlzzbwSC4wFgrW/ubtYCtJH6nXp1/v3xPO75zMFZHEeJjEZiXb8uc0p5Fl7 +lHwHUCDBy3HnKIsyHn8dq9gfBrFBVcK0E0tNmfD84HBHoyrjAPNLpkvsMN2QRAh5w0D KzbAEoDTIfktEUsPB28iFxUUD/njeg2dpapDInmYZf4FrthjveGg3357SmEzL+dYU39n aAyoFuLhbCgSAbDHeWfPDdW1MdsDuRmAUMpYaTc+t8SgtOvbmNvUmMefwRrFLbB76ll/ 2CUq3mTKjuvqUXgFnqtg+NdL0WV4pl2PE7I+wM7LO/g6GdrXwAtp9AFLstht2STkQvqI 9AVg== X-Gm-Message-State: AOJu0YxDv7NjcKTwruSh/4+B7lvosG9jF1I3OS8Ldk+/F+VMbxAwsbiL 7TH7iz4j4ZiFVm2f96yIoWQLtmCnKWimv7CnlY5XUWYwWeaW9J3I 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788998719091575336 X-GMAIL-MSGID: 1788998719091575336 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: 191694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1164797dyi; Wed, 24 Jan 2024 10:09:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5HQAtKxFIPsgiMXVv3CwznD6kkfbYpMi1s/AgavDSyZKX7evFT+uSUrsu/DUuqY/674Lw X-Received: by 2002:aa7:d0c5:0:b0:559:ea16:130 with SMTP id u5-20020aa7d0c5000000b00559ea160130mr2162883edo.26.1706119797087; Wed, 24 Jan 2024 10:09:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706119797; cv=pass; d=google.com; s=arc-20160816; b=G/z4hV02BEOBXUb98EM1lAS7Ivi+bnX4nQTPv/fBVKeb58bWtIHsPQ4RLN7xcQdrTk eI25x+ObGht5foB6FppxNwzcxUi3rsYaUkJCUmfOA12qKhG/2zsDo1dqFHdQqcaLjx6L /DkmXSw2Rnvemlbrxd2MQupsVDnqb+h65qIBqHlChEl2FRlEMToXPE0d6Jz/hiyvGFAN o8tn9Was6RnnHOEqgx10QUizjsFDcA7jyP0D19s2dv4DXpgdIslBaXZi/Qw+6rGRxMop r+1eqKGQWr0DF3FPtIkKcUne1BzfYRfyUdxi2ieb6sZ0mRv9aOLg0jNKW3L7snwhw6Fa rbjA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NTk+QOHhuV0ddu1f13MxSI+SyTG7OrguLkgzhrD1Zbc=; fh=//5dA86WBdnCv7og0in5q2yYUR5lF94gp6vKTG7Ux18=; b=Wg31Ig5d9pIKeWntXG7fsj+tZtxkTjr54Jyle06X8MtZS29ZjxiDvLPpGmmY989puR o3WbkBrhzYK8PqlMf6jtUDsch9SZTvM2qefO6Opn8dzH2rREnyxonSpzmv7Q1TCmOJEU 5/p037O5b/934PufMByCIG3gasdYCh2BkzWswlrn0duefMerOFYE/o7FgS5KLsx/1qVP qsuoXNF1i6NL/CdXO4S9m5pxqyfLiJRQL+441XP4gurjBElNIZoBRRUH9bkbMi743lWz 763XgjNESdZoUrWYHMh5GF7Q4yo4vhccDxfOUb8ePVxcyzuRLGv57VysZlIy6OxhnVeG qxFw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=R65PTh7b; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37486-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37486-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f10-20020a50ee8a000000b0055a4e70e567si6266538edr.585.2024.01.24.10.09.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 10:09:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37486-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=R65PTh7b; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37486-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37486-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B07A31F23297 for ; Wed, 24 Jan 2024 18:09:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E600712AAD0; Wed, 24 Jan 2024 18:09:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R65PTh7b" Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4F6A86125 for ; Wed, 24 Jan 2024 18:09:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706119768; cv=none; b=aMn4YXgQQN6xisjRUTeFClJ592hBGHGmtSrtyhERwu6BiqNB6AzbWCTb2sOpkFZYfgOigk19kVveeb8kpqpEEEoXaKrLV5d+mmPJZkaA1DITNTtPNrrg+WWa1QFRDntoOlTB6XUVwoKF/URvM5kkdD+UzGVCuve206bdXycEYgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706119768; c=relaxed/simple; bh=zRp6RJBo9ni0fMGxg1rRNC47znJI/AG1cmoQVqhj9/0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rKfzCJoIf7mQ0pz7f5BBU88DcUagZQcOsS9T5iD5LsUC9dOSuswXi01Zq7fDpa9TqhfOO5BnZAqk3iBtoaYvJKEThxjUZpCoNRZKkyCQsqJoBMMNpwFe0/7w1+0qwA2l5HAp2osWtSZZZWb86Ez4PStxvu6p6hiS5+j63d36VhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=R65PTh7b; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-51008c86ecbso2537880e87.2 for ; Wed, 24 Jan 2024 10:09:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706119764; x=1706724564; darn=vger.kernel.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=R65PTh7bjVC6VP6AJn4Wc8SK2KPR1/xu9MAtd9JL+gnEVdHZSxCU37aQ5DnQlBgdn1 IZPontVVY0TnrgRMKE0U8BcVGNRM4K+0Ky/ej1oI5DWlDqcvfub62Q7ThLZlfv0owOmw M9zqOphIwksgeJ6+8wEgpLOq0IYyf3PrqeUizdPcoKXWt+RRoj+kcj7V/tzAz1MbwHoJ s0rvgaHSqupdstWHUOJ1goOO8yBeWwmmNJrdNSEYN96M2D7lEYN7IjzX51uX9H6yjK6V gQICfvf5hajzFJbu9lkv13hTu3/hLjoIAd/Ikw4m4SJHYWCwmp/bI/VfM3udwY8Gs17L CrDA== 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=i9IMA33q3yTpJ2TQXYfiBBkLBqKN3wo2GItDuLsIXxja8XPiuNHsawWgKZjpPm8NSm 12Uq2ltuKm+k9PUxoFwYUwENUsXwT/NYXF9TeaUhuMtdgTMtGLP3XLQeshGdTej38HzK TOZSArtX3MKrBL23gFMV9nESYPKvoaM0g8wFAPDP53vULq/zNNek2T2fARz0Nd46Oea6 7LH9wKnw237PTdvMv44HC4wUGVHzTy3UfcBaPAncZ8IbmU7V3Vikh4hu5bYEx1qCnJKc 85h0hGuUhaVWcE2CDFK2P0DrGIs4Y0n9dMuijhyBKNInwfcYw063emWAL5sUWwEdP2Em LipQ== X-Gm-Message-State: AOJu0YwSRA4Z8n+0IqkC7kfjpbAdp758IgArHCzjLERHTsJkz+2Ag1hh KRo+jXv2K7KqoozhwsroQdGWpH4nqMvdy2y5vqajPogNhxvBBu/g 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788996272052764986 X-GMAIL-MSGID: 1788996272052764986 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