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 85CB6C433FE for ; Thu, 24 Nov 2022 08:50:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBD146B0071; Thu, 24 Nov 2022 03:50:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E6EDA6B0072; Thu, 24 Nov 2022 03:50:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0EA46B0074; Thu, 24 Nov 2022 03:50:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C1EAF6B0071 for ; Thu, 24 Nov 2022 03:50:50 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6EC1AC12DE for ; Thu, 24 Nov 2022 08:50:50 +0000 (UTC) X-FDA: 80167715460.24.A6362BB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id EC7D5180004 for ; Thu, 24 Nov 2022 08:50:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669279849; 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=AlSq+R0UCGrzWTN2OI+5ccwHLBt+HswKEpfrCXKCBz8=; b=V3rFspKG7Lf/yR1JD+ycj4QhEinEyqB0iMSifRXJztUsRlNH0QgX76rsrNcyLuBz0iq0Ij fu1Vn9GpuxRX0Z+NEqXdoIKjwA7rC4IZv+wrGunBeuuZHjJW4XtGTQGadX8SGVQjLI7FBh 5PFtOdMtOoERuo3pKmH7OQze+UoSsnk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-671-3zIRQ0w4Nq2f5_u9J6KBsg-1; Thu, 24 Nov 2022 03:50:47 -0500 X-MC-Unique: 3zIRQ0w4Nq2f5_u9J6KBsg-1 Received: by mail-wr1-f69.google.com with SMTP id t12-20020adfa2cc000000b0022adcbb248bso207610wra.1 for ; Thu, 24 Nov 2022 00:50:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AlSq+R0UCGrzWTN2OI+5ccwHLBt+HswKEpfrCXKCBz8=; b=18kTu93eDPSvniVpQzIuKnFJGtTYrcHawonyl76nCdsMUi1eacMi3L/syFKMBNTODs UL/asuJfZYKOFTqMh/fEgpSG37+r2wzNw/VlsdVWaSZBaUb34ZB5nj1KIpAXGlkUX+Eg bV5UcylxK6g66SJNaqTqb6drJcIsTjcML6hQHnLq8Aw78TsvSCxfntY35V4hOMbIbx/C Iok2sGWSdkANHhfSGfnEZe7SB8VIBphhuBszmx3slFMj2sjquC3H9R2YHC+KD958scTW TwH3Ax18kCj7Qs4b+lsU6EXrNnCwHYwzHgOohIOpt0NP87ZfDQmL/OluTDJ7RzeezORq JaIA== X-Gm-Message-State: ANoB5pnI6XW1Thats0SpGA2zbbcAimrVDOi3qCDpBVz7yqLxBFelsATi ZeZH+wAMWWrABkU4F4bpbZzwDIodxcAgSZ7BeUHz4ovSQqTpO3JuV5rIYzHkGpjRxZkIGqGJYYN Z6dObSVyDw1I= X-Received: by 2002:a05:600c:4f12:b0:3cf:e7bd:303a with SMTP id l18-20020a05600c4f1200b003cfe7bd303amr9934580wmq.151.1669279846792; Thu, 24 Nov 2022 00:50:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4lUOpm6GRem5reVbjhERXENobOIVrxKMIYsHMxEqh3Q90ezhbtAxzFjghfs6HhVnGK2ub/Ng== X-Received: by 2002:a05:600c:4f12:b0:3cf:e7bd:303a with SMTP id l18-20020a05600c4f1200b003cfe7bd303amr9934560wmq.151.1669279846458; Thu, 24 Nov 2022 00:50:46 -0800 (PST) Received: from ?IPV6:2003:cb:c704:2200:bfcb:7212:1370:de13? (p200300cbc7042200bfcb72121370de13.dip0.t-ipconnect.de. [2003:cb:c704:2200:bfcb:7212:1370:de13]) by smtp.gmail.com with ESMTPSA id k2-20020adfe3c2000000b00241bc209ae0sm755714wrm.32.2022.11.24.00.50.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Nov 2022 00:50:46 -0800 (PST) Message-ID: Date: Thu, 24 Nov 2022 09:50:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH] mm: migrate: Fix THP's mapcount on isolation To: Matthew Wilcox Cc: Hugh Dickins , Gavin Shan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, william.kucharski@oracle.com, ziy@nvidia.com, kirill.shutemov@linux.intel.com, zhenyzha@redhat.com, shan.gavin@gmail.com, riel@surriel.com, apopple@nvidia.com References: <20221123005752.161003-1-gshan@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: 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: 7bit ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V3rFspKG; spf=pass (imf06.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669279850; a=rsa-sha256; cv=none; b=xMxqumou89zfC4mzZFVdApJ0yyF/DAVQMJG48lVdDOPT3fUsRic4qUE+SIY3q4JEq5Yjik YxP9T6nPUmxxu1B25Yh9vlZEh1/9ucfxuwVOWixaiUxGXJPyzHorU+BTiYq5kr3jOyU93m toPk2KhkpUWR8GBmFWlHo8AjLFxqqW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669279850; 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=AlSq+R0UCGrzWTN2OI+5ccwHLBt+HswKEpfrCXKCBz8=; b=wVjZOIAP0SyLtIPnwM7Rnz7+kUU945RrVJwFIyOmBVKwg362fmifEG2hQuuiPBt4GTbOCk BxL87S7A6TShJgcT6bLIBYPoD1MKsU9kS/56vMizKfw9q06eZzsuOkSAUWOQTMrIKjDaOc Az7fE9tV44VOTpjrEhVc9kf6gvyXxe8= X-Stat-Signature: 65xzqud9g5q4i6sehr3kq5kedxikytsg X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: EC7D5180004 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V3rFspKG; spf=pass (imf06.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-HE-Tag: 1669279849-499904 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 23.11.22 17:07, Matthew Wilcox wrote: > On Wed, Nov 23, 2022 at 09:56:38AM +0100, David Hildenbrand wrote: >> But we do have an even better helper in place already: >> mm/huge_memory.c:can_split_folio() >> >> Which cares about >> >> a) Swapcache for THP: each subpage could be in the swapcache >> b) Requires the caller to hold one reference to be safe >> >> But I am a bit confused about the "extra_pins" for !anon. Where do the >> folio_nr_pages() references come from? > > When we add a folio to the page cache, we increment its refcount by > folio_nr_pages() instead of by 1. I suspect this is no longer needed > (if it was ever needed) and it could be changed. See > __filemap_add_folio(): > > long nr = 1; > if (!huge) { > nr = folio_nr_pages(folio); > folio_ref_add(folio, nr); > >> So *maybe* it makes sense to factor out can_split_folio() and call it >> something like: "folio_maybe_additionally_referenced" [to clearly >> distinguish it from "folio_maybe_dma_pinned" that cares about actual page >> pinning (read/write page content)]. >> >> Such a function could return false positives/negatives due to races and the >> caller would have to hold one reference and be able to deal with the >> semantics. > > I don't like the 'pextra_pins' parameter to a generic function ... Right, that part should remain khugepaged specific. The assumption would be, that the caller of the generic function holds exactly one additional reference. -- Thanks, David / dhildenb