Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp631549lqt; Thu, 6 Jun 2024 13:31:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXJxGlpdCODjQJaPUusGi+EeEgoX6TKpLyltUixSWF+X3YMtu5zeGy8KJNa6lHWOIlk4/jxW4kCxLrRnAkwM52/BG/UkATc8PGjOG66Rg== X-Google-Smtp-Source: AGHT+IGdCw0Xn+WsLVOmJVBRDPqMajIXG847kNqBgTbtFvxs8m+Z5VL7etHUncZ+ovPgUnBmohvC X-Received: by 2002:a17:902:e802:b0:1f3:f5c:cd80 with SMTP id d9443c01a7336-1f6d02d4655mr8503915ad.5.1717705873538; Thu, 06 Jun 2024 13:31:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717705873; cv=pass; d=google.com; s=arc-20160816; b=Pe5dGWaj+4bwxYOsa5NDAOVPlR1Xw6cMjHipsDDfNXYcQARkTewIA5kq3fJZVewPul bi+i4rhN5gise0XQjZ6VDVqY455qUEVpI2NklefR2uQgSnQst4Mg3uebSl/aHe5o6dGC EMGwFMvIlPIp5Zf7zBW8MCE1YZ0lBEq8Q1P0aNvbN4Bd07tBcfPrkslO9wZkou14iDvS HUJT2rniiIThjlOSs0cy1Z70GOLlMDgwfSoT7cnH4spoW206BWI7Sj7SAco+ESuH2M7n MwYJIINxa009DPUwI9cwrC+Sk8twhJg9Z4tJFEMTy5ZDEtlZMkJI9DZF3MYOjG1x7I72 0AzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=z5NfvXWO/90Z6j5OMVbYqZABK9/u9XXuehG4bdp4rXs=; fh=g1FobINBkkIYfmrg5BqBZ5ioUkvXQss/KRj85+fcWa4=; b=UIZVfDodx3FIxxr+wt8PeaSfLDHSpXcIZfch6SbYymVzTqmqkHNDvGA5P2PGPzqBvQ jWjWwZ5d9jnpQDhNlce331+jzj12Q1JQQToOrgfXijLAivAGgT88LvGV/JB74OrU27nQ agRz9TJDrm1eby0vJt78BcppHzSYwrRjuYRaAvyCIrGhBqJzbUzUeQOo20F2vLhj8Ajt G+Zrq/XVVFQTKiyCKSe4lP9MNW8z1I6H5Rt3FYF+CYLYCp1T8VmfwH3t46rfmSiapArK EaqoNQ+pux0TfEmpAhJi7VcU2j1QxzxNkDX0wNgKPJTqKrEvjdWsDc/b52iM/8Qm8qNM pndA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=fqhVzOEv; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-204984-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204984-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd75fc5asi16982285ad.12.2024.06.06.13.31.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 13:31:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204984-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=fqhVzOEv; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-204984-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204984-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2836828999B for ; Thu, 6 Jun 2024 20:31:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27CAA71B25; Thu, 6 Jun 2024 20:31:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="fqhVzOEv" Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5C153A8CB; Thu, 6 Jun 2024 20:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717705867; cv=none; b=jfdr91+8LSZOoFHWkrQ0oYUbBeXGGBrsRbxFUvwGVJQt1Pl10R1rdRH1/DhJlfnZAcu+ZN2yolQgtvNcUD4OTF+ft89MC+nNWmiobu1ub+7RNdvLJUxdfLBdAjgmPtmHCjLon9FtrcxSCvrM0W82ou5W4z8wdFOtMg128jTfzmI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717705867; c=relaxed/simple; bh=9zpNMMYi2kTeT92RNaA7BfoE8kpGt56jKFsjqH9YhIo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LYqBt1LPgItnHlBxplyfXV31d2fvNOBnrRYNCTA/dLNHXm6sIiRuoFDItPo8TwSOJTKpq5smBCnJ/59qzUpox3wXCKvvXvRfzXI6jZbi+Bub+6acXr54lVfrakFdA7HVUv44CvC11QKi/oYIpHmMNC1VE7GagIZPKQzbpkba3JI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com; spf=pass smtp.mailfrom=pankajraghav.com; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b=fqhVzOEv; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pankajraghav.com Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.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 mout-p-202.mailbox.org (Postfix) with ESMTPS id 4VwGDw5WZVz9sqx; Thu, 6 Jun 2024 22:30:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1717705856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=z5NfvXWO/90Z6j5OMVbYqZABK9/u9XXuehG4bdp4rXs=; b=fqhVzOEvhXg6LmCCHh9I/eetys9d2oOHuYWpTTsAoQ4IJJQS8UdnBNKsZmqKCc69NMo/rA ggLklI9puPXPNMrL1ANJ32kpmfQgjfSKxj2rqpFdb1rt66T5EzNycVT4W56jmxOlnEUDq5 VmdQ9iDftbPydPxcECIZm0j1/fuxG38gXny7MyUWEw/TO4SZED4ROgTQozTI6oliNLJUoA YmlgxoRM7y5B/GqNhsyPcRoyTH/sSJzg+3Xmdw68U8mDjVvh9JaJ+jM2+V+856/QRoIkyk AeIX4IPm7sohwbNLPb0ZimfcLWlHx9WOYHX7iTinwE5BZo5l+6gztH1/FSApJA== Date: Thu, 6 Jun 2024 20:30:53 +0000 From: "Pankaj Raghav (Samsung)" To: David Hildenbrand Cc: Shuah Khan , Andrew Morton , willy@infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, gost.dev@samsung.com, mcgrof@kernel.org, linux-kselftest@vger.kernel.org, Zi Yan , Pankaj Raghav Subject: Re: [PATCH] selftests/mm: use volatile keyword to not optimize mmap read variable Message-ID: <20240606203053.y5zxa54ndv53d3qj@quentin> References: <20240606135835.600022-1-kernel@pankajraghav.com> <5b4e7ef2-3ced-4d4a-989c-e99b06598d32@redhat.com> <20240606201831.ywmawi7xl6jgj3p4@quentin> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Jun 06, 2024 at 10:21:51PM +0200, David Hildenbrand wrote: > On 06.06.24 22:18, Pankaj Raghav (Samsung) wrote: > > On Thu, Jun 06, 2024 at 05:57:21PM +0200, David Hildenbrand wrote: > > > On 06.06.24 17:56, David Hildenbrand wrote: > > > > On 06.06.24 15:58, Pankaj Raghav (Samsung) wrote: > > > > > From: Pankaj Raghav > > > > > > > > > > create_pagecache_thp_and_fd() in split_huge_page_test.c used the > > > > > variable dummy to perform mmap read. > > > > > > > > > > However, this test was skipped even on XFS which has large folio > > > > > support. The issue was compiler (gcc 13.2.0) was optimizing out the > > > > > dummy variable, therefore, not creating huge page in the page cache. > > > > > > > > > > Add volatile keyword to force compiler not to optimize out the loop > > > > > where we read from the mmaped addr. > > > > > > > > > > Signed-off-by: Pankaj Raghav > > > > > --- > > > > > tools/testing/selftests/mm/split_huge_page_test.c | 2 +- > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c > > > > > index d3c7f5fb3e7b..c573a58f80ab 100644 > > > > > --- a/tools/testing/selftests/mm/split_huge_page_test.c > > > > > +++ b/tools/testing/selftests/mm/split_huge_page_test.c > > > > > @@ -300,7 +300,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd, > > > > > char **addr) > > > > > { > > > > > size_t i; > > > > > - int __attribute__((unused)) dummy = 0; > > > > > + volatile int __attribute__((unused)) dummy = 0; > > > > > srand(time(NULL)); > > > > > > > > > > base-commit: d97496ca23a2d4ee80b7302849404859d9058bcd > > > > > > > > The rick we do in some other tests is: > > > > > > > > char *tmp; > > > > > > > > tmp = *whatever; > > > > asm volatile("" : "+r" (tmp)); > > > > > > char tmp; of course. See cow.c as an example. > > Thanks David! I remember also seeing this when I grepped for volatile in > > the selftests directory. > > > > Willy gave the idea of making it as a global variable [1]. But your > > trick also works :) > > > > diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c > > index d3c7f5fb3e7b..9c957703c1f7 100644 > > --- a/tools/testing/selftests/mm/split_huge_page_test.c > > +++ b/tools/testing/selftests/mm/split_huge_page_test.c > > @@ -341,6 +341,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd, > > for (size_t i = 0; i < fd_size; i++) > > dummy += *(*addr + i); > > + asm volatile("" : "+r" (dummy)); > > if (!check_huge_file(*addr, fd_size / pmd_pagesize, pmd_pagesize)) { > > ksft_print_msg("No large pagecache folio generated, please provide a filesystem supporting large folio\n"); > > > > I am fine with either solutions. But using the trick asm volatile is more > > cleaner than making it a global variable IMO and makes it more uniform > > across the other mm tests. > > You can then even the "__attribute__((unused))", because the compile must > assume that it is used inside the asm statement. Yup! I will send a new version. Thanks David. > > -- > Cheers, > > David / dhildenb >