Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5850058rwd; Wed, 24 May 2023 07:34:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7k1UPMzh2DHd17hPJPP6/ZEuXlHz6YEb0d4gWfenFxYKknG45V0wejr+Qqs6gBIyy9F7rM X-Received: by 2002:a05:6a20:9f99:b0:103:946d:8a4c with SMTP id mm25-20020a056a209f9900b00103946d8a4cmr17880382pzb.5.1684938895969; Wed, 24 May 2023 07:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684938895; cv=none; d=google.com; s=arc-20160816; b=cWB47sVnGiuUfGMCdWGamBxsQBTqzMFlT5EkVHsvVUCYM+noPRf+GM4sTLilWzlCPB qFeW/71A/vO9FkdfFquDC+5x0I8cnSb0SsMGqyFQkyFebaXpFRsy6jbAsq6v7JrfRxQz oWEPcAYlwn9mNwka7iINMmTzbZAo429GxdljobIPG5Nh4v0qimiYqOBCslxOD9HJLa/L 0+yRicqvt+XmxJ1iiDXwdiLFv3N85i/70w2GMrbOAzcUEGCLuWaNG5GXK9bsb33GK0PX ft/q4brBiSzkGR4QUHNxEDWtoZPz38y98RdbbWBqsAfbtjxUZXrThcbb3xzz5Wbqp7eX UzBg== 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:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=/kJ2BoKi5i78Mh/y8Y03JIn+l1TFTW2WOH0z7fk8TZU=; b=lpLqoLkXwBlVhSZfuLCaIgoKc4r/N+ZHfG0MNbUIy+dZPG9YXWDtSHHIZtyAlB8RqG nd7UwHU1YPyoaGpYqy67L/WsoHexHUthTXs9/WC8iMHKvrM8uSxkwJMHy16n9rtpoRrT d4gxYjTKrXSBkaRGeuC/xgjmAqeLcvDRvhZNBtLm7PLP8CJG9OP8LBW00jdddfdbHE/5 kdVEqcQ7C3lgXO8jVMAWeBZJYw9WJh7Wckg8V/Nu1KQdjDFEn8Fmv3u3hCQOiHe2q01H Byfza4BxLUkxufHTwJ+5acxIkZ7Qzr76QepqdRPUqRqy8mcZWk+SK6Zur9gZEy5n6h6Z Cp5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=fIm4enJ3; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a17090a430600b0024dec043858si1459075pjg.74.2023.05.24.07.34.41; Wed, 24 May 2023 07:34:55 -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=@collabora.com header.s=mail header.b=fIm4enJ3; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235771AbjEXOQd (ORCPT + 99 others); Wed, 24 May 2023 10:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235635AbjEXOQa (ORCPT ); Wed, 24 May 2023 10:16:30 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F45212F; Wed, 24 May 2023 07:16:28 -0700 (PDT) Received: from [192.168.10.48] (unknown [119.155.11.156]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id AFC8E6605943; Wed, 24 May 2023 15:16:08 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684937786; bh=AuJTdSQvXF6YuhHcmscNAwhCf5setc7Hta7xDcqui0k=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=fIm4enJ3OeMwYz3UmiX6os2xp2qfzmCLKiUjTfJ4WEheyVlpslMtqmurhm5tWkKaE B5c862c9aeNgkl2gI4F0CHbOHo9bCwe0x1uvKAZ/Ysnlpi3cIWXeQ2Bz3HiLhkEeRM 9a8r0sAzu0TsuTVvBmJ4/eabCHK0KDuQFc/s+dr0jaSKCc0cjrKYJEahnBrOKm4PRi QLsTEsZBuLUD9wscuazomaYC3KRhTITFTzEJJ+rp00hx1mdxxV5Ijtx4xWfAaB52sm xDB1AKaJuABxKR46EqktjF1zovF2M9Zmgm1WFZ4OkXRpgzwW3Q6Qb/m0OIcDkaoDUD ByXuRdFihANXg== Message-ID: <8947d94d-8229-f8ee-e981-9b73462ecb94@collabora.com> Date: Wed, 24 May 2023 19:16:02 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Cc: Muhammad Usama Anjum , linux-mm@kvack.org, Paul Gofman , Alexander Viro , Shuah Khan , Christian Brauner , Yang Shi , Vlastimil Babka , "Liam R . Howlett" , Yun Zhou , Cyrill Gorcunov , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Andrew Morton , Suren Baghdasaryan , Andrei Vagin , Alex Sierra , Matthew Wilcox , Pasha Tatashin , Danylo Mocherniuk , Axel Rasmussen , "Gustavo A . R . Silva" , David Hildenbrand , Dan Williams , linux-kernel@vger.kernel.org, Mike Rapoport , linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, Greg KH , kernel@collabora.com, Nadav Amit Subject: Re: [PATCH RESEND v15 2/5] fs/proc/task_mmu: Implement IOCTL to get and optionally clear info about PTEs Content-Language: en-US To: Peter Xu References: <20230420060156.895881-1-usama.anjum@collabora.com> <20230420060156.895881-3-usama.anjum@collabora.com> <0edfaf12-66f2-86d3-df1c-f5dff10fb743@collabora.com> From: Muhammad Usama Anjum In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_SORBS_WEB, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 5/24/23 6:55 PM, Peter Xu wrote: ... >>> What is the steps of the test? Is it as simple as "writeprotect", >>> "unprotect", then write all pages in a single thread? >>> >>> Is UFFDIO_WRITEPROTECT sent in one range covering all pages? >>> >>> Maybe you can attach the test program here too. >> >> I'd not attached the test earlier as I thought that you wouldn't be >> interested in running the test. I've attached it now. The test has multiple > > Thanks. No plan to run it, just to make sure I understand why such a > difference. > >> threads where one thread tries to get status of flags and reset them, while >> other threads write to that memory. In main(), we call the pagemap_scan >> ioctl to get status of flags and reset the memory area as well. While in N >> threads, the memory is written. >> >> I usually run the test by following where memory area is of 100000 * pages: >> ./win2_linux 8 100000 1 1 0 >> >> I'm running tests on real hardware. The results are pretty consistent. I'm >> also testing only on x86_64. PM_SCAN_OP_WP wins every time as compared to >> UFFDIO_WRITEPROTECT. > > If it's multi-threaded test especially when the ioctl runs together with > the writers, then I'd assume it's caused by writers frequently need to > flush tlb (when writes during UFFDIO_WRITEPROTECT), the flush target could > potentially also include the core running the main thread who is also > trying to reprotect because they run on the same mm. > > This makes me think that your current test case probably is the worst case > of Nadav's patch 6ce64428d6 because (1) the UFFDIO_WRITEPROTECT covers a > super large range, and (2) there're a _lot_ of concurrent writers during > the ioctl, so all of them will need to trigger a tlb flush, and that tlb > flush will further slow down the ioctl sender. > > While I think that's the optimal case sometimes, of having minimum tlb > flush on the ioctl(UFFDIO_WRITEPROTECT), so maybe it makes sense somewhere > else where concurrent writers are not that much. I'll need to rethink a bit > on all these to find out whether we can have a good way for both.. > > For now, if your workload is mostly exactly like your test case, maybe you > can have your pagemap version of WP-only op there, making sure tlb flush is > within the pgtable lock critical section (so you should be safe even > without Nadav's patch). If so, I'd appreciate you can add some comment > somewhere about such difference of using pagemap WP-only and > ioctl(UFFDIO_WRITEPROTECT), though. In short, functional-wise they should > be the same, but trivial detail difference on performance as TBD (maybe one > day we can have a good approach for all and make them aligned again, but > maybe that also doesn't need to block your work). Thank you for understanding what I've been trying to convey. We are going to translate Windows syscall to this new ioctl. So it is very difficult to find out the exact use cases as application must be using this syscall in several different ways. There is one thing for sure is that we want to get best performance possible which we are getting by adding WP-only. I'll add it and send v16. I think that we are almost there. > -- BR, Muhammad Usama Anjum