From owner-svn-src-head@FreeBSD.ORG Thu Apr 2 14:23:01 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 045196CE; Thu, 2 Apr 2015 14:23:01 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E2EF9C40; Thu, 2 Apr 2015 14:23:00 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t32EN0KL098230; Thu, 2 Apr 2015 14:23:00 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t32EN0Qu098229; Thu, 2 Apr 2015 14:23:00 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201504021423.t32EN0Qu098229@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Thu, 2 Apr 2015 14:23:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r280989 - head/sys/netinet X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Apr 2015 14:23:01 -0000 Author: glebius Date: Thu Apr 2 14:22:59 2015 New Revision: 280989 URL: https://svnweb.freebsd.org/changeset/base/280989 Log: Provide a comment explaining issues with the counter(9) trick, so that people won't copy and paste it blindly. Prodded by: ian Sponsored by: Nginx, Inc. Modified: head/sys/netinet/ip_id.c Modified: head/sys/netinet/ip_id.c ============================================================================== --- head/sys/netinet/ip_id.c Thu Apr 2 13:51:06 2015 (r280988) +++ head/sys/netinet/ip_id.c Thu Apr 2 14:22:59 2015 (r280989) @@ -254,6 +254,20 @@ ip_fillid(struct ip *ip) ip->ip_id = ip_randomid(); else { counter_u64_add(V_ip_id, 1); + /* + * There are two issues about this trick, to be kept in mind. + * 1) We can migrate between counter_u64_add() and next + * line, and grab counter from other CPU, resulting in too + * quick ID reuse. This is tolerable in our particular case, + * since probability of such event is much lower then reuse + * of ID due to legitimate overflow, that at modern Internet + * speeds happens all the time. + * 2) We are relying on the fact that counter(9) is based on + * UMA_ZONE_PCPU uma(9) zone. We also take only last + * sixteen bits of a counter, so we don't care about the + * fact that machines with 32-bit word update their counters + * not atomically. + */ ip->ip_id = htons((*(uint64_t *)zpcpu_get(V_ip_id)) & 0xffff); } }