From patchwork Tue Feb 6 22:32:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daeho Jeong X-Patchwork-Id: 197665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1861785dyb; Tue, 6 Feb 2024 14:33:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUEc8/XMlKtNJXJuRi1M01iq+jcYDc6vFHeAyfgCVTCsv531iT1tVOjkNP4Wb0QTtF+7NQ030ZNIraeA9E5V8tdyZIOiA== X-Google-Smtp-Source: AGHT+IEmywJZoXYyCTkhmNpIDMvYw9YO0j2UVGPkBmV8BAdR61YF8vcnNpNm+mXvFcUSYAjJ9F6Y X-Received: by 2002:a05:6402:14c8:b0:55f:fb25:47d9 with SMTP id f8-20020a05640214c800b0055ffb2547d9mr2811031edx.8.1707258806197; Tue, 06 Feb 2024 14:33:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707258806; cv=pass; d=google.com; s=arc-20160816; b=EyMSFfxENgntAfAitjJIjCpbXehnd5rdEJxg52xRweFcr4Heol+OK1j5yb0zykjIzu jWCFpimvsGpjc+Mayjt928JhNiHgmLIcrtE/H/SJgATNeWHtM1I/HLRw4Yv1B8OjwXG2 CN+q1W3nygG7wUrb94Y+/ziy7K6HpLHHYbZShK2HRBBo9sYepNcvZs596BTHXtlhml6Z uuaxtWdnGKp2mYWMGkJT+Uuvp6oWUMWjZxmKFxt4RQAfI5ZbEkUjX+iS0LYfmP7h//AT yerqNm5ZT71U7lpK4VS7lhNPv35Ru+3kAKgDE1ZuSn8hseTE2Gu0+Ur77C/OuOVP+XPP 6n0A== ARC-Message-Signature: i=2; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=00pmZ6kibv+G4s9omY1rvgDUEdmKCy0BpQNbUzvHf2k=; fh=1ZMUmSTvEEQQCpmdNhoym7ppXYVJcAIdy91dWLXDcV8=; b=n37TqcWhJneZiixzAGX66AmRENGOJhP2cQGXrjQFEmQK/MeiQ3HKcECybZuTl1PhuX ui1j/JYSUOyCcH4CK59po8JXy8xb8oT6bauw15tAfe0NnMwXdsUOxBlD3I1+wiJuoxYr hGJg3g2S0N0exK9r5cOWCFzuOqdGOm3T24wrahm7xbJxZmwlXfm098uXsdwDKwHjhAF7 HJBMwNEdXx5wQ8nnuQrSwI6A2N2m8sKW447HDNEp9u6gOBO/hsyHQNYnHyRsCTfZwbOl +llikxmjTcfImX/EEjsuy4x73yXSj585+dfKmoR4pNM2J/JbxWhCJVYIunjjCLrfjiou 5BnQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dAbjJP2F; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-55691-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55691-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCWLIAitkLDtFLw5qz+vecyPgr/z2YobSVkkGb5fpeou1TE4xrhK+tmnz67oOUH9eOg5yRWeKHuJMo8OKZN0RPnOvF9PHQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id co11-20020a0564020c0b00b00560c6ffd6c6si1858edb.344.2024.02.06.14.33.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 14:33:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55691-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dAbjJP2F; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-55691-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55691-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9FFD61F24949 for ; Tue, 6 Feb 2024 22:33:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A8BC1C6A8; Tue, 6 Feb 2024 22:33:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dAbjJP2F" Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68FA51C29C for ; Tue, 6 Feb 2024 22:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707258786; cv=none; b=tDBNYJGxXeP1byklM1S2b8T1c0XEAjBAFISBQkl40oFOrKUgYDpheLS0K9h0t0HqxN7E4LkxxPVbQl3z+i/oBg5W+5nWSJRMk1zSMLPy5Ztdbr+XpXadelizEDSy83VsxOmMI1C0QL6iD9CSBleq0m2VyYs6zL+g9JaA8XJU/C8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707258786; c=relaxed/simple; bh=sukycBZ4DQwhrKijFq94qphTf/v5PohQw/3KG49HqcA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=g23cIlUHkelbzxPZm1eVmQJR8dIqUXgxJ7XqZPR50QLGzO51XYDI4R019vgQu+ImaKlZJm1n2LSIe19J4TqBJu7eqg14/9Z0v9ob8xPjzdkx8ud7/gMcykN8Jk0uv4CNwttGOCUuf5iu4PvuBGO/vnAVGwDXSR6I3kynRTVs6pI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dAbjJP2F; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-296c2b74448so1083649a91.0 for ; Tue, 06 Feb 2024 14:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707258784; x=1707863584; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=00pmZ6kibv+G4s9omY1rvgDUEdmKCy0BpQNbUzvHf2k=; b=dAbjJP2FjvUbWZ5/xlj6zKL4uz+PsmKUwIhiDyxC8zgL9JMA1+U7gytU4oTc1LW60H 75IAexDRyQmRjVTQEbKyTvV3fjncv+fedDJMvePXHo1CLzl1m75VjFrNn7nch+xeNFcU OCM6K17P5yuz56w5GZUptlCpY+ZysHnw8kGY4uOnWJY9IA9LbLww40QXPH4cDBHmLf3F X26/TwEc+fGgy422shTBaAmTzY2G0Ox8qjABs7V8cy7PUk2I7eieRuNMSe29EHIYRjQ6 IniX0JEdhDGIXOuQLDaiMjXXZ7o4cws4hG8OrHCzLepS5X0qC26akGOjqES8btFKRFWL xzOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707258784; x=1707863584; 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=00pmZ6kibv+G4s9omY1rvgDUEdmKCy0BpQNbUzvHf2k=; b=T8RL2SpfpnIJwTI1SWCibAv64Ly3qVe+OhZyXq/XmGtbea2i4oI48tBtOi3aJboFP8 Dfsp/A3OZ0sTNlvmXSg3Jxr+viqp8TUwiJH0KogzS6DXYD+kNJq85/l1/CakDfDHrMWh w+eHwzsjafmHPDCfkS6zsLqugeVoL+KBTtqh9O0NBjIaUIFzUgUIE9YpaJVK1HHB34VB Bx4MBciCMUSNBzfICq/qC6pQvFNwykBcgrpn6bZvLaofpAdYehiu/7uakbYwi2AQvosA u1NQ32ib66mdFLoo8oI+M44TukxL3wKzGYNM9KKU1PNBmkrmDhysKbkL34xXefF2+wCb l3rQ== X-Gm-Message-State: AOJu0YzKr5Uo59d1KcfymziiXplvmHFIKwW/MyGz7tarNqkuvH564pUY i8Cy3be8ficRfqWvFsCKF/mRyKod6bDPdAnIHGmS6f3jQYuOFffGeHNWKRSU X-Received: by 2002:a17:90a:3189:b0:296:9bc8:c16d with SMTP id j9-20020a17090a318900b002969bc8c16dmr984401pjb.26.1707258784206; Tue, 06 Feb 2024 14:33:04 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXc6fivOnbrdtPy6PSV7U7G5sDFUskyySDlpl9XItR4RSmzcx7WMPVFXScv6FmQATmvQ9oKEViDUfNAso87u1Z0mEqh74yLewWSU9k55Kdg4ukOvCfb2h7wDftWZXIUJ2u2PHzIwashMdbsNPBlEmCqnlDUUc4acxza8JQoQVtzXxOfsw== Received: from daehojeong-desktop.mtv.corp.google.com ([2620:0:1000:8411:6e38:9e6f:4818:7d04]) by smtp.gmail.com with ESMTPSA id n3-20020a170902dc8300b001d6f091ca04sm32371pld.13.2024.02.06.14.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 14:33:03 -0800 (PST) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong , Jaegeuk Kim Subject: [PATCH 1/3] f2fs: separate f2fs_gc_range() to use GC for a range Date: Tue, 6 Feb 2024 14:32:55 -0800 Message-ID: <20240206223257.3461359-1-daeho43@gmail.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790190609708087254 X-GMAIL-MSGID: 1790190609708087254 From: Daeho Jeong Make f2fs_gc_range() an extenal function to use it for GC for a range. Signed-off-by: Daeho Jeong Signed-off-by: Jaegeuk Kim --- fs/f2fs/gc.c | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index a079eebfb080..a46d5053f965 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1983,10 +1983,34 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) init_atgc_management(sbi); } +static int f2fs_gc_range(struct f2fs_sb_info *sbi, + unsigned int start_seg, unsigned int end_seg, bool dry_run) +{ + unsigned int segno; + + for (segno = start_seg; segno <= end_seg; segno += sbi->segs_per_sec) { + struct gc_inode_list gc_list = { + .ilist = LIST_HEAD_INIT(gc_list.ilist), + .iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS), + }; + + do_garbage_collect(sbi, segno, &gc_list, FG_GC, true); + put_gc_inode(&gc_list); + + if (!dry_run && get_valid_blocks(sbi, segno, true)) + return -EAGAIN; + + if (fatal_signal_pending(current)) + return -ERESTARTSYS; + } + + return 0; +} + static int free_segment_range(struct f2fs_sb_info *sbi, - unsigned int secs, bool gc_only) + unsigned int secs, bool dry_run) { - unsigned int segno, next_inuse, start, end; + unsigned int next_inuse, start, end; struct cp_control cpc = { CP_RESIZE, 0, 0, 0 }; int gc_mode, gc_type; int err = 0; @@ -2012,25 +2036,8 @@ static int free_segment_range(struct f2fs_sb_info *sbi, f2fs_allocate_segment_for_resize(sbi, type, start, end); /* do GC to move out valid blocks in the range */ - for (segno = start; segno <= end; segno += sbi->segs_per_sec) { - struct gc_inode_list gc_list = { - .ilist = LIST_HEAD_INIT(gc_list.ilist), - .iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS), - }; - - do_garbage_collect(sbi, segno, &gc_list, FG_GC, true); - put_gc_inode(&gc_list); - - if (!gc_only && get_valid_blocks(sbi, segno, true)) { - err = -EAGAIN; - goto out; - } - if (fatal_signal_pending(current)) { - err = -ERESTARTSYS; - goto out; - } - } - if (gc_only) + err = f2fs_gc_range(sbi, start, end, dry_run); + if (err || dry_run) goto out; stat_inc_cp_call_count(sbi, TOTAL_CALL); From patchwork Tue Feb 6 22:32:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daeho Jeong X-Patchwork-Id: 197667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1862180dyb; Tue, 6 Feb 2024 14:34:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJ3e8Dk/vnOGzETCXegd2CcGMrT43v+vSsLvRKq7e7qzTZ8xC/pNjVUY8nk3wewtFkdaXI X-Received: by 2002:a17:903:124e:b0:1d7:858a:9ee1 with SMTP id u14-20020a170903124e00b001d7858a9ee1mr3336623plh.47.1707258857104; Tue, 06 Feb 2024 14:34:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707258857; cv=pass; d=google.com; s=arc-20160816; b=XB6Ae9QsPWXQd236fMRlvSu1Qv2L4SSBhUp/vQw+WGj5dKrKsvJlf5+mjMVza3E+eg Rjv39bNl6ScHZNkFnoyegj6+jJ2KBjLw7dpMIqqsG608bO7nK9t3cRYikByX/9uxZN+r cDTtRsUsSx3M5F/AYldRQ0Kc0zppB8bvle6lWyzdqWBwuR6KVeTJuhncuYgnBj3r90RP TWor5lRpi7jsqBh9zKPRISc4gygemGSFpBejsV5c1Rv1NdtEXXHDYo4Mp4HTn4zn3hbe KrvdKdr2pOJc/h6h9eky7vG7vnyvE/o3xz0mdYjlLREwujLF9JpdTUjHQeR4ia80GMpC mBFg== ARC-Message-Signature: i=2; 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:dkim-signature; bh=gVd6xrn9TMNrvJaedeT5HJ5aap1fph73205495XGdnA=; fh=mw5H+utJ2Sst1/GRQRWWSmm27NsDFkFxFU/nEPXs6eM=; b=XQvzeXWOvLNrh4ZY5YsIrfH/CbwvyS6PaSaEqZmfRA0myXBFKfgaeFOK5VzIA97I3C lxvarJd/Lm5PKY/sdJKiz6q7Fg1vKx3hjADQrUPa54eOh1cwee9mWStzFvTGMeLyfrpD 4Go89XiZTiGmtOJdUFQEPalNj6Zt2d3rSBJ0Il1Mpwzoshx0Uz7tesVtGID3NaY2DExo suJ7yNbUo44+V4NN2hrxO6vraTJAizcvpGYvg+21haVe1GfQlRv3NSM87wt9EFHmCtdk VZcHyIuooFUrnkElN6JxEskmRkq1ulhU9N8bJj+aJScmVLX/c0fbLcHWQeI1R/E3B0TG DPEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Wf3xVRwd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-55692-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55692-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCXOe21oyoT7Ax3WqQQksVEieiwl4Pw9ndnhNWCYy3K9+58FvOP0Cytj82dz0UgtRfAFhVzWiTkZ9jo2A3X/0AqQoyqdYA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f10-20020a056a001aca00b006e04bccfdefsi8172pfv.138.2024.02.06.14.34.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 14:34:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55692-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Wf3xVRwd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-55692-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55692-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 81809284069 for ; Tue, 6 Feb 2024 22:33:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6AF061CF98; Tue, 6 Feb 2024 22:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wf3xVRwd" Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1E841C2BE for ; Tue, 6 Feb 2024 22:33:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707258789; cv=none; b=k9zUZfaKaahbk31/Wu6ZLwltdiCEI8tq6bPpG07bbEIMj/gfCccV++HAW1+xx8zvU6IZlXIgDp6y4XtBftJsPTGUMfts6/SvlXPEJ+2Jni81oP9gssb4bXfbkziHEGCqIO2D4QBnnoLkYDAqUZ4CGzl74HaVew7zq37Yn5hbYvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707258789; c=relaxed/simple; bh=gfsVpmwhRu8HTKpAYGChUTLFL+Kp+83MHsCmT5S9RM0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g/+mzTPR8I9Mv/5931GZtF0K5F5Ln5DKDl5ly1qBoEU0ykn5GT6vwqHH9ZLw4GCkyDtNCRdb0+7YruPAmSqI+dJTbo3yVO251Hjw4H+qdiiWW1g3QDturpflWCq4loTrP4LwkbPJUOBmkjR9/KaazOXMrnWK9G1qQrVkKr0FLdI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Wf3xVRwd; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1d98fc5ebceso263515ad.1 for ; Tue, 06 Feb 2024 14:33:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707258786; x=1707863586; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gVd6xrn9TMNrvJaedeT5HJ5aap1fph73205495XGdnA=; b=Wf3xVRwdRawsygnOV8han1Ytrdm4/Htgj+cVGUSHAY8Ujc3nxfbwYOtH7BEoqGjPKO C2RjB8HfoyLJKw6vFCxw1hrrlrxkk1EKZ4L8U7emB3BwZny3vLLRSEWa3hi9iQ+nWLcx Dw6wi5w7mvSdvwI1Xf1EQ7UQU9NqOks8LzuXno1/a7J3mcE+GQMVTMVI7U8LHlKuEF7G CpbKUepm2RRXLgsQ/uMcAn4VRbkA3ddhisQouteIpl/Kne/TzAvMC4/9fpcxFvAMKoxk 3tm+CzEmyiIUt1gqssBxJ81y7EMtbnB5VI8KZSSJi5d6zJ4SmPvm5tEM+vs1PilzFTqj lY4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707258786; x=1707863586; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gVd6xrn9TMNrvJaedeT5HJ5aap1fph73205495XGdnA=; b=GO7sQ+CFlaL8Xb9NYs15OfPbFXyfdr/PbkjnwlEnw+iCNl9irP/WaSrOuGTlJ//c4n NuE/tIjZEu2IHE4ahyiNLPSCsLoxc3zB6Pm2JdcqbsJjmHjvoHGz+nMhlXlI0dgsglfV UVmG9QpSWdHQid747cIE7wjTQj5Cye45PhMPwyTg2R0JMGL6zjDksBnzZ9AjFQBBVAhR axD6JTYzl4oYVDSRVjQMdvDig3YRNL2taNdzqycLgdnptLGUboKEVNddACVEJT3jQN8P F7PyD88Z/9UBwFi95HBvTbado72s3l2LKedDkIBfDcIE9MjP/DyfJgyKP7TYOdO44XCY Qeew== X-Gm-Message-State: AOJu0YxdfcpKpW2F8/Hz/U3C6uoB0MhP0AoGdPrng3vXbwMMno+/nUHY 6rSXinWDa9e/pMmBqYs02tBVRdPedNc6PjPG5/nAbXxf57T7zar9mHLlPJTq X-Received: by 2002:a17:902:7406:b0:1d8:ed67:c360 with SMTP id g6-20020a170902740600b001d8ed67c360mr2837481pll.65.1707258785913; Tue, 06 Feb 2024 14:33:05 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV4Y5JNu1CAKFjge2yJIaLgiUcGpSyXnxnZWHumvqm5xHT9aPmENYYvGjRjDJomle+RDUhL1traW2GuUxD6IMxBPfgzV5nhSLXV7kUA1VihvW/trsb0jyhPm/80vAlIw2ex4bfgcYxeGy5Laztoj22+7LdtlTBLSz4YSu0a/RQrfxx5Kg== Received: from daehojeong-desktop.mtv.corp.google.com ([2620:0:1000:8411:6e38:9e6f:4818:7d04]) by smtp.gmail.com with ESMTPSA id n3-20020a170902dc8300b001d6f091ca04sm32371pld.13.2024.02.06.14.33.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 14:33:05 -0800 (PST) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong , Jaegeuk Kim Subject: [PATCH 2/3] f2fs: support file pinning for zoned devices Date: Tue, 6 Feb 2024 14:32:56 -0800 Message-ID: <20240206223257.3461359-2-daeho43@gmail.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240206223257.3461359-1-daeho43@gmail.com> References: <20240206223257.3461359-1-daeho43@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790190663618674620 X-GMAIL-MSGID: 1790190663618674620 From: Daeho Jeong Support file pinning with conventional storage area for zoned devices Signed-off-by: Daeho Jeong Signed-off-by: Jaegeuk Kim --- fs/f2fs/f2fs.h | 14 +++++++++- fs/f2fs/file.c | 24 ++++++++++++---- fs/f2fs/gc.c | 14 +++++++--- fs/f2fs/segment.c | 71 +++++++++++++++++++++++++++++++++++++++++------ fs/f2fs/segment.h | 10 +++++++ 5 files changed, 114 insertions(+), 19 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 543898482f8b..9b8b4d6a0d61 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3708,7 +3708,8 @@ void f2fs_get_new_segment(struct f2fs_sb_info *sbi, unsigned int *newseg, bool new_sec, int dir); void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, unsigned int start, unsigned int end); -void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force); +int f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force); +int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi); void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, @@ -3886,6 +3887,9 @@ void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control); void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); +int f2fs_gc_range(struct f2fs_sb_info *sbi, + unsigned int start_seg, unsigned int end_seg, + bool dry_run, unsigned int dry_run_sections); int f2fs_resize_fs(struct file *filp, __u64 block_count); int __init f2fs_create_garbage_collection_cache(void); void f2fs_destroy_garbage_collection_cache(void); @@ -4540,6 +4544,14 @@ static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi) return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS; } +static inline bool f2fs_valid_pinned_area(struct f2fs_sb_info *sbi, + block_t blkaddr) +{ + int devi = f2fs_target_device_index(sbi, blkaddr); + + return !bdev_is_zoned(FDEV(devi).bdev); +} + static inline bool f2fs_low_mem_mode(struct f2fs_sb_info *sbi) { return F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_LOW; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 25b119cf3499..4078e7616aef 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1735,9 +1735,11 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset, f2fs_down_write(&sbi->pin_sem); - f2fs_lock_op(sbi); - f2fs_allocate_new_section(sbi, CURSEG_COLD_DATA_PINNED, false); - f2fs_unlock_op(sbi); + err = f2fs_allocate_pinning_section(sbi); + if (err) { + f2fs_up_write(&sbi->pin_sem); + goto out_err; + } map.m_seg_type = CURSEG_COLD_DATA_PINNED; err = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_PRE_DIO); @@ -3187,6 +3189,7 @@ int f2fs_pin_file_control(struct inode *inode, bool inc) static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg) { struct inode *inode = file_inode(filp); + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); __u32 pin; int ret = 0; @@ -3196,7 +3199,7 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg) if (!S_ISREG(inode->i_mode)) return -EINVAL; - if (f2fs_readonly(F2FS_I_SB(inode)->sb)) + if (f2fs_readonly(sbi->sb)) return -EROFS; ret = mnt_want_write_file(filp); @@ -3209,9 +3212,18 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg) clear_inode_flag(inode, FI_PIN_FILE); f2fs_i_gc_failures_write(inode, 0); goto done; + } else if (f2fs_is_pinned_file(inode)) { + goto done; } - if (f2fs_should_update_outplace(inode, NULL)) { + if (f2fs_sb_has_blkzoned(sbi) && F2FS_HAS_BLOCKS(inode)) { + ret = -EFBIG; + goto out; + } + + /* Let's allow file pinning on zoned device. */ + if (!f2fs_sb_has_blkzoned(sbi) && + f2fs_should_update_outplace(inode, NULL)) { ret = -EINVAL; goto out; } @@ -3233,7 +3245,7 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg) set_inode_flag(inode, FI_PIN_FILE); ret = F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN]; done: - f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); + f2fs_update_time(sbi, REQ_TIME); out: inode_unlock(inode); mnt_drop_write_file(filp); diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index a46d5053f965..100695540087 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1983,10 +1983,12 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) init_atgc_management(sbi); } -static int f2fs_gc_range(struct f2fs_sb_info *sbi, - unsigned int start_seg, unsigned int end_seg, bool dry_run) +int f2fs_gc_range(struct f2fs_sb_info *sbi, + unsigned int start_seg, unsigned int end_seg, + bool dry_run, unsigned int dry_run_sections) { unsigned int segno; + unsigned int gc_secs = dry_run_sections; for (segno = start_seg; segno <= end_seg; segno += sbi->segs_per_sec) { struct gc_inode_list gc_list = { @@ -1994,11 +1996,15 @@ static int f2fs_gc_range(struct f2fs_sb_info *sbi, .iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS), }; - do_garbage_collect(sbi, segno, &gc_list, FG_GC, true); + do_garbage_collect(sbi, segno, &gc_list, FG_GC, + dry_run_sections == 0); put_gc_inode(&gc_list); if (!dry_run && get_valid_blocks(sbi, segno, true)) return -EAGAIN; + if (dry_run && dry_run_sections && + !get_valid_blocks(sbi, segno, true) && --gc_secs == 0) + break; if (fatal_signal_pending(current)) return -ERESTARTSYS; @@ -2036,7 +2042,7 @@ static int free_segment_range(struct f2fs_sb_info *sbi, f2fs_allocate_segment_for_resize(sbi, type, start, end); /* do GC to move out valid blocks in the range */ - err = f2fs_gc_range(sbi, start, end, dry_run); + err = f2fs_gc_range(sbi, start, end, dry_run, 0); if (err || dry_run) goto out; diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 7901ede58113..7d5e9476d8d5 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2640,7 +2640,8 @@ static int is_next_segment_free(struct f2fs_sb_info *sbi, * This function should be returned with success, otherwise BUG */ static void get_new_segment(struct f2fs_sb_info *sbi, - unsigned int *newseg, bool new_sec, int dir) + unsigned int *newseg, bool new_sec, int dir, + bool pinning) { struct free_segmap_info *free_i = FREE_I(sbi); unsigned int segno, secno, zoneno; @@ -2660,6 +2661,17 @@ static void get_new_segment(struct f2fs_sb_info *sbi, if (segno < GET_SEG_FROM_SEC(sbi, hint + 1)) goto got_it; } + + /* + * If we format f2fs on zoned storage, let's try to get pinned sections + * from beginning of the storage, which should be a conventional one. + */ + if (f2fs_sb_has_blkzoned(sbi)) { + segno = pinning ? + 0 : max(first_zoned_segno(sbi), *newseg); + left_start = hint = GET_SEC_FROM_SEG(sbi, segno); + } + find_other_zone: secno = find_next_zero_bit(free_i->free_secmap, MAIN_SECS(sbi), hint); if (secno >= MAIN_SECS(sbi)) { @@ -2788,12 +2800,13 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type) * Allocate a current working segment. * This function always allocates a free segment in LFS manner. */ -static void new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) +static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) { struct curseg_info *curseg = CURSEG_I(sbi, type); unsigned short seg_type = curseg->seg_type; unsigned int segno = curseg->segno; int dir = ALLOC_LEFT; + bool pinning = type == CURSEG_COLD_DATA_PINNED; if (curseg->inited) write_sum_page(sbi, curseg->sum_blk, @@ -2805,13 +2818,21 @@ static void new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) dir = ALLOC_RIGHT; segno = __get_next_segno(sbi, type); - get_new_segment(sbi, &segno, new_sec, dir); + get_new_segment(sbi, &segno, new_sec, dir, pinning); + + if (new_sec && pinning && + !f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) { + __set_free(sbi, segno); + return -EAGAIN; + } + curseg->next_segno = segno; reset_curseg(sbi, type, 1); curseg->alloc_type = LFS; if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) curseg->fragment_remained_chunk = get_random_u32_inclusive(1, sbi->max_fragment_chunk); + return 0; } static int __next_free_blkoff(struct f2fs_sb_info *sbi, @@ -3084,7 +3105,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, f2fs_up_read(&SM_I(sbi)->curseg_lock); } -static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type, +static int __allocate_new_segment(struct f2fs_sb_info *sbi, int type, bool new_sec, bool force) { struct curseg_info *curseg = CURSEG_I(sbi, type); @@ -3094,21 +3115,49 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type, !curseg->next_blkoff && !get_valid_blocks(sbi, curseg->segno, new_sec) && !get_ckpt_valid_blocks(sbi, curseg->segno, new_sec)) - return; + return 0; old_segno = curseg->segno; - new_curseg(sbi, type, true); + if (new_curseg(sbi, type, true)) + return -EAGAIN; stat_inc_seg_type(sbi, curseg); locate_dirty_segment(sbi, old_segno); + return 0; } -void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force) +int f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force) { + int ret; + f2fs_down_read(&SM_I(sbi)->curseg_lock); down_write(&SIT_I(sbi)->sentry_lock); - __allocate_new_segment(sbi, type, true, force); + ret = __allocate_new_segment(sbi, type, true, force); up_write(&SIT_I(sbi)->sentry_lock); f2fs_up_read(&SM_I(sbi)->curseg_lock); + + return ret; +} + +int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) +{ + int err; + bool gc_required = true; + +retry: + f2fs_lock_op(sbi); + err = f2fs_allocate_new_section(sbi, CURSEG_COLD_DATA_PINNED, false); + f2fs_unlock_op(sbi); + + if (f2fs_sb_has_blkzoned(sbi) && err && gc_required) { + f2fs_down_write(&sbi->gc_lock); + f2fs_gc_range(sbi, 0, GET_SEGNO(sbi, FDEV(0).end_blk), true, 1); + f2fs_up_write(&sbi->gc_lock); + + gc_required = false; + goto retry; + } + + return err; } void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi) @@ -3474,6 +3523,10 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, * new segment. */ if (segment_full) { + if (type == CURSEG_COLD_DATA_PINNED && + !((curseg->segno + 1) % sbi->segs_per_sec)) + goto skip_new_segment; + if (from_gc) { get_atssr_segment(sbi, type, se->type, AT_SSR, se->mtime); @@ -3485,6 +3538,8 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, stat_inc_seg_type(sbi, curseg); } } + +skip_new_segment: /* * segment dirty status should be updated after segment allocation, * so we just need to update status only one time after previous diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 8129be788bd5..8b6996ddc9ba 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -969,3 +969,13 @@ static inline void wake_up_discard_thread(struct f2fs_sb_info *sbi, bool force) dcc->discard_wake = true; wake_up_interruptible_all(&dcc->discard_wait_queue); } + +static inline unsigned int first_zoned_segno(struct f2fs_sb_info *sbi) +{ + int devi; + + for (devi = 0; devi < sbi->s_ndevs; devi++) + if (bdev_is_zoned(FDEV(devi).bdev)) + return GET_SEGNO(sbi, FDEV(devi).start_blk); + return 0; +} From patchwork Tue Feb 6 22:32:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daeho Jeong X-Patchwork-Id: 197666 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1861967dyb; Tue, 6 Feb 2024 14:33:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxYtE3QHWqFqYq5hgpQb/xiH4u84NJLXM0bN7skBSa3n+yRCCCxV9xPOw39JKIOObNMS9B X-Received: by 2002:a17:90b:4f82:b0:296:51f0:53e5 with SMTP id qe2-20020a17090b4f8200b0029651f053e5mr945184pjb.30.1707258829835; Tue, 06 Feb 2024 14:33:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707258829; cv=pass; d=google.com; s=arc-20160816; b=QnN3mrWptg1YUAiv1ZHyadZuGpsw/bAbusfZWlqSwmMoNzC4pQCx8NwLh+x5vmxFJd wqlFVu10B9ObXQvb3pW7rMNRpXANfaeSSr5WWtPEw3sLSbsv8ajfXsTqKUEVwOWd6oB8 KG2HjYRoRAphOmvQGTEgvWwpNdTnlwUzhgfZ4OLEa7gEAV5RRsEXuVIAH+vjz6qcZX/Z /UMo24ahin8w1WjQz/d/tYkOHhjXZY4fbGGWk4lqN+1wPm89knU4ur2O/A7jmJxrAYr3 IslsUuxFoWn6FLEKzS85Q8+ZO95KzQC4slkSQfMVVaMuiruRKQBQHBkmepFIPQFIYXIN lFFQ== ARC-Message-Signature: i=2; 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:dkim-signature; bh=wX4f3WxNax0yrGD3k4jTwh/vCGQc2wn1RTN07jtNKD0=; fh=VhfCUje6gMigQwh9izVCU0rUzvpZQXMj6LnI6Rl5u4A=; b=D5qRmUw9XkMRBoWWr4q4rM/Mjr5olTJwAsYOmrrwpMisb4jyzqVQFcTXVdKCrsvfw0 E2C5OmLBB2fFJQmQNqvFrnvconZkw5eKdpMx8+PiQPGQ31BmdDHPOz9Y/tfwCXFFMx2+ 7Bjev3QjGzaVBJEErEF5uMVX/sQN1rZnU95k6+UTyq+w+jNBM2s4mEn8+vGCqblpMufS AoNTXxuHu0JNmBeyKZ6yav1VJB1SFsHjW1Qj8BkWkuD8mDQiTE3LDeMHATeA68zZ64NP NfLYPY9d71AMlA2QdZ2sY/8mG/B/pLV3aNlYM7P8IRamYagiQ7fcXfo1PKDvEaidiNlf RwzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DSFz46fx; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-55693-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55693-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCXHoRHctWaS/YQJSymOnNnkqqe0e6+mYOzHD40CGfu+s//b7ceZB4ErERcQ8Av1G+JtkUe39WNrSJ+PEuwYENz9w716GA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id my12-20020a17090b4c8c00b00296a5ca1a5asi49581pjb.66.2024.02.06.14.33.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 14:33:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55693-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DSFz46fx; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-55693-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55693-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 91058288E8D for ; Tue, 6 Feb 2024 22:33:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 584C81CF89; Tue, 6 Feb 2024 22:33:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DSFz46fx" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83E401C694 for ; Tue, 6 Feb 2024 22:33:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707258790; cv=none; b=E9OqfTWT1WqlUSWOX8W+Gxvv3kfclLKV65rMMmlX+HeZqV3H35veewRAqUKQMNO6QlvrTU48UFDb9ervok/c1Cwn+o7afPpvNSovPM7G+ElYsPpRVH1qjM2L9FhhJwdATjhXdOMd99TV8Aa3nT4+cFcjwV9ytW7Y3k56L1oPNQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707258790; c=relaxed/simple; bh=VPLzgYSU/JVdj5M5bhzldmNLypV0tiHKJ2uCNlyny0Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rXsNtcRnCTkHvnbo/11fpZCFgrZx0u/WbuZWAQxTW2qewpmP8c/cBWcm4RV4dhdtefgM2YfQfiGpYRrNOVZTGpj9v/FBFfYb0Xz7Z8VZgWydl8Kc0Vz+c4HdYIfA2B83ZyMhROzXd1F+yAGj6ao9wmR3Utbx5vaDoSvZWuILFFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DSFz46fx; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1d71cb97937so246965ad.3 for ; Tue, 06 Feb 2024 14:33:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707258787; x=1707863587; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wX4f3WxNax0yrGD3k4jTwh/vCGQc2wn1RTN07jtNKD0=; b=DSFz46fxEkyrlL98sGiICCWHGTkY4gRRgDBUOCQ89IFJ4W8ElymPsqvMTFReUKlWnu IACO9JLCepWYHDcEqxDMohcsu0wglNvTAa9u9Q72L6Y261zHQNPqO8nxIOdSd0zDNlGj M/rU4d+LPgeYZWljAP/1/VgD68UL6hJvuso/wJfnQOktBFPlmZdIscHNendMr/j8b20+ HI/ZaXWszb35RsUt0y1tbYKbzg7PT7E628Zb6e5t1icwZHAAGofakjC77I/q1Ep7T3Ep NqbfvvtXxbG1fSDPj64qHOD2kEGvAOIz9pte7Ua3JByi5kt6w8P5iengPCx25ab6AMiR Xc7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707258787; x=1707863587; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wX4f3WxNax0yrGD3k4jTwh/vCGQc2wn1RTN07jtNKD0=; b=Q60qiNC6OHlR/a/JnLxIZ5YGPv3C+GPXiPjuk/ZMf7oM01GUA4TNJ/7nEyIcmvPjFO tAQets+JaGaYWV4UoatkSbfg2EUuXgNSWq5mkWA6HPAP3fU7EMVqvuVThX+7oqSxgfVU SIq5ivXnlBLZFX/fJ4Au3Frucq5Y9wv0SjO94j2LRO14xHzm5y6Dru4tdQQBb4wRSHuz Q+MapjgLGgz+rKPnS4nQVCbyLhGZ2YtAtE4yKS37BG5tNpZPIbq6SvNigTx7wRMu6Fad WpGZPECrHgAdJi4eF98GqM/+ykK/pRgvvNdpSBJPquIPKT4q4w8LCoYZeD9dn4TWWFaC toig== X-Gm-Message-State: AOJu0YyngGU9fSd2kzn/hoL2HlmnVdDwpJIB1sf8c0xrzuG49xkHWQIa Sj6C6k2m0v+eJO+p/UT+V1F07HWxmnF8+VgzXsk6/Q1ZeYaTKc3ZBtxkpv7z X-Received: by 2002:a17:903:2384:b0:1d9:8082:4577 with SMTP id v4-20020a170903238400b001d980824577mr3344088plh.17.1707258787618; Tue, 06 Feb 2024 14:33:07 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWNOpv8rOlo8TCfKwGJroovU1eMRu/KL1OCxn0n6wFaqz2gpI03/r7Ik9ituO9iOkDmBfExo3HmdF8WGKPcQlzMfLaUKv2vKHK0FNi2YE712lJG3vIPdR2lz8FWF9XBbyAsJDN4/lSxOkQiHWVPb9smRXq3yc5MitIO5BvQiwkX8yBcfg== Received: from daehojeong-desktop.mtv.corp.google.com ([2620:0:1000:8411:6e38:9e6f:4818:7d04]) by smtp.gmail.com with ESMTPSA id n3-20020a170902dc8300b001d6f091ca04sm32371pld.13.2024.02.06.14.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 14:33:07 -0800 (PST) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong , Jaegeuk Kim Subject: [PATCH 3/3] f2fs: support swap file pinning for zoned devices Date: Tue, 6 Feb 2024 14:32:57 -0800 Message-ID: <20240206223257.3461359-3-daeho43@gmail.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240206223257.3461359-1-daeho43@gmail.com> References: <20240206223257.3461359-1-daeho43@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790190634354364250 X-GMAIL-MSGID: 1790190634354364250 From: Daeho Jeong Support swap file pinning for zoned devices Signed-off-by: Daeho Jeong Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 54 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 05158f89ef32..5d8ee6e73dbe 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3905,28 +3905,40 @@ static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk, unsigned int blkcnt) { struct f2fs_sb_info *sbi = F2FS_I_SB(inode); + struct f2fs_map_blocks map = { .m_next_pgofs = NULL, + .m_next_extent = NULL, .m_seg_type = CURSEG_COLD_DATA_PINNED, + .m_may_create = true }; unsigned int blkofs; unsigned int blk_per_sec = BLKS_PER_SEC(sbi); unsigned int secidx = start_blk / blk_per_sec; - unsigned int end_sec = secidx + blkcnt / blk_per_sec; + unsigned int end_sec; int ret = 0; + if (!blkcnt) + return 0; + end_sec = secidx + (blkcnt - 1) / blk_per_sec; + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); filemap_invalidate_lock(inode->i_mapping); set_inode_flag(inode, FI_ALIGNED_WRITE); set_inode_flag(inode, FI_OPU_WRITE); - for (; secidx < end_sec; secidx++) { + for (; secidx <= end_sec; secidx++) { + unsigned int blkofs_end = secidx == end_sec ? + (blkcnt - 1) % blk_per_sec : blk_per_sec - 1; + f2fs_down_write(&sbi->pin_sem); - f2fs_lock_op(sbi); - f2fs_allocate_new_section(sbi, CURSEG_COLD_DATA_PINNED, false); - f2fs_unlock_op(sbi); + ret = f2fs_allocate_pinning_section(sbi); + if (ret) { + f2fs_up_write(&sbi->pin_sem); + break; + } set_inode_flag(inode, FI_SKIP_WRITES); - for (blkofs = 0; blkofs < blk_per_sec; blkofs++) { + for (blkofs = 0; blkofs <= blkofs_end; blkofs++) { struct page *page; unsigned int blkidx = secidx * blk_per_sec + blkofs; @@ -3944,6 +3956,12 @@ static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk, clear_inode_flag(inode, FI_SKIP_WRITES); ret = filemap_fdatawrite(inode->i_mapping); + if (!ret && blkofs != blk_per_sec) { + map.m_lblk = secidx * blk_per_sec + blkofs; + map.m_len = blk_per_sec - blkofs; + ret = f2fs_map_blocks(inode, &map, + F2FS_GET_BLOCK_PRE_DIO); + } f2fs_up_write(&sbi->pin_sem); @@ -4015,19 +4033,17 @@ static int check_swap_activate(struct swap_info_struct *sis, nr_pblocks = map.m_len; if ((pblock - SM_I(sbi)->main_blkaddr) & sec_blks_mask || - nr_pblocks & sec_blks_mask) { + nr_pblocks & sec_blks_mask || + !f2fs_valid_pinned_area(sbi, pblock)) { not_aligned++; nr_pblocks = roundup(nr_pblocks, blks_per_sec); if (cur_lblock + nr_pblocks > sis->max) nr_pblocks -= blks_per_sec; - if (!nr_pblocks) { - /* this extent is last one */ - nr_pblocks = map.m_len; - f2fs_warn(sbi, "Swapfile: last extent is not aligned to section"); - goto next; - } + /* this extent is last one */ + if (!nr_pblocks) + nr_pblocks = last_lblock - cur_lblock; ret = f2fs_migrate_blocks(inode, cur_lblock, nr_pblocks); @@ -4035,7 +4051,7 @@ static int check_swap_activate(struct swap_info_struct *sis, goto out; goto retry; } -next: + if (cur_lblock + nr_pblocks >= sis->max) nr_pblocks = sis->max - cur_lblock; @@ -4073,17 +4089,17 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file, sector_t *span) { struct inode *inode = file_inode(file); + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); int ret; if (!S_ISREG(inode->i_mode)) return -EINVAL; - if (f2fs_readonly(F2FS_I_SB(inode)->sb)) + if (f2fs_readonly(sbi->sb)) return -EROFS; - if (f2fs_lfs_mode(F2FS_I_SB(inode))) { - f2fs_err(F2FS_I_SB(inode), - "Swapfile not supported in LFS mode"); + if (f2fs_lfs_mode(sbi) && !f2fs_sb_has_blkzoned(sbi)) { + f2fs_err(sbi, "Swapfile not supported in LFS mode"); return -EINVAL; } @@ -4102,7 +4118,7 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file, stat_inc_swapfile_inode(inode); set_inode_flag(inode, FI_PIN_FILE); - f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); + f2fs_update_time(sbi, REQ_TIME); return ret; }