Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2360577rwb; Thu, 27 Jul 2023 06:14:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlG5dE0pwF0Rq1FxeAL0Bt89NKYBiVFE6bd71GY/eRaBiA0U9xXUoPVw7GkdpraoxBK+Avlm X-Received: by 2002:ac2:4e81:0:b0:4fd:d002:ddad with SMTP id o1-20020ac24e81000000b004fdd002ddadmr1597770lfr.12.1690463658398; Thu, 27 Jul 2023 06:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690463658; cv=none; d=google.com; s=arc-20160816; b=fi6Xbm8JDwAOq5WqgloiFcnp6w1gk4CLkmpadgd8zdpGAtYuD+WlvcYXD+qPSCq3Oo HMqeJiVXBoqkB+ahR9EYoWh1ZQdjCMj70TanzXv7rOYX6ShlzO8wMq88XCjoWQlYvur8 q4BO+DgHVvQ+v49q56CA0nr/D2V34iwRx9JtKpLOVJe+RFY0Vkte5mCtJHsPiX/5hyag qqye6CJC2YtFqCipgsasI/7bJgTuwoXOHUFONM1btGyDsRMBhMCb2ZNIHVXArHlARSmf nRUXMYoaU/4VS/8cgihoLPNsXTHCumLeGYrsCSYZSrDN8IjVQy5esMo9usqoOrYO30Lm q06g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=SH5Ey1yx/8W+gaQNuiqylV1qlICOL1HJ7A2uan0PMYc=; fh=BUiWmF+JaD1DXMRXtfCtWXuuqLKlpuc8628xTWMKllk=; b=kz6PJEnEpc2EVXqugAx2OXAzv85lNAFzhV6AV/xcjJrvow6tKQLKgQcJHi5rORqiiU csmHUzdtn2Q3SWBJVsc9uV3nQeKaBWmmPe/FB5SaTodkaBWM1RaWKi7wyf4J+GjFr+1J oCjoWoRcd9TRrOCIws0zLSvct07dmxcf0+B1u/HVEvD720doSwu4A7KKWHhFtTLJFlzM g2+kdBrMthkZajq3QiKy/lE9o91jrnNNBvTHXeY3cspcaU6RpdioiZSnYMFGCxx+UjCn vO99wA59FsLMkYrEKINAgJDuLW5fe4VZbRbfCUwY4o1mqhhtNZc8nYncnk61bpY4dImD /cEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=i9T+QFaw; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v15-20020aa7dbcf000000b00522567926c8si883157edt.11.2023.07.27.06.13.52; Thu, 27 Jul 2023 06:14:18 -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=@google.com header.s=20221208 header.b=i9T+QFaw; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232947AbjG0LSj (ORCPT + 99 others); Thu, 27 Jul 2023 07:18:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232245AbjG0LSf (ORCPT ); Thu, 27 Jul 2023 07:18:35 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B87D4E61 for ; Thu, 27 Jul 2023 04:18:33 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbd33a1819so56215e9.1 for ; Thu, 27 Jul 2023 04:18:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690456712; x=1691061512; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SH5Ey1yx/8W+gaQNuiqylV1qlICOL1HJ7A2uan0PMYc=; b=i9T+QFawmfH9eqYrh3XFg91TUVPFLGrGsr7hAIR7iYpnWl5/P7iYfGWOSE6FDiDvrn 2ONOFL80+FD4M2wIcn38qAGOkyhpHs4YvoSa/xob+21UCVsGXcpMiWoEkG0vCZmrk/mm XlrbWFtNK9hydzzJvPHP2FPZKWkab9U2bw922rPeO4hG0XEkEpnEWyO4t+S8Qw7jrJ83 KvCn1fk30ZUxBKX3s1chc06AvfOfvn5UA9USV8LlryblfuGEk28s7MxN1KYXXRejP/ZN q5aAUfGxfN0f/JfluZdJItXXtttE8Jct1vH86IHmCHzETa4PfIxLL+EvMR2zl8xuP5DJ kTtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690456712; x=1691061512; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SH5Ey1yx/8W+gaQNuiqylV1qlICOL1HJ7A2uan0PMYc=; b=gerYx9yuZJDvgq87rRb7G6WSu9igBekwiqk5gSEtpFyrurusid4jTsVZBJHTZypUFL ib68NE+huag4XaTIzQ461h4VEgEvmifNr2FU5GAH1K+s2WnXyKWFBcqwwXWs6e4MvYCR b3oFg/ntQsO6VJhmLpUsk734wFBxUNzCKfe6D4iDPfqurmsuxlAx8XL7HjubeiOGUftV QI7dbkEG/pp1uOwi4n9rQWD5ZcW6qLZ8G7hZ6or8Snmu4FyaVLbv2KbBeTUW+ZpjCiC9 epPjQEUziUCM/zGgVzz4zpEzvXM8ktbuV24MulqEmlZ2TlSXv3Cn8C5C+zzb6eAz2CLw PxvQ== X-Gm-Message-State: ABy/qLZuV9pMwR2mdx+ZFnJC5wDe0izSYLCiBD0gGz2Ky5DLFabKcrnG DonvYa/T8hMUTac0BG6er/wEeudMUtPte73JH/7k+w== X-Received: by 2002:a05:600c:1c06:b0:3f1:73b8:b5fe with SMTP id j6-20020a05600c1c0600b003f173b8b5femr23389wms.3.1690456712044; Thu, 27 Jul 2023 04:18:32 -0700 (PDT) MIME-Version: 1.0 References: <20230713101415.108875-6-usama.anjum@collabora.com> <7eedf953-7cf6-c342-8fa8-b7626d69ab63@collabora.com> <382f4435-2088-08ce-20e9-bc1a15050861@collabora.com> <44eddc7d-fd68-1595-7e4f-e196abe37311@collabora.com> <1afedab8-5929-61e5-b0da-9c70dc01c254@collabora.com> <94c6b665-bbc2-5030-f9b1-d933791008b8@codeweavers.com> In-Reply-To: <94c6b665-bbc2-5030-f9b1-d933791008b8@codeweavers.com> From: =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Date: Thu, 27 Jul 2023 13:18:19 +0200 Message-ID: Subject: Re: [v3] fs/proc/task_mmu: Implement IOCTL for efficient page table scanning To: Paul Gofman Cc: Muhammad Usama Anjum , "Kirill A. Shutemov" , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Andrei Vagin , Danylo Mocherniuk , Alex Sierra , Alexander Viro , Andrew Morton , Axel Rasmussen , Christian Brauner , Cyrill Gorcunov , Dan Williams , David Hildenbrand , Greg KH , "Gustavo A . R . Silva" , "Liam R . Howlett" , Matthew Wilcox , Mike Rapoport , Nadav Amit , Pasha Tatashin , Peter Xu , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Yang Shi , Yun Zhou , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, kernel@collabora.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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, 27 Jul 2023 at 01:06, Paul Gofman wrote: > > Hello Micha=C5=82, > > I was looking into that from the Wine point of view and did a bit > of testing, so will try to answer the question cited below. Thanks for the extensive explanation! > Without Windows large pages I guess the only way to make this work > correctly is to disable THP with madvise(MADV_NOHUGEPAGE) on the memory > ranges allocated with MEM_WRITE_WATCH, as the memory changes should not > only be reported but also tracked with 4k page granularity as Windows > applications expect. > > Currently we don't implement MEM_LARGE_PAGES flag support in Wine > (while of course might want to do that in the future). On Windows using > this flag requires special permissions and implies more than just using > huge pages under the hood but also, in particular, locking pages in > memory. I'd expect that support to be extended in Windows though in the > future in some way. WRT write watches, the range is watched with large > page granularity. GetWriteWatch lpdwGranularity output parameter returns > the value of "large page minimum" (returned by GetLargePageMinimum) and > the returned addresses correspond to those large pages. I suppose to > implement that on top of Linux huge pages we'd need a way to control > huge pages allocation at the first place, i. e., a way to enforce the > specified size for the huge pages for the memory ranged being mapped. > Without that I am afraid the only way to correctly implement that is to > still disable THP on the range and only adjust our API output so that > matches expected. > > Not related to the question, but without any relation to Wine and > Windows API current way of dealing with THP in the API design looks a > bit not straightforward to me. In a sense that transparent huge pages > will appear not so transparent when it comes to dirty pages tracking. If > I understand correctly, the application which allocated a reasonably big > memory area and didn't use madvise(MADV_NOHUGEPAGE) might end up with a > whole range being a single page and getting dirtified as a whole, which > may likely void app's optimization based on changed memory tracking. Not > that I know an ideal way out of this, maybe it is a matter of having THP > disabled by default on watched ranges or clearly warning about this > caveat in documentation? So, this means that the max_pages limit should count HugeTLB pages as 1 not HPAGE_SIZE/PAGE_SIZE pages. Also, to get this right, we might need another PAGE_IS_HUGETLB category, so that userspace can differentiate the ranges if needed. Is it possible (on Windows) to have MEM_LARGE_PAGES allocation near a normal one and run GetWriteWatch() on both in one call? If so, how does it behave / what is expected? Best Regards Micha=C5=82 Miros=C5=82aw