From patchwork Tue Aug 22 19:26:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 804635 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZjqouiVZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xcLCf4vKgz9t0F for ; Wed, 23 Aug 2017 05:26:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753048AbdHVT0v (ORCPT ); Tue, 22 Aug 2017 15:26:51 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35962 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752499AbdHVT0t (ORCPT ); Tue, 22 Aug 2017 15:26:49 -0400 Received: by mail-pg0-f67.google.com with SMTP id y129so28089471pgy.3 for ; Tue, 22 Aug 2017 12:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=b4zXce3MfcbruncjU6BRvcYT5eOX6nMwq6hVm17pNPU=; b=ZjqouiVZYHsc7OD3wO1lCCx05D4c7kD+01+G6oOEUnrso0ulIxUAh7PpQjGPSA95ku RGAleZIjPuDfekKS3ewzT/9iA6SmYpMXrfjsKO9F4f22It8xjeFHuEzMVGrMJ9jjUSHO A1GMOExgpzHreWkwc1S+eLuTHm9/Y/CzPSWcQti8hqDnlh0F+9f+yXSscO0V4FL/qLyo 3ivWTyT9INKBYJbWaFx8oWgU1qSvWuoEX5s11ckHlUHGQrZRrC4gwS7ThKul3oVkf2kj p6mjyC2l1j46b853UNTIUJazyxW0Zda975s95Si8MkGeLhdVLPfp8vmMNLWUH38VZJWz iK3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=b4zXce3MfcbruncjU6BRvcYT5eOX6nMwq6hVm17pNPU=; b=ejNGs3HMFtxs7VE8J7PKX6ZWQlPMOBwWxnLW8JexnwmeY+B3BEcEy2LtPR3RH7WK4F jpUS5jp4KYmtBSn6ayxHJAHvMAGZY1C5MbAGLnsUTFrc4voAvzGVujYO2/4iGA8LlnHj qXPV6AvwpANqBXEUQsvutzSt1F98hwk9E2oR3n/I5XM3TfS7z5ePK3EUvXnrtoSXQl2l DWHThBNCDCzf0F4z4b+/4qvGFvFOFNDdpx+8ODmk/l7MQJptWd1NtW6G9eHTefi6vZfI dp6hT8dN8VsBEPsI0cwj3YNbTP6oBcgCYcbRkzf4rp643KbU+AZYMO3AmRQd9Mvhj/C6 CWNA== X-Gm-Message-State: AHYfb5gU3w7s2Z6oReKGj0teHtykt/SKpmDpzT8g6OwV2R3NaXdg3xBv VjpB7Sp57agu8A== X-Received: by 10.84.224.199 with SMTP id k7mr274659pln.108.1503430008705; Tue, 22 Aug 2017 12:26:48 -0700 (PDT) Received: from ?IPv6:2620:15c:2c1:100:a0c1:d6e7:ce5:7c79? ([2620:15c:2c1:100:a0c1:d6e7:ce5:7c79]) by smtp.googlemail.com with ESMTPSA id s189sm1342991pgc.31.2017.08.22.12.26.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 12:26:47 -0700 (PDT) Message-ID: <1503430006.2499.55.camel@edumazet-glaptop3.roam.corp.google.com> Subject: [PATCH net-next] net: sched: use kvmalloc() for class hash tables From: Eric Dumazet To: David Miller Cc: netdev , Jamal Hadi Salim , Cong Wang , Jiri Pirko Date: Tue, 22 Aug 2017 12:26:46 -0700 X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet High order GFP_KERNEL allocations can stress the host badly. Use modern kvmalloc_array()/kvfree() instead of custom allocations. Signed-off-by: Eric Dumazet Acked-by: Alexei Starovoitov --- net/sched/sch_api.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 0fea0c50b7636b75b57ddf408c45ecce344813f4..aaf552b8e1205f29e0d95e943898bea35b647299 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -621,14 +621,10 @@ EXPORT_SYMBOL(qdisc_watchdog_cancel); static struct hlist_head *qdisc_class_hash_alloc(unsigned int n) { - unsigned int size = n * sizeof(struct hlist_head), i; struct hlist_head *h; + unsigned int i; - if (size <= PAGE_SIZE) - h = kmalloc(size, GFP_KERNEL); - else - h = (struct hlist_head *) - __get_free_pages(GFP_KERNEL, get_order(size)); + h = kvmalloc_array(n, sizeof(struct hlist_head), GFP_KERNEL); if (h != NULL) { for (i = 0; i < n; i++) @@ -637,16 +633,6 @@ static struct hlist_head *qdisc_class_hash_alloc(unsigned int n) return h; } -static void qdisc_class_hash_free(struct hlist_head *h, unsigned int n) -{ - unsigned int size = n * sizeof(struct hlist_head); - - if (size <= PAGE_SIZE) - kfree(h); - else - free_pages((unsigned long)h, get_order(size)); -} - void qdisc_class_hash_grow(struct Qdisc *sch, struct Qdisc_class_hash *clhash) { struct Qdisc_class_common *cl; @@ -679,7 +665,7 @@ void qdisc_class_hash_grow(struct Qdisc *sch, struct Qdisc_class_hash *clhash) clhash->hashmask = nmask; sch_tree_unlock(sch); - qdisc_class_hash_free(ohash, osize); + kvfree(ohash); } EXPORT_SYMBOL(qdisc_class_hash_grow); @@ -699,7 +685,7 @@ EXPORT_SYMBOL(qdisc_class_hash_init); void qdisc_class_hash_destroy(struct Qdisc_class_hash *clhash) { - qdisc_class_hash_free(clhash->hash, clhash->hashsize); + kvfree(clhash->hash); } EXPORT_SYMBOL(qdisc_class_hash_destroy);