From patchwork Wed Apr 10 15:03:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624741 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 68B74CD128A for ; Wed, 10 Apr 2024 15:12:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDE486B00C4; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B65E36B00C1; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B7766B00C3; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7721F6B00C0 for ; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 34D25C0822 for ; Wed, 10 Apr 2024 15:11:57 +0000 (UTC) X-FDA: 81993962274.29.E893862 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf16.hostedemail.com (Postfix) with ESMTP id 2BF58180015 for ; Wed, 10 Apr 2024 15:11:53 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 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=1712761914; 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=xeRFAEtTB6ifOA0Xty8nltqQ4YmeM2x0oln0yUmLntk=; b=S8j5cIltyo/sYdz2y6VAdKx3xwEg51Clwaa71vox3NmB0V9480t6/g0Y2W7sQBh8SbE7Uj vQA5mBAhAJpfb0a8PhtkcJNd6pOEchLVWE1mZQ168SdiwC7sj3HhHy6kgT7WZfu0g6HwdR AdSj4BZ6H0HM5a8q7z91+8JnKjMAUh8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712761914; a=rsa-sha256; cv=none; b=ov0rwAGaG9XJUzotyz0PzvTmwgJSzyY1DTpasRlx4tfdk1zaogwTomMrEXVPNKB3f9GCQC Ha3OyXEGwC/dSNoOyt8ytkV2O/13y1gamBfABI2f5e6FWQMFp3ZmdFSZhU2FR0DqubSlyT AsJMEcEn3sktuaBJ4ZU2fvph97najCc= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF5rv05QXz4f3kj7 for ; 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 D454F1A0D11 for ; 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> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g4orBZmFSt+Jg--.51485S6 X-Coremail-Antispam: 1UD129KBjvJXoW7CFW7KF13Ar18tF1DXFy3XFb_yoW8uryfpF W7uw4rGrWUWFsYvr93AFy2yF4fWa4kWayUAF9xGwn8AasxKF42gFWvk3W3X3yUJr4rAa1f ZF4Uury3GFyjg3DanT9S1TB71UUUUjJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUljb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAFwI0_Gr0_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1lwIvzi4gevceMmRv5w3NCjCaZ3dZmHoUydpHHAcingJyjtNLBUp6/M9FwqAviAMgDE5awMSGt/j38nK5FG6017bsmGYvSerKZYcsO50BZVDcz4ibL6qhTyK0F4goleFUYxsopuiwbAslCizTlZrzY5aO7gehwBnEa6XB0p9DSDDRuZhA6P+g7IEtG6gRnFquNhPId1nKBuYxaXXbiLY7Y8rzDezurURlXdW/dkv9ZBd2I4E+yNjAUDsQpCkpBA7Btu13a6IdxirtReWhNrP0iErhHMHMqTiziMTZ9VKJESlp8/d/stMjwjf3u6PABQIl2HEJi4dlw/voAxQWBt8vNFKvtVgCOcjVWCYMpk8pGnIZsuB8DVkDB+odRm8nabaJ9NipoyQZb2hPxb22G8aSUp+J7FTEi3fnOi0zH0FRanHz/AfqIDvRVjJr91SkKvWXXO24MAwGnNLVc5MwZw+wGoG1C8TiU45zB9B1RmID9pvloNvjSp5NLbrc7vh/2xAmCH9E11jntM+otTvqH8QdpsFLY4xwRqNLeSA09yC6ipFBPEXVj4hXfYXvz9GiWtUQwfZlurNvXYywvfWWVpFtjE6YsDRjs2PtPPOFn3+m kDed7q3z TK7DhSn2XPM9rKWO4z4hBb85TzcCBz04azhnk0dWKms/xc93DlGsctQQ8bdzEAp6scylYcraBKLpOh/anKy7LyETrAyLn/n2VZzMONVLMaE027R3GBB7FjOsYdFT8GteIpTH/X0PwTKdcVOtlKYinekjPKYKlKPFOPzzPM+msTZzneN1edrlcnSwatIMjub6yM3H+LfFkctMWAc01k0BewkMJQg6oEBYr3XOMJN+9HAc38olIpVPgyr79ghwqcvAcgWIE 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. 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;