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 5947DC00140 for ; Mon, 15 Aug 2022 04:06:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D4FA8D0002; Mon, 15 Aug 2022 00:06:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95DBE6B0074; Mon, 15 Aug 2022 00:06:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D8348D0002; Mon, 15 Aug 2022 00:06:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6845C6B0073 for ; Mon, 15 Aug 2022 00:06:31 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 11223140CB8 for ; Mon, 15 Aug 2022 04:06:31 +0000 (UTC) X-FDA: 79800490182.25.0786A44 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 88C581401B7 for ; Mon, 15 Aug 2022 04:06:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660536390; 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=g/Qyy/TUtlP5wQvlalN7RTOTbhmCvMUhu++naFHk9Mk=; b=LoeSVcveva0DNNKD9Bb5eXUKq11gyOIhHs9TPUBv5X7F6cmhseM0C3g1bzOPY9J5oZJhik zjyJuDfIIBEEftklhaJgVqia+hbfTWU0VVbTxIl9BLaly53Sod3AwdqCs6cQFxhkGCDJqZ FIvrLBlAW1I+uC8Q8po8wW/nvO80fI0= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-55-fXmETw1EOlWfo7pLDH40Zw-1; Mon, 15 Aug 2022 00:06:28 -0400 X-MC-Unique: fXmETw1EOlWfo7pLDH40Zw-1 Received: by mail-lf1-f70.google.com with SMTP id p36-20020a05651213a400b004779d806c13so1014879lfa.10 for ; Sun, 14 Aug 2022 21:06:28 -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:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=g/Qyy/TUtlP5wQvlalN7RTOTbhmCvMUhu++naFHk9Mk=; b=6GLQ3Hh0G3tdtnpQ+rrmGwc66UOHgquO4odOdd3Y3DOTFTOkYzBYT7DeqAbIPgz7GK xx/nLBmc/H8xe1uDBTdMKN+E5Ae08SY1gEUitfwqQTxOvpVcNlnfRoZw3fTKnG492P63 +1fs3vO0dR32G3k8GI/l/BCNk5TumUiZm1mlbjPi658uYxqydCbOf0i7aSa84TGpM5hL XYJKp1esOE2UN50MJ4EBseZnze6N3qsZT2E4iUBFahN5gjXeOvFbhIaXkRVRNZZ7E/Ua LmRTnDiNerQhIwhnMlTywH31eiX5pgKM44l6XNBsmKytb2XCXgow5NF35fbtn7K2b37H eQYA== X-Gm-Message-State: ACgBeo2LFdcGTfZ24P7GWOxQ0X9LxqXvVzHSXxOXmXjSjiymwg6UXbse LiyiCzlZht7/eAJHg0EWEYNB5Rdg8+tc5RCVzIUV1jHMDkktIaH4ULJt2+4B5nW2AJsTNmhr2mV jowVTH/h7vA== X-Received: by 2002:a2e:2418:0:b0:25e:43f6:384f with SMTP id k24-20020a2e2418000000b0025e43f6384fmr4431488ljk.361.1660536387128; Sun, 14 Aug 2022 21:06:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR52qXe+GKx07PMg/MOOtNKldBHgwnksYeoALnBVSNmwcSekT1p1h2vXeTAa4vGQP4+hGNtN4A== X-Received: by 2002:a2e:2418:0:b0:25e:43f6:384f with SMTP id k24-20020a2e2418000000b0025e43f6384fmr4431472ljk.361.1660536386930; Sun, 14 Aug 2022 21:06:26 -0700 (PDT) Received: from [192.168.1.121] (91-145-109-188.bb.dnainternet.fi. [91.145.109.188]) by smtp.gmail.com with ESMTPSA id g3-20020a2ea4a3000000b0025e5fd96bf6sm1284615ljm.15.2022.08.14.21.06.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 Aug 2022 21:06:26 -0700 (PDT) Message-ID: <490e670d-40fe-6284-04d9-9be8fd15d49f@redhat.com> Date: Mon, 15 Aug 2022 07:06:25 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 2/2] selftests/hmm-tests: Add test for dirty bits From: =?UTF-8?Q?Mika_Penttil=c3=a4?= To: Alistair Popple Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , David Hildenbrand , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , linuxram@us.ibm.com, paulus@ozlabs.org References: <8f19b172d32be2e889b837f88b1ba070bf2c97ee.1660281458.git-series.apopple@nvidia.com> <1ec090fa-f93b-c197-e5b3-ff2b0d5862ef@redhat.com> <87lerqw72n.fsf@nvdebian.thelocal> <58be2b37-0c3a-06d8-35f5-50bf4b765fb2@redhat.com> <87h72ew4p6.fsf@nvdebian.thelocal> <2aa2013a-735d-a96a-2f35-0a44a06d85f0@redhat.com> In-Reply-To: <2aa2013a-735d-a96a-2f35-0a44a06d85f0@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660536390; a=rsa-sha256; cv=none; b=vX+rR+8Xz/ppnCgq6FfucQUfJcULYH5YjAUuPQvz7b8qQcTrljTRVW0VDSYwqVBzPP5aGS wRd8cV58DLHuNy0mEmOvvfF1if/H+XDGbfgiu6jNu4HCZxfzQJJF1YsL89cgl5KXZQJMmr DdaAnIP4I9FJWxI99PcJXm2OPL58DXg= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LoeSVcve; spf=pass (imf09.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mpenttil@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660536390; 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=g/Qyy/TUtlP5wQvlalN7RTOTbhmCvMUhu++naFHk9Mk=; b=NLBzlnUAL5eZ6Ul1nPDW2Lki1JVrNezP1m3XfuPyuwO5cEn3TMBUoYyrnO/6nALnBm2+13 YYkTEheQq8i2bRyjS2FeNUvbu7RRNHtPS2ed7JGPnwXwx+scjdLpHoBMNC2O/56E8uGbos rPCY+gU5996SL9V6yjJvtBSHUzjJ9o4= X-Stat-Signature: rcuxaw8wo6cdwihycn868body7sx1e1e X-Rspamd-Queue-Id: 88C581401B7 X-Rspam-User: X-Rspamd-Server: rspam03 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LoeSVcve; spf=pass (imf09.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mpenttil@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1660536390-14724 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 15.8.2022 7.05, Mika Penttilä wrote: > > > On 15.8.2022 6.21, Alistair Popple wrote: >> >> Mika Penttilä writes: >> >>> On 15.8.2022 5.35, Alistair Popple wrote: >>>> Mika Penttilä writes: >>>> >>>>> Hi Alistair! >>>>> >>>>> On 12.8.2022 8.22, Alistair Popple wrote: >>>> [...] >>>> >>>>>> +    buffer->ptr = mmap(NULL, size, >>>>>> +               PROT_READ | PROT_WRITE, >>>>>> +               MAP_PRIVATE | MAP_ANONYMOUS, >>>>>> +               buffer->fd, 0); >>>>>> +    ASSERT_NE(buffer->ptr, MAP_FAILED); >>>>>> + >>>>>> +    /* Initialize buffer in system memory. */ >>>>>> +    for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) >>>>>> +        ptr[i] = 0; >>>>>> + >>>>>> +    ASSERT_FALSE(write_cgroup_param(cgroup, "memory.reclaim", >>>>>> 1UL<<30)); >>>>>> + >>>>>> +    /* Fault pages back in from swap as clean pages */ >>>>>> +    for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) >>>>>> +        tmp += ptr[i]; >>>>>> + >>>>>> +    /* Dirty the pte */ >>>>>> +    for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) >>>>>> +        ptr[i] = i; >>>>>> + >>>>> >>>>> The anon pages are quite likely in memory at this point, and dirty >>>>> in pte. >>>> Why would the pte be dirty? I just confirmed using some modified >>>> pagemap >>>> code that on my system at least this isn't the case. >>>> >>>>>> +    /* >>>>>> +     * Attempt to migrate memory to device, which should fail >>>>>> because >>>>>> +     * hopefully some pages are backed by swap storage. >>>>>> +     */ >>>>>> +    ASSERT_TRUE(hmm_migrate_sys_to_dev(self->fd, buffer, npages)); >>>>> >>>>> And pages marked dirty also now. But could you elaborate how and >>>>> where the above >>>>> fails in more detail, couldn't immediately see it... >>>> Not if you don't have patch 1 of this series applied. If the >>>> trylock_page() in migrate_vma_collect_pmd() succeeds (which it almost >>>> always does) it will have cleared the pte without setting PageDirty. >>>> >>> >>> Ah yes but I meant with the patch 1 applied, the comment "Attempt to >>> migrate >>> memory to device, which should fail because hopefully some pages are >>> backed by >>> swap storage" indicates that hmm_migrate_sys_to_dev() would fail..and >>> there's >>> that ASSERT_TRUE which means fail here. >>> >>> So I understand the data loss but where is the >>> hmm_migrate_sys_to_dev() failing, >>> with or wihtout patch 1 applied? >> >> Oh right. hmm_migrate_sys_to_dev() will fail because the page is in the >> swap cache, and migrate_vma_*() doesn't currently support migrating >> pages with a mapping. >> > > Ok I forgot we skip also page cache pages, not just file pages... Meant we skip swap cache pages also, not just file pages.. > > > > >>>> So now we have a dirty page without PageDirty set and without a dirty >>>> pte. If this page gets swapped back to disk and is still in the swap >>>> cache data will be lost because reclaim will see a clean page and won't >>>> write it out again. >>>> At least that's my understanding - please let me know if you see >>>> something that doesn't make sense. >>>> >>>>>> + >>>>>> +    ASSERT_FALSE(write_cgroup_param(cgroup, "memory.reclaim", >>>>>> 1UL<<30)); >>>>>> + >>>>>> +    /* Check we still see the updated data after restoring from >>>>>> swap. */ >>>>>> +    for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) >>>>>> +        ASSERT_EQ(ptr[i], i); >>>>>> + >>>>>> +    hmm_buffer_free(buffer); >>>>>> +    destroy_cgroup(); >>>>>> +} >>>>>> + >>>>>>     /* >>>>>>      * Read anonymous memory multiple times. >>>>>>      */ >>>>> >>>>> >>>>> --Mika >>>> >>