From patchwork Wed Jul 20 02:21:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CGEL X-Patchwork-Id: 12923284 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 4F7EBC43334 for ; Wed, 20 Jul 2022 02:22:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE0F16B0072; Tue, 19 Jul 2022 22:22:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D69E96B0073; Tue, 19 Jul 2022 22:22:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C09DB6B0074; Tue, 19 Jul 2022 22:22:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AB56D6B0072 for ; Tue, 19 Jul 2022 22:22:58 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7CE22A8A3A for ; Wed, 20 Jul 2022 02:22:58 +0000 (UTC) X-FDA: 79705880436.25.4479AD0 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf05.hostedemail.com (Postfix) with ESMTP id 1E7D5100073 for ; Wed, 20 Jul 2022 02:22:57 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id d7-20020a17090a564700b001f209736b89so747771pji.0 for ; Tue, 19 Jul 2022 19:22:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cO1rkdmuR7oU7bdfMTLhtMVH5g0UFDfLxXUgSSq290Q=; b=Pg+23lszg/SMLvpTmuUuWn7zjrLDDUntSNiqSnY9WYIdZX/j15HznIbwfe6QbVfLfp f6rctMgHQYPkaceqThkzrLIK0LgkpI/jV3EQenObsbg6f12v9mHQQetSWZGFeDCCy5Kz VDC13JEj7ZqqP2hpBqBXPqj4vVLVc9WhaneWRXlCaqm5mCvMupRHQwBDhfWPir3ZIY9+ 5cd7gNbxEZYvDd1JnQ51MS0kN0JJmvbASMGr79k6oXMya+crLOP3qS11M/l64IoFPdZS 7DM5ZVQvCAU5TowlrZ4RR3ajmC2pvb9t57I2+cWD7sshfFy6IFh6CkQmQq1Rfsz7IRey cQmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cO1rkdmuR7oU7bdfMTLhtMVH5g0UFDfLxXUgSSq290Q=; b=6LbbLQXR3z5sDIXgn0pUsXiqTeBN3dpMZPHuKIpDTsCMVgT2izQeVbW1LJ7LihUyNH 3fiKXoHG+YZ/j9ByIbUX/s5wwtERt5qH+/Lj9JtbYDE8CRkjJd59IohCieHKWOKNtZnk VJaBZZEu5mZCdbFDKwbxlCOGIOR+KtmN7cIzC7xz1Z1EacAjojibnjW1pc3pPezUGsQN LprHOVJZ+YBpMoI3QwnhdoF+BuWGesrYIpeObDPumq8Ock1X25oFLCMKYJPAwct10V1t GwTa+ekeGambOkuOjUhqVLicCwY4e58LVHneXsJacWDrgEZywqvBJ84ryXkQDx3rRVg7 9BGg== X-Gm-Message-State: AJIora9hiYjzcd8oEJ8Sf0/xz9huj+NDUlL0C+7F4eohDp1NM6n5lBCu Hu9fA0INDlmsLwF19Q9cIzs= X-Google-Smtp-Source: AGRyM1tHNsb+oWEVREcDzaw1lIXwkfEzP1rakZkQKX9TOABe/2TEHuqjDnSIhJIm2G8raA5nLI9n4A== X-Received: by 2002:a17:902:e551:b0:16c:5a22:4823 with SMTP id n17-20020a170902e55100b0016c5a224823mr35231811plf.38.1658283776923; Tue, 19 Jul 2022 19:22:56 -0700 (PDT) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id f129-20020a625187000000b00525b61fc3f8sm12361724pfb.40.2022.07.19.19.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 19:22:56 -0700 (PDT) From: cgel.zte@gmail.com X-Google-Original-From: yang.yang29@zte.com.cn To: viro@zeniv.linux.org.uk, hughd@google.com, akpm@linux-foundation.org, hch@infradead.org, hsiangkao@linux.alibaba.com Cc: yang.yang29@zte.com.cn, axboe@kernel.dk, yangerkun@huawei.com, johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ran Xiaokai , CGEL ZTE Subject: [PATCH] fs: drop_caches: skip dropping pagecache which is always dirty Date: Wed, 20 Jul 2022 02:21:19 +0000 Message-Id: <20220720022118.1495752-1-yang.yang29@zte.com.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658283778; a=rsa-sha256; cv=none; b=IcqD/YpMZbde6qkMLy6GHsFeqn4WOC410pBVNkjaSqWtnwkTpv6/82okP8nTqXhuGEfgUS gIyZZT+u6VWXhw11n/2i9TQRrwjJpLxEBB03VB90dXEHeNG85wj1TKAZ1NomYmDQYG2Iyy DROE4qEjf/SUqR7iFgELsRDWO+QEk4Y= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Pg+23lsz; spf=pass (imf05.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658283778; 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:references:dkim-signature; bh=cO1rkdmuR7oU7bdfMTLhtMVH5g0UFDfLxXUgSSq290Q=; b=DSWBMxcDh5jk7Y+dDHlAl7U1gZqsjEfB0gE3XB8DRbFFI5A7Ap/uKUxDsFJKExhXk0bVeU rWjwiUEJNyKoYSCFAdgpEmkp3gi5KqiAnvgzBvDU+ZHTkE/Vzk9u/wM5lH+Tos7XEaKNQx OghaRs4+RkmNAHrcXJb6vkoxo/cPJ48= X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1E7D5100073 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Pg+23lsz; spf=pass (imf05.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: q7gykxawe3g163iugtyiwhcn34d859r6 X-HE-Tag: 1658283777-251347 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: From: Yang Yang Pagecache of some kind of fs has PG_dirty bit set once it was allocated, so it can't be dropped. These fs include ramfs and tmpfs. This can make drop_pagecache_sb() more efficient. Introduce a new fs flag to do this, and this new flag may be used in other case in future. Signed-off-by: Ran Xiaokai Signed-off-by: Yang Yang Signed-off-by: CGEL ZTE --- fs/drop_caches.c | 7 +++++++ fs/ramfs/inode.c | 2 +- include/linux/fs.h | 1 + mm/shmem.c | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/drop_caches.c b/fs/drop_caches.c index e619c31b6bd9..16956d5d3922 100644 --- a/fs/drop_caches.c +++ b/fs/drop_caches.c @@ -19,6 +19,13 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused) { struct inode *inode, *toput_inode = NULL; + /* + * Pagecache of this kind of fs has PG_dirty bit set once it was + * allocated, so it can't be dropped. + */ + if (sb->s_type->fs_flags & FS_ALWAYS_DIRTY) + return; + spin_lock(&sb->s_inode_list_lock); list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { spin_lock(&inode->i_lock); diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c index bc66d0173e33..5fb62d37618f 100644 --- a/fs/ramfs/inode.c +++ b/fs/ramfs/inode.c @@ -289,7 +289,7 @@ static struct file_system_type ramfs_fs_type = { .init_fs_context = ramfs_init_fs_context, .parameters = ramfs_fs_parameters, .kill_sb = ramfs_kill_sb, - .fs_flags = FS_USERNS_MOUNT, + .fs_flags = FS_USERNS_MOUNT | FS_ALWAYS_DIRTY, }; static int __init init_ramfs_fs(void) diff --git a/include/linux/fs.h b/include/linux/fs.h index e285bd9d6188..90cdd10d683e 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2532,6 +2532,7 @@ struct file_system_type { #define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */ #define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */ #define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */ +#define FS_ALWAYS_DIRTY 64 /* Pagecache is always dirty. */ #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ int (*init_fs_context)(struct fs_context *); const struct fs_parameter_spec *parameters; diff --git a/mm/shmem.c b/mm/shmem.c index 8baf26eda989..5d549f61735f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3974,7 +3974,7 @@ static struct file_system_type shmem_fs_type = { .parameters = shmem_fs_parameters, #endif .kill_sb = kill_litter_super, - .fs_flags = FS_USERNS_MOUNT, + .fs_flags = FS_USERNS_MOUNT | FS_ALWAYS_DIRTY, }; void __init shmem_init(void)