From owner-freebsd-net@FreeBSD.ORG Tue Oct 15 00:40:36 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5AD722DA for ; Tue, 15 Oct 2013 00:40:36 +0000 (UTC) (envelope-from laurie_jennings_1977@yahoo.com) Received: from nm3-vm0.bullet.mail.bf1.yahoo.com (nm3-vm0.bullet.mail.bf1.yahoo.com [98.139.212.154]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EB29A236E for ; Tue, 15 Oct 2013 00:40:35 +0000 (UTC) Received: from [66.196.81.171] by nm3.bullet.mail.bf1.yahoo.com with NNFMP; 15 Oct 2013 00:40:28 -0000 Received: from [98.139.212.245] by tm17.bullet.mail.bf1.yahoo.com with NNFMP; 15 Oct 2013 00:40:28 -0000 Received: from [127.0.0.1] by omp1054.mail.bf1.yahoo.com with NNFMP; 15 Oct 2013 00:40:28 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 921048.35951.bm@omp1054.mail.bf1.yahoo.com Received: (qmail 86745 invoked by uid 60001); 15 Oct 2013 00:40:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1381797628; bh=0r467h4lPFN3ohkziKN4P89dl95yHQdX5ip/LYtFx3Q=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=bQux1E+uCbjxdrIfCpygTFoLK5zsOV6LMPHON4zCG+pnf0ZGKtqrEhKqAPLoeDJ+/ClnaNvjeOALupz5rJ4bK4v/aMwxC9jHrqeDTrdaQPtn/zJikHYJb8LpNd6VvUkW1ouXNkzq+wKdSthFySQ7M0Dgla94efqQ4hou1kUqhZk= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=2BnDR8iISFafleznNIPMQMjGD2Rbhv3g0ySXWjNp4hL0R62CRmfMhUp744O+c1Lu+7RmJaOAUQSebgUlUGaZtnMBpRHPG/iLXRFybDhGzJxkc+AlCZnbwhTxEyou0+b2t/007VVTR/R/z7U7A4EiTe3J6kP+yBOfdQ/trDw2wc4=; X-YMail-OSG: mZqivQEVM1lJyLslkwgMPzAroFWYYkxSGK5pXAEHFd23Zfd 3_1WXMnxJRqRgYf25lHGlfHk2HLgpv3eLq34kcovUdKBHzMigu4lvrg38pPQ x0QSzziweuAMu1T14VZ3d6EPMPxbGetOnxhEReMLgylIvC.A7V0f9C3pw3Wz d3WXu7Xz4DMDXxwlxQspW6qPdV4w6dMDZmDQDvCb9dwiXN5iGhqVPFyDfM9N aklKbbCSefF1c4_cG7IN_QSn6y_zGAzQUWPWwlPe3JmboGFPWLQ4gLJGJZki X.13cWUhxf3piMyQuCnIzDEReyE3BOMBkGhjIKIKgFL8h6eRdpuPSQzhw4xO Cdpf7hSw8HpGjzk9bgmgv1EHcX4Hu85sDSGgJCjICC49J5WZPTpTcKbQ3dj4 UafZwChYeV8EF6n5uDs1lVnaczD0TlQRqA0feqGQIymzHfEgW5Q17S9zQqXl TIoXS3gPTYADSUDgXf0KA_J85GGiecsRzLOhvJA.ZROdlmUsDPcGTI7lqdq. nmjD43AkqpT0e90aj0xylzDcNDRqMkqR9.QeQXvR3Xhx.T6sDkVCkroukZyM - Received: from [98.203.118.124] by web125802.mail.ne1.yahoo.com via HTTP; Mon, 14 Oct 2013 17:40:28 PDT X-Rocket-MIMEInfo: 002.001, Sm9obiwgDQoNCkkgZ290IHRoaXMgd29ya2luZyB0aGFua3MgdG8geW91ciBoZWxwLiBJIGhhdmUgdG8gcnVuIG15IGFwcCBvbiBhbiBvbGQgc3lzdGVtIGFuZCBJIGNhbid0DQpnZXQgc2htX21hcCB0byB3b3JrIG9uIGEgMzItYml0IGJ1aWxkLiAgSSd2ZSB0cmFjZWQgaXQgdG8gdm1fZmF1bHRfd2lyZSgpIHJldHVybmluZyAyIChLRVJOX1BST1RFQ1RJT05fRkFJTFVSRSkuDQpUaGlzIHN0dWZmIGlzIGFib3ZlIG15IHBheSBncmFkZS4gSXMgdGhlcmUgc29tZSBvcHRpb24gdGhhdCBJJ20gbWlzc2luZz8gSSABMAEBAQE- X-Mailer: YahooMailClassic/352 YahooMailWebService/0.8.160.587 Message-ID: <1381797628.75337.YahooMailBasic@web125802.mail.ne1.yahoo.com> Date: Mon, 14 Oct 2013 17:40:28 -0700 (PDT) From: Laurie Jennings Subject: Re: shm_map questions To: freebsd-net@freebsd.org, John Baldwin In-Reply-To: <201304221143.54205.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 00:40:36 -0000 John,=20 I got this working thanks to your help. I have to run my app on an old syst= em and I can't get shm_map to work on a 32-bit build. I've traced it to vm_fault_wire() r= eturning 2 (KERN_PROTECTION_FAILURE). This stuff is above my pay grade. Is there some option that I'm missing? I = need to make this work and it's driving me crazy! Laurie -------------------------------------------- On Mon, 4/22/13, John Baldwin wrote: Subject: Re: shm_map questions To: freebsd-net@freebsd.org Cc: "Laurie Jennings" Date: Monday, April 22, 2013, 8:43 AM =20 On Saturday, April 20, 2013 9:18:24 pm Laurie Jennings wrote: > That does help. Is there a way for the kernel to access the memory map=20 directlyby segment name? =20 There is not, no.=A0 It wouldn't be hard to add, but the issue there is that the existing shm_map/unmap API assumes you have an open file descriptor and is tailored to having a userland process provide memory rather than having the kernel provide a SHM to userland, so even if you added a shm_open() that gave you a reference on the underlying shm object (struct shmfd *), you would need a slightly different shm_map/unmap that took that object directly rather than an fd. =20 > Laurie >=20 > --- On Thu, 4/18/13, John Baldwin wrote: >=20 > From: John Baldwin > Subject: Re: shm_map questions > To: freebsd-net@freebsd.org > Cc: "Laurie Jennings" > Date: Thursday, April 18, 2013, 6:50 AM >=20 > On Thursday, April 11, 2013 10:58:14 am Laurie Jennings wrote: > > Im working on a simple project that shares a memory segment between a user=20 > processand a kernel module. I'm having some problems with shm_map and there=20 > doesn't seem to be much info on it. > > Im not sure what happened to the memory when the user process that creates=20 > it terminates.=A0 I have some questions. > > 1) Does the kernel mapping keep the segment from being garbage collected=20 > when the use process that creates it terminated? I've experienced=20 shm_unmap()=20 > panic when tryingto unmap a segment > > scenario:=A0=20 > > User process Maps SegmentKernel maps it=A0 with shm_map()User Process=20 > TerminatesKernel tries to shm_unmap() and it panics. >=20 > The kernel mapping bumps the refcount on the underlying vm object, so it=20 will > not go away.=A0 OTOH, you should be keeping your own reference count on the > associated fd so that you can call shm_unmap().=A0 That is, the model should=20 be > something like: >=20 > struct mydata *foo; >=20 > foo->fp =3D fget(fd); > shm_map(fp, &foo->p); > /* Don't call fdrop */ >=20 > and then when unmapping: >=20 > struct mydata *foo; >=20 > shm_unmap(foo->fp, foo->p); > fdrop(foo->fp); >=20 > > 2) Is there a way for the kernel process to know when the user process has=20 > goneaway? A ref count? >=20 > You can install a process_exit EVENTHANDLER if you want to destroy this when=20 a > process goes away.=A0 I have used shm_map/unmap for other objects that already > had a reference count so I did my shm_unmap when that object was destroyed. >=20 > > 3) Does a SHM_ANON segment persist as long as the kernel has it mapped, or=20 > doesit get garbage collected when the creating user process terminates? >=20 > It goes away when the backing 'struct file' goes away.=A0 If you follow the=20 > model above of keeping a reference count on the associated struct file then > it won't go away until you fdrop() after the shm_unmap. >=20 > > 4) When using a named segment, can the kernel "reuse" a mapping for a new=20 > userprocess? > > Example: > > User process creates shm segment with path /fooKernel Maps shm segment=20 with=20 > shm_map()User process terminates.User process runs again, opening segment=20 /foo > > Does the kernel need to re-map, or is the original mapping valid? >=20 > The mapping is not per-process, so if you have mapped a shm for /foo and > mapped it, it will stay mapped until you call shm_unmap.=A0 Multiple processes > can shm_open /foo and mmap it and they will all share the same memory. >=20 > You could even share a SHM_ANON fd among multiple processes by passing it > across a UNIX domain socket. >=20 > Hope this helps. >=20 > --=20 > John Baldwin > _______________________________________________ > freebsd-net@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" > _______________________________________________ > freebsd-net@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" >=20 =20 --=20 John Baldwin _______________________________________________ freebsd-net@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-net To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"