Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1240084imm; Fri, 12 Oct 2018 14:26:18 -0700 (PDT) X-Google-Smtp-Source: ACcGV61/XBlganJr24jxp8C4PMQYCLYibfgH3/i5DJN2WS4UMtkLYWjrSk5qk52meKUUtKKNHaxd X-Received: by 2002:a17:902:28a4:: with SMTP id f33-v6mr7433390plb.297.1539379578044; Fri, 12 Oct 2018 14:26:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539379578; cv=none; d=google.com; s=arc-20160816; b=YQENl8A6UHAXG0BH6+rRDlGHCQCmKHRnS1x5TRdop5jdo53b4Jclwoq81BVHv8GACA emQVP5+4UC+ZNT05NV5tIIM8mTnRi6HGQNH7kGWBgxr5/lHHnFn4nTLpKa7nvUKZTdGz a5S3tQzcm8Vv/+EQR3ITJDVRVDhRI33fAqnqOFO5M4/L3+u1gNVaQpgBs+GApTVqyLpD u6HRjWukDh8nBSN2hgMcb7CFJUOJcHON4JVTiSnzAO4xuRvgob3pMZH/jKXO/ta43nja SMDKwowwW5fuLDkMGd2yDlrhsMI8ek9D5Mdh8gPMaFponw0qsV2UIQvh+xTP/fJ6QNox l51Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature; bh=LF/YoHEd6r00UlYo875GaIQxjYz0VZX1XmCm0FXDGnY=; b=CH1eTpIlyHpQW/sv8wG58+cuLC5XrAbWqPOcKEL8dbAHUX4iIBXMgP5OP8c+YxlEtX f77X7eR0ezrya46sJRwWoDe2fOl63ubN5F4aBwIh+OXSfiMDemWA6GDd9zlwAZoqCW4C msevie9anDwgv4FVX7CjaQtt8mUq/aPlS8w2371zrrrs6tpPazDnTewCofNK44voGKMC q53+Wkl7qDJPoMgcP4wjkxSN14gfpwPHHTeNsppOXrFa0/4glZN0axZUVNwSGEtIRx9f 3FsNZ+eFWlLG4E3iAEg5tFUfysePJ/nmBlgFpsozHTAVTm8dNMcPtkbz4xLBduDnXbDa Y/Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CixZwotb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x10-v6si1522815pfm.136.2018.10.12.14.25.49; Fri, 12 Oct 2018 14:26:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CixZwotb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726030AbeJME7W (ORCPT + 99 others); Sat, 13 Oct 2018 00:59:22 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44440 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725785AbeJME7W (ORCPT ); Sat, 13 Oct 2018 00:59:22 -0400 Received: by mail-pl1-f193.google.com with SMTP id p25-v6so6472793pli.11 for ; Fri, 12 Oct 2018 14:24:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=LF/YoHEd6r00UlYo875GaIQxjYz0VZX1XmCm0FXDGnY=; b=CixZwotbFH8KgYAAQfsjqqPc8VX4nNMA3w3JlMX9LFnULIo2RvcC5Xa0rVBeVHRS7M THTu8xr5tkBslxN+iZkx/zAVU2oGvto3o4nw9bDs4jYrosdllNKh2yRNeIx2gR9SsGT6 DqEJtkPXG6FhZGx1WwlhqrLposZKAqyW3Cqu7CGcOufea11aJpb2bJ4tajgLYwZbFfhi fpz797F46bZshzvh8nTRYtlwTiZXdSNeR5YClakfoCwc1wbaDVrg8Fcjt4gbUuCxEIw1 JsdCHluRL6h1I9+i2KeTsfCkjth5tIl5tI85Ttgcos6r6hRrlx/Y4i06ub6uWPeUGOTz IUUw== 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:user-agent :mime-version; bh=LF/YoHEd6r00UlYo875GaIQxjYz0VZX1XmCm0FXDGnY=; b=GMwC1k5OPYAiHVb6njSpgZOTu3BjjLbmD8VZAgFAjNpB97VwQ+EEOx4KSjvCDOflYN Z/M3OHzdiTpGT/jT/YcdaOSiiv6jfUtuKvI4LLlvP84JNKVw8ygveiidBbcRAl0oR/uf 5zo/9e8oVUUjDY8E5Hirp5A/hubm38UyMzcN+6jzXx/xW+etliNAj8lmEozf75asKvTJ u/sZYa87k5W4MSgELyAUL8IrAwVjN0F92dbZqVJ4m5shBjPnNXgBcqIuRlywtyiQz6Pw eJTSDMJweOgiVPJfsfMplPPqRllRnQf6BgK/feG+AkU48OwQ4dcHHE6j7R13bh+0UBGO v9EA== X-Gm-Message-State: ABuFfohbtNyuLYef3O/Q2rC1UYhYkc6vA3yUwxaMBunn9fvCHg+XGQW/ dYX/pxwJLkezxNkyBsTtG4BUog== X-Received: by 2002:a17:902:74c2:: with SMTP id f2-v6mr7269417plt.45.1539379499023; Fri, 12 Oct 2018 14:24:59 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id g3-v6sm2981344pgn.37.2018.10.12.14.24.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 14:24:58 -0700 (PDT) Date: Fri, 12 Oct 2018 14:24:57 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Christoph Lameter , Pekka Enberg , Joonsoo Kim , Andrew Morton cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [patch] mm, slab: avoid high-order slab pages when it does not reduce waste Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The slab allocator has a heuristic that checks whether the internal fragmentation is satisfactory and, if not, increases cachep->gfporder to try to improve this. If the amount of waste is the same at higher cachep->gfporder values, there is no significant benefit to allocating higher order memory. There will be fewer calls to the page allocator, but each call will require zone->lock and finding the page of best fit from the per-zone free areas. Instead, it is better to allocate order-0 memory if possible so that pages can be returned from the per-cpu pagesets (pcp). There are two reasons to prefer this over allocating high order memory: - allocating from the pcp lists does not require a per-zone lock, and - this reduces stranding of MIGRATE_UNMOVABLE pageblocks on pcp lists that increases slab fragmentation across a zone. We are particularly interested in the second point to eliminate cases where all other pages on a pageblock are movable (or free) and fallback to pageblocks of other migratetypes from the per-zone free areas causes high-order slab memory to be allocated from them rather than from free MIGRATE_UNMOVABLE pages on the pcp. Signed-off-by: David Rientjes --- mm/slab.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/slab.c b/mm/slab.c --- a/mm/slab.c +++ b/mm/slab.c @@ -1748,6 +1748,7 @@ static size_t calculate_slab_order(struct kmem_cache *cachep, for (gfporder = 0; gfporder <= KMALLOC_MAX_ORDER; gfporder++) { unsigned int num; size_t remainder; + int order; num = cache_estimate(gfporder, size, flags, &remainder); if (!num) @@ -1803,6 +1804,20 @@ static size_t calculate_slab_order(struct kmem_cache *cachep, */ if (left_over * 8 <= (PAGE_SIZE << gfporder)) break; + + /* + * If a higher gfporder would not reduce internal fragmentation, + * no need to continue. The preference is to keep gfporder as + * small as possible so slab allocations can be served from + * MIGRATE_UNMOVABLE pcp lists to avoid stranding. + */ + for (order = gfporder + 1; order <= slab_max_order; order++) { + cache_estimate(order, size, flags, &remainder); + if (remainder < left_over) + break; + } + if (order > slab_max_order) + break; } return left_over; }