mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
Pull f2fs updates from Jaegeuk Kim: "In this round, we introduce sysfile-based quota support which is required for Android by default. In addition, we allow that users are able to reserve some blocks in runtime to mitigate performance drops in low free space. Enhancements: - assign proper data segments according to write_hints given by user - issue cache_flush on dirty devices only among multiple devices - exploit cp_error flag and add more faults to enhance fault injection test - conduct more readaheads during f2fs_readdir - add a range for discard commands Bug fixes: - fix zero stat->st_blocks when inline_data is set - drop crypto key and free stale memory pointer while evict_inode is failing - fix some corner cases in free space and segment management - fix wrong last_disk_size This series includes lots of clean-ups and code enhancement in terms of xattr operations, discard/flush command control. In addition, it adds versatile debugfs entries to monitor f2fs status" Cherry-picked from origin/upstream-f2fs-stable-linux-4.14.y: 7b538c1c32e1 f2fs: deny accessing encryption policy if encryption is off c43ffa1881bc f2fs: inject fault in inc_valid_node_count fa73e8745557 f2fs: expose quota information in debugfs eb538327e573 f2fs: separate nat entry mem alloc from nat_tree_lock a7c6829c1c38 f2fs: validate before set/clear free nat bitmap eb84a567f686 f2fs: avoid opened loop codes in __add_ino_entry 793cdb935708 f2fs: apply write hints to select the type of segments for buffered write 75a69567eefc f2fs: introduce scan_curseg_cache for cleanup 6180b68c28c0 f2fs: optimize the way of traversing free_nid_bitmap 221656e4b864 f2fs: keep scanning until enough free nids are acquired 0b0a1e72b5d5 f2fs: trace checkpoint reason in fsync() af75a621ef34 f2fs: keep isize once block is reserved cross EOF 3b96799dba53 f2fs: avoid race in between GC and block exchange c33a70d7192d f2fs: save a multiplication for last_nid calculation 4c8fdcd5d79e f2fs: fix summary info corruption ff95a94dd04c f2fs: remove dead code in update_meta_page c7f08b508dc6 f2fs: remove unneeded semicolon 91d560341eab f2fs: don't bother with inode->i_version 270e78cfc169 f2fs: check curseg space before foreground GC d3ad907d7caa f2fs: use rw_semaphore to protect SIT cache d9e1a6b6966b f2fs: support quota sys files 3aec74eb20fe f2fs: add quota_ino feature infra cf9435582aae f2fs: optimize __update_nat_bits e56a876fd562 f2fs: modify for accurate fggc node io stat a39d96b9a10c Revert "f2fs: handle dirty segments inside refresh_sit_entry" 0ccccb3839f5 f2fs: add a function to move nid cd3b86fce8dd f2fs: export SSR allocation threshold ca50229b7ef5 f2fs: give correct trimmed blocks in fstrim 73b8db889f80 f2fs: support bio allocation error injection b8a938e4f875 f2fs: support get_page error injection f2b91f22a9a2 f2fs: add missing sysfs description 6cef55704e9e f2fs: support soft block reservation cef5e7165c08 f2fs: handle error case when adding xattr entry a7848c0dee2c f2fs: support flexible inline xattr size c63143060c45 f2fs: show current cp state 032d140917f9 f2fs: add missing quota_initialize f241f66c3aee f2fs: show # of dirty segments via sysfs 1687d9f07bc3 f2fs: stop all the operations by cp_error flag f793a2c291f9 f2fs: remove several redundant assignments fb000836b122 f2fs: avoid using timespec a4b9ed205158 f2fs: fix to correct no_fggc_candidate bc69d5602412 Revert "f2fs: return wrong error number on f2fs_quota_write" f49f4124b02e f2fs: remove obsolete pointer for truncate_xattr_node c6bfa17c9fc4 f2fs: retry ENOMEM for quota_read|write 5e14327f2573 f2fs: limit # of inmemory pages a064458a6d7d f2fs: update ctx->pos correctly when hitting hole in directory 372b93f94f7e f2fs: relocate readahead codes in readdir() 457e9c032c4a f2fs: allow readdir() to be interrupted 2d1af27c57f9 f2fs: trace f2fs_readdir 7bbdc74b724a f2fs: trace f2fs_lookup 76e8f60644aa f2fs: skip searching non-exist range in truncate_hole 2f18884d3c65 f2fs: avoid stale fi->gdirty_list pointer 0dbf4fd41748 f2fs/crypto: drop crypto key at evict_inode only 8c5827634ad6 f2fs: fix to avoid race when accessing last_disk_size c2e2eec698e2 f2fs: Fix bool initialization/comparison ab0a7977c988 f2fs: give up CP_TRIMMED_FLAG if it drops discards 001cc0b0c526 f2fs: trace f2fs_remove_discard c72699d2320d f2fs: reduce cmd_lock coverage in __issue_discard_cmd 0eeceeb20671 f2fs: split discard policy 775d0e58bb72 f2fs: wrap discard policy 77b5bf3aaf14 f2fs: support issuing/waiting discard in range 6b50d3ec7d11 f2fs: fix to flush multiple device in checkpoint 5483b178450e f2fs: enhance multiple device flush 06800576e497 f2fs: fix to show ino management cache size correctly a815ce9938f4 f2fs: drop FI_UPDATE_WRITE tag after f2fs_issue_flush 3257c6570745 f2fs: obsolete ALLOC_NID_LIST list d54bf9da4f50 f2fs: convert inline data for direct I/O & FI_NO_PREALLOC 32c57300f669 f2fs: allow readpages with NULL file pointer dba2b4548cf9 f2fs: show flush list status in sysfs fae7dc47bdda f2fs: introduce read_xattr_block 148edd027e9c f2fs: introduce read_inline_xattr b735df5e29d1 Revert "f2fs: reuse nids more aggressively" 13e34cbab66f Revert "f2fs: node segment is prior to data segment selected victim" a76d81af17ce f2fs: fix to clear FI_NO_PREALLOC Bug: 70801385 Change-Id: I3b8e0c21f4f8d52b669776fce41df77a4363d473 Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
144 lines
3.3 KiB
C
144 lines
3.3 KiB
C
/*
|
|
* f2fs shrinker support
|
|
* the basic infra was copied from fs/ubifs/shrinker.c
|
|
*
|
|
* Copyright (c) 2015 Motorola Mobility
|
|
* Copyright (c) 2015 Jaegeuk Kim <jaegeuk@kernel.org>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
#include <linux/fs.h>
|
|
#include <linux/f2fs_fs.h>
|
|
|
|
#include "f2fs.h"
|
|
#include "node.h"
|
|
|
|
static LIST_HEAD(f2fs_list);
|
|
static DEFINE_SPINLOCK(f2fs_list_lock);
|
|
static unsigned int shrinker_run_no;
|
|
|
|
static unsigned long __count_nat_entries(struct f2fs_sb_info *sbi)
|
|
{
|
|
long count = NM_I(sbi)->nat_cnt - NM_I(sbi)->dirty_nat_cnt;
|
|
|
|
return count > 0 ? count : 0;
|
|
}
|
|
|
|
static unsigned long __count_free_nids(struct f2fs_sb_info *sbi)
|
|
{
|
|
long count = NM_I(sbi)->nid_cnt[FREE_NID] - MAX_FREE_NIDS;
|
|
|
|
return count > 0 ? count : 0;
|
|
}
|
|
|
|
static unsigned long __count_extent_cache(struct f2fs_sb_info *sbi)
|
|
{
|
|
return atomic_read(&sbi->total_zombie_tree) +
|
|
atomic_read(&sbi->total_ext_node);
|
|
}
|
|
|
|
unsigned long f2fs_shrink_count(struct shrinker *shrink,
|
|
struct shrink_control *sc)
|
|
{
|
|
struct f2fs_sb_info *sbi;
|
|
struct list_head *p;
|
|
unsigned long count = 0;
|
|
|
|
spin_lock(&f2fs_list_lock);
|
|
p = f2fs_list.next;
|
|
while (p != &f2fs_list) {
|
|
sbi = list_entry(p, struct f2fs_sb_info, s_list);
|
|
|
|
/* stop f2fs_put_super */
|
|
if (!mutex_trylock(&sbi->umount_mutex)) {
|
|
p = p->next;
|
|
continue;
|
|
}
|
|
spin_unlock(&f2fs_list_lock);
|
|
|
|
/* count extent cache entries */
|
|
count += __count_extent_cache(sbi);
|
|
|
|
/* shrink clean nat cache entries */
|
|
count += __count_nat_entries(sbi);
|
|
|
|
/* count free nids cache entries */
|
|
count += __count_free_nids(sbi);
|
|
|
|
spin_lock(&f2fs_list_lock);
|
|
p = p->next;
|
|
mutex_unlock(&sbi->umount_mutex);
|
|
}
|
|
spin_unlock(&f2fs_list_lock);
|
|
return count;
|
|
}
|
|
|
|
unsigned long f2fs_shrink_scan(struct shrinker *shrink,
|
|
struct shrink_control *sc)
|
|
{
|
|
unsigned long nr = sc->nr_to_scan;
|
|
struct f2fs_sb_info *sbi;
|
|
struct list_head *p;
|
|
unsigned int run_no;
|
|
unsigned long freed = 0;
|
|
|
|
spin_lock(&f2fs_list_lock);
|
|
do {
|
|
run_no = ++shrinker_run_no;
|
|
} while (run_no == 0);
|
|
p = f2fs_list.next;
|
|
while (p != &f2fs_list) {
|
|
sbi = list_entry(p, struct f2fs_sb_info, s_list);
|
|
|
|
if (sbi->shrinker_run_no == run_no)
|
|
break;
|
|
|
|
/* stop f2fs_put_super */
|
|
if (!mutex_trylock(&sbi->umount_mutex)) {
|
|
p = p->next;
|
|
continue;
|
|
}
|
|
spin_unlock(&f2fs_list_lock);
|
|
|
|
sbi->shrinker_run_no = run_no;
|
|
|
|
/* shrink extent cache entries */
|
|
freed += f2fs_shrink_extent_tree(sbi, nr >> 1);
|
|
|
|
/* shrink clean nat cache entries */
|
|
if (freed < nr)
|
|
freed += try_to_free_nats(sbi, nr - freed);
|
|
|
|
/* shrink free nids cache entries */
|
|
if (freed < nr)
|
|
freed += try_to_free_nids(sbi, nr - freed);
|
|
|
|
spin_lock(&f2fs_list_lock);
|
|
p = p->next;
|
|
list_move_tail(&sbi->s_list, &f2fs_list);
|
|
mutex_unlock(&sbi->umount_mutex);
|
|
if (freed >= nr)
|
|
break;
|
|
}
|
|
spin_unlock(&f2fs_list_lock);
|
|
return freed;
|
|
}
|
|
|
|
void f2fs_join_shrinker(struct f2fs_sb_info *sbi)
|
|
{
|
|
spin_lock(&f2fs_list_lock);
|
|
list_add_tail(&sbi->s_list, &f2fs_list);
|
|
spin_unlock(&f2fs_list_lock);
|
|
}
|
|
|
|
void f2fs_leave_shrinker(struct f2fs_sb_info *sbi)
|
|
{
|
|
f2fs_shrink_extent_tree(sbi, __count_extent_cache(sbi));
|
|
|
|
spin_lock(&f2fs_list_lock);
|
|
list_del(&sbi->s_list);
|
|
spin_unlock(&f2fs_list_lock);
|
|
}
|