From patchwork Sat Jan 27 01:58:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4242C47DA9 for ; Sat, 27 Jan 2024 02:03:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 073C06B00A8; Fri, 26 Jan 2024 21:03:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 021976B00A9; Fri, 26 Jan 2024 21:03:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D97476B00AA; Fri, 26 Jan 2024 21:03:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C2C4D6B00A8 for ; Fri, 26 Jan 2024 21:03:03 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9AB7AC031A for ; Sat, 27 Jan 2024 02:03:03 +0000 (UTC) X-FDA: 81723443046.02.5D640FC Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf22.hostedemail.com (Postfix) with ESMTP id 1F746C0015 for ; Sat, 27 Jan 2024 02:02:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf22.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320980; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W4Z4WZaEfIoZ3vwpGldL2aH+8SMBSn2purh947hOd1g=; b=kSBpl2C/YQSORk799QBmPRcP3BQIkd8r9eQoS9Kp1TtEgj6n2y+l5YCD5+Rtt7LJ2+/vGd oUX11WLarZz7caV3hljfk98jezthh2TEUt7X+0P+zGFpWMUiCjg3jDoHnmVGihJ9cxbc68 9itQZZpiOauZlxCXYmKiCSF/DFoThsU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf22.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320980; a=rsa-sha256; cv=none; b=FZfoC+nOb7Kz/oNY7wGEGmGg4WRWL/E16fgkmhvfbsD7yQjo3y+TcYAYgADHwp27yVwXPd DeItRBuuFUut5+Qfh8u6MvhPumK52lF80QJFqjjPPvjbKnI78icwfCtkESazJGkVg5IsmB tTgApygmkpumOc35EonWpKVR6Oqq3ck= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrn3tcDz4f3lgG for ; Sat, 27 Jan 2024 10:02:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id DF90F1A0232 for ; Sat, 27 Jan 2024 10:02:55 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S29; Sat, 27 Jan 2024 10:02:55 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v3 25/26] filemap: support disable large folios on active inode Date: Sat, 27 Jan 2024 09:58:24 +0800 Message-Id: <20240127015825.1608160-26-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S29 X-Coremail-Antispam: 1UD129KBjvJXoW7CFW7KF13Ar18uFW5tw4ktFb_yoW5JF47pF y7Cw4rJrW8XF4YyrykAFsFvr4ag348WayUAFy3Was8A3ZxKF42gFWUCasxXry7Ar4rAa1x Za1UAry7GFyYg3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbCe HDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: d1xq9wqy4bicaej34jwgy98pdqgu33gy X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1F746C0015 X-HE-Tag: 1706320979-574827 X-HE-Meta: U2FsdGVkX1/q7riuDVa1kfsJtv6/8fEP0wz4LJGN8PyfNcMhnfIDA5baey/feDoBIjQeMcwa2kkKDPeGXKl0NZw9bSyYtDGckI1gc9nokrNYmiskxQf6wxHtFdphQv1kTXAkLT63YjxP5f/68CWCUD/WldjPt3SdBUltsUKihRmUG3nv4bv496RYYCyx0THFxDkXAPAsXqHzKKvY+Pbjfxf3gT/3cJszdLoH4PlhLryknVNJ/pLW/jZ1n/4GXHMZvMsB8ChpJEifQ7erWJZxGvsz/rJQUFpkZHwSEVHbvkmZb0oLs+KciLYJKUK/ptnSYqm256Foxfwc11Odg010ZQHHvqJLwitzasvSQrdRHHmDLnGHM/nyOecGyoVdl03U4brlfTiNChv+mq/XJzfLLKh3SR36P6Vm7YEEJp1StyBLQogvSQFDuZOO3uR/8kLm3cF5rdAxT6LsW5Yt8zl4OKaEkVC4Lp5iQ45qrDuSqvlpl+ytyNyqLWDjxin1bGDz3y+7ySindGv22g8xZqW50y4iNAbpWATgb0vXdhUsGVx4ZjdWxXoyc02+1hoL8oUVM6uFDMuz2nceWD7/OFVOXVYZ/TRh7WtlpLc/3gBaIU/vGIIRMLW9L6Xv1y+3YwubioOGWvoz4OuCBBG86xC5bjZ1YtF8JKsVi2oH/RlrYCFnzIXHlCmlfDU3NOTIVjewRjxoGIVB1OCB4s9s+PMcGT4V7EnJPyPq2qFAoP6cv7BjhR3I04GDE8jBGUPPw5w8Ht1BrwOKTK43MpdVW8SA9DzpzwnWBUyfzWqrciUics/PIveJKgJfm5rQmQhL0soAL/JxUTNHzUjoP5aW3EXMJYXMJsgydtt1dc1Qoo1242pMLzxGBN1i7DORGNky6XEDNG2LeMh9N2PkufVi1wZ045nJutkX4eJuv1nX+baE52HByPN8JR7CAhB/znAzMFFdYvRnERT3N/aT5khhCF3 qx9PZGw4 HF5DxRF0qzordg/YT0I0nJ37xHAhLqScTryhJK4G6cQrc5mGMikOT8h/FpKikFzSC0lBiVzecIpWDhLDjcUjerdahdWr8RJIW0nn0j1v7zmEjHqRptJoqxRbwu8eTh5VkA6r//99WyL7yXor/6hth85l5r7rW6ESh7lYkZxVXmpg/zdkeFHz1ACia3bTqP0pCM1TFHiQXsjhsB6qcGvIssctPt8wbX5xLCC+HtWABcVHlX5Dqm0Mq5b/HSlpax0fEapVX 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: List-Subscribe: List-Unsubscribe: From: Zhang Yi Since commit 730633f0b7f9 ("mm: Protect operations adding pages to page cache with invalidate_lock"), mapping->invalidate_lock can protect us from adding new folios into page cache. So it's possible to disable active inodes' large folios support, even through it might be dangerous. Filesystems can disable it under mapping->invalidate_lock and drop all page cache before dropping AS_LARGE_FOLIO_SUPPORT, besides, the order of folio must also be determined under the lock. Signed-off-by: Zhang Yi --- include/linux/pagemap.h | 14 ++++++++++++++ mm/readahead.c | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 06142ff7f9ce..7f77670960d8 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -343,6 +343,20 @@ static inline void mapping_set_large_folios(struct address_space *mapping) __set_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); } +/** + * mapping_clear_large_folios() - The file disable supports large folios. + * @mapping: The file. + * + * The filesystem have to make sure the file is in atomic context and all + * cached folios have been cleared under mapping->invalidate_lock before + * calling this function. + */ +static inline void mapping_clear_large_folios(struct address_space *mapping) +{ + WARN_ON_ONCE(!rwsem_is_locked(&mapping->invalidate_lock)); + __clear_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); +} + /* * Large folio support currently depends on THP. These dependencies are * being worked on but are not yet fixed. diff --git a/mm/readahead.c b/mm/readahead.c index 6925e6959fd3..c97eceaf7214 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -493,8 +493,11 @@ void page_cache_ra_order(struct readahead_control *ractl, int err = 0; gfp_t gfp = readahead_gfp_mask(mapping); - if (!mapping_large_folio_support(mapping) || ra->size < 4) + filemap_invalidate_lock_shared(mapping); + if (!mapping_large_folio_support(mapping) || ra->size < 4) { + filemap_invalidate_unlock_shared(mapping); goto fallback; + } limit = min(limit, index + ra->size - 1); @@ -506,7 +509,6 @@ void page_cache_ra_order(struct readahead_control *ractl, new_order--; } - filemap_invalidate_lock_shared(mapping); while (index <= limit) { unsigned int order = new_order;