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 DABC6C7EE22 for ; Thu, 11 May 2023 06:59:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 767DA6B0072; Thu, 11 May 2023 02:59:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 715766B0074; Thu, 11 May 2023 02:59:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DDC16B0075; Thu, 11 May 2023 02:59:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 49E726B0072 for ; Thu, 11 May 2023 02:59:28 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1CD27C0610 for ; Thu, 11 May 2023 06:59:28 +0000 (UTC) X-FDA: 80777073216.04.B841F64 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by imf08.hostedemail.com (Postfix) with ESMTP id B210B160018 for ; Thu, 11 May 2023 06:59:25 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ellerman.id.au header.s=201909 header.b=NJNN2mxn; spf=pass (imf08.hostedemail.com: domain of mpe@ellerman.id.au designates 150.107.74.76 as permitted sender) smtp.mailfrom=mpe@ellerman.id.au; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683788366; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9VphvYDUUTpJa6Y51rDbdnX2+VZhjxsrx/SPIlypOzg=; b=8pBgsDYDOHyTLAaGpVUqUPffsBjrmPZC3NUm3qKexlby2/v4wx8bIH5AfbZfy959trfD4V QQIhQw+NTkk+2nkQ5dCxv6uep/mo+W7cbWfUqiBP3C5mG6qXINl39ffpLq1a/LZcNQ2glX Pz5OIwTSPUgA1LUqqwveaO0oh4QCcJc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683788366; a=rsa-sha256; cv=none; b=ttmgj2wffrEGtF3MHPuM+F6+OsbGBS3Tgs7cGEYh7tD5YF1fK3HrdGd8qdLXSs11AJmmdt 6YTjS+QOTIPZ/jcUZtE/RPW6U+Vv5auVyH+N6W5MJ3wx2yBXDV0x3MonypDy196GQT45k+ aEqdnPqZJN6djg716W9Yg1nQpHc4Zvg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=ellerman.id.au header.s=201909 header.b=NJNN2mxn; spf=pass (imf08.hostedemail.com: domain of mpe@ellerman.id.au designates 150.107.74.76 as permitted sender) smtp.mailfrom=mpe@ellerman.id.au; dmarc=none Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4QGxy40qx8z4x2c; Thu, 11 May 2023 13:21:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1683775292; bh=9VphvYDUUTpJa6Y51rDbdnX2+VZhjxsrx/SPIlypOzg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=NJNN2mxnfu/5QYe7146XafzWTY72GFa0FBjWrl2NLrxKyugO0NAVfnvefKNqSd6pa yQzeAxhIemK5n1/e0B8WFeiOUkigosZGcXEkcK8l8kQ1qQNk/OQ+4+PdoZoVutNUq9 mFkl2ewnLvfRjTL9efoWJN5c14AkgYpUrfyPElVTvbpr1OCax+7l8CPQkZUET5fBE4 F488/tp145G5ISsXEhhYnOw7qJ/ZbGXVDqj45X75FmW0Ifq6CcdC0EH4JPwMlatPi1 COCqhjngty6kkF+aWLnfOykGPX2ig66VE9Wvld7fRyrnldUEGBEihtrS6EaG3QRXWi 7BQRutfI41uWQ== From: Michael Ellerman To: Nhat Pham , akpm@linux-foundation.org Cc: hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bfoster@redhat.com, willy@infradead.org, linux-api@vger.kernel.org, kernel-team@meta.com, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH v13 3/3] selftests: Add selftests for cachestat In-Reply-To: <20230503013608.2431726-4-nphamcs@gmail.com> References: <20230503013608.2431726-1-nphamcs@gmail.com> <20230503013608.2431726-4-nphamcs@gmail.com> Date: Thu, 11 May 2023 13:21:28 +1000 Message-ID: <877ctfa6yv.fsf@mail.lhotse> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: B210B160018 X-Stat-Signature: iyz7iy1j1sgiowoopu4briqtdm68exnz X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1683788365-769759 X-HE-Meta: U2FsdGVkX1/Cly9Gw0/FqA5qJ3r6u0YyPvNk4biVvCs9UQDWs2biMmNJPWB1Nf4ydf30Up5N+7hKMohAxtx2EdlFMoZVPKvtyw8SBrK1hxEqIbsOixT/ZloXhlhrdhPuJVSAqM9DGKY7blorUors/aTvlPdwijh40kCim3PGYKgzbLjSZqOBVbrF5L3a8MHLIC04SCsN6I8RjoznjjSHAysx6t7pNJ/JYUf+blKZVjyMAMBO4611pntzZTuCYIbPttC/FwhGcDME/EjHpXqE7lG4v14Q8lCFUroDWPvZd0/0Y/BB4YdkZuWBBMATQUk7svcyoNFjwyQ6q+sbkuBDdw1fg0T+5+69EdsIcgfgb1YAZDfSOh4CeoONm2zrvB7fJykqUVJMvym4tfU0ttPuEjfnQGHa1AKMpOF6cczuD4MqNZEnX1rg2i8dIk8i5Ctx9x1amgPwxyyKAvqEMVk2Px5TMNTrHrRwCNAcyeV9TXYwEQzRSMpP7FilAhDJDqlQO5qRcQUAjcVAYyQcRdlEbDOdX/nyK17g8yOArumMaYARjKXSKsfL5fl1aweST8Maof8W9Vpqh8+tCObJlsB7u2VVlzsYjtteoMBMm4sEEsJrAMX6oAQF82wwJCtOWMReVsC43o2SpCvf2mNcqFSZBZ4pQHZ2N0COUs8Dwqc7BR6JcyHGbNRJBeVLuK4SpTw/V2IyCR5rHA4PvtoWpZgKF+ZI61M0gbZa/PwikL4mMgr1r8ufC9sgLtZaRyw0tnxRrsAGyJLQC7sG2ujxMAidBQ4gopP9OjDNRqsbhNBXmdmi59uG2y5xd7mBmSFLeXOFOlIB7abbqUpKY+MiJbIb+C/SIhKBNtCKL4UH5ClGMYP/u9PxDd3xb3Fn3PolmlWe0g0a6fQ1kbLvX03ur3Jp5GbdAc6rN+qH0W/Xx4Py8US/r3GG3buQ4xHUaH9V4zQ66PFRQ+c+glCIWqV3uwC 4ds7AeFb EZOgC8e95RInEAWbVlGZTtaLnOXKn+lgNCUZ9WkUJxap1PRu2kr8DkeoOmX+aGrKu99u6xsstF2i1My6g1FxRiKEcL/FhyEOComVBJhkqkbXtt2Y= 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: Nhat Pham writes: > Test cachestat on a newly created file, /dev/ files, and /proc/ files. > Also test on a shmem file (which can also be tested with huge pages > since tmpfs supports huge pages). > > Signed-off-by: Nhat Pham ... > diff --git a/tools/testing/selftests/cachestat/test_cachestat.c b/tools/testing/selftests/cachestat/test_cachestat.c > new file mode 100644 > index 000000000000..c3823b809c25 > --- /dev/null > +++ b/tools/testing/selftests/cachestat/test_cachestat.c > @@ -0,0 +1,258 @@ > +// SPDX-License-Identifier: GPL-2.0 > +#define _GNU_SOURCE > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "../kselftest.h" > + > +static const char * const dev_files[] = { > + "/dev/zero", "/dev/null", "/dev/urandom", > + "/proc/version", "/proc" > +}; > +static const int cachestat_nr = 451; > + > +void print_cachestat(struct cachestat *cs) > +{ > + ksft_print_msg( > + "Using cachestat: Cached: %lu, Dirty: %lu, Writeback: %lu, Evicted: %lu, Recently Evicted: %lu\n", > + cs->nr_cache, cs->nr_dirty, cs->nr_writeback, > + cs->nr_evicted, cs->nr_recently_evicted); > +} > + > +bool write_exactly(int fd, size_t filesize) > +{ > + char data[filesize]; On kernels with 64K pages (powerpc at least), this tries to allocate 64MB on the stack which segfaults. Allocating data with malloc avoids the problem and allows the test to pass. Looks like this commit is still in mm-unstable, so maybe Andrew can squash the incremental diff below in, if it looks OK to you. The diff is a bit big because I unindented the body of the function. cheers diff --git a/tools/testing/selftests/cachestat/test_cachestat.c b/tools/testing/selftests/cachestat/test_cachestat.c index 9be2262e5c17..54d09b820ed4 100644 --- a/tools/testing/selftests/cachestat/test_cachestat.c +++ b/tools/testing/selftests/cachestat/test_cachestat.c @@ -31,48 +31,59 @@ void print_cachestat(struct cachestat *cs) bool write_exactly(int fd, size_t filesize) { - char data[filesize]; - bool ret = true; int random_fd = open("/dev/urandom", O_RDONLY); + char *cursor, *data; + int remained; + bool ret; if (random_fd < 0) { ksft_print_msg("Unable to access urandom.\n"); ret = false; goto out; - } else { - int remained = filesize; - char *cursor = data; + } - while (remained) { - ssize_t read_len = read(random_fd, cursor, remained); + data = malloc(filesize); + if (!data) { + ksft_print_msg("Unable to allocate data.\n"); + ret = false; + goto close_random_fd; + } - if (read_len <= 0) { - ksft_print_msg("Unable to read from urandom.\n"); - ret = false; - goto close_random_fd; - } + remained = filesize; + cursor = data; - remained -= read_len; - cursor += read_len; + while (remained) { + ssize_t read_len = read(random_fd, cursor, remained); + + if (read_len <= 0) { + ksft_print_msg("Unable to read from urandom.\n"); + ret = false; + goto out_free_data; } - /* write random data to fd */ - remained = filesize; - cursor = data; - while (remained) { - ssize_t write_len = write(fd, cursor, remained); + remained -= read_len; + cursor += read_len; + } - if (write_len <= 0) { - ksft_print_msg("Unable write random data to file.\n"); - ret = false; - goto close_random_fd; - } + /* write random data to fd */ + remained = filesize; + cursor = data; + while (remained) { + ssize_t write_len = write(fd, cursor, remained); - remained -= write_len; - cursor += write_len; + if (write_len <= 0) { + ksft_print_msg("Unable write random data to file.\n"); + ret = false; + goto out_free_data; } + + remained -= write_len; + cursor += write_len; } + ret = true; +out_free_data: + free(data); close_random_fd: close(random_fd); out: