Date: Mon, 13 May 2013 18:19:43 +0300 From: Eugen-Andrei Gavriloaie <shiretu@gmail.com> To: freebsd-hackers@freebsd.org Subject: Managing userland data pointers in kqueue/kevent Message-ID: <CCE4FFC4-F846-4F81-85EE-776B753C63C6@gmail.com>
next in thread | raw e-mail | index | archive | help
--Apple-Mail=_DEAB8EC6-1EB6-4F18-8B38-E783ED902DC7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hello to all, I'm trying to reply to this thread: = http://lists.freebsd.org/pipermail/freebsd-hackers/2010-November/033565.ht= ml I also faced this very difficult task of tracking down the user data = registered into kq. I end up having some "Tokens" instances which I never deallocate but = always re-use them or create new ones if necessary. This tokens are used = as user data for kq. They are keeping the actual pointers inside them, = and the pointer itself has a reference to the Token. When the pointer = dies, I reset the guts of the token. When the time comes to use the = token, I have the guarantee is not the corpse of a token (never = deallocate them, remember?) and I can see that the actual pointer was = gone, everyone is happy. At the application shutdown, I cleanup the mess = (the tokens). However, I just want to say that Paul has a valid point = when he is wondering why EV_FREEWATCH was not provisioned/implemented.=20= The moment we throw multi-threading into equation, this becomes a = extremely hard thing to manage (close to impossible), including my = "proven-to-work" Token trick. It renders the user data pointer = completely useless because in the end we need to keep an association map = inside user space. That is forcing user space code to do a lookup before = use, instead of straightforward use. Not to mention the fact that we = need to perform a lock before searching it. That brings havoc on kernel = side on 1000+ active connections (a multi-threaded streaming server for = example).=20 I'm pretty sure this user data pointer is also breaking a well known = pointer management paradigm, but I just can't remember which. = Regardless, it has all the ingredients for memory leaks and/or, the = worst one, use of corpse pointers which are bound to crash the app. I = agree, C/C++ is not for the faint of heart, but with little or close to = no efforts, his EV_FREEWATCH can be put to very good use, and user space = code not only becomes less prone to mem issues, but also cleaner. To summarise, +1 for the EV_FREEWATCH. I simply love the idea! Clean and = very very efficient. Best regards, Andrei ------ Eugen-Andrei Gavriloaie Web: http://www.rtmpd.com --Apple-Mail=_DEAB8EC6-1EB6-4F18-8B38-E783ED902DC7 Content-Disposition: attachment; filename=smime.p7s Content-Type: application/pkcs7-signature; name=smime.p7s Content-Transfer-Encoding: base64 MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIO5jCCBJ0w ggOFoAMCAQICEDQ96SusJzT/j8s0lPvMcFQwDQYJKoZIhvcNAQEFBQAwbzELMAkGA1UEBhMCU0Ux FDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5hbCBUVFAgTmV0 d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9vdDAeFw0wNTA2MDcwODA5MTBa Fw0yMDA1MzAxMDQ4MzhaMIGuMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVVQxFzAVBgNVBAcTDlNh bHQgTGFrZSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxITAfBgNVBAsTGGh0 dHA6Ly93d3cudXNlcnRydXN0LmNvbTE2MDQGA1UEAxMtVVROLVVTRVJGaXJzdC1DbGllbnQgQXV0 aGVudGljYXRpb24gYW5kIEVtYWlsMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsjmF pPJ9q0E7YkY3rs3BYHW8OWX5ShpHornMSMxqmNVNNRm5pELlzkniii8efNIxB8dOtINknS4p1aJk xIW9hVE1eaROaJB7HHqkkqgX8pgV8pPMyaQylbsMTzC9mKALi+VuG6JG+ni8om+rWV6lL8/K2m2q L+usobNqqrcuZzWLeeEeaYji5kbNoKXqvgvOdjp6Dpvq/NonWz1zHyLmSGHGTPNpsaguG7bUMSAs vIKKjqQOpdeJQ/wWWq8dcdcRWdq6hw2v+vPhwvCkxWeM1tZUOt4KpLoDd7NlyP0e03RiqhjKaJMe oYV+9Udly/hNVyh00jT/MLbu9mIwFIws6wIDAQABo4H0MIHxMB8GA1UdIwQYMBaAFK29mHo0tCb3 +sQmVO8DveA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PXVsiincjXx4xbMVGIMbn6tNxUOVoQjar6dH7sxq5zJ4Xk6a4mfGREPEBoLNJexs qKpctLIJ0s4PCA0qKJhTaxNdc8UVAAAAAAAA --Apple-Mail=_DEAB8EC6-1EB6-4F18-8B38-E783ED902DC7--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CCE4FFC4-F846-4F81-85EE-776B753C63C6>