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 A0023C00140 for ; Mon, 15 Aug 2022 03:11:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D69F26B0073; Sun, 14 Aug 2022 23:11:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D19B08D0002; Sun, 14 Aug 2022 23:11:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB9AD6B0075; Sun, 14 Aug 2022 23:11:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AAC096B0073 for ; Sun, 14 Aug 2022 23:11:32 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8286740CC3 for ; Mon, 15 Aug 2022 03:11:32 +0000 (UTC) X-FDA: 79800351624.29.DCFD93D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id EC7A918008E for ; Mon, 15 Aug 2022 03:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660533091; 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=SjMszlsPJzqPdD9SX0g5g2TJ7r/jfUNF1gkXOi6GAxg=; b=hnOvz8IepOsBbJSwH7bIasw7teAWZi9xcu8GcrYpVJ3djcY6agL6fp8alRHZriGEWly/KV zfSYk3qeNwrfidCifw3hERQw4K7hOi2svOEge6bioXCjb9/7e2KbT1WJRSKqG83rcKk5rw aO0hR7J8f1G67JWktdbEq0qzjwcZu+A= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-365-mS9aYzLgNmuCFIOXi4LnMg-1; Sun, 14 Aug 2022 23:11:29 -0400 X-MC-Unique: mS9aYzLgNmuCFIOXi4LnMg-1 Received: by mail-lf1-f72.google.com with SMTP id v16-20020a056512049000b0048d0d86c689so992428lfq.15 for ; Sun, 14 Aug 2022 20:11:29 -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:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=SjMszlsPJzqPdD9SX0g5g2TJ7r/jfUNF1gkXOi6GAxg=; b=FEcOJ0qZpDo9jYj92z/nNoPwXc7cTTaV0mPwoPOmm2K0cEy+zlTZB5H+wMRJckY67D CmP041onZIjIZIli/J2tEj/EtjiD797LiwsiiMKFs2ExGQC8zwtIuHhfeNh0bKwin4ha Auud98INFFBioQPjO+AnDTqP0hp4hQ8STNHTLMqlii4SPOAGMWkaULqT9H1H4LqsJULb luIsajyE1zWUzwEZc5R2NOfoe7G2/9w48Tl1kuA/O0sY4cqeUvzHtbjuG8jJvBH6yCuH UaF6qMRNN94LjE+TObKvZLWwSdLYp0jJ5rFXLyBR1dCE+30FGPde1nu5Jy+y9OotT8pn s0Iw== X-Gm-Message-State: ACgBeo00ZYzdIMBU3KtPBiI+VgYeOtqIrhdSkJ5uAs+QzkuaLIcAUDUu nESPxvBZ+jXUJ9qa/WtxxMBFwfFhARZS9NBLxbAIZZmpZJav48Svllx3Mjr2Q7PxBy6FrKsiB9x DpgXfXIHhiw== X-Received: by 2002:a05:651c:1584:b0:25d:c6ad:6237 with SMTP id h4-20020a05651c158400b0025dc6ad6237mr4128029ljq.509.1660533088491; Sun, 14 Aug 2022 20:11:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR75Rkq4uNFv4jWdO6CE/+UN/BzpT4Y4J0IXpmyBUcSf+60GXQXh+SEmp9hi7JNUXySLvgWU7A== X-Received: by 2002:a05:651c:1584:b0:25d:c6ad:6237 with SMTP id h4-20020a05651c158400b0025dc6ad6237mr4128010ljq.509.1660533088227; Sun, 14 Aug 2022 20:11:28 -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 h5-20020a05651c124500b0025e2cb58c6esm1271348ljh.37.2022.08.14.20.11.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 Aug 2022 20:11:27 -0700 (PDT) Message-ID: <58be2b37-0c3a-06d8-35f5-50bf4b765fb2@redhat.com> Date: Mon, 15 Aug 2022 06:11:26 +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 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> From: =?UTF-8?Q?Mika_Penttil=c3=a4?= In-Reply-To: <87lerqw72n.fsf@nvdebian.thelocal> 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=1660533092; a=rsa-sha256; cv=none; b=idcxTbQsf8PEixI6i7HXUI8fL3w1YM2v/ysG1DCV+P+ROq1kadIeg5tj+wvUxhBfil9wGY IfZgVe4RtbpP0oPIxitGAX9N8CDdJlPIBfKDa705VHP999gYaVD9ISHGiWuzqH7eXggPFB k1nGXL4XEHy/RtVGZZh8OYZO/rdG5h0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hnOvz8Ie; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mpenttil@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660533092; 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=SjMszlsPJzqPdD9SX0g5g2TJ7r/jfUNF1gkXOi6GAxg=; b=PVTWbnR98pyMCxpOkuTvGHimErEyHTG2TXbFNhiwGdZ/lHnCdBOwYe9Rr74nJi6z3EJdub jvAw+63mxLQm93iLCaI6uWlwvRFJBWgjV3gujobl+e8NPf8BwkBG6rG16x5yndr5ifV4re UM4Z2Iph7/uG1E7vO1/YzcYQc5oTY2s= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EC7A918008E Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hnOvz8Ie; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mpenttil@redhat.com X-Rspam-User: X-Stat-Signature: xakpgikynwmh1yppfg78917yniiia55u X-HE-Tag: 1660533091-889527 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 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? > 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 >