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"
27 #include "xfs_mount.h"
28 #include "xfs_bmap_btree.h"
29 #include "xfs_inode.h"
30 #include "xfs_dinode.h"
31 #include "xfs_error.h"
32 #include "xfs_filestream.h"
33 #include "xfs_vnodeops.h"
34 #include "xfs_inode_item.h"
35 #include "xfs_quota.h"
36 #include "xfs_trace.h"
37 #include "xfs_fsops.h"
39 #include <linux/kthread.h>
40 #include <linux/freezer.h>
43 * The inode lookup is done in batches to keep the amount of lock traffic and
44 * radix tree lookups to a minimum. The batch size is a trade off between
45 * lookup reduction and stack usage. This is in the reclaim path, so we can't
48 #define XFS_LOOKUP_BATCH 32
51 xfs_inode_ag_walk_grab(
54 struct inode *inode = VFS_I(ip);
56 /* nothing to sync during shutdown */
57 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
60 /* avoid new or reclaimable inodes. Leave for reclaim code to flush */
61 if (xfs_iflags_test(ip, XFS_INEW | XFS_IRECLAIMABLE | XFS_IRECLAIM))
64 /* If we can't grab the inode, it must on it's way to reclaim. */
68 if (is_bad_inode(inode)) {
80 struct xfs_perag *pag,
81 int (*execute)(struct xfs_inode *ip,
82 struct xfs_perag *pag, int flags),
97 struct xfs_inode *batch[XFS_LOOKUP_BATCH];
101 read_lock(&pag->pag_ici_lock);
102 nr_found = radix_tree_gang_lookup(&pag->pag_ici_root,
103 (void **)batch, first_index,
106 read_unlock(&pag->pag_ici_lock);
111 * Grab the inodes before we drop the lock. if we found
112 * nothing, nr == 0 and the loop will be skipped.
114 for (i = 0; i < nr_found; i++) {
115 struct xfs_inode *ip = batch[i];
117 if (done || xfs_inode_ag_walk_grab(ip))
121 * Update the index for the next lookup. Catch overflows
122 * into the next AG range which can occur if we have inodes
123 * in the last block of the AG and we are currently
124 * pointing to the last inode.
126 first_index = XFS_INO_TO_AGINO(mp, ip->i_ino + 1);
127 if (first_index < XFS_INO_TO_AGINO(mp, ip->i_ino))
131 /* unlock now we've grabbed the inodes. */
132 read_unlock(&pag->pag_ici_lock);
134 for (i = 0; i < nr_found; i++) {
137 error = execute(batch[i], pag, flags);
139 if (error == EAGAIN) {
143 if (error && last_error != EFSCORRUPTED)
147 /* bail out if the filesystem is corrupted. */
148 if (error == EFSCORRUPTED)
151 } while (nr_found && !done);
161 xfs_inode_ag_iterator(
162 struct xfs_mount *mp,
163 int (*execute)(struct xfs_inode *ip,
164 struct xfs_perag *pag, int flags),
167 struct xfs_perag *pag;
173 while ((pag = xfs_perag_get(mp, ag))) {
174 ag = pag->pag_agno + 1;
175 error = xfs_inode_ag_walk(mp, pag, execute, flags);
179 if (error == EFSCORRUPTED)
183 return XFS_ERROR(last_error);
188 struct xfs_inode *ip,
189 struct xfs_perag *pag,
192 struct inode *inode = VFS_I(ip);
193 struct address_space *mapping = inode->i_mapping;
196 if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
199 if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) {
200 if (flags & SYNC_TRYLOCK)
202 xfs_ilock(ip, XFS_IOLOCK_SHARED);
205 error = xfs_flush_pages(ip, 0, -1, (flags & SYNC_WAIT) ?
206 0 : XBF_ASYNC, FI_NONE);
207 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
210 if (flags & SYNC_WAIT)
217 struct xfs_inode *ip,
218 struct xfs_perag *pag,
223 xfs_ilock(ip, XFS_ILOCK_SHARED);
224 if (xfs_inode_clean(ip))
226 if (!xfs_iflock_nowait(ip)) {
227 if (!(flags & SYNC_WAIT))
232 if (xfs_inode_clean(ip)) {
237 error = xfs_iflush(ip, flags);
240 xfs_iunlock(ip, XFS_ILOCK_SHARED);
245 * Write out pagecache data for the whole filesystem.
249 struct xfs_mount *mp,
254 ASSERT((flags & ~(SYNC_TRYLOCK|SYNC_WAIT)) == 0);
256 error = xfs_inode_ag_iterator(mp, xfs_sync_inode_data, flags);
258 return XFS_ERROR(error);
260 xfs_log_force(mp, (flags & SYNC_WAIT) ? XFS_LOG_SYNC : 0);
265 * Write out inode metadata (attributes) for the whole filesystem.
269 struct xfs_mount *mp,
272 ASSERT((flags & ~SYNC_WAIT) == 0);
274 return xfs_inode_ag_iterator(mp, xfs_sync_inode_attr, flags);
279 struct xfs_mount *mp)
284 * If the buffer is pinned then push on the log so we won't get stuck
285 * waiting in the write for someone, maybe ourselves, to flush the log.
287 * Even though we just pushed the log above, we did not have the
288 * superblock buffer locked at that point so it can become pinned in
289 * between there and here.
291 bp = xfs_getsb(mp, 0);
292 if (XFS_BUF_ISPINNED(bp))
293 xfs_log_force(mp, 0);
295 return xfs_bwrite(mp, bp);
299 * When remounting a filesystem read-only or freezing the filesystem, we have
300 * two phases to execute. This first phase is syncing the data before we
301 * quiesce the filesystem, and the second is flushing all the inodes out after
302 * we've waited for all the transactions created by the first phase to
303 * complete. The second phase ensures that the inodes are written to their
304 * location on disk rather than just existing in transactions in the log. This
305 * means after a quiesce there is no log replay required to write the inodes to
306 * disk (this is the main difference between a sync and a quiesce).
309 * First stage of freeze - no writers will make progress now we are here,
310 * so we flush delwri and delalloc buffers here, then wait for all I/O to
311 * complete. Data is frozen at that point. Metadata is not frozen,
312 * transactions can still occur here so don't bother flushing the buftarg
313 * because it'll just get dirty again.
317 struct xfs_mount *mp)
319 int error, error2 = 0;
321 /* push non-blocking */
322 xfs_sync_data(mp, 0);
323 xfs_qm_sync(mp, SYNC_TRYLOCK);
325 /* push and block till complete */
326 xfs_sync_data(mp, SYNC_WAIT);
327 xfs_qm_sync(mp, SYNC_WAIT);
329 /* write superblock and hoover up shutdown errors */
330 error = xfs_sync_fsdata(mp);
332 /* make sure all delwri buffers are written out */
333 xfs_flush_buftarg(mp->m_ddev_targp, 1);
335 /* mark the log as covered if needed */
336 if (xfs_log_need_covered(mp))
337 error2 = xfs_fs_log_dummy(mp, SYNC_WAIT);
339 /* flush data-only devices */
340 if (mp->m_rtdev_targp)
341 XFS_bflush(mp->m_rtdev_targp);
343 return error ? error : error2;
348 struct xfs_mount *mp)
350 int count = 0, pincount;
352 xfs_reclaim_inodes(mp, 0);
353 xfs_flush_buftarg(mp->m_ddev_targp, 0);
356 * This loop must run at least twice. The first instance of the loop
357 * will flush most meta data but that will generate more meta data
358 * (typically directory updates). Which then must be flushed and
359 * logged before we can write the unmount record. We also so sync
360 * reclaim of inodes to catch any that the above delwri flush skipped.
363 xfs_reclaim_inodes(mp, SYNC_WAIT);
364 xfs_sync_attr(mp, SYNC_WAIT);
365 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
374 * Second stage of a quiesce. The data is already synced, now we have to take
375 * care of the metadata. New transactions are already blocked, so we need to
376 * wait for any remaining transactions to drain out before proceding.
380 struct xfs_mount *mp)
384 /* wait for all modifications to complete */
385 while (atomic_read(&mp->m_active_trans) > 0)
388 /* flush inodes and push all remaining buffers out to disk */
392 * Just warn here till VFS can correctly support
393 * read-only remount without racing.
395 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
397 /* Push the superblock and write an unmount record */
398 error = xfs_log_sbcount(mp, 1);
400 xfs_fs_cmn_err(CE_WARN, mp,
401 "xfs_attr_quiesce: failed to log sb changes. "
402 "Frozen image may not be consistent.");
403 xfs_log_unmount_write(mp);
404 xfs_unmountfs_writesb(mp);
408 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
409 * Doing this has two advantages:
410 * - It saves on stack space, which is tight in certain situations
411 * - It can be used (with care) as a mechanism to avoid deadlocks.
412 * Flushing while allocating in a full filesystem requires both.
415 xfs_syncd_queue_work(
416 struct xfs_mount *mp,
418 void (*syncer)(struct xfs_mount *, void *),
419 struct completion *completion)
421 struct xfs_sync_work *work;
423 work = kmem_alloc(sizeof(struct xfs_sync_work), KM_SLEEP);
424 INIT_LIST_HEAD(&work->w_list);
425 work->w_syncer = syncer;
428 work->w_completion = completion;
429 spin_lock(&mp->m_sync_lock);
430 list_add_tail(&work->w_list, &mp->m_sync_list);
431 spin_unlock(&mp->m_sync_lock);
432 wake_up_process(mp->m_sync_task);
436 * Flush delayed allocate data, attempting to free up reserved space
437 * from existing allocations. At this point a new allocation attempt
438 * has failed with ENOSPC and we are in the process of scratching our
439 * heads, looking about for more room...
442 xfs_flush_inodes_work(
443 struct xfs_mount *mp,
446 struct inode *inode = arg;
447 xfs_sync_data(mp, SYNC_TRYLOCK);
448 xfs_sync_data(mp, SYNC_TRYLOCK | SYNC_WAIT);
456 struct inode *inode = VFS_I(ip);
457 DECLARE_COMPLETION_ONSTACK(completion);
460 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inodes_work, &completion);
461 wait_for_completion(&completion);
462 xfs_log_force(ip->i_mount, XFS_LOG_SYNC);
466 * Every sync period we need to unpin all items, reclaim inodes and sync
467 * disk quotas. We might need to cover the log to indicate that the
468 * filesystem is idle and not frozen.
472 struct xfs_mount *mp,
477 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
478 xfs_log_force(mp, 0);
479 xfs_reclaim_inodes(mp, 0);
480 /* dgc: errors ignored here */
481 error = xfs_qm_sync(mp, SYNC_TRYLOCK);
482 if (mp->m_super->s_frozen == SB_UNFROZEN &&
483 xfs_log_need_covered(mp))
484 error = xfs_fs_log_dummy(mp, 0);
487 wake_up(&mp->m_wait_single_sync_task);
494 struct xfs_mount *mp = arg;
496 xfs_sync_work_t *work, *n;
500 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
502 if (list_empty(&mp->m_sync_list))
503 timeleft = schedule_timeout_interruptible(timeleft);
506 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
509 spin_lock(&mp->m_sync_lock);
511 * We can get woken by laptop mode, to do a sync -
512 * that's the (only!) case where the list would be
513 * empty with time remaining.
515 if (!timeleft || list_empty(&mp->m_sync_list)) {
517 timeleft = xfs_syncd_centisecs *
518 msecs_to_jiffies(10);
519 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
520 list_add_tail(&mp->m_sync_work.w_list,
523 list_splice_init(&mp->m_sync_list, &tmp);
524 spin_unlock(&mp->m_sync_lock);
526 list_for_each_entry_safe(work, n, &tmp, w_list) {
527 (*work->w_syncer)(mp, work->w_data);
528 list_del(&work->w_list);
529 if (work == &mp->m_sync_work)
531 if (work->w_completion)
532 complete(work->w_completion);
542 struct xfs_mount *mp)
544 mp->m_sync_work.w_syncer = xfs_sync_worker;
545 mp->m_sync_work.w_mount = mp;
546 mp->m_sync_work.w_completion = NULL;
547 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd/%s", mp->m_fsname);
548 if (IS_ERR(mp->m_sync_task))
549 return -PTR_ERR(mp->m_sync_task);
555 struct xfs_mount *mp)
557 kthread_stop(mp->m_sync_task);
561 __xfs_inode_set_reclaim_tag(
562 struct xfs_perag *pag,
563 struct xfs_inode *ip)
565 radix_tree_tag_set(&pag->pag_ici_root,
566 XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino),
567 XFS_ICI_RECLAIM_TAG);
569 if (!pag->pag_ici_reclaimable) {
570 /* propagate the reclaim tag up into the perag radix tree */
571 spin_lock(&ip->i_mount->m_perag_lock);
572 radix_tree_tag_set(&ip->i_mount->m_perag_tree,
573 XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino),
574 XFS_ICI_RECLAIM_TAG);
575 spin_unlock(&ip->i_mount->m_perag_lock);
576 trace_xfs_perag_set_reclaim(ip->i_mount, pag->pag_agno,
579 pag->pag_ici_reclaimable++;
583 * We set the inode flag atomically with the radix tree tag.
584 * Once we get tag lookups on the radix tree, this inode flag
588 xfs_inode_set_reclaim_tag(
591 struct xfs_mount *mp = ip->i_mount;
592 struct xfs_perag *pag;
594 pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino));
595 write_lock(&pag->pag_ici_lock);
596 spin_lock(&ip->i_flags_lock);
597 __xfs_inode_set_reclaim_tag(pag, ip);
598 __xfs_iflags_set(ip, XFS_IRECLAIMABLE);
599 spin_unlock(&ip->i_flags_lock);
600 write_unlock(&pag->pag_ici_lock);
605 __xfs_inode_clear_reclaim(
609 pag->pag_ici_reclaimable--;
610 if (!pag->pag_ici_reclaimable) {
611 /* clear the reclaim tag from the perag radix tree */
612 spin_lock(&ip->i_mount->m_perag_lock);
613 radix_tree_tag_clear(&ip->i_mount->m_perag_tree,
614 XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino),
615 XFS_ICI_RECLAIM_TAG);
616 spin_unlock(&ip->i_mount->m_perag_lock);
617 trace_xfs_perag_clear_reclaim(ip->i_mount, pag->pag_agno,
623 __xfs_inode_clear_reclaim_tag(
628 radix_tree_tag_clear(&pag->pag_ici_root,
629 XFS_INO_TO_AGINO(mp, ip->i_ino), XFS_ICI_RECLAIM_TAG);
630 __xfs_inode_clear_reclaim(pag, ip);
634 * Grab the inode for reclaim exclusively.
635 * Return 0 if we grabbed it, non-zero otherwise.
638 xfs_reclaim_inode_grab(
639 struct xfs_inode *ip,
644 * do some unlocked checks first to avoid unnecceary lock traffic.
645 * The first is a flush lock check, the second is a already in reclaim
646 * check. Only do these checks if we are not going to block on locks.
648 if ((flags & SYNC_TRYLOCK) &&
649 (!ip->i_flush.done || __xfs_iflags_test(ip, XFS_IRECLAIM))) {
654 * The radix tree lock here protects a thread in xfs_iget from racing
655 * with us starting reclaim on the inode. Once we have the
656 * XFS_IRECLAIM flag set it will not touch us.
658 spin_lock(&ip->i_flags_lock);
659 ASSERT_ALWAYS(__xfs_iflags_test(ip, XFS_IRECLAIMABLE));
660 if (__xfs_iflags_test(ip, XFS_IRECLAIM)) {
661 /* ignore as it is already under reclaim */
662 spin_unlock(&ip->i_flags_lock);
665 __xfs_iflags_set(ip, XFS_IRECLAIM);
666 spin_unlock(&ip->i_flags_lock);
671 * Inodes in different states need to be treated differently, and the return
672 * value of xfs_iflush is not sufficient to get this right. The following table
673 * lists the inode states and the reclaim actions necessary for non-blocking
677 * inode state iflush ret required action
678 * --------------- ---------- ---------------
680 * shutdown EIO unpin and reclaim
681 * clean, unpinned 0 reclaim
682 * stale, unpinned 0 reclaim
683 * clean, pinned(*) 0 requeue
684 * stale, pinned EAGAIN requeue
685 * dirty, delwri ok 0 requeue
686 * dirty, delwri blocked EAGAIN requeue
687 * dirty, sync flush 0 reclaim
689 * (*) dgc: I don't think the clean, pinned state is possible but it gets
690 * handled anyway given the order of checks implemented.
692 * As can be seen from the table, the return value of xfs_iflush() is not
693 * sufficient to correctly decide the reclaim action here. The checks in
694 * xfs_iflush() might look like duplicates, but they are not.
696 * Also, because we get the flush lock first, we know that any inode that has
697 * been flushed delwri has had the flush completed by the time we check that
698 * the inode is clean. The clean inode check needs to be done before flushing
699 * the inode delwri otherwise we would loop forever requeuing clean inodes as
700 * we cannot tell apart a successful delwri flush and a clean inode from the
701 * return value of xfs_iflush().
703 * Note that because the inode is flushed delayed write by background
704 * writeback, the flush lock may already be held here and waiting on it can
705 * result in very long latencies. Hence for sync reclaims, where we wait on the
706 * flush lock, the caller should push out delayed write inodes first before
707 * trying to reclaim them to minimise the amount of time spent waiting. For
708 * background relaim, we just requeue the inode for the next pass.
710 * Hence the order of actions after gaining the locks should be:
712 * shutdown => unpin and reclaim
713 * pinned, delwri => requeue
714 * pinned, sync => unpin
717 * dirty, delwri => flush and requeue
718 * dirty, sync => flush, wait and reclaim
722 struct xfs_inode *ip,
723 struct xfs_perag *pag,
728 xfs_ilock(ip, XFS_ILOCK_EXCL);
729 if (!xfs_iflock_nowait(ip)) {
730 if (!(sync_mode & SYNC_WAIT))
735 if (is_bad_inode(VFS_I(ip)))
737 if (XFS_FORCED_SHUTDOWN(ip->i_mount)) {
741 if (xfs_ipincount(ip)) {
742 if (!(sync_mode & SYNC_WAIT)) {
748 if (xfs_iflags_test(ip, XFS_ISTALE))
750 if (xfs_inode_clean(ip))
753 /* Now we have an inode that needs flushing */
754 error = xfs_iflush(ip, sync_mode);
755 if (sync_mode & SYNC_WAIT) {
761 * When we have to flush an inode but don't have SYNC_WAIT set, we
762 * flush the inode out using a delwri buffer and wait for the next
763 * call into reclaim to find it in a clean state instead of waiting for
764 * it now. We also don't return errors here - if the error is transient
765 * then the next reclaim pass will flush the inode, and if the error
766 * is permanent then the next sync reclaim will reclaim the inode and
769 if (error && error != EAGAIN && !XFS_FORCED_SHUTDOWN(ip->i_mount)) {
770 xfs_fs_cmn_err(CE_WARN, ip->i_mount,
771 "inode 0x%llx background reclaim flush failed with %d",
772 (long long)ip->i_ino, error);
775 xfs_iflags_clear(ip, XFS_IRECLAIM);
776 xfs_iunlock(ip, XFS_ILOCK_EXCL);
778 * We could return EAGAIN here to make reclaim rescan the inode tree in
779 * a short while. However, this just burns CPU time scanning the tree
780 * waiting for IO to complete and xfssyncd never goes back to the idle
781 * state. Instead, return 0 to let the next scheduled background reclaim
782 * attempt to reclaim the inode again.
788 xfs_iunlock(ip, XFS_ILOCK_EXCL);
790 XFS_STATS_INC(xs_ig_reclaims);
792 * Remove the inode from the per-AG radix tree.
794 * Because radix_tree_delete won't complain even if the item was never
795 * added to the tree assert that it's been there before to catch
796 * problems with the inode life time early on.
798 write_lock(&pag->pag_ici_lock);
799 if (!radix_tree_delete(&pag->pag_ici_root,
800 XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino)))
802 __xfs_inode_clear_reclaim(pag, ip);
803 write_unlock(&pag->pag_ici_lock);
806 * Here we do an (almost) spurious inode lock in order to coordinate
807 * with inode cache radix tree lookups. This is because the lookup
808 * can reference the inodes in the cache without taking references.
810 * We make that OK here by ensuring that we wait until the inode is
811 * unlocked after the lookup before we go ahead and free it. We get
812 * both the ilock and the iolock because the code may need to drop the
813 * ilock one but will still hold the iolock.
815 xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
817 xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
825 * Walk the AGs and reclaim the inodes in them. Even if the filesystem is
826 * corrupted, we still want to try to reclaim all the inodes. If we don't,
827 * then a shut down during filesystem unmount reclaim walk leak all the
828 * unreclaimed inodes.
831 xfs_reclaim_inodes_ag(
832 struct xfs_mount *mp,
836 struct xfs_perag *pag;
840 int trylock = flags & SYNC_TRYLOCK;
846 while ((pag = xfs_perag_get_tag(mp, ag, XFS_ICI_RECLAIM_TAG))) {
847 unsigned long first_index = 0;
851 ag = pag->pag_agno + 1;
854 if (!mutex_trylock(&pag->pag_ici_reclaim_lock)) {
858 first_index = pag->pag_ici_reclaim_cursor;
860 mutex_lock(&pag->pag_ici_reclaim_lock);
863 struct xfs_inode *batch[XFS_LOOKUP_BATCH];
866 write_lock(&pag->pag_ici_lock);
867 nr_found = radix_tree_gang_lookup_tag(
869 (void **)batch, first_index,
871 XFS_ICI_RECLAIM_TAG);
873 write_unlock(&pag->pag_ici_lock);
878 * Grab the inodes before we drop the lock. if we found
879 * nothing, nr == 0 and the loop will be skipped.
881 for (i = 0; i < nr_found; i++) {
882 struct xfs_inode *ip = batch[i];
884 if (done || xfs_reclaim_inode_grab(ip, flags))
888 * Update the index for the next lookup. Catch
889 * overflows into the next AG range which can
890 * occur if we have inodes in the last block of
891 * the AG and we are currently pointing to the
894 first_index = XFS_INO_TO_AGINO(mp, ip->i_ino + 1);
895 if (first_index < XFS_INO_TO_AGINO(mp, ip->i_ino))
899 /* unlock now we've grabbed the inodes. */
900 write_unlock(&pag->pag_ici_lock);
902 for (i = 0; i < nr_found; i++) {
905 error = xfs_reclaim_inode(batch[i], pag, flags);
906 if (error && last_error != EFSCORRUPTED)
910 *nr_to_scan -= XFS_LOOKUP_BATCH;
912 } while (nr_found && !done && *nr_to_scan > 0);
914 if (trylock && !done)
915 pag->pag_ici_reclaim_cursor = first_index;
917 pag->pag_ici_reclaim_cursor = 0;
918 mutex_unlock(&pag->pag_ici_reclaim_lock);
923 * if we skipped any AG, and we still have scan count remaining, do
924 * another pass this time using blocking reclaim semantics (i.e
925 * waiting on the reclaim locks and ignoring the reclaim cursors). This
926 * ensure that when we get more reclaimers than AGs we block rather
927 * than spin trying to execute reclaim.
929 if (trylock && skipped && *nr_to_scan > 0) {
933 return XFS_ERROR(last_error);
941 int nr_to_scan = INT_MAX;
943 return xfs_reclaim_inodes_ag(mp, mode, &nr_to_scan);
947 * Shrinker infrastructure.
950 xfs_reclaim_inode_shrink(
951 struct shrinker *shrink,
955 struct xfs_mount *mp;
956 struct xfs_perag *pag;
960 mp = container_of(shrink, struct xfs_mount, m_inode_shrink);
962 if (!(gfp_mask & __GFP_FS))
965 xfs_reclaim_inodes_ag(mp, SYNC_TRYLOCK, &nr_to_scan);
966 /* terminate if we don't exhaust the scan */
973 while ((pag = xfs_perag_get_tag(mp, ag, XFS_ICI_RECLAIM_TAG))) {
974 ag = pag->pag_agno + 1;
975 reclaimable += pag->pag_ici_reclaimable;
982 xfs_inode_shrinker_register(
983 struct xfs_mount *mp)
985 mp->m_inode_shrink.shrink = xfs_reclaim_inode_shrink;
986 mp->m_inode_shrink.seeks = DEFAULT_SEEKS;
987 register_shrinker(&mp->m_inode_shrink);
991 xfs_inode_shrinker_unregister(
992 struct xfs_mount *mp)
994 unregister_shrinker(&mp->m_inode_shrink);