From patchwork Mon Feb 7 14:16:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1589304 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=kyb5rXUi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jsp9W3MNyz9s8q for ; Tue, 8 Feb 2022 01:16:47 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2014C3C9B2B for ; Mon, 7 Feb 2022 15:16:45 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 9C7783C0720 for ; Mon, 7 Feb 2022 15:16:33 +0100 (CET) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 2B9E61A0014C for ; Mon, 7 Feb 2022 15:16:33 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id BE658210FE; Mon, 7 Feb 2022 14:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1644243392; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=me+7zoVKJp0HYLI4nnapXPAFKVGzKYBf/9XVFM15OaM=; b=kyb5rXUijkoQrvZLLxEPxKZIy0qeJqMBGFUs4jcjNuhYZU21ROmWw9ezuUIgVijDmTmquw pBDsFybEZybkmfm9Bj/FD8belCokAT2hq+g0henPfAyPlXfk3lo1GTKAPkzx77jvl3mgYG ygoXe6q3SaU+ovxaAQAwExDZxjAXkeo= Received: from g78.suse.de (unknown [10.163.24.138]) by relay2.suse.de (Postfix) with ESMTP id ECFA8A3B81; Mon, 7 Feb 2022 14:16:31 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 7 Feb 2022 14:16:14 +0000 Message-Id: <20220207141618.2844-2-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220207141618.2844-1-rpalethorpe@suse.com> References: <20220207141618.2844-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/5] memcontrol: Lift out some common definitions into a shared header X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Some simple functions can be shared between tests. The original selftests share a bit more. However this doesn't make as much sense in LTP due to library differences. Signed-off-by: Richard Palethorpe Reviewed-by: Cyril Hrubis Reviewed-by: Li Wang --- .../kernel/controllers/memcg/memcontrol02.c | 32 +------------ .../controllers/memcg/memcontrol_common.h | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 31 deletions(-) create mode 100644 testcases/kernel/controllers/memcg/memcontrol_common.h diff --git a/testcases/kernel/controllers/memcg/memcontrol02.c b/testcases/kernel/controllers/memcg/memcontrol02.c index 548f36829..d5a24cc0a 100644 --- a/testcases/kernel/controllers/memcg/memcontrol02.c +++ b/testcases/kernel/controllers/memcg/memcontrol02.c @@ -23,14 +23,7 @@ */ #define _GNU_SOURCE -#include -#include - -#include "tst_test.h" -#include "tst_cgroup.h" - -#define TMPDIR "mntdir" -#define MB(x) (x << 20) +#include "memcontrol_common.h" static size_t page_size; static const struct tst_cgroup_group *cg_test; @@ -38,20 +31,6 @@ static struct tst_cgroup_group *cg_child; static int fd; static int file_to_all_error = 10; -/* - * Checks if two given values differ by less than err% of their - * sum. An extra percent is added for every doubling of the page size - * to compensate for wastage in page sized allocations. - */ -static inline int values_close(const ssize_t a, - const ssize_t b, - const ssize_t err) -{ - const ssize_t page_adjusted_err = ffs(page_size >> 13) + err; - - return 100 * labs(a - b) <= (a + b) * page_adjusted_err; -} - static void alloc_anon_50M_check(void) { const ssize_t size = MB(50); @@ -78,15 +57,6 @@ static void alloc_anon_50M_check(void) current, anon); } -static void alloc_pagecache(const int fd, size_t size) -{ - char buf[BUFSIZ]; - size_t i; - - for (i = 0; i < size; i += sizeof(buf)) - SAFE_WRITE(1, fd, buf, sizeof(buf)); -} - static void alloc_pagecache_50M_check(void) { const size_t size = MB(50); diff --git a/testcases/kernel/controllers/memcg/memcontrol_common.h b/testcases/kernel/controllers/memcg/memcontrol_common.h new file mode 100644 index 000000000..67f3ca318 --- /dev/null +++ b/testcases/kernel/controllers/memcg/memcontrol_common.h @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#include "tst_test.h" +#include "tst_cgroup.h" + +#define TMPDIR "mntdir" +#define MB(x) (x << 20) + +/* + * Checks if two given values differ by less than err% of their + * sum. An extra percent is added for every doubling of the page size + * to compensate for wastage in page sized allocations. + */ +static inline int values_close(const ssize_t a, + const ssize_t b, + const ssize_t err) +{ + const size_t page_size = SAFE_SYSCONF(_SC_PAGESIZE); + const ssize_t page_adjusted_err = ffs(page_size >> 13) + err; + + return 100 * labs(a - b) <= (a + b) * page_adjusted_err; +} + +static inline void alloc_pagecache(const int fd, size_t size) +{ + char buf[BUFSIZ]; + size_t i; + + SAFE_LSEEK(fd, 0, SEEK_END); + + for (i = 0; i < size; i += sizeof(buf)) + SAFE_WRITE(1, fd, buf, sizeof(buf)); +} + +static inline void alloc_anon(const size_t size) +{ + const size_t page_size = SAFE_SYSCONF(_SC_PAGESIZE); + char *const buf = SAFE_MALLOC(size); + size_t i; + + for (i = 0; i < size; i += page_size) + buf[i] = 0; + + free(buf); +}