From owner-freebsd-current@FreeBSD.ORG Wed Jan 22 02:25:30 2014 Return-Path: Delivered-To: current@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 ESMTPS id 709A18AD for ; Wed, 22 Jan 2014 02:25:30 +0000 (UTC) Received: from mail-lb0-x234.google.com (mail-lb0-x234.google.com [IPv6:2a00:1450:4010:c04::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D86E711C0 for ; Wed, 22 Jan 2014 02:25:29 +0000 (UTC) Received: by mail-lb0-f180.google.com with SMTP id n15so6639610lbi.11 for ; Tue, 21 Jan 2014 18:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=hEiJo1Uw6tut8Xcx9mA8dd3O12DeXRWTc1AwJnszpBo=; b=XkSRDCnbvWONfjko/os401rvk6zpeqynJMWZFvL/mZTC9PDpKdLXNmxDSnzenPWVv5 kIAw8nMZI/ufY4JSrl+XXiKsLFZchsPXaYu+vQ+1OEW4e7X1AQLFN/Nx9yIBNpmfdNbb n4UGsiaddT9ru0lH95SXOi4M0DV7HG07ufv+GXCga7Yz2LWIq0M4xPOkFOayuAfBoZcf +Hui+f49GbAv1FbVRrh3Da8ZMpOvqx3/nlKd8IgiA5HZ/CWlO66STNh+k/Gjz7fFVXpJ TYccpjSiOVInoyx8KmlDCb9rtxDGoe19Q4RLVkpSF3V/QchdN6jqtAi5lYhx6pPDUkoC 6FoA== MIME-Version: 1.0 X-Received: by 10.112.132.102 with SMTP id ot6mr866867lbb.27.1390357527798; Tue, 21 Jan 2014 18:25:27 -0800 (PST) Sender: rizzo.unipi@gmail.com Received: by 10.115.4.162 with HTTP; Tue, 21 Jan 2014 18:25:27 -0800 (PST) Date: Tue, 21 Jan 2014 18:25:27 -0800 X-Google-Sender-Auth: 7UNAsOiO2obiisLJRRgfyKi48WQ Message-ID: Subject: possible selrecord optimization ? From: Luigi Rizzo To: FreeBSD Current Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.17 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jan 2014 02:25:30 -0000 Looking at how selrecord() / selwakeup() and their Linux counterparts poll_wait() and wake_up() are used, i noticed the following: - linux tends to call wake_up() unconditionally at the beginning of the poll handler - FreeBSD tends to call selrecord() only when it detects a blocking situation, and this also requires something (a lock or a retry; the lock in selinfo is not good for this) to avoid the race between the blocking_test..selrecord pair and the selwakeup(). FreeBSD could call selrecord unconditionally (and save the extra lock/retry), but selrecord is expensive as it queues the thread on the struct selinfo, and this takes a lock. I wonder if we could use the same optimization as Linux: as soon as pollscan/selscan detects a non-blocking fd, make selrecord a no-op (which is probably as simple as setting SELTD_RESCAN; and since it only goes up we do not need to lock to check it). This way, we would pay at most for one extra selrecord per poll/select. Even more interesting, it could simplify the logic and locking in poll handlers. As an example, in sys/uipc_socket.c :: sopoll_generic() we could completely decouple the locks on so_snd and so_rcv. comments ? Note that it is only an optimization, so we could write poll handlers in the selrecord-then-test style even without it. cheers luigi