2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_alloc_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_inode.h"
37 #include "xfs_dinode.h"
38 #include "xfs_error.h"
39 #include "xfs_mru_cache.h"
40 #include "xfs_filestream.h"
41 #include "xfs_vnodeops.h"
42 #include "xfs_utils.h"
43 #include "xfs_buf_item.h"
44 #include "xfs_inode_item.h"
46 #include "xfs_quota.h"
47 #include "xfs_trace.h"
49 #include <linux/kthread.h>
50 #include <linux/freezer.h>
56 struct xfs_perag
*pag
,
57 uint32_t *first_index
,
64 * use a gang lookup to find the next inode in the tree
65 * as the tree is sparse and a gang lookup walks to find
66 * the number of objects requested.
68 if (tag
== XFS_ICI_NO_TAG
) {
69 nr_found
= radix_tree_gang_lookup(&pag
->pag_ici_root
,
70 (void **)&ip
, *first_index
, 1);
72 nr_found
= radix_tree_gang_lookup_tag(&pag
->pag_ici_root
,
73 (void **)&ip
, *first_index
, 1, tag
);
79 * Update the index for the next lookup. Catch overflows
80 * into the next AG range which can occur if we have inodes
81 * in the last block of the AG and we are currently
82 * pointing to the last inode.
84 *first_index
= XFS_INO_TO_AGINO(mp
, ip
->i_ino
+ 1);
85 if (*first_index
< XFS_INO_TO_AGINO(mp
, ip
->i_ino
))
93 struct xfs_perag
*pag
,
94 int (*execute
)(struct xfs_inode
*ip
,
95 struct xfs_perag
*pag
, int flags
),
101 uint32_t first_index
;
113 write_lock(&pag
->pag_ici_lock
);
115 read_lock(&pag
->pag_ici_lock
);
116 ip
= xfs_inode_ag_lookup(mp
, pag
, &first_index
, tag
);
119 write_unlock(&pag
->pag_ici_lock
);
121 read_unlock(&pag
->pag_ici_lock
);
125 /* execute releases pag->pag_ici_lock */
126 error
= execute(ip
, pag
, flags
);
127 if (error
== EAGAIN
) {
134 /* bail out if the filesystem is corrupted. */
135 if (error
== EFSCORRUPTED
)
138 } while ((*nr_to_scan
)--);
148 * Select the next per-ag structure to iterate during the walk. The reclaim
149 * walk is optimised only to walk AGs with reclaimable inodes in them.
151 static struct xfs_perag
*
152 xfs_inode_ag_iter_next_pag(
153 struct xfs_mount
*mp
,
154 xfs_agnumber_t
*first
,
157 struct xfs_perag
*pag
= NULL
;
159 if (tag
== XFS_ICI_RECLAIM_TAG
) {
163 spin_lock(&mp
->m_perag_lock
);
164 found
= radix_tree_gang_lookup_tag(&mp
->m_perag_tree
,
165 (void **)&pag
, *first
, 1, tag
);
167 spin_unlock(&mp
->m_perag_lock
);
170 *first
= pag
->pag_agno
+ 1;
171 /* open coded pag reference increment */
172 ref
= atomic_inc_return(&pag
->pag_ref
);
173 spin_unlock(&mp
->m_perag_lock
);
174 trace_xfs_perag_get_reclaim(mp
, pag
->pag_agno
, ref
, _RET_IP_
);
176 pag
= xfs_perag_get(mp
, *first
);
183 xfs_inode_ag_iterator(
184 struct xfs_mount
*mp
,
185 int (*execute
)(struct xfs_inode
*ip
,
186 struct xfs_perag
*pag
, int flags
),
192 struct xfs_perag
*pag
;
198 nr
= nr_to_scan
? *nr_to_scan
: INT_MAX
;
200 while ((pag
= xfs_inode_ag_iter_next_pag(mp
, &ag
, tag
))) {
201 error
= xfs_inode_ag_walk(mp
, pag
, execute
, flags
, tag
,
206 if (error
== EFSCORRUPTED
)
214 return XFS_ERROR(last_error
);
217 /* must be called with pag_ici_lock held and releases it */
219 xfs_sync_inode_valid(
220 struct xfs_inode
*ip
,
221 struct xfs_perag
*pag
)
223 struct inode
*inode
= VFS_I(ip
);
224 int error
= EFSCORRUPTED
;
226 /* nothing to sync during shutdown */
227 if (XFS_FORCED_SHUTDOWN(ip
->i_mount
))
230 /* avoid new or reclaimable inodes. Leave for reclaim code to flush */
232 if (xfs_iflags_test(ip
, XFS_INEW
| XFS_IRECLAIMABLE
| XFS_IRECLAIM
))
235 /* If we can't grab the inode, it must on it's way to reclaim. */
239 if (is_bad_inode(inode
)) {
247 read_unlock(&pag
->pag_ici_lock
);
253 struct xfs_inode
*ip
,
254 struct xfs_perag
*pag
,
257 struct inode
*inode
= VFS_I(ip
);
258 struct address_space
*mapping
= inode
->i_mapping
;
261 error
= xfs_sync_inode_valid(ip
, pag
);
265 if (!mapping_tagged(mapping
, PAGECACHE_TAG_DIRTY
))
268 if (!xfs_ilock_nowait(ip
, XFS_IOLOCK_SHARED
)) {
269 if (flags
& SYNC_TRYLOCK
)
271 xfs_ilock(ip
, XFS_IOLOCK_SHARED
);
274 error
= xfs_flush_pages(ip
, 0, -1, (flags
& SYNC_WAIT
) ?
275 0 : XBF_ASYNC
, FI_NONE
);
276 xfs_iunlock(ip
, XFS_IOLOCK_SHARED
);
279 if (flags
& SYNC_WAIT
)
287 struct xfs_inode
*ip
,
288 struct xfs_perag
*pag
,
293 error
= xfs_sync_inode_valid(ip
, pag
);
297 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
298 if (xfs_inode_clean(ip
))
300 if (!xfs_iflock_nowait(ip
)) {
301 if (!(flags
& SYNC_WAIT
))
306 if (xfs_inode_clean(ip
)) {
311 error
= xfs_iflush(ip
, flags
);
314 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
320 * Write out pagecache data for the whole filesystem.
324 struct xfs_mount
*mp
,
329 ASSERT((flags
& ~(SYNC_TRYLOCK
|SYNC_WAIT
)) == 0);
331 error
= xfs_inode_ag_iterator(mp
, xfs_sync_inode_data
, flags
,
332 XFS_ICI_NO_TAG
, 0, NULL
);
334 return XFS_ERROR(error
);
336 xfs_log_force(mp
, (flags
& SYNC_WAIT
) ? XFS_LOG_SYNC
: 0);
341 * Write out inode metadata (attributes) for the whole filesystem.
345 struct xfs_mount
*mp
,
348 ASSERT((flags
& ~SYNC_WAIT
) == 0);
350 return xfs_inode_ag_iterator(mp
, xfs_sync_inode_attr
, flags
,
351 XFS_ICI_NO_TAG
, 0, NULL
);
355 xfs_commit_dummy_trans(
356 struct xfs_mount
*mp
,
359 struct xfs_inode
*ip
= mp
->m_rootip
;
360 struct xfs_trans
*tp
;
364 * Put a dummy transaction in the log to tell recovery
365 * that all others are OK.
367 tp
= xfs_trans_alloc(mp
, XFS_TRANS_DUMMY1
);
368 error
= xfs_trans_reserve(tp
, 0, XFS_ICHANGE_LOG_RES(mp
), 0, 0, 0);
370 xfs_trans_cancel(tp
, 0);
374 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
376 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
377 xfs_trans_ihold(tp
, ip
);
378 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
379 error
= xfs_trans_commit(tp
, 0);
380 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
382 /* the log force ensures this transaction is pushed to disk */
383 xfs_log_force(mp
, (flags
& SYNC_WAIT
) ? XFS_LOG_SYNC
: 0);
389 struct xfs_mount
*mp
)
394 * If the buffer is pinned then push on the log so we won't get stuck
395 * waiting in the write for someone, maybe ourselves, to flush the log.
397 * Even though we just pushed the log above, we did not have the
398 * superblock buffer locked at that point so it can become pinned in
399 * between there and here.
401 bp
= xfs_getsb(mp
, 0);
402 if (XFS_BUF_ISPINNED(bp
))
403 xfs_log_force(mp
, 0);
405 return xfs_bwrite(mp
, bp
);
409 * When remounting a filesystem read-only or freezing the filesystem, we have
410 * two phases to execute. This first phase is syncing the data before we
411 * quiesce the filesystem, and the second is flushing all the inodes out after
412 * we've waited for all the transactions created by the first phase to
413 * complete. The second phase ensures that the inodes are written to their
414 * location on disk rather than just existing in transactions in the log. This
415 * means after a quiesce there is no log replay required to write the inodes to
416 * disk (this is the main difference between a sync and a quiesce).
419 * First stage of freeze - no writers will make progress now we are here,
420 * so we flush delwri and delalloc buffers here, then wait for all I/O to
421 * complete. Data is frozen at that point. Metadata is not frozen,
422 * transactions can still occur here so don't bother flushing the buftarg
423 * because it'll just get dirty again.
427 struct xfs_mount
*mp
)
429 int error
, error2
= 0;
431 /* push non-blocking */
432 xfs_sync_data(mp
, 0);
433 xfs_qm_sync(mp
, SYNC_TRYLOCK
);
435 /* push and block till complete */
436 xfs_sync_data(mp
, SYNC_WAIT
);
437 xfs_qm_sync(mp
, SYNC_WAIT
);
439 /* write superblock and hoover up shutdown errors */
440 error
= xfs_sync_fsdata(mp
);
442 /* make sure all delwri buffers are written out */
443 xfs_flush_buftarg(mp
->m_ddev_targp
, 1);
445 /* mark the log as covered if needed */
446 if (xfs_log_need_covered(mp
))
447 error2
= xfs_commit_dummy_trans(mp
, SYNC_WAIT
);
449 /* flush data-only devices */
450 if (mp
->m_rtdev_targp
)
451 XFS_bflush(mp
->m_rtdev_targp
);
453 return error
? error
: error2
;
458 struct xfs_mount
*mp
)
460 int count
= 0, pincount
;
462 xfs_reclaim_inodes(mp
, 0);
463 xfs_flush_buftarg(mp
->m_ddev_targp
, 0);
466 * This loop must run at least twice. The first instance of the loop
467 * will flush most meta data but that will generate more meta data
468 * (typically directory updates). Which then must be flushed and
469 * logged before we can write the unmount record. We also so sync
470 * reclaim of inodes to catch any that the above delwri flush skipped.
473 xfs_reclaim_inodes(mp
, SYNC_WAIT
);
474 xfs_sync_attr(mp
, SYNC_WAIT
);
475 pincount
= xfs_flush_buftarg(mp
->m_ddev_targp
, 1);
484 * Second stage of a quiesce. The data is already synced, now we have to take
485 * care of the metadata. New transactions are already blocked, so we need to
486 * wait for any remaining transactions to drain out before proceding.
490 struct xfs_mount
*mp
)
494 /* wait for all modifications to complete */
495 while (atomic_read(&mp
->m_active_trans
) > 0)
498 /* flush inodes and push all remaining buffers out to disk */
502 * Just warn here till VFS can correctly support
503 * read-only remount without racing.
505 WARN_ON(atomic_read(&mp
->m_active_trans
) != 0);
507 /* Push the superblock and write an unmount record */
508 error
= xfs_log_sbcount(mp
, 1);
510 xfs_fs_cmn_err(CE_WARN
, mp
,
511 "xfs_attr_quiesce: failed to log sb changes. "
512 "Frozen image may not be consistent.");
513 xfs_log_unmount_write(mp
);
514 xfs_unmountfs_writesb(mp
);
518 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
519 * Doing this has two advantages:
520 * - It saves on stack space, which is tight in certain situations
521 * - It can be used (with care) as a mechanism to avoid deadlocks.
522 * Flushing while allocating in a full filesystem requires both.
525 xfs_syncd_queue_work(
526 struct xfs_mount
*mp
,
528 void (*syncer
)(struct xfs_mount
*, void *),
529 struct completion
*completion
)
531 struct xfs_sync_work
*work
;
533 work
= kmem_alloc(sizeof(struct xfs_sync_work
), KM_SLEEP
);
534 INIT_LIST_HEAD(&work
->w_list
);
535 work
->w_syncer
= syncer
;
538 work
->w_completion
= completion
;
539 spin_lock(&mp
->m_sync_lock
);
540 list_add_tail(&work
->w_list
, &mp
->m_sync_list
);
541 spin_unlock(&mp
->m_sync_lock
);
542 wake_up_process(mp
->m_sync_task
);
546 * Flush delayed allocate data, attempting to free up reserved space
547 * from existing allocations. At this point a new allocation attempt
548 * has failed with ENOSPC and we are in the process of scratching our
549 * heads, looking about for more room...
552 xfs_flush_inodes_work(
553 struct xfs_mount
*mp
,
556 struct inode
*inode
= arg
;
557 xfs_sync_data(mp
, SYNC_TRYLOCK
);
558 xfs_sync_data(mp
, SYNC_TRYLOCK
| SYNC_WAIT
);
566 struct inode
*inode
= VFS_I(ip
);
567 DECLARE_COMPLETION_ONSTACK(completion
);
570 xfs_syncd_queue_work(ip
->i_mount
, inode
, xfs_flush_inodes_work
, &completion
);
571 wait_for_completion(&completion
);
572 xfs_log_force(ip
->i_mount
, XFS_LOG_SYNC
);
576 * Every sync period we need to unpin all items, reclaim inodes and sync
577 * disk quotas. We might need to cover the log to indicate that the
578 * filesystem is idle.
582 struct xfs_mount
*mp
,
587 if (!(mp
->m_flags
& XFS_MOUNT_RDONLY
)) {
588 xfs_log_force(mp
, 0);
589 xfs_reclaim_inodes(mp
, 0);
590 /* dgc: errors ignored here */
591 error
= xfs_qm_sync(mp
, SYNC_TRYLOCK
);
592 if (xfs_log_need_covered(mp
))
593 error
= xfs_commit_dummy_trans(mp
, 0);
596 wake_up(&mp
->m_wait_single_sync_task
);
603 struct xfs_mount
*mp
= arg
;
605 xfs_sync_work_t
*work
, *n
;
609 timeleft
= xfs_syncd_centisecs
* msecs_to_jiffies(10);
611 if (list_empty(&mp
->m_sync_list
))
612 timeleft
= schedule_timeout_interruptible(timeleft
);
615 if (kthread_should_stop() && list_empty(&mp
->m_sync_list
))
618 spin_lock(&mp
->m_sync_lock
);
620 * We can get woken by laptop mode, to do a sync -
621 * that's the (only!) case where the list would be
622 * empty with time remaining.
624 if (!timeleft
|| list_empty(&mp
->m_sync_list
)) {
626 timeleft
= xfs_syncd_centisecs
*
627 msecs_to_jiffies(10);
628 INIT_LIST_HEAD(&mp
->m_sync_work
.w_list
);
629 list_add_tail(&mp
->m_sync_work
.w_list
,
632 list_splice_init(&mp
->m_sync_list
, &tmp
);
633 spin_unlock(&mp
->m_sync_lock
);
635 list_for_each_entry_safe(work
, n
, &tmp
, w_list
) {
636 (*work
->w_syncer
)(mp
, work
->w_data
);
637 list_del(&work
->w_list
);
638 if (work
== &mp
->m_sync_work
)
640 if (work
->w_completion
)
641 complete(work
->w_completion
);
651 struct xfs_mount
*mp
)
653 mp
->m_sync_work
.w_syncer
= xfs_sync_worker
;
654 mp
->m_sync_work
.w_mount
= mp
;
655 mp
->m_sync_work
.w_completion
= NULL
;
656 mp
->m_sync_task
= kthread_run(xfssyncd
, mp
, "xfssyncd/%s", mp
->m_fsname
);
657 if (IS_ERR(mp
->m_sync_task
))
658 return -PTR_ERR(mp
->m_sync_task
);
664 struct xfs_mount
*mp
)
666 kthread_stop(mp
->m_sync_task
);
670 __xfs_inode_set_reclaim_tag(
671 struct xfs_perag
*pag
,
672 struct xfs_inode
*ip
)
674 radix_tree_tag_set(&pag
->pag_ici_root
,
675 XFS_INO_TO_AGINO(ip
->i_mount
, ip
->i_ino
),
676 XFS_ICI_RECLAIM_TAG
);
678 if (!pag
->pag_ici_reclaimable
) {
679 /* propagate the reclaim tag up into the perag radix tree */
680 spin_lock(&ip
->i_mount
->m_perag_lock
);
681 radix_tree_tag_set(&ip
->i_mount
->m_perag_tree
,
682 XFS_INO_TO_AGNO(ip
->i_mount
, ip
->i_ino
),
683 XFS_ICI_RECLAIM_TAG
);
684 spin_unlock(&ip
->i_mount
->m_perag_lock
);
685 trace_xfs_perag_set_reclaim(ip
->i_mount
, pag
->pag_agno
,
688 pag
->pag_ici_reclaimable
++;
692 * We set the inode flag atomically with the radix tree tag.
693 * Once we get tag lookups on the radix tree, this inode flag
697 xfs_inode_set_reclaim_tag(
700 struct xfs_mount
*mp
= ip
->i_mount
;
701 struct xfs_perag
*pag
;
703 pag
= xfs_perag_get(mp
, XFS_INO_TO_AGNO(mp
, ip
->i_ino
));
704 write_lock(&pag
->pag_ici_lock
);
705 spin_lock(&ip
->i_flags_lock
);
706 __xfs_inode_set_reclaim_tag(pag
, ip
);
707 __xfs_iflags_set(ip
, XFS_IRECLAIMABLE
);
708 spin_unlock(&ip
->i_flags_lock
);
709 write_unlock(&pag
->pag_ici_lock
);
714 __xfs_inode_clear_reclaim(
718 pag
->pag_ici_reclaimable
--;
719 if (!pag
->pag_ici_reclaimable
) {
720 /* clear the reclaim tag from the perag radix tree */
721 spin_lock(&ip
->i_mount
->m_perag_lock
);
722 radix_tree_tag_clear(&ip
->i_mount
->m_perag_tree
,
723 XFS_INO_TO_AGNO(ip
->i_mount
, ip
->i_ino
),
724 XFS_ICI_RECLAIM_TAG
);
725 spin_unlock(&ip
->i_mount
->m_perag_lock
);
726 trace_xfs_perag_clear_reclaim(ip
->i_mount
, pag
->pag_agno
,
732 __xfs_inode_clear_reclaim_tag(
737 radix_tree_tag_clear(&pag
->pag_ici_root
,
738 XFS_INO_TO_AGINO(mp
, ip
->i_ino
), XFS_ICI_RECLAIM_TAG
);
739 __xfs_inode_clear_reclaim(pag
, ip
);
743 * Inodes in different states need to be treated differently, and the return
744 * value of xfs_iflush is not sufficient to get this right. The following table
745 * lists the inode states and the reclaim actions necessary for non-blocking
749 * inode state iflush ret required action
750 * --------------- ---------- ---------------
752 * shutdown EIO unpin and reclaim
753 * clean, unpinned 0 reclaim
754 * stale, unpinned 0 reclaim
755 * clean, pinned(*) 0 requeue
756 * stale, pinned EAGAIN requeue
757 * dirty, delwri ok 0 requeue
758 * dirty, delwri blocked EAGAIN requeue
759 * dirty, sync flush 0 reclaim
761 * (*) dgc: I don't think the clean, pinned state is possible but it gets
762 * handled anyway given the order of checks implemented.
764 * As can be seen from the table, the return value of xfs_iflush() is not
765 * sufficient to correctly decide the reclaim action here. The checks in
766 * xfs_iflush() might look like duplicates, but they are not.
768 * Also, because we get the flush lock first, we know that any inode that has
769 * been flushed delwri has had the flush completed by the time we check that
770 * the inode is clean. The clean inode check needs to be done before flushing
771 * the inode delwri otherwise we would loop forever requeuing clean inodes as
772 * we cannot tell apart a successful delwri flush and a clean inode from the
773 * return value of xfs_iflush().
775 * Note that because the inode is flushed delayed write by background
776 * writeback, the flush lock may already be held here and waiting on it can
777 * result in very long latencies. Hence for sync reclaims, where we wait on the
778 * flush lock, the caller should push out delayed write inodes first before
779 * trying to reclaim them to minimise the amount of time spent waiting. For
780 * background relaim, we just requeue the inode for the next pass.
782 * Hence the order of actions after gaining the locks should be:
784 * shutdown => unpin and reclaim
785 * pinned, delwri => requeue
786 * pinned, sync => unpin
789 * dirty, delwri => flush and requeue
790 * dirty, sync => flush, wait and reclaim
794 struct xfs_inode
*ip
,
795 struct xfs_perag
*pag
,
801 * The radix tree lock here protects a thread in xfs_iget from racing
802 * with us starting reclaim on the inode. Once we have the
803 * XFS_IRECLAIM flag set it will not touch us.
805 spin_lock(&ip
->i_flags_lock
);
806 ASSERT_ALWAYS(__xfs_iflags_test(ip
, XFS_IRECLAIMABLE
));
807 if (__xfs_iflags_test(ip
, XFS_IRECLAIM
)) {
808 /* ignore as it is already under reclaim */
809 spin_unlock(&ip
->i_flags_lock
);
810 write_unlock(&pag
->pag_ici_lock
);
813 __xfs_iflags_set(ip
, XFS_IRECLAIM
);
814 spin_unlock(&ip
->i_flags_lock
);
815 write_unlock(&pag
->pag_ici_lock
);
817 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
818 if (!xfs_iflock_nowait(ip
)) {
819 if (!(sync_mode
& SYNC_WAIT
))
824 if (is_bad_inode(VFS_I(ip
)))
826 if (XFS_FORCED_SHUTDOWN(ip
->i_mount
)) {
830 if (xfs_ipincount(ip
)) {
831 if (!(sync_mode
& SYNC_WAIT
)) {
837 if (xfs_iflags_test(ip
, XFS_ISTALE
))
839 if (xfs_inode_clean(ip
))
842 /* Now we have an inode that needs flushing */
843 error
= xfs_iflush(ip
, sync_mode
);
844 if (sync_mode
& SYNC_WAIT
) {
850 * When we have to flush an inode but don't have SYNC_WAIT set, we
851 * flush the inode out using a delwri buffer and wait for the next
852 * call into reclaim to find it in a clean state instead of waiting for
853 * it now. We also don't return errors here - if the error is transient
854 * then the next reclaim pass will flush the inode, and if the error
855 * is permanent then the next sync reclaim will reclaim the inode and
858 if (error
&& error
!= EAGAIN
&& !XFS_FORCED_SHUTDOWN(ip
->i_mount
)) {
859 xfs_fs_cmn_err(CE_WARN
, ip
->i_mount
,
860 "inode 0x%llx background reclaim flush failed with %d",
861 (long long)ip
->i_ino
, error
);
864 xfs_iflags_clear(ip
, XFS_IRECLAIM
);
865 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
867 * We could return EAGAIN here to make reclaim rescan the inode tree in
868 * a short while. However, this just burns CPU time scanning the tree
869 * waiting for IO to complete and xfssyncd never goes back to the idle
870 * state. Instead, return 0 to let the next scheduled background reclaim
871 * attempt to reclaim the inode again.
877 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
888 return xfs_inode_ag_iterator(mp
, xfs_reclaim_inode
, mode
,
889 XFS_ICI_RECLAIM_TAG
, 1, NULL
);
893 * Shrinker infrastructure.
896 xfs_reclaim_inode_shrink(
897 struct shrinker
*shrink
,
901 struct xfs_mount
*mp
;
902 struct xfs_perag
*pag
;
906 mp
= container_of(shrink
, struct xfs_mount
, m_inode_shrink
);
908 if (!(gfp_mask
& __GFP_FS
))
911 xfs_inode_ag_iterator(mp
, xfs_reclaim_inode
, 0,
912 XFS_ICI_RECLAIM_TAG
, 1, &nr_to_scan
);
913 /* if we don't exhaust the scan, don't bother coming back */
920 while ((pag
= xfs_inode_ag_iter_next_pag(mp
, &ag
,
921 XFS_ICI_RECLAIM_TAG
))) {
922 reclaimable
+= pag
->pag_ici_reclaimable
;
929 xfs_inode_shrinker_register(
930 struct xfs_mount
*mp
)
932 mp
->m_inode_shrink
.shrink
= xfs_reclaim_inode_shrink
;
933 mp
->m_inode_shrink
.seeks
= DEFAULT_SEEKS
;
934 register_shrinker(&mp
->m_inode_shrink
);
938 xfs_inode_shrinker_unregister(
939 struct xfs_mount
*mp
)
941 unregister_shrinker(&mp
->m_inode_shrink
);