[Patch] swapfile.c

Nathan D. Fabian (ndfabia@sandia.gov)
Tue, 19 Jun 2001 18:24:25 -0600


--------------Boundary-00=_P4D7RQCU0F69RZW8TCH0
Content-Type: text/plain;
charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

The following diff tries to improve on the efficiency of try_to_unuse(). =
It=20
removes the potential O(|swap_map|^2) business and makes it linear time. =
=20
I'm not sure what this means in terms of overall change, but Linus seemed=
=20
interested in the innefficiency in that code. Test with caution.

Nathan.
--------------Boundary-00=_P4D7RQCU0F69RZW8TCH0
Content-Type: text/x-c;
charset=iso-8859-1;
name=swapfile.diff
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=swapfile.diff

ZGlmZiAtdXdyTiBsaW51eC9tbS9zd2FwZmlsZS5jLm9sZCBsaW51eC9tbS9zd2FwZmlsZS5jCi0t
LSBsaW51eC9tbS9zd2FwZmlsZS5jLm9sZAlUdWUgSnVuIDE5IDE3OjE1OjA3IDIwMDEKKysrIGxp
bnV4L21tL3N3YXBmaWxlLmMJVHVlIEp1biAxOSAxNzo0NDoyNCAyMDAxCkBAIC0zMjgsNiArMzI4
LDQxIEBACiAJcmV0dXJuOwogfQogCitzdGF0aWMgaW50IHVudXNlX2VudHJ5IChzd3BfZW50cnlf
dCBlbnRyeSkgeworCXN0cnVjdCBwYWdlICpwYWdlOworCXN0cnVjdCB0YXNrX3N0cnVjdCAqcDsK
KworCS8qIEdldCBhIHBhZ2UgZm9yIHRoZSBlbnRyeSwgdXNpbmcgdGhlIGV4aXN0aW5nIHN3YXAK
KyAgICAgICAJY2FjaGUgcGFnZSBpZiB0aGVyZSBpcyBvbmUuICBPdGhlcndpc2UsIGdldCBhIGNs
ZWFuCisgICAgICAgCXBhZ2UgYW5kIHJlYWQgdGhlIHN3YXAgaW50byBpdC4gKi8KKwlwYWdlID0g
cmVhZF9zd2FwX2NhY2hlX2FzeW5jKGVudHJ5KTsKKwlpZiAoIXBhZ2UpIHsKKwkJc3dhcF9mcmVl
KGV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ZpY2VfdW5sb2NrKHNpKTsKIAkJc3dhcF9saXN0
X3VubG9jaygpOworCisJCQkvKiBMZWF2ZSB0aGUgZGV2aWNlIGxvY2tlZCBmb3IgbG9vcCAqLwor
CQl9CiAJfQorCXN3YXBfZGV2aWNlX3VubG9jayAoc2kpOworCiAJcmV0dXJuIDA7CiB9CiAK

--------------Boundary-00=_P4D7RQCU0F69RZW8TCH0--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/