summaryrefslogtreecommitdiffstats
path: root/packages/linux/linux-wrt-2.4.20/130-nfsswap.patch
blob: 15e215c7da451e8185492f30c62afc7a85842c13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
#
# Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
#

--- /dev/null	2004-04-06 13:56:48.000000000 -0400
+++ linux-2.4.20/Documentation/netswap.txt	2005-01-07 02:55:48.022456424 -0500
@@ -0,0 +1,51 @@
+                     Swapping over network
+
+Support for this is enabled via the CONFIG_NETSWAP option, which is
+automatically enabled when enabling swap files located on NFS volumes
+(CONFIG_SWAP_VIA_NFS).
+
+When swapping to files located on a network file system like NFS or
+CODA or others or to nbd (network block device, see `nbd.txt')
+partitions there is the problem that this requires additional memory,
+besides the page which is currently swapped in or out, probably at
+least two more pages for each page in question.
+
+This means that not only there needs to be free space left in the swap
+file or the swap partition, but in addition there must be enough free
+memory left in the system to perform the swap out of pages.
+
+This is particularly painful as receiving data over the network itself
+consumes memory, and this memory is allocated from an interrupt
+context (i.e. in the interrupt handler of the network card). That
+means that on a congested network there are chances that the machine
+runs out of memory, simply because the network device's interrupt
+routines allocate memory faster that it is freed by swapping via
+network.
+
+To cope with this problem, there is a new socket option `SO_SWAPPING'
+which has to be set on the `SOL_SOCKET' level with setsockopt() (see
+setsockopt(2)). When this option is set on any network socket, then
+the system will start to drop network packets it receives on any other
+socket when the number of free pages falls below a certain threshold.
+
+This threshold initially is 4 pages less than `freepages.min' (see
+`Documentation/sysctl/vm.txt') but can be tuned using the sysctl
+interface by writing to the file `/proc/sys/net/swapping/threshold'
+
+There are two other files:
+
+`/proc/sys/net/swapping/dropped':
+    how many network packets have been dropped so far. This file is
+    writable, writing to it simply sets the counter to the given value
+    (useful for resetting the counter).
+
+`/proc/sys/net/swapping/sock_count':
+    How many network sockets have the `SO_SWAPPING' option set (read
+    only, of course).
+
+When using swap-files on NFS volumes, then the `SO_SWAPPING' option is
+set or cleared by swapon/swapoff system calls, so the user need not
+care about it.
+
+Swapping over the network is insecure unless the data would be
+encrypted, which is not the case with NFS. It is also very slow.
--- /dev/null	2004-04-06 13:56:48.000000000 -0400
+++ linux-2.4.20/Documentation/nfsswap.txt	2005-01-07 02:55:48.022456424 -0500
@@ -0,0 +1,41 @@
+                   Swapping to files on NFS volumes
+
+To  do  this you have to  say  `Y' or  `M'  to the CONFIG_SWAP_VIA_NFS
+configuration  option. When compling support  for this as a module you
+should  read  `Documentation/modules.txt'.  For  auto-loading  of  the
+module during the `swapon' system call you have to place a line like
+
+alias swapfile-mod nfsswap
+
+in   `/etc/modules.conf'  (or `/etc/conf.modules',  depending  on your
+setup). NFS volumes  holding swapfile should  be mounted  with `rsize'
+and `wsize' set to something  less than the size  of a page, otherwise
+deadlocks  caused by memory fragmentation can  happen,  i.e. mount the
+volume which is to hold the swapfiles with
+
+mount -t nfs -o rsize=2048,wsize=2048 NFS_SERVER_IP:/server_volume /mount_point
+
+or set the option in `/etc/fstab'. Read `Documentation/nfsroot.txt' to
+learn how to set mount options for the root file  system, if your swap
+files are to be located on the root file system.
+
+Setting the  `rsize' and `wsize' to  anything less than PAGE_SIZE is a
+performance hit, so  you probably want to  have  at least two  volumes
+mounted, one for the swapfiles, one for the rest.
+
+You may want to read `Documentation/netswap.txt' as well.
+
+Swapfiles on NFS volumes can be treated like any other swapfile,
+i.e.
+
+dd if=/dev/zero of=/swapfiles/SWAPFILE bs=1k count=20480
+mkswap /swapfiles/SWAPFILE
+swapon /swapfiles/SWAPFILE
+
+will  create a 20M swapfile and  tell the system  to use it. Actually,
+one could use lseek(2) to create  an empty swapfile. This is different
+from swapfiles located on local harddisk.
+
+Swapping  over  the network is   insecure   unless the data  would  be
+encrypted, which is not the case with NFS. It is also very slow.
+
--- linux-2.4.20/drivers/block/blkpg.c~130-nfsswap	2002-08-02 20:39:43.000000000 -0400
+++ linux-2.4.20/drivers/block/blkpg.c	2005-01-07 02:55:48.022456424 -0500
@@ -34,7 +34,7 @@
 #include <linux/blk.h>			/* for set_device_ro() */
 #include <linux/blkpg.h>
 #include <linux/genhd.h>
-#include <linux/swap.h>			/* for is_swap_partition() */
+#include <linux/swap.h>			/* for swap_run_test() */
 #include <linux/module.h>               /* for EXPORT_SYMBOL */
 
 #include <asm/uaccess.h>
@@ -114,6 +114,29 @@
 	return 0;
 }
 
+/* swap_run_test() applies this hook to all swapfiles until it returns
+ * "1".  If it never returns "1", the result of swap_run_test() is "0",
+ * otherwise "1".
+ */
+static int is_swap_partition_hook(unsigned int flags, struct file *swap_file,
+				  void *testdata)
+{
+	kdev_t swap_dev = S_ISBLK(swap_file->f_dentry->d_inode->i_mode)
+		? swap_file->f_dentry->d_inode->i_rdev : 0;
+	kdev_t dev = *((kdev_t *)testdata);
+	
+	if (flags & SWP_USED && dev == swap_dev) {
+		return 1;
+	} else {
+		return 0;
+	}
+}
+
+static inline int is_swap_partition(kdev_t dev)
+{
+	return swap_run_test(is_swap_partition_hook, &dev);
+}
+
 /*
  * Delete a partition given by partition number
  *
--- linux-2.4.20/fs/Config.in~130-nfsswap	2005-01-07 02:54:46.352831000 -0500
+++ linux-2.4.20/fs/Config.in	2005-01-07 02:55:48.023456272 -0500
@@ -4,6 +4,12 @@
 mainmenu_option next_comment
 comment 'File systems'
 
+if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+   tristate 'Swapping to block devices' CONFIG_BLKDEV_SWAP
+else
+   define_bool CONFIG_BLKDEV_SWAP y
+fi
+
 bool 'Quota support' CONFIG_QUOTA
 tristate 'Kernel automounter support' CONFIG_AUTOFS_FS
 tristate 'Kernel automounter version 4 support (also supports v3)' CONFIG_AUTOFS4_FS
@@ -104,6 +110,12 @@
    dep_tristate 'NFS file system support' CONFIG_NFS_FS $CONFIG_INET
    dep_mbool '  Provide NFSv3 client support' CONFIG_NFS_V3 $CONFIG_NFS_FS
    dep_bool '  Root file system on NFS' CONFIG_ROOT_NFS $CONFIG_NFS_FS $CONFIG_IP_PNP
+   if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+      dep_tristate '  Swapping via NFS (EXPERIMENTAL)' CONFIG_SWAP_VIA_NFS $CONFIG_NFS_FS
+      if [ "$CONFIG_SWAP_VIA_NFS" = "y" -o "$CONFIG_SWAP_VIA_NFS" = "m" ]; then
+         define_bool CONFIG_NETSWAP  y
+      fi
+   fi
 
    dep_tristate 'NFS server support' CONFIG_NFSD $CONFIG_INET
    dep_mbool '  Provide NFSv3 server support' CONFIG_NFSD_V3 $CONFIG_NFSD
--- linux-2.4.20/fs/Makefile~130-nfsswap	2005-01-07 02:54:46.353831000 -0500
+++ linux-2.4.20/fs/Makefile	2005-01-07 02:55:48.023456272 -0500
@@ -8,7 +8,7 @@
 O_TARGET := fs.o
 
 export-objs :=	filesystems.o open.o dcache.o buffer.o
-mod-subdirs :=	nls
+mod-subdirs :=	nls nfs
 
 obj-y :=	open.o read_write.o devices.o file_table.o buffer.o \
 		super.o block_dev.o char_dev.o stat.o exec.o pipe.o namei.o \
@@ -70,6 +70,7 @@
 subdir-$(CONFIG_JFS_FS)		+= jfs
 subdir-$(CONFIG_SQUASHFS)	+= squashfs
 
+obj-$(CONFIG_BLKDEV_SWAP)       += blkdev_swap.o
 
 obj-$(CONFIG_BINFMT_AOUT)	+= binfmt_aout.o
 obj-$(CONFIG_BINFMT_EM86)	+= binfmt_em86.o
--- /dev/null	2004-04-06 13:56:48.000000000 -0400
+++ linux-2.4.20/fs/blkdev_swap.c	2005-01-07 02:55:48.023456272 -0500
@@ -0,0 +1,309 @@
+/*
+ * Swapping to partitions or files located on partitions.
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/locks.h>
+#include <linux/blkdev.h>
+#include <linux/pagemap.h>
+#include <linux/swap.h>
+#include <linux/fs.h>
+
+#ifdef DEBUG_BLKDEV_SWAP
+# define dprintk(fmt...) printk(##fmt)
+#else
+# define dprintk(fmt...) do { /* */ } while (0)
+#endif
+
+#define BLKDEV_SWAP_ID      "blkdev"
+#define BLKDEV_FILE_SWAP_ID "blkdev file"
+
+/*
+ * Helper function, copied here from buffer.c
+ */
+
+/*
+ * Start I/O on a page.
+ * This function expects the page to be locked and may return
+ * before I/O is complete. You then have to check page->locked
+ * and page->uptodate.
+ *
+ * brw_page() is SMP-safe, although it's being called with the
+ * kernel lock held - but the code is ready.
+ *
+ * FIXME: we need a swapper_inode->get_block function to remove
+ *        some of the bmap kludges and interface ugliness here.
+ */
+int brw_page(int rw, struct page *page, kdev_t dev, int b[], int size)
+{
+	struct buffer_head *head, *bh;
+
+	if (!PageLocked(page))
+		panic("brw_page: page not locked for I/O");
+
+	if (!page->buffers)
+		create_empty_buffers(page, dev, size);
+	head = bh = page->buffers;
+
+	/* Stage 1: lock all the buffers */
+	do {
+		lock_buffer(bh);
+		bh->b_blocknr = *(b++);
+		set_bit(BH_Mapped, &bh->b_state);
+		set_buffer_async_io(bh);
+		bh = bh->b_this_page;
+	} while (bh != head);
+
+	/* Stage 2: start the IO */
+	do {
+		struct buffer_head *next = bh->b_this_page;
+		submit_bh(rw, bh);
+		bh = next;
+	} while (bh != head);
+	return 0;
+}
+
+/*
+ * We implement to methods: swapping to partitions, and swapping to files
+ * located on partitions.
+ */
+
+struct blkdev_swap_data {
+	kdev_t dev;
+};
+
+struct test_data {
+	struct file * filp;
+	kdev_t dev;
+};
+
+static int is_blkdev_swapping(unsigned int flags,
+			      struct file * swapf,
+			      void *data)
+{
+	struct test_data *testdata = (struct test_data *) data;
+	struct file * filp = testdata->filp;
+	kdev_t dev = testdata->dev;
+
+	/* Only check filp's that don't match the one already opened
+	 * for us by sys_swapon(). Otherwise, we will always flag a
+	 * busy swap file.
+	 */
+
+	if (swapf != filp) {
+		if (dev == swapf->f_dentry->d_inode->i_rdev)
+			return 1;
+	}
+	return 0;
+}
+
+static int blkdev_swap_open(struct file * filp, void **dptr)
+{
+	int swapfilesize;
+	kdev_t dev;
+	struct blkdev_swap_data *data;
+	int error;
+	struct test_data testdata;
+
+	MOD_INC_USE_COUNT;
+
+	if (!S_ISBLK(filp->f_dentry->d_inode->i_mode)) {
+		dprintk(__FUNCTION__": can't handle this swap file: %s\n",
+		       swapf->d_name.name);
+		error = 0; /* not for us */
+		goto bad_swap;
+	}
+	
+	dev = filp->f_dentry->d_inode->i_rdev;
+	set_blocksize(dev, PAGE_SIZE);
+	error = -ENODEV;
+	if (!dev ||
+	    (blk_size[MAJOR(dev)] && !blk_size[MAJOR(dev)][MINOR(dev)])) {
+		printk("blkdev_swap_open: blkdev weirdness for %s\n",
+		       filp->f_dentry->d_name.name);
+		goto bad_swap;
+	}
+		
+	/* Check to make sure that we aren't already swapping. */
+	error = -EBUSY;
+	testdata.filp = filp;
+	testdata.dev = dev;
+	if (swap_run_test(is_blkdev_swapping, &testdata)) {
+		printk("blkdev_swap_open: already swapping to %s\n",
+		       filp->f_dentry->d_name.name);
+		goto bad_swap;
+ 	}
+
+	swapfilesize = 0;
+	if (blk_size[MAJOR(dev)])
+		swapfilesize = blk_size[MAJOR(dev)][MINOR(dev)]
+			>> (PAGE_SHIFT - 10);
+
+	if ((data = kmalloc(sizeof(*data), GFP_KERNEL)) == NULL) {
+		printk("blkdev_swap_open: can't allocate data for %s\n",
+		       filp->f_dentry->d_name.name);
+		error = -ENOMEM;
+		goto bad_swap;
+	}
+	data->dev = dev;
+	*dptr = data;
+
+	dprintk("blkdev_swap_open: returning %d\n", swapfilesize);
+	return swapfilesize;
+
+ bad_swap:
+	MOD_DEC_USE_COUNT;
+	return error; /* this swap thing is not for us */	
+}
+
+static int blkdev_swap_release(struct file * filp, void *data)
+{
+	dprintk("blkdev_swap_release: releasing swap device %s\n",
+		filp->f_dentry->d_name.name);
+	kfree(data);
+	MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+static int blkdev_rw_page(int rw, struct page *page, unsigned long offset,
+			  void *ptr)
+{
+	struct blkdev_swap_data *data = (struct blkdev_swap_data *)ptr;
+ 	brw_page(rw, page, data->dev, (int *)&offset, PAGE_SIZE);
+	return 1;
+}
+
+static struct swap_ops blkdev_swap_ops = {
+	blkdev_swap_open,
+	blkdev_swap_release,
+	blkdev_rw_page
+};
+
+struct blkdevfile_swap_data {
+	struct inode *swapf;
+};
+
+static int is_blkdevfile_swapping(unsigned int flags,
+				  struct file * swapf,
+				  void * data)
+{
+	struct file * filp = (struct file *) data;
+
+	/* Only check filp's that don't match the one already opened
+	 * for us by sys_swapon(). Otherwise, we will always flag a
+	 * busy swap file.
+	 */
+
+	if (swapf != filp) {
+		if (filp->f_dentry->d_inode == swapf->f_dentry->d_inode)
+			return 1;
+	}
+	return 0;
+}
+
+static int blkdevfile_swap_open(struct file *swapf, void **dptr)
+{
+	int error = 0;
+	int swapfilesize;
+	struct blkdevfile_swap_data *data;
+
+	MOD_INC_USE_COUNT;
+
+	/* first check whether this is a regular file located on a local 
+	 * hard disk
+	 */
+	if (!S_ISREG(swapf->f_dentry->d_inode->i_mode)) {
+		dprintk("blkdevfile_swap_open: "
+			"can't handle this swap file: %s\n",
+			swapf->d_name.name);
+		error = 0; /* not for us */
+		goto bad_swap;
+	}
+	if (!swapf->f_dentry->d_inode->i_mapping->a_ops->bmap) {
+		dprintk("blkdevfile_swap_open: no bmap for file: %s\n",
+			swapf->d_name.name);
+		error = 0; /* not for us */
+		goto bad_swap;
+	}
+
+	if (swap_run_test(is_blkdevfile_swapping, swapf)) {
+		dprintk("blkdevfile_swap_open: already swapping to %s\n",
+			swapf->d_name.name);
+		error = -EBUSY;
+		goto bad_swap;
+	}
+	swapfilesize = swapf->f_dentry->d_inode->i_size >> PAGE_SHIFT;
+	if ((data = kmalloc(sizeof(*data), GFP_KERNEL)) == NULL) {
+		error = -ENOMEM;
+		goto bad_swap;
+	}
+	data->swapf = swapf->f_dentry->d_inode;
+	*dptr = data;
+	return swapfilesize;
+
+ bad_swap:
+	MOD_DEC_USE_COUNT;
+	return error;
+}
+
+static int blkdevfile_swap_release(struct file *swapf, void *data)
+{
+	kfree(data);
+	MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+static int blkdevfile_rw_page(int rw, struct page *page, unsigned long offset,
+			      void *ptr)
+{
+	struct blkdevfile_swap_data *data = (struct blkdevfile_swap_data *)ptr;
+	struct inode * swapf = data->swapf;
+	int i, j;
+	unsigned int block = offset
+		<< (PAGE_SHIFT - swapf->i_sb->s_blocksize_bits);
+	kdev_t dev = swapf->i_dev;
+	int block_size;
+	int zones[PAGE_SIZE/512];
+	int zones_used;
+
+	block_size = swapf->i_sb->s_blocksize;
+	for (i=0, j=0; j< PAGE_SIZE ; i++, j += block_size)
+		if (!(zones[i] = bmap(swapf,block++))) {
+			printk("blkdevfile_rw_page: bad swap file\n");
+			return 0;
+			}
+	zones_used = i;
+	
+ 	/* block_size == PAGE_SIZE/zones_used */
+ 	brw_page(rw, page, dev, zones, block_size);
+	return 1;
+}
+
+static struct swap_ops blkdevfile_swap_ops = {
+	blkdevfile_swap_open,
+	blkdevfile_swap_release,
+	blkdevfile_rw_page
+ };
+
+int __init blkdev_swap_init(void)
+{
+	(void)register_swap_method(BLKDEV_SWAP_ID, &blkdev_swap_ops);
+	(void)register_swap_method(BLKDEV_FILE_SWAP_ID, &blkdevfile_swap_ops);
+	return 0;
+}
+
+void __exit blkdev_swap_exit(void)
+{
+	unregister_swap_method(BLKDEV_SWAP_ID);
+	unregister_swap_method(BLKDEV_FILE_SWAP_ID);
+}
+
+module_init(blkdev_swap_init)
+module_exit(blkdev_swap_exit)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Many. Stuffed into a module by cH (Claus-Justus Heine)");
+MODULE_DESCRIPTION("Swapping to partitions and files on local hard-disks");
--- linux-2.4.20/fs/buffer.c~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/fs/buffer.c	2005-01-07 02:56:22.809168040 -0500
@@ -743,7 +743,7 @@
 	bh->b_private = private;
 }
 
-static void end_buffer_io_async(struct buffer_head * bh, int uptodate)
+void end_buffer_io_async(struct buffer_head * bh, int uptodate)
 {
 	static spinlock_t page_uptodate_lock = SPIN_LOCK_UNLOCKED;
 	unsigned long flags;
@@ -2345,47 +2345,6 @@
 	return err;
 }
 
-/*
- * Start I/O on a page.
- * This function expects the page to be locked and may return
- * before I/O is complete. You then have to check page->locked
- * and page->uptodate.
- *
- * brw_page() is SMP-safe, although it's being called with the
- * kernel lock held - but the code is ready.
- *
- * FIXME: we need a swapper_inode->get_block function to remove
- *        some of the bmap kludges and interface ugliness here.
- */
-int brw_page(int rw, struct page *page, kdev_t dev, int b[], int size)
-{
-	struct buffer_head *head, *bh;
-
-	if (!PageLocked(page))
-		panic("brw_page: page not locked for I/O");
-
-	if (!page->buffers)
-		create_empty_buffers(page, dev, size);
-	head = bh = page->buffers;
-
-	/* Stage 1: lock all the buffers */
-	do {
-		lock_buffer(bh);
-		bh->b_blocknr = *(b++);
-		set_bit(BH_Mapped, &bh->b_state);
-		set_buffer_async_io(bh);
-		bh = bh->b_this_page;
-	} while (bh != head);
-
-	/* Stage 2: start the IO */
-	do {
-		struct buffer_head *next = bh->b_this_page;
-		submit_bh(rw, bh);
-		bh = next;
-	} while (bh != head);
-	return 0;
-}
-
 int block_symlink(struct inode *inode, const char *symname, int len)
 {
 	struct address_space *mapping = inode->i_mapping;
--- linux-2.4.20/fs/nfs/Makefile~130-nfsswap	2001-11-09 17:28:15.000000000 -0500
+++ linux-2.4.20/fs/nfs/Makefile	2005-01-07 02:55:48.026455816 -0500
@@ -15,6 +15,14 @@
 obj-$(CONFIG_ROOT_NFS) += nfsroot.o mount_clnt.o      
 obj-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o
 
-obj-m   := $(O_TARGET)
+obj-$(CONFIG_SWAP_VIA_NFS) += nfsswap.o
+ifeq ($(CONFIG_SWAP_VIA_NFS),m)
+export-objs := nfs_syms.o
+obj-y += nfs_syms.o
+endif
+
+ifeq ($(CONFIG_NFS_FS),m)
+obj-m   += $(O_TARGET)
+endif
 
 include $(TOPDIR)/Rules.make
--- linux-2.4.20/fs/nfs/file.c~130-nfsswap	2002-02-25 14:38:09.000000000 -0500
+++ linux-2.4.20/fs/nfs/file.c	2005-01-07 02:55:48.026455816 -0500
@@ -58,11 +58,6 @@
 	setattr:	nfs_notify_change,
 };
 
-/* Hack for future NFS swap support */
-#ifndef IS_SWAPFILE
-# define IS_SWAPFILE(inode)	(0)
-#endif
-
 /*
  * Flush all dirty pages, and check for write errors.
  *
@@ -217,8 +212,6 @@
 		inode->i_ino, (unsigned long) count, (unsigned long) *ppos);
 
 	result = -EBUSY;
-	if (IS_SWAPFILE(inode))
-		goto out_swapfile;
 	result = nfs_revalidate_inode(NFS_SERVER(inode), inode);
 	if (result)
 		goto out;
@@ -230,10 +223,6 @@
 	result = generic_file_write(file, buf, count, ppos);
 out:
 	return result;
-
-out_swapfile:
-	printk(KERN_INFO "NFS: attempt to write to active swap file!\n");
-	goto out;
 }
 
 /*
--- /dev/null	2004-04-06 13:56:48.000000000 -0400
+++ linux-2.4.20/fs/nfs/nfs_syms.c	2005-01-07 02:55:48.026455816 -0500
@@ -0,0 +1,10 @@
+#include <linux/config.h>
+#define __NO_VERSION__
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/sunrpc/clnt.h>
+#include <linux/nfs_fs.h>
+
+EXPORT_SYMBOL(__nfs_refresh_inode);
+EXPORT_SYMBOL(nfs_write_attributes);
+
--- /dev/null	2004-04-06 13:56:48.000000000 -0400
+++ linux-2.4.20/fs/nfs/nfsswap.c	2005-01-07 02:55:48.027455664 -0500
@@ -0,0 +1,350 @@
+/*
+ * Swapping to files located on NFS mounted volumes
+ * Copyright (c) 2000 Claus-Justus Heine
+ *
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/swap.h>
+#include <linux/pagemap.h>
+#include <linux/file.h>
+#include <linux/fs.h>
+#include <linux/socket.h>
+#include <linux/smp_lock.h>
+#include <net/netswapping.h>
+#include <net/sock.h>
+
+#include <linux/sunrpc/clnt.h>
+#include <linux/nfs_fs.h>
+#include <linux/nfs_fs_sb.h>
+#include <asm/uaccess.h>
+
+#define NFSDBG_FACILITY		NFSDBG_SWAP
+
+#define NFS_SWAP_ID "nfs file"
+
+/* we cache some values here. In principle, we only need the file.
+ */
+struct nfs_swap_data {
+	struct file       *file;
+	struct inode      *inode;
+	struct nfs_server *server;
+	struct socket     *socket;
+};
+
+/* Nearly a clone of nfs_readpage_sync() in read.c, but "struct page" does not
+ * contain information about the file offset when swapping. So.
+ */
+static int nfs_read_swap_page(struct page *page,
+			      struct nfs_server *server,
+			      struct inode *inode,
+			      struct file  *file)
+{
+	unsigned int     rsize   = server->rsize;
+	unsigned int     count   = PAGE_SIZE;
+	unsigned int     offset  = 0; /* always at start of page */
+	int		 result, eof;
+	struct rpc_cred	 *cred;
+	struct nfs_fattr fattr;
+
+	cred = nfs_file_cred(file);
+
+	do {
+		if (count < rsize)
+			rsize = count;
+
+		lock_kernel();
+		result = NFS_PROTO(inode)->read(inode, cred,
+						&fattr,
+						NFS_RPC_SWAPFLAGS,
+						offset, rsize, page, &eof);
+		nfs_refresh_inode(inode, &fattr);
+		unlock_kernel();
+
+		/*
+		 * Even if we had a partial success we can't mark the page
+		 * cache valid.
+		 */
+		if (result < 0) {
+			if (result == -EISDIR)
+				result = -EINVAL;
+			goto io_error;
+		}
+		count  -= result;
+		offset += result;
+		if (result < rsize)	/* NFSv2ism */
+			break;
+	} while (count);
+
+	if (count) {
+		char *kaddr = kmap(page);
+		memset(kaddr + offset, 0, count);
+		kunmap(page);
+	}
+	flush_dcache_page(page);
+	result = 0;
+
+io_error:
+	return result;
+}
+
+/* Like nfs_writepage_sync(), but when swapping page->index does not encode
+ * the offset in the swap file alone.
+ *
+ */
+static int nfs_write_swap_page(struct page *page,
+			       struct nfs_server *server,
+			       struct inode *inode,
+			       struct file *file)
+{
+	struct rpc_cred	 *cred;
+	unsigned int     wsize   = server->wsize;
+	unsigned int     count   = PAGE_SIZE;
+	unsigned int     offset  = 0;
+	int              result;
+	struct nfs_writeverf verf;
+	struct nfs_fattr fattr;
+
+	cred = nfs_file_cred(file);
+
+	do {
+		if (count < wsize)
+			wsize = count;
+		
+		lock_kernel();
+		result = NFS_PROTO(inode)->write(inode, cred, &fattr,
+						 NFS_RW_SWAP|NFS_RW_SYNC, 
+						 offset, wsize, page, &verf);
+		nfs_write_attributes(inode, &fattr);
+		unlock_kernel();
+
+		if (result < 0) {
+			goto io_error;
+		}
+		if (result != wsize)
+			printk("NFS: short write, wsize=%u, result=%d\n",
+			wsize, result);
+		offset  += wsize;
+		count   -= wsize;
+		/*
+		 * If we've extended the file, update the inode
+		 * now so we don't invalidate the cache.
+		 */
+		if (offset > inode->i_size)
+			inode->i_size = offset;
+	} while (count);
+
+	result = 0;
+
+io_error:
+
+	return result;
+}
+
+/* Unluckily (for us) form 2.4.19 -> 2.4.20 the nfs-proc's where
+ * changed and expect now a proper file-mapping page, where index
+ * encodes the offset alone.
+ * 
+ * What we do: we save the original value of page->index, initialize
+ * page->index to what the NFS/sun-rpc subsystem expects and restore
+ * the index later.
+ */
+static int nfs_rw_swap_page(int rw, struct page *page,
+			    unsigned long offset, void *dptr)
+{
+	int error;
+	struct nfs_swap_data *data = dptr;
+	unsigned long alloc_flag = current->flags & PF_MEMALLOC;
+	unsigned long page_index;
+
+	if (!PageLocked(page))
+		panic("nfs_rw_swap_page: page not locked for I/O");
+
+	/* prevent memory deadlocks */
+	if (!(current->flags & PF_MEMALLOC)) {
+		dprintk("nfs_rw_swap_page: Setting PF_MEMALLOC\n");
+	}
+	current->flags |= PF_MEMALLOC;
+
+	/* now tweak the page->index field ... */
+	page_index  = page->index;
+	page->index = ((loff_t)offset*(loff_t)PAGE_SIZE) >> PAGE_CACHE_SHIFT;
+
+	if (rw == WRITE) {
+		error = nfs_write_swap_page(page,
+					    data->server,
+					    data->inode,
+					    data->file);
+	} else {
+		error = nfs_read_swap_page(page,
+					   data->server,
+					   data->inode,
+					   data->file);
+	}
+	
+	if (!alloc_flag) {
+		current->flags &= ~PF_MEMALLOC;
+	}
+
+	/* now restore the page->index field ... */
+	page->index = page_index;
+
+	if (error) {
+		/* Must mark the page invalid after I/O error */
+		SetPageError(page);
+		ClearPageUptodate(page);
+	} else {
+		ClearPageError(page);
+		SetPageUptodate(page);
+	}
+
+	if (!error) { /* in case of an error rw_swap_page() likes to unlock
+		       * itself.
+		       */
+		UnlockPage(page);
+	}
+
+	return error < 0 ? 0 : 1;
+}
+
+static int is_nfsfile_swapping(unsigned int flags,
+			       struct file * swapf,
+			       void * data)
+{
+	struct file * filp = (struct file *) data;
+
+	/* Only check filp's that don't match the one already opened
+	 * for us by sys_swapon(). Otherwise, we will always flag a
+	 * busy swap file.
+	 */
+
+	if (swapf != filp) {
+		if (filp->f_dentry->d_inode == swapf->f_dentry->d_inode)
+			return 1;
+	}
+	return 0;
+}
+
+static int nfs_swap_open(struct file *swapf, void **dptr)
+{
+	int error = 0;
+	int swapfilesize;
+	struct nfs_swap_data *data;
+	int on = 1;
+	mm_segment_t fs;
+	struct inode *inode = swapf->f_dentry->d_inode;
+
+	MOD_INC_USE_COUNT;
+
+	if (!S_ISREG(inode->i_mode)) {
+		dprintk("nfs_swap_open: can't handle this swap file: %s\n",
+			swapf->f_dentry->d_name.name);
+		error = 0; /* not for us */
+		goto bad_swap;
+	}
+	/* determine whether this file really is located on an NFS mounted
+	 * volume
+	 */
+	if (!inode->i_sb || inode->i_sb->s_magic != NFS_SUPER_MAGIC) {
+		dprintk("nfs_swap_open: %s is not an NFS file.\n",
+			swapf->f_dentry->d_name.name);
+		error = 0; /* not for us */
+		goto bad_swap;
+	}
+
+	if (swap_run_test(is_nfsfile_swapping, swapf)) {
+		dprintk("nfs_swap_open: already swapping to %s\n",
+			swapf->f_dentry->d_name.name);
+		error = -EBUSY;
+		goto bad_swap;
+	}
+	swapfilesize = inode->i_size >> PAGE_SHIFT;
+	if ((data = kmalloc(sizeof(*data), GFP_KERNEL)) == NULL) {
+		error = -ENOMEM;
+		goto bad_swap;
+	}
+	data->file   = swapf;
+	data->inode  = inode;
+	data->server = NFS_SERVER(inode);
+	data->socket = data->server->client->cl_xprt->sock;
+	
+	/* set socket option SO_SWAPPING */
+	fs = get_fs();
+	set_fs(KERNEL_DS);
+	error = sock_setsockopt(data->socket, SOL_SOCKET, SO_SWAPPING,
+				(char *)&on, sizeof(on));
+	set_fs(fs);
+	if (error) {
+		dprintk("nfs_swap_open: error setting SO_SWAPPING\n");
+		goto bad_swap_2;
+	}
+
+	*dptr = data;
+	return swapfilesize;
+
+ bad_swap_2:
+	kfree(data);
+ bad_swap:
+	MOD_DEC_USE_COUNT;
+	return error;
+}
+
+static int nfs_swap_release(struct file *swapf, void *dptr)
+{
+	struct nfs_swap_data *data = (struct nfs_swap_data *)dptr;
+	int off = 0;
+	mm_segment_t fs;
+	int error;
+
+#if 1
+	if (swapf != data->file ||
+	    swapf->f_dentry->d_inode != data->inode ||
+	    !swapf->f_dentry->d_inode->i_sb ||
+	    swapf->f_dentry->d_inode->i_sb->s_magic != NFS_SUPER_MAGIC ||
+	    NFS_SERVER(swapf->f_dentry->d_inode) != data->server ||
+	    data->socket != data->server->client->cl_xprt->sock) {
+		panic("nfs_swap_release: nfs swap data messed up");
+	}
+#endif
+
+	/* remove socket option SO_SWAPPING */
+	fs = get_fs();
+	set_fs(KERNEL_DS);
+	error = sock_setsockopt(data->socket, SOL_SOCKET, SO_SWAPPING,
+				(char *)&off, sizeof(off));
+	set_fs(fs);
+	if (error) {
+		dprintk("nfs_swap_open: error clearing SO_SWAPPING\n");
+	}
+	kfree(data);
+	MOD_DEC_USE_COUNT;
+	return error;
+}
+
+static struct swap_ops nfs_swap_ops = {
+	open: nfs_swap_open,
+	release: nfs_swap_release,
+	rw_page: nfs_rw_swap_page
+};
+
+int __init nfs_swap_init(void)
+{
+	(void)register_swap_method(NFS_SWAP_ID, &nfs_swap_ops);
+	return 0;
+}
+
+void __exit nfs_swap_exit(void)
+{
+	unregister_swap_method(NFS_SWAP_ID);
+}
+
+module_init(nfs_swap_init)
+module_exit(nfs_swap_exit)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("(c) 1996-2002 cH (Claus-Justus Heine)");
+MODULE_DESCRIPTION("Swapping to files located on volumes mounted via NFS");
--- linux-2.4.20/fs/nfs/read.c~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/fs/nfs/read.c	2005-01-07 02:55:48.027455664 -0500
@@ -50,11 +50,6 @@
  */
 static void	nfs_readpage_result(struct rpc_task *task);
 
-/* Hack for future NFS swap support */
-#ifndef IS_SWAPFILE
-# define IS_SWAPFILE(inode)	(0)
-#endif
-
 static kmem_cache_t *nfs_rdata_cachep;
 
 static __inline__ struct nfs_read_data *nfs_readdata_alloc(void)
@@ -92,7 +87,6 @@
 	int		rsize = NFS_SERVER(inode)->rsize;
 	int		result;
 	int		count = PAGE_CACHE_SIZE;
-	int		flags = IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0;
 	int		eof;
 
 	dprintk("NFS: nfs_readpage_sync(%p)\n", page);
@@ -114,7 +108,7 @@
 			offset, rsize, page);
 
 		lock_kernel();
-		result = NFS_PROTO(inode)->read(inode, cred, &fattr, flags,
+		result = NFS_PROTO(inode)->read(inode, cred, &fattr, 0,
 						offset, rsize, page, &eof);
 		nfs_refresh_inode(inode, &fattr);
 		unlock_kernel();
@@ -246,7 +240,7 @@
 	task = &data->task;
 
 	/* N.B. Do we need to test? Never called for swapfile inode */
-	flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
+	flags = RPC_TASK_ASYNC;
 
 	nfs_read_rpcsetup(head, data);
 
@@ -476,8 +470,6 @@
 	}
 
 	error = nfs_readpage_sync(file, inode, page);
-	if (error < 0 && IS_SWAPFILE(inode))
-		printk("Aiee.. nfs swap-in of page failed!\n");
 out:
 	return error;
 
--- linux-2.4.20/fs/nfs/write.c~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/fs/nfs/write.c	2005-01-07 02:57:10.476921440 -0500
@@ -49,7 +49,6 @@
 #include <linux/config.h>
 #include <linux/types.h>
 #include <linux/slab.h>
-#include <linux/swap.h>
 #include <linux/pagemap.h>
 #include <linux/file.h>
 
@@ -92,11 +91,6 @@
 static void	nfs_commit_done(struct rpc_task *);
 #endif
 
-/* Hack for future NFS swap support */
-#ifndef IS_SWAPFILE
-# define IS_SWAPFILE(inode)	(0)
-#endif
-
 static kmem_cache_t *nfs_wdata_cachep;
 
 static __inline__ struct nfs_write_data *nfs_writedata_alloc(void)
@@ -128,7 +122,7 @@
  * For the moment, we just call nfs_refresh_inode().
  */
 static __inline__ int
-nfs_write_attributes(struct inode *inode, struct nfs_fattr *fattr)
+__nfs_write_attributes(struct inode *inode, struct nfs_fattr *fattr)
 {
 	if ((fattr->valid & NFS_ATTR_FATTR) && !(fattr->valid & NFS_ATTR_WCC)) {
 		fattr->pre_size  = NFS_CACHE_ISIZE(inode);
@@ -139,6 +133,11 @@
 	return nfs_refresh_inode(inode, fattr);
 }
 
+int nfs_write_attributes(struct inode *inode, struct nfs_fattr *fattr)
+{
+	return __nfs_write_attributes(inode, fattr);
+}
+
 /*
  * Write a page synchronously.
  * Offset is the data offset within the page.
@@ -150,8 +149,7 @@
 	struct rpc_cred	*cred = NULL;
 	loff_t		base;
 	unsigned int	wsize = NFS_SERVER(inode)->wsize;
-	int		result, refresh = 0, written = 0, flags;
-	u8		*buffer;
+	int		result, refresh = 0, written = 0;
 	struct nfs_fattr fattr;
 	struct nfs_writeverf verf;
 
@@ -167,15 +165,14 @@
 
 	base = page_offset(page) + offset;
 
-	flags = ((IS_SWAPFILE(inode)) ? NFS_RW_SWAP : 0) | NFS_RW_SYNC;
-
 	do {
-		if (count < wsize && !IS_SWAPFILE(inode))
+		if (count < wsize)
 			wsize = count;
 
-		result = NFS_PROTO(inode)->write(inode, cred, &fattr, flags,
+		result = NFS_PROTO(inode)->write(inode, cred, &fattr,
+						 NFS_RW_SYNC,
 						 offset, wsize, page, &verf);
-		nfs_write_attributes(inode, &fattr);
+		__nfs_write_attributes(inode, &fattr);
 
 		if (result < 0) {
 			/* Must mark the page invalid after I/O error */
@@ -186,7 +183,6 @@
 			printk("NFS: short write, wsize=%u, result=%d\n",
 			wsize, result);
 		refresh = 1;
-		buffer  += wsize;
 		base    += wsize;
 	        offset  += wsize;
 		written += wsize;
@@ -1057,7 +1053,7 @@
 	 *	  writebacks since the page->count is kept > 1 for as long
 	 *	  as the page has a write request pending.
 	 */
-	nfs_write_attributes(inode, resp->fattr);
+	__nfs_write_attributes(inode, resp->fattr);
 	while (!list_empty(&data->pages)) {
 		req = nfs_list_entry(data->pages.next);
 		nfs_list_remove_request(req);
@@ -1211,7 +1207,7 @@
 	if (nfs_async_handle_jukebox(task))
 		return;
 
-	nfs_write_attributes(inode, resp->fattr);
+	__nfs_write_attributes(inode, resp->fattr);
 	while (!list_empty(&data->pages)) {
 		req = nfs_list_entry(data->pages.next);
 		nfs_list_remove_request(req);
--- linux-2.4.20/include/linux/fs.h~130-nfsswap	2005-01-07 02:54:46.357830000 -0500
+++ linux-2.4.20/include/linux/fs.h	2005-01-07 02:55:48.030455208 -0500
@@ -1507,6 +1507,10 @@
 extern int inode_change_ok(struct inode *, struct iattr *);
 extern int inode_setattr(struct inode *, struct iattr *);
 
+/* for swapping to block devices */
+void create_empty_buffers(struct page *page, kdev_t dev, unsigned long blocksize);
+void end_buffer_io_async(struct buffer_head * bh, int uptodate);
+
 /*
  * Common dentry functions for inclusion in the VFS
  * or in other stackable file systems.  Some of these
--- linux-2.4.20/include/linux/nfs_fs.h~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/include/linux/nfs_fs.h	2005-01-07 02:55:48.030455208 -0500
@@ -40,8 +40,8 @@
  */
 #define NFS_MAX_DIRCACHE		16
 
-#define NFS_MAX_FILE_IO_BUFFER_SIZE	32768
-#define NFS_DEF_FILE_IO_BUFFER_SIZE	4096
+#define NFS_MAX_FILE_IO_BUFFER_SIZE	(8*PAGE_SIZE)
+#define NFS_DEF_FILE_IO_BUFFER_SIZE	PAGE_SIZE
 
 /*
  * The upper limit on timeouts for the exponential backoff algorithm.
@@ -205,6 +205,8 @@
 extern int  nfs_writepage(struct page *);
 extern int  nfs_flush_incompatible(struct file *file, struct page *page);
 extern int  nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
+extern int nfs_write_attributes(struct inode *inode, struct nfs_fattr *fattr);
+
 /*
  * Try to write back everything synchronously (but check the
  * return value!)
@@ -375,6 +377,7 @@
 #define NFSDBG_XDR		0x0020
 #define NFSDBG_FILE		0x0040
 #define NFSDBG_ROOT		0x0080
+#define NFSDBG_SWAP             0x0100
 #define NFSDBG_ALL		0xFFFF
 
 #ifdef __KERNEL__
--- linux-2.4.20/include/linux/slab.h~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/include/linux/slab.h	2005-01-07 02:55:48.030455208 -0500
@@ -39,6 +39,7 @@
 #define	SLAB_HWCACHE_ALIGN	0x00002000UL	/* align objs on a h/w cache lines */
 #define SLAB_CACHE_DMA		0x00004000UL	/* use GFP_DMA memory */
 #define SLAB_MUST_HWCACHE_ALIGN	0x00008000UL	/* force alignment */
+#define SLAB_LOW_GFP_ORDER	0x00010000UL	/* use as low a gfp order as possible */
 
 /* flags passed to a constructor func */
 #define	SLAB_CTOR_CONSTRUCTOR	0x001UL		/* if not set, then deconstructor */
--- linux-2.4.20/include/linux/swap.h~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/include/linux/swap.h	2005-01-07 02:55:48.031455056 -0500
@@ -58,15 +58,29 @@
 #define SWAP_MAP_MAX	0x7fff
 #define SWAP_MAP_BAD	0x8000
 
+struct swap_ops {
+	int (*open)(struct file *swapf, void **data);
+	int (*release)(struct file *swapf, void *data);
+	int (*rw_page)(int rw,
+		       struct page *page, unsigned long offset, void *data);
+};
+
+struct swap_method {
+	struct swap_method *next;
+	char * name;
+	struct swap_ops *ops;
+	int use_count;
+};
+
 /*
  * The in-memory structure used to track swap areas.
  */
 struct swap_info_struct {
 	unsigned int flags;
-	kdev_t swap_device;
+	struct file *swap_file;
+	struct swap_method *method;
+	void *data;
 	spinlock_t sdev_lock;
-	struct dentry * swap_file;
-	struct vfsmount *swap_vfsmnt;
 	unsigned short * swap_map;
 	unsigned int lowest_bit;
 	unsigned int highest_bit;
@@ -141,11 +155,15 @@
 extern int total_swap_pages;
 extern unsigned int nr_swapfiles;
 extern struct swap_info_struct swap_info[];
-extern int is_swap_partition(kdev_t);
+extern int register_swap_method(char *name, struct swap_ops *ops);
+extern int unregister_swap_method(char *name);
+extern int swap_run_test(int (*test_fct)(unsigned int flags,
+					 struct file *swap_file,
+					 void *testdata), void *testdata);
 extern void si_swapinfo(struct sysinfo *);
 extern swp_entry_t get_swap_page(void);
-extern void get_swaphandle_info(swp_entry_t, unsigned long *, kdev_t *, 
-					struct inode **);
+struct swap_method *get_swaphandle_info(swp_entry_t entry,
+					unsigned long *offset, void **data);
 extern int swap_duplicate(swp_entry_t);
 extern int swap_count(struct page *);
 extern int valid_swaphandles(swp_entry_t, unsigned long *);
--- /dev/null	2004-04-06 13:56:48.000000000 -0400
+++ linux-2.4.20/include/net/netswapping.h	2005-01-07 02:55:48.031455056 -0500
@@ -0,0 +1,47 @@
+#ifndef _LINUX_NETSWAPPING_H
+#define _LINUX_NETSWAPPING_H
+
+#include <linux/swap.h>
+#include <linux/init.h>
+
+/* It is a mess. Socket options are defined in asm-ARCH/socket.h */
+
+#define SO_SWAPPING 0x00100000 /* hopefully not used by anybody else */
+
+#ifdef __KERNEL__
+
+#define CTL_NETSWAP 0x00100000
+
+enum {
+	NET_SWAP_DROPPED = 1,
+	NET_SWAP_DROP_THRESHOLD = 2,
+	NET_SWAP_SOCK_COUNT = 3
+};
+
+extern unsigned int netswap_free_pages_min;
+extern int netswap_sock_count;
+extern unsigned int netswap_dropped;
+
+/* this is "#defined" and not inline because sock.h includes us, but we need
+ * the "struct sock" definition.
+ */
+#define netswap_low_memory(sk, skb)					   \
+({									   \
+	int _ret = 0;							   \
+									   \
+	if (netswap_sock_count > 0 && /* anybody swapping via network? */  \
+	    !(sk)->swapping &&    /* but we are not needed for swapping */ \
+	    nr_free_pages() < netswap_free_pages_min) { /* so drop us */   \
+		printk("netswap_low_memory: "				   \
+		       "dropping skb 0x%p@0x%p\n", skb, sk);		   \
+		netswap_dropped ++;					   \
+		_ret = 1;						   \
+	}								   \
+	_ret;								   \
+})
+
+extern int __init netswap_init(void);
+
+#endif
+
+#endif
--- linux-2.4.20/include/net/sock.h~130-nfsswap	2002-08-02 20:39:46.000000000 -0400
+++ linux-2.4.20/include/net/sock.h	2005-01-07 02:55:48.032454904 -0500
@@ -103,6 +103,10 @@
 #include <linux/filter.h>
 #endif
 
+#ifdef CONFIG_NETSWAP
+#include <net/netswapping.h>
+#endif
+
 #include <asm/atomic.h>
 #include <net/dst.h>
 
@@ -539,6 +543,12 @@
 				no_check,
 				broadcast,
 				bsdism;
+#ifdef CONFIG_NETSWAP
+	/* Increased by SO_SWAPPING with arg != 0, decreased by
+	 * SO_SWAPPING with arg 0
+	 */
+	int 		        swapping;
+#endif
 	unsigned char		debug;
 	unsigned char		rcvtstamp;
 	unsigned char		use_write_queue;
@@ -1168,6 +1178,11 @@
 			return err;	/* Toss packet */
 	}
 #endif /* CONFIG_FILTER */
+#ifdef CONFIG_NETSWAP
+	/* an inline function defined in net/netswapping.h */
+	if (netswap_low_memory(sk, skb))
+		return -ENOMEM;
+#endif /* CONFIG_NETSWAP */
 
 	skb->dev = NULL;
 	skb_set_owner_r(skb, sk);
--- linux-2.4.20/kernel/ksyms.c~130-nfsswap	2005-01-07 02:54:46.362830000 -0500
+++ linux-2.4.20/kernel/ksyms.c	2005-01-07 02:55:48.032454904 -0500
@@ -41,6 +41,7 @@
 #include <linux/mm.h>
 #include <linux/capability.h>
 #include <linux/highuid.h>
+#include <linux/swapctl.h>
 #include <linux/brlock.h>
 #include <linux/fs.h>
 #include <linux/tty.h>
@@ -127,6 +128,11 @@
 EXPORT_SYMBOL(kmap_prot);
 EXPORT_SYMBOL(kmap_pte);
 #endif
+EXPORT_SYMBOL(nr_free_pages);
+/* EXPORT_SYMBOL(freepages); */
+EXPORT_SYMBOL(register_swap_method);
+EXPORT_SYMBOL(unregister_swap_method);
+EXPORT_SYMBOL(swap_run_test);
 
 /* filesystem internal functions */
 EXPORT_SYMBOL(def_blk_fops);
@@ -531,7 +537,7 @@
 EXPORT_SYMBOL(make_bad_inode);
 EXPORT_SYMBOL(is_bad_inode);
 EXPORT_SYMBOL(event);
-EXPORT_SYMBOL(brw_page);
+EXPORT_SYMBOL(end_buffer_io_async);
 EXPORT_SYMBOL(__inode_dir_notify);
 
 #ifdef CONFIG_UID16
--- linux-2.4.20/mm/page_io.c~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/mm/page_io.c	2005-01-07 02:55:48.033454752 -0500
@@ -36,11 +36,8 @@
 static int rw_swap_page_base(int rw, swp_entry_t entry, struct page *page)
 {
 	unsigned long offset;
-	int zones[PAGE_SIZE/512];
-	int zones_used;
-	kdev_t dev = 0;
-	int block_size;
-	struct inode *swapf = 0;
+	struct swap_method *method;
+	void *data;
 
 	if (rw == READ) {
 		ClearPageUptodate(page);
@@ -48,30 +45,11 @@
 	} else
 		kstat.pswpout++;
 
-	get_swaphandle_info(entry, &offset, &dev, &swapf);
-	if (dev) {
-		zones[0] = offset;
-		zones_used = 1;
-		block_size = PAGE_SIZE;
-	} else if (swapf) {
-		int i, j;
-		unsigned int block = offset
-			<< (PAGE_SHIFT - swapf->i_sb->s_blocksize_bits);
-
-		block_size = swapf->i_sb->s_blocksize;
-		for (i=0, j=0; j< PAGE_SIZE ; i++, j += block_size)
-			if (!(zones[i] = bmap(swapf,block++))) {
-				printk("rw_swap_page: bad swap file\n");
-				return 0;
-			}
-		zones_used = i;
-		dev = swapf->i_dev;
-	} else {
+	method = get_swaphandle_info(entry, &offset, &data);
+	if (!method || !method->ops->rw_page(rw, page, offset, data)) {
 		return 0;
 	}
 
- 	/* block_size == PAGE_SIZE/zones_used */
- 	brw_page(rw, page, dev, zones, block_size);
 	return 1;
 }
 
--- linux-2.4.20/mm/slab.c~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/mm/slab.c	2005-01-07 02:55:48.034454600 -0500
@@ -111,10 +111,12 @@
 # define CREATE_MASK	(SLAB_DEBUG_INITIAL | SLAB_RED_ZONE | \
 			 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
 			 SLAB_NO_REAP | SLAB_CACHE_DMA | \
-			 SLAB_MUST_HWCACHE_ALIGN)
+			 SLAB_MUST_HWCACHE_ALIGN | \
+			 SLAB_LOW_GFP_ORDER)
 #else
 # define CREATE_MASK	(SLAB_HWCACHE_ALIGN | SLAB_NO_REAP | \
-			 SLAB_CACHE_DMA | SLAB_MUST_HWCACHE_ALIGN)
+			 SLAB_CACHE_DMA | SLAB_MUST_HWCACHE_ALIGN | \
+			 SLAB_LOW_GFP_ORDER)
 #endif
 
 /*
@@ -247,8 +249,13 @@
 };
 
 /* internal c_flags */
-#define	CFLGS_OFF_SLAB	0x010000UL	/* slab management in own cache */
-#define	CFLGS_OPTIMIZE	0x020000UL	/* optimized slab lookup */
+#define	CFLGS_OFF_SLAB	0x020000UL	/* slab management in own cache */
+#define	CFLGS_OPTIMIZE	0x040000UL	/* optimized slab lookup */
+#define CFLGS_MASK (CFLGS_OFF_SLAB | CFLGS_OPTIMIZE)
+
+#if (CFLGS_MASK & CREATE_MASK)
+# error BUG: internal and external SLAB flags overlap
+#endif
 
 /* c_dflags (dynamic flags). Need to hold the spinlock to access this member */
 #define	DFLGS_GROWN	0x000001UL	/* don't reap a recently grown */
@@ -452,7 +459,12 @@
 		snprintf(name, sizeof(name), "size-%Zd",sizes->cs_size);
 		if (!(sizes->cs_cachep =
 			kmem_cache_create(name, sizes->cs_size,
-					0, SLAB_HWCACHE_ALIGN, NULL, NULL))) {
+					  0,
+#if CONFIG_NETSWAP
+					  SLAB_LOW_GFP_ORDER|  /* sorry */
+#endif
+					  SLAB_HWCACHE_ALIGN,
+					  NULL, NULL))) {
 			BUG();
 		}
 
@@ -732,6 +744,8 @@
 			break;
 		if (!cachep->num)
 			goto next;
+		if (cachep->gfporder == 0 && (flags & SLAB_LOW_GFP_ORDER))
+			break;
 		if (flags & CFLGS_OFF_SLAB && cachep->num > offslab_limit) {
 			/* Oops, this num of objs will cause problems. */
 			cachep->gfporder--;
--- linux-2.4.20/mm/swapfile.c~130-nfsswap	2002-08-02 20:39:46.000000000 -0400
+++ linux-2.4.20/mm/swapfile.c	2005-01-07 02:55:48.037454144 -0500
@@ -11,12 +11,17 @@
 #include <linux/swap.h>
 #include <linux/swapctl.h>
 #include <linux/blkdev.h> /* for blk_size */
+#include <linux/file.h>
 #include <linux/vmalloc.h>
 #include <linux/pagemap.h>
 #include <linux/shm.h>
 
 #include <asm/pgtable.h>
 
+#ifdef CONFIG_KMOD
+#include <linux/kmod.h>
+#endif
+
 spinlock_t swaplock = SPIN_LOCK_UNLOCKED;
 unsigned int nr_swapfiles;
 int total_swap_pages;
@@ -31,8 +36,78 @@
 
 struct swap_info_struct swap_info[MAX_SWAPFILES];
 
+static struct swap_method *swap_methods = NULL;
+
 #define SWAPFILE_CLUSTER 256
 
+int register_swap_method(char *name, struct swap_ops *ops)
+{
+	struct swap_method *pos;
+	struct swap_method *new;
+	int result = 0;
+
+	lock_kernel();
+
+	for (pos = swap_methods; pos; pos = pos->next) {
+		if (strcmp(pos->name, name) == 0) {
+			printk(KERN_ERR "register_swap_method: "
+			       "method %s already registered\n", name);
+			result = -EBUSY;
+			goto out;
+		}
+	}
+
+	if (!(new = kmalloc(sizeof(*new), GFP_KERNEL))) {
+		printk(KERN_ERR "register_swap_method: "
+		       "no memory for new method \"%s\"\n", name);
+		result = -ENOMEM;
+		goto out;
+	}
+
+	new->name      = name;
+	new->ops       = ops;
+	new->use_count = 0;
+
+	/* ok, insert at top of list */
+	printk("register_swap_method: method %s\n", name);
+	new->next    = swap_methods;
+	swap_methods = new;
+ out:
+	unlock_kernel();
+	return result;
+}
+
+int unregister_swap_method(char *name)
+{
+	struct swap_method **method, *next;
+	int result = 0;
+
+	lock_kernel();
+
+	for (method = &swap_methods; *method; method = &(*method)->next) {
+		if (strcmp((*method)->name, name) == 0) {
+			if ((*method)->use_count > 0) {
+				printk(KERN_ERR "unregister_swap_method: "
+				       "method \"%s\" is in use\n", name);
+				result = -EBUSY;
+				goto out;
+			}
+
+			next = (*method)->next;
+			kfree(*method);
+			*method = next;			
+			printk("unregister_swap_method: method %s\n", name);
+			goto out;
+		}
+	}
+	/* not found */
+	printk("unregister_swap_method: no such method %s\n", name);
+	result = -ENOENT;
+ out:
+	unlock_kernel();
+	return result;
+}
+
 static inline int scan_swap_map(struct swap_info_struct *si)
 {
 	unsigned long offset;
@@ -711,13 +786,14 @@
 	struct nameidata nd;
 	int i, type, prev;
 	int err;
+	struct file *swap_file;
 	
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
 	err = user_path_walk(specialfile, &nd);
 	if (err)
-		goto out;
+		return err;
 
 	lock_kernel();
 	prev = -1;
@@ -725,15 +801,20 @@
 	for (type = swap_list.head; type >= 0; type = swap_info[type].next) {
 		p = swap_info + type;
 		if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) {
-			if (p->swap_file == nd.dentry)
+			if (p->swap_file &&
+			    p->swap_file->f_dentry == nd.dentry)
 			  break;
 		}
 		prev = type;
 	}
 	err = -EINVAL;
+	/* p->swap_file contains all needed info, no need to keep nd, so
+	 * release it now.
+	 */
+	path_release(&nd);
 	if (type < 0) {
 		swap_list_unlock();
-		goto out_dput;
+		goto out;
 	}
 
 	if (prev < 0) {
@@ -767,32 +848,30 @@
 		total_swap_pages += p->pages;
 		p->flags = SWP_WRITEOK;
 		swap_list_unlock();
-		goto out_dput;
+		goto out;
 	}
-	if (p->swap_device)
-		blkdev_put(p->swap_file->d_inode->i_bdev, BDEV_SWAP);
-	path_release(&nd);
 
+	if (p->method->ops->release)
+		p->method->ops->release(p->swap_file, p->data);
 	swap_list_lock();
 	swap_device_lock(p);
-	nd.mnt = p->swap_vfsmnt;
-	nd.dentry = p->swap_file;
-	p->swap_vfsmnt = NULL;
+	p->method->use_count --;
+	p->method = NULL;
+	p->data   = NULL;
+	swap_file = p->swap_file;
 	p->swap_file = NULL;
-	p->swap_device = 0;
 	p->max = 0;
 	swap_map = p->swap_map;
 	p->swap_map = NULL;
 	p->flags = 0;
 	swap_device_unlock(p);
 	swap_list_unlock();
+	filp_close(swap_file, NULL);
 	vfree(swap_map);
 	err = 0;
 
-out_dput:
-	unlock_kernel();
-	path_release(&nd);
 out:
+	unlock_kernel();
 	return err;
 }
 
@@ -805,18 +884,17 @@
 	if (!page)
 		return -ENOMEM;
 
-	len += sprintf(buf, "Filename\t\t\tType\t\tSize\tUsed\tPriority\n");
+	len += sprintf(buf, "%-32s%-16s%-8s%-8sPriority\n",
+		       "Filename", "Type", "Size", "Used");
 	for (i = 0 ; i < nr_swapfiles ; i++, ptr++) {
 		if ((ptr->flags & SWP_USED) && ptr->swap_map) {
-			char * path = d_path(ptr->swap_file, ptr->swap_vfsmnt,
+			char * path = d_path(ptr->swap_file->f_dentry,
+					     ptr->swap_file->f_vfsmnt,
 						page, PAGE_SIZE);
 
 			len += sprintf(buf + len, "%-31s ", path);
 
-			if (!ptr->swap_device)
-				len += sprintf(buf + len, "file\t\t");
-			else
-				len += sprintf(buf + len, "partition\t");
+			len += sprintf(buf + len, "%-15s ", ptr->method->name);
 
 			usedswap = 0;
 			for (j = 0; j < ptr->max; ++j)
@@ -827,7 +905,7 @@
 					default:
 						usedswap++;
 				}
-			len += sprintf(buf + len, "%d\t%d\t%d\n", ptr->pages << (PAGE_SHIFT - 10), 
+			len += sprintf(buf + len, "%-8d%-8d%d\n", ptr->pages << (PAGE_SHIFT - 10), 
 				usedswap << (PAGE_SHIFT - 10), ptr->prio);
 		}
 	}
@@ -835,18 +913,55 @@
 	return len;
 }
 
-int is_swap_partition(kdev_t dev) {
+/* apply a test function to all active swap objects. E.g. for checking
+ * whether a partition is used for swapping
+ */
+int swap_run_test(int (*test_fct)(unsigned int flags,
+				  struct file * swap_file,
+				  void *testdata), void *testdata)
+{
 	struct swap_info_struct *ptr = swap_info;
 	int i;
 
 	for (i = 0 ; i < nr_swapfiles ; i++, ptr++) {
-		if (ptr->flags & SWP_USED)
-			if (ptr->swap_device == dev)
+		if (ptr->swap_file && 
+		    test_fct(ptr->flags, ptr->swap_file, testdata))
 				return 1;
 	}
 	return 0;
 }
 
+/* Walk through the list of known swap method until somebody wants to
+ * handle this file. Pick the first one which claims to be able to
+ * swap to this kind of file.
+ *
+ * return value: < 0: error, 0: not found, > 0: swapfilesize
+ */
+int find_swap_method(struct file *swap_file,
+		     struct swap_info_struct *p)
+{
+	int swapfilesize = 0;
+	struct swap_method *method;
+
+	p->method = NULL;
+	for (method = swap_methods; method; method = method->next) {
+		swapfilesize = method->ops->open(swap_file, &p->data);
+		if (swapfilesize == 0) {
+			continue;
+		}
+		if (swapfilesize > 0) {
+			p->method = method;
+			p->method->use_count ++;
+			p->swap_file = swap_file;
+			break;
+		}
+		if (swapfilesize < 0) {
+			break;
+		}
+	}
+	return swapfilesize;
+}
+
 /*
  * Written 01/25/92 by Simmule Turner, heavily changed by Linus.
  *
@@ -855,8 +970,6 @@
 asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
 {
 	struct swap_info_struct * p;
-	struct nameidata nd;
-	struct inode * swap_inode;
 	unsigned int type;
 	int i, j, prev;
 	int error;
@@ -866,8 +979,9 @@
 	int nr_good_pages = 0;
 	unsigned long maxpages = 1;
 	int swapfilesize;
-	struct block_device *bdev = NULL;
 	unsigned short *swap_map;
+	char * tmp_specialfile;
+	struct file *swap_file;
 	
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
@@ -886,8 +1000,7 @@
 		nr_swapfiles = type+1;
 	p->flags = SWP_USED;
 	p->swap_file = NULL;
-	p->swap_vfsmnt = NULL;
-	p->swap_device = 0;
+	p->method = NULL;
 	p->swap_map = NULL;
 	p->lowest_bit = 0;
 	p->highest_bit = 0;
@@ -901,53 +1014,56 @@
 		p->prio = --least_priority;
 	}
 	swap_list_unlock();
-	error = user_path_walk(specialfile, &nd);
-	if (error)
+
+	/* Open the swap using filp_open. Bail out on any errors. */
+	tmp_specialfile = getname(specialfile);
+	if (IS_ERR(tmp_specialfile)) {
+		error = PTR_ERR(tmp_specialfile);
 		goto bad_swap_2;
+	}
+	p->swap_file = filp_open(tmp_specialfile, O_RDWR, 0600);
+	putname(tmp_specialfile);
+	if (IS_ERR(p->swap_file)) {
+		error = PTR_ERR(p->swap_file);
+		goto bad_swap_1;
+	}
 
-	p->swap_file = nd.dentry;
-	p->swap_vfsmnt = nd.mnt;
-	swap_inode = nd.dentry->d_inode;
 	error = -EINVAL;
 
-	if (S_ISBLK(swap_inode->i_mode)) {
-		kdev_t dev = swap_inode->i_rdev;
-		struct block_device_operations *bdops;
-		devfs_handle_t de;
-
-		p->swap_device = dev;
-		set_blocksize(dev, PAGE_SIZE);
-		
-		bd_acquire(swap_inode);
-		bdev = swap_inode->i_bdev;
-		de = devfs_get_handle_from_inode(swap_inode);
-		bdops = devfs_get_ops(de);  /*  Increments module use count  */
-		if (bdops) bdev->bd_op = bdops;
+ 	swapfilesize = find_swap_method(p->swap_file, p);
+	if (swapfilesize < 0) {
+		error = swapfilesize;
+		goto bad_swap_1;
+	}
+#ifdef CONFIG_KMOD
+	if (swapfilesize == 0) {
+		(void)request_module("swapfile-mod");
 
-		error = blkdev_get(bdev, FMODE_READ|FMODE_WRITE, 0, BDEV_SWAP);
-		devfs_put_ops(de);/*Decrement module use count now we're safe*/
-		if (error)
-			goto bad_swap_2;
-		set_blocksize(dev, PAGE_SIZE);
-		error = -ENODEV;
-		if (!dev || (blk_size[MAJOR(dev)] &&
-		     !blk_size[MAJOR(dev)][MINOR(dev)]))
-			goto bad_swap;
-		swapfilesize = 0;
-		if (blk_size[MAJOR(dev)])
-			swapfilesize = blk_size[MAJOR(dev)][MINOR(dev)]
-				>> (PAGE_SHIFT - 10);
-	} else if (S_ISREG(swap_inode->i_mode))
-		swapfilesize = swap_inode->i_size >> PAGE_SHIFT;
-	else
-		goto bad_swap;
+		swapfilesize = find_swap_method(p->swap_file, p);
+		if (swapfilesize < 0) {
+			error = swapfilesize;
+			goto bad_swap_1;
+		}
+	}
+#endif		
+	if (swapfilesize == 0) {
+		printk("Don't know how to swap to this kind of file\n");
+		goto bad_swap_1; /* free swap map */
+	}
+  
+	/* After this point, the swap-file has been opened by the swap
+	 * method. We must make sure to use the bad_swap label for any
+	 * errors.
+	 */
 
 	error = -EBUSY;
 	for (i = 0 ; i < nr_swapfiles ; i++) {
 		struct swap_info_struct *q = &swap_info[i];
 		if (i == type || !q->swap_file)
 			continue;
-		if (swap_inode->i_mapping == q->swap_file->d_inode->i_mapping)
+		if (p->swap_file->f_dentry->d_inode->i_mapping
+		    ==
+		    q->swap_file->f_dentry->d_inode->i_mapping)
 			goto bad_swap;
 	}
 
@@ -1083,17 +1199,27 @@
 	swap_list_unlock();
 	error = 0;
 	goto out;
+
 bad_swap:
-	if (bdev)
-		blkdev_put(bdev, BDEV_SWAP);
+	if (p->method->ops->release)
+		p->method->ops->release(p->swap_file, p->data);
+	swap_list_lock();
+	p->method->use_count --;
+	p->method = NULL;
+	p->data = NULL;
+	swap_list_unlock();
+
+bad_swap_1:
+	swap_list_lock();
+	swap_file = p->swap_file;
+	p->swap_file = NULL;
+	swap_list_unlock();
+	filp_close(swap_file, NULL);
+	
 bad_swap_2:
+
 	swap_list_lock();
 	swap_map = p->swap_map;
-	nd.mnt = p->swap_vfsmnt;
-	nd.dentry = p->swap_file;
-	p->swap_device = 0;
-	p->swap_file = NULL;
-	p->swap_vfsmnt = NULL;
 	p->swap_map = NULL;
 	p->flags = 0;
 	if (!(swap_flags & SWAP_FLAG_PREFER))
@@ -1101,7 +1227,7 @@
 	swap_list_unlock();
 	if (swap_map)
 		vfree(swap_map);
-	path_release(&nd);
+
 out:
 	if (swap_header)
 		free_page((long) swap_header);
@@ -1217,8 +1343,8 @@
 /*
  * Prior swap_duplicate protects against swap device deletion.
  */
-void get_swaphandle_info(swp_entry_t entry, unsigned long *offset, 
-			kdev_t *dev, struct inode **swapf)
+struct swap_method *get_swaphandle_info(swp_entry_t entry,
+					unsigned long *offset, void **data)
 {
 	unsigned long type;
 	struct swap_info_struct *p;
@@ -1226,32 +1352,26 @@
 	type = SWP_TYPE(entry);
 	if (type >= nr_swapfiles) {
 		printk(KERN_ERR "rw_swap_page: %s%08lx\n", Bad_file, entry.val);
-		return;
+		return NULL;
 	}
 
 	p = &swap_info[type];
 	*offset = SWP_OFFSET(entry);
 	if (*offset >= p->max && *offset != 0) {
 		printk(KERN_ERR "rw_swap_page: %s%08lx\n", Bad_offset, entry.val);
-		return;
+		return NULL;
 	}
 	if (p->swap_map && !p->swap_map[*offset]) {
 		printk(KERN_ERR "rw_swap_page: %s%08lx\n", Unused_offset, entry.val);
-		return;
+		return NULL;
 	}
 	if (!(p->flags & SWP_USED)) {
 		printk(KERN_ERR "rw_swap_page: %s%08lx\n", Unused_file, entry.val);
-		return;
+		return NULL;
 	}
 
-	if (p->swap_device) {
-		*dev = p->swap_device;
-	} else if (p->swap_file) {
-		*swapf = p->swap_file->d_inode;
-	} else {
-		printk(KERN_ERR "rw_swap_page: no swap file or device\n");
-	}
-	return;
+	*data = p->data;
+	return p->method;
 }
 
 /*
--- linux-2.4.20/net/Config.in~130-nfsswap	2002-08-02 20:39:46.000000000 -0400
+++ linux-2.4.20/net/Config.in	2005-01-07 02:55:48.037454144 -0500
@@ -16,6 +16,9 @@
 fi
 bool 'Socket Filtering'  CONFIG_FILTER
 tristate 'Unix domain sockets' CONFIG_UNIX
+if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+    bool 'Swapping via network sockets (EXPERIMENTAL)' CONFIG_NETSWAP
+fi
 bool 'TCP/IP networking' CONFIG_INET
 if [ "$CONFIG_INET" = "y" ]; then
    source net/ipv4/Config.in
--- linux-2.4.20/net/Makefile~130-nfsswap	2002-08-02 20:39:46.000000000 -0400
+++ linux-2.4.20/net/Makefile	2005-01-07 02:55:48.037454144 -0500
@@ -51,6 +51,7 @@
 ifeq ($(CONFIG_NET),y)
 obj-$(CONFIG_MODULES)		+= netsyms.o
 obj-$(CONFIG_SYSCTL)		+= sysctl_net.o
+obj-$(CONFIG_NETSWAP)           += netswapping.o
 endif
 
 include $(TOPDIR)/Rules.make
--- linux-2.4.20/net/core/sock.c~130-nfsswap	2002-08-02 20:39:46.000000000 -0400
+++ linux-2.4.20/net/core/sock.c	2005-01-07 02:55:48.038453992 -0500
@@ -403,6 +403,21 @@
 			ret = -ENONET;
 			break;
 #endif
+#ifdef CONFIG_NETSWAP
+		case SO_SWAPPING:
+			if (valbool) {
+				if (!sk->swapping) {
+					netswap_sock_count ++;
+				}
+				sk->swapping ++;
+			} else if (sk->swapping > 0) {
+				sk->swapping --;
+				if (!sk->swapping) {
+					netswap_sock_count --;
+				}
+			}
+			break;
+#endif
 		/* We implement the SO_SNDLOWAT etc to
 		   not be settable (1003.1g 5.3) */
 		default:
@@ -553,6 +568,12 @@
 			goto lenout;
 		}
 
+#ifdef CONFIG_NETSWAP
+		case SO_SWAPPING:
+			v.val = sk->swapping;
+			break;
+#endif
+
 		/* Dubious BSD thing... Probably nobody even uses it, but
 		 * the UNIX standard wants it for whatever reason... -DaveM
 		 */
--- linux-2.4.20/net/ipv4/tcp_ipv4.c~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/net/ipv4/tcp_ipv4.c	2005-01-07 02:55:48.039453840 -0500
@@ -1657,6 +1657,12 @@
 	if (filter && sk_filter(skb, filter))
 		goto discard;
 #endif /* CONFIG_FILTER */
+#ifdef CONFIG_NETSWAP
+	/* tcp doesn't use sock_queue_rcv_skb() ... */
+	/* an inline function defined in net/netswapping.h */
+	if (netswap_low_memory(sk, skb))
+		goto discard;
+#endif /* CONFIG_NETSWAP */
 
   	IP_INC_STATS_BH(IpInDelivers);
 
--- linux-2.4.20/net/ipv6/tcp_ipv6.c~130-nfsswap	2002-11-28 18:53:15.000000000 -0500
+++ linux-2.4.20/net/ipv6/tcp_ipv6.c	2005-01-07 02:55:48.042453384 -0500
@@ -1433,6 +1433,12 @@
 	if (filter && sk_filter(skb, filter))
 		goto discard;
 #endif /* CONFIG_FILTER */
+#ifdef CONFIG_NETSWAP
+	/* tcp doesn't use sock_queue_rcv_skb() ... */
+	/* an inline function defined in net/netswapping.h */
+	if (netswap_low_memory(sk, skb))
+		goto discard;
+#endif /* CONFIG_NETSWAP */
 
 	/*
 	 *	socket locking is here for SMP purposes as backlog rcv
--- /dev/null	2004-04-06 13:56:48.000000000 -0400
+++ linux-2.4.20/net/netswapping.c	2005-01-07 02:55:48.042453384 -0500
@@ -0,0 +1,76 @@
+/*
+ * linux/net/swapping.c
+ *
+ * Support paging over network connections (inet only)
+ *
+ * (c) 2000 Claus-Justus Heine <heine@instmath.rwth-aachen.de>
+ */
+
+#include <linux/slab.h>
+#include <linux/swap.h>
+#include <linux/swapctl.h>
+#include <linux/skbuff.h>
+#include <linux/module.h>
+#include <linux/sysctl.h>
+#include <linux/init.h>
+#include <net/netswapping.h>
+#include <net/sock.h>
+#include <asm/uaccess.h>
+
+unsigned int netswap_dropped; /* statistics */
+unsigned int netswap_free_pages_min;
+int netswap_sock_count;   /* how many sockets have swapping option set */
+
+#ifdef CONFIG_SYSCTL
+
+static ctl_table netswap_table[] = {
+	{NET_SWAP_DROPPED, "dropped",
+	 &netswap_dropped, sizeof(int), 0644, NULL, &proc_dointvec },
+	{NET_SWAP_DROP_THRESHOLD, "threshold",
+	 &netswap_free_pages_min, sizeof(int), 0644, NULL, &proc_dointvec },
+	{NET_SWAP_SOCK_COUNT, "sock_count",
+	 &netswap_sock_count, sizeof(int), 0444, NULL, &proc_dointvec },
+	{0},
+};
+
+static struct ctl_table_header *netswap_sysctl_header;
+
+static ctl_table netswap_net_table[] = {
+	{CTL_NETSWAP, "swapping", NULL, 0, 0555, netswap_table},
+	{0}
+};
+
+static ctl_table netswap_root_table[] = {
+	{CTL_NET, "net", NULL, 0, 0555, netswap_net_table},
+	{0}
+};
+
+#endif
+
+int __init netswap_init(void)
+{
+	/* drop packets when below this threshold */
+	netswap_free_pages_min = 32 /* freepages.min */;
+#ifdef CONFIG_SYSCTL
+	netswap_sysctl_header = register_sysctl_table(netswap_root_table, 0);
+#endif
+	return 0;
+}
+
+void __exit netswap_exit(void)
+{
+#ifdef CONFIG_SYSCTL
+	unregister_sysctl_table(netswap_sysctl_header);
+#endif
+}
+
+/* linux/init.h -- VERY nice :-)
+ *
+ * On the other hand, we have no control over the order the initcalls
+ * are performed ...
+ *
+ * Actually, we are not compiled as module ...
+ */
+
+module_init(netswap_init)
+module_exit(netswap_exit)
--- linux-2.4.20/net/netsyms.c~130-nfsswap	2005-01-07 02:52:47.208944000 -0500
+++ linux-2.4.20/net/netsyms.c	2005-01-07 02:55:48.043453232 -0500
@@ -596,4 +596,10 @@
 EXPORT_SYMBOL(wireless_send_event);
 #endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */
 
+#ifdef CONFIG_NETSWAP
+EXPORT_SYMBOL(netswap_sock_count);
+EXPORT_SYMBOL(netswap_free_pages_min);
+EXPORT_SYMBOL(netswap_dropped);
+#endif
+
 #endif  /* CONFIG_NET */
--- linux-2.4.20/net/packet/af_packet.c~130-nfsswap	2002-08-02 20:39:46.000000000 -0400
+++ linux-2.4.20/net/packet/af_packet.c	2005-01-07 02:55:48.045452928 -0500
@@ -453,6 +453,12 @@
 			snaplen = res;
 	}
 #endif /* CONFIG_FILTER */
+#ifdef CONFIG_NETSWAP
+	/* packet doesn't use sock_queue_rcv_skb() ... */
+	/* an inline function defined in net/netswapping.h */
+	if (netswap_low_memory(sk, skb))
+		goto drop_n_restore;
+#endif /* CONFIG_NETSWAP */
 
 	if (atomic_read(&sk->rmem_alloc) + skb->truesize >= (unsigned)sk->rcvbuf)
 		goto drop_n_acct;
@@ -500,7 +506,7 @@
 	po->stats.tp_drops++;
 	spin_unlock(&sk->receive_queue.lock);
 
-#ifdef CONFIG_FILTER
+#if defined(CONFIG_FILTER) || defined(CONFIG_NETSWAP)
 drop_n_restore:
 #endif
 	if (skb_head != skb->data && skb_shared(skb)) {
@@ -561,6 +567,12 @@
 			snaplen = res;
 	}
 #endif
+#ifdef CONFIG_NETSWAP
+	/* packet doesn't use sock_queue_rcv_skb() ... */
+	/* an inline function defined in net/netswapping.h */
+	if (netswap_low_memory(sk, skb))
+		goto drop_n_restore;
+#endif /* CONFIG_NETSWAP */
 
 	if (sk->type == SOCK_DGRAM) {
 		macoff = netoff = TPACKET_ALIGN(TPACKET_HDRLEN) + 16;
--- linux-2.4.20/net/sunrpc/sched.c~130-nfsswap	2002-11-28 18:53:16.000000000 -0500
+++ linux-2.4.20/net/sunrpc/sched.c	2005-01-07 02:55:48.046452776 -0500
@@ -79,10 +79,11 @@
  */
 static spinlock_t rpc_sched_lock = SPIN_LOCK_UNLOCKED;
 
+#if CONFIG_SWAP_VIA_NFS || CONFIG_SWAP_VIA_NFS_MODULE
 /*
  * This is the last-ditch buffer for NFS swap requests
  */
-static u32			swap_buffer[PAGE_SIZE >> 2];
+static u32			swap_buffer[2*PAGE_SIZE >> 2];
 static long			swap_buffer_used;
 
 /*
@@ -96,6 +97,7 @@
 {
 	clear_bit(1, &swap_buffer_used);
 }
+#endif
 
 /*
  * Disable the timer for a given RPC task. Should be called with
@@ -501,6 +503,7 @@
 __rpc_execute(struct rpc_task *task)
 {
 	int		status = 0;
+	unsigned long alloc_flag = current->flags & PF_MEMALLOC;
 
 	dprintk("RPC: %4d rpc_execute flgs %x\n",
 				task->tk_pid, task->tk_flags);
@@ -510,6 +513,13 @@
 		return 0;
 	}
 
+	if (task->tk_flags & RPC_TASK_SWAPPER) {
+		if (!current->flags & PF_MEMALLOC) {
+			dprintk("__rpc_execute: Setting PF_MEMALLOC\n");
+		}
+		current->flags |= PF_MEMALLOC;
+	}
+
  restarted:
 	while (1) {
 		/*
@@ -554,7 +564,8 @@
 			rpc_set_sleeping(task);
 			if (RPC_IS_ASYNC(task)) {
 				spin_unlock_bh(&rpc_queue_lock);
-				return 0;
+				status = 0;
+				goto out;
 			}
 		}
 		spin_unlock_bh(&rpc_queue_lock);
@@ -563,7 +574,12 @@
 			/* sync task: sleep here */
 			dprintk("RPC: %4d sync task going to sleep\n",
 							task->tk_pid);
-			if (current->pid == rpciod_pid)
+			/* it's ok to wait for rpciod when swapping,
+			 * because this means it needed memory and is
+			 * doing the swap-out itself.
+			 */
+			if (current->pid == rpciod_pid &&
+			    !(task->tk_flags & RPC_TASK_SWAPPER))
 				printk(KERN_ERR "RPC: rpciod waiting on sync task!\n");
 
 			__wait_event(task->tk_wait, !RPC_IS_SLEEPING(task));
@@ -608,6 +624,10 @@
 	/* Release all resources associated with the task */
 	rpc_release_task(task);
 
+ out:
+	if (!alloc_flag) {
+		current->flags &= ~PF_MEMALLOC;
+	}	
 	return status;
 }
 
@@ -699,10 +719,16 @@
 {
 	u32	*buffer;
 	int	gfp;
+	unsigned long alloc_flag = current->flags & PF_MEMALLOC;
+	void    *ret = NULL;
 
-	if (flags & RPC_TASK_SWAPPER)
+	if (flags & RPC_TASK_SWAPPER) {
 		gfp = GFP_ATOMIC;
-	else if (flags & RPC_TASK_ASYNC)
+		if (!(current->flags & PF_MEMALLOC)) {
+			dprintk("rpc_allocate: Setting PF_MEMALLOC\n");
+		}
+		current->flags |= PF_MEMALLOC;
+	} else if (flags & RPC_TASK_ASYNC)
 		gfp = GFP_RPC;
 	else
 		gfp = GFP_KERNEL;
@@ -710,29 +736,44 @@
 	do {
 		if ((buffer = (u32 *) kmalloc(size, gfp)) != NULL) {
 			dprintk("RPC:      allocated buffer %p\n", buffer);
-			return buffer;
+			ret = buffer;
+			goto out;
 		}
+#if CONFIG_SWAP_VIA_NFS || CONFIG_SWAP_VIA_NFS_MODULE
 		if ((flags & RPC_TASK_SWAPPER) && size <= sizeof(swap_buffer)
 		    && rpc_lock_swapbuf()) {
 			dprintk("RPC:      used last-ditch swap buffer\n");
-			return swap_buffer;
+			ret = swap_buffer;
+			goto out;
+#endif
+		}
+		if (flags & RPC_TASK_ASYNC) {
+			ret = NULL;
+			goto out;
 		}
-		if (flags & RPC_TASK_ASYNC)
-			return NULL;
 		yield();
 	} while (!signalled());
 
-	return NULL;
+ out:
+	if (!alloc_flag) {
+		current->flags &= ~PF_MEMALLOC;
+	}
+	return ret;
 }
 
 void
 rpc_free(void *buffer)
 {
+#if CONFIG_SWAP_VIA_NFS || CONFIG_SWAP_VIA_NFS_MODULE
 	if (buffer != swap_buffer) {
+#endif
 		kfree(buffer);
 		return;
+#if CONFIG_SWAP_VIA_NFS || CONFIG_SWAP_VIA_NFS_MODULE
 	}
 	rpc_unlock_swapbuf();
+	printk("RPC:      Released swap buffer\n");
+#endif
 }
 
 /*
--- linux-2.4.20/net/sunrpc/xprt.c~130-nfsswap	2002-11-28 18:53:16.000000000 -0500
+++ linux-2.4.20/net/sunrpc/xprt.c	2005-01-07 02:55:48.047452624 -0500
@@ -139,7 +139,7 @@
 __xprt_lock_write(struct rpc_xprt *xprt, struct rpc_task *task)
 {
 	if (!xprt->snd_task) {
-		if (xprt->nocong || __xprt_get_cong(xprt, task))
+		if (__xprt_get_cong(xprt, task))
 			xprt->snd_task = task;
 	}
 	if (xprt->snd_task != task) {
@@ -179,7 +179,7 @@
 		if (!task)
 			return;
 	}
-	if (xprt->nocong || __xprt_get_cong(xprt, task))
+	if (__xprt_get_cong(xprt, task))
 		xprt->snd_task = task;
 }
 
@@ -276,6 +276,9 @@
 {
 	struct rpc_rqst *req = task->tk_rqstp;
 
+	if (xprt->nocong || RPC_IS_SWAPPER(task))
+		return 1;
+
 	if (req->rq_cong)
 		return 1;
 	dprintk("RPC: %4d xprt_cwnd_limited cong = %ld cwnd = %ld\n",