Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1948959rdb; Thu, 7 Dec 2023 13:28:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsLYHEYYmS3k4AYPhKyYo+pfhYYe3wGiuWSfCoj6kIPlLpWw+WVTC86H4iydAsaSpKBbdD X-Received: by 2002:a92:c210:0:b0:35d:59a2:68f6 with SMTP id j16-20020a92c210000000b0035d59a268f6mr3483955ilo.35.1701984495513; Thu, 07 Dec 2023 13:28:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701984495; cv=none; d=google.com; s=arc-20160816; b=hcSOXTeguMWXjRvxuyUscvUQAG2s+D310zLmPAGrLLSN39lreyLFGgZjqyuMOL+yTT eeIdm4CKm3rJSEjGTaZSlSHf0DLjjwwb9NroB3y1rScTe1700MsGrsegJG5WPhmk2OUs UoyHJkX9970kBQT8kxfOC9HD7D1hJtx06JYhPB084b8mCC0fVP/9Za6szl6jQIpY/+Jh j/wWYimydnqihzbDGuWNeDWlV76pOqop/dTk5/2aqTU0Ivr8UrHumnfg1XDFTimmIRbX 3Ft7SnqOQSvFoIOi9tXoA5GPgVJRdAX0HHFPbcOATI/sT6pnnLxUIiZnGmvsL6l98yiI RUrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=C7Yf3Gyz2poDrlJ/i6bRFpW4r3T86H5wARr3qsse2RM=; fh=ib4gl95HfLmZdfX9QIMf3rTepWCH9JlNymcDKJTPhJg=; b=Q5cLJv44HeH655qKdPGytIsMJMmcj+y4e7ZTq07nnqwGOoEriCNvMsveOBkciegGbg ZhZjmWFtkN11Hpyy+6EG41AsceMktCQjt6TLpmR5dNECCcB30Yfy9OyYYuQhjJXfY61e +LHdvZ3daTGk+6Ax2AER7S6HHhXCNePWMZ22P44fI3uNkF6cNi3U2z5YF7r5nel4L7DC sk0TIhbuscQp8pPdOY/qgJni96KoBbTQ2PPFshcl2MVv2YJJqC6/7v4AKmL5LupViYeY jNZ3sdxMLky6SlO1fi6JL/PsPg4CpHD6ppsGojMnCZHkdh7k38VN9JRWtr+3V5ky7ZY1 Wt9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CWDme+1e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id o36-20020a635d64000000b005c1cc7273basi315448pgm.257.2023.12.07.13.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 13:28:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CWDme+1e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 6783A803B723; Thu, 7 Dec 2023 13:27:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235476AbjLGV0k (ORCPT + 99 others); Thu, 7 Dec 2023 16:26:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444035AbjLGVZ4 (ORCPT ); Thu, 7 Dec 2023 16:25:56 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E30183C07 for ; Thu, 7 Dec 2023 13:24:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701984261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C7Yf3Gyz2poDrlJ/i6bRFpW4r3T86H5wARr3qsse2RM=; b=CWDme+1ekjhtrVS6iDAqvMCwDF6Kp1KXMq+algqyi2q3qa+Exoi73uKQ5KSiJzzlvhnLed I+rMsMDTocM15RpZ6kmIpevS1JLWxthAaPttEToDJNXtMIjqwgGqMm7MtwIAYa/rPBPrIL fiD/IN23tOnFoW0Tw9zxHAZfO7Ft5BE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-8zEOlF5DPGemNRiwVlcCcg-1; Thu, 07 Dec 2023 16:24:17 -0500 X-MC-Unique: 8zEOlF5DPGemNRiwVlcCcg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A78C93C40B58; Thu, 7 Dec 2023 21:24:15 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1024B1C060AF; Thu, 7 Dec 2023 21:24:12 +0000 (UTC) From: David Howells To: Jeff Layton , Steve French Cc: David Howells , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Dominique Martinet , Eric Van Hensbergen , Ilya Dryomov , Christian Brauner , linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 36/59] netfs: Make netfs_skip_folio_read() take account of blocksize Date: Thu, 7 Dec 2023 21:21:43 +0000 Message-ID: <20231207212206.1379128-37-dhowells@redhat.com> In-Reply-To: <20231207212206.1379128-1-dhowells@redhat.com> References: <20231207212206.1379128-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 07 Dec 2023 13:27:31 -0800 (PST) Make netfs_skip_folio_read() take account of blocksize such as crypto blocksize. Signed-off-by: David Howells cc: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/buffered_read.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 0d47e5ea6870..8b27ef2e78ca 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -331,6 +331,7 @@ EXPORT_SYMBOL(netfs_read_folio); /* * Prepare a folio for writing without reading first + * @ctx: File context * @folio: The folio being prepared * @pos: starting position for the write * @len: length of write @@ -344,32 +345,41 @@ EXPORT_SYMBOL(netfs_read_folio); * If any of these criteria are met, then zero out the unwritten parts * of the folio and return true. Otherwise, return false. */ -static bool netfs_skip_folio_read(struct folio *folio, loff_t pos, size_t len, - bool always_fill) +static bool netfs_skip_folio_read(struct netfs_inode *ctx, struct folio *folio, + loff_t pos, size_t len, bool always_fill) { struct inode *inode = folio_inode(folio); - loff_t i_size = i_size_read(inode); + loff_t i_size = i_size_read(inode), low, high; size_t offset = offset_in_folio(folio, pos); size_t plen = folio_size(folio); + size_t min_bsize = 1UL << ctx->min_bshift; + + if (likely(min_bsize == 1)) { + low = folio_file_pos(folio); + high = low + plen; + } else { + low = round_down(pos, min_bsize); + high = round_up(pos + len, min_bsize); + } if (unlikely(always_fill)) { - if (pos - offset + len <= i_size) - return false; /* Page entirely before EOF */ + if (low < i_size) + return false; /* Some part of the block before EOF */ zero_user_segment(&folio->page, 0, plen); folio_mark_uptodate(folio); return true; } - /* Full folio write */ - if (offset == 0 && len >= plen) + /* Full page write */ + if (pos == low && high == pos + len) return true; - /* Page entirely beyond the end of the file */ - if (pos - offset >= i_size) + /* pos beyond last page in the file */ + if (low >= i_size) goto zero_out; /* Write that covers from the start of the folio to EOF or beyond */ - if (offset == 0 && (pos + len) >= i_size) + if (pos == low && (pos + len) >= i_size) goto zero_out; return false; @@ -448,7 +458,7 @@ int netfs_write_begin(struct netfs_inode *ctx, * to preload the granule. */ if (!netfs_is_cache_enabled(ctx) && - netfs_skip_folio_read(folio, pos, len, false)) { + netfs_skip_folio_read(ctx, folio, pos, len, false)) { netfs_stat(&netfs_n_rh_write_zskip); goto have_folio_no_wait; }