From owner-freebsd-arch@FreeBSD.ORG Sun Jan 8 02:59:19 2012 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EA6021065673; Sun, 8 Jan 2012 02:59:18 +0000 (UTC) (envelope-from giovanni.trematerra@gmail.com) Received: from mail-qy0-f182.google.com (mail-qy0-f182.google.com [209.85.216.182]) by mx1.freebsd.org (Postfix) with ESMTP id 63FA68FC0A; Sun, 8 Jan 2012 02:59:18 +0000 (UTC) Received: by qcse13 with SMTP id e13so2109379qcs.13 for ; Sat, 07 Jan 2012 18:59:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=0aufyMnADM7W7OJQtv7bhYH/1mLoNq68Z3UV6wYxFOs=; b=e8/UC1S8TdXTly+vyrT5Bi2xJzCePLDz+V7XHzNqT8oQMYFzGotmEZElLIp9e7/8H4 s6sv7SilEXqdawPd8ipWlZHNo7Tt+Ir3XiTLTAdcIRFWd06sbrLWq/aVY+pnVGJCZYz/ ymLv6dgx78IspQlSd8qiluOlpOV84mrp6hIEs= MIME-Version: 1.0 Received: by 10.224.175.2 with SMTP id v2mr13794045qaz.69.1325990147263; Sat, 07 Jan 2012 18:35:47 -0800 (PST) Sender: giovanni.trematerra@gmail.com Received: by 10.229.185.82 with HTTP; Sat, 7 Jan 2012 18:35:47 -0800 (PST) Date: Sun, 8 Jan 2012 03:35:47 +0100 X-Google-Sender-Auth: hLMtQ6zc1bPNm7zwZ4zufg7lMSY Message-ID: From: Giovanni Trematerra To: freebsd-arch@freebsd.org, jilles@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Cc: Attilio Rao , flo@freebsd.org, Konstantin Belousov Subject: pipe/fifo code merged. 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: Sun, 08 Jan 2012 02:59:19 -0000 Hi, the patch at http://www.trematerra.net/patches/pipefifo_merge2.diff is a preliminary version of the FIFO optimizations project that I picked up from the wiki. http://wiki.freebsd.org/IdeasPage#FIFO_optimizations_.28GSoC.29 zhaoshuai@ produced the following patch in the 2009 which attempted a first merge of the interfaces: http://www.trematerra.net/patches/fifo_soc2009.diff However I felt like the work was not yet completed and come up with my final version. Now fifoes derive their structures from pipes one with just special handling to support VFS operations. All the operations but the creation/destruction for fifoes and pipes are handled by the same code. The heart of the patch is the new struct pipeinfo. pipeinfo is a per-file descriptor state. Basically it maintains a read end and a write end for the descriptor. As pipes are bidirectional in FreeBSD, for a pipe this two fields are always equal but different for a fifo. To let fifo code in sys/fs/fifofs/fifo_vnops.c create/destroy the pipe, two functions (pipe_ctor/pipe_dtor) were written. pipe_ctor setups things like a call to kern_pipe and return a pipeinfo structure, while pipe_dtor releases all the resources for a given pipeinfo. Once a pipe was setup during a fifo_open call, all the subsequent operations on the fifo are handled by the same code of a pipe expect for the clean up code that calls pipe_dtor. Allocation of two pipeinfo structures for a pipe were showed to slow down things by some micro-benchmarking. To speed up things during creation/destruction of pipes, the patch allocates all the needed data structure zone using the umapipe struct that packing together all the needed data structures to be allocated at pipe creation. A similar umafifo structure is used for fifoes. Thanks to jilles that made a review of the patch in a previous form, privately. Thanks a lot to attilio that answered my stupid questions and drove me in the right direction. TEST The patch passed all the test in tools/regression/pipe and tools/regression/fifo it passed a overnight of running stress test pho's suite and some buildworld/buildkernel of FreeBSD HEAD. PERFORMANCE the patch doesn't add any performance penalty at pipe code, the test was performed by compiling a GENERIC kernel. There's a lot of pipe code involving during a compilation. Such a test was used to discovery a performance regression in r226042. this is the ministat output http://www.trematerra.net/patches/pipeperf/pipeperf_result here the raw data http://www.trematerra.net/patches/pipeperf/pipeperf_rawresult The new fifo implementation gives to fifoes a boost of at least 15% in avarage. The test was send 1000 chunk of different size through a fifo. here the output of ministat output http://www.trematerra.net/patches/fifoperf/fifoperf_result here the raw results http://www.trematerra.net/patches/fifoperf/fifoperf_rawresult if someone would like to reproduce the test can download a copy of the sources a http://www.trematerra.net/patches/fifoperf/ the code is from zhaoshuai@. Makefile, builds benchmark.c benchmark.c set up a fifo, fork and send a number of messages of a size depending from the input parameters. runme.sh run the test launching benchmark binary to send different number of messages of different sizes. Test and review are welcomed. -- Gianni