Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5072997ybv; Mon, 17 Feb 2020 11:40:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwpSTcuUocoOkHAvLYUAf1frq9+RfoGZ6ZrmgAx/4iulLyBcLbbn3hI9Y1SSJV4gBDajzSq X-Received: by 2002:aca:5844:: with SMTP id m65mr394014oib.136.1581968431708; Mon, 17 Feb 2020 11:40:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581968431; cv=none; d=google.com; s=arc-20160816; b=bQHnsmWkbK08RIg+Qrm94816FmZ1zF/4TbhKt6uzpvhEk+rGQdJRBFM1AGaAXY+gyy otb3jBLJ+0/2rE3jFD19/n+bK6l+/PbqN+jrOBE56m9KLPJ9js47OTEhWSMMNhYerOn7 8y8GNYNBToVJ7qE7RSKvjE1fyLa1u8TVFu+de7fMQIQNGn2ECiSREwmy6JSF1XVK80Rm j+B/qFFqrXuJCSyCb2GI0NDEHMdnQB2Gj4+EVOWSGZZ6GRUPNxR2rRgzAxuihErnl5g+ pX6iB1hZCRKRr8B2Voa8qQL98vhhDcBP428kcHphWOFOp3tbWKP/Eawuo5elSQFmWlev JXGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=SKkyzb5cfak3borDNSeEJWU8QHnqn3f+eFUXleon1Hk=; b=RF1UBuuDGPxvM7Lld5E8ukp0kFZeCgZpTsKfI0ZK4B9sbVo7m/VUEW0qOBuEuV8u17 t5KETYFVYZhQNUw+oyWRvGtn/aXhNU8nCmNwnp3Nq0uc+d9drW82rX/4SuWiX+w3kQ6i F8Qs8zDgpsdymEKFsgo4gmF2HTQWDniXIhM12OMocZxdR6nMmcsUbUznQ3Ik7MJOfW34 o6jPU/18+h/u4y0r461Tc1bVvmgKLBxfj6bYErZbBmXYddLf967Jf3c5uypePBzVJQVP GooXTIjsSXQCKaunGq1dOg6CxpxxNjt4AkMGikWm2X8iXWEyGP4nB+mOyYFu39doWgrI nddg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6si610017otk.171.2020.02.17.11.40.13; Mon, 17 Feb 2020 11:40:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728589AbgBQTdc (ORCPT + 99 others); Mon, 17 Feb 2020 14:33:32 -0500 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:58953 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726781AbgBQTdc (ORCPT ); Mon, 17 Feb 2020 14:33:32 -0500 Received: from callcc.thunk.org (75-104-88-254.mobility.exede.net [75.104.88.254] (may be forged)) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 01HJXG2Q007801 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Feb 2020 14:33:23 -0500 Received: by callcc.thunk.org (Postfix, from userid 15806) id 9E1AD4211EF; Mon, 17 Feb 2020 14:33:14 -0500 (EST) Date: Mon, 17 Feb 2020 14:33:14 -0500 From: "Theodore Y. Ts'o" To: Uladzislau Rezki Cc: "Paul E. McKenney" , Joel Fernandes , Ext4 Developers List , Suraj Jitindar Singh Subject: Re: [PATCH RFC] ext4: fix potential race between online resizing and write operations Message-ID: <20200217193314.GA12604@mit.edu> References: <20200215233817.GA670792@mit.edu> <20200216121246.GG2935@paulmck-ThinkPad-P72> <20200217160827.GA5685@pc636> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200217160827.GA5685@pc636> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Mon, Feb 17, 2020 at 05:08:27PM +0100, Uladzislau Rezki wrote: > Hello, Joel, Paul, Ted. > > > > > Good point! > > > > Now that kfree_rcu() is on its way to being less of a hack deeply > > entangled into the bowels of RCU, this might be fairly easy to implement. > > It might well be simply a matter of a function pointer and a kvfree_rcu() > > API. Adding Uladzislau Rezki and Joel Fernandez on CC for their thoughts. > > > I think it makes sense. For example i see there is a similar demand in > the mm/list_lru.c too. As for implementation, it will not be hard, i think. > > The easiest way is to inject kvfree() support directly into existing kfree_call_rcu() > logic(probably will need to rename that function), i.e. to free vmalloc() allocations > only in "emergency path" by just calling kvfree(). So that function in its turn will > figure out if it is _vmalloc_ address or not and trigger corresponding "free" path. The other difference between ext4_kvfree_array_rcu() and kfree_rcu() is that kfree_rcu() is a magic macro which frees a structure, which has to contain a struct rcu_head. In this case, I'm freeing a pointer to set of structures, or in another case, a set of buffer_heads, which do *not* have an rcu_head structure. > struct test_kvfree_rcu { > unsigned char array[PAGE_SIZE * 2]; > struct rcu_head rcu; > }; I suspect I'd still want to use the ext4_kfree_array_rcu(), for a couple of reasons. First of all, the array is variably sized. So we don't know how big it is. That could be fixed via something like struct test_kvfree_rcu { struct rcu_head rcu; struct test_s []; }; ... but the other issue is that we have code where we have arrays of arrays, e.g.: struct ext4_group_info ***s_group_info; which is an array of array of pointers to ext4_group_info. Trying to cram in the rcu_head makes the code more complicated --- and also, resizing file systems is something that happens often, and I don't want to optimize it by keeping rcu_head structs around all the time. This is why at least for *this* use case, it's actually better to allocate temp array just before callig call_rcu(), and if I can't allocate it due to memory pressure, we'll it's OK to use synchronize_rcu() followed by kvfree(). Cheers, - Ted