Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3731324pxv; Mon, 26 Jul 2021 10:29:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz77HI/TacUZDoVyjYKuaSGIdWmDiVLCWFvuSQrWST5Riy7eHe3S+n/xRqYPWNcas8eAJU9 X-Received: by 2002:a17:906:3915:: with SMTP id f21mr11925720eje.178.1627320577266; Mon, 26 Jul 2021 10:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627320577; cv=none; d=google.com; s=arc-20160816; b=XmDgnHYGufPinSIRU+cobK+yz1xY50UvOH2fa0qsnu1CmzZT0G4eDMcWmUefG0RIm8 vzRAwuJtO/xUE9XU3q+7tmwoo1c8hvtUGRrihcbRRAKIGIniMfLu5h3vWLzuZJC9p+a5 kBEdgJpxAOH7p9L5xuLNobIklssdX2vUN5bA0fk3V7R4u5yqOIWnWkhK3aUsqZ291pwg qe9GcxJQG6y9xcyCqfIyezFyxWxUUpU2Y0ma+E6n56JNtMMK7gXzXsnao9Lr4Ye6fUdV raN77tgZK0pWZE100pcOiVWHTqdc17IUj/7Al1+NhPrwkRewpcTwsFZEQEvBLtZKZt/n oGzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Vqs3NN7xHX7VuOasPLpzjTGLT3AH9xa8Uq7MQmQ6U4c=; b=eXEDLp8ZlTFqgoSyAUN54sLI7TZVwUf+ZKP6g58y0TbG+MFeMKtvnleXDHaXSJmzmR pDttYk2EgDtoqVtIc2k8xCowUXeWJuoY26BOGDO/l+nNUIq/1zAnzvpH9zAaP9EiUfYB gHYK1+65r62K3bbe9tHvDzaAlAs7/C/0p5MCBxM0eLr7kVuGsxpFflIb3JgBVWBkjXZD vKx02cyNTIhV+K1huYE21BvqunpBVTwmBXdzkMZJ2NHU/oJ3iFqHWA+FGbIgxaNqFZEn kmJ7JJ/HQtK+Fx/MwVgBGJ+q13w/P1OXa0eQmYubSrEmskySLwh7kTTQUg3yVLCNNS+U eMHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=FHZjLR+N; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si557083eje.250.2021.07.26.10.29.08; Mon, 26 Jul 2021 10:29:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=FHZjLR+N; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237053AbhGZQsD (ORCPT + 99 others); Mon, 26 Jul 2021 12:48:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236125AbhGZQsA (ORCPT ); Mon, 26 Jul 2021 12:48:00 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39F19C0F26E9; Mon, 26 Jul 2021 10:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Vqs3NN7xHX7VuOasPLpzjTGLT3AH9xa8Uq7MQmQ6U4c=; b=FHZjLR+NROgvBqw4Rm7M0EuXpa Kq6UeMFn2BtIU2GMt1yXDOwsIQZHALmf+/OE6I98Khff0DHRw8lbz4cZx6pl/fT02klNbbERY4Wl9 73UDsnMBCMKydcqtpoq0Np+twUCVzutn0wWZQI/9BkedfPwQ93MnGgGoGg3D/rErUq5MwHPDXsvC6 xHMFpHwVQJg3ZVRYJxwGD6376R4w+aik2waOk0pqxN1RhLFxH8wb8tB4GqkYfawx4Ut2aFgesDBw3 rcviwx77AEEexcFpnrw6y66YYaEkaDUyP0NlaE8/MYGc7IVElytXGb805x+X6gnoa/0v6x6P+Ej9l Cx7Uu3RA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m84GP-00EExM-FX; Mon, 26 Jul 2021 17:19:47 +0000 Date: Mon, 26 Jul 2021 18:19:37 +0100 From: Matthew Wilcox To: Goldwyn Rodrigues Cc: linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-nfs@vger.kernel.org Subject: Re: [PATCH] fs: reduce pointers while using file_ra_state_init() Message-ID: References: <20210726164647.brx3l2ykwv3zz7vr@fiona> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210726164647.brx3l2ykwv3zz7vr@fiona> Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Mon, Jul 26, 2021 at 11:46:47AM -0500, Goldwyn Rodrigues wrote: > Simplification. > > file_ra_state_init() take struct address_space *, just to use inode > pointer by dereferencing from mapping->host. > > The callers also derive mapping either by file->f_mapping, or > even file->f_mapping->host->i_mapping. > > Change file_ra_state_init() to accept struct inode * to reduce pointer > dereferencing, both in the callee and the caller. > > Signed-off-by: Goldwyn Rodrigues Reviewed-by: Matthew Wilcox (Oracle) (some adjacent comments) > diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c > index 4806295116d8..c43bf9915cda 100644 > --- a/fs/btrfs/free-space-cache.c > +++ b/fs/btrfs/free-space-cache.c > @@ -351,7 +351,7 @@ static void readahead_cache(struct inode *inode) > if (!ra) > return; > > - file_ra_state_init(ra, inode->i_mapping); > + file_ra_state_init(ra, inode); > last_index = (i_size_read(inode) - 1) >> PAGE_SHIFT; > > page_cache_sync_readahead(inode->i_mapping, ra, NULL, 0, last_index); Why does btrfs allocate a file_ra_state using kmalloc instead of on the stack? > +++ b/include/linux/fs.h > @@ -3260,7 +3260,7 @@ extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out, > > > extern void > -file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping); > +file_ra_state_init(struct file_ra_state *ra, struct inode *inode); This should move to pagemap.h (and lose the extern). I'd put it near the definition of VM_READAHEAD_PAGES. > diff --git a/mm/readahead.c b/mm/readahead.c > index d589f147f4c2..3541941df5e7 100644 > --- a/mm/readahead.c > +++ b/mm/readahead.c > @@ -31,9 +31,9 @@ > * memset *ra to zero. > */ > void > -file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping) > +file_ra_state_init(struct file_ra_state *ra, struct inode *inode) > { > - ra->ra_pages = inode_to_bdi(mapping->host)->ra_pages; > + ra->ra_pages = inode_to_bdi(inode)->ra_pages; > ra->prev_pos = -1; > } > EXPORT_SYMBOL_GPL(file_ra_state_init); I'm not entirely sure why this function is out-of-line, tbh. Would it make more sense for it to be static inline in a header?