if (folio)
return folio;
- /* Skip allocation for unused swap slot for readahead path. */
+ /* Skip allocation for unused and bad swap slot for readahead. */
if (!swap_entry_swapped(si, entry))
return NULL;
return swap_count(si->swap_map[offset]);
}
-/*
- * How many references to @entry are currently swapped out?
- * This does not give an exact answer when swap count is continued,
- * but does include the high COUNT_CONTINUED flag to allow for that.
+/**
+ * swap_entry_swapped - Check if the swap entry is swapped.
+ * @si: the swap device.
+ * @entry: the swap entry.
*/
bool swap_entry_swapped(struct swap_info_struct *si, swp_entry_t entry)
{
ci = swap_cluster_lock(si, offset);
count = swap_count(si->swap_map[offset]);
swap_cluster_unlock(ci);
- return !!count;
+
+ return count && count != SWAP_MAP_BAD;
}
/*
count = si->swap_map[offset + i];
/*
- * swapin_readahead() doesn't check if a swap entry is valid, so the
- * swap entry could be SWAP_MAP_BAD. Check here with lock held.
+ * For swapin out, allocator never allocates bad slots. for
+ * swapin, readahead is guarded by swap_entry_swapped.
*/
- if (unlikely(swap_count(count) == SWAP_MAP_BAD)) {
+ if (WARN_ON(swap_count(count) == SWAP_MAP_BAD)) {
err = -ENOENT;
goto unlock_out;
}