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 54100C00140 for ; Mon, 15 Aug 2022 04:05:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A71588D0002; Mon, 15 Aug 2022 00:05:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F99C6B0074; Mon, 15 Aug 2022 00:05:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 874438D0002; Mon, 15 Aug 2022 00:05:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 71F496B0073 for ; Mon, 15 Aug 2022 00:05:11 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 36F3A160C6E for ; Mon, 15 Aug 2022 04:05:11 +0000 (UTC) X-FDA: 79800486822.17.A59D990 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id ABA07401B5 for ; Mon, 15 Aug 2022 04:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660536309; 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=V5rX/kWCOUf7vLxdENPfT3W8GLw3cWWjdBwH52UOWD4=; b=AxHDAKTRRgJHK1wODb/BEwhPYPVHmijxk3OrG4mu5oYuPeSI59NV5ddua9xV+LTqdgsgKG BWPJuwBHvuf0MBS0pLK9Fto+witzEaQjIyrrhybQ47toz+wW7+v+4W0MqLwwc6cCPsvvJJ 8A4UYcafs535E3jiD72Uxjg4QtX9Lsw= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-328-51oc1W-CO_mb6rrowSV4Ew-1; Mon, 15 Aug 2022 00:05:04 -0400 X-MC-Unique: 51oc1W-CO_mb6rrowSV4Ew-1 Received: by mail-lj1-f200.google.com with SMTP id y10-20020a2eb00a000000b0025e505fc2c4so1891239ljk.11 for ; Sun, 14 Aug 2022 21:05:04 -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=V5rX/kWCOUf7vLxdENPfT3W8GLw3cWWjdBwH52UOWD4=; b=roV9q6GQPEdsbUgW2jFY1DWDEeq1lNLgGww3uYcopsJbSen1RlzWPXeDbGBuXQr/1T 5iHYsbLOZGm/19rKo2Xm0W6iMRNwN+awE0SpKJQc7R0yaS15+0FpdWjmQi7xWdpmV8C8 +35VVc/0CSDofcJswh3eGIcVXrIaWJ1J1CljMePW9mW7Nk8MioDK1Ji//zc+1df4uQ3z BJN4jCvpbI2NYil5BIkfCH5cwFhiP8MzkHkpeaP+IQXMAOUhbb1eCk3YUfNoGJpmV1i0 wwO38UxOq/zzYtcdtD1/8ZDFw13a6BA+6LpibuYjx9LXHT+45UIvZxqgQWaI5bRt5Chr ZdXA== X-Gm-Message-State: ACgBeo3oQ3QucTHm35XV9Z00UOOaZrcdldCZD40WiBjmKyUxhI5nGXjk F1ZyNHPSkBq8vcHLYnoesqfpmxgiQnc+h+jVA5OKLvyX+ymvoRULiBYKwEwKmH77a1Iv4ufm0us jyJUj2DILAQ== X-Received: by 2002:a05:6512:12c2:b0:48b:a139:fea with SMTP id p2-20020a05651212c200b0048ba1390feamr4576160lfg.46.1660536303062; Sun, 14 Aug 2022 21:05:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR51Revb9bo/WDN7MZ8RPV/wtHGPj/jzdmmQxIPSyX0W1xdO1GrEIpfY4ss3gUj2v7hd6vZpzw== X-Received: by 2002:a05:6512:12c2:b0:48b:a139:fea with SMTP id p2-20020a05651212c200b0048ba1390feamr4576142lfg.46.1660536302767; Sun, 14 Aug 2022 21:05:02 -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 m14-20020a19434e000000b0048aef1abb08sm957530lfj.297.2022.08.14.21.05.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 Aug 2022 21:05:02 -0700 (PDT) Message-ID: <2aa2013a-735d-a96a-2f35-0a44a06d85f0@redhat.com> Date: Mon, 15 Aug 2022 07:05:01 +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> <58be2b37-0c3a-06d8-35f5-50bf4b765fb2@redhat.com> <87h72ew4p6.fsf@nvdebian.thelocal> From: =?UTF-8?Q?Mika_Penttil=c3=a4?= In-Reply-To: <87h72ew4p6.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-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AxHDAKTR; spf=pass (imf07.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mpenttil@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660536310; a=rsa-sha256; cv=none; b=EZwrVeQTpQtFia0rBf+I6JJxDK/7nyV/UHAJd7dXkgozANkotmLzwzv+nz0mJULsQSswoN Dm0/t0SxelapSlLbH+01pIqCnqY+6lmSXIcIcX8z4XOa8eZCY8/8u2nukGjm4wDWvwNqDB mCuL+F8K3sXKH+SuhDk1dUEy82otl1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660536310; 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=V5rX/kWCOUf7vLxdENPfT3W8GLw3cWWjdBwH52UOWD4=; b=gP3Jlw45QeF5OSsxrUuSmU7JkyfVuEX3YBA3V+/3OTL5zElzP/QcbjnnSRDfqjCYQUFtLU YM+QM14cOAYthsJ1pm1Ti7SIPjwScM+1SIW7dI3mwXeQmSYD5gzh7WB9xCatWJ/1ky/jqL R1/2gSnjvSIab+K0LlQstoinvc9geto= Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AxHDAKTR; spf=pass (imf07.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mpenttil@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: ABA07401B5 X-Stat-Signature: demw9fnsogdfnrb4ub4ye8g5hn3j7aon X-Rspam-User: X-HE-Tag: 1660536309-495201 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 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... >>> 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 >>> >