From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABF1FC433FE for ; Thu, 27 Jan 2022 13:22:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A1076B0072; Thu, 27 Jan 2022 08:22:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 250A96B0073; Thu, 27 Jan 2022 08:22:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13F596B0075; Thu, 27 Jan 2022 08:22:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0109.hostedemail.com [216.40.44.109]) by kanga.kvack.org (Postfix) with ESMTP id 06ADC6B0072 for ; Thu, 27 Jan 2022 08:22:38 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BADCD83C3C for ; Thu, 27 Jan 2022 13:22:37 +0000 (UTC) X-FDA: 79076131554.10.81EABC3 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by imf02.hostedemail.com (Postfix) with ESMTP id B8E8B80035 for ; Thu, 27 Jan 2022 13:22:35 +0000 (UTC) Received: by mail-lf1-f54.google.com with SMTP id n8so5320599lfq.4 for ; Thu, 27 Jan 2022 05:22:35 -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=FWO9YIEbl2WruOoU06oIsmAAcZW9kF52DRpY/EbaFsA=; b=O2Zbvkv9Qo3ikXFhJqnd1ezNZDO17wGjQRqAXzhVozz0qRI/n+bM+RFStWuqC51Fp3 L/QMuVP4sF4599qYyXAI53RB9inYqg0Eit18lqpeDQ/XuzWNSzOewA+MuX0SYhZkhdM2 UGSn+HQOxTEbon0NY/WcVG2d5HcB70yxD4K3NVW5AYHm7UJZWZ0UwJJTmRsou2i3o8GU ewBuMNLyXJ+MFCTPyWe9mIGmrXsDrzuR2n/JHlGKXyhourqIp1EcELodWwcMFmsqX8Rq ucnJZSB+aHqRHj1DzY/l89WnwdxnYtSjqcDYRLkNgGH9z198TbzKpH5I4m0MyckBlwu4 BC+Q== 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=FWO9YIEbl2WruOoU06oIsmAAcZW9kF52DRpY/EbaFsA=; b=N9Qj85fNYDSkQcYDnA4Q8Gae30TG5VGM0e8Z7wUUW/KA/Hmns30mrzAhPui1K9wPQv DFnMdURFGm9aY6bkgi0lqb7uMTU++5G5ERM+iZl4UrJiJU5HTbVVvDng4pP/8xcMSBDr wuxnH4Rx/oynGRy/dRaznyoo1blYJVuczFh3dbbUXtIZ3XGkzidbXqeYzcE0WRYu07uj TMphWe9AdDJxUeBDzVat3IGUY6165pfoGmvUh3Y7WH+mWwmShqVYcAHQ8bTQ9CJaN8Qi squUntcVRT21ol/olgNheUW5z3zIZwfAma0n9U/BJFEnlbdwtf611+GaaM1nQzZ5RoIm j1Cg== X-Gm-Message-State: AOAM532WX+O+7ZCiyXAcJIYHMuwk5YO0CP8jWp6bUsmFTFzvkxaVZKOg 5WXgd+4P98xo8ikXp4xDWV2LZal3kAM= X-Google-Smtp-Source: ABdhPJwMjP9wKO8E6h1MFu/ndgKiDvcZg5RIQP5a7Qt7P6fabYmuMKOssUiblVY1O2jqwDj+i8h5pA== X-Received: by 2002:a05:6512:228f:: with SMTP id f15mr2957438lfu.115.1643289754311; Thu, 27 Jan 2022 05:22:34 -0800 (PST) Received: from elysium.toya.net.pl (staticline-31-183-166-172.toya.net.pl. [31.183.166.172]) by smtp.gmail.com with ESMTPSA id s16sm1306918lfp.197.2022.01.27.05.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 05:22:33 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, mike.rapoport@gmail.com, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH 01/16] tools: Move gfp.h and slab.h from radix-tree to lib Date: Thu, 27 Jan 2022 14:21:19 +0100 Message-Id: <777d0cfcf531357cfe39d53987aa964a3a42ce8b.1643206612.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=O2Zbvkv9; spf=pass (imf02.hostedemail.com: domain of karolinadrobnik@gmail.com designates 209.85.167.54 as permitted sender) smtp.mailfrom=karolinadrobnik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: nil X-Rspamd-Queue-Id: B8E8B80035 X-Stat-Signature: bqkf47ektgoeiwjfq59zt84xe4uqh4qh X-Rspamd-Server: rspam12 X-HE-Tag: 1643289755-832709 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Merge radix-tree definitions from gfp.h and slab.h with these in tools/lib, so they can be used in other test suites. Fix style issues in slab.h. Update radix-tree test files. Signed-off-by: Karolina Drobnik --- tools/include/linux/gfp.h | 28 ++++++++++++++ .../radix-tree =3D> include}/linux/slab.h | 15 ++++---- tools/lib/slab.c | 38 +++++++++++++++++++ tools/testing/radix-tree/Makefile | 3 +- tools/testing/radix-tree/linux.c | 27 ------------- tools/testing/radix-tree/linux/gfp.h | 33 ---------------- 6 files changed, 76 insertions(+), 68 deletions(-) rename tools/{testing/radix-tree =3D> include}/linux/slab.h (68%) create mode 100644 tools/lib/slab.c delete mode 100644 tools/testing/radix-tree/linux/gfp.h diff --git a/tools/include/linux/gfp.h b/tools/include/linux/gfp.h index 22030756fbc0..4dce3cddd134 100644 --- a/tools/include/linux/gfp.h +++ b/tools/include/linux/gfp.h @@ -1,4 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _TOOLS_INCLUDE_LINUX_GFP_H #define _TOOLS_INCLUDE_LINUX_GFP_H =20 +#include + +#define __GFP_ZERO 0x8000u +#define __GFP_DIRECT_RECLAIM 0x400000u + +#define __GFP_BITS_SHIFT 26 +#define __GFP_BITS_MASK ((gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) + +#define __GFP_HIGH 0x20u +#define __GFP_IO 0x40u +#define __GFP_FS 0x80u +#define __GFP_NOWARN 0x200u +#define __GFP_ATOMIC 0x80000u +#define __GFP_ACCOUNT 0x100000u +#define __GFP_KSWAPD_RECLAIM 0x2000000u + +#define __GFP_RECLAIM (__GFP_DIRECT_RECLAIM | __GFP_KSWAPD_RECLAIM) +#define GFP_ZONEMASK 0x0fu +#define GFP_ATOMIC (__GFP_HIGH | __GFP_ATOMIC | __GFP_KSWAPD_RECLAIM) +#define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) +#define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM) + +static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) +{ + return !!(gfp_flags & __GFP_DIRECT_RECLAIM); +} + #endif /* _TOOLS_INCLUDE_LINUX_GFP_H */ diff --git a/tools/testing/radix-tree/linux/slab.h b/tools/include/linux/= slab.h similarity index 68% rename from tools/testing/radix-tree/linux/slab.h rename to tools/include/linux/slab.h index 2958830ce4d7..07d7930d4003 100644 --- a/tools/testing/radix-tree/linux/slab.h +++ b/tools/include/linux/slab.h @@ -1,20 +1,21 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#ifndef SLAB_H -#define SLAB_H +#ifndef _TOOLS_SLAB_H +#define _TOOLS_SLAB_H =20 #include #include =20 -#define SLAB_HWCACHE_ALIGN 1 #define SLAB_PANIC 2 #define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are r= eclaimable */ =20 -void *kmalloc(size_t size, gfp_t); -void kfree(void *); +#define kzalloc_node(size, flags, node) kmalloc(size, flags) + +void *kmalloc(size_t size, gfp_t gfp); +void kfree(void *p); =20 static inline void *kzalloc(size_t size, gfp_t gfp) { - return kmalloc(size, gfp | __GFP_ZERO); + return kmalloc(size, gfp | __GFP_ZERO); } =20 void *kmem_cache_alloc(struct kmem_cache *cachep, int flags); @@ -24,4 +25,4 @@ struct kmem_cache *kmem_cache_create(const char *name, = unsigned int size, unsigned int align, unsigned int flags, void (*ctor)(void *)); =20 -#endif /* SLAB_H */ +#endif /* _TOOLS_SLAB_H */ diff --git a/tools/lib/slab.c b/tools/lib/slab.c new file mode 100644 index 000000000000..959997fb0652 --- /dev/null +++ b/tools/lib/slab.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#include +#include +#include +#include + +int kmalloc_nr_allocated; +int kmalloc_verbose; + +void *kmalloc(size_t size, gfp_t gfp) +{ + void *ret; + + if (!(gfp & __GFP_DIRECT_RECLAIM)) + return NULL; + + ret =3D malloc(size); + uatomic_inc(&kmalloc_nr_allocated); + if (kmalloc_verbose) + printf("Allocating %p from malloc\n", ret); + if (gfp & __GFP_ZERO) + memset(ret, 0, size); + return ret; +} + +void kfree(void *p) +{ + if (!p) + return; + uatomic_dec(&kmalloc_nr_allocated); + if (kmalloc_verbose) + printf("Freeing %p to malloc\n", p); + free(p); +} diff --git a/tools/testing/radix-tree/Makefile b/tools/testing/radix-tree= /Makefile index aa6abfe0749c..c4ea4fbb0bfc 100644 --- a/tools/testing/radix-tree/Makefile +++ b/tools/testing/radix-tree/Makefile @@ -5,7 +5,8 @@ CFLAGS +=3D -I. -I../../include -g -Og -Wall -D_LGPL_SOUR= CE -fsanitize=3Daddress \ LDFLAGS +=3D -fsanitize=3Daddress -fsanitize=3Dundefined LDLIBS+=3D -lpthread -lurcu TARGETS =3D main idr-test multiorder xarray -CORE_OFILES :=3D xarray.o radix-tree.o idr.o linux.o test.o find_bit.o b= itmap.o +CORE_OFILES :=3D xarray.o radix-tree.o idr.o linux.o test.o find_bit.o b= itmap.o \ + slab.o OFILES =3D main.o $(CORE_OFILES) regression1.o regression2.o regression3= .o \ regression4.o tag_check.o multiorder.o idr-test.o iteration_check.o \ iteration_check_2.o benchmark.o diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/= linux.c index 2d9c59df60de..81539f543954 100644 --- a/tools/testing/radix-tree/linux.c +++ b/tools/testing/radix-tree/linux.c @@ -14,7 +14,6 @@ =20 int nr_allocated; int preempt_count; -int kmalloc_verbose; int test_verbose; =20 struct kmem_cache { @@ -78,32 +77,6 @@ void kmem_cache_free(struct kmem_cache *cachep, void *= objp) pthread_mutex_unlock(&cachep->lock); } =20 -void *kmalloc(size_t size, gfp_t gfp) -{ - void *ret; - - if (!(gfp & __GFP_DIRECT_RECLAIM)) - return NULL; - - ret =3D malloc(size); - uatomic_inc(&nr_allocated); - if (kmalloc_verbose) - printf("Allocating %p from malloc\n", ret); - if (gfp & __GFP_ZERO) - memset(ret, 0, size); - return ret; -} - -void kfree(void *p) -{ - if (!p) - return; - uatomic_dec(&nr_allocated); - if (kmalloc_verbose) - printf("Freeing %p to malloc\n", p); - free(p); -} - struct kmem_cache * kmem_cache_create(const char *name, unsigned int size, unsigned int alig= n, unsigned int flags, void (*ctor)(void *)) diff --git a/tools/testing/radix-tree/linux/gfp.h b/tools/testing/radix-t= ree/linux/gfp.h deleted file mode 100644 index 32159c08a52e..000000000000 --- a/tools/testing/radix-tree/linux/gfp.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _GFP_H -#define _GFP_H - -#include - -#define __GFP_BITS_SHIFT 26 -#define __GFP_BITS_MASK ((gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) - -#define __GFP_HIGH 0x20u -#define __GFP_IO 0x40u -#define __GFP_FS 0x80u -#define __GFP_NOWARN 0x200u -#define __GFP_ZERO 0x8000u -#define __GFP_ATOMIC 0x80000u -#define __GFP_ACCOUNT 0x100000u -#define __GFP_DIRECT_RECLAIM 0x400000u -#define __GFP_KSWAPD_RECLAIM 0x2000000u - -#define __GFP_RECLAIM (__GFP_DIRECT_RECLAIM|__GFP_KSWAPD_RECLAIM) - -#define GFP_ZONEMASK 0x0fu -#define GFP_ATOMIC (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM) -#define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) -#define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM) - - -static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) -{ - return !!(gfp_flags & __GFP_DIRECT_RECLAIM); -} - -#endif --=20 2.30.2