Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1326820rdh; Fri, 24 Nov 2023 09:49:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtz4ajoOresSMHSO84CObjlVy0AC67O/4mXsr+aNrACOggqpFT+5GZ0SKXZfmqm999iA7P X-Received: by 2002:a17:902:db07:b0:1cc:2ef7:2abe with SMTP id m7-20020a170902db0700b001cc2ef72abemr3467874plx.48.1700848143277; Fri, 24 Nov 2023 09:49:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700848143; cv=none; d=google.com; s=arc-20160816; b=svb+DryxovvbVLulP1RwIMSTbHW97NNOmt1j+DJOf6xa/cTkQYF5exSOLOGs1EpUnS S2K2vHr6x3mVRo6FVUfm9AQhlllRZs7Uh+IEoJ8yEiYFJW4zzZZMP5omKEMi7Mi5biff TG9XVr1TOZHdgpLCHyFDKMbtiObtvKphiG8D3S20pmRd6X8kKWwBktKcjKQ8Y80uX/g5 lr7rEN0iJ7GU1ef67S9kalm16n3g1SNfzrf6Cxxyv2gxC39MQDhaxOpB4xlrNkpzGe+I lxzP+vZan33NU23l/n28HK0O3zs+LRRN5AKi34u46LTrLVSm2suz+1sEblWxz8atDrwT D/9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:autocrypt:from:references:cc:to:content-language :subject:user-agent:mime-version:date:message-id:dkim-signature; bh=GxUuGgqvBiwXQGtDlv7ryFP6iHTy8SVVoV36zP4gnMI=; fh=RmezdOjIlNmAYy7PZT+m3H9hNWRRTuqllr7I/aH9vlg=; b=gNg1kBOP0EhU6jVe2L11vSXmhzlsPGouEgMRDZEQ8MwHmhwXxgpApWQESnoCBf71so pT5EVd6kicua8cuyTsR5/CvXEYS8kQ8RpYTy+zgelebZgDujJUPNCOLl/aO8jbpobRtm MGOx3QVrLiXPmHSx8C4pELqpNVCbqCAizeeBnTBL19qJSBtkfjg1tvTxSgAkCwBD1YIH lu0B6sCv5iKbNcG+Vjaea1bDPfXkkQUkZqURVLncMLZqesUsC5rT/UDINX4+KPVXA+1X vSVES+qUHNKMQKjqhS0p3fTcao2CxEB1xDfp4+WQ+GLEbiaNFoK0NvwBKc0FLclH/QbW TIZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Al4pcUIy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id i13-20020a170902c94d00b001cf579f7584si4158288pla.376.2023.11.24.09.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 09:49:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Al4pcUIy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 1C2B5802D539; Fri, 24 Nov 2023 09:49:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231285AbjKXRsw (ORCPT + 99 others); Fri, 24 Nov 2023 12:48:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229741AbjKXRsu (ORCPT ); Fri, 24 Nov 2023 12:48:50 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93AE3171D for ; Fri, 24 Nov 2023 09:48:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700848135; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=GxUuGgqvBiwXQGtDlv7ryFP6iHTy8SVVoV36zP4gnMI=; b=Al4pcUIy/wg8bvSfdIerrlJbVfNYueaVjj4+H0j4zF/502fUa+L0Wc7J4yYVAYRt4fOgaW mH/pry2cunVkePN5uOYQwaS1S69TsGFVgMi0oBQQy48i5mkyquUmLjy07ZdWSkHcHJn0sq OuVk8JnT2xadhJQYDuJeHpQakCTZR0M= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-380-Uki9BwfaNoCeDgz0W3pJYg-1; Fri, 24 Nov 2023 12:48:54 -0500 X-MC-Unique: Uki9BwfaNoCeDgz0W3pJYg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-332e899b927so743036f8f.2 for ; Fri, 24 Nov 2023 09:48:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700848133; x=1701452933; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GxUuGgqvBiwXQGtDlv7ryFP6iHTy8SVVoV36zP4gnMI=; b=JRK9AOC/EZeuc22JTbh8DaEHJ6LCo1TUFhgDkEQUtf286kS2iKHReoc511u7ZZKpRZ P5kAVqPeQN98bG7Pw//6en1nf1i6IrzgX+QqwzoQamP0cZjQj3G/3WyzByD9M5tEs0Kv vEYPd1fwA5S+dajG4q+ffNba5N0/o8V29uSG3QHAdYMcKE1JGWdyxtIUnbGVrH66CRMr PT99/DKFaHZxE4LaiMbQ27pns2erEwpVyg3N1ksPONnsIo+zRxMOP0SkwHbk359t4J5S 20JX43QqlSoe7n+6uvQNbNIbAeBQ+pxYjpf/7fCvp5Ey9raTLT2jk7IkkxfMCR3Vu227 rRyA== X-Gm-Message-State: AOJu0YwK8ArNXKkuj9Iwi+1Lx/+PEZUkZcSG5zVXG+xN0Uz2awM/MBv2 9Jms+r9o0UaZZr4+lbTGEFMw+5RU0/7MqmKZ+/LF1+U5rnjslDADb1SrhBwne8MNB76y4giodrd PgoqCZgnf9DHA0cpmhz9KiZWu X-Received: by 2002:a05:600c:4fc5:b0:401:bd2e:49fc with SMTP id o5-20020a05600c4fc500b00401bd2e49fcmr2891460wmq.24.1700848133202; Fri, 24 Nov 2023 09:48:53 -0800 (PST) X-Received: by 2002:a05:600c:4fc5:b0:401:bd2e:49fc with SMTP id o5-20020a05600c4fc500b00401bd2e49fcmr2891445wmq.24.1700848132768; Fri, 24 Nov 2023 09:48:52 -0800 (PST) Received: from ?IPV6:2003:cb:c721:a000:7426:f6b4:82a3:c6ab? (p200300cbc721a0007426f6b482a3c6ab.dip0.t-ipconnect.de. [2003:cb:c721:a000:7426:f6b4:82a3:c6ab]) by smtp.gmail.com with ESMTPSA id j14-20020a05600c190e00b0040b3525428bsm5704150wmq.2.2023.11.24.09.48.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Nov 2023 09:48:52 -0800 (PST) Message-ID: Date: Fri, 24 Nov 2023 18:48:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RESEND PATCH v7 09/10] selftests/mm/cow: Generalize do_run_with_thp() helper Content-Language: en-US To: Ryan Roberts , Andrew Morton , Matthew Wilcox , Yin Fengwei , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , Kefeng Wang Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20231122162950.3854897-1-ryan.roberts@arm.com> <20231122162950.3854897-10-ryan.roberts@arm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCB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awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20231122162950.3854897-10-ryan.roberts@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 24 Nov 2023 09:49:02 -0800 (PST) On 22.11.23 17:29, Ryan Roberts wrote: > do_run_with_thp() prepares (PMD-sized) THP memory into different states > before running tests. With the introduction of small-sized THP, we would > like to reuse this logic to also test those smaller THP sizes. So let's > add a size parameter which tells the function what size THP it should > operate on. > > A separate commit will utilize this change to add new tests for > small-sized THP, where available. > > Signed-off-by: Ryan Roberts > --- > tools/testing/selftests/mm/cow.c | 146 +++++++++++++++++-------------- > 1 file changed, 79 insertions(+), 67 deletions(-) > > diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c > index 7324ce5363c0..d03c453cfd5c 100644 > --- a/tools/testing/selftests/mm/cow.c > +++ b/tools/testing/selftests/mm/cow.c > @@ -32,7 +32,7 @@ > > static size_t pagesize; > static int pagemap_fd; > -static size_t thpsize; > +static size_t pmdsize; > static int nr_hugetlbsizes; > static size_t hugetlbsizes[10]; > static int gup_fd; > @@ -734,14 +734,14 @@ enum thp_run { > THP_RUN_PARTIAL_SHARED, > }; > > -static void do_run_with_thp(test_fn fn, enum thp_run thp_run) > +static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t size) Nit: can we still call it "thpsize" in this function? That makes it clearer IMHO and avoids most renaming. > { > char *mem, *mmap_mem, *tmp, *mremap_mem = MAP_FAILED; > - size_t size, mmap_size, mremap_size; > + size_t mmap_size, mremap_size; > int ret; > > - /* For alignment purposes, we need twice the thp size. */ > - mmap_size = 2 * thpsize; > + /* For alignment purposes, we need twice the requested size. */ > + mmap_size = 2 * size; > mmap_mem = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, > MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); > if (mmap_mem == MAP_FAILED) { > @@ -749,36 +749,40 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run) > return; > } > > - /* We need a THP-aligned memory area. */ > - mem = (char *)(((uintptr_t)mmap_mem + thpsize) & ~(thpsize - 1)); > + /* We need to naturally align the memory area. */ > + mem = (char *)(((uintptr_t)mmap_mem + size) & ~(size - 1)); > > - ret = madvise(mem, thpsize, MADV_HUGEPAGE); > + ret = madvise(mem, size, MADV_HUGEPAGE); > if (ret) { > ksft_test_result_fail("MADV_HUGEPAGE failed\n"); > goto munmap; > } > > /* > - * Try to populate a THP. Touch the first sub-page and test if we get > - * another sub-page populated automatically. > + * Try to populate a THP. Touch the first sub-page and test if > + * we get the last sub-page populated automatically. > */ > mem[0] = 0; > - if (!pagemap_is_populated(pagemap_fd, mem + pagesize)) { > + if (!pagemap_is_populated(pagemap_fd, mem + size - pagesize)) { > ksft_test_result_skip("Did not get a THP populated\n"); > goto munmap; > } Yes! I have a patch lying around here that does that same. :) I guess there is no need to set MADV_NOHUGEPAGE on the remainder of the mmap'ed are: Assume we want a 64KiB thp. We mmap'ed 128KiB. If we get a reasonably aligned area, we might populate a 128KiB THP. But I assume the MADV_HUGEPAGE will in all configurations properly create a separate 64KiB VMA and we'll never get 128 KiB populated. So this should work reliably. > - memset(mem, 0, thpsize); > + memset(mem, 0, size); > > - size = thpsize; > switch (thp_run) { > case THP_RUN_PMD: > case THP_RUN_PMD_SWAPOUT: > + if (size != pmdsize) { > + ksft_test_result_fail("test bug: can't PMD-map size\n"); > + goto munmap; > + } Maybe rather "assert()" because that's a real BUG in the test? [...] > + pmdsize = read_pmd_pagesize(); > + if (pmdsize) > + ksft_print_msg("[INFO] detected PMD-mapped THP size: %zu KiB\n", Maybe simply: "detected PMD size". Zes, we read it via the THP interface, but that shouldn't matter much. -- Cheers, David / dhildenb