Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3985237pxb; Tue, 17 Nov 2020 08:29:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnZLjjlwwLbfOYz7Fg6YolgPoq7aqh8Zl/E+X8muvQK87weelZfr3LYgaHOONuUB98ZwM2 X-Received: by 2002:aa7:c597:: with SMTP id g23mr21438983edq.184.1605630564999; Tue, 17 Nov 2020 08:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605630564; cv=none; d=google.com; s=arc-20160816; b=lM7Euw2QfvTrAxgZ0ll6kT+pXg0EgGZkWGufKRarS6lHxzcHaGiBgBl94ZLARBJrJl Qb+YOCrkguGOnevFgoHLBl85XEUgQ/WiM6ww/pCv4yDegC87Ln7BGv09I26d2z8Bexan FIe0NFY3RtFWiMeVehthz5uU1snmT8xvgoqOzf1XuxHnUO2GrGwea/Zuwowo23G10QSd jaBMI0VuzJ75X0T/vAQnvVow5PwOyfg8VuJZNMcC5Sas9OV/HKqwxFqVc4PvT9eJ+rLV JJ5hg+mcLnj5oZOG7yc2R/zNPS2ghgbaK5GhGL5oQoQg0Yvxtwvq986SfR7ndPLUm5hD RZ3w== 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=z75qkcvTDD7D5ZVAs+uCqlqVE13UoCxrYrBW5Z0YsDk=; b=XIvDe82NbPQx96F2/ig5m4uJPpFalqC4l1trUUyULo9RfPdL2EndU2Zm0vdhkoVRuE GismN1N74ivIzoRiLtmjWoeoAoghZU+7JxDKfxnQ5U8E7ySBneqIbckRQJdFTmSzZgf8 UnJNuITQRmF8P03SmQflsLTpDnel8cTQ9/VgSLCWGjNK0/4n/N3mLM59o8AFZmgtuUFR 5YPx/GyR3Peq1mPxpfQ/z4F8SRAILT53hfFPTUDmy121mY0k5gmVVRv2HGVnVbVlsSaX 4JUmPUDmTwB1+nCRyQ1TaKD4Ftqoz2biJlGUcMjkSKvoK1wgp490EoXESiBBuo2fvFNu krDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NbWG5mav; 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 63si14409524edn.339.2020.11.17.08.29.00; Tue, 17 Nov 2020 08:29:24 -0800 (PST) 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=NbWG5mav; 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 S1727001AbgKQQ03 (ORCPT + 99 others); Tue, 17 Nov 2020 11:26:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbgKQQ03 (ORCPT ); Tue, 17 Nov 2020 11:26:29 -0500 Received: from mail-oo1-xc42.google.com (mail-oo1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE60FC0613CF for ; Tue, 17 Nov 2020 08:26:28 -0800 (PST) Received: by mail-oo1-xc42.google.com with SMTP id l10so4872685oom.6 for ; Tue, 17 Nov 2020 08:26:28 -0800 (PST) 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=z75qkcvTDD7D5ZVAs+uCqlqVE13UoCxrYrBW5Z0YsDk=; b=NbWG5mavXseC8TwQhZgdUwUaEBWIg13azPa/dMhqYJ71H7R1Z/qeTEhVaPbUVfXyE7 cuuDbCoMHIkFBt9qXX+uZsQB+89riqdLmQ+Ffxx0ad4LOr351/dC7ap3Si3KFvSK4Mbu qKKfB3tCkpSSeKQ40lQuoVQzZYl8KLmUe7l8MnAJpt/8rqT5/DrPdYZfW0upTES0dNdI a6Yxcj79g/bjpQENWeUZUTpbfKlPhhN0tzEyTZrTW7+jaOqhRfIEw5d0vt2cZc8xGLWG VGnbiU/hV7wmCd9cvERoCxcrALe9HXxE5vyEiqOzyoKTFOR/LBmkiop+NMI7MROxwuoU oyAg== 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=z75qkcvTDD7D5ZVAs+uCqlqVE13UoCxrYrBW5Z0YsDk=; b=caex4Ra9kkHJa6PrwHW+3k0CtUiFpFsf/URkl6k0Vs9P6tRfhtIWN69ChTCwjDvpJm Q/zLY9Hh9nKHJW8n3J7dKSHZUuru5MtoiZ2l1POhwexCm1CYogq4EGrc0slwd6emkCxt haJ2QOY+1V0q11v/HAjxwGDRQgn4g90U7RhcG4p42zFtxAiJk/a7fOKhdPB+SemQNxp3 NGRAR7CNpyAPIX3+GPTsfTfuf2ZANgUZXlBdtJk6xT7bk/olstRD8Qcc2QZhfsGBzPVx JWdrj3+WKVJiptnGbSzm6caGosMWvYX9QFnJDkn2hUwC2Ivd23f158CXG0AKmJO1EvUs oTpg== X-Gm-Message-State: AOAM530NoiTrvMTdsbNxy8jBa7tl5RFn8m7wXITnuQFlvq80ixkiK9/A JfMhi14jtLMlLRctIrHk0TqoLQ== X-Received: by 2002:a4a:e5ce:: with SMTP id r14mr3587297oov.11.1605630387621; Tue, 17 Nov 2020 08:26:27 -0800 (PST) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id b123sm6262913oii.47.2020.11.17.08.26.25 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Tue, 17 Nov 2020 08:26:26 -0800 (PST) Date: Tue, 17 Nov 2020 08:26:03 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Matthew Wilcox cc: Hugh Dickins , Andrew Morton , Jan Kara , William Kucharski , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, hch@lst.de, hannes@cmpxchg.org, yang.shi@linux.alibaba.com, dchinner@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 00/16] Overhaul multi-page lookups for THP In-Reply-To: <20201117153947.GL29991@casper.infradead.org> Message-ID: References: <20201112212641.27837-1-willy@infradead.org> <20201117153947.GL29991@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 Tue, 17 Nov 2020, Matthew Wilcox wrote: > On Mon, Nov 16, 2020 at 02:34:34AM -0800, Hugh Dickins wrote: > > Fix to [PATCH v4 15/16] mm/truncate,shmem: Handle truncates that split THPs. > > One machine ran fine, swapping and building in ext4 on loop0 on huge tmpfs; > > one machine got occasional pages of zeros in its .os; one machine couldn't > > get started because of ext4_find_dest_de errors on the newly mkfs'ed fs. > > The partial_end case was decided by PAGE_SIZE, when there might be a THP > > there. The below patch has run well (for not very long), but I could > > easily have got it slightly wrong, off-by-one or whatever; and I have > > not looked into the similar code in mm/truncate.c, maybe that will need > > a similar fix or maybe not. > > Thank you for the explanation in your later email! There is indeed an > off-by-one, although in the safe direction. > > > --- 5103w/mm/shmem.c 2020-11-12 15:46:21.075254036 -0800 > > +++ 5103wh/mm/shmem.c 2020-11-16 01:09:35.431677308 -0800 > > @@ -874,7 +874,7 @@ static void shmem_undo_range(struct inod > > long nr_swaps_freed = 0; > > pgoff_t index; > > int i; > > - bool partial_end; > > + bool same_page; > > > > if (lend == -1) > > end = -1; /* unsigned, so actually very big */ > > @@ -907,16 +907,12 @@ static void shmem_undo_range(struct inod > > index++; > > } > > > > - partial_end = ((lend + 1) % PAGE_SIZE) > 0; > > + same_page = (lstart >> PAGE_SHIFT) == end; > > 'end' is exclusive, so this is always false. Maybe something "obvious": > > same_page = (lstart >> PAGE_SHIFT) == (lend >> PAGE_SHIFT); > > (lend is inclusive, so lend in 0-4095 are all on the same page) My brain is not yet in gear this morning, so I haven't given this the necessary thought: but I do have to question what you say there, and throw it back to you for the further thought - the first shmem_getpage(inode, lstart >> PAGE_SHIFT, &page, SGP_READ); the second shmem_getpage(inode, end, &page, SGP_READ). So same_page = (lstart >> PAGE_SHIFT) == end had seemed right to me. > > > page = NULL; > > shmem_getpage(inode, lstart >> PAGE_SHIFT, &page, SGP_READ); > > if (page) { > > - bool same_page; > > - > > page = thp_head(page); > > same_page = lend < page_offset(page) + thp_size(page); > > - if (same_page) > > - partial_end = false; > > set_page_dirty(page); > > if (!truncate_inode_partial_page(page, lstart, lend)) { > > start = page->index + thp_nr_pages(page); > > @@ -928,7 +924,7 @@ static void shmem_undo_range(struct inod > > page = NULL; > > } > > > > - if (partial_end) > > + if (!same_page) > > shmem_getpage(inode, end, &page, SGP_READ); > > if (page) { > > page = thp_head(page); >