From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54BB9C433E6 for ; Tue, 12 Jan 2021 21:37:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1BEB2311F for ; Tue, 12 Jan 2021 21:37:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405961AbhALVgt (ORCPT ); Tue, 12 Jan 2021 16:36:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:34186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436695AbhALULV (ORCPT ); Tue, 12 Jan 2021 15:11:21 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8106022B4B; Tue, 12 Jan 2021 20:10:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610482241; bh=ZTt+6woZSonBj4+dQImSe3XHLhl9qf3tp0jA5qezGhQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=SpWkND1pPV6dgizIJoCrMV4DPz5VVyBR7uM5ztL1EyRDEiI7c3jvxkwmxAv+vPlTc BFEbc0p5m+YYqWJ2Mql+7Ky7rLDTqXC+qBBPoHhrhriXR1Mpn1D/jLbk2tK2IDFPkt lNu4bYnIiuf1MZn1pZJZRJsc2v/2YkJr8CBi9QDVOcwq/05lzP3UHKbHvTXqSPcNbl zXuZBLn32C16rRU+uKYLrUOy1g2g4Iey4ly4PMh34P0UTfE2KKvP84cqpnLLy4akkU 7SUr4SfwT0vkfgeptSXdLjRtrIEmYIHLvdwbOaxb0HerOEyuTzlhx5M8Q2CLvGaWG7 /S8lP4tmgvoOg== Message-ID: <4c4c08e37aeff87f0dd2ea52037c32d07d2868d1.camel@kernel.org> Subject: Re: [PATCH v6 net-next 14/15] net: bonding: ensure .ndo_get_stats64 can sleep From: Saeed Mahameed To: Vladimir Oltean Cc: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org, Andrew Lunn , Florian Fainelli , Cong Wang , Stephen Hemminger , Eric Dumazet , George McCollister , Oleksij Rempel , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Arnd Bergmann , Taehee Yoo , Jiri Pirko , Florian Westphal , Nikolay Aleksandrov , Pravin B Shelar , Sridhar Samudrala Date: Tue, 12 Jan 2021 12:10:38 -0800 In-Reply-To: <20210112143710.nxpxnlcojhvqipw7@skbuf> References: <20210109172624.2028156-1-olteanv@gmail.com> <20210109172624.2028156-15-olteanv@gmail.com> <20210112143710.nxpxnlcojhvqipw7@skbuf> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, 2021-01-12 at 16:37 +0200, Vladimir Oltean wrote: > On Mon, Jan 11, 2021 at 03:38:49PM -0800, Saeed Mahameed wrote: > > GFP_ATOMIC is a little bit aggressive especially when user daemons > > are > > periodically reading stats. This can be avoided. > > > > You can pre-allocate with GFP_KERNEL an array with an "approximate" > > size. > > then fill the array up with whatever slaves the the bond has at > > that > > moment, num_of_slaves can be less, equal or more than the array > > you > > just allocated but we shouldn't care .. > > > > something like: > > rcu_read_lock() > > nslaves = bond_get_num_slaves(); > > rcu_read_unlock() > > sarray = kcalloc(nslaves, sizeof(struct bonding_slave_dev), > > GFP_KERNEL); > > rcu_read_lock(); > > bond_fill_slaves_array(bond, sarray); // also do: dev_hold() > > rcu_read_unlock(); > > > > > > bond_get_slaves_array_stats(sarray); > > > > bond_put_slaves_array(sarray); > > I don't know what to say about acquiring RCU read lock twice and > traversing the list of interfaces three or four times. You can optimize this by tracking #num_slaves. > On the other hand, what's the worst that can happen if the GFP_ATOMIC > memory allocation fails. It's not like there is any data loss. > User space will retry when there is less memory pressure. Anyway Up to you, i just don't like it when we use GFP_ATOMIC when it can be avoided, especially for periodic jobs, like stats polling..