Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp206369lqj; Wed, 10 Apr 2024 08:13:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCULUtIjQ4T9i44/vpZBKDpR34hAFfcXQ8ns7wHh0cAVrCLjh+Lf77t0XBqVprY6/yDAlWHxlUWLP6qIQ9DXEILcO7WkyJuZ93eXJdB5bw== X-Google-Smtp-Source: AGHT+IHGVLspOoTRKLHj/sUF/OaCVpB4iaypbSu4SUM50RHOuKE7QS/EpbZ3jd1rv7Dwt4gNpJPE X-Received: by 2002:a05:620a:4486:b0:78e:bdc8:563b with SMTP id x6-20020a05620a448600b0078ebdc8563bmr498111qkp.71.1712761994167; Wed, 10 Apr 2024 08:13:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712761994; cv=pass; d=google.com; s=arc-20160816; b=J1B/QmmResJmJYh3zULCOppnekhYZCs/lWI1elnfdIGEkR0R09Z4Jbbg+BWpz+QXzt BuaUQP5cztPL0s59oVIfgZQZxcWgXAw7fQ4q1A+GHaSdGhZyJQbL97fr9wjIJYs7l3Cq wnvhl9cYodExliOlvT3nz4JtH9gYlXGEEncKoiUbiQbeiQ+yev/VM0mcBFFpBd+LeUkS BSO1C5PhD8jwB/uECUNQLHrmW/nGU7D51vWype0SIPh8XseUd1B0MyoMDEf+h5cvHhSc 1159XLBvxtapZZaSJSNh7oATEudzpGjv6hQBGQxbKQQP+hqJT8fdFDLl7Sfx8V9KtH9l /HEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=xeRFAEtTB6ifOA0Xty8nltqQ4YmeM2x0oln0yUmLntk=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=YL5nTjhzSrZs3GmrUAING9vXSZ/q1XVLF9+8Offid7Lm/0nqJqfxeLVY+vuRgoJYtu UdFP5jTUddNIMizc2z9LjxnR3JZP5Cikzf9k6NiRnTTYRFTS8+1Tds4JfkoB3u/OaihN k2we0U5YUfs4FbOgmn31rLCE2H8gG+9jMwdLxNLHKAY8vK5BYwva/RNETp27BmYui40s jRJ/h7R/ONuSQKeOqDzscUJQTht1giJ3v1+4AiVfM4loNH08Bl8a0i4t7ZX9nzseXbsI jbYRXHWhljElbRmswLVHAtT7QDEWeeRLQD6I1A23czwNYXz/GE71jkdxTwjNx0l0MkJy Hq3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2004-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2004-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id du20-20020a05620a47d400b00789ed7b0a06si12461142qkb.229.2024.04.10.08.13.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 08:13:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2004-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2004-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2004-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DF5451C24105 for ; Wed, 10 Apr 2024 15:12:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D86AD16F26E; Wed, 10 Apr 2024 15:11:56 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3806815444A; Wed, 10 Apr 2024 15:11:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712761916; cv=none; b=Y29Ce8oxHE1+kZQN2cIbblZG0s2mu7uRwZ7fqVjjaiQwhQPY2GdmP8VWch0PoeckP4y54ygbqzkLLKVbYZdmChcQcPurrZVmRgCyG5z2jdlE1cSnh88waMbmgRa+kJmxxoxfBMS5XV4LwdJFk6fT30WlKPwa8uah/NN92Tnq96s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712761916; c=relaxed/simple; bh=qedOqUe8njcEX0z1KrWk7ZkIOm2CEHudY9JaQgkVuTc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OZlMHso4LQeAYd+HztC73yJTt77N8alaazxphub0B82AEjW6yzLjGbCpeDwIskBDIV8OO5S7cyVrKeYYQc6Cx56E/NNl1R0jYDclMq7ICbB2u/R6RAmgCukY0P1JawCa2jKRT7uRlJWQ5YkQfr6FAF5zpD1t26+gR9znspnW/tI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF5rv0Y5qz4f3kjF; Wed, 10 Apr 2024 23:11:43 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E1FCE1A0175; Wed, 10 Apr 2024 23:11:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S6; Wed, 10 Apr 2024 23:11:49 +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, david@fromorbit.com, 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 v4 31/34] filemap: support disable large folios on active inode Date: Wed, 10 Apr 2024 23:03:10 +0800 Message-Id: <20240410150313.2820364-3-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAn9g4orBZmFSt+Jg--.51485S6 X-Coremail-Antispam: 1UD129KBjvJXoW7CFW7KF13Ar18tF1DXFy3XFb_yoW8uryfpF W7uw4rGrWUWFsYvr93AFy2yF4fWa4kWayUAF9xGwn8AasxKF42gFWvk3W3X3yUJr4rAa1f ZF4Uury3GF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0zRjNtcUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ 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. Signed-off-by: Zhang Yi --- include/linux/pagemap.h | 14 ++++++++++++++ mm/readahead.c | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2df35e65557d..7e963bc64158 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -360,6 +360,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 130c0e7df99f..481fe355485c 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -505,6 +505,12 @@ void page_cache_ra_order(struct readahead_control *ractl, } filemap_invalidate_lock_shared(mapping); + + if (unlikely(!mapping_large_folio_support(mapping))) { + filemap_invalidate_unlock_shared(mapping); + goto fallback; + } + while (index <= limit) { unsigned int order = new_order; -- 2.39.2