From mboxrd@z Thu Jan 1 00:00:00 1970 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=-19.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL autolearn=ham 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 E3DE9C5519F for ; Tue, 17 Nov 2020 16:26:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7085624248 for ; Tue, 17 Nov 2020 16:26:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NbWG5mav" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727008AbgKQQ03 (ORCPT ); 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-Google-Smtp-Source: ABdhPJwEbtJaSAIffWbfsiQiaPRdu+CN3ysGQxSh48oJAho68bZkA6+kWULhGCBChKSe1hVhZ9aP1w== 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); > From mboxrd@z Thu Jan 1 00:00:00 1970 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=-19.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 9422CC56202 for ; Tue, 17 Nov 2020 16:26:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DDFBD24655 for ; Tue, 17 Nov 2020 16:26:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NbWG5mav" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDFBD24655 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EF7E46B005D; Tue, 17 Nov 2020 11:26:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA8146B0068; Tue, 17 Nov 2020 11:26:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D71AD6B0071; Tue, 17 Nov 2020 11:26:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id A5A3A6B005D for ; Tue, 17 Nov 2020 11:26:29 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 43473180AD804 for ; Tue, 17 Nov 2020 16:26:29 +0000 (UTC) X-FDA: 77494438098.26.plate86_3f1246f27333 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 12FD11804B647 for ; Tue, 17 Nov 2020 16:26:29 +0000 (UTC) X-HE-Tag: plate86_3f1246f27333 X-Filterd-Recvd-Size: 6112 Received: from mail-oo1-f65.google.com (mail-oo1-f65.google.com [209.85.161.65]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Nov 2020 16:26:28 +0000 (UTC) Received: by mail-oo1-f65.google.com with SMTP id t142so4860045oot.7 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=gZO8S1qQOBGH2ndx2m0Z6F16SzNjpY7Bs3nMfjKPH/FLY6GwO44KWuj0llT5G+vvMZ wIRXKyJ9iGQ0vLxAVAQpC0LY3fCJH1uFckfamGNUxnXm7dWAmMv0FBBS5cU2db4fhLsJ zK+cZV/unLGjCdC8ZwTQhtX41loCNMraq7tv/+/3iBN2jL3u3VHnzNQWtuKdgZjOzmpI n064SEsNLU8fRul/FMqwWZNYzNwUXojfrmrQ+/8jOjBNoqF/iYOmq6Tr888wq62radMy Hb2mOandkyKvpJ7Bvgsj0NTRe7pxT6N+/zygpzjVdZ2cmoCWTvu23RpPnqtxFXRTJLll UdGw== X-Gm-Message-State: AOAM532Lr7s/Uc71suKiKiUwWDyFcqJq/UkGdetHghzrCpZlqEcZJm5K 1yghFzPnBPFGTTiBfw5DOaf1nw== X-Google-Smtp-Source: ABdhPJwEbtJaSAIffWbfsiQiaPRdu+CN3ysGQxSh48oJAho68bZkA6+kWULhGCBChKSe1hVhZ9aP1w== 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); >