Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6513180rdb; Tue, 2 Jan 2024 04:45:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzwyIY0c0pmQeXmuYDe1bGYB12yq7mKOCJI5LhZwhc0jk4bWI4tMEOzVNmcwwZ/HPigzbm X-Received: by 2002:ad4:4eee:0:b0:67f:458f:bd5b with SMTP id dv14-20020ad44eee000000b0067f458fbd5bmr27740231qvb.27.1704199510807; Tue, 02 Jan 2024 04:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704199510; cv=none; d=google.com; s=arc-20160816; b=vRw6vgp+5Bcb/R7y5xEgbTkC03DGVyHpe0+SzWcPNBkKzFQ/b74dhylxxNNNdr1o9h UQcQCU16fnihfRaUbAvQjxyVk7aKRM6zBm4XZ+96HT5aR/TDSgdKH7699ZF5qYbSVHnk i8zz5GyyEvbLhNtFKCHpO8tb2qSPX1SRGAZqGn+FevDLSPSiyKexAr22cVK1KY8IRxJD caS5OY3EO0urdturY/vhB/DYhqtbrpAJu4Nh0FS9yZYcityB4qH1lRYNphRQlJvYgu3/ UQPpF8t4PuzaEdgmAc2W+FnQmdXFtWbFh5j6rAQvtv7AjsIzD0u60X3p3GV1Gg7e5f/S 88nQ== ARC-Message-Signature: i=1; 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=+IprirHtrMJCNOTB07rV6w8BTpOq0sjI72CpQi/v6hQ=; fh=yWWoL3IRufgA/+2kSpO6uyfw9eN3ZOO7zvul0qbDPkA=; b=X0EvD31Ek4zfcJ1kT9bip7+75QANBGTV/OTIQPK4X4iIqRjoXk7W3wimlFpeCfJKT6 L0CQisgCXBrpkAliAw23i38fAv2+TF4BiTPgTPPaGXScz6OgOwOdR77w2wRsF7Ja7CJN zTmTV1SAJo9uscvqb3rb53gZMP8VqOTeSDZ83X2f4hNhCbxhRD9b8M2fmNlrBxdb/9zZ w07/NpJoYJ1bEGRoW9kpR1k8QRNAE2KKTzSpq4gGO4J2UJU5JybO7hyCBiyeBZgFAYKn YsvTrEo9Iuq2AlQoD0MGwXajADkpKck59a3ZO0dtK41SRWL/BTanULjbDscuLxTDSybv gtsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-618-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-618-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s5-20020a0ce305000000b0067f29c99880si5492152qvl.292.2024.01.02.04.45.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 04:45:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-618-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-618-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-618-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 91B931C21F78 for ; Tue, 2 Jan 2024 12:45:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 130A6111BB; Tue, 2 Jan 2024 12:42:23 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (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 45052156E7; Tue, 2 Jan 2024 12:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4T4CD84W1cz4f3l81; Tue, 2 Jan 2024 20:42:16 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 599821A07FD; Tue, 2 Jan 2024 20:42:18 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgBnwUGUBJRl+EvDFQ--.31823S28; Tue, 02 Jan 2024 20:42:18 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@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, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v2 24/25] filemap: support disable large folios on active inode Date: Tue, 2 Jan 2024 20:39:17 +0800 Message-Id: <20240102123918.799062-25-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240102123918.799062-1-yi.zhang@huaweicloud.com> References: <20240102123918.799062-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:gCh0CgBnwUGUBJRl+EvDF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Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= 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, besides, the order of folio must also be determined under the lock. Signed-off-by: Zhang Yi --- include/linux/pagemap.h | 13 +++++++++++++ mm/readahead.c | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 06142ff7f9ce..2554699ba7e3 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -343,6 +343,19 @@ 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) +{ + __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; -- 2.39.2