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 DFE92C433F5 for ; Mon, 24 Jan 2022 11:01:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08ACD6B0087; Mon, 24 Jan 2022 06:01:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 039C46B0088; Mon, 24 Jan 2022 06:01:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E435D6B0089; Mon, 24 Jan 2022 06:01:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay027.a.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id D1B366B0087 for ; Mon, 24 Jan 2022 06:01:15 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 9218E1209FD for ; Mon, 24 Jan 2022 11:01:15 +0000 (UTC) X-FDA: 79064888910.03.8C21105 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 6E83640082 for ; Mon, 24 Jan 2022 11:01:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643022074; 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: in-reply-to:in-reply-to:references:references; bh=9pIWysbK7uAS4zY0QBr87aHP0XtUU5Z92lI6LszdCnk=; b=IQQSF4jZnC0Obg2De39ACNa27CbB4TEawkUXrjjbthOVW9yS4PVx1Eon36iIajoGXs5AnI V/oQfRN/TzmYwSGW4OgXePJSOQLzVJ4v50/kNEKCRkCxnnthrYO2ff65RaxzxgZ9RiwKGe w9hDaXQ9reu+S5AhWjqDLDH1yuQ8oko= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-483-mbuO4jBnOx--1x1ioX_cJA-1; Mon, 24 Jan 2022 06:01:12 -0500 X-MC-Unique: mbuO4jBnOx--1x1ioX_cJA-1 Received: by mail-pf1-f199.google.com with SMTP id d9-20020a62f809000000b004bb5ffee9b3so9058166pfh.15 for ; Mon, 24 Jan 2022 03:01:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9pIWysbK7uAS4zY0QBr87aHP0XtUU5Z92lI6LszdCnk=; b=IUalZ2j8Y/s6Y9N9YOLG+GpJ7+eqTgF3pDAy6JztFxymK3Eu4ZNJ/MeVdTKdvGWZLd Cg37PgoFh1agLW/kNP8Fy8Ora0wieDJWjC5axDqUbGGwZi46rEhBGZEXwruMzxKt9Lrg ESMmfMX2Fk4rpjKPX3cLRINqsxVas6Q0JQiLsejUizBdtQcmYC9kWksAaoAq+nbDKAuX 5CfZofSioEIqmzPOP9SsQ5bMzRptT8kjnDjj1/mpjoDnhEmLV7QgtmcOZWrKWRtwvmZi m+u+f7b+BGSJ6JZjbq8aweWNfgYcUeOiHxJ0Hn12Ji+EOJde3HJnEx+ggKdPSX8/Kjup BuxQ== X-Gm-Message-State: AOAM531Wi0N5qWqOhlyIakiC+8q/lvOSw7EYKX4n5eRaNeej4P/O2q4P EsI+AIJ0Kip40wsP682nO7o0N8gi9YHeYUbnmi51p2QT448oo0l6nv4Eq/PjPq966dfySuXC9EH 5Ur4RVJ/pz9I= X-Received: by 2002:a17:902:ec8d:b0:14b:12aa:dc6b with SMTP id x13-20020a170902ec8d00b0014b12aadc6bmr13959030plg.110.1643022071663; Mon, 24 Jan 2022 03:01:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZYHhviLUCVWev5Ra3LhgWopKWizHfMu72oNVWNnslOg4Cv35SXQF8v3cr3YdtXOFT90jpSw== X-Received: by 2002:a17:902:ec8d:b0:14b:12aa:dc6b with SMTP id x13-20020a170902ec8d00b0014b12aadc6bmr13958995plg.110.1643022071335; Mon, 24 Jan 2022 03:01:11 -0800 (PST) Received: from xz-m1.local ([94.177.118.73]) by smtp.gmail.com with ESMTPSA id gt19sm12681405pjb.50.2022.01.24.03.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 03:01:10 -0800 (PST) Date: Mon, 24 Jan 2022 19:01:04 +0800 From: Peter Xu To: Hugh Dickins Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, David Hildenbrand , Andrea Arcangeli , Yang Shi , Vlastimil Babka , Andrew Morton , Alistair Popple , "Kirill A . Shutemov" , Matthew Wilcox Subject: Re: [PATCH RFC v2 1/2] mm: Don't skip swap entry even if zap_details specified Message-ID: References: <20211115134951.85286-1-peterx@redhat.com> <20211115134951.85286-2-peterx@redhat.com> <9937aaa-d9ab-2839-b0b7-691d85c9141@google.com> <391aa58d-ce84-9d4-d68d-d98a9c533255@google.com> <93dd745c-5e8b-a50-4ec5-b3f3728ad8b@google.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IQQSF4jZ; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf11.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: 3t78h4m3qcuniy81b813s9xx55ok6c1e X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6E83640082 X-HE-Tag: 1643022074-673019 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 Mon, Jan 24, 2022 at 04:54:29PM +0800, Peter Xu wrote: > I have a quick idea on reproducer now (perhaps file size shrinking on private > pages being swapped out), I'll try to write a real reproducer and update later. Here's the reproducer.. ===8<=== #define _GNU_SOURCE /* See feature_test_macros(7) */ #include #include #include #include #include int page_size; int shmem_fd; char *buffer; void main(void) { int ret; char val; page_size = getpagesize(); shmem_fd = memfd_create("test", 0); assert(shmem_fd >= 0); ret = ftruncate(shmem_fd, page_size * 2); assert(ret == 0); buffer = mmap(NULL, page_size * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE, shmem_fd, 0); assert(buffer != MAP_FAILED); /* Write private page, swap it out */ buffer[page_size] = 1; madvise(buffer, page_size * 2, MADV_PAGEOUT); /* This should drop private buffer[page_size] already */ ret = ftruncate(shmem_fd, page_size); assert(ret == 0); /* Recover the size */ ret = ftruncate(shmem_fd, page_size * 2); assert(ret == 0); /* Re-read the data, it should be all zero */ val = buffer[page_size]; if (val == 0) printf("Good\n"); else printf("BUG\n"); } ===8<=== I'm looking for a correct Fixes for the 1st patch, but afaict it seems not right even in the initial git commit, which traces back to the "history" git repo of your commit: dd9fd0e03de6 ("[PATCH] rmap: nonlinear truncation", 2004-04-17) Where we have: /* * If details->check_mapping, we leave swap entries; * if details->nonlinear_vma, we leave file entries. */ if (unlikely(details)) continue; if (!pte_file(ptent)) free_swap_and_cache(pte_to_swp_entry(ptent)); As I don't know how it could be right if the user only specified details->nonlinear_vma but keeping details->check_mapping==NULL.. there, and there're definitely callers for that, e.g.: static long madvise_dontneed(struct vm_area_struct * vma, unsigned long start, unsigned long end) { if ((vma->vm_flags & VM_LOCKED) || is_vm_hugetlb_page(vma)) return -EINVAL; if (unlikely(vma->vm_flags & VM_NONLINEAR)) { struct zap_details details = { .nonlinear_vma = vma, .last_index = ULONG_MAX, }; zap_page_range(vma, start, end - start, &details); } else zap_page_range(vma, start, end - start, NULL); return 0; } So I plan to add the Fixes to the initial git commit, 1da177e4c3f4 ("Linux-2.6.12-rc2", 2005-04-16). Does it sound right to you? Thanks, -- Peter Xu