Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2710466rwo; Thu, 3 Aug 2023 13:46:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFDIOIGXUxVnnHgIEZ54pFCkJAQhLAjgCaWlPzXrHyK60x8vYwLDckRUbo67EyTpxapTkh X-Received: by 2002:a05:6a21:7788:b0:130:7803:5843 with SMTP id bd8-20020a056a21778800b0013078035843mr19164324pzc.4.1691095564783; Thu, 03 Aug 2023 13:46:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691095564; cv=none; d=google.com; s=arc-20160816; b=O/ezrF0O5yjFi6doIS7bJ75dG+yIfeCHtsqhstoLFzm3NkzXLGTjQhVER74FgAilsj l7Alst0j5jiwW28m1mpdYZxPe2KPFFgobDfmjIOm2gudEyWhx8d5AZh1JTdkm+Kzu4e3 Nd+VE3tEdk41NfGNKImXTFcFZUNp+haBQJaFYGdrH9KHDk5UzEYPNG7lMRFr+80Okr+a 743lHX5dFH4o8a4dzcLDxHoyipKhmb9f/dbInIQ/QPbh+IlBlO/QERtvKHs1K7PoWddw M6Yhec2hF/xylSKAXE7815ho6AGegn7VKr5Pm69liTKEv57xcjg8B5zllkJ63Wwd1SRY qPEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pPDr3fHEuj+B4yeJMYhNPLAGlxXe+c7xVHr2n9vPefY=; fh=18wL8z9Vztckz2a1HBSq3wbMKHbPpRJ7lDSUxdgce5s=; b=IjAk2afyvG0Dl6exuskWP/oadOjTTp50IG7L+oC06UOpKbUPAO4XdgPRN+1Vy+2zaW t0Vk3ohjC5hFX2D4ZQTisecXdRZ31Tg2mbv2uH5lY5sCEsn6/i2xGt86pVlIVC86Mjw/ DvSLiITwOYQTAFF3fWjVOEcAR9Ap6ls5Ygxj6vy1DxkfNwn7mErjVk5w4K3gUk0aq9cx j2cAY0uBbHNPD6FLksXJaTuM8dJfLEW3LvL2cq5O0Yn7PWHdqjpLp5nBDIv3lWrOFrla J30e/jdqrgP34VUB/mg85ke/MMAAzY8eQw+EIdoQeHyCXT/9hSXAUJ7QNEeEWXBLEc62 4NoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Njc0yKCN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h186-20020a6283c3000000b0066882062113si470563pfe.9.2023.08.03.13.45.50; Thu, 03 Aug 2023 13:46:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Njc0yKCN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbjHCTHD (ORCPT + 99 others); Thu, 3 Aug 2023 15:07:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjHCTGw (ORCPT ); Thu, 3 Aug 2023 15:06:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5529A3A98 for ; Thu, 3 Aug 2023 12:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691089526; 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=pPDr3fHEuj+B4yeJMYhNPLAGlxXe+c7xVHr2n9vPefY=; b=Njc0yKCNv2heVDtwEQfcY3iCaVrHfSU2IgaiZXCMFoTcRWHQ3uyY5Zi9BlU0gC5cG3I4DG GYx50I5+wOm8NUYGHO0fKXX7hOlbYUPX1+epxDNQB0+N0wLncFAfB7Q2Qz2E0rH/DGjnmH 0rFgsDbA/FcytF+uy2iecDSjBV8n4P4= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-h-th-gJvMi2lYI1TSOSdeA-1; Thu, 03 Aug 2023 15:05:24 -0400 X-MC-Unique: h-th-gJvMi2lYI1TSOSdeA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-76cb292df12so32374285a.0 for ; Thu, 03 Aug 2023 12:05:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691089524; x=1691694324; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pPDr3fHEuj+B4yeJMYhNPLAGlxXe+c7xVHr2n9vPefY=; b=RMdT/WI+dBzverncAuwk1Ed3mkkeSLka0mM23R3cdgu8z1F83KSPnEERq3Nd+x5DJd t2jHRIGFcHSrZ9i6SM3FaaA1+qHu88CxJatL4FVGQwQDwxn90e9vDTz/3+26ATtBfCy6 cdmfkQrHA8W3HpTof9m9jHD8Pu94ASGXGTYCu1LfmFoe4kT/NWzcuggRLNztgaatWnc9 kwZ1JMkRZkdKBfRwKu9Fxc193iRFXLau3xTFZRQC9xTVkOOpidnPtJ/yN4H0Cwxoq8bz 9Xgb/B7lQzWQv3amqHEXD78FvNxk7ayq7vongbmZu0+hIPUqrONYZ70L0i4KU5WkIfYx YUcQ== X-Gm-Message-State: ABy/qLYNamZb8I+W1cR/6C6O8rqdZNnhIhJoaSLVWPAodmNXRvbdxxlP mcSuHT0o4ZVugjGIQ5qB0PLMejS2leznvYk5FJBmpMVNSYnkbpUnVvlq3vLb8vDCXwEYA9aFJXg mbLB5TJ9jO9Xtrg+KCcodbbyK X-Received: by 2002:a05:622a:c1:b0:400:8036:6f05 with SMTP id p1-20020a05622a00c100b0040080366f05mr24001863qtw.2.1691089523797; Thu, 03 Aug 2023 12:05:23 -0700 (PDT) X-Received: by 2002:a05:622a:c1:b0:400:8036:6f05 with SMTP id p1-20020a05622a00c100b0040080366f05mr24001840qtw.2.1691089523525; Thu, 03 Aug 2023 12:05:23 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id m25-20020aed27d9000000b0040fe0fdf555sm135924qtg.22.2023.08.03.12.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 12:05:23 -0700 (PDT) Date: Thu, 3 Aug 2023 15:05:21 -0400 From: Peter Xu To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrew Morton , Linus Torvalds , liubo , Matthew Wilcox , Hugh Dickins , Jason Gunthorpe , John Hubbard , Mel Gorman , Shuah Khan , Paolo Bonzini Subject: Re: [PATCH v3 6/7] selftest/mm: ksm_functional_tests: test in mmap_and_merge_range() if anything got merged Message-ID: References: <20230803143208.383663-1-david@redhat.com> <20230803143208.383663-7-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230803143208.383663-7-david@redhat.com> 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_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Thu, Aug 03, 2023 at 04:32:07PM +0200, David Hildenbrand wrote: > Let's extend mmap_and_merge_range() to test if anything in the current > process was merged. range_maps_duplicates() is too unreliable for that > use case, so instead look at KSM stats. > > Trigger a complete unmerge first, to cleanup the stable tree and > stabilize accounting of merged pages. > > Note that we're using /proc/self/ksm_merging_pages instead of > /proc/self/ksm_stat, because that one is available in more existing > kernels. > > If /proc/self/ksm_merging_pages can't be opened, we can't perform any > checks and simply skip them. > > We have to special-case the shared zeropage for now. But the only user > -- test_unmerge_zero_pages() -- performs its own merge checks. > > Signed-off-by: David Hildenbrand Acked-by: Peter Xu One nitpick: > --- > .../selftests/mm/ksm_functional_tests.c | 47 +++++++++++++++++++ > 1 file changed, 47 insertions(+) > > diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c > index 0de9d33cd565..cb63b600cb4f 100644 > --- a/tools/testing/selftests/mm/ksm_functional_tests.c > +++ b/tools/testing/selftests/mm/ksm_functional_tests.c > @@ -30,6 +30,7 @@ > static int ksm_fd; > static int ksm_full_scans_fd; > static int proc_self_ksm_stat_fd; > +static int proc_self_ksm_merging_pages_fd; > static int ksm_use_zero_pages_fd; > static int pagemap_fd; > static size_t pagesize; > @@ -88,6 +89,22 @@ static long get_my_ksm_zero_pages(void) > return my_ksm_zero_pages; > } > > +static long get_my_merging_pages(void) > +{ > + char buf[10]; > + ssize_t ret; > + > + if (proc_self_ksm_merging_pages_fd < 0) > + return proc_self_ksm_merging_pages_fd; Better do the fds check all in main(), e.g. not all callers below considers negative values, so -1 can pass "if (get_my_merging_pages())" etc. > + > + ret = pread(proc_self_ksm_merging_pages_fd, buf, sizeof(buf) - 1, 0); > + if (ret <= 0) > + return -errno; > + buf[ret] = 0; > + > + return strtol(buf, NULL, 10); > +} -- Peter Xu