Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2387446pxb; Mon, 20 Sep 2021 21:02:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydO//uI7qo6A4Ap+AS9Gqwt0u50zV7TQgcJJAMwvRsAp4oNcBdgYrXqvKgfQqfRYVLMeKL X-Received: by 2002:a17:907:1b02:: with SMTP id mp2mr32949548ejc.196.1632196945375; Mon, 20 Sep 2021 21:02:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632196945; cv=none; d=google.com; s=arc-20160816; b=mrBp7TL2RKShXzjezQokiGY8aaimSg/em1PaAnbYPFloQXzfEQWul8XYdX1O8LMeeK VRJXOMWbJAALVmCHrQJF26VQ9avFHHC8TTFxdjsv6y/rv4ezrfduonxe0kZzb7oxOFi4 iBHIe/U8LQFXFYcvfcWRB/iKVFrMUbMFNp0slJKloWHGSDpQAXTI5eIuE2/P67TFImIx UkeetsgfzzZu7B62y2V28RE+GbWj8o9oUzYswO+eZ3rfqrKItWiz8QOMOPqBYZMc8ULt l6yivSQylIQuie0Q1p3JxrEJIfUEF/Ajq60XohrSuFVYQpM1N9G3Tx2vBtnHh9pFXdSa QxYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/xBEjLn8neg2tRAMyWTbvXCFNduQWyte0Fp7znCoDD4=; b=0RA8DtCj/K3lLKg+QEoaP9SmHlKFt5+Ao7fdlYLQmv/bDLprS73jvx1YRliyHCBljN W+XZVMD9XFxYBeV7ul63hsD0yV00+7kZ+YVLVkwYQqUZw3504QVAuHEW7omCNXgOa7yd 64Bc3kZPalPb86hWM77L1SPECvgndW1OlSHNx2SaDOHHCM81yC/jhovOpT+zNKzohf8i gdFTis9++MIU2kL5g8IAQaaPCVFLl7lheW5mRPOxqCW9hsRPrdAW975Nd/6C0X9nzHGF 9+wHiizdYJ0h/xW0Ew2JRUG5+Px/ONhT5Fn6uFDsvMHa1BNNf92pW+Yw8U7/bJhhhEsx cC9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=prKje2XM; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 26si18901466eji.106.2021.09.20.21.02.01; Mon, 20 Sep 2021 21:02:25 -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=@gmail.com header.s=20210112 header.b=prKje2XM; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243907AbhIUCHd (ORCPT + 99 others); Mon, 20 Sep 2021 22:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236794AbhIUBv3 (ORCPT ); Mon, 20 Sep 2021 21:51:29 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA0F9C0DBA98; Mon, 20 Sep 2021 15:35:21 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id eg28so44386645edb.1; Mon, 20 Sep 2021 15:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/xBEjLn8neg2tRAMyWTbvXCFNduQWyte0Fp7znCoDD4=; b=prKje2XMyXXLq4tB6hSuSVp8msgpZmzcJdPnTSUaUBHBrzX5B5Tfk7YPfTa16cCn/c 5xIkwNGf+OzVUmwvYi2NJUy4XgXJz2SeQYVjqjB/YJx+fAhCnh2oLBWbTk7F8zZjGUA/ bzFLVRCdCqYoXNmp2JvKSkN4gQIkU4pvAbnAAo48DIoh2mYs9EwoRwSN8R+2a+aah5nk /JvkJpqKKJN5NIPIk9OKksghWlWZ0eCegP4kLCDVsrE/sWe9nMxx6rfwmZqWtniTBPFS OECNbfOTxS6a+/WDAOt8f4rUHDXRG28i1s7jI8HKRG+15RufUKBqda0IG2sRKBG4kAwI gDmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/xBEjLn8neg2tRAMyWTbvXCFNduQWyte0Fp7znCoDD4=; b=A9WmbLJCvAbzr++HFX3sAfgEE3g+OW9/EjTbUzcIeli9s1XOfnI7p93PRUwWp3ZBGm sI78XdDS9B/kkjOz5Zxst8qXdxDs9jFlPjkghxBDIBveCOarm3p7aAyLH16bhMrd1mqF /PryOsZUkIyXuZg/ek69z/7n+W58bsR6DwrRx3I/xAJpHEizAdMRTwYWUAIA6hlV56cC hlXAtzNX+36ijUA68TEmb7eflih5gGkKATKqzLO0GGOkNk+sSnb2YA9K4m0xd+Gxv3GJ 5ZQOzT695BNDDChNa8nQPxw88LNgAvzCMD3WTWEZlnl+zCbVoga8a9LiRcrepwYDel2V dO+w== X-Gm-Message-State: AOAM533E+XZzyuO8Wrb6W4MWS5Pp//Z5I1GAvyWlayNNiIh0r57zwh6I tFWPR5QTzZy2bJzLmb+xFxJQwwJOoyPqevG59rSmcNdh X-Received: by 2002:a17:906:3854:: with SMTP id w20mr29819934ejc.537.1632177320456; Mon, 20 Sep 2021 15:35:20 -0700 (PDT) MIME-Version: 1.0 References: <20210917205731.262693-1-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Mon, 20 Sep 2021 15:35:08 -0700 Message-ID: Subject: Re: [PATCH] fs: buffer: check huge page size instead of single page for invalidatepage To: Matthew Wilcox Cc: Hugh Dickins , cfijalkovich@google.com, song@kernel.org, Andrew Morton , Hao Sun , Linux MM , Linux FS-devel Mailing List , Linux Kernel Mailing List , Song Liu Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 20, 2021 at 2:50 PM Matthew Wilcox wrote: > > On Mon, Sep 20, 2021 at 02:23:41PM -0700, Yang Shi wrote: > > On Sun, Sep 19, 2021 at 7:41 AM Matthew Wilcox wrote: > > > > > > On Fri, Sep 17, 2021 at 05:07:03PM -0700, Yang Shi wrote: > > > > > The debugging showed the page passed to invalidatepage is a huge page > > > > > and the length is the size of huge page instead of single page due to > > > > > read only FS THP support. But block_invalidatepage() would throw BUG if > > > > > the size is greater than single page. > > > > > > Things have already gone wrong before we get to this point. See > > > do_dentry_open(). You aren't supposed to be able to get a writable file > > > descriptor on a file which has had huge pages added to the page cache > > > without the filesystem's knowledge. That's the problem that needs to > > > be fixed. > > > > I don't quite understand your point here. Do you mean do_dentry_open() > > should fail for such cases instead of truncating the page cache? > > No, do_dentry_open() should have truncated the page cache when it was > called and found that there were THPs in the cache. Then khugepaged > should see that someone has the file open for write and decline to create > new THPs. So it shouldn't be possible to get here with THPs in the cache. AFAICT, it does so. In do_dentry_open(): /* * XXX: Huge page cache doesn't support writing yet. Drop all page * cache for this file before processing writes. */ if (f->f_mode & FMODE_WRITE) { /* * Paired with smp_mb() in collapse_file() to ensure nr_thps * is up to date and the update to i_writecount by * get_write_access() is visible. Ensures subsequent insertion * of THPs into the page cache will fail. */ smp_mb(); if (filemap_nr_thps(inode->i_mapping)) truncate_pagecache(inode, 0); } In khugepaged: filemap_nr_thps_inc(mapping); /* * Paired with smp_mb() in do_dentry_open() to ensure * i_writecount is up to date and the update to nr_thps is * visible. Ensures the page cache will be truncated if the * file is opened writable. */ smp_mb(); if (inode_is_open_for_write(mapping->host)) { result = SCAN_FAIL; __mod_lruvec_page_state(new_page, NR_FILE_THPS, -nr); filemap_nr_thps_dec(mapping); goto xa_locked; } But I'm not quite sure if there is any race condition.