From mboxrd@z Thu Jan 1 00:00:00 1970 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 ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F824606A32A for ; Mon, 16 Nov 2026 14:23:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=iodPkPgq; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ISN9/1AR DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1794838995; h=date : in-reply-to : mime-version : references : message-id : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=BYG49OVQ1jup5v00WB4N51Rp8LuOyNEvT7/t8eQQGV4=; b=iodPkPgqZ3COAMkXDmszYbVlf4Z732i+BRV28bJtxJbg75jDutk2Nqr87vLIm03xjeeTH HPIFSlfClOVbQ2EX8HJyFBWlinJvcJ/2vaG6BlGQ/SXmDq01bc5pfnQanPb2GE49JX0TSQf 8jJw8qJrno7pEi+ROQ9upGyeh9K785Y= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E6DD53EA0AE for ; Mon, 16 Nov 2026 15:23:15 +0100 (CET) Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 86AD03EA0AE for ; Mon, 16 Nov 2026 15:22:17 +0100 (CET) Received: from mail-pg1-x547.google.com (mail-pg1-x547.google.com [IPv6:2607:f8b0:4864:20::547]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 34976600801 for ; Mon, 16 Nov 2026 15:22:16 +0100 (CET) Received: by mail-pg1-x547.google.com with SMTP id 41be03b00d2f7-cddc4bde4b1so1227304a12.3 for ; Mon, 16 Nov 2026 06:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1794838934; x=1795443734; darn=lists.linux.it; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=KA641LrdmsHzwH9HaiV6SOUkyzgAxqgjuxE4K0UvaIU=; b=ISN9/1ARAO8k6oOgV89KaqCca1lhEe7/K5ZH/Ihnb1xEEhXipp6WBNPBJeYa0WpLlK qCLXgbChA+5Rwj4dYMu3/7oJr3HgHi1DeQqurRDhCzeO7yqBPaGfvjI20Ls0BFlMIvvZ +okaYR6WhBA2+t1BVNwpqw8BnDf3nY4I7nlwWkdjKzQLwgaXmfvvLZfM7TH/YyEFajrl uXRA5M3d6/tmCkkAjbY5/8UKqG47iMp5s4NMWLODdTGsi1qCktlf9a/WeBDRkoECLlns 8o8YwSO/MJwwDOyZDAD3X5Dd4ESd+G06zamZXL/uioT1ZrdzeAiJJRe0PFgWyxlcIoXJ a0wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794838934; x=1795443734; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KA641LrdmsHzwH9HaiV6SOUkyzgAxqgjuxE4K0UvaIU=; b=JwO7QYc+EVHap2LtmJIPNtGGSRfRD0zusGoE7e6nUEFOBTO9kefDKOFH4PU2YqN34F V85xPFzwf/+pqFMHnzLxb8AVEysrcSEirYHGINXEB4Z/fhwNQ/2sh6+6kE6Y2KyLnq1s d9/ru0gNYVLSCMCpbBeJg+zsCL6qgL/PcL6kytOOt0PovaVHGrEo56eGNctWE/O7bP8Y +YRdMIR1AIFvwVsrKhc/AxF7B1kn0wjfilz1leY5c0yBxKL3Ut0HPSQYnlQMTzZ7Gh7R 8pSuUJuftfqtPgc691dFPRh7B2i4VPUVNqsroxxH1ftQXVnuYwVHURv+l5akuLYglb39 dCzg== X-Gm-Message-State: APuU4Z/f2JxSkX1DRk0XpKae+9VQhIVKKiwupz5+7aKiKux1JOhZhtwu eiPh3eUsffsGy7ooqp4LmxFcx7sxI2LVBRY93gQ+wwOpnE6j7oUtPgPW4CJarTiaGoeJ/yR6wmg Cv3UD9CMG/0SmCyIFhlskmg3Ij5E3hYIJMJA7P7oz4wecv19cc+chsvSPGtFzHsXfFE49ureme0 qQBVviKRFAZBywjLRqlIN57pm3mA== X-Received: from pgqs26.prod.google.com ([2002:a65:691a:0:b0:cdb:91c5:5e0b]) (user=wakel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6372:a709:b0:3fa:bafe:61de with SMTP id adf61e73a8af0-3fabafe8c88mr3467001637.11.1794838934095; Mon, 16 Nov 2026 06:22:14 -0800 (PST) Date: Mon, 16 Nov 2026 14:22:04 +0000 In-Reply-To: <20261116142206.3151308-1-wakel@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261111093151.374731-1-wakel@google.com> <20261116142206.3151308-1-wakel@google.com> X-Mailer: git-send-email 2.56.0.611.g1030f0b940-goog Message-ID: <20261116142206.3151308-3-wakel@google.com> To: ltp@lists.linux.it X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Virus-Scanned: clamav-milter 1.0.9 at in-2.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v2 2/4] memcg, userfaultfd07: Populate whole pages instead of single bytes X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Archive: List-Post: List-Help: List-Subscribe: , From: Wake Liu via ltp Reply-To: Wake Liu Cc: kaleshsingh@google.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "ltp" memcontrol02 and mem_process, the helper of memcg_control_test.sh, fault in their memory by writing one byte per getpagesize() bytes, and userfaultfd07 populates the page cache of its memfd by writing a single byte. All of them assume that this populates whole pages of getpagesize() bytes. That is not the case when the kernel faults in and caches memory in smaller units than the page size it reports to userspace, as with the 16K page size emulation that Android uses on x86_64. Only one in four 4K pages gets populated there, so memcontrol02 sees only about a quarter of the expected 50M in memory.current, mem_process stays below the memory limit it is supposed to exceed, and UFFDIO_CONTINUE in userfaultfd07 fails for the part of the page that is not in the page cache: TBROK: ioctl(4,UFFDIO_CONTINUE,...) failed: EAGAIN/EWOULDBLOCK (11) Write the whole buffers instead. Nothing changes on kernels where both page sizes are equal. Signed-off-by: Wake Liu --- Notes: alloc_anon() in memcontrol_common.h, used by memcontrol03 and memcontrol04, writes one byte per page as well. It frees the buffer right away, so GCC and Clang would drop a plain memset() there as a dead store and it needs a different fix. I will look at it separately. .../kernel/controllers/memcg/control/mem_process.c | 11 ++++++----- testcases/kernel/controllers/memcg/memcontrol02.c | 13 +++++++------ .../kernel/syscalls/userfaultfd/userfaultfd07.c | 11 +++++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/testcases/kernel/controllers/memcg/control/mem_process.c b/testcases/kernel/controllers/memcg/control/mem_process.c index 8ecabb272..f32189cc2 100644 --- a/testcases/kernel/controllers/memcg/control/mem_process.c +++ b/testcases/kernel/controllers/memcg/control/mem_process.c @@ -10,6 +10,7 @@ #include #include #include +#include #include /* @@ -49,14 +50,14 @@ void process_options(int argc, char **argv) /* * touch_memory: force physical memory allocation + * + * Write the whole area rather than one byte per getpagesize(), so that it + * gets fully populated regardless of the granularity the kernel faults in + * memory with. */ void touch_memory(char *p) { - int i; - int pagesize = getpagesize(); - - for (i = 0; i < (int)memsize; i += pagesize) - p[i] = 0xef; + memset(p, 0xef, memsize); } void mem_map(void) diff --git a/testcases/kernel/controllers/memcg/memcontrol02.c b/testcases/kernel/controllers/memcg/memcontrol02.c index 52096f697..6687c6e84 100644 --- a/testcases/kernel/controllers/memcg/memcontrol02.c +++ b/testcases/kernel/controllers/memcg/memcontrol02.c @@ -27,7 +27,6 @@ #define _GNU_SOURCE #include "memcontrol_common.h" -static size_t page_size; static struct tst_cg_group *cg_child; static int fd = -1; static int file_to_all_error = 10; @@ -35,14 +34,18 @@ static int file_to_all_error = 10; static void alloc_anon_50M_check(void) { const ssize_t size = MB(50); - char *buf, *ptr; + char *buf; ssize_t anon, current; const char *const anon_key_fmt = TST_CG_VER_IS_V1(tst_cg, "memory") ? "rss %zd" : "anon %zd"; buf = SAFE_MALLOC(size); - for (ptr = buf; ptr < buf + size; ptr += page_size) - *ptr = 0; + /* + * Write the whole buffer rather than one byte per getpagesize(), so + * that it gets fully populated regardless of the granularity the + * kernel faults in memory with. + */ + memset(buf, 1, size); SAFE_CG_SCANF(cg_child, "memory.current", "%zd", ¤t); TST_EXP_EXPR(current >= size, @@ -113,8 +116,6 @@ static void test_memcg_current(unsigned int n) static void setup(void) { - page_size = SAFE_SYSCONF(_SC_PAGESIZE); - switch (tst_fs_type(TMPDIR)) { case TST_VFAT_MAGIC: case TST_EXFAT_MAGIC: diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd07.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd07.c index e0a1b0d23..dce6d8827 100644 --- a/testcases/kernel/syscalls/userfaultfd/userfaultfd07.c +++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd07.c @@ -32,7 +32,7 @@ static void setup(void) static void set_pages(void) { - char ch = 'A'; + char *buf; page_size = SAFE_SYSCONF(_SC_PAGE_SIZE); @@ -45,8 +45,15 @@ static void set_pages(void) /* * Populate page cache so that after MADV_DONTNEED the next access * can generate a MINOR fault rather than a MISSING fault. + * + * Write the whole page, as UFFDIO_CONTINUE needs the page cache to + * cover the whole range and the kernel may cache memory in units + * smaller than getpagesize(). */ - SAFE_PWRITE(1, memfd, &ch, 1, 0); + buf = SAFE_MALLOC(page_size); + memset(buf, 'A', page_size); + SAFE_PWRITE(1, memfd, buf, page_size, 0); + free(buf); page = SAFE_MMAP(NULL, page_size, PROT_READ, MAP_SHARED, memfd, 0); } -- 2.56.0.611.g1030f0b940-goog -- Mailing list info: https://lists.linux.it/listinfo/ltp