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 A6EB3C433F5 for ; Thu, 20 Jan 2022 15:51:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D4B36B00A3; Thu, 20 Jan 2022 10:51:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 383F26B00A5; Thu, 20 Jan 2022 10:51:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 273606B00A6; Thu, 20 Jan 2022 10:51:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 185B06B00A3 for ; Thu, 20 Jan 2022 10:51:53 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B5457181CAC4A for ; Thu, 20 Jan 2022 15:51:52 +0000 (UTC) X-FDA: 79051106064.22.465BD20 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id EB9311C0007 for ; Thu, 20 Jan 2022 15:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642693911; 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=CoYY5viRTf6GNH+jXrDipEksbJM4x4BdIORqy3eZioQ=; b=Yzvo8ybZMSTCnbAM+ROZuisisTlX/zpk/xPWAK41tvU4XEDoRtnQxc5Jn+cuP7hm72hLkC 8i2tygT6SsMsED5qnD8sykP4PRwfVewlVc8A5XxrjEXbunDW7AO+B9Ev2LApSvf+hU6aLz EFEa+8UdkiwONykVyCiqHJUCtpSFNCk= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-554-1he-WHK-O9-8tUUEQoWScA-1; Thu, 20 Jan 2022 10:51:50 -0500 X-MC-Unique: 1he-WHK-O9-8tUUEQoWScA-1 Received: by mail-ed1-f70.google.com with SMTP id a18-20020aa7d752000000b00403d18712beso6266952eds.17 for ; Thu, 20 Jan 2022 07:51:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=CoYY5viRTf6GNH+jXrDipEksbJM4x4BdIORqy3eZioQ=; b=OCbY6zG2xlL490FIfPj3FeIjnS9zaKGZJiZh949+S1DmcQYieiM93ILFs7dsVqg1l6 NdlePzGg5gzT4k0d14MiUgxbWa5Y8MgREwyTSh9e/lhHYfv7VaaCaHCVlaaaeByw8p4v CjkehlaFjVXWcEBOTv0fkf3bbW7Zrw+1j17ioh9lNmnShNqJg9B6eaQUgkIrlcDlIoH6 3Xs5AODgorasR7Nk24E6xw1ObQ/ujjj0Q7UoGgIeO+zZhmmC9UrQn1puGfNCEp6QPoAG kw7cvXbqzWo6GQICVlSdfc5yXWGxwPUOaCB5VufEM+82Yj1aOuHlylZ/6gMHnxcPGB5V hA7A== X-Gm-Message-State: AOAM530UMsjYxjCJJVNtFc6HXO6OkxbUf2d81+nx0LZWYtMjMibRH3x4 qUCR2s//4X6t8/O5kL6HAJMtGIQDw9SfvxR21cfqnqa2wpWSYLRRGp1VN/0jZo6tMmno2EtwwIO fPk7vM9Y2ivI= X-Received: by 2002:a05:6402:4406:: with SMTP id y6mr19755878eda.223.1642693908821; Thu, 20 Jan 2022 07:51:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcWYPWw0qlk/R3upaiwvY2ZgKVUs8+1u3TPq9D7w89gknnCekiLfKaMoADb7owdWhHRLMnvA== X-Received: by 2002:a05:6402:4406:: with SMTP id y6mr19755861eda.223.1642693908646; Thu, 20 Jan 2022 07:51:48 -0800 (PST) Received: from ?IPV6:2003:cb:c70e:5800:eeb:dae2:b1c0:f5d1? (p200300cbc70e58000eebdae2b1c0f5d1.dip0.t-ipconnect.de. [2003:cb:c70e:5800:eeb:dae2:b1c0:f5d1]) by smtp.gmail.com with ESMTPSA id b2sm1461596edu.84.2022.01.20.07.51.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jan 2022 07:51:48 -0800 (PST) Message-ID: <88a8b1a3-232d-df9c-d7f6-0ea9f2dd4b36@redhat.com> Date: Thu, 20 Jan 2022 16:51:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page To: Matthew Wilcox Cc: "zhangliang (AG)" , Andrew Morton , Linux-MM , Linux Kernel Mailing List , wangzhigang17@huawei.com, Linus Torvalds References: <9cd7eee2-91fd-ddb8-e47d-e8585e5baa05@redhat.com> <747ff31c-6c9e-df6c-f14d-c43aa1c77b4a@redhat.com> <759f9bc8-0b10-7f0f-28a6-f292bed9053f@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 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: EB9311C0007 X-Stat-Signature: f564zd1gcn4yc75o4inc3hcq4ooppus6 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Yzvo8ybZ; spf=none (imf20.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam07 X-HE-Tag: 1642693911-575429 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: >> Yes, we are talking past each other and no, I am talking about fully >> mapped THP, just mapped via PTEs. >> >> Please refer to our THP COW logic: do_huge_pmd_wp_page() > > You're going to have to be a bit more explicit. That's clearly handling > the case where there's a PMD mapping. If there is _also_ a PTE mapping, > then obviously the page is mapped more than once and can't be reused! > >>> >>>>> Anon THP is always going to start out aligned (and can be moved by >>>>> mremap()). Arguably it should be broken up if it's moved so it can be >>>>> reformed into aligned THPs by khugepaged. >>>> >>>> Can you elaborate, I'm missing the point where something gets moved. I >>>> don't care about mremap() at all here. >>>> >>>> >>>> 1. You have a read-only, PTE mapped THP >>>> 2. Write fault on the THP >>>> 3. We PTE-map the THP because we run into a false positive in our COW >>>> logic to handle COW on PTE >>>> 4. Write fault on the PTE >>>> 5. We always have to COW each and every sub-page and can never reuse, >>>> because page_count() > 1 >>>> >>>> That's essentially what reuse_swap_page() tried to handle before. >>>> Eventually optimizing for this is certainly the next step, but I'd like >>>> to document which effect the removal of reuse_swap_page() will have to THP. >>> >>> I'm talking about step 0. How do we get a read-only, PTE-mapped THP? >>> Through mremap() or perhaps through an mprotect()/mmap()/munmap() that >>> failed to split the THP. >> >> do_huge_pmd_wp_page() > > I feel you could be a little more verbose about what you think is > going on here. Are you talking about the fallback: path where we > call __split_huge_pmd()? Sorry, I was less verbose because I was just sending out the patch+description to Linus' reply and was assuming you're going to read it anyways ;) Yes, I'm speaking about exactly that fallback path. -- Thanks, David / dhildenb