From patchwork Sun Mar 19 22:24:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 740761 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vmYY70S8Lz9s3l for ; Mon, 20 Mar 2017 09:24:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KD5qrwUt"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752264AbdCSWY4 (ORCPT ); Sun, 19 Mar 2017 18:24:56 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:36850 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752143AbdCSWYy (ORCPT ); Sun, 19 Mar 2017 18:24:54 -0400 Received: by mail-lf0-f66.google.com with SMTP id g70so8818027lfh.3 for ; Sun, 19 Mar 2017 15:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=l4mnq+NG0wtKgjia78zcSIlVtVDOAIIL8jW5H+OQwrg=; b=KD5qrwUtgRwCMjeoGRvBcS/52+/JVSs3NmQUZfA4w1WvaRtXKNCpJoNKCic2JCyA0F CoB+iyUDoUrBNIUkvRgZdAcR2vdu/aWhcpKz9SXm2BBF8uVrk74pypULyF1vd6qvNOtw EZlOJtbQ/xUmiqjgZKt6ZfNhoni6Exl+iK9Ab/m2r3Zf6EN6FSZPdQOogGXnQk6lF77b ISm70R7x1n5LHpEBtZEpNE1e5CjvY72YjmhtbaxoZ4mri5KrcXpKCwRlmu6i9oBBbWtM hRmgnFgdpuR7YRjDkGEECFzVxjhIpuD7s0tce3CcsGieP1oxmBTeYnepSL+RMWdLxKDF b+Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=l4mnq+NG0wtKgjia78zcSIlVtVDOAIIL8jW5H+OQwrg=; b=SLxZ10PAmHmdiSD8KDKIdFU9XKx8ztLceLodQwNyvxtDu9ilvf5r4Gbys/RVkKCb2w P2tvKPvYddWQSUP6Ynqd1hEBtpntRrA1+VYFx1OWUO5i0kZ58DmkfZKFgT/eLidAD++0 iFMQNkLh63G+JsgHUZJ2YPiixhZYFf6gJCjmwKv4VFG9XRDRY9w9LIojSe8vMwpTIkWB UwPBh16dfM6xaWLoZqGsIAA4+YPTfIjHxLk7tTGCyfj2Y8T2afziUI9jQ4TaOSmiYTGL rQmIzGb+9Z4kzlFhbu4Lg+uwnzj5mV7T8Mb6uUpKZay3831ghfj2VAOI/dr+LlQrpUQJ vZ9w== X-Gm-Message-State: AFeK/H3rCG8QiLwgr+8BKmz2ANord8pVybJ9OFdKXbkWvCgSf6U/GJEMi0JvmEUz33uBNw== X-Received: by 10.25.79.69 with SMTP id a5mr6848390lfk.58.1489962292591; Sun, 19 Mar 2017 15:24:52 -0700 (PDT) Received: from avx2 (nat6-minsk-pool-46-53-208-182.telecom.by. [46.53.208.182]) by smtp.gmail.com with ESMTPSA id y18sm2702150lja.7.2017.03.19.15.24.51 (version=TLS1_2 cipher=AES128-GCM-SHA256 bits=128/128); Sun, 19 Mar 2017 15:24:51 -0700 (PDT) Date: Mon, 20 Mar 2017 01:24:49 +0300 From: Alexey Dobriyan To: steffen.klassert@secunet.com Cc: herbert@gondor.apana.org.au, davem@davemloft.net, netdev@vger.kernel.org Subject: [PATCH 2/4] flowcache: make flow_cache_hash_size() return "unsigned int" Message-ID: <20170319222449.GB17015@avx2> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hash size can't negative so "unsigned int" is logically correct. Propagate "unsigned int" to loop counters. Space savings: add/remove: 0/0 grow/shrink: 2/2 up/down: 6/-18 (-12) function old new delta flow_cache_flush_tasklet 362 365 +3 __flow_cache_shrink 333 336 +3 flow_cache_cpu_up_prep 178 171 -7 flow_cache_lookup 1159 1148 -11 Total: Before=170822884, After=170822872, chg -0.00% Lookup becomes smaller and this is what matters. Signed-off-by: Alexey Dobriyan --- net/core/flow.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) --- a/net/core/flow.c +++ b/net/core/flow.c @@ -47,7 +47,7 @@ struct flow_flush_info { static struct kmem_cache *flow_cachep __read_mostly; -#define flow_cache_hash_size(cache) (1 << (cache)->hash_shift) +#define flow_cache_hash_size(cache) (1U << (cache)->hash_shift) #define FLOW_HASH_RND_PERIOD (10 * 60 * HZ) static void flow_cache_new_hashrnd(unsigned long arg) @@ -119,9 +119,10 @@ static void __flow_cache_shrink(struct flow_cache *fc, struct flow_cache_entry *fle; struct hlist_node *tmp; LIST_HEAD(gc_list); - int i, deleted = 0; + int deleted = 0; struct netns_xfrm *xfrm = container_of(fc, struct netns_xfrm, flow_cache_global); + unsigned int i; for (i = 0; i < flow_cache_hash_size(fc); i++) { int saved = 0; @@ -295,9 +296,10 @@ static void flow_cache_flush_tasklet(unsigned long data) struct flow_cache_entry *fle; struct hlist_node *tmp; LIST_HEAD(gc_list); - int i, deleted = 0; + int deleted = 0; struct netns_xfrm *xfrm = container_of(fc, struct netns_xfrm, flow_cache_global); + unsigned int i; fcp = this_cpu_ptr(fc->percpu); for (i = 0; i < flow_cache_hash_size(fc); i++) { @@ -327,7 +329,7 @@ static void flow_cache_flush_tasklet(unsigned long data) static int flow_cache_percpu_empty(struct flow_cache *fc, int cpu) { struct flow_cache_percpu *fcp; - int i; + unsigned int i; fcp = per_cpu_ptr(fc->percpu, cpu); for (i = 0; i < flow_cache_hash_size(fc); i++) @@ -402,12 +404,12 @@ void flow_cache_flush_deferred(struct net *net) static int flow_cache_cpu_prepare(struct flow_cache *fc, int cpu) { struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, cpu); - size_t sz = sizeof(struct hlist_head) * flow_cache_hash_size(fc); + unsigned int sz = sizeof(struct hlist_head) * flow_cache_hash_size(fc); if (!fcp->hash_table) { fcp->hash_table = kzalloc_node(sz, GFP_KERNEL, cpu_to_node(cpu)); if (!fcp->hash_table) { - pr_err("NET: failed to allocate flow cache sz %zu\n", sz); + pr_err("NET: failed to allocate flow cache sz %u\n", sz); return -ENOMEM; } fcp->hash_rnd_recalc = 1;