From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D334BC00140 for ; Wed, 10 Aug 2022 09:03:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 313168E0005; Wed, 10 Aug 2022 05:03:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C3188E0001; Wed, 10 Aug 2022 05:03:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B1518E0005; Wed, 10 Aug 2022 05:03:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0D4B68E0001 for ; Wed, 10 Aug 2022 05:03:18 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AE6C840E26 for ; Wed, 10 Aug 2022 09:03:16 +0000 (UTC) X-FDA: 79783093992.06.07FE540 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 1522F100035 for ; Wed, 10 Aug 2022 09:03:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660122195; 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; bh=zDfT4OTVP3mlZybmyw3sBtbkZmpGAIdes/TJqqs05cY=; b=K41H2IPUCe719RNH+3PxUB4HiOEMzqAiee70EBMEGPSp+05paCus67bm6WKAsbeu5BpVQS wNVujc69GzXls0AaUIWivGtx5X9Nm+/StgrSCVgF9u/z3YcGHqRvDIXabKYN0pTIoxdqdM f+pb2iJqDG8dGHrVZifT+JOO55CEu9w= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-dMl8KWtQMAGhqWcRKmLC7Q-1; Wed, 10 Aug 2022 05:03:14 -0400 X-MC-Unique: dMl8KWtQMAGhqWcRKmLC7Q-1 Received: by mail-wm1-f69.google.com with SMTP id b16-20020a05600c4e1000b003a5a47762c3so1384220wmq.9 for ; Wed, 10 Aug 2022 02:03:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=zDfT4OTVP3mlZybmyw3sBtbkZmpGAIdes/TJqqs05cY=; b=IkNnUqzoDYZS/ErQu5YyGdK5+ERaQYhHLHPDJzF3UjzGcXuZTLXjTQC7cleY1d7r26 IdihgffSsBTNBhsmP1FqedtWrJ3XJiw9Wn9dsP3aJdodPgCaftUrihwDCUUGS0EKjJXn /p2OBe6nYZvJUnMuZ5v08q9CUXHnoTqTRbnaOf+avOe5dTHXT9mXU3NPvixKtIdwFevA 9IqsRkscEnidPaLvGSIgYzfRrh83B4mJZJKPtI+E8fhuQEkPP0M0A5rpNgvMHVFysRJB DmVqQFA7RF/eJ1Btn0VjZPdELUIliyNMbz5iZp7eNCGNsqJn9aU1CqM57DvxQfLFxamt VZoA== X-Gm-Message-State: ACgBeo16FPg1QljcVfm2inSIUyvhJ0Lq8RlxLqS/4ASS9gQfCmg8X8N5 2CsQJUjyjnWUr8+GEZZyP1uUDEZNdIVo6F0vdzfeHGIcKKLCfeQfYzHl1gLVfHdTOMUjBMJe9Ke yAGSmdzhLlJc= X-Received: by 2002:a5d:5a94:0:b0:221:6cec:2589 with SMTP id bp20-20020a5d5a94000000b002216cec2589mr15124091wrb.336.1660122193176; Wed, 10 Aug 2022 02:03:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR7B/fed6AkUKvETZNZzY2Aw/ljCBjLPi20tQHr8C2p9Bwqnl1tq+PpkGuYpyjcrSsB3Ep52mA== X-Received: by 2002:a5d:5a94:0:b0:221:6cec:2589 with SMTP id bp20-20020a5d5a94000000b002216cec2589mr15124042wrb.336.1660122192829; Wed, 10 Aug 2022 02:03:12 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:1600:a3ce:b459:ef57:7b93? (p200300cbc7071600a3ceb459ef577b93.dip0.t-ipconnect.de. [2003:cb:c707:1600:a3ce:b459:ef57:7b93]) by smtp.gmail.com with ESMTPSA id i9-20020a05600c050900b003a3187a2d4csm1655413wmc.22.2022.08.10.02.03.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Aug 2022 02:03:12 -0700 (PDT) Message-ID: <95ed1a81-ff8e-2c48-8838-4b3995af51b7@redhat.com> Date: Wed, 10 Aug 2022 11:03:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: Muhammad Usama Anjum , Jonathan Corbet , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , Arnd Bergmann , Andrew Morton , Peter Zijlstra , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Shuah Khan , "open list:DOCUMENTATION" , open list , "open list:PROC FILESYSTEM" , "open list:ABI/API" , "open list:GENERIC INCLUDE/ASM HEADER FILES" , "open list:MEMORY MANAGEMENT" , "open list:PERFORMANCE EVENTS SUBSYSTEM" , "open list:KERNEL SELFTEST FRAMEWORK" , krisman@collabora.com Cc: kernel@collabora.com References: <20220726161854.276359-1-usama.anjum@collabora.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 0/5] Add process_memwatch syscall In-Reply-To: <20220726161854.276359-1-usama.anjum@collabora.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660122196; a=rsa-sha256; cv=none; b=UfPVCwqg/Z4Bg3LZRgzxbWN8hKdzBQlvtGyTzcpftJG5JXPXo08ON2hoTBz8Cqa/M3vIs1 /dGfiB5CQEdi2c8GN6yMpMSkfRFjZ5DBSwdKMhv7qvBliOuH748ixgdwM76jdcVsv25lc8 0BBODUENyR06jpE4LnCxrEMLBL4Wnz8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K41H2IPU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660122196; h=from:from:sender: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:dkim-signature; bh=zDfT4OTVP3mlZybmyw3sBtbkZmpGAIdes/TJqqs05cY=; b=eoc8l47PF4F0N6ixxf5c80TCUYT7y26aPfkMmCuoLx7Z6gjSrsl5gk+dpQyyxgiEGDLPe9 f1zRTr5KycU7Ps8j6wDXX2XNYJ+bPPN6lQ1h1oxkhZQIlAg4Tci6/5YsGymnPCyvwOAD+u 4rVeaJ4eXfKe+JVKjxpiUW8vraG0qXc= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1522F100035 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K41H2IPU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Stat-Signature: bisp59gfahk6837wq5e8o1csq1suewqa X-HE-Tag: 1660122195-974284 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 26.07.22 18:18, Muhammad Usama Anjum wrote: > Hello, Hi, > > This patch series implements a new syscall, process_memwatch. Currently, > only the support to watch soft-dirty PTE bit is added. This syscall is > generic to watch the memory of the process. There is enough room to add > more operations like this to watch memory in the future. > > Soft-dirty PTE bit of the memory pages can be viewed by using pagemap > procfs file. The soft-dirty PTE bit for the memory in a process can be > cleared by writing to the clear_refs file. This series adds features that > weren't possible through the Proc FS interface. > - There is no atomic get soft-dirty PTE bit status and clear operation > possible. Such an interface might be easy to add, no? > - The soft-dirty PTE bit of only a part of memory cannot be cleared. Same. So I'm curious why we need a new syscall for that. > > Historically, soft-dirty PTE bit tracking has been used in the CRIU > project. The Proc FS interface is enough for that as I think the process > is frozen. We have the use case where we need to track the soft-dirty > PTE bit for running processes. We need this tracking and clear mechanism > of a region of memory while the process is running to emulate the > getWriteWatch() syscall of Windows. This syscall is used by games to keep > track of dirty pages and keep processing only the dirty pages. This > syscall can be used by the CRIU project and other applications which > require soft-dirty PTE bit information. > > As in the current kernel there is no way to clear a part of memory (instead > of clearing the Soft-Dirty bits for the entire processi) and get+clear > operation cannot be performed atomically, there are other methods to mimic > this information entirely in userspace with poor performance: > - The mprotect syscall and SIGSEGV handler for bookkeeping > - The userfaultfd syscall with the handler for bookkeeping You write "poor performance". Did you actually implement a prototype using userfaultfd-wp? Can you share numbers for comparison? Adding an new syscall just for handling a corner case feature (soft-dirty, which we all love, of course) needs good justification. > > long process_memwatch(int pidfd, unsigned long start, int len, > unsigned int flags, void *vec, int vec_len); > > This syscall can be used by the CRIU project and other applications which > require soft-dirty PTE bit information. The following operations are > supported in this syscall: > - Get the pages that are soft-dirty. > - Clear the pages which are soft-dirty. > - The optional flag to ignore the VM_SOFTDIRTY and only track per page > soft-dirty PTE bit Huh, why? VM_SOFTDIRTY is an internal implementation detail and should remain such. VM_SOFTDIRTY translates to "all pages in this VMA are soft-dirty". -- Thanks, David / dhildenb