Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp184706pxy; Wed, 21 Apr 2021 22:57:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiGeaJX01vWOrlVceNneIy1HXaE3RShhddrC/3GGhv+Cj+O8J9dDUqknqGecHoOUDpJ40x X-Received: by 2002:a17:906:a51:: with SMTP id x17mr1570875ejf.25.1619071033315; Wed, 21 Apr 2021 22:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619071033; cv=none; d=google.com; s=arc-20160816; b=fz0HulVJGsoZYWEizI8lc4gic1zFZ6/leIE4dsSWxvMhrLiWqZhDQynqqoCBrzmRaB PBlfweAVk1EMhSXJLdfjy2mKz2jl5gn6I7jbwa2/P95DJWumADQGW21T8jXQtkRT0thv ZBI2j6D6MM2TCwitOf/V5SMwtZm4O1BJoDSIh14dnl1xRtzdutUk2KATthrGA+En4ASw MS9rulSuBM6OmtOaW9Uxfs8uYlIRCoJeJBYaL45ubXbk0OcmblKfFPfrENlnN39Cpp/y /K8RubsDQCpvJWE70+F6aU9tbl8Njoaq4PeRlLLNGI1BZXdiF3tqMzkLgGpnE3+Chkn9 9STQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=Yd2gs0ulaQk3ryBAG/T9ZY2Wi9SgLd9cQYKXihYv8FY=; b=Ki/XuxjIdeMJDbcv+hoyrp6AgFt4YikZqX4MIxpKvEA21E4NbL8mpALXjaVMXB5DOa 5oEMP1GeqwY0DlfrsiERcnvDMG4XZTL2o3p8hP5uzLmkYqs1U5X8bwxetNvoCPV9aqNr UlFyCUUU2ixmRXG/GWMhLQzRCSizhOW4sXN2YafQ01ov7YQR9z5sO0ACjHoH+ZMZgj9X ZBWR0Pno999OgR3/OiLsMnWNhYLSRDNmeoVKiwec57sXLZc8BWgz3pJpaheUaTYsPjEa afjab28DOpHPQUdLeaULdus37LMEMMw0DaBjOGMSjTCpvSRwjaZC3ddOMD4Wkbv+EdZJ xAvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qgLnNEFA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r19si1303914ejy.43.2021.04.21.22.56.50; Wed, 21 Apr 2021 22:57:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@google.com header.s=20161025 header.b=qgLnNEFA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbhDVF40 (ORCPT + 99 others); Thu, 22 Apr 2021 01:56:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbhDVF40 (ORCPT ); Thu, 22 Apr 2021 01:56:26 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE32BC06138B for ; Wed, 21 Apr 2021 22:55:51 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id i12so13741936qke.3 for ; Wed, 21 Apr 2021 22:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=Yd2gs0ulaQk3ryBAG/T9ZY2Wi9SgLd9cQYKXihYv8FY=; b=qgLnNEFAyhsCr5cTqAilhCCR88xu+Lo0ZCHkoYuo9qoV9qF5+bl0g2GDlTmSFyksax ac+CqrVtJ4ALOfyvVhbTdPiah0c0VuiBGi8wYRpGPinVYsDjJbXJE5s//i9QIYjdeYdU LM0uyBCx6cLA8P4esZfCYogttHX/0pJrFcX9MeLotQzuNT4H7z7XqntpI2jcW//5pxdq 3jWYc4yiEbbY365WjsxyBm81g2fUS35RYgRJRARaOalJlPngmh2neZzzi4sa0NUbmRUj F50jwME1yvUTFGtN9FO4UmbErfRtmFuW77Q9nsSBUeJGvk9mVMXDyipPC9PhhiGmcRu9 xEKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=Yd2gs0ulaQk3ryBAG/T9ZY2Wi9SgLd9cQYKXihYv8FY=; b=cDFhzw/kJEUTyL0bInHQIKrC0zXxLqJO2i2QbBWJ/9amc2gLFJktK7cQ/1MoiDdta5 2X0snTvacIlRklXL07YI3yoVq+6znYYx9bdxB3yg3vtznMbjX+Z4lNpy52Ezh+cRDHGb habtc/ddQJi7mpoh+yKi86nWfQErs+2b8qwJiLGWMwlkMNJf39wQ+1WdXWDLkDL12/XK 9T6dXGxdfXKEZJ+EmRe4rw2MeHeUWHN332ZFWSm8pjxxArQR+zNczSCKtNAMnFAy11w3 Yg3jLpqbsi+mR63hoT8kP4Gpagq9Zfxs4Ldnyf8gvO/KnB1RPoGt0LHFrdETZnSrlCEk a+QA== X-Gm-Message-State: AOAM533/mUoOXuTCC3+gHjwmcNTlPLmBCdJqe4uk6bDP70dY0lPDZmYW e4I9G0vur08PxvIrj0h5K/WpOQ== X-Received: by 2002:a05:620a:4143:: with SMTP id k3mr1849181qko.497.1619070950786; Wed, 21 Apr 2021 22:55:50 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id i21sm1505944qtr.94.2021.04.21.22.55.49 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Wed, 21 Apr 2021 22:55:50 -0700 (PDT) Date: Wed, 21 Apr 2021 22:55:37 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Matthew Wilcox cc: Hugh Dickins , Andrew Morton , William Kucharski , Christoph Hellwig , Jan Kara , Dave Chinner , Johannes Weiner , "Kirill A. Shutemov" , Yang Shi , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 2/2] mm/filemap: fix mapping_seek_hole_data on THP & 32-bit In-Reply-To: <20210422011631.GL3596236@casper.infradead.org> Message-ID: References: <20210422011631.GL3596236@casper.infradead.org> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 22 Apr 2021, Matthew Wilcox wrote: > On Wed, Apr 21, 2021 at 05:39:14PM -0700, Hugh Dickins wrote: > > No problem on 64-bit without huge pages, but xfstests generic/285 > > and other SEEK_HOLE/SEEK_DATA tests have regressed on huge tmpfs, > > and on 32-bit architectures, with the new mapping_seek_hole_data(). > > Several different bugs turned out to need fixing. > > > > u64 casts added to stop unfortunate sign-extension when shifting > > (and let's use shifts throughout, rather than mixed with * and /). > > That confuses me. loff_t is a signed long long, but it can't be negative > (... right?) So how does casting it to an u64 before dividing by > PAGE_SIZE help? That is a good question. Sprinkling u64s was the first thing I tried, and I'd swear that it made a good difference at the time; but perhaps that was all down to just the one on xas.xa_index << PAGE_SHIFT. Or is it possible that one of the other bugs led to a negative loff_t, and the casts got better behaviour out of that? Doubtful. What I certainly recall from yesterday was leaving out one (which?) of the casts as unnecessary, and wasting quite a bit of time until I put it back in. Did I really choose precisely the only one necessary? Taking most of them out did give me good quick runs just now: I'll go over them again and try full runs on all machines. You'll think me crazy, but yesterday's experience leaves me reluctant to change without full testing - but agree it's not good to leave ignorant magic in. > > > Use round_up() when advancing pos, to stop assuming that pos was > > already THP-aligned when advancing it by THP-size. (But I believe > > this use of round_up() assumes that any THP must be THP-aligned: > > true while tmpfs enforces that alignment, and is the only fs with > > FS_THP_SUPPORT; but might need to be generalized in the future? > > If I try to generalize it right now, I'm sure to get it wrong!) > > No generalisation needed in future. Folios must be naturally aligned > within a file. Thanks for the info: I did search around in your various patch series from last October, and failed to find a decider there: I imagined that when you started on compound pages for more efficient I/O, there would be no necessity to align them (whereas huge pmd mappings of shared files make the alignment important). Anyway, assuming natural alignment is easiest - but it's remarkable how few places need to rely on it. > > > @@ -2681,7 +2681,8 @@ loff_t mapping_seek_hole_data(struct add > > > > rcu_read_lock(); > > while ((page = find_get_entry(&xas, max, XA_PRESENT))) { > > - loff_t pos = xas.xa_index * PAGE_SIZE; > > + loff_t pos = (u64)xas.xa_index << PAGE_SHIFT; > > + unsigned int seek_size; > > I've been preferring size_t for 'number of bytes in a page' because > I'm sure somebody is going to want a page larger than 2GB in the next > ten years. Ah, there I was simply following what the author of seek_page_size() had chosen, and I think that's the right thing to do in today's tree: let's see who that author was... hmm, someone called Matthew Wilcox :)