Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4438977pxb; Mon, 21 Feb 2022 21:39:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxDwxbh7piXqsnhLdWSzYYwo2Bw9m/iy7/bVjUTqeFBhMzXMfKJUQp8d1QRdDJYeALWAr/ X-Received: by 2002:a17:903:41d0:b0:14f:aa3b:45c6 with SMTP id u16-20020a17090341d000b0014faa3b45c6mr9727798ple.105.1645508344745; Mon, 21 Feb 2022 21:39:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645508344; cv=none; d=google.com; s=arc-20160816; b=Pos5y+MTHptgyjjfb2ZOAmUdf5buFgQNo2XkosS61caAkMA6HXD/4Zt55hPkXXvcpW om/vBT3aGeOFHmz3PGPT4SqhfoxBbVPniDbLExMKHMirUGJ2Yvt4hbwSqgus8eR8y7C4 Q0aIPcreAHgaLU4ft0ccqCkuHq8vyJ0ApP2hejLjtWVsww4Cvx/A3AbSEtP+DqMTVy+Z YlzL1a7LaK6RAuz7Rqg3o0PJ0IGALrcmOI+j/2MPExFYyBqmUFzBlf4HiZZZxkdMHJAq udIssrR1gNGHMrJkWs6w8GjiaSGxTt6c+85YYlkKGeU5AgeZI7er96YzVnAmYpWXMPUs i2nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ehNQdlI9mPXdldG87wHGJGXW6GsgTB2HkJJp4vDiMvs=; b=evOazrjPZT/5EENhcSd7vqxFyLbnhJGblwvq4X9cs7IzaN9uXi9b3TfJn9pUdKnhb+ m9GR9bjxiD+2yu72wV01zHkjiTlgp4pcU7KMqMGQ9BUeo5MF487Ad9bQCgkgE7A5dHCq sY2oo5NsDqcoFZtc5ylTeWvLqQpMmF3KZeAnX5Z+hZQXId8c09Vnqt7xhjLHY3LnCeVi e63o6w9lZBHz0U2QFmdvC2TwkU5EnljOcv6b0ccoXNovgNPOiC/bq74vOogXjrnGYJB+ H/TcbbtFF1MlTZ8CrtIatRQEgbNBxkECkWUwSCTzMRAEBxXFawrPp0oSJqHM9em2prai aSmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qlaVWsO4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d1si1089367pjx.81.2022.02.21.21.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:39:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qlaVWsO4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DEA88BE1D4; Mon, 21 Feb 2022 21:06:07 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355876AbiBULRX (ORCPT + 99 others); Mon, 21 Feb 2022 06:17:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355873AbiBULPU (ORCPT ); Mon, 21 Feb 2022 06:15:20 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1434CF6 for ; Mon, 21 Feb 2022 02:54:03 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id u5so12596509ple.3 for ; Mon, 21 Feb 2022 02:54:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ehNQdlI9mPXdldG87wHGJGXW6GsgTB2HkJJp4vDiMvs=; b=qlaVWsO4wSTU3J0DH2Hpj3dMsi97mWHbdhECMnS3joUeasrk2uCdT2Jsmn+qIr9fLe rViNtkASpFYzpkolR6zh0SSWu6KdwdyStVhbZtvJPmsetjJYkEodcgwRZToKocOqYzXp 2aONPUD1l/wjsooqbu2AT9/xm2Es0hJdg6t1ldwpTs1qoGcNK3P0NOimVfqpqulx8+jY A9E6Y7dM5wGAqY3f7dDQHAVGyZZ2KSNUulpKOWtTqp5ppCG94DDmaysD/n5TwvITPAj3 wRKyP8MX8+1pwmDbCM0zemfWRrbDL5678sUQC/T8/T70yB9PPlieHMoRTd3hFflEyvqy ROkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ehNQdlI9mPXdldG87wHGJGXW6GsgTB2HkJJp4vDiMvs=; b=uU/PIAqo8WRfgragZny2QrXCxc9VBdTFP4jCBEqpmsXq9CTvqZS5Ur9PPVnM5+DVED o3hFZWCju9BhoJ7SYa52GxKETkyV7mf/cn/LqYWsBSToEMWzaIlpYNgriXT86l/WT8v2 hdwcHrcHnmDqr2tsagB85o23MJObyNxArlu0+oN1SgrdCMgFi9C28U6QKoi0Tis2HNkG 3LoR0XFIL7Bm/o4nCC6nT+xpe2DlWOhMTRihlOT43OoiT5RdFhTI06aLlvetGYxYAxY5 6xMgXnBsNOv0/yD7PpHXBoCDnhlm6ATqGAbNM0ewx/oYjW2O1FPQw9PmtlLTNITblTWT 7cYw== X-Gm-Message-State: AOAM533Ej8GdTlNSPOP1BEX2C6ejwXJb7iGIQSppVCW8owx0rOYGLkL+ q419r2z+rCAoVmqy9cfgqLo= X-Received: by 2002:a17:902:b091:b0:14b:4b27:48d1 with SMTP id p17-20020a170902b09100b0014b4b2748d1mr18959339plr.52.1645440843472; Mon, 21 Feb 2022 02:54:03 -0800 (PST) Received: from ip-172-31-19-208.ap-northeast-1.compute.internal (ec2-18-181-137-102.ap-northeast-1.compute.amazonaws.com. [18.181.137.102]) by smtp.gmail.com with ESMTPSA id u6sm2214725pfk.203.2022.02.21.02.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 02:54:03 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: linux-mm@kvack.org Cc: Roman Gushchin , Andrew Morton , Vlastimil Babka , linux-kernel@vger.kernel.org, Joonsoo Kim , David Rientjes , Christoph Lameter , Pekka Enberg , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH 3/5] mm/slab: Do not call kmalloc_large() for unsupported size Date: Mon, 21 Feb 2022 10:53:34 +0000 Message-Id: <20220221105336.522086-4-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220221105336.522086-1-42.hyeyoo@gmail.com> References: <20220221105336.522086-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SLAB's kfree() does not support freeing an object that is allocated from kmalloc_large(). Fix this as SLAB do not pass requests larger than KMALLOC_MAX_CACHE_SIZE directly to page allocator. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- include/linux/slab.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 37bde99b74af..aeda3e863f2b 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -564,15 +564,19 @@ static __always_inline __alloc_size(1) void *kmalloc_large(size_t size, gfp_t fl * Try really hard to succeed the allocation but fail * eventually. */ +#ifndef CONFIG_SLOB static __always_inline __alloc_size(1) void *kmalloc(size_t size, gfp_t flags) { if (__builtin_constant_p(size)) { -#ifndef CONFIG_SLOB unsigned int index; -#endif - if (size > KMALLOC_MAX_CACHE_SIZE) - return kmalloc_large(size, flags); -#ifndef CONFIG_SLOB + + if (size > KMALLOC_MAX_CACHE_SIZE) { + if (IS_ENABLED(CONFIG_SLUB)) + return kmalloc_large(size, flags); + else + return NULL; + } + index = kmalloc_index(size); if (!index) @@ -581,10 +585,17 @@ static __always_inline __alloc_size(1) void *kmalloc(size_t size, gfp_t flags) return kmem_cache_alloc_trace( kmalloc_caches[kmalloc_type(flags)][index], flags, size); -#endif } return __kmalloc(size, flags); } +#else +static __always_inline __alloc_size(1) void *kmalloc(size_t size, gfp_t flags) +{ + if (__builtin_constant_p(size) && size > KMALLOC_MAX_CACHE_SIZE) + return kmalloc_large(size, flags); + return __kmalloc(size, flags); +} +#endif static __always_inline __alloc_size(1) void *kmalloc_node(size_t size, gfp_t flags, int node) { -- 2.33.1