From owner-freebsd-arch@FreeBSD.ORG Thu Jun 7 00:41:49 2007 Return-Path: X-Original-To: arch@freebsd.org Delivered-To: freebsd-arch@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3B7EB16A46C for ; Thu, 7 Jun 2007 00:41:49 +0000 (UTC) (envelope-from howard0su@gmail.com) Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.177]) by mx1.freebsd.org (Postfix) with ESMTP id B2AF213C455 for ; Thu, 7 Jun 2007 00:41:48 +0000 (UTC) (envelope-from howard0su@gmail.com) Received: by py-out-1112.google.com with SMTP id a29so588603pyi for ; Wed, 06 Jun 2007 17:41:48 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=GlMQOs/ZpG4BWihpDQYceptsVrTxgcaRilF2Rlun0guRK7W2WPOc2Q7sixOfKHIxraX3qQrfROyxTw7V2RYYjviTQiHwFwqsUoZa0DhVjo2V018Oi6Ip5vfhzLhpLnt/fOB7vPHQTp+kTq4hEHhvUh8dewgiOGEjWkz7InQ1A2k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=uhxLbuGJFSUCTBRvbOkxYPq1BcXAny41XJORF11mAwtABF/Ps8whFt0nn49cl6mml9UOUOGZh1R7QdWJ3hC3vJ8kmmsSRoVZeHH/91c5EovA9xpuD7O/nxpYpvrmkxi0M2O7cYP9saMNiTTBB46sslp9JmhtaLxL67N1PuiMbEo= Received: by 10.35.71.1 with SMTP id y1mr1914257pyk.1181176908060; Wed, 06 Jun 2007 17:41:48 -0700 (PDT) Received: by 10.35.81.19 with HTTP; Wed, 6 Jun 2007 17:41:48 -0700 (PDT) Message-ID: Date: Thu, 7 Jun 2007 08:41:48 +0800 From: "Howard Su" To: arch@freebsd.org In-Reply-To: MIME-Version: 1.0 References: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: alc@freebsd.org Subject: Re: help on lock around vm_page X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jun 2007 00:41:49 -0000 Some further reading give me a different message: The pages returned by vm_page_grab should have VPO_BUSY flag which will prevent anyone else to move this page to cache. So current approach should be ok. Am I right? Maybe there is some edge cases since I only meet this bug in a low memory situation. -- -Howard On 6/7/07, Howard Su wrote: > > I want some helps from VM guru. I try to fix a panic in tmpfs. In > order to push tmpfs into -Current, I really want some help to solve > this. > > 1. we allocate an object from vm_pager_alloc(OBJT_SWAP, ...) when create a > file. > 2. the panic is during handling write op: > a) find the first page we want to write > b) call vm_page_grab to get the page from object. > c) call use sf_buf_alloc to map it into kernel_map > d) use uiomove to move the data > e) mark page as dirty > f) loop to a until all pages are handled. > > there is a race condition. while doing b-c & e, we hold the > OBJ_LOCK/page_queue_lock. when doing d, we have to drop the locks to > call uiomove. When calling uio move, the page may moved to cache queue > since in that time it is not dirty. > > There is a solution that we allocate a page buffer. Before a), we > uiomove it to the buffer and replace uiomove with a bcopy in d). Then, > we can hold lock in b - e. I feel this will cause performance problem. > > For the detailed code, please check: > > http://perforce.freebsd.org/fileViewer.cgi?FSPC=//depot/user/howardsu/truss/sys/fs/tmpfs/tmpfs%5fvnops.c&REV=30 > > function: tmpfs_uio_xfer() > > Any idea to close this race condition? > > PS: If you can review my code about usage of vm, it will be appreciated. > > -- > -Howard >