From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756554AbZLUBX2 (ORCPT ); Sun, 20 Dec 2009 20:23:28 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756212AbZLUBXN (ORCPT ); Sun, 20 Dec 2009 20:23:13 -0500 Received: from one.firstfloor.org ([213.235.205.2]:58868 "EHLO one.firstfloor.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752095AbZLUBXH (ORCPT ); Sun, 20 Dec 2009 20:23:07 -0500 Date: Mon, 21 Dec 2009 02:23:05 +0100 From: Andi Kleen To: Linus Torvalds Cc: Andi Kleen , Andrew Morton , ebiederm@xmission.com, Linux Kernel Mailing List Subject: [PATCH] SYSCTL: Print binary sysctl warnings (nearly) only once Message-ID: <20091221012305.GB5143@basil.fritz.box> References: <20091219358.549678091@firstfloor.org> <20091219145832.A0424B158A@basil.firstfloor.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Dec 19, 2009 at 09:40:56AM -0800, Linus Torvalds wrote: > > > On Sat, 19 Dec 2009, Andi Kleen wrote: > > > > Turn all the bin_tables from const to non-const. This is needed for the next > > patch. Unfortunately there were a lot of them, so the patch is rather > > large, but it is completely mechanic. > > Ouch. I hate this. > > I'd much rather have a constant sysctl bin_table. > > If the _only_ thing you want to do is to do a "warn-on-once" logic, I > would seriously suggest you use a small hash-table instead of turning > bin_table non-const. I played around with this. The standard name hash couldn't be used because this is a string of ints, not chars. I ended up using FNV32 hash which seemed to do bests when hashing all the possible binary sysctls. Tested patch appended. -Andi --- SYSCTL: Print binary sysctl warnings (nearly) only once When printing legacy sysctls print the warning message for each of them only once. This way there is a guarantee the syslog won't be flooded for any sane program. The original attempt at this made the tables non const and stored the flag inline. Linus suggested using a separate hash table for this, this is based on a code snippet from him. The hash implies this is not exact and can sometimes not print a new sysctl due to a hash collision, but in practice this should not be a problem I used a FNV32 hash over the binary string with a 32byte bitmap. This gives relatively little collisions when all the predefined binary sysctls are hashed: size 256 bucket length number 0: [25] 1: [67] 2: [88] ak@linux.intel.com -- Speaking for myself only. 3: [47] 4: [22] 5: [6] 6: [1] The worst case is a single collision of 6 hash values. Signed-off-by: Andi Kleen --- kernel/sysctl_binary.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) Index: linux-2.6.33-rc1-ak/kernel/sysctl_binary.c =================================================================== --- linux-2.6.33-rc1-ak.orig/kernel/sysctl_binary.c +++ linux-2.6.33-rc1-ak/kernel/sysctl_binary.c @@ -1417,6 +1417,35 @@ static void deprecated_sysctl_warning(co return; } +#define WARN_ONCE_HASH_BITS 8 +#define WARN_ONCE_HASH_SIZE (1<