From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934116AbbI1O1V (ORCPT ); Mon, 28 Sep 2015 10:27:21 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:34983 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933973AbbI1O1P (ORCPT ); Mon, 28 Sep 2015 10:27:15 -0400 Message-ID: <1443450427.2531.2.camel@edumazet-glaptop2.roam.corp.google.com> Subject: Re: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for four elements From: Eric Dumazet To: David Laight Cc: "'Neil Horman'" , Denys Vlasenko , "David S. Miller" , Vlad Yasevich , Marcelo Ricardo Leitner , "linux-sctp@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Date: Mon, 28 Sep 2015 07:27:07 -0700 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1CBA41B0@AcuExch.aculab.com> References: <1443443644-12825-1-git-send-email-dvlasenk@redhat.com> <20150928135127.GB5248@hmsreliant.think-freely.org> <063D6719AE5E284EB5DD2968C1650D6D1CBA41B0@AcuExch.aculab.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2015-09-28 at 14:12 +0000, David Laight wrote: > From: Neil Horman > > Sent: 28 September 2015 14:51 > > On Mon, Sep 28, 2015 at 02:34:04PM +0200, Denys Vlasenko wrote: > > > Seemingly innocuous sctp_trans_state_to_prio_map[] array > > > is way bigger than it looks, since > > > "[SCTP_UNKNOWN] = 2" expands into "[0xffff] = 2" ! > > > > > > This patch replaces it with switch() statement. > > What about just adding 1 (and masking) before indexing the array? > That might require a static inline function with a local static array. > > Or define the array as (say) [16] and just mask the state before using > it as an index? Just let the compiler do its job, instead of obfuscating source. Compilers can transform a switch into an (optimal) table if it is really a gain.