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 E5275C27C79 for ; Thu, 20 Jun 2024 16:27:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73FC58D00C0; Thu, 20 Jun 2024 12:27:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F0428D00AF; Thu, 20 Jun 2024 12:27:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B7E98D00C0; Thu, 20 Jun 2024 12:27:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3DEC28D00AF for ; Thu, 20 Jun 2024 12:27:34 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D4C7A16038F for ; Thu, 20 Jun 2024 16:27:33 +0000 (UTC) X-FDA: 82251797586.10.CDE012F Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) by imf13.hostedemail.com (Postfix) with ESMTP id 060F320004 for ; Thu, 20 Jun 2024 16:27:31 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ZNOR1WxA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of hughd@google.com designates 209.85.160.53 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718900844; a=rsa-sha256; cv=none; b=BdsgOVo+D/Xv/eKWxDtCV5D9PwwB4lsyqc4TOMJ0cGMVunmmnkbHyGO+FLgL4JU+y9xfBu 5/jnw4nhfzTB8n4ADAr3P6Uqn6L3vF/ipapAk8t5QtJmljzrwUu0ZQMSjw5rStCCespY/A E+4GiLYeGU9tZeruSFLvhxRm9kIWtMY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ZNOR1WxA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of hughd@google.com designates 209.85.160.53 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718900844; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LJOyqSR9lG9EDrbgCSZX5dpQpgzoCzpoMZm9oXH8nto=; b=Aqi/bZ5jkI40I3vFeRpBAf/GyWemEYd4l+VSnEwldZUSqCggqyVChWkZUNUqkaWVi9JfSl LDxTcyS9KQO8jrLZmTwC/5dR1yKUX80IZS5YgwFok5qoR+U5MnI5VI41fZ6lxd5XSPj9Z1 hnywGrxrWxrfIoGgbyoJNZKjAyBhSFY= Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-25caf76158cso633793fac.0 for ; Thu, 20 Jun 2024 09:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718900851; x=1719505651; darn=kvack.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=LJOyqSR9lG9EDrbgCSZX5dpQpgzoCzpoMZm9oXH8nto=; b=ZNOR1WxAqPGUMr4S57qJrFyCZ/oTYXbhasUMfIe6soGOHowAkr6OyMhEhg6yqatLOv 8mWQIe2HdKBbV+OGwSurA9dvvtpd9H5hg5bc+AkBQpsYubNy23CXNJxO3X8E4b/PgpSf ALZvOMEKGT3vuyaptRG2LEUAolRQVoWhzt8JHz6KsZ50Wrj+pUhgKsoxLJaxiFbS+6m5 WJ5IkayxYFV6+HGv6SLDLwrF23ILTHFBQkgAq347qVhpYZcBKDvhKqjepx64DhI89mXd zj6pRKiz8MT7eE+fsW4jiOKuvdNRqjhGJWw1TYNZ1cOIbn/nJQLeAY9Q53BekXIkZu5Y BmWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718900851; x=1719505651; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LJOyqSR9lG9EDrbgCSZX5dpQpgzoCzpoMZm9oXH8nto=; b=HzbXbxgpmjFdXLRlgfBFCOlw3B0JDvyFh5Yf5sjxojl2JNI4MTiEjM6TkLvVs5dEmS gxXwTr2orUtGKUY2Ke1LqeBLiFxiNjU9cIzuDQUQiCs875NSwrsHNgm+uAr3YNHxB1ly ftVxiZpATUFNLMjYt2qviR4M/EnGGRBoSDpxM/yY2sl0W8xzBKegD7VI3Nn6dEb6VdhX ekc6whzcRzMJs/qysKeRWW7E4+NsMkJyDuum1OdgK0eoQMR/t7MQmSbzOtEJc++CAhXE XgZNS+3Mzfvjix7IbUDdR9FjxM7nZcVw/Q+d3T0YT1ciqB/vGVbi+5WK2Zqt1BuhMdAW Tl9Q== X-Forwarded-Encrypted: i=1; AJvYcCXgKlO5WxnRuqxwrDG5uuMEfCu/18GthHGh0Dzk0ihQkHpOvMwOSC2iPESxyJAF6Bhb/DBfPeWY78R3rCuNDvT1Voo= X-Gm-Message-State: AOJu0YzMWvflbcDxIvxDv7j2RFDgUtYe0fTKWyx+knMuKuGY1EOwm96Q DL+JbAVCnliJJ9WAkJC6XogvQA8h3GBf0ZTk2Ush4qWFZWrLFBDCme2WJuGvlw== X-Google-Smtp-Source: AGHT+IFOtBQNQsP0PLBL4sB1EhF5m77tG7xFzLzDAYZH9IhuN2sIE01sJKRp2pkHtfQQ6NLCYY/KYw== X-Received: by 2002:a05:6870:a447:b0:254:b1b1:7ea4 with SMTP id 586e51a60fabf-25c9498fcadmr6894761fac.12.1718900850745; Thu, 20 Jun 2024 09:27:30 -0700 (PDT) Received: from darker.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-2567aa10337sm4289189fac.22.2024.06.20.09.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 09:27:29 -0700 (PDT) Date: Thu, 20 Jun 2024 09:27:18 -0700 (PDT) From: Hugh Dickins To: David Hildenbrand cc: Hugh Dickins , Andrew Morton , Barry Song , Baolin Wang , willy@infradead.org, wangkefeng.wang@huawei.com, chrisl@kernel.org, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, ioworker0@gmail.com, da.gomez@samsung.com, p.raghav@samsung.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 0/9] support large folio swap-out and swap-in for shmem In-Reply-To: <2a358ff4-4219-4262-9225-d9aab14445f6@redhat.com> Message-ID: References: <20240618130538.ffab3ce1b4e66e3ba095d8cf@linux-foundation.org> <475f0f2c-afc7-4225-809f-93c93f45c830@linux.alibaba.com> <2683b71d-aebd-5527-348c-18c0e021b653@google.com> <25ae21b4-23d5-73ba-2e0a-e642ec4b69a0@google.com> <2a358ff4-4219-4262-9225-d9aab14445f6@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 060F320004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: qyxdehrnfydznub1hqdscjdgf8kc7qph X-HE-Tag: 1718900851-812209 X-HE-Meta: U2FsdGVkX1+sSofb7z/Jibkm1ZCYlJ3fKz+MVxW5hbdyJfEVFat1gTHHHdoV2v8WRI5P8wjhzSbYZxl+p+Wk7S2+So7kOK1/h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hjFUPfIxlBLNf+vkJmOxHSG3Zz4Tw88tJu6soE58qt9rkdR5hF+nqy5EanrMF7k/MElU10PQ/+yO2gVA1wuQxILC6iiMXp8uhKLTIYz8JJ7/M6VYp4hB2J8Ob8bxFBQ== 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: List-Subscribe: List-Unsubscribe: On Thu, 20 Jun 2024, David Hildenbrand wrote: > > > > (I do have doubts about Barry's: the "_new" in folio_add_new_anon_rmap() > > was all about optimizing a known-exclusive case, so it surprises me > > to see it being extended to non-exclusive; and I worry over how its > > atomic_set(&page->_mapcount, 0)s can be safe when non-exclusive (but > > I've never caught up with David's exclusive changes, I'm out of date). > > We discussed that a while ago: if we wouldn't be holding the folio lock in the > "folio == swapcache" at that point (which we do for both do_swap_page() and > unuse_pte()) things would already be pretty broken. You're thinking of the non-atomic-ness of atomic_set(): I agree that the folio lock makes that safe (against other adds; but not against concurrent removes, which could never occur with the old "_new" usage). But what I'm worried about is the 0 in atomic_set(&page->_mapcount, 0): once the folio lock has been dropped, another non-exclusive add could come in and set _mapcount again to 0 instead of to 1 (mapcount 1 when it should be 2)? > > That's I added a while ago: > > if (unlikely(!folio_test_anon(folio))) { > VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio); > /* > * For a PTE-mapped large folio, we only know that the single > * PTE is exclusive. Further, __folio_set_anon() might not get > * folio->index right when not given the address of the head > * page. > */ > ... > > We should probably move that VM_WARN_ON_FOLIO() to folio_add_new_anon_rmap() > and document that it's required in the non-exclusive case. > > > > > But even if those are wrong, I'd expect them to tend towards a mapped > > page becoming unreclaimable, then "Bad page map" when munmapped, > > not to any of the double-free symptoms I've actually seen.) > > What's the first known-good commit? I cannot answer that with any certainty: we're on the shifting sands of next and mm-unstable, and the bug itself is looking rather like something which gets amplified or masked by other changes - witness my confident arrival at Barry's series as introducing the badness, only for a longer run then to contradict that conclusion. There was no sign of a problem in a 20-hour run of the same load on rc3-based next-2024-06-13 (plus my posted fixes); there has been no sign of this problem on 6.10-rc1, rc2, rc3 (but I've not tried rc4 itself, mm.git needing the more urgent attention). mm-everything- 2024-06-15 (minus Chris's mTHP swap) did not show this problem, but did show filemap_get_folio() hang. mm-everything-2024-06-18 (minus Baolin's mTHP shmem swap) is where I'm hunting it. Hugh