}
new_cluster:
- ci = isolate_lock_cluster(si, &si->free_clusters);
- if (ci) {
- found = alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci),
- order, usage);
- if (found)
- goto done;
+ /*
+ * If the device need discard, prefer new cluster over nonfull
+ * to spread out the writes.
+ */
+ if (si->flags & SWP_PAGE_DISCARD) {
+ ci = isolate_lock_cluster(si, &si->free_clusters);
+ if (ci) {
+ found = alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci),
+ order, usage);
+ if (found)
+ goto done;
+ }
}
- /* Try reclaim from full clusters if free clusters list is drained */
- if (vm_swap_full())
- swap_reclaim_full_clusters(si, false);
-
if (order < PMD_ORDER) {
while ((ci = isolate_lock_cluster(si, &si->nonfull_clusters[order]))) {
found = alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci),
if (found)
goto done;
}
+ }
+ if (!(si->flags & SWP_PAGE_DISCARD)) {
+ ci = isolate_lock_cluster(si, &si->free_clusters);
+ if (ci) {
+ found = alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci),
+ order, usage);
+ if (found)
+ goto done;
+ }
+ }
+
+ /* Try reclaim full clusters if free and nonfull lists are drained */
+ if (vm_swap_full())
+ swap_reclaim_full_clusters(si, false);
+
+ if (order < PMD_ORDER) {
/*
* Scan only one fragment cluster is good enough. Order 0
* allocation will surely success, and large allocation