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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 4C9B2C48BCF for ; Sun, 13 Jun 2021 15:15:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C1B761354 for ; Sun, 13 Jun 2021 15:15:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231915AbhFMPRc (ORCPT ); Sun, 13 Jun 2021 11:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231782AbhFMPRc (ORCPT ); Sun, 13 Jun 2021 11:17:32 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7893C061574; Sun, 13 Jun 2021 08:15:30 -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=v98zU0j/C6eV6H036hdUoeCGabSgBkr+f3noxRgGg0w=; b=jkiVo7PoDoav/f/Yu12SWrXrPO K2LfqUn41R17NKRPAe9Ce4z3jncIm2SaRlYt0R0Rbn9TzMa+caKUS3fTbz7WVoU5GXXqoI9T8NOxo ZA+259/CVDbq/nczC4MkMwa4OZBgSG49/KQRj3KxgoKo1d2C0UIDzET4ZEqJwB8gGxJsSTsqm1q0M 0Gcg+ym9OnioCBhRTTWgmRjy//rz2gq+Fn3ZrA7f/RnyaVaSUbHPIVQT3a0fJin0slPJTMPWSa7o0 zrMcRsm0aNb7JlwKlKlXW2hMKacpOnSMk+ayUMvXv52uhQmQuQ+5vMY/SS1qhTI2/tsKvjFqQNkHE z3cZTxIQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lsRpJ-004bY9-Px; Sun, 13 Jun 2021 15:15:10 +0000 Date: Sun, 13 Jun 2021 16:15:05 +0100 From: Matthew Wilcox To: Jeff Layton Cc: ceph-devel@vger.kernel.org, linux-cachefs@redhat.com, pfmeec@rit.edu, dhowells@redhat.com, idryomov@gmail.com, stable@vger.kernel.org, Andrew W Elble Subject: Re: [PATCH v4] ceph: fix write_begin optimization when write is beyond EOF Message-ID: References: <20210613113650.8672-1-jlayton@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org On Sun, Jun 13, 2021 at 08:02:12AM -0400, Jeff Layton wrote: > > + /* clamp length to end of the current page */ > > + if (len > PAGE_SIZE) > > + len = PAGE_SIZE - offset; > > Actually, I think this should be: > > len = min(len, PAGE_SIZE - offset); > > Otherwise, len could still go beyond the end of the page. I don't understand why you want to clamp length instead of just coping with len being > PAGE_SIZE. > > + > > + /* full page write */ > > + if (offset == 0 && len == PAGE_SIZE) > > + goto zero_out; That becomes >=. > > + /* zero-length file */ > > + if (i_size == 0) > > + goto zero_out; > > + > > + /* position beyond last page in the file */ > > + if (index > ((i_size - 1) / PAGE_SIZE)) > > + goto zero_out; > > + > > + /* write that covers the the page from start to EOF or beyond it */ > > + if (offset == 0 && (pos + len) >= i_size) > > + goto zero_out; That doesn't need any change. > > + return false; > > +zero_out: > > + zero_user_segments(page, 0, offset, offset + len, PAGE_SIZE); That also doesn't need any change.