Date: Sun, 16 Jun 2002 22:19:19 -0600 From: "Kenneth D. Merry" <ken@kdm.org> To: current@FreeBSD.org Cc: alc@FreeBSD.org Subject: vm_object_allocate() question Message-ID: <20020616221919.A78576@panzer.kdm.org>
next in thread | raw e-mail | index | archive | help
--W/nzBZO5zC0uMSeA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline As part of my zero copy patches, I have to allocate a vm object. To keep the object pointer from potentially getting spammed, I have it protected by a mutex. vm_object_allocate() calls uma_zalloc() with the M_WAITOK flag, therefore WITNESS complains that we could sleep with a mutex held. There are two obvious solutions to the problem, and I'd like some opinions on which is the better approach: 1. Allocate my vm object and assign it to a temporary variable in jumbo_vm_init() outside the mutex protection. Only assign it to the right pointer if we haven't already been initialized. This would work, but seems like it would be a bit of an unnecessary step. 2. Change vm_object_allocate() somehow so that uma_zalloc() isn't called with M_WAITOK. I've attached patches for the second option. I created a new function, vm_object_allocate_wait(), that allows the user to specify whether or not to wait on the uma_zalloc() call. vm_object_allocate() is a wrapper for the new vm_object_allocate_wait() call that preserves the current behavior. Patches are attached, comments would be appreciated! Thanks, Ken -- Kenneth Merry ken@kdm.org --W/nzBZO5zC0uMSeA Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="vm_object_allocate.20020616" ==== //depot/FreeBSD-zero/src/sys/kern/uipc_jumbo.c#3 - /usr/home/ken/perforce/FreeBSD-zero/src/sys/kern/uipc_jumbo.c ==== *** /tmp/tmp.72862.0 Sun Jun 16 22:11:05 2002 --- /usr/home/ken/perforce/FreeBSD-zero/src/sys/kern/uipc_jumbo.c Sun Jun 16 21:39:21 2002 *************** *** 101,107 **** } /* allocate our object */ ! jumbo_vm_object = vm_object_allocate(OBJT_DEFAULT, JUMBO_MAX_PAGES); SLIST_INIT(&jumbo_kmap_free); SLIST_INIT(&jumbo_kmap_inuse); --- 101,113 ---- } /* allocate our object */ ! jumbo_vm_object = vm_object_allocate_wait(OBJT_DEFAULT, JUMBO_MAX_PAGES, ! M_NOWAIT); ! ! if (jumbo_vm_object == NULL) { ! mtx_unlock(&jumbo_mutex); ! return (0); ! } SLIST_INIT(&jumbo_kmap_free); SLIST_INIT(&jumbo_kmap_inuse); ==== //depot/FreeBSD-zero/src/sys/vm/vm_object.c#13 - /usr/home/ken/perforce/FreeBSD-zero/src/sys/vm/vm_object.c ==== *** /tmp/tmp.72862.1 Sun Jun 16 22:11:05 2002 --- /usr/home/ken/perforce/FreeBSD-zero/src/sys/vm/vm_object.c Wed Jun 5 21:28:48 2002 *************** *** 336,354 **** } /* ! * vm_object_allocate: * ! * Returns a new object with the given size. */ vm_object_t ! vm_object_allocate(objtype_t type, vm_size_t size) { vm_object_t result; ! result = (vm_object_t) uma_zalloc(obj_zone, M_WAITOK); ! _vm_object_allocate(type, size, result); return (result); } --- 336,369 ---- } /* ! * vm_object_allocate_wait * ! * Return a new object with the given size, and give the user the ! * option of waiting for it to complete or failing if the needed ! * memory isn't available. */ vm_object_t ! vm_object_allocate_wait(objtype_t type, vm_size_t size, int flags) { vm_object_t result; ! result = (vm_object_t) uma_zalloc(obj_zone, flags); ! ! if (result != NULL) ! _vm_object_allocate(type, size, result); return (result); + } + + /* + * vm_object_allocate: + * + * Returns a new object with the given size. + */ + vm_object_t + vm_object_allocate(objtype_t type, vm_size_t size) + { + return(vm_object_allocate_wait(type, size, M_WAITOK)); } ==== //depot/FreeBSD-zero/src/sys/vm/vm_object.h#7 - /usr/home/ken/perforce/FreeBSD-zero/src/sys/vm/vm_object.h ==== *** /tmp/tmp.72862.2 Sun Jun 16 22:11:05 2002 --- /usr/home/ken/perforce/FreeBSD-zero/src/sys/vm/vm_object.h Wed Jun 5 21:28:57 2002 *************** *** 183,188 **** --- 183,189 ---- void vm_object_pip_wait(vm_object_t object, char *waitid); vm_object_t vm_object_allocate (objtype_t, vm_size_t); + vm_object_t vm_object_allocate_wait (objtype_t, vm_size_t, int); void _vm_object_allocate (objtype_t, vm_size_t, vm_object_t); boolean_t vm_object_coalesce (vm_object_t, vm_pindex_t, vm_size_t, vm_size_t); void vm_object_collapse (vm_object_t); --W/nzBZO5zC0uMSeA-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020616221919.A78576>