Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp993346rdb; Fri, 16 Feb 2024 01:47:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXwijTIl1+HOEZ1PMqjcdFxDL5gzMHUca0r5mOS6h0P9p1rPYqL9o/mqD3ynSefItkGPxsV0t6yE4mq9M4lN/0MP+9v0v0FYSTiYVz7jw== X-Google-Smtp-Source: AGHT+IEBk4xCmSmg1fMVy/fwqwJZZxz4HzgzIHzYgZCae0S1CUP1hPtbN+t7PMDYpylo/j3vXW0X X-Received: by 2002:a17:902:ba94:b0:1d9:c367:205d with SMTP id k20-20020a170902ba9400b001d9c367205dmr3876729pls.53.1708076834493; Fri, 16 Feb 2024 01:47:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708076834; cv=pass; d=google.com; s=arc-20160816; b=iksBVp2Rj38URP0cyZ8ajid8fkc8sdK9BaAHF24zggIB8ckng4GiD6XzamqguYAzzG oZ2JU7ZiwfX3Vi9a6FEo1w6DGUQnXctycopZlb+3+NNLa1uHvnGewAQ1Om1Xh+0X2WK6 wImJq78ZMQm5b76LQCtawZ3FLh4YJgVP7ko6bbQMFYF1myFUdbJG/57SaZSNpLn3M4XB wHTWGrqeBkDs4Lhn8VOcn+ZDnbhx2cVnZlIZFFU26ue9jcJfw0pwaMpC9nor6eKU5OEB TzkHkVsR2P1gh7FLNJd0vyzEATkZ0F7rsTIsVgXuMtrMUEG47xmgV1MgTneTyuM3W342 luEA== 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; bh=bCgbvj1AZnKSg1pxMttRlFR5amX0BqXMrzHfMsSVV30=; fh=HExTucq0dOYcX9UcJK5hZZIaOHOivzTqptKgetBoMjU=; b=BPzc8ei0SVLMOe+2QfuHZwEQZ4anBvPkaUVRCgAAQCjvcKlEU79gko35gpe1bg58e5 yw+WabBNKjqh2BySMeA8z76AWWojmdc+6WmgVdGNmwU50fOzI+eKgRm01oj9sMvb+JF8 DZ8zaD9oBYHrKAzpV0k+N3BQA83M3uFejzkdAXHbJQokR6aOK4Z1Bg4EEN1VBWLixbHv JS7ZygUxxns58PwN6bCs3zCHrfVzFwCt4ECcCNXcKYr88OL29Y0g78e4XlAt263aW6ts N287bNla/hTqdc7LkBZc3hwFhYTYB4wfQKy9J4hs1LwQ0qUtdbsDh0bsX5w9AOKtTJg8 c52A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68348-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a4-20020a170902ecc400b001d720af9a66si2739563plh.366.2024.02.16.01.47.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 01:47:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68348-linux.lists.archive=gmail.com@vger.kernel.org" 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 85FF3B24096 for ; Fri, 16 Feb 2024 09:42:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E32AA1C29B; Fri, 16 Feb 2024 09:42:21 +0000 (UTC) Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 B16EE1BC3C; Fri, 16 Feb 2024 09:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708076541; cv=none; b=TFBz6ttQKvdfXgfst7tVBc9ozBVdEs+h2ZdaDSM756MltyG/3KhnK2G7kCWwgLqxtCNBw2xAnd8og3hqAzrhBkZQfdPBGjw99+hXIGxrfgz0NH0v0cd07vHz9pse0SV/+wsWEFsX6W19lfcNr+WcprdFIe67DK+aABr4eW8WsW4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708076541; c=relaxed/simple; bh=Q+JVFdprvh+ju0dZQZEF5lrVykjwRilx+UVW9MwZJ48=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=hsS2SPHJyRIVuW9lRr64OmKgAFnO+BjhvSiASrYhQfymQWeNrEvnnEeUS8QOVRBjTAHEnn0WKFvPpGJghQLbmwHgIL76upu5OPEhdfIY7LIxsDCtLpav1EPmvQsmdum+PyP5tmgb0A8mK1mCjA0hTlLS7XVUBOUbsyUY3EBAYzA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-55ee686b5d5so639608a12.0; Fri, 16 Feb 2024 01:42:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708076537; x=1708681337; 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=bCgbvj1AZnKSg1pxMttRlFR5amX0BqXMrzHfMsSVV30=; b=gX/FcqYOxsXDz1tnbMkKEv8bOtfpkWDKWLhIGFBNyUcOMfSOc1hNyqsVqK/KcL8JRi 0k+4+nT3gPyk5vdFBLsvbifnIMq2cwq/sJ0BPiPOMHJYKpVa1e2svx76A9oi9LgQcklB aTAmuD5Wj0RlXYJ+i6cVgwayYp3JxXhBhDkCGNEoIqloSU34fNQl5EAUfPeFu0UtmpL/ 6GvssS+h02YA25XgSHkMHRbTQcEoPuYGPMSM5xWofaewrdnj299UkEQc1jCwqc8N5nBC 49dKvrz6vy/7i44X16NL0WrXu8pNBgyV5qfCOuSBkDEFVovwXxs53R+jWYgHKJzzuF7K aWwg== X-Forwarded-Encrypted: i=1; AJvYcCWaF4JfM+5yOYgg997zwUe1f3m/F0vDU3vERYjJ4/GDriJkD4BBAi0mT/ge0jxivbHeMqzwCgiIkXR8ugOKDcc9J4bcESAedhv1fr/p X-Gm-Message-State: AOJu0YwzxJs0DqcVxiIDaMXIkzCgSEaoIUbjNtk8nYw+bjV0ca15BHmq h5g/AfvLDkTWIdFTaFnRCtTlJsWi43DA/KtkN+LJi+iwKQicrAHC13k2oeha X-Received: by 2002:a17:906:ccd9:b0:a3d:2b01:2187 with SMTP id ot25-20020a170906ccd900b00a3d2b012187mr3357841ejb.40.1708076536681; Fri, 16 Feb 2024 01:42:16 -0800 (PST) Received: from localhost (fwdproxy-lla-008.fbsv.net. [2a03:2880:30ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id ti14-20020a170907c20e00b00a3d42c54e48sm1372189ejc.153.2024.02.16.01.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 01:42:16 -0800 (PST) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, horms@kernel.org, Johannes Berg Subject: [PATCH net-next v2] net: sysfs: Do not create sysfs for non BQL device Date: Fri, 16 Feb 2024 01:41:52 -0800 Message-Id: <20240216094154.3263843-1-leitao@debian.org> X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Creation of sysfs entries is expensive, mainly for workloads that constantly creates netdev and netns often. Do not create BQL sysfs entries for devices that don't need, basically those that do not have a real queue, i.e, devices that has NETIF_F_LLTX and IFF_NO_QUEUE, such as `lo` interface. This will remove the /sys/class/net/eth0/queues/tx-X/byte_queue_limits/ directory for these devices. In the example below, eth0 has the `byte_queue_limits` directory but not `lo`. # ls /sys/class/net/lo/queues/tx-0/ traffic_class tx_maxrate tx_timeout xps_cpus xps_rxqs # ls /sys/class/net/eth0/queues/tx-0/byte_queue_limits/ hold_time inflight limit limit_max limit_min This also removes the #ifdefs, since we can also use netdev_uses_bql() to check if the config is enabled. (as suggested by Jakub). Suggested-by: Eric Dumazet Signed-off-by: Breno Leitao --- net/core/net-sysfs.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 946caefdd959..af238026ac3c 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1459,6 +1459,9 @@ static const struct attribute_group dql_group = { .name = "byte_queue_limits", .attrs = dql_attrs, }; +#else +/* Fake declaration, all the code using it should be dead */ +extern const struct attribute_group dql_group; #endif /* CONFIG_BQL */ #ifdef CONFIG_XPS @@ -1696,6 +1699,15 @@ static const struct kobj_type netdev_queue_ktype = { .get_ownership = netdev_queue_get_ownership, }; +static bool netdev_uses_bql(const struct net_device *dev) +{ + if (dev->features & NETIF_F_LLTX || + dev->priv_flags & IFF_NO_QUEUE) + return false; + + return IS_ENABLED(CONFIG_BQL); +} + static int netdev_queue_add_kobject(struct net_device *dev, int index) { struct netdev_queue *queue = dev->_tx + index; @@ -1713,11 +1725,11 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index) if (error) goto err; -#ifdef CONFIG_BQL - error = sysfs_create_group(kobj, &dql_group); - if (error) - goto err; -#endif + if (netdev_uses_bql(dev)) { + error = sysfs_create_group(kobj, &dql_group); + if (error) + goto err; + } kobject_uevent(kobj, KOBJ_ADD); return 0; @@ -1738,9 +1750,9 @@ static int tx_queue_change_owner(struct net_device *ndev, int index, if (error) return error; -#ifdef CONFIG_BQL - error = sysfs_group_change_owner(kobj, &dql_group, kuid, kgid); -#endif + if (netdev_uses_bql(ndev)) + error = sysfs_group_change_owner(kobj, &dql_group, kuid, kgid); + return error; } #endif /* CONFIG_SYSFS */ @@ -1772,9 +1784,10 @@ netdev_queue_update_kobjects(struct net_device *dev, int old_num, int new_num) if (!refcount_read(&dev_net(dev)->ns.count)) queue->kobj.uevent_suppress = 1; -#ifdef CONFIG_BQL - sysfs_remove_group(&queue->kobj, &dql_group); -#endif + + if (netdev_uses_bql(dev)) + sysfs_remove_group(&queue->kobj, &dql_group); + kobject_put(&queue->kobj); } -- 2.39.3