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 8B19DC43217 for ; Fri, 14 Oct 2022 13:48:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDACC6B0072; Fri, 14 Oct 2022 09:48:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8A5F6B0074; Fri, 14 Oct 2022 09:48:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D52AF6B0078; Fri, 14 Oct 2022 09:48:08 -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 B72326B0072 for ; Fri, 14 Oct 2022 09:48:08 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 892411A0144 for ; Fri, 14 Oct 2022 13:48:08 +0000 (UTC) X-FDA: 80019683856.14.D7272DD Received: from mail-lf1-f73.google.com (mail-lf1-f73.google.com [209.85.167.73]) by imf02.hostedemail.com (Postfix) with ESMTP id 7EDBE80032 for ; Fri, 14 Oct 2022 13:48:06 +0000 (UTC) Received: by mail-lf1-f73.google.com with SMTP id c1-20020a197601000000b004a2b252ee0dso1666078lff.14 for ; Fri, 14 Oct 2022 06:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=aiT4AGCUafLoWk2pbrHo53OIgKYTElZc1R+Afi5d73I=; b=cQ+NKquQ/ldSjGX4EJ8OLK4ogWivX0GdXKT4EZ8E/QdhOMBcueIkAC0xr6OxDaRDYM +tATfZPmv1h53MAXVlvW6sTBatupqhAGwCKXjDrLqSRkOQ3MDkNlFkPziiaKIABE5hmo tjv6ccHnxLp8jlI5dhPUSUtrsbwg0mOJjGS6h1CPeIEH9tTXylG8bSanvx7wRwYRJAba uQLNVdR+W6ZXLhNRiOha8/AcyGVywyyJoS+8d9MtYyY2/122/PCTOWirAsysu7eTofIE j4u49Anavdk7FmDseRf/UVUI2StrsJNSuH1Q2jcM3gj+Adr0/HGcz0LJ2cnkD1c0wcaA Q4vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=aiT4AGCUafLoWk2pbrHo53OIgKYTElZc1R+Afi5d73I=; b=pmvONK4wKmwxe7luFNCgiJlfL5JwCkB7qtVP7/oQ/yaHn1assgynu9mKQMFkKJvQNs kFh5xNptqiX+TtMoPNuqROrl6n68YIj7vpwgXoym1hIOkhOtHaT7GN0zjGPkINu0qEwb jPk62euqW1c6lUm0ulphoq/jwoufGUDVzHAPosg/EdiI4GkbkT9GI8VmQOzahrc2dpcX hJYpcAgOyL5QytjwyE5ury883g7EyqgHQV2w6Xb4RvHSLPh0kbo7wmr6Io7n1COQ/xLv LodaVBSx1btMYli84JLoSAzQmoHRY0PMtaTwhumvrWfI/0Ly+sxmhJM7pHC0TSvZQR9c 9acg== X-Gm-Message-State: ACrzQf2ilOcqMVUNWwKwooJcNAw/lsCeAxTNlEwu/V2GzkzIO4fQ2Te4 nnGvvpCHr47yBoRBkiwxLW3hDd4RcBFe X-Google-Smtp-Source: AMsMyM6fAAMwou9/zT1qtfIkwskBg+TuKICMRMPbatPuP2ZTJQELmBdb4OuYKL3cJ8Y/9OwlVd/w/gMEaLLo X-Received: from mdanylo.waw.corp.google.com ([2a00:79e0:9b:0:9507:b1bd:1910:a25d]) (user=mdanylo job=sendgmr) by 2002:a05:651c:4ca:b0:26c:50be:5df6 with SMTP id e10-20020a05651c04ca00b0026c50be5df6mr1791206lji.177.1665755284565; Fri, 14 Oct 2022 06:48:04 -0700 (PDT) Date: Fri, 14 Oct 2022 15:48:02 +0200 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog Message-ID: <20221014134802.1361436-1-mdanylo@google.com> Subject: Re: [PATCH v3 0/4] Implement IOCTL to get and clear soft dirty PTE From: Danylo Mocherniuk To: avagin@gmail.com Cc: akpm@linux-foundation.org, corbet@lwn.net, david@redhat.com, gregkh@linuxfoundation.org, kernel@collabora.com, krisman@collabora.com, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mdanylo@google.com, peter.enderborg@sony.com, shuah@kernel.org, surenb@google.com, usama.anjum@collabora.com, viro@zeniv.linux.org.uk, willy@infradead.org, emmir@google.com, figiel@google.com, kyurtsever@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665755286; a=rsa-sha256; cv=none; b=OArr7WXB0fYmAaQMlpTR62J+fal0G6+SMIP2nFEuHbfI/7fCpV93ASMK3/9TG1sdYRghPg gytrZ8isB8QJTUuJCMyEBCc+cY6MgfnnmhoBNErRVWdj/s74YsK3JiiS2/tZELPHPjyVVP eJdKvPw7Cyd4tA1Y0pB2BeHITm0XQEg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=cQ+NKquQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3lGhJYwcKCKsXOLYjWZRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--mdanylo.bounces.google.com designates 209.85.167.73 as permitted sender) smtp.mailfrom=3lGhJYwcKCKsXOLYjWZRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--mdanylo.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665755286; 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=aiT4AGCUafLoWk2pbrHo53OIgKYTElZc1R+Afi5d73I=; b=HnqUBbWF2+StDd+kVoS5kUu+gze8e53gQCWlUU5QyciX5ZeO7zRZYaWmFCgFz3wFzYodcf bWKcwHB+cWdAqkR33901IkcycUtQX6CVAgp8RseG2xDs4ecvZtRHgkPr3liZ3u79T9D973 F/WlSaESEttFJGX8DHwv/omQ9DuPtC8= X-Stat-Signature: 1qo3ikqje4xqtm3573p39jdn8onj8b5r X-Rspamd-Queue-Id: 7EDBE80032 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=cQ+NKquQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3lGhJYwcKCKsXOLYjWZRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--mdanylo.bounces.google.com designates 209.85.167.73 as permitted sender) smtp.mailfrom=3lGhJYwcKCKsXOLYjWZRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--mdanylo.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1665755286-452554 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 Tue, Oct 11, 2022 at 6:52 AM Andrei Vagin wrote: > > On Mon, Oct 03, 2022 at 04:21:22PM +0500, Muhammad Usama Anjum wrote: > > On 9/28/22 10:24 PM, Andrei Vagin wrote: > > > On Wed, Sep 21, 2022 at 11:26 AM Muhammad Usama Anjum > > > wrote: > > >> > > >> Hi, > > >> > > >> Thank you for reviewing. > > >> > > >> On 9/19/22 7:58 PM, Andrei Vagin wrote: > > >>>> This ioctl can be used by the CRIU project and other applications = which > > >>>> require soft-dirty PTE bit information. The following operations a= re > > >>>> supported in this ioctl: > > >>>> - Get the pages that are soft-dirty. > > >>> > > >>> I think this interface doesn't have to be limited by the soft-dirty > > >>> bits only. For example, CRIU needs to know whether file, present an= d swap bits > > >>> are set or not. > > >> These operations can be performed by pagemap procfs file. Definitely > > >> performing them through IOCTL will be faster. But I'm trying to add = a > > >> simple IOCTL by which some specific PTE bit can be read and cleared > > >> atomically. This IOCTL can be extended to include other bits like fi= le, > > >> present and swap bits by keeping the interface simple. The following > > >> mask advice is nice. But if we add that kind of masking, it'll start= to > > >> look like a filter on top of pagemap. My intention is to not duplica= te > > >> the functionality already provided by the pagemap. One may ask, then= why > > >> am I adding "get the soft-dirty pages" functionality? I'm adding it = to > > >> complement the get and clear operation. The "get" and "get and clear= " > > >> operations with special flag (PAGEMAP_SD_NO_REUSED_REGIONS) can give > > >> results quicker by not splitting the VMAs. > > > > > > This simple interface is good only for a limited number of use-cases. > > > The interface > > > that I suggest doesn't duplicate more code than this one, but it is m= uch more > > > universal. It will be a big mess if you add a separate API for each > > > specific use-case. > > > > > > > > >>> I mean we should be able to specify for what pages we need to get i= nfo > > >>> for. An ioctl argument can have these four fields: > > >>> * required bits (rmask & mask =3D=3D mask) - all bits from this mas= k have to be set. > > >>> * any of these bits (amask & mask !=3D 0) - any of these bits is se= t. > > >>> * exclude masks (emask & mask =3D=3D 0) =3D none of these bits are = set. > > >>> * return mask - bits that have to be reported to user. > > The required mask (rmask) makes sense to me. At the moment, I only know > > about the practical use case for the required mask. Can you share how > > can any and exclude masks help for the CRIU? > > > > I looked at should_dump_page in the CRIU code: > https://github.com/checkpoint-restore/criu/blob/45641ab26d7bb78706a6215fd= ef8f9133abf8d10/criu/mem.c#L102 > > When CRIU dumps file private mappings, it needs to get pages that have > PME_PRESENT or PME_SWAP but don't have PME_FILE. I would really like to see the mask discussed will be adopted. With it CRIU= will be able to migrate huge sparse VMAs assuming that a single hole is processe= d in=20 O(1) time.=20 Use cases for migrating sparse VMAs are binaries sanitized with ASAN, MSAN = or TSAN [1]. All of these sanitizers produce sparse mappings of shadow memory = [2]. Being able to migrate such binaries allows to highly reduce the amount of w= ork needed to identify and fix post-migration crashes, which happen constantly. > > > >>>> - Clear the pages which are soft-dirty. > > >>>> - The optional flag to ignore the VM_SOFTDIRTY and only track per = page > > >>>> soft-dirty PTE bit > > >>>> > > >>>> There are two decisions which have been taken about how to get the= output > > >>>> from the syscall. > > >>>> - Return offsets of the pages from the start in the vec > > >>> > > >>> We can conside to return regions that contains pages with the same = set > > >>> of bits. > > >>> > > >>> struct page_region { > > >>> =C2=A0 =C2=A0 =C2=A0 void *start; > > >>> =C2=A0 =C2=A0 =C2=A0 long size; > > >>> =C2=A0 =C2=A0 =C2=A0 u64 bitmap; > > >>> } > > >>> > > >>> And ioctl returns arrays of page_region-s. I believe it will be mor= e > > >>> compact form for many cases. > > >> Thank you for mentioning this. I'd considered this while development= . > > >> But I gave up and used the simple array to return the offsets of the > > >> pages as in the problem I'm trying to solve, the dirty pages may be > > >> present amid non-dirty pages. The range may not be useful in that ca= se. > > > > > > This is a good example. If we expect more than two consequent pages > > > on average, the "region" interface looks more prefered. I don't know = your > > > use-case, but in the case of CRIU, this assumption looks reasonable. Plus one for page_region data structure. It will make ASAN shadow memory representation much more compact as well as any other classical use-case.= =20 [1] https://github.com/google/sanitizers=09 [2] https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm#64-= bit=09 Best, Danylo