From patchwork Mon Sep 9 22:19:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daeho Jeong X-Patchwork-Id: 13797643 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A6F7ECE58E for ; Mon, 9 Sep 2024 22:20:14 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1snmk2-0004sH-Jh; Mon, 09 Sep 2024 22:20:14 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1snmjy-0004rl-D1 for linux-f2fs-devel@lists.sourceforge.net; Mon, 09 Sep 2024 22:20:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=96o2jLIHz/bI5xeY8SRyIJjzjj2HXt3FtxwUFI6EfOI=; b=FVcOWtXgvUhx8lbeeKj1Qs3apH UsGdTEGOJe0brnRJdIDo4YrFphVasTALptsHwww7smiVFaU+VSMi43P9QlMYfq/B9gZvdgpP9LxY8 b0aM2nMwZecli5JJyJiJZTTODhPf+QF0euRZiqhXHag1b3SGOMt7d9RDzMQabCGZvM7k=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=96o2jLIHz/bI5xeY8SRyIJjzjj2HXt3FtxwUFI6EfOI=; b=L 7s4MN5SyzNzCzbDu5FjF0SPjxU78gK/UBazMABVBaqHAmlGhN5XMMHMgRN26bocKGef9YW6cgZdTP 0Xnjf3B7TlvqFSHh1hEZ6ax5XETgU+RCVxlD049pzYYYIzrHIL0dQ3xus4M6OU/kBHNmJR7iMdEav Fr6AhxnNj5SqCjno=; Received: from mail-pj1-f41.google.com ([209.85.216.41]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1snmjq-0006gP-Pq for linux-f2fs-devel@lists.sourceforge.net; Mon, 09 Sep 2024 22:20:03 +0000 Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2d88edf1340so3120097a91.1 for ; Mon, 09 Sep 2024 15:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725920392; x=1726525192; darn=lists.sourceforge.net; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=96o2jLIHz/bI5xeY8SRyIJjzjj2HXt3FtxwUFI6EfOI=; b=ayx3EnjCIzRjYJ+TgWnPaz877YxPT9s8396w6mpgyRy72l2FQhjXsRvfWVoIyYIRPr Ob2vLz5bwuYyjPCcFxaAYpD3dYMnia28HuEUmtaX3PR1viUoollF2rQN0uSOUzePoSj8 lznQbr09KIa9V/nW4rFuIvGImLeR5zu8nVuj6nqbr/QMFFI2/8wdn8Tz7kRd30rCagHK lrtclAR1iAb1QufXLAv5ROVEQc2H9wyUVj2RTwWL/WUXzzML4uNQAmZt4+bt+tqZN2qE Bfp0OQffJ0UM+IIVVsV36AlbO6voy+di6jT7zxj75nB75ZyvpLf4Etob++rEMTf1tkSv cQ0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725920392; x=1726525192; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=96o2jLIHz/bI5xeY8SRyIJjzjj2HXt3FtxwUFI6EfOI=; b=QBbs/dHRafVdk99LFLX9jHhcp3sYIsXw/cUee1JzBQ5vGAM3sTE8NBje715U4Bd+hz EhBGJAgLBN8azCqKINVo6ShklkNw7ZKjMPN97Qrxz8MYC3lMWZfE9vyIY9btb/qCrqew nolKc4gb7M05P97XGlu7mLvI6vIpr2mor5ibZcS6WaXZuXzFMXym1SJRt8xPOpwsZk8t d//CyY0KwNmBxZTmelhVjNpB/ZDPZUi0cEeXOklc7bTRTejcVWzALr4QJiy/tmS1KFTl OZ0Et9Jx401RI6JYxT4dPZCmAalt41Q+J+/iiE0MJ6Ifb45X6jRaarC5AYI2igdg0MY9 D5UQ== X-Forwarded-Encrypted: i=1; AJvYcCXe1VZpHK3uAR2r4dnf8luro4HqzEUaA/aAAY6J+exxt3WCFeXWZ4LPXBbwTMjo16Tng4nrYRhhlB1ChfLw4g9U@lists.sourceforge.net X-Gm-Message-State: AOJu0YzM30tnPukM8MwxyrBWKawGkcg6dnpqdGVBqwjjvUKXwWRFCJeN XTrQAlAZROAZ7/dlj4eR26s5a2F+b7D6pjsD5O9boLLCDjGJR2PR X-Google-Smtp-Source: AGHT+IGYtptBMoCRyIFLyR68NFRnQCLG+PIh/2i8YAvc5XVEbC/o5hvfd2WlnY6N4BtfpvmnF8kruQ== X-Received: by 2002:a17:90a:e651:b0:2d8:f99d:48d2 with SMTP id 98e67ed59e1d1-2dad50fcd09mr10727795a91.29.1725920391729; Mon, 09 Sep 2024 15:19:51 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2a00:79e0:2e14:7:ed56:14c3:db02:6c66]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db04988470sm5016840a91.54.2024.09.09.15.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 15:19:51 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Date: Mon, 9 Sep 2024 15:19:40 -0700 Message-ID: <20240909221946.2004046-1-daeho43@gmail.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog MIME-Version: 1.0 X-Headers-End: 1snmjq-0006gP-Pq Subject: [f2fs-dev] [PATCH v2 1/7] f2fs: make BG GC more aggressive for zoned devices X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daeho Jeong Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Daeho Jeong Since we don't have any GC on device side for zoned devices, need more aggressive BG GC. So, tune the parameters for that. Signed-off-by: Daeho Jeong Reviewed-by: Chao Yu --- fs/f2fs/f2fs.h | 20 ++++++++++++++++++-- fs/f2fs/gc.c | 25 +++++++++++++++++++++---- fs/f2fs/gc.h | 21 +++++++++++++++++++++ fs/f2fs/super.c | 5 +++++ 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index ac19c61f0c3e..5e4db3ba534a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2854,13 +2854,26 @@ static inline bool is_inflight_io(struct f2fs_sb_info *sbi, int type) return false; } +static inline bool is_inflight_read_io(struct f2fs_sb_info *sbi) +{ + return get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_DIO_READ); +} + static inline bool is_idle(struct f2fs_sb_info *sbi, int type) { + bool zoned_gc = (type == GC_TIME && + F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_BLKZONED)); + if (sbi->gc_mode == GC_URGENT_HIGH) return true; - if (is_inflight_io(sbi, type)) - return false; + if (zoned_gc) { + if (is_inflight_read_io(sbi)) + return false; + } else { + if (is_inflight_io(sbi, type)) + return false; + } if (sbi->gc_mode == GC_URGENT_MID) return true; @@ -2869,6 +2882,9 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type) (type == DISCARD_TIME || type == GC_TIME)) return true; + if (zoned_gc) + return true; + return f2fs_time_over(sbi, type); } diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 724bbcb447d3..46e3bc26b78a 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -116,7 +116,17 @@ static int gc_thread_func(void *data) goto next; } - if (has_enough_invalid_blocks(sbi)) + if (f2fs_sb_has_blkzoned(sbi)) { + if (has_enough_free_blocks(sbi, LIMIT_NO_ZONED_GC)) { + wait_ms = gc_th->no_gc_sleep_time; + f2fs_up_write(&sbi->gc_lock); + goto next; + } + if (wait_ms == gc_th->no_gc_sleep_time) + wait_ms = gc_th->max_sleep_time; + } + + if (need_to_boost_gc(sbi)) decrease_sleep_time(gc_th, &wait_ms); else increase_sleep_time(gc_th, &wait_ms); @@ -179,9 +189,16 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi) return -ENOMEM; gc_th->urgent_sleep_time = DEF_GC_THREAD_URGENT_SLEEP_TIME; - gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME; - gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME; - gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME; + + if (f2fs_sb_has_blkzoned(sbi)) { + gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME_ZONED; + gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME_ZONED; + gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME_ZONED; + } else { + gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME; + gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME; + gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME; + } gc_th->gc_wake = false; diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h index a8ea3301b815..55c4ba73362e 100644 --- a/fs/f2fs/gc.h +++ b/fs/f2fs/gc.h @@ -15,6 +15,11 @@ #define DEF_GC_THREAD_MAX_SLEEP_TIME 60000 #define DEF_GC_THREAD_NOGC_SLEEP_TIME 300000 /* wait 5 min */ +/* GC sleep parameters for zoned deivces */ +#define DEF_GC_THREAD_MIN_SLEEP_TIME_ZONED 10 +#define DEF_GC_THREAD_MAX_SLEEP_TIME_ZONED 20 +#define DEF_GC_THREAD_NOGC_SLEEP_TIME_ZONED 60000 + /* choose candidates from sections which has age of more than 7 days */ #define DEF_GC_THREAD_AGE_THRESHOLD (60 * 60 * 24 * 7) #define DEF_GC_THREAD_CANDIDATE_RATIO 20 /* select 20% oldest sections as candidates */ @@ -25,6 +30,9 @@ #define LIMIT_INVALID_BLOCK 40 /* percentage over total user space */ #define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */ +#define LIMIT_NO_ZONED_GC 60 /* percentage over total user space of no gc for zoned devices */ +#define LIMIT_BOOST_ZONED_GC 25 /* percentage over total user space of boosted gc for zoned devices */ + #define DEF_GC_FAILED_PINNED_FILES 2048 #define MAX_GC_FAILED_PINNED_FILES USHRT_MAX @@ -152,6 +160,12 @@ static inline void decrease_sleep_time(struct f2fs_gc_kthread *gc_th, *wait -= min_time; } +static inline bool has_enough_free_blocks(struct f2fs_sb_info *sbi, + unsigned int limit_perc) +{ + return free_sections(sbi) > ((sbi->total_sections * limit_perc) / 100); +} + static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi) { block_t user_block_count = sbi->user_block_count; @@ -167,3 +181,10 @@ static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi) free_user_blocks(sbi) < limit_free_user_blocks(invalid_user_blocks)); } + +static inline bool need_to_boost_gc(struct f2fs_sb_info *sbi) +{ + if (f2fs_sb_has_blkzoned(sbi)) + return !has_enough_free_blocks(sbi, LIMIT_BOOST_ZONED_GC); + return has_enough_invalid_blocks(sbi); +} diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 3959fd137cc9..ca2101ad918e 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -707,6 +707,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount) if (!strcmp(name, "on")) { F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; } else if (!strcmp(name, "off")) { + if (f2fs_sb_has_blkzoned(sbi)) { + f2fs_warn(sbi, "zoned devices need bggc"); + kfree(name); + return -EINVAL; + } F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF; } else if (!strcmp(name, "sync")) { F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC;