Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp768572pxf; Wed, 10 Mar 2021 17:51:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNglpl7MWGxi26sA6oNGwRRfCABxNg6uJQr6Bqw85+mIa8gRHTxc2fBumPhJWgJjBkfwVG X-Received: by 2002:a17:906:6a94:: with SMTP id p20mr770235ejr.68.1615427507116; Wed, 10 Mar 2021 17:51:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615427507; cv=none; d=google.com; s=arc-20160816; b=dUxZo0SONSyYfMQrZwRqXvtEdxxoDEGxcqG7fqdr1oq8LS+FHg9UGRuQRDIKdDY49q yKYW9Iv4ESaRZLed2FBT3S9ttgBcjhfkKvUyvgxKWCDYua8yxixSrvsg4YJ/vorkpEJr TxxzmvyY0EGNSaiSHUxeZTdR6iWDWfZZ1jTHj/8lbhfJv3mCljPatXubXROTbRLPAnIe 6Wh2Y9Ac2vRAWigG83E9K6pz67Sn+Fl2ozeeiy8rog5JeMidP6mZI2BgBDB+/z91ttpp nV57P7tB1DOpA+f0AwtyFqW9Zc0Cd/GAENZoL7XrD8A9qytxpnboZJle0i1+cL9Wcr7p /L0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:dmarc-filter :sender:dkim-signature; bh=bcTQDfhEjZ/+fOWTwuNtJfBy5vQPGXrdq2f+qUvfdu8=; b=Hb3yMuChSuiTNTSS4T2ZpLqV/450bPziT7FMi5Ijc5vMlIZawiuP+KKpz2d9ln3pjd bSkQdGMNzpqKVlG8YMKAz4ljxX3OgcCHX3Gwnc7mRoegv/9G2rppBgnu0gisKHJm1lTG cEB+b1LdZtP4nw9xAZx4oWHVGzzEX9iK8P4jDAM+S/+AcL5Yu8WkoXCOLTtqMMCDyVib cqhijCNBOZroWRnJihh1F0CQA0N+EtkPfrmgKVQwHpZLtRKpdgx2JHAhAM624tYo1rly Qi3HK1O3yrfN6ulIS+DnWAgqZn/pe7j0x2fPAC9m/qZoJfYzvWkWb1lH2V9Gg5/Jm5iH L0gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=SGe1uroB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cc7si742089edb.420.2021.03.10.17.51.10; Wed, 10 Mar 2021 17:51:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=SGe1uroB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229483AbhCKBsH (ORCPT + 99 others); Wed, 10 Mar 2021 20:48:07 -0500 Received: from z11.mailgun.us ([104.130.96.11]:17361 "EHLO z11.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbhCKBrr (ORCPT ); Wed, 10 Mar 2021 20:47:47 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1615427267; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=bcTQDfhEjZ/+fOWTwuNtJfBy5vQPGXrdq2f+qUvfdu8=; b=SGe1uroBfPBKGTAZkcGwrzCofFPrXagmltV/0QOMIvVrDgIIoEMIW3QTLXMlQCFRUGIex3TZ rWts7XjMC/7A0DyYZwKi+/Al2BKoJh6zDsfq/T6ZuOuCa+xI5ZxS5zYkpT6OePdsfTJnzYw/ 72vR5EPharK2vlbEHDnF+IUSft4= X-Mailgun-Sending-Ip: 104.130.96.11 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n06.prod.us-west-2.postgun.com with SMTP id 604976c3bb6300df7570f2ec (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 11 Mar 2021 01:47:47 GMT Sender: stummala=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 3FB0CC433ED; Thu, 11 Mar 2021 01:47:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from codeaurora.org (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: stummala) by smtp.codeaurora.org (Postfix) with ESMTPSA id A6726C433C6; Thu, 11 Mar 2021 01:47:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A6726C433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=stummala@codeaurora.org From: Sahitya Tummala To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Cc: Sahitya Tummala , linux-kernel@vger.kernel.org Subject: [PATCH] f2fs: allow to change discard policy based on cached discard cmds Date: Thu, 11 Mar 2021 07:17:32 +0530 Message-Id: <1615427252-7505-1-git-send-email-stummala@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the default DPOLICY_BG discard thread is ioaware, which prevents the discard thread from issuing the discard commands. On low RAM setups, it is observed that these discard commands in the cache are consuming high memory. This patch aims to relax the memory pressure on the system due to f2fs pending discard cmds by changing the policy to DPOLICY_FORCE based on the nm_i->ram_thresh configured. Signed-off-by: Sahitya Tummala --- fs/f2fs/node.c | 7 ++++++- fs/f2fs/node.h | 1 + fs/f2fs/segment.c | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 3a24423..dc8a01c 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -44,6 +44,7 @@ int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type) { struct f2fs_nm_info *nm_i = NM_I(sbi); + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; struct sysinfo val; unsigned long avail_ram; unsigned long mem_size = 0; @@ -90,7 +91,11 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type) /* it allows 20% / total_ram for inmemory pages */ mem_size = get_pages(sbi, F2FS_INMEM_PAGES); res = mem_size < (val.totalram / 5); - } else { + } else if (type == DISCARD_CACHE) { + mem_size = (atomic_read(&dcc->discard_cmd_cnt) * + sizeof(struct discard_cmd)) >> PAGE_SHIFT; + res = mem_size < ((avail_ram * nm_i->ram_thresh / 100)); + } else if (type == NAT_ENTRIES) { if (!sbi->sb->s_bdi->wb.dirty_exceeded) return true; } diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index f84541b..7a45c0f 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -147,6 +147,7 @@ enum mem_type { INO_ENTRIES, /* indicates inode entries */ EXTENT_CACHE, /* indicates extent cache */ INMEM_PAGES, /* indicates inmemory pages */ + DISCARD_CACHE, /* indicates memory of cached discard cmds */ BASE_CHECK, /* check kernel status */ }; diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index deca74c..13b3d728 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1773,7 +1773,8 @@ static int issue_discard_thread(void *data) continue; } - if (sbi->gc_mode == GC_URGENT_HIGH) + if (sbi->gc_mode == GC_URGENT_HIGH || + !f2fs_available_free_memory(sbi, DISCARD_CACHE)) __init_discard_policy(sbi, &dpolicy, DPOLICY_FORCE, 1); sb_start_intwrite(sbi->sb); -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.