From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2310170809 for ; Thu, 16 Jan 2025 03:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736997293; cv=none; b=aO2RPG74rA/pulcM6x/sHcNo00nqrT+7kMPj7bmUfzET3VmHKsJg7aBU1WCEP4OTHG1vtag3yGIe0JfVkc3uRbjf4jY2p7IliAw8i546D/cVf3VS0WWHdPcZLENsnz99QqQs8nJI2iC1JO3RUIBFTyr2tNfWvA+wSkh8XL/OnFc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736997293; c=relaxed/simple; bh=3OHLqz3k45PS/p9b3DQZ48WfOOiekdCo5FnVBqm3RLk=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=ga8cqVmpC2YGafI0eINsIS4SLWcDUsS4p2qhTO17sPs42+dwvd7Q/rlCuvgUQZL3GtREhLEiPPueNUKDSu5axjhq7fiiJwr8I76o9ewzkjyA2jopvY6pVKHW8OBw0/VNwE5bLG/hB6rbUGP9fspfTRVQELgQyrnMKCEMS/UPQvw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sfyivdce; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Sfyivdce" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D410BC4CED1; Thu, 16 Jan 2025 03:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736997292; bh=3OHLqz3k45PS/p9b3DQZ48WfOOiekdCo5FnVBqm3RLk=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=SfyivdcesoTnCQenfjKd5vdJsz3oMXRNvKyugHhEwzOy7vghyMRG7ZZdQaUk8zhJS 54aOT38ITeXlgfnbZJtUKBnds9T1U/soeG97JX6Rmg0mE4bN1RxGiRaKlLRTat6vdE I4FiPIIYxjCmiMPDLtgSLfhA4E1fds3xXURgvf2AjOKwrvXDbZ4SIdC4GA+KKJYch1 lQDtC3ayANwWIVPC/wzDIDU9l32qdfvUuoNF1SJsfZN4HkchqkhRZ++B3ac4sHc6KY 5vXIUZjM+i90FdY5SPF5QUKPhIyeigds5IqT2GJsAaQgoykG6Fnr5clyNT12Y91PWc f9Dip+2CL+efQ== Message-ID: Date: Thu, 16 Jan 2025 11:14:49 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org Subject: Re: [f2fs-dev] [PATCH 2/2] f2fs: add a sysfs entry to request donate file-backed pages To: Jaegeuk Kim , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net References: <20250115221814.1920703-1-jaegeuk@kernel.org> <20250115221814.1920703-3-jaegeuk@kernel.org> Content-Language: en-US From: Chao Yu In-Reply-To: <20250115221814.1920703-3-jaegeuk@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/16/25 06:16, Jaegeuk Kim via Linux-f2fs-devel wrote: > 1. ioctl(fd1, F2FS_IOC_DONATE_RANGE, {0,3}); > 2. ioctl(fd2, F2FS_IOC_DONATE_RANGE, {1,2}); > 3. ioctl(fd3, F2FS_IOC_DONATE_RANGE, {3,1}); > 4. echo 3 > /sys/fs/f2fs/blk/donate_caches > > will reclaim 3 page cache ranges, registered by #1, #2, and #3. > > Signed-off-by: Jaegeuk Kim > --- > Documentation/ABI/testing/sysfs-fs-f2fs | 7 +++++++ > fs/f2fs/f2fs.h | 2 ++ > fs/f2fs/shrinker.c | 27 +++++++++++++++++++++++++ > fs/f2fs/sysfs.c | 8 ++++++++ > 4 files changed, 44 insertions(+) > > diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs > index 3e1630c70d8a..6f9d8b8889fd 100644 > --- a/Documentation/ABI/testing/sysfs-fs-f2fs > +++ b/Documentation/ABI/testing/sysfs-fs-f2fs > @@ -828,3 +828,10 @@ Date: November 2024 > Contact: "Chao Yu" > Description: It controls max read extent count for per-inode, the value of threshold > is 10240 by default. > + > +What: /sys/fs/f2fs//donate_caches > +Date: December 2024 > +Contact: "Jaegeuk Kim" > +Description: It reclaims the certian file-backed pages registered by > + ioctl(F2FS_IOC_DONATE_RANGE). > + For example, writing N tries to drop N address spaces in LRU. > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 951fbc3f94c7..399ddd10a94f 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -1637,6 +1637,7 @@ struct f2fs_sb_info { > > /* control donate caches */ > unsigned int donate_files; > + unsigned int donate_caches; > > /* basic filesystem units */ > unsigned int log_sectors_per_block; /* log2 sectors per block */ > @@ -4259,6 +4260,7 @@ unsigned long f2fs_shrink_count(struct shrinker *shrink, > struct shrink_control *sc); > unsigned long f2fs_shrink_scan(struct shrinker *shrink, > struct shrink_control *sc); > +void f2fs_donate_caches(struct f2fs_sb_info *sbi); > void f2fs_join_shrinker(struct f2fs_sb_info *sbi); > void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); > > diff --git a/fs/f2fs/shrinker.c b/fs/f2fs/shrinker.c > index 83d6fb97dcae..22f62813910b 100644 > --- a/fs/f2fs/shrinker.c > +++ b/fs/f2fs/shrinker.c > @@ -130,6 +130,33 @@ unsigned long f2fs_shrink_scan(struct shrinker *shrink, > return freed; > } > > +void f2fs_donate_caches(struct f2fs_sb_info *sbi) > +{ > + struct inode *inode; > + struct f2fs_inode_info *fi; > + int nfiles = sbi->donate_caches; > + > + while (nfiles--) { > + spin_lock(&sbi->inode_lock[DONATE_INODE]); > + if (list_empty(&sbi->inode_list[DONATE_INODE])) { > + spin_unlock(&sbi->inode_lock[DONATE_INODE]); > + break; > + } > + fi = list_first_entry(&sbi->inode_list[DONATE_INODE], > + struct f2fs_inode_info, gdonate_list); > + list_move_tail(&fi->gdonate_list, &sbi->inode_list[DONATE_INODE]); > + inode = igrab(&fi->vfs_inode); > + spin_unlock(&sbi->inode_lock[DONATE_INODE]); > + > + if (!inode) > + continue; > + > + invalidate_inode_pages2_range(inode->i_mapping, > + fi->donate_start, fi->donate_end); fi->donate_start and fi->donate_end can be updated in ioctl concurrently and become inconsistent here, is it fine? Thanks, > + iput(inode); > + } > +} > + > void f2fs_join_shrinker(struct f2fs_sb_info *sbi) > { > spin_lock(&f2fs_list_lock); > diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c > index 6b99dc49f776..f81190fabdd3 100644 > --- a/fs/f2fs/sysfs.c > +++ b/fs/f2fs/sysfs.c > @@ -811,6 +811,12 @@ static ssize_t __sbi_store(struct f2fs_attr *a, > return count; > } > > + if (!strcmp(a->attr.name, "donate_caches")) { > + sbi->donate_caches = min(t, sbi->donate_files); > + f2fs_donate_caches(sbi); > + return count; > + } > + > *ui = (unsigned int)t; > > return count; > @@ -1030,6 +1036,7 @@ F2FS_SBI_GENERAL_RW_ATTR(max_victim_search); > F2FS_SBI_GENERAL_RW_ATTR(migration_granularity); > F2FS_SBI_GENERAL_RW_ATTR(migration_window_granularity); > F2FS_SBI_GENERAL_RW_ATTR(dir_level); > +F2FS_SBI_GENERAL_RW_ATTR(donate_caches); > #ifdef CONFIG_F2FS_IOSTAT > F2FS_SBI_GENERAL_RW_ATTR(iostat_enable); > F2FS_SBI_GENERAL_RW_ATTR(iostat_period_ms); > @@ -1178,6 +1185,7 @@ static struct attribute *f2fs_attrs[] = { > ATTR_LIST(migration_granularity), > ATTR_LIST(migration_window_granularity), > ATTR_LIST(dir_level), > + ATTR_LIST(donate_caches), > ATTR_LIST(ram_thresh), > ATTR_LIST(ra_nid_pages), > ATTR_LIST(dirty_nats_ratio),